Skip to content

Transition fillcolor #1722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
@@ -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) {
12 changes: 8 additions & 4 deletions src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
@@ -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);
}
21 changes: 21 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
@@ -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() {