diff --git a/frontend/src/components/Graph.js b/frontend/src/components/Graph.js index 4d41969..471721e 100644 --- a/frontend/src/components/Graph.js +++ b/frontend/src/components/Graph.js @@ -9,7 +9,6 @@ function translator(minX, minY, maxX, maxY, width, height, top, left, bottom, ri const normalized = [normalize(x, minX, maxX), normalize(y, minY, maxY)]; const dataWidth = width - left - right; const dataHeight = height - top - bottom; - console.log('translator',{x, y, minX, maxX, minY, maxY, normalized, dataWidth, dataHeight, top, left, bottom, right}); return [normalized[0] * dataWidth + left, (((1 - normalized[1]) * dataHeight) + top)]; } } @@ -20,13 +19,33 @@ function colorFactory(i) { return `hsl(${hue}, 60%, 43%)`; } +class GraphDatasetSelector { + view(vnode) { + const { options, selectedIndex, onSelect } = vnode.attrs; + return (
+ +
) + } +} + class Graph { + oninit(vnode) { + vnode.state.selected = 0; + } + view(vnode) { const { title, width, height, margins, datasets} = {...Graph.defaults, ...vnode.attrs}; return (
+ {vnode.state.selected = i;}} selectedIndex={vnode.state.selected} options={datasets.map((v)=>(v.title))} /> {title && {title}} @@ -47,11 +66,16 @@ class Graph { const minY = props.minY ?? 0.95 * props.data.reduce((p,c) => Math.min(p, c[0]), props.data[0][(hasX ? 1 : 0)]); const maxY = props.maxY ?? 1.05 * props.data.reduce((prev, current) => Math.max(prev, hasX ? current[1] : current[0]), 0); const tx = translator(minX, minY, maxX, maxY, width, height, ...margins); + const isSelected = i == vnode.state.selected; + const datasetLabel = ( + + ); const points = props.data.map((datum) => tx(...datum)); - const line = ( v.join(',')).join(' ')} />) + const line = ( v.join(',')).join(' ')} />) const yLabels = (props.yLabels.map((label) => { + if (!isSelected) return null; const yPos = tx(0, label.position)[1]; return ( <> @@ -67,7 +91,23 @@ class Graph { ); })); - return [line, ...yLabels]; + const xLabels = (props.xLabels.map((label) => { + if (!isSelected) return null; + const xPos = tx(label.position, 0)[0]; + return ( + <> + {label.label} + {label.line && } + + ) + })) + return [datasetLabel, line, ...yLabels, ...xLabels]; })} diff --git a/frontend/src/views/HistoryView.js b/frontend/src/views/HistoryView.js index 331e8da..7f7f3a0 100644 --- a/frontend/src/views/HistoryView.js +++ b/frontend/src/views/HistoryView.js @@ -36,6 +36,11 @@ class HistoryView { { position: 20, label: '20'}, { position: 0, label: '0', line: true}, ], + xLabels: [ + { position: 0, label: '0'}, + { position: 3, label: '3', line: true}, + { position: 6, label: '6', line: true}, + ] }, { title: "Pressure",