@@ -85,7 +85,8 @@ proto.update = function(fullTrace, calcTrace) {
85
85
// convert z from 2D -> 1D
86
86
var z = calcPt . z ,
87
87
rowLen = z [ 0 ] . length ,
88
- colLen = z . length ;
88
+ colLen = z . length ,
89
+ colorOptions ;
89
90
90
91
this . contourOptions . z = flattenZ ( z , rowLen , colLen ) ;
91
92
this . heatmapOptions . z = [ ] . concat . apply ( [ ] , z ) ;
@@ -95,9 +96,22 @@ proto.update = function(fullTrace, calcTrace) {
95
96
this . contourOptions . x = this . heatmapOptions . x = calcPt . x ;
96
97
this . contourOptions . y = this . heatmapOptions . y = calcPt . y ;
97
98
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
+ }
101
115
102
116
// convert text from 2D -> 1D
103
117
this . textLabels = [ ] . concat . apply ( [ ] , fullTrace . text ) ;
@@ -124,20 +138,20 @@ function flattenZ(zIn, rowLen, colLen) {
124
138
return zOut ;
125
139
}
126
140
127
- function convertColorscale ( fullTrace ) {
141
+ function convertColorscale ( fullTrace , fill ) {
128
142
var contours = fullTrace . contours ,
129
143
start = contours . start ,
130
144
end = contours . end ,
131
145
cs = contours . size || 1 ;
132
146
133
147
var colorMap = makeColorMap ( fullTrace ) ;
134
148
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
136
150
levels = new Array ( N ) ,
137
151
levelColors = new Array ( 4 * N ) ;
138
152
139
153
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
141
155
var color = str2RGBArray ( colorMap ( level ) ) ;
142
156
143
157
for ( var j = 0 ; j < 4 ; j ++ ) {
0 commit comments