Skip to content

Commit e1caa9e

Browse files
committed
unify contour.style and contourcarpet.style
this makes contours.coloring='lines' work with carpet also fixes some unusual bugs like if the first contour is not shown that were fixed long ago for contour
1 parent b0f9bb2 commit e1caa9e

File tree

3 files changed

+22
-75
lines changed

3 files changed

+22
-75
lines changed

src/traces/contour/style.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ module.exports = function style(gd) {
3131
var line = trace.line;
3232
var cs = contours.size || 1;
3333
var start = contours.start;
34-
var colorLines = contours.coloring === 'lines';
3534

36-
var colorMap = makeColorMap(trace);
35+
// for contourcarpet only - is this a constraint-type contour trace?
36+
var isConstraintType = contours.type === 'constraint';
37+
var colorLines = !isConstraintType && contours.coloring === 'lines';
38+
var colorFills = !isConstraintType && contours.coloring === 'fill';
39+
40+
var colorMap = isConstraintType ? null : makeColorMap(trace);
3741

3842
c.selectAll('g.contourlevel').each(function(d) {
3943
d3.select(this).selectAll('path')
@@ -52,18 +56,24 @@ module.exports = function style(gd) {
5256
});
5357
});
5458

55-
var firstFill;
59+
if(isConstraintType) {
60+
c.selectAll('g.contourfill path')
61+
.style('fill', trace.fillcolor);
62+
}
63+
else if(colorFills) {
64+
var firstFill;
5665

57-
c.selectAll('g.contourfill path')
58-
.style('fill', function(d) {
59-
if(firstFill === undefined) firstFill = d.level;
60-
return colorMap(d.level + 0.5 * cs);
61-
});
66+
c.selectAll('g.contourfill path')
67+
.style('fill', function(d) {
68+
if(firstFill === undefined) firstFill = d.level;
69+
return colorMap(d.level + 0.5 * cs);
70+
});
6271

63-
if(firstFill === undefined) firstFill = start;
72+
if(firstFill === undefined) firstFill = start;
6473

65-
c.selectAll('g.contourbg path')
66-
.style('fill', colorMap(firstFill - 0.5 * cs));
74+
c.selectAll('g.contourbg path')
75+
.style('fill', colorMap(firstFill - 0.5 * cs));
76+
}
6777
});
6878

6979
heatmapStyle(gd);

src/traces/contourcarpet/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ContourCarpet.supplyDefaults = require('./defaults');
1515
ContourCarpet.colorbar = require('../contour/colorbar');
1616
ContourCarpet.calc = require('./calc');
1717
ContourCarpet.plot = require('./plot');
18-
ContourCarpet.style = require('./style');
18+
ContourCarpet.style = require('../contour/style');
1919

2020
ContourCarpet.moduleType = 'trace';
2121
ContourCarpet.name = 'contourcarpet';

src/traces/contourcarpet/style.js

-63
This file was deleted.

0 commit comments

Comments
 (0)