Skip to content

Commit

Permalink
Merge pull request #1722 from plotly/fillcolor-animation
Browse files Browse the repository at this point in the history
Transition fillcolor
  • Loading branch information
rreusser authored May 25, 2017
2 parents 122ec6d + 96b4e31 commit 0daf073
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ drawing.dashStyle = function(dash, lineWidth) {
return dash;
};

// Same as fillGroupStyle, except in this case the selection may be a transition
drawing.singleFillStyle = function(sel) {
var node = d3.select(sel.node());
var data = node.data();
var fillcolor = (((data[0] || [])[0] || {}).trace || {}).fillcolor;
if(fillcolor) {
sel.call(Color.fill, fillcolor);
}
};

drawing.fillGroupStyle = function(s) {
s.style('stroke-width', 0)
.each(function(d) {
Expand Down
12 changes: 8 additions & 4 deletions src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,12 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
// For the sake of animations, wrap the points around so that
// the points on the axes are the first two points. Otherwise
// animations get a little crazy if the number of points changes.
transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1));
transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1))
.call(Drawing.singleFillStyle);
} else {
// fill to self: just join the path to itself
transition(ownFillEl3).attr('d', fullpath + 'Z');
transition(ownFillEl3).attr('d', fullpath + 'Z')
.call(Drawing.singleFillStyle);
}
}
}
Expand All @@ -354,15 +356,17 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
// contours, we just add the two paths closed on themselves.
// This makes strange results if one path is *not* entirely
// inside the other, but then that is a strange usage.
transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z');
transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z')
.call(Drawing.singleFillStyle);
}
else {
// tonextx/y: for now just connect endpoints with lines. This is
// the correct behavior if the endpoints are at the same value of
// y/x, but if they *aren't*, we should ideally do more complicated
// things depending on whether the new endpoint projects onto the
// existing curve or off the end of it
transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z');
transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z')
.call(Drawing.singleFillStyle);
}
trace._polygons = trace._polygons.concat(prevPolygons);
}
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,27 @@ describe('end-to-end scatter tests', function() {
.catch(fail)
.then(done);
});

it('animates fillcolor', function(done) {
function fill() {
return d3.selectAll('.js-fill').node().style.fill;
}

Plotly.plot(gd, [{
x: [1, 2, 3, 4, 5, 6, 7],
y: [2, 3, 4, 5, 6, 7, 8],
fill: 'tozeroy',
fillcolor: 'rgb(255, 0, 0)',
}]).then(function() {
expect(fill()).toEqual('rgb(255, 0, 0)');
return Plotly.animate(gd,
[{data: [{fillcolor: 'rgb(0, 0, 255)'}]}],
{frame: {duration: 0, redraw: false}}
);
}).then(function() {
expect(fill()).toEqual('rgb(0, 0, 255)');
}).catch(fail).then(done);
});
});

describe('scatter hoverPoints', function() {
Expand Down

0 comments on commit 0daf073

Please sign in to comment.