Data: a filter of the targets shown on the plots; Images: the names checked by default
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a862758fb
commit
9dcd31687c
2 files changed
+32
-8
No files matched your search
@@ -45,9 +45,10 @@ export default function Data({ selection, choose, analysis, setAnalysis }) {
|
|||||||
// all; otherwise the detectors run again without the others)
|
// all; otherwise the detectors run again without the others)
|
||||||
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 { station, start, end } = selection;
|
const { station, start, end } = selection;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setData(null); setTargets("");
|
setData(null); setTargets(""); setHidden([]);
|
||||||
if (!station) return;
|
if (!station) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
call(`/api/curves?${new URLSearchParams({ station, start, end })}`).then(d => { setData(d); setLoading(false); });
|
call(`/api/curves?${new URLSearchParams({ station, start, end })}`).then(d => { setData(d); setLoading(false); });
|
||||||
@@ -66,8 +67,9 @@ export default function Data({ selection, choose, analysis, setAnalysis }) {
|
|||||||
</div>
|
</div>
|
||||||
<Selector selection={selection} choose={choose} />
|
<Selector selection={selection} choose={choose} />
|
||||||
{loading && <Loader />}
|
{loading && <Loader />}
|
||||||
|
{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}
|
source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden}
|
||||||
analysis={analysis} setAnalysis={setAnalysis} />}
|
analysis={analysis} setAnalysis={setAnalysis} />}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -85,6 +87,28 @@ export default function Data({ selection, choose, analysis, setAnalysis }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The targets shown on the plots, at once; the others are removed from them, not from the detectors
|
||||||
|
function TargetFilter({ d, hidden, setHidden }) {
|
||||||
|
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));
|
||||||
|
return (
|
||||||
|
<Card shadow="sm" withBorder>
|
||||||
|
<Stack gap="sm">
|
||||||
|
<Checkbox.Group label="Targets shown on the plots" value={sensors.filter(s => !hidden.includes(s))}
|
||||||
|
onChange={v => setHidden(sensors.filter(s => !v.includes(s)))}>
|
||||||
|
<Group gap="md" mt={6}>
|
||||||
|
{sensors.map(c => <Checkbox key={c} size="xs" value={c} label={c + (refs.has(c) ? " (ref.)" : "")} />)}
|
||||||
|
</Group>
|
||||||
|
</Checkbox.Group>
|
||||||
|
<Group gap="sm">
|
||||||
|
<Button size="xs" variant="default" onClick={() => setHidden(hidden.length ? [] : sensors)}>
|
||||||
|
{hidden.length ? "Show all" : "Hide all"}</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 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 }) {
|
||||||
@@ -131,7 +155,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: the folder of the analysis shown, held by App (the sidebar opens one)
|
// analysis: the folder of the analysis shown, held by App (the sidebar opens one)
|
||||||
function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, analysis, setAnalysis }) {
|
function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, analysis, setAnalysis }) {
|
||||||
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; };
|
||||||
const [Plotly, setPlotly] = useState(null), [ready, setReady] = useState(false);
|
const [Plotly, setPlotly] = useState(null), [ready, setReady] = useState(false);
|
||||||
@@ -150,7 +174,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, 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), 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)); }, []);
|
||||||
|
|
||||||
@@ -214,11 +238,11 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawFig(g, m) {
|
function drawFig(g, m) {
|
||||||
const p = PLOTS[m], { c } = 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.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 }, x: T[t.t], y: t.y, 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(),
|
||||||
@@ -299,7 +323,7 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
|
|||||||
// Drag on the bar: select a range (Analysis), otherwise zoom in time
|
// Drag on the bar: select a range (Analysis), otherwise zoom in time
|
||||||
useEffect(() => { if (ready) Plotly.relayout(bar.current, { dragmode: readOnly ? "zoom" : "select", selections: [] }); }, [ready, readOnly]);
|
useEffect(() => { if (ready) Plotly.relayout(bar.current, { dragmode: readOnly ? "zoom" : "select", selections: [] }); }, [ready, readOnly]);
|
||||||
useEffect(() => { if (ready) drawPlots(true).then(drawBar); }, [dark]);
|
useEffect(() => { if (ready) drawPlots(true).then(drawBar); }, [dark]);
|
||||||
useEffect(() => { if (ready) drawPlots(true); }, [shown]);
|
useEffect(() => { if (ready) drawPlots(true); }, [shown, hidden]);
|
||||||
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;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function Viewer({ station, d, compact, wide, toggle, moment }) {
|
|||||||
<Group gap="lg" justify="space-between">
|
<Group gap="lg" justify="space-between">
|
||||||
<Text ref={r.time} ff="monospace" size="sm" />
|
<Text ref={r.time} ff="monospace" size="sm" />
|
||||||
<Group gap="md">
|
<Group gap="md">
|
||||||
<label className="check"><input type="checkbox" ref={r.names} disabled={!withPositions} /> Names</label>
|
<label className="check"><input type="checkbox" ref={r.names} disabled={!withPositions} defaultChecked={withPositions} /> Names</label>
|
||||||
{withPositions
|
{withPositions
|
||||||
? <span className="legend"><span className="target">○ Target</span> <span className="ref">◌ Reference</span></span>
|
? <span className="legend"><span className="target">○ Target</span> <span className="ref">◌ Reference</span></span>
|
||||||
: <Text size="sm" c="dimmed">x, y are not positions in the image on this station</Text>}
|
: <Text size="sm" c="dimmed">x, y are not positions in the image on this station</Text>}
|
||||||
|
|||||||
Reference in new issue
Block a user