Skip to content

Commit 88516ea

Browse files
committed
Transition fillcolor
1 parent cea9455 commit 88516ea

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/components/drawing/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ drawing.dashStyle = function(dash, lineWidth) {
157157
return dash;
158158
};
159159

160+
// Same as fillGroupStyle, except in this case the selection may be a transition
161+
drawing.singleFillStyle = function(sel) {
162+
var node = d3.select(sel.node());
163+
var data = node.data();
164+
var fillcolor = (((data[0] || [])[0] || {}).trace || {}).fillcolor;
165+
if(fillcolor) {
166+
sel.call(Color.fill, fillcolor);
167+
}
168+
};
169+
160170
drawing.fillGroupStyle = function(s) {
161171
s.style('stroke-width', 0)
162172
.each(function(d) {

src/traces/scatter/plot.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,12 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
340340
// For the sake of animations, wrap the points around so that
341341
// the points on the axes are the first two points. Otherwise
342342
// animations get a little crazy if the number of points changes.
343-
transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1));
343+
transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1))
344+
.call(Drawing.singleFillStyle);
344345
} else {
345346
// fill to self: just join the path to itself
346-
transition(ownFillEl3).attr('d', fullpath + 'Z');
347+
transition(ownFillEl3).attr('d', fullpath + 'Z')
348+
.call(Drawing.singleFillStyle);
347349
}
348350
}
349351
}
@@ -354,15 +356,17 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
354356
// contours, we just add the two paths closed on themselves.
355357
// This makes strange results if one path is *not* entirely
356358
// inside the other, but then that is a strange usage.
357-
transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z');
359+
transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z')
360+
.call(Drawing.singleFillStyle);
358361
}
359362
else {
360363
// tonextx/y: for now just connect endpoints with lines. This is
361364
// the correct behavior if the endpoints are at the same value of
362365
// y/x, but if they *aren't*, we should ideally do more complicated
363366
// things depending on whether the new endpoint projects onto the
364367
// existing curve or off the end of it
365-
transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z');
368+
transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z')
369+
.call(Drawing.singleFillStyle);
366370
}
367371
trace._polygons = trace._polygons.concat(prevPolygons);
368372
}

test/jasmine/tests/scatter_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,27 @@ describe('end-to-end scatter tests', function() {
437437
.catch(fail)
438438
.then(done);
439439
});
440+
441+
it('animates fillcolor', function(done) {
442+
function fill() {
443+
return d3.selectAll('.js-fill').node().style.fill;
444+
}
445+
446+
Plotly.plot(gd, [{
447+
x: [1, 2, 3, 4, 5, 6, 7],
448+
y: [2, 3, 4, 5, 6, 7, 8],
449+
fill: 'tozeroy',
450+
fillcolor: 'rgb(255, 0, 0)',
451+
}]).then(function() {
452+
expect(fill()).toEqual('rgb(255, 0, 0)');
453+
return Plotly.animate(gd,
454+
[{data: [{fillcolor: 'rgb(0, 0, 255)'}]}],
455+
{frame: {duration: 0, redraw: false}}
456+
);
457+
}).then(function() {
458+
expect(fill()).toEqual('rgb(0, 0, 255)');
459+
}).catch(fail).then(done);
460+
});
440461
});
441462

442463
describe('scatter hoverPoints', function() {

0 commit comments

Comments
 (0)