Skip to content

Commit 6fc4a57

Browse files
authored
vis: tree display: add keys to data joins (#1513)
1 parent 2e10c85 commit 6fc4a57

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

packages/ott-vis-panel/src/components/TreeDisplay.tsx

+16-6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
241241
const tr = d3.transition().duration(1000).ease(d3.easeCubicInOut);
242242

243243
const balancerGroup = wholeGraph.select("g.balancers");
244+
// TODO: add key function to data join when balancer ids are stable
244245
const balancerCircles = balancerGroup.selectAll(".balancer").data(balancerNodes);
245246
balancerCircles
246247
.join(
@@ -261,7 +262,10 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
261262
.attr("cx", d => d.x)
262263
.attr("cy", d => d.y)
263264
.attr("r", NODE_RADIUS + 10);
264-
const balancerTexts = balancerGroup.selectAll(".balancer-text").data(balancerNodes);
265+
const balancerTexts = balancerGroup
266+
.selectAll(".balancer-text")
267+
// TODO: add key function to data join when balancer ids are stable
268+
.data(balancerNodes);
265269
balancerTexts
266270
.join(
267271
create =>
@@ -286,7 +290,9 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
286290

287291
// create groups for all the monoliths
288292
const monolithGroup = wholeGraph.select("g.monoliths");
289-
const monolithGroups = monolithGroup.selectAll("g.monolith").data(monolithNodes);
293+
const monolithGroups = monolithGroup
294+
.selectAll("g.monolith")
295+
.data(monolithNodes, (d: any) => d.id);
290296
// for debugging, draw the bounding boxes of the monolith trees
291297
if (DEBUG_BOUNDING_BOXES) {
292298
monolithGroups
@@ -310,7 +316,9 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
310316
.y((d: any) => d.y);
311317

312318
const monolith = d3.select(this);
313-
const monolithLinks = monolith.selectAll(".treelink").data(d.tree.links());
319+
const monolithLinks = monolith
320+
.selectAll(".treelink")
321+
.data(d.tree.links(), (d: any) => d.source?.data?.id + d.target?.data?.id);
314322
monolithLinks
315323
.join(
316324
create => create.append("path").attr("class", "treelink"),
@@ -327,7 +335,7 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
327335

328336
const monolithCircles = monolith
329337
.selectAll(".monolith")
330-
.data(d.tree.descendants());
338+
.data(d.tree.descendants(), (d: any) => d.data?.id);
331339
monolithCircles
332340
.join(
333341
create =>
@@ -350,7 +358,7 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
350358

351359
const monolithTexts = monolith
352360
.selectAll(".monolith-text")
353-
.data(d.tree.descendants());
361+
.data(d.tree.descendants(), (d: any) => d.data?.id);
354362
monolithTexts
355363
.join(
356364
create =>
@@ -391,7 +399,9 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({ systemState, width, height })
391399
};
392400
});
393401
});
394-
const balancerMonolithLinks = gb2mLinks.selectAll(".b2m-link").data(b2mLinkData);
402+
const balancerMonolithLinks = gb2mLinks
403+
.selectAll(".b2m-link")
404+
.data(b2mLinkData, (d: any) => d.source?.data?.id + d.target?.data?.id);
395405
balancerMonolithLinks
396406
.join(
397407
create =>

0 commit comments

Comments
 (0)