Skip to content

Commit

Permalink
fix: Graph > 데이터가 없을 때 삭제되지 않는 문제
Browse files Browse the repository at this point in the history
  • Loading branch information
YuHyun-P committed Dec 7, 2023
1 parent 622c38c commit 4545e4b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/frontend/src/components/graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ type AddedLineType = {
};

function renderD3(svgRef: RefObject<SVGGElement>, data: InitialDataProps[]) {
if (!data.length) {
return;
}

const { parsedData, additionalLinks } = parsingMultipleParents(data);
const addedLine: AddedLineType[] = [];

// Select the root of the tree and bind the data
const svg = d3.select(svgRef.current);

if (!parsedData.length) {
svg.select("#text").selectAll("*").remove();
svg.select("#link").selectAll("*").remove();
svg.select("#node").selectAll("*").remove();
return;
}

// Stratify the data
const stratify = d3
.stratify<InitialDataProps>()
.parentId((d) => d.parentId)
.id((d) => d.id);

const rootNode = stratify(parsedData);

// Create a tree layout
Expand All @@ -38,9 +45,6 @@ function renderD3(svgRef: RefObject<SVGGElement>, data: InitialDataProps[]) {
const treeData = treeLayout(rootNode);
fillColor(treeData);

// Select the root of the tree and bind the data
const svg = d3.select(svgRef.current);

// Add text next to each node
svg
.select("#text")
Expand Down

0 comments on commit 4545e4b

Please sign in to comment.