Skip to content

Commit c76cdf8

Browse files
committed
Merge pull request #522 from monfera/fi-51-contour-plot-fill
FI-51 contour plot fill
2 parents 2fcde64 + f421d4e commit c76cdf8

File tree

7 files changed

+10732
-83
lines changed

7 files changed

+10732
-83
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"delaunay-triangulate": "^1.1.6",
5555
"es6-promise": "^3.0.2",
5656
"fast-isnumeric": "^1.1.1",
57-
"gl-contour2d": "^1.0.1",
57+
"gl-contour2d": "^1.1.2",
5858
"gl-error2d": "^1.0.0",
5959
"gl-error3d": "^1.0.0",
6060
"gl-heatmap2d": "^1.0.2",

src/traces/contourgl/convert.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ proto.update = function(fullTrace, calcTrace) {
8585
// convert z from 2D -> 1D
8686
var z = calcPt.z,
8787
rowLen = z[0].length,
88-
colLen = z.length;
88+
colLen = z.length,
89+
colorOptions;
8990

9091
this.contourOptions.z = flattenZ(z, rowLen, colLen);
9192
this.heatmapOptions.z = [].concat.apply([], z);
@@ -95,9 +96,22 @@ proto.update = function(fullTrace, calcTrace) {
9596
this.contourOptions.x = this.heatmapOptions.x = calcPt.x;
9697
this.contourOptions.y = this.heatmapOptions.y = calcPt.y;
9798

98-
var colorOptions = convertColorscale(fullTrace);
99-
this.contourOptions.levels = colorOptions.levels;
100-
this.contourOptions.levelColors = colorOptions.levelColors;
99+
100+
// pass on fill information
101+
if(fullTrace.contours.coloring === 'fill') {
102+
colorOptions = convertColorscale(fullTrace, true);
103+
this.contourOptions.levels = colorOptions.levels.slice(1);
104+
// though gl-contour2d automatically defaults to a transparent layer for the last
105+
// band color, it's set manually here in case the gl-contour2 API changes
106+
this.contourOptions.fillColors = colorOptions.levelColors;
107+
this.contourOptions.levelColors = [].concat.apply([], this.contourOptions.levels.map(function() {
108+
return [0.25, 0.25, 0.25, 1.0];
109+
}));
110+
} else {
111+
colorOptions = convertColorscale(fullTrace, false);
112+
this.contourOptions.levels = colorOptions.levels;
113+
this.contourOptions.levelColors = colorOptions.levelColors;
114+
}
101115

102116
// convert text from 2D -> 1D
103117
this.textLabels = [].concat.apply([], fullTrace.text);
@@ -124,20 +138,20 @@ function flattenZ(zIn, rowLen, colLen) {
124138
return zOut;
125139
}
126140

127-
function convertColorscale(fullTrace) {
141+
function convertColorscale(fullTrace, fill) {
128142
var contours = fullTrace.contours,
129143
start = contours.start,
130144
end = contours.end,
131145
cs = contours.size || 1;
132146

133147
var colorMap = makeColorMap(fullTrace);
134148

135-
var N = Math.floor((end - start) / cs) + 1,
149+
var N = Math.floor((end - start) / cs) + (fill ? 2 : 1), // for K thresholds (contour linees) there are K+1 areas
136150
levels = new Array(N),
137151
levelColors = new Array(4 * N);
138152

139153
for(var i = 0; i < N; i++) {
140-
var level = levels[i] = start + cs * (i);
154+
var level = levels[i] = start + cs * (i) - (fill ? cs / 2 : 0); // in case of fill, use band midpoint
141155
var color = str2RGBArray(colorMap(level));
142156

143157
for(var j = 0; j < 4; j++) {

0 commit comments

Comments
 (0)