Skip to content

Commit 64ffa80

Browse files
committed
fix collapsed
1 parent c3f9fa2 commit 64ffa80

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

app/components/code-graph.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function CodeGraph({
261261
const type = "category" in element.data
262262

263263
if (element.data.expand) {
264-
deleteNeighbors([element.data], chart)
264+
deleteNeighbors([element.data] as Node[], chart)
265265
}
266266

267267
graph.Elements.splice(index, 1);
@@ -314,8 +314,6 @@ export function CodeGraph({
314314
deleteNeighbors([node], chart);
315315
}
316316

317-
const element = chart.elements(`#${node.id}`)
318-
element.data('expand', expand)
319317
graphNode.data.expand = expand
320318

321319
setSelectedObj(undefined)
@@ -342,20 +340,21 @@ export function CodeGraph({
342340
chart.add(elements);
343341
chart.elements().layout(LAYOUT).run();
344342
} else {
345-
const deleteNodes = nodes.filter(n => n.expand === true)
343+
const deleteNodes = graph.Elements.filter(n => n.data.expand === true && nodes.some(e => e.id === n.data.id))
344+
345+
debugger
346+
346347
if (deleteNodes.length > 0) {
347-
deleteNeighbors(deleteNodes, chart);
348+
deleteNeighbors(deleteNodes.map(n => n.data) as Node[], chart);
348349
chart.elements().layout(LAYOUT).run();
349350
}
350351
}
351352

352353
nodes.forEach((node) => {
353354
const graphNode = graph.Elements.find(e => e.data.id === node.id)
354-
const element = chart.elements(`#${node.id}`)
355355

356356
if (!graphNode) return
357357

358-
element.data("expand", expand)
359358
graphNode.data.expand = expand
360359
})
361360

@@ -479,11 +478,7 @@ export function CodeGraph({
479478
position={position}
480479
url={url}
481480
handelExpand={(nodes, expand) => {
482-
if (nodes && expand !== undefined) {
483-
handleExpand(nodes, expand)
484-
} else {
485-
handleDoubleTap()
486-
}
481+
handleExpand(nodes, expand)
487482
}}
488483
parentWidth={containerWidth}
489484
/>

app/components/elementMenu.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Props {
1414
handelRemove: (nodes: number[]) => void;
1515
position: Position | undefined;
1616
url: string;
17-
handelExpand: (nodes?: Node[], expand?: boolean) => void;
17+
handelExpand: (nodes: Node[], expand: boolean) => void;
1818
parentWidth: number;
1919
}
2020

@@ -114,13 +114,15 @@ export default function ElementMenu({ obj, objects, setPath, handelRemove, posit
114114
</button>
115115
<button
116116
className="p-2"
117-
onClick={() => handelExpand()}
117+
onClick={() => handelExpand([obj], true)}
118118
>
119-
{
120-
obj.expand ?
121-
<Minimize2 color="white" />
122-
: <Maximize2 color="white" />
123-
}
119+
<Maximize2 color="white" />
120+
</button>
121+
<button
122+
className="p-2"
123+
onClick={() => handelExpand([obj], false)}
124+
>
125+
<Minimize2 color="white" />
124126
</button>
125127
</>
126128
}

app/components/model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import twcolors from 'tailwindcss/colors'
22
import { Path } from '../page'
33

4+
export interface Element {
5+
data: Node | Edge,
6+
}
7+
48
export interface Category {
59
name: string,
610
index: number,
@@ -74,7 +78,7 @@ export class Graph {
7478
return this.categoriesMap;
7579
}
7680

77-
get Elements(): any[] {
81+
get Elements(): Element[] {
7882
return this.elements;
7983
}
8084

0 commit comments

Comments
 (0)