Add toggle button. And stats

This commit is contained in:
Alfred Melch 2019-08-11 19:08:06 +02:00
parent d6a1c9af4f
commit 65e63dee92
3 changed files with 67 additions and 2 deletions

View File

@ -42,6 +42,11 @@
} }
canvas { canvas {
max-width: 730px; max-width: 730px;
margin: 10px 0;
}
#toggle {
width: 100%;
margin-bottom: 10px;
} }
</style> </style>
</head> </head>
@ -123,6 +128,7 @@
</table> </table>
<h2>Charts</h2> <h2>Charts</h2>
<button id="toggle">Toggle performance measure (ms &lt;-&gt; hz)</button>
<div id="chartRoot">Select a Case to show the charts.</div> <div id="chartRoot">Select a Case to show the charts.</div>
</main> </main>
<script src="./results.js"></script> <script src="./results.js"></script>

View File

@ -27,8 +27,8 @@ export default {
set2: [win_edge_simplify_stack_false, win_edge_simplify_stack_true], set2: [win_edge_simplify_stack_false, win_edge_simplify_stack_true],
set3: [ set3: [
mac_safa_bavaria_vs_false, mac_safa_bavaria_vs_false,
mac_ffox_bavaria_vs_false,
mac_safa_bavaria_vs_true, mac_safa_bavaria_vs_true,
mac_ffox_bavaria_vs_false,
mac_ffox_bavaria_vs_true mac_ffox_bavaria_vs_true
], ],
set4: [ set4: [

View File

@ -13,6 +13,7 @@ function processHash() {
setCharts(set) setCharts(set)
setDimensions(set) setDimensions(set)
printStats()
} }
} }
@ -41,6 +42,8 @@ function setDimensions(set) {
// Chart rendering // Chart rendering
const charts = []
function killChildren(node) { function killChildren(node) {
while (node.hasChildNodes()) node.removeChild(node.lastChild) while (node.hasChildNodes()) node.removeChild(node.lastChild)
} }
@ -48,19 +51,75 @@ function killChildren(node) {
function createChart(config) { function createChart(config) {
let canvas = document.createElement('canvas') let canvas = document.createElement('canvas')
let ctx = canvas.getContext('2d') let ctx = canvas.getContext('2d')
new Chart(ctx, config) charts.push(new Chart(ctx, config))
return canvas return canvas
} }
function destroyCharts() {
while (charts.length) {
let chart = charts.pop()
chart.destroy()
}
}
function setCharts(set) { function setCharts(set) {
let resultsRoot = document.getElementById('chartRoot') let resultsRoot = document.getElementById('chartRoot')
destroyCharts()
killChildren(resultsRoot) killChildren(resultsRoot)
for (let config of results[set]) { for (let config of results[set]) {
resultsRoot.appendChild(createChart(config)) resultsRoot.appendChild(createChart(config))
} }
} }
// toggle button
function togglePerformanceMeasure() {
const toggleLabel = label =>
label === 'Performance - Milliseconds per operation (ms)'
? 'Performance - Operations per second (hz)'
: 'Performance - Milliseconds per operation (ms)'
for (let chart of charts) {
let datasets = chart.config.data.datasets
for (let dataset of datasets) {
if (dataset.id !== 'numberOfNodes') {
dataset.data = dataset.data.map(val => 1000 / val)
}
}
let scaleLabel = chart.config.options.scales.yAxes[0].scaleLabel
scaleLabel.labelString = toggleLabel(scaleLabel.labelString)
chart.update()
}
printStats()
}
// stats
function printStats() {
const sum = arr => arr.reduce((a, b) => a + b, 0)
const mean = arr => sum(arr) / arr.length
const median = arr => [...arr].sort()[Math.floor(arr.length / 2)]
let i = 0
for (let chart of charts) {
console.log(`=== Stats for chart #${i} ===`)
let datasets = chart.config.data.datasets
for (let dataset of datasets) {
if (dataset.data.length === 0 || dataset.id === 'numberOfNodes') continue
let data = dataset.data
console.log(
`Dataset: ${dataset.label}, mean: ${mean(data)}, median: ${median(
data
)}`
)
}
i++
}
}
// init // init
processHash() processHash()
window.onhashchange = processHash window.onhashchange = processHash
document
.getElementById('toggle')
.addEventListener('click', togglePerformanceMeasure)