Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a004e40

Browse files
committed
fix bug where last contour fill sometimes covered everything
this would only happen if its line rounded away to nothing, because it only crossed the boundary an infinitesimal amount
1 parent 7ef3235 commit a004e40

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/traces/contour/find_all_paths.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ function makePath(pi, loc, edgeflag) {
8484
if(equalPts(pts[pts.length - 1], pts[pts.length - 2])) pts.pop();
8585
locStr = loc.join(',');
8686

87+
var atEdge = (marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) ||
88+
(marchStep[1] && (loc[1] < 0 || loc[1] > m - 2)),
89+
closedLoop = (locStr === startLocStr) && (marchStep.join(',') === startStepStr);
90+
91+
if(atEdge) pi.foundedge = true;
92+
8793
// have we completed a loop, or reached an edge?
88-
if((locStr === startLocStr && marchStep.join(',') === startStepStr) ||
89-
(edgeflag && (
90-
(marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) ||
91-
(marchStep[1] && (loc[1] < 0 || loc[1] > m - 2))))) {
92-
break;
93-
}
94+
if((closedLoop) || (edgeflag && atEdge)) break;
95+
9496
mi = pi.crossings[locStr];
9597
}
9698

src/traces/contour/plot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ function emptyPathinfo(contours, plotinfo, cd0) {
9393
// all unclosed paths (may have less items than starts,
9494
// if a path is closed by rounding)
9595
edgepaths: [],
96+
// we found some edges (even if they later got removed due to rounding)
97+
foundedge: false,
9698
// all closed paths
9799
paths: [],
98100
// store axes so we can convert to px
@@ -163,7 +165,7 @@ function makeFills(plotgroup, pathinfo, perimeter, contours) {
163165
}
164166

165167
function joinAllPaths(pi, perimeter) {
166-
var fullpath = (pi.edgepaths.length || pi.z[0][0] < pi.level) ?
168+
var fullpath = (pi.foundedge || pi.z[0][0] < pi.level) ?
167169
'' : ('M' + perimeter.join('L') + 'Z'),
168170
i = 0,
169171
startsleft = pi.edgepaths.map(function(v, i) { return i; }),

src/traces/contour/style.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ module.exports = function style(gd) {
4242
line.dash);
4343
});
4444

45-
c.selectAll('g.contourbg path')
46-
.style('fill', colorMap(start - cs / 2));
45+
var firstFill;
4746

4847
c.selectAll('g.contourfill path')
49-
.style('fill', function(d, i) {
50-
return colorMap(start + (i + 0.5) * cs);
48+
.style('fill', function(d) {
49+
if(firstFill === undefined) firstFill = d.level;
50+
return colorMap(d.level + 0.5 * cs);
5151
});
52+
53+
if(firstFill === undefined) firstFill = start;
54+
55+
c.selectAll('g.contourbg path')
56+
.style('fill', colorMap(firstFill - 0.5 * cs));
5257
});
5358

5459
heatmapStyle(gd);

0 commit comments

Comments
 (0)