Skip to content

Commit 53e4bb5

Browse files
committed
Refactor
1 parent e625b8b commit 53e4bb5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib/graphs/highlighting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { HighlightedGraphState, TreeChartState } from '$lib/models/treechar
22
import { allSimplePaths } from 'graphology-simple-path';
33
import { edgePathFromNodePath } from 'graphology-shortest-path';
44
import type Graph from 'graphology';
5+
import { getGraphRootNode } from '$lib/graphs/utils';
56

67
export function isInterestingNode(treeChartState: TreeChartState, node: string): boolean {
78
if (!treeChartState.hovered.targetNode && !treeChartState.selected.targetNode) {
@@ -36,7 +37,7 @@ export function getHighlightedGraphState(graph?: Graph, node?: string) {
3637
if (node) {
3738
graphState.targetNode = node;
3839
if (graph) {
39-
const root = graph.nodes()[0];
40+
const root = getGraphRootNode(graph);
4041
const paths = allSimplePaths(graph, root, node);
4142
if (paths) {
4243
graphState.highlightedNodes = paths.reduce(

src/lib/graphs/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type Graph from 'graphology';
2+
import type { Attributes } from 'graphology-types';
3+
4+
export function getGraphRootNode(graph: Graph<Attributes, Attributes, Attributes>): string {
5+
return graph.nodes()[0];
6+
}

0 commit comments

Comments
 (0)