diff --git a/src/traces/scatter/line_points.js b/src/traces/scatter/line_points.js index d399965acf8..0c65cdee26b 100644 --- a/src/traces/scatter/line_points.js +++ b/src/traces/scatter/line_points.js @@ -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; @@ -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 @@ -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; @@ -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; @@ -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, diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index c10567bd30b..6666550fd27 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -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 diff --git a/test/image/baselines/ultra_zoom_fill.png b/test/image/baselines/ultra_zoom_fill.png new file mode 100644 index 00000000000..700e55552fa Binary files /dev/null and b/test/image/baselines/ultra_zoom_fill.png differ diff --git a/test/image/mocks/ultra_zoom_fill.json b/test/image/mocks/ultra_zoom_fill.json new file mode 100644 index 00000000000..f5100f0e70b --- /dev/null +++ b/test/image/mocks/ultra_zoom_fill.json @@ -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 ] + } + } +}