Skip to content

Commit b298ae2

Browse files
authored
Merge pull request #115 from tmr232/highlight-node-fail-quietly
Demo: Failing to highlight nodes doesn't hide the graph
2 parents 715a8d1 + 3b861c7 commit b298ae2

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/components/renderer.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,21 @@ export class Renderer {
7474
}
7575

7676
private highlightNode(svg: string, nodeId: string): string {
77-
const dom = svgFromString(svg);
78-
// We construct the SVG, so we know the node must exist.
79-
const node: G = dom.findOne(`g#${nodeId}`) as G;
80-
// Same applies to the polygon.
81-
82-
const poly: Polygon = node.findOne("polygon") as Polygon;
83-
// The highlight class is used when previewing colors in the demo.
84-
node.addClass("highlight");
85-
poly.fill(listToScheme(this.colorList)["node.highlight"]);
86-
return dom.svg();
77+
try {
78+
const dom = svgFromString(svg);
79+
// We construct the SVG, so we know the node must exist.
80+
const node: G = dom.findOne(`g#${nodeId}`) as G;
81+
// Same applies to the polygon.
82+
83+
const poly: Polygon = node.findOne("polygon") as Polygon;
84+
// The highlight class is used when previewing colors in the demo.
85+
node.addClass("highlight");
86+
poly.fill(listToScheme(this.colorList)["node.highlight"]);
87+
return dom.svg();
88+
} catch (e) {
89+
console.error(`Failed to highlight node ${nodeId}:`, e);
90+
return svg;
91+
}
8792
}
8893

8994
private renderStatic(functionSyntax: Parser.SyntaxNode, language: Language) {

0 commit comments

Comments
 (0)