Skip to content

Commit 3082644

Browse files
authored
BUG: Ambiguous precedence of CSS selectors for SVG nodes/edges. (#915)
1 parent 6882158 commit 3082644

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

packages/frontend/src/stdlib/analyses/diagram_graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function diagramToGraphviz(
5757
attributes: {
5858
id,
5959
label: [label, overLabel].filter((s) => s).join(" : "),
60-
class: graphStyles.svgCssClasses(meta).join(" "),
60+
class: graphStyles.svgNodeCssClasses(meta).join(" "),
6161
fontname: graphStyles.graphvizFontname(meta),
6262
},
6363
});
@@ -79,7 +79,7 @@ export function diagramToGraphviz(
7979
attributes: {
8080
id,
8181
label: overLabel ?? "",
82-
class: graphStyles.svgCssClasses(meta).join(" "),
82+
class: graphStyles.svgEdgeCssClasses(meta).join(" "),
8383
fontname: graphStyles.graphvizFontname(meta),
8484
},
8585
});

packages/frontend/src/stdlib/analyses/model_graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function modelToGraphviz(
5454
attributes: {
5555
id,
5656
label: ob.label?.join(".") ?? "",
57-
class: graphStyles.svgCssClasses(meta).join(" "),
57+
class: graphStyles.svgNodeCssClasses(meta).join(" "),
5858
fontname: graphStyles.graphvizFontname(meta),
5959
},
6060
});
@@ -74,7 +74,7 @@ export function modelToGraphviz(
7474
attributes: {
7575
id,
7676
label,
77-
class: graphStyles.svgCssClasses(meta).join(" "),
77+
class: graphStyles.svgEdgeCssClasses(meta).join(" "),
7878
fontname: graphStyles.graphvizFontname(meta),
7979
// Not recognized by Graphviz but will be passed through!
8080
arrowstyle: meta?.arrowStyle ?? "default",

packages/frontend/src/stdlib/analyses/stock_flow_diagram.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ function StockFlowSVG(props: {
129129
return result;
130130
};
131131

132-
const linkClass = ["edge", svgStyles["link"]].join(" ");
133132
return (
134133
<svg
135134
ref={props.ref}
@@ -144,7 +143,7 @@ function StockFlowSVG(props: {
144143
<For each={props.layout?.edges ?? []}>{(edge) => <EdgeSVG edge={edge} />}</For>
145144
<For each={linkPaths()}>
146145
{(data) => (
147-
<g class={linkClass}>
146+
<g class={svgStyles["link"]}>
148147
<path marker-end={`url(#arrowhead-${linkMarker})`} d={data} />
149148
</g>
150149
)}

packages/frontend/src/stdlib/graph_styles.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ export const defaultEdgeAttributes: Required<Viz.Graph>["edgeAttributes"] = {
2828
export const graphvizFontname = (meta?: BaseTypeMeta): string =>
2929
meta?.textClasses?.includes(textStyles.code) ? "Courier" : "Helvetica";
3030

31-
// XXX: This should probably go somewhere else.
32-
export const svgCssClasses = (meta?: BaseTypeMeta): string[] => [
33-
...(meta?.svgClasses ?? []),
31+
/** CSS classes applied to a node in an SVG graph. */
32+
export const svgNodeCssClasses = (meta?: BaseTypeMeta): string[] => [
33+
...(meta?.svgClasses ?? ["node"]),
34+
...(meta?.textClasses ?? []),
35+
];
36+
37+
/** CSS classes applied to an edge in an SVG graph. */
38+
export const svgEdgeCssClasses = (meta?: BaseTypeMeta): string[] => [
39+
...(meta?.svgClasses ?? ["edge"]),
3440
...(meta?.textClasses ?? []),
3541
];

packages/frontend/src/stdlib/svg_styles.module.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
}
1313

1414
.link path {
15+
fill: none;
1516
stroke: blue;
17+
stroke-width: 1.2;
1618
}

packages/frontend/src/visualization/graph_svg.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function NodeSVG<Id>(props: { node: GraphLayout.Node<Id> }) {
4646
} = destructure(props, { deep: true });
4747

4848
return (
49-
<g class={`node ${props.node.cssClass ?? ""}`}>
49+
<g class={props.node.cssClass ?? "node"}>
5050
<rect x={x() - width() / 2} y={y() - height() / 2} width={width()} height={height()} />
5151
<Show when={props.node.label}>
5252
<text class="label" x={x()} y={y()} dominant-baseline="middle" text-anchor="middle">
@@ -89,7 +89,7 @@ export function EdgeSVG<Id>(props: { edge: GraphLayout.Edge<Id> }) {
8989
};
9090

9191
return (
92-
<g class={`edge ${props.edge.cssClass ?? ""}`}>
92+
<g class={props.edge.cssClass ?? "edge"}>
9393
<Switch fallback={defaultPath()}>
9494
<Match when={props.edge.style === "double"}>
9595
<path class="double-outer" d={path()} />

0 commit comments

Comments
 (0)