Skip to content

Commit a80fd16

Browse files
committed
Compatibility with focused view
1 parent 1cb0515 commit a80fd16

8 files changed

Lines changed: 165 additions & 126 deletions

File tree

client/src/pages/tree/Axis.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,17 @@ function AxisOverlay({
258258
y: yGraphScale(xAxisDataY),
259259
});
260260
const xAxisY = Math.min(xAxisYRaw, height - X_AXIS_HEIGHT);
261+
// Y axis line
262+
const { x: yAxisXRaw, y: yAxisStartY } = sigma.graphToViewport({
263+
x: xGraphScale(yAxisDataX),
264+
y: yGraphScale(yLo),
265+
});
266+
const yAxisX = Math.max(yAxisXRaw, Y_AXIS_WIDTH);
261267

268+
const { y: yAxisEndY } = sigma.graphToViewport({
269+
x: xGraphScale(yAxisDataX),
270+
y: yGraphScale(yHi),
271+
});
262272
const { x: xAxisEndX } = sigma.graphToViewport({
263273
x: xGraphScale(xHi),
264274
y: yGraphScale(xAxisDataY),
@@ -284,6 +294,13 @@ function AxisOverlay({
284294
ctx.lineTo(x, y + 6);
285295
ctx.stroke();
286296

297+
ctx.strokeStyle = alpha(theme.palette.divider, 0.15);
298+
ctx.setLineDash([2]);
299+
ctx.lineTo(x, yAxisEndY);
300+
ctx.stroke();
301+
ctx.strokeStyle = theme.palette.text.primary;
302+
ctx.setLineDash([]);
303+
287304
ctx.textAlign = "center";
288305
ctx.textBaseline = "top";
289306
ctx.fillText(label, x, y + 8);
@@ -293,18 +310,6 @@ function AxisOverlay({
293310
ctx.textBaseline = "bottom";
294311
ctx.fillText(xAxisLabel, (xAxisStartX + xAxisEndX) / 2, xAxisY + 40);
295312

296-
// Y axis line
297-
const { x: yAxisXRaw, y: yAxisStartY } = sigma.graphToViewport({
298-
x: xGraphScale(yAxisDataX),
299-
y: yGraphScale(yLo),
300-
});
301-
const yAxisX = Math.max(yAxisXRaw, Y_AXIS_WIDTH);
302-
303-
const { y: yAxisEndY } = sigma.graphToViewport({
304-
x: xGraphScale(yAxisDataX),
305-
y: yGraphScale(yHi),
306-
});
307-
308313
ctx.beginPath();
309314
ctx.moveTo(yAxisX, yAxisStartY);
310315
ctx.lineTo(yAxisX, yAxisEndY);
@@ -322,9 +327,17 @@ function AxisOverlay({
322327

323328
ctx.beginPath();
324329
ctx.moveTo(x, y);
330+
325331
ctx.lineTo(x - 6, y);
326332
ctx.stroke();
327333

334+
ctx.strokeStyle = alpha(theme.palette.divider, 0.15);
335+
ctx.setLineDash([2]);
336+
ctx.lineTo(xAxisEndX, y);
337+
ctx.stroke();
338+
ctx.strokeStyle = theme.palette.text.primary;
339+
ctx.setLineDash([]);
340+
328341
ctx.textAlign = "right";
329342
ctx.textBaseline = "middle";
330343
ctx.fillText(label, x - 8, y);

client/src/pages/tree/ScatterPlotGraph.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AxisOverlay, {
88
createSymlogScatterScale,
99
} from "./Axis";
1010
import { SharedGraphProps } from "./SharedGraphProps";
11-
import { TreeControls } from "./TreeGraph";
11+
import { FocusedView, TreeControls } from "./TreeGraph";
1212
import { getScatterPlotUniqueId, useComputePlot } from "./useComputePlot";
1313
import { useGraphColoring } from "./useGraphColoring";
1414
import { useHighlighting } from "./useHighlighting";
@@ -18,19 +18,22 @@ const getScatterPlotGraphId = (step: number, event: TraceEvent): string =>
1818
const getScatterPlotGraphPId = (step: number, event: TraceEvent): string =>
1919
getScatterPlotUniqueId(event.pId, step);
2020

21-
export function ScatterPlotGraph({
22-
width = 1,
23-
height = 1,
24-
logAxis,
25-
eventTypeFilter,
26-
step,
27-
trackedProperty,
28-
trace,
29-
layer,
30-
traceKey,
31-
xMetric,
32-
yMetric,
33-
}: ScatterPlotGraphProps & SharedGraphProps) {
21+
export function ScatterPlotGraph(
22+
props: ScatterPlotGraphProps & SharedGraphProps,
23+
) {
24+
const {
25+
width = 1,
26+
height = 1,
27+
logAxis,
28+
eventTypeFilter,
29+
step,
30+
trackedProperty,
31+
trace,
32+
layer,
33+
traceKey,
34+
xMetric,
35+
yMetric,
36+
} = props;
3437
const { data: plot } = useComputePlot({
3538
key: traceKey,
3639
trace: trace,
@@ -114,6 +117,7 @@ export function ScatterPlotGraph({
114117
layer={layer}
115118
isHighlightingEnabled={isHighlightingEnabled}
116119
/>
120+
<FocusedView {...props} />
117121
</>
118122
);
119123
}

client/src/pages/tree/SharedGraphProps.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type SharedGraphProps = {
99
trackedProperty?: string;
1010
width?: number;
1111
height?: number;
12+
onExit?: () => void;
1213
};

client/src/pages/tree/TreeGraph.tsx

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@ function Dot({ label, color }: { label?: ReactNode; color?: string }) {
9494

9595
export type TreeGraphProps = {
9696
tree?: TreeWorkerReturnType;
97-
onExit?: () => void;
9897
} & SharedGraphProps;
9998

10099
export type NodeType = { x: number; y: number; label: string; size: number };
101100
export type EdgeType = { label: string };
102101

103102
export function TreeGraph(props: TreeGraphProps) {
104-
const { trace, tree, layer: key, onExit } = props;
105-
106-
const acrylic = useAcrylic();
107-
const theme = useTheme();
103+
const { trace, tree, layer: key } = props;
108104

109105
const [orientation, setOrientation] =
110106
useState<keyof typeof orientationOptions>("vertical");
@@ -122,6 +118,29 @@ export function TreeGraph(props: TreeGraphProps) {
122118

123119
const isHighlightingEnabled = !isEmpty(highlightEdges);
124120

121+
return (
122+
<>
123+
<TreeControls
124+
layer={key}
125+
isHighlightingEnabled={isHighlightingEnabled}
126+
setOrientation={setOrientation}
127+
orientation={orientation}
128+
/>
129+
<FocusedView {...props} />
130+
</>
131+
);
132+
}
133+
134+
export function FocusedView(props: SharedGraphProps) {
135+
const { trace, layer: key, onExit } = props;
136+
137+
const acrylic = useAcrylic();
138+
const theme = useTheme();
139+
140+
const highlightEdges = useHighlighting(key);
141+
142+
const isHighlightingEnabled = !isEmpty(highlightEdges);
143+
125144
const bg = getShade(
126145
highlightNodesOptions.find(
127146
(highlight) => highlight.type === highlightEdges?.type,
@@ -134,76 +153,68 @@ export function TreeGraph(props: TreeGraphProps) {
134153
const event = trace?.events?.[highlightEdges?.step ?? 0];
135154

136155
return (
137-
<>
138-
<TreeControls
139-
layer={key}
140-
isHighlightingEnabled={isHighlightingEnabled}
141-
setOrientation={setOrientation}
142-
orientation={orientation}
143-
/>
156+
<Stack
157+
sx={{
158+
width: "100%",
159+
height: "100%",
160+
position: "absolute",
161+
top: 0,
162+
left: 0,
163+
pt: 6,
164+
pointerEvents: "none",
165+
}}
166+
>
144167
<Stack
145168
sx={{
146169
width: "100%",
147170
height: "100%",
148-
position: "absolute",
149-
top: 0,
150-
left: 0,
151-
pt: 6,
152-
pointerEvents: "none",
171+
border: isHighlightingEnabled ? `2px solid ${bg}` : "none",
172+
// The top bar has a 0.5px border, so the top border of the graph needs to be 0.5 pixels thicker
173+
borderTopWidth: "2.5px",
174+
transition: (t) => t.transitions.create("box-shadow"),
153175
}}
154176
>
155-
<Stack
156-
sx={{
157-
width: "100%",
158-
height: "100%",
159-
border: isHighlightingEnabled ? `2px solid ${bg}` : "none",
160-
// The top bar has a 0.5px border, so the top border of the graph needs to be 0.5 pixels thicker
161-
borderTopWidth: "2.5px",
162-
transition: (t) => t.transitions.create("box-shadow"),
163-
}}
164-
>
165-
{isHighlightingEnabled && (
166-
<Scroll x style={{ height: theme.spacing(5) }}>
167-
<Box
177+
{isHighlightingEnabled && (
178+
<Scroll x style={{ height: theme.spacing(5) }}>
179+
<Box
180+
sx={{
181+
...pick(acrylic, "backdropFilter"),
182+
transition: (t) => t.transitions.create("background-color"),
183+
pointerEvents: "all",
184+
alignItems: "center",
185+
p: 2,
186+
height: "100%",
187+
bgcolor: alpha(bg, 0.05) || "info.main",
188+
display: "flex",
189+
justifyContent: "space-between",
190+
minWidth: "max-content",
191+
gap: 2,
192+
}}
193+
>
194+
<Typography variant="overline">
195+
{startCase(highlightEdges?.type)}{" "}
196+
<Box sx={{ opacity: 0.7 }} component="span">
197+
<Dot color={getColorHex(event?.type)} />{" "}
198+
{startCase(event?.type)} {event?.id}
199+
{", "}
200+
Step {highlightEdges?.step}{" "}
201+
</Box>
202+
</Typography>
203+
<Button
204+
onClick={onExit}
205+
variant="outlined"
168206
sx={{
169-
...pick(acrylic, "backdropFilter"),
170-
transition: (t) => t.transitions.create("background-color"),
171-
pointerEvents: "all",
172-
alignItems: "center",
173-
p: 2,
174-
height: "100%",
175-
bgcolor: alpha(bg, 0.05) || "info.main",
176-
display: "flex",
177-
justifyContent: "space-between",
178-
minWidth: "max-content",
179-
gap: 2,
207+
mr: -1,
208+
height: theme.spacing(4),
180209
}}
181210
>
182-
<Typography variant="overline">
183-
{startCase(highlightEdges?.type)}{" "}
184-
<Box sx={{ opacity: 0.7 }} component="span">
185-
<Dot color={getColorHex(event?.type)} />{" "}
186-
{startCase(event?.type)} {event?.id}
187-
{", "}
188-
Step {highlightEdges?.step}{" "}
189-
</Box>
190-
</Typography>
191-
<Button
192-
onClick={onExit}
193-
variant="outlined"
194-
sx={{
195-
mr: -1,
196-
height: theme.spacing(4),
197-
}}
198-
>
199-
Exit focused view
200-
</Button>
201-
</Box>
202-
</Scroll>
203-
)}
204-
</Stack>
211+
Exit focused view
212+
</Button>
213+
</Box>
214+
</Scroll>
215+
)}
205216
</Stack>
206-
</>
217+
</Stack>
207218
);
208219
}
209220

client/src/pages/tree/index.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ export function TreePage({ template: Page }: PageContentProps) {
105105
step: throttled,
106106
layer: key,
107107
showAllEdges: layoutModes[mode].showAllEdges,
108+
onExit: () => {
109+
const layer = one.get();
110+
if (!isEmpty(layer?.source?.highlighting)) {
111+
one.set((l) => set(l, "source.highlighting", {}));
112+
}
113+
},
108114
};
109115
return (
110116
<>
@@ -123,20 +129,7 @@ export function TreePage({ template: Page }: PageContentProps) {
123129
>
124130
{mode !== "plot" ? (
125131
<>
126-
<TreeGraph
127-
{...sharedProps}
128-
tree={tree}
129-
onExit={() => {
130-
const layer = one.get();
131-
if (
132-
!isEmpty(layer?.source?.highlighting)
133-
) {
134-
one.set((l) =>
135-
set(l, "source.highlighting", {}),
136-
);
137-
}
138-
}}
139-
/>
132+
<TreeGraph {...sharedProps} tree={tree} />
140133
</>
141134
) : (
142135
<>

client/src/pages/tree/useComputePlot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function getScatterPlotUniqueId(
8080
logicalId: string | number | null | undefined,
8181
step: number,
8282
) {
83-
return `${logicalId}-${step}`;
83+
return `${logicalId} (Step ${step})`;
8484
}
8585

8686
export type Bounds = { xMin: number; xMax: number; yMin: number; yMax: number };

0 commit comments

Comments
 (0)