Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 66a8abf

Browse files
committedMay 24, 2017
Transition fillcolor
Conflicts: test/jasmine/tests/scatter_test.js
1 parent 6cc5ffd commit 66a8abf

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed
 

‎src/components/drawing/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ drawing.dashStyle = function(dash, lineWidth) {
156156
return dash;
157157
};
158158

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

‎src/traces/scatter/plot.js

+8-4
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

+21
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,27 @@ describe('end-to-end scatter tests', function() {
575575
.catch(fail)
576576
.then(done);
577577
});
578+
579+
it('animates fillcolor', function(done) {
580+
function fill() {
581+
return d3.selectAll('.js-fill').node().style.fill;
582+
}
583+
584+
Plotly.plot(gd, [{
585+
x: [1, 2, 3, 4, 5, 6, 7],
586+
y: [2, 3, 4, 5, 6, 7, 8],
587+
fill: 'tozeroy',
588+
fillcolor: 'rgb(255, 0, 0)',
589+
}]).then(function() {
590+
expect(fill()).toEqual('rgb(255, 0, 0)');
591+
return Plotly.animate(gd,
592+
[{data: [{fillcolor: 'rgb(0, 0, 255)'}]}],
593+
{frame: {duration: 0, redraw: false}}
594+
);
595+
}).then(function() {
596+
expect(fill()).toEqual('rgb(0, 0, 255)');
597+
}).catch(fail).then(done);
598+
});
578599
});
579600

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

0 commit comments

Comments
 (0)
Please sign in to comment.