@luxonis/depthai-pipeline-lib 1.15.0 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,20 @@ const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, head
18
18
  const [shouldFitAndResize, setShouldFitAndResize] = React.useState(false);
19
19
  const [openLegend, setOpenLegend] = React.useState(false);
20
20
  const pipelineState = React.useMemo(() => pipelineStateParsed, [pipelineStateParsed]);
21
+ const layoutSignature = React.useMemo(() => {
22
+ if (!pipeline) {
23
+ return '';
24
+ }
25
+ const nodeSignature = pipeline.nodes
26
+ .map((node) => `${node.id}:${node.parentId ?? ''}`)
27
+ .sort()
28
+ .join('|');
29
+ const edgeSignature = pipeline.edges
30
+ .map((edge) => `${edge.id}:${edge.source}:${edge.target}:${edge.sourceHandle ?? ''}:${edge.targetHandle ?? ''}:${edge.type ?? ''}`)
31
+ .sort()
32
+ .join('|');
33
+ return `${nodeSignature}__${edgeSignature}`;
34
+ }, [pipeline]);
21
35
  // biome-ignore lint/correctness/useExhaustiveDependencies: Intended
22
36
  React.useEffect(() => {
23
37
  void fitView();
@@ -25,34 +39,22 @@ const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, head
25
39
  }, [reactFlowWidth, reactFlowHeight]);
26
40
  const [nodes, setNodes, onNodesChange] = useNodesState([]);
27
41
  const [edges, setEdges] = useEdgesState([]);
42
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Layout should only rerun when graph structure changes
28
43
  React.useEffect(() => {
29
44
  if (!autoArrangeRef.current) {
30
45
  return;
31
46
  }
32
47
  const layouted = getLayoutedElements(pipeline?.nodes ?? [], pipeline?.edges ?? []);
33
- if (pipelineState) {
34
- const updatedNodes = updateNodesOnPipelineStateChange([...layouted.nodes], pipelineState);
35
- const adjustedNodes = adjustNodes([...updatedNodes], layouted.edges);
36
- setNodes([...adjustedNodes]);
37
- }
38
- else {
39
- const adjustedNodes = adjustNodes([...layouted.nodes], layouted.edges);
40
- setNodes([...adjustedNodes]);
41
- }
48
+ const adjustedNodes = adjustNodes([...layouted.nodes], layouted.edges);
49
+ setNodes([...adjustedNodes]);
42
50
  setEdges([...layouted.edges]);
43
51
  setShouldFitAndResize(true);
44
- }, [pipeline?.edges, pipeline?.nodes, setEdges, setNodes, pipelineState]);
52
+ }, [layoutSignature, setEdges, setNodes]);
45
53
  // biome-ignore lint/correctness/useExhaustiveDependencies: Intended
46
54
  React.useEffect(() => {
47
55
  if (pipelineState && nodes.length > 0) {
48
56
  const updatedNodes = updateNodesOnPipelineStateChange(nodes, pipelineState);
49
57
  setNodes([...updatedNodes]);
50
- if (!autoArrangeRef.current) {
51
- return;
52
- }
53
- else {
54
- setShouldFitAndResize(true);
55
- }
56
58
  }
57
59
  // eslint-disable-next-line react-hooks/exhaustive-deps
58
60
  }, [pipelineState]);
@@ -25,11 +25,14 @@ function nodeStateToState(state) {
25
25
  function formatIOStates(values) {
26
26
  let returnObj = {};
27
27
  for (const [key, value] of Object.entries(values)) {
28
+ const dotColor = isNaN(Number(value.state))
29
+ ? 'gray'
30
+ : nodeStateToDotColor(value.state);
28
31
  returnObj = {
29
32
  ...returnObj,
30
33
  [key]: {
31
34
  ...value,
32
- dotColor: value.state ? nodeStateToDotColor(value.state) : 'gray',
35
+ dotColor: dotColor,
33
36
  },
34
37
  };
35
38
  }
@@ -39,7 +42,10 @@ export function parsePipelineState(rawPayload) {
39
42
  const { nodeStates } = rawPayload;
40
43
  const parsedNodeStates = [];
41
44
  for (const [nodeId, nodeState] of nodeStates) {
42
- const state = nodeState?.state ? nodeStateToState(nodeState.state) : 'IDLE';
45
+ const parsedState = Number(nodeState?.state);
46
+ const state = isNaN(parsedState)
47
+ ? 'IDLE'
48
+ : nodeStateToState(parsedState);
43
49
  const currentNode = {
44
50
  id: nodeId,
45
51
  inputs: formatIOStates(nodeState.inputStates),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/depthai-pipeline-lib",
3
- "version": "1.15.0",
3
+ "version": "1.16.1",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/src/index.js",