299 |
299 |
300 //////////////////////////////////////////////////////////////// |
300 //////////////////////////////////////////////////////////////// |
301 // UI widgets. |
301 // UI widgets. |
302 |
302 |
303 ui.dom = {}; |
303 ui.dom = {}; |
|
304 ui.dom.putBr = function(parentDom, text) { |
|
305 var lines = text.split('\n'); |
|
306 parentDom.appendChild(document.createTextNode(lines[0])); |
|
307 for (var i = 1; i < lines.length; i++) { |
|
308 parentDom.appendChild(document.createElement('br')); |
|
309 parentDom.appendChild(document.createTextNode(lines[i])); |
|
310 } |
|
311 } |
304 ui.dom.table = function(tbl, cols, cfg) { |
312 ui.dom.table = function(tbl, cols, cfg) { |
305 var tableDom = document.createElement('table'); |
313 var tableDom = document.createElement('table'); |
306 if (typeof cfg.tblClass === 'string') |
314 if (typeof cfg.tblClass === 'string') |
307 tableDom.classList.add(cfg.tblClass); |
315 tableDom.classList.add(cfg.tblClass); |
308 if (typeof cfg.tblTitle === 'string') |
316 if (typeof cfg.tblTitle === 'string') |
309 tableDom.title = cfg.tblTitle; |
317 tableDom.title = cfg.tblTitle; |
310 var trDom = document.createElement('tr'); |
318 var trDom = document.createElement('tr'); |
311 for (var i = 0; i < cols.length; i++) { |
319 for (var i = 0; i < cols.length; i++) { |
312 var thDom = document.createElement('td'); |
320 var thDom = document.createElement('td'); |
313 thDom.appendChild(document.createTextNode(cols[i])); |
321 ui.dom.putBr(thDom, cols[i]); |
314 trDom.appendChild(thDom); |
322 trDom.appendChild(thDom); |
315 } |
323 } |
316 tableDom.appendChild(trDom); |
324 tableDom.appendChild(trDom); |
317 for (var i = 0; i < tbl.length; i++) { |
325 for (var i = 0; i < tbl.length; i++) { |
318 var row = tbl[i]; |
326 var row = tbl[i]; |
867 tblRow.push(parseFloat(row.meanSpeed.toPrecision(3))); |
875 tblRow.push(parseFloat(row.meanSpeed.toPrecision(3))); |
868 tblRow.push(parseFloat(row.maxSpeed.toPrecision(3))); |
876 tblRow.push(parseFloat(row.maxSpeed.toPrecision(3))); |
869 } |
877 } |
870 tbl.push(tblRow); |
878 tbl.push(tblRow); |
871 } |
879 } |
872 var tblCols = ['maxVal', 'n', '%']; |
880 var tblCols = ['max\nval', 'n', '%']; |
873 if (scoreChecked) { |
881 if (scoreChecked) { |
874 tblCols.push('min score'); |
882 tblCols.push('min\nscore'); |
875 tblCols.push('mean score'); |
883 tblCols.push('mean\nscore'); |
876 tblCols.push('max score'); |
884 tblCols.push('max\nscore'); |
877 } |
885 } |
878 if (turnChecked) { |
886 if (turnChecked) { |
879 tblCols.push('min turn'); |
887 tblCols.push('min\nturn'); |
880 tblCols.push('mean turn'); |
888 tblCols.push('mean\nturn'); |
881 tblCols.push('max turn'); |
889 tblCols.push('max\nturn'); |
882 } |
890 } |
883 if (speedChecked) { |
891 if (speedChecked) { |
884 tblCols.push('min speed'); |
892 tblCols.push('min\nspeed'); |
885 tblCols.push('mean speed'); |
893 tblCols.push('mean\nspeed'); |
886 tblCols.push('max speed'); |
894 tblCols.push('max\nspeed'); |
887 } |
895 } |
888 var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) }); |
896 var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) }); |
889 reportDom.appendChild(tableDom); |
897 reportDom.appendChild(tableDom); |
890 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
898 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
891 } |
899 } |