Data: remove the points under a label of the checked families, the curves joined over the holes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 17:14:38 +01:00
1 parent 0e6e671caa
commit 0db5775e97
1 file changed
+19 -7
+19 -7
View File
@@ -50,6 +50,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
const [source, setSource] = useState("detectors"), [families, setFamilies] = useState(DETECTED), [targets, setTargets] = useState(""); const [source, setSource] = useState("detectors"), [families, setFamilies] = useState(DETECTED), [targets, setTargets] = useState("");
const [focus, setFocus] = useState(false); // with an event open, the plots show only its sensors const [focus, setFocus] = useState(false); // with an event open, the plots show only its sensors
const [hidden, setHidden] = useState([]); // the targets removed from the plots (the detectors still read them) const [hidden, setHidden] = useState([]); // the targets removed from the plots (the detectors still read them)
const [cut, setCut] = useState(false); // the points under a label of the checked families removed, the curves joined
const { station, start, end } = selection; const { station, start, end } = selection;
useEffect(() => { useEffect(() => {
setData(null); setTargets(""); setHidden([]); setData(null); setTargets(""); setHidden([]);
@@ -74,7 +75,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
{loading && <Loader />} {loading && <Loader />}
{data && <TargetFilter d={data} hidden={hidden} setHidden={setHidden} />} {data && <TargetFilter d={data} hidden={hidden} setHidden={setHidden} />}
{data && <Curves key={`${station}${start}${end}`} selection={selection} d={data} setImage={(t, nearest) => setMoment({ t, nearest })} {data && <Curves key={`${station}${start}${end}`} selection={selection} d={data} setImage={(t, nearest) => setMoment({ t, nearest })}
source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} cut={cut}
analysis={analysis} setAnalysis={setAnalysis} support={support} setSupport={setSupport} />} analysis={analysis} setAnalysis={setAnalysis} support={support} setSupport={setSupport} />}
</Stack> </Stack>
</Grid.Col> </Grid.Col>
@@ -84,7 +85,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
<StationImages selection={selection} compact wide={wide} toggle={() => setWide(!wide)} moment={moment} /> <StationImages selection={selection} compact wide={wide} toggle={() => setWide(!wide)} moment={moment} />
{data && <Settings key={`${station}${start}${end}`} d={data} families={families} setFamilies={setFamilies} {data && <Settings key={`${station}${start}${end}`} d={data} families={families} setFamilies={setFamilies}
targets={targets} setTargets={setTargets} detect={source === "detectors"} targets={targets} setTargets={setTargets} detect={source === "detectors"}
focus={focus} setFocus={setFocus} />} focus={focus} setFocus={setFocus} cut={cut} setCut={setCut} />}
</Stack> </Stack>
</div> </div>
</Grid.Col> </Grid.Col>
@@ -116,7 +117,7 @@ function TargetFilter({ d, hidden, setHidden }) {
// The families apply at once (filter of the page, Detectors and LLM); the targets, with the button: each set of targets // The families apply at once (filter of the page, Detectors and LLM); the targets, with the button: each set of targets
// runs the detectors again (the LLM labels do not state their sensors: they do not filter them) // runs the detectors again (the LLM labels do not state their sensors: they do not filter them)
function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus }) { function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus, cut, setCut }) {
const sensors = Object.keys(d.T).filter(k => k && !k.startsWith("system:")); const sensors = Object.keys(d.T).filter(k => k && !k.startsWith("system:"));
const refs = new Set(d.plots.flatMap(p => p.traces).filter(t => t.name.endsWith(" (ref.)")).map(t => t.t)); const refs = new Set(d.plots.flatMap(p => p.traces).filter(t => t.name.endsWith(" (ref.)")).map(t => t.t));
const [checked, setChecked] = useState(targets ? targets.split(",") : sensors); const [checked, setChecked] = useState(targets ? targets.split(",") : sensors);
@@ -127,6 +128,8 @@ function Settings({ d, families, setFamilies, targets, setTargets, detect, focus
<Title order={5}>Diagnostic settings</Title> <Title order={5}>Diagnostic settings</Title>
<Switch label="Focus on event curves" description="With an event open, the plots show only its sensors" <Switch label="Focus on event curves" description="With an event open, the plots show only its sensors"
checked={focus} onChange={e => setFocus(e.currentTarget.checked)} /> checked={focus} onChange={e => setFocus(e.currentTarget.checked)} />
<Switch label="Remove labeled points" description="The points under a label of the families shown leave the plots; the curves join over the holes"
checked={cut} onChange={e => setCut(e.currentTarget.checked)} />
<Checkbox.Group label="Families shown" value={families} onChange={setFamilies}> <Checkbox.Group label="Families shown" value={families} onChange={setFamilies}>
<SimpleGrid cols={2} spacing={6} verticalSpacing={6} mt={6}> <SimpleGrid cols={2} spacing={6} verticalSpacing={6} mt={6}>
{DETECTED.map(f => <Checkbox key={f} size="xs" value={f} label={f} color={FAMILIES[f]} iconColor="#1a1b1e" />)} {DETECTED.map(f => <Checkbox key={f} size="xs" value={f} label={f} color={FAMILIES[f]} iconColor="#1a1b1e" />)}
@@ -160,7 +163,7 @@ const mentions = (text, s) => new RegExp(`(^|[^\\w])${s.replace(/[^\w]/g, "\\$&"
const sensorsOf = (l, names) => l.sensors ?? names.filter(s => mentions(l.description, s)); const sensorsOf = (l, names) => l.sensors ?? names.filter(s => mentions(l.description, s));
// analysis, support: the folder of the analysis, of the support request shown, held by App (the sidebar opens one) // analysis, support: the folder of the analysis, of the support request shown, held by App (the sidebar opens one)
function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, analysis, setAnalysis, function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, cut, analysis, setAnalysis,
support, setSupport }) { support, setSupport }) {
const { A, B, T, plots: PLOTS } = d; const { A, B, T, plots: PLOTS } = d;
const plotIndex = (title, otherwise) => { const i = PLOTS.findIndex(p => p.title === title); return i < 0 ? otherwise : i; }; const plotIndex = (title, otherwise) => { const i = PLOTS.findIndex(p => p.title === title); return i < 0 ? otherwise : i; };
@@ -181,7 +184,7 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
// the focus: the sensors of the open event (none: all, as for No data); shown, their key // the focus: the sensors of the open event (none: all, as for No data); shown, their key
const names = useMemo(() => Object.keys(T).filter(k => k && !k.startsWith("system:")), [T]); const names = useMemo(() => Object.keys(T).filter(k => k && !k.startsWith("system:")), [T]);
const kept = focus && opened ? sensorsOf(opened, names) : [], shown = kept.join(","); const kept = focus && opened ? sensorsOf(opened, names) : [], shown = kept.join(",");
current.current = { views, labels, choice, opened, open, kept: new Set(kept), shown, hidden: new Set(hidden), c: THEMES[dark ? "dark" : "light"] }; // what the Plotly events read current.current = { views, labels, choice, opened, open, kept: new Set(kept), shown, hidden: new Set(hidden), cut, c: THEMES[dark ? "dark" : "light"] }; // what the Plotly events read
useEffect(() => { import("plotly.js-dist-min").then(m => setPlotly(() => m.default)); }, []); useEffect(() => { import("plotly.js-dist-min").then(m => setPlotly(() => m.default)); }, []);
@@ -244,12 +247,21 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
return { visible: kept.has(t.t) ? true : "legendonly", uirevision: shown }; return { visible: kept.has(t.t) ? true : "legendonly", uirevision: shown };
} }
// The points of a trace, without those under a label of the checked families when cut (no family or None: kept)
function points(t) {
const { cut, labels } = current.current, x = T[t.t];
const under = cut ? labels.filter(l => DETECTED.includes(l.family)).map(l => [readable(l.start), readable(l.end)]) : [];
if (!under.length) return { x, y: t.y };
const keep = x.map(v => !under.some(([a, b]) => a <= v && v < b));
return { x: x.filter((_, i) => keep[i]), y: t.y.filter((_, i) => keep[i]) };
}
function drawFig(g, m) { function drawFig(g, m) {
const p = PLOTS[m], { c, hidden } = current.current, b = bar.current?._fullLayout; const p = PLOTS[m], { c, hidden } = current.current, b = bar.current?._fullLayout;
g.style.height = `${HEIGHT}px`; // responsive: Plotly takes the height of the div again at each restyle, it needs one g.style.height = `${HEIGHT}px`; // responsive: Plotly takes the height of the div again at each restyle, it needs one
// uirevision: the zoom and the hidden sensors stay when the plot changes; the y axis, specific to each plot, refits. // uirevision: the zoom and the hidden sensors stay when the plot changes; the y axis, specific to each plot, refits.
// A new plot takes the range already shown. t: the room for the plot menu (left) and the toolbar (right). // A new plot takes the range already shown. t: the room for the plot menu (left) and the toolbar (right).
return Plotly.react(g, p.traces.filter(t => !hidden.has(t.t)).map(t => ({ type: "scatter", mode: t.mode || "lines", marker: { size: 4 }, x: T[t.t], y: t.y, name: t.name, return Plotly.react(g, p.traces.filter(t => !hidden.has(t.t)).map(t => ({ type: "scatter", mode: t.mode || "lines", marker: { size: 4 }, ...points(t), name: t.name,
uid: t.name.replace(/\W/g, "_"), line: t.line, ...focusTrace(t), uid: t.name.replace(/\W/g, "_"), line: t.line, ...focusTrace(t),
hovertemplate: `${t.name}: %{y}<br>%{x|%Y-%m-%d %H:%M} UTC<extra></extra>` })), hovertemplate: `${t.name}: %{y}<br>%{x|%Y-%m-%d %H:%M} UTC<extra></extra>` })),
{ ...skin(c), height: HEIGHT, hovermode: "closest", margin: { ...margin(), t: 42, b: 36 }, uirevision: 1, shapes: zones(), { ...skin(c), height: HEIGHT, hovermode: "closest", margin: { ...margin(), t: 42, b: 36 }, uirevision: 1, shapes: zones(),
@@ -330,7 +342,7 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
// Drag on the bar: select a range (Analysis, Support), otherwise zoom in time // Drag on the bar: select a range (Analysis, Support), otherwise zoom in time
useEffect(() => { if (ready) Plotly.relayout(bar.current, { dragmode: select ? "select" : "zoom", selections: [] }); }, [ready, select]); useEffect(() => { if (ready) Plotly.relayout(bar.current, { dragmode: select ? "select" : "zoom", selections: [] }); }, [ready, select]);
useEffect(() => { if (ready) drawPlots(true).then(drawBar); }, [dark]); useEffect(() => { if (ready) drawPlots(true).then(drawBar); }, [dark]);
useEffect(() => { if (ready) drawPlots(true); }, [shown, hidden]); useEffect(() => { if (ready) drawPlots(true); }, [shown, hidden, cut, cut && labels]);
useEffect(() => { if (ready) plotDivs().forEach(g => Plotly.relayout(g, { shapes: zones() })); }, [ready, labels, choice, opened]); useEffect(() => { if (ready) plotDivs().forEach(g => Plotly.relayout(g, { shapes: zones() })); }, [ready, labels, choice, opened]);
useEffect(() => { useEffect(() => {
if (!ready || !bar.current._fullLayout) return; if (!ready || !bar.current._fullLayout) return;