Skip to content

Commit 9a8c702

Browse files
committed
bar: add object constancy to transitions
1 parent 709ee2f commit 9a8c702

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/traces/bar/plot.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPo
3131
// padding in pixels around text
3232
var TEXTPAD = 3;
3333

34+
function keyFunc(d) {return d.id;}
35+
function getKeyFunc(trace) {
36+
if(trace.ids) {
37+
return keyFunc;
38+
}
39+
}
40+
3441
function dirSign(a, b) {
3542
return (a < b) ? 1 : -1;
3643
}
@@ -103,7 +110,8 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
103110

104111
var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
105112

106-
var bars = pointGroup.selectAll('g.point').data(Lib.identity);
113+
var keyFunc = getKeyFunc(trace);
114+
var bars = pointGroup.selectAll('g.point').data(Lib.identity, keyFunc);
107115

108116
bars.enter().append('g')
109117
.classed('point', true);

test/image/mocks/animation_bar.json

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "bar",
44
"x": ["A", "B", "C"],
55
"y": [24, 5, 8],
6+
"ids": ["A", "B", "C"],
67
"error_y": {"array": [3, 2, 1]}
78
}],
89
"layout": {
@@ -17,6 +18,7 @@
1718
{"data": [{"width": 0.25}]},
1819
{"data": [{"marker": {"line": {"width": 10}}}]},
1920
{"data": [{"marker": {"line": {"color": ["orange", "yellow", "blue"]}}}]},
21+
{"data": [{"ids": ["B", "C", "A"]}]},
2022
{"layout": {"yaxis": {"range": [0, 20]}}}
2123
]
2224
}

0 commit comments

Comments
 (0)