Skip to content

Commit

Permalink
Merge pull request #3696 from plotly/line-decimation-fill-fix
Browse files Browse the repository at this point in the history
Always include the very first and last points for fills
  • Loading branch information
etpinard authored Apr 1, 2019
2 parents 189ad5d + 9e8c3e9 commit 6ebffbd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
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 @@ -224,7 +224,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": [
{
"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 ]
}
}
}

0 comments on commit 6ebffbd

Please sign in to comment.