Add chart labels

This commit is contained in:
Alfred Melch 2019-08-06 14:34:39 +02:00
parent 6308b16f34
commit bf710b68bc
2 changed files with 32 additions and 5 deletions

View File

@ -47,7 +47,12 @@ class WasmVsJsChart extends React.Component {
render() {
let data = JSON.parse(JSON.stringify(this.props.data)) // deep copy
let options = genOptions('Wasm vs. JavaScript', false, this.state.scaleY)
let options = genOptions(
'Wasm vs. JavaScript',
false,
this.state.scaleY,
this.state.values
)
if (this.state.values === 'hz') this.convertDataToHz(data)
return (
<>

View File

@ -26,11 +26,31 @@ export const datasetTemplates = {
transformToObjectFormCase: genDataset('transformToObjectFormCase', 'green')
}
export function genOptions(title, stacked = false, scaleY = 'linear') {
function genScaleLabel(label) {
return {
display: true,
labelString: label,
fontStyle: 'bold'
}
}
export function genOptions(
title,
stacked = false,
scaleY = 'linear',
perfUnit = 'mean'
) {
const perfUnitText = {
mean: 'Milliseconds per operation (ms)',
hz: 'Operations per second (hz)'
}
return {
animation: {
duration: 0
},
legend: {
position: 'bottom'
},
title: {
display: true,
text: title
@ -46,7 +66,7 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
scales: {
xAxes: [
{
// type: scaleX,
scaleLabel: genScaleLabel('Tolerance (length)'),
stacked
}
],
@ -57,7 +77,8 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
stacked,
ticks: {
min: 0
}
},
scaleLabel: genScaleLabel(`Performance - ${perfUnitText[perfUnit]}`)
},
{
id: 'nodes',
@ -68,7 +89,8 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
},
ticks: {
min: 0
}
},
scaleLabel: genScaleLabel('Number of positions in result (#)')
}
]
}