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() { render() {
let data = JSON.parse(JSON.stringify(this.props.data)) // deep copy 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) if (this.state.values === 'hz') this.convertDataToHz(data)
return ( return (
<> <>

View File

@ -26,11 +26,31 @@ export const datasetTemplates = {
transformToObjectFormCase: genDataset('transformToObjectFormCase', 'green') 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 { return {
animation: { animation: {
duration: 0 duration: 0
}, },
legend: {
position: 'bottom'
},
title: { title: {
display: true, display: true,
text: title text: title
@ -46,7 +66,7 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
scales: { scales: {
xAxes: [ xAxes: [
{ {
// type: scaleX, scaleLabel: genScaleLabel('Tolerance (length)'),
stacked stacked
} }
], ],
@ -57,7 +77,8 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
stacked, stacked,
ticks: { ticks: {
min: 0 min: 0
} },
scaleLabel: genScaleLabel(`Performance - ${perfUnitText[perfUnit]}`)
}, },
{ {
id: 'nodes', id: 'nodes',
@ -68,7 +89,8 @@ export function genOptions(title, stacked = false, scaleY = 'linear') {
}, },
ticks: { ticks: {
min: 0 min: 0
} },
scaleLabel: genScaleLabel('Number of positions in result (#)')
} }
] ]
} }