Skip to content
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

Always include the very first and last points for fills #3696

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
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
18 changes: 12 additions & 6 deletions src/traces/scatter/line_points.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ module.exports = function linePoints(d, opts) {
var baseTolerance = opts.baseTolerance;
var shape = opts.shape;
var linear = shape === 'linear';
var fill = opts.fill && opts.fill !== 'none';
var segments = [];
var minTolerance = constants.minTolerance;
var pts = new Array(d.length);
var len = d.length;
var pts = new Array(len);
var pti = 0;

var i;
Expand Down Expand Up @@ -160,8 +162,10 @@ module.exports = function linePoints(d, opts) {
var ptCount = 0;
for(var i = 0; i < 4; i++) {
var edge = edges[i];
var ptInt = segmentsIntersect(pt1[0], pt1[1], pt2[0], pt2[1],
edge[0], edge[1], edge[2], edge[3]);
var ptInt = segmentsIntersect(
pt1[0], pt1[1], pt2[0], pt2[1],
edge[0], edge[1], edge[2], edge[3]
);
if(ptInt && (!ptCount ||
Math.abs(ptInt.x - out[0][0]) > 1 ||
Math.abs(ptInt.y - out[0][1]) > 1
Expand Down Expand Up @@ -359,7 +363,7 @@ module.exports = function linePoints(d, opts) {
}

// loop over ALL points in this trace
for(i = 0; i < d.length; i++) {
for(i = 0; i < len; i++) {
clusterStartPt = getPt(i);
if(!clusterStartPt) continue;

Expand All @@ -368,7 +372,7 @@ module.exports = function linePoints(d, opts) {
addPt(clusterStartPt);

// loop over one segment of the trace
for(i++; i < d.length; i++) {
for(i++; i < len; i++) {
clusterHighPt = getPt(i);
if(!clusterHighPt) {
if(connectGaps) continue;
Expand All @@ -387,7 +391,9 @@ module.exports = function linePoints(d, opts) {

clusterRefDist = ptDist(clusterHighPt, clusterStartPt);

if(clusterRefDist < getTolerance(clusterHighPt, nextPt) * minTolerance) continue;
// #3147 - always include the very first and last points for fills
if(!(fill && (pti === 0 || pti === len - 1)) &&
clusterRefDist < getTolerance(clusterHighPt, nextPt) * minTolerance) continue;

clusterUnitVector = [
(clusterHighPt[0] - clusterStartPt[0]) / clusterRefDist,
Expand Down
3 changes: 2 additions & 1 deletion src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
connectGaps: trace.connectgaps,
baseTolerance: Math.max(line.width || 1, 3) / 4,
shape: line.shape,
simplify: line.simplify
simplify: line.simplify,
fill: trace.fill
});

// since we already have the pixel segments here, use them to make
Expand Down
Binary file added test/image/baselines/ultra_zoom_fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions test/image/mocks/ultra_zoom_fill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"data": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which looks like:

image

on master.

{
"name": 10000,
"fill": "toself",
"x": [ 1, 10, 10, 1 ],
"y": [ 10000, 10000, -10000, -10000 ]
},
{
"fill": "toself",
"name": 100,
"x": [ 1, 10, 10, 1 ],
"y": [ 100, 100, -100, -100 ]
}
],
"layout": {
"yaxis": {
"range": [ -0.5, 0.5 ]
}
}
}