Add legend information

This commit is contained in:
Alfred Melch 2019-08-06 15:15:36 +02:00
parent bf710b68bc
commit 39c83787be
4 changed files with 39 additions and 14 deletions

View File

@ -24,6 +24,7 @@
"chart.js": "^2.8.0", "chart.js": "^2.8.0",
"file-drop-element": "^0.2.0", "file-drop-element": "^0.2.0",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"platform": "^1.3.5",
"react": "^16.8.6", "react": "^16.8.6",
"react-chartjs-2": "^2.7.6", "react-chartjs-2": "^2.7.6",
"react-debounce-render": "^5.0.0", "react-debounce-render": "^5.0.0",

View File

@ -43,6 +43,11 @@ select {
.component { .component {
min-width: 300px; min-width: 300px;
flex: 1; flex: 1;
padding: 10px;
}
.chartComponent {
min-width: 500px;
} }
@media screen and (max-width: 800px) { @media screen and (max-width: 800px) {

View File

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import { Line, Bar } from 'react-chartjs-2' import { Line, Bar } from 'react-chartjs-2'
import debounceRender from 'react-debounce-render' import debounceRender from 'react-debounce-render'
import platform from 'platform'
import { downloadAsJson } from '../../../lib/json-download/index.js' import { downloadAsJson } from '../../../lib/json-download/index.js'
import { datasetTemplates, genOptions, beautifyLabels } from './chartOptions.js' import { datasetTemplates, genOptions, beautifyLabels } from './chartOptions.js'
@ -18,9 +19,17 @@ export class Chart extends React.Component {
data: stats[name] data: stats[name]
})) }))
datasets.push({ ...datasetTemplates.numberOfNodes, data: nodeData }) datasets.push({ ...datasetTemplates.numberOfNodes, data: nodeData })
datasets.push({
label: `High quality mode: ${formState.highQual}`,
data: []
})
datasets.push({
label: `Platform: ${platform.description}`,
data: []
})
let data = { datasets, labels } let data = { datasets, labels }
return ( return (
<div className="component"> <div className="component chartComponent">
<h2>Chart</h2> <h2>Chart</h2>
{chart === 'wasmVsJs' && <WasmVsJsChart data={data} />} {chart === 'wasmVsJs' && <WasmVsJsChart data={data} />}
{chart === 'wasmStack' && <WasmStackChart data={data} />} {chart === 'wasmStack' && <WasmStackChart data={data} />}
@ -48,7 +57,7 @@ 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( let options = genOptions(
'Wasm vs. JavaScript', 'Simplify.wasm vs. Simplify.js',
false, false,
this.state.scaleY, this.state.scaleY,
this.state.values this.state.values
@ -121,7 +130,7 @@ class WasmStackChart extends React.Component {
render() { render() {
const data = this.props.data const data = this.props.data
modifyDataArrays(data, 'simplifyWASM', 'storeCoords', 'loadResult') modifyDataArrays(data, 'simplifyWASM', 'storeCoords', 'loadResult')
const options = genOptions('Wasm execution', true) const options = genOptions('Simplify.wasm runtime insights', true)
return ( return (
<> <>
<Bar <Bar
@ -140,7 +149,10 @@ class WasmStackChart extends React.Component {
class JsStackChart extends React.Component { class JsStackChart extends React.Component {
render() { render() {
const data = this.props.data const data = this.props.data
const options = genOptions('SimplifyJS execution', true) const options = genOptions(
'Simplify.js with coordinates transformation',
true
)
modifyDataArrays( modifyDataArrays(
data, data,
'origSimplifyWithTransformCase', 'origSimplifyWithTransformCase',

View File

@ -7,23 +7,30 @@ function genDataset(label, color, yAxisID = 'performance', type) {
yAxisID, yAxisID,
fill: false, fill: false,
backgroundColor: color, backgroundColor: color,
borderColor: color borderColor: color,
data: []
} }
} }
export const datasetTemplates = { export const datasetTemplates = {
numberOfNodes: genDataset('numberOfNodes', 'grey', 'nodes', 'line'), numberOfNodes: genDataset('# of positions', 'grey', 'nodes', 'line'),
simplifyWASM: genDataset('simplifyWASM', 'red'), simplifyWASM: genDataset('Simplify.wasm', 'red'),
simplifyJS: genDataset('simplifyJS', 'blue'), simplifyJS: genDataset('Simplify.js', 'blue'),
simplifyJSAlt: genDataset('simplifyJSAlt', 'green'), simplifyJSAlt: genDataset('Simplify.js Alternative', 'green'),
storeCoords: genDataset('storeCoords', 'blue'), storeCoords: genDataset('Store coordinates', 'blue'),
loadResult: genDataset('loadResult', 'green'), loadResult: genDataset('Load result', 'green'),
origSimplifyWithTransformCase: genDataset( origSimplifyWithTransformCase: genDataset(
'origSimplifyWithTransformCase', 'Simplify.js with data transformation',
'red' 'red'
), ),
transformToArrayFormCase: genDataset('transformToArrayFormCase', 'blue'), transformToArrayFormCase: genDataset(
transformToObjectFormCase: genDataset('transformToObjectFormCase', 'green') 'Transform result to array format',
'green'
),
transformToObjectFormCase: genDataset(
'Transform coordinates to object format',
'blue'
)
} }
function genScaleLabel(label) { function genScaleLabel(label) {