Rework the toggles so we can hide the trend line from the loss graph. No need for a raw toggle either.

This commit is contained in:
Jaret Burkett
2026-06-08 13:56:37 -06:00
parent cac3815b2c
commit 0d018db689

View File

@@ -136,8 +136,7 @@ export default function JobLossGraph({ job }: Props) {
// Controls // Controls
const [useLogScale, setUseLogScale] = useState(false); const [useLogScale, setUseLogScale] = useState(false);
const [showRaw, setShowRaw] = useState(false); const [showTrend, setShowTrend] = useState(true);
const [showSmoothed, setShowSmoothed] = useState(true);
// 0..100 slider. 100 = no smoothing, 0 = heavy smoothing. // 0..100 slider. 100 = no smoothing, 0 = heavy smoothing.
const [smoothing, setSmoothing] = useState(80); const [smoothing, setSmoothing] = useState(80);
@@ -229,45 +228,34 @@ export default function JobLossGraph({ job }: Props) {
const fullSmooth = emaWithNulls(raw, fullAlpha); const fullSmooth = emaWithNulls(raw, fullAlpha);
const color = strokeForKey(key); const color = strokeForKey(key);
const colorFaded = color.replace('1)', '0.40)');
const colorDull = dulledColor(color); const colorDull = dulledColor(color);
const colArrays: (number | null)[][] = []; const colArrays: (number | null)[][] = [];
if (showRaw) { // Main series: smoothed by the slider (slider at 100% = raw), always shown.
data.push(raw); data.push(smooth);
seriesConfigs.push({
label: `${key} (raw)`,
scale: scaleKey,
stroke: colorFaded,
width: 1.25,
spanGaps: false,
points: { show: false },
});
colArrays.push(raw);
}
if (showSmoothed) {
data.push(smooth);
seriesConfigs.push({
label: key,
scale: scaleKey,
stroke: color,
width: 2,
spanGaps: false,
points: { show: false },
});
colArrays.push(smooth);
}
data.push(fullSmooth);
seriesConfigs.push({ seriesConfigs.push({
label: `${key} (trend)`, label: key,
scale: scaleKey, scale: scaleKey,
stroke: colorDull, stroke: color,
width: 2.5, width: 2,
spanGaps: false, spanGaps: false,
points: { show: false }, points: { show: false },
}); });
colArrays.push(fullSmooth); colArrays.push(smooth);
if (showTrend) {
data.push(fullSmooth);
seriesConfigs.push({
label: `${key} (trend)`,
scale: scaleKey,
stroke: colorDull,
width: 2.5,
spanGaps: false,
points: { show: false },
});
colArrays.push(fullSmooth);
}
scaleArrays[scaleKey] = colArrays; scaleArrays[scaleKey] = colArrays;
@@ -318,7 +306,7 @@ export default function JobLossGraph({ job }: Props) {
} }
return { data: data as uPlot.AlignedData, seriesConfigs, scales, axes, yClip }; return { data: data as uPlot.AlignedData, seriesConfigs, scales, axes, yClip };
}, [series, activeKeys, smoothing, plotStride, windowSize, useLogScale, showRaw, showSmoothed, clipOutliers]); }, [series, activeKeys, smoothing, plotStride, windowSize, useLogScale, showTrend, clipOutliers]);
// Layout wrapper we measure for sizing — uPlot collapses its own mount node // Layout wrapper we measure for sizing — uPlot collapses its own mount node
// to width:min-content, so we can't read sizes off it. // to width:min-content, so we can't read sizes off it.
@@ -342,8 +330,8 @@ export default function JobLossGraph({ job }: Props) {
// axis distribution changes. Data updates go through setData. // axis distribution changes. Data updates go through setData.
const hasData = (built.data[0]?.length ?? 0) > 1; const hasData = (built.data[0]?.length ?? 0) > 1;
const structuralKey = useMemo( const structuralKey = useMemo(
() => `${activeKeys.join('|')}|raw=${showRaw}|sm=${showSmoothed}|log=${useLogScale}|has=${hasData}`, () => `${activeKeys.join('|')}|trend=${showTrend}|log=${useLogScale}|has=${hasData}`,
[activeKeys, showRaw, showSmoothed, useLogScale, hasData], [activeKeys, showTrend, useLogScale, hasData],
); );
useEffect(() => { useEffect(() => {
@@ -508,8 +496,7 @@ export default function JobLossGraph({ job }: Props) {
<div className="bg-gray-950 border border-gray-800 rounded-lg p-3"> <div className="bg-gray-950 border border-gray-800 rounded-lg p-3">
<label className="block text-xs text-gray-400 mb-2">Display</label> <label className="block text-xs text-gray-400 mb-2">Display</label>
<div className="flex flex-wrap gap-2"> <div className="flex flex-wrap gap-2">
<ToggleButton checked={showSmoothed} onClick={() => setShowSmoothed(v => !v)} label="Smoothed" /> <ToggleButton checked={showTrend} onClick={() => setShowTrend(v => !v)} label="Trend" />
<ToggleButton checked={showRaw} onClick={() => setShowRaw(v => !v)} label="Raw" />
<ToggleButton checked={useLogScale} onClick={() => setUseLogScale(v => !v)} label="Log Y" /> <ToggleButton checked={useLogScale} onClick={() => setUseLogScale(v => !v)} label="Log Y" />
<ToggleButton checked={clipOutliers} onClick={() => setClipOutliers(v => !v)} label="Clip outliers" /> <ToggleButton checked={clipOutliers} onClick={() => setClipOutliers(v => !v)} label="Clip outliers" />
</div> </div>
@@ -555,7 +542,6 @@ export default function JobLossGraph({ job }: Props) {
value={smoothing} value={smoothing}
onChange={e => setSmoothing(Number(e.target.value))} onChange={e => setSmoothing(Number(e.target.value))}
className="w-full accent-blue-500" className="w-full accent-blue-500"
disabled={!showSmoothed}
/> />
</div> </div>