Skip to content

Commit c9f436d

Browse files
committed
highleted nodes work on graph
1 parent 62b883c commit c9f436d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/feedback-components/src/feedback/edit-state.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export interface EntityOutput {
265265
match: any | null;
266266
reasoning: string | null;
267267
color: string | null;
268+
children: any[] | null;
268269
}
269270

270271
export interface GraphData {
@@ -285,7 +286,7 @@ export function treeToGraph(tree: TreeData[]): GraphData {
285286
continue;
286287
}
287288

288-
const { indices, id, name, type } = node;
289+
const { indices, id, name, type, children } = node;
289290

290291
const nodeData: EntityOutput = {
291292
id,
@@ -295,6 +296,7 @@ export function treeToGraph(tree: TreeData[]): GraphData {
295296
txt_range: [indices],
296297
reasoning: null,
297298
match: node.match,
299+
children
298300
};
299301

300302
nodeMap.set(node.id, node);

packages/feedback-components/src/feedback/graph.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { useEffect, useState } from "react";
1515
import { Spinner, Popover } from "@blueprintjs/core";
1616
import { ErrorBoundary } from "@macrostrat/ui-components";
17+
import { getTagStyle } from "../extractions";
1718

1819
export function GraphView(props: {
1920
tree: TreeData[];
@@ -92,22 +93,24 @@ export function GraphView(props: {
9293
h(
9394
"g.nodes",
9495
nodes.map((d) => {
95-
const isSelected = selectedNodes.includes(d.id);
96-
const stroke = isSelected ? "white" : "black";
96+
const active = selectedNodes.includes(d.id);
97+
const stroke = active ? "white" : "black";
98+
const highlighted = isHighlighted(d.id, selectedNodes, nodes);
99+
const style = getTagStyle(d.color, { highlighted, active });
97100

98101
return h("circle", {
99102
cx: d.x,
100103
cy: d.y,
101104
r: 5,
102-
fill: d.color || "blue",
105+
fill: style.backgroundColor || "blue",
103106
onClick: (e) => {
104107
e.stopPropagation();
105108
dispatch({
106109
type: "toggle-node-selected",
107110
payload: { ids: [d.id] },
108111
});
109112
},
110-
className: isSelected ? "selected" : "",
113+
className: active ? "selected" : "",
111114
stroke,
112115
strokeWidth: 2,
113116
},
@@ -122,3 +125,11 @@ export function GraphView(props: {
122125
])
123126
);
124127
}
128+
129+
function isHighlighted(id: number, selectedNodes: number[], nodes: TreeData[]) {
130+
if (selectedNodes.length === 0) return true;
131+
return (
132+
selectedNodes.includes(id) ||
133+
nodes.some((node) => selectedNodes.includes(node.id) && node.children.some((child) => child.id === id))
134+
);
135+
}

0 commit comments

Comments
 (0)