Skip to content

Commit 673d627

Browse files
authored
fix(core, angular, react, vue, svelte): fix scatter graph data updates (#654)
1 parent d97ebe6 commit 673d627

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

Diff for: packages/core/src/components/graphs/scatter.ts

+17-28
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,30 @@ export class Scatter extends Component {
2727
// Grab container SVG
2828
const svg = this.getContainerSVG();
2929

30-
const groupedData = this.model.getGroupedData();
30+
const options = this.model.getOptions();
31+
const { groupMapsTo } = options.data;
32+
33+
const domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
34+
const rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
35+
const scatterData = this.model.getDisplayData().filter(d => d[rangeIdentifier] !== undefined && d[rangeIdentifier] !== null);
3136

3237
// Update data on dot groups
33-
const dotGroups = svg
34-
.selectAll("g.dots")
35-
.data(groupedData, (group) => group.name);
38+
const circles = svg
39+
.selectAll("circle.dot")
40+
.data(scatterData, (datum) => `${datum[groupMapsTo]}-${datum[domainIdentifier]}`);
3641

37-
// Remove dot groups that need to be removed
38-
dotGroups.exit().attr("opacity", 0).remove();
42+
// Remove circles that need to be removed
43+
circles.exit().attr("opacity", 0).remove();
3944

4045
// Add the dot groups that need to be introduced
41-
const dotGroupsEnter = dotGroups
46+
const enteringCircles = circles
4247
.enter()
43-
.append("g")
44-
.classed("dots", true)
45-
.attr("role", Roles.GROUP);
46-
47-
const rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
48-
// Update data on all circles
49-
const dots = dotGroupsEnter
50-
.merge(dotGroups)
51-
.selectAll("circle.dot")
52-
.data((group) =>
53-
group.data.filter(
54-
(datum) =>
55-
datum[rangeIdentifier] !== null &&
56-
datum[rangeIdentifier] !== undefined
57-
)
58-
);
59-
60-
// Add the circles that need to be introduced
61-
const dotsEnter = dots.enter().append("circle").attr("opacity", 0);
48+
.append("circle")
49+
.classed("dot", true)
50+
.attr("opacity", 0);
6251

6352
// Apply styling & position
64-
const circlesToStyle = dotsEnter.merge(dots);
53+
const circlesToStyle = enteringCircles.merge(circles);
6554
this.styleCircles(circlesToStyle, animate);
6655

6756
// Add event listeners to elements drawn
@@ -165,10 +154,10 @@ export class Scatter extends Component {
165154
filled
166155
)
167156
)
168-
.attr("cx", getXValue)
169157
.transition(
170158
transitions.getTransition("scatter-update-enter", animate)
171159
)
160+
.attr("cx", getXValue)
172161
.attr("cy", getYValue)
173162
.attr("r", options.points.radius)
174163
.attr("fill", (d) => {

0 commit comments

Comments
 (0)