diff --git a/benchmarking/src/components/chart.js b/benchmarking/src/components/chart.js index d1aa514..770bad1 100644 --- a/benchmarking/src/components/chart.js +++ b/benchmarking/src/components/chart.js @@ -2,7 +2,7 @@ import React from 'react' import { Line, Bar } from 'react-chartjs-2' import debounceRender from 'react-debounce-render' -import { datasetTemplates, genOptions } from './chartOptions.js' +import { datasetTemplates, genOptions, beautifyLabels } from './chartOptions.js' export class Chart extends React.Component { render() { @@ -10,7 +10,7 @@ export class Chart extends React.Component { let { tolRange, chart } = formState tolRange = tolRange || [] - let labels = tolRange + let labels = beautifyLabels(tolRange) // let labels = tolRange.map(x => Math.round(x * 1000) / 1000) let datasets = Object.keys(stats).map(name => ({ ...datasetTemplates[name], diff --git a/benchmarking/src/components/chartOptions.js b/benchmarking/src/components/chartOptions.js index 6b0826c..193e052 100644 --- a/benchmarking/src/components/chartOptions.js +++ b/benchmarking/src/components/chartOptions.js @@ -74,3 +74,15 @@ export function genOptions(title, stacked = false, scaleY = 'linear') { } } } + +/** + * Show a maximum precision + * @param {array} labels + */ +export function beautifyLabels(labels, precision = 5) { + let prec = Math.pow(10, precision) + return labels.map(label => { + let rounded = Math.round(label * prec) / prec + return rounded === 0 ? label : rounded + }) +}