@@ -72,67 +72,96 @@ function draw(gd) {
72
72
}
73
73
74
74
function makeColorBarData ( gd ) {
75
+ var fullLayout = gd . _fullLayout ;
75
76
var calcdata = gd . calcdata ;
76
77
var out = [ ] ;
77
78
79
+ // single out item
80
+ var opts ;
81
+ // colorbar attr parent container
82
+ var cont ;
83
+ // trace attr container
84
+ var trace ;
85
+ // colorbar options
86
+ var cbOpt ;
87
+
88
+ function initOpts ( opts ) {
89
+ return extendFlat ( opts , {
90
+ // fillcolor can be a d3 scale, domain is z values, range is colors
91
+ // or leave it out for no fill,
92
+ // or set to a string constant for single-color fill
93
+ _fillcolor : null ,
94
+ // line.color has the same options as fillcolor
95
+ _line : { color : null , width : null , dash : null } ,
96
+ // levels of lines to draw.
97
+ // note that this DOES NOT determine the extent of the bar
98
+ // that's given by the domain of fillcolor
99
+ // (or line.color if no fillcolor domain)
100
+ _levels : { start : null , end : null , size : null } ,
101
+ // separate fill levels (for example, heatmap coloring of a
102
+ // contour map) if this is omitted, fillcolors will be
103
+ // evaluated halfway between levels
104
+ _filllevels : null ,
105
+ // for continuous colorscales: fill with a gradient instead of explicit levels
106
+ // value should be the colorscale [[0, c0], [v1, c1], ..., [1, cEnd]]
107
+ _fillgradient : null ,
108
+ // when using a gradient, we need the data range specified separately
109
+ _zrange : null
110
+ } ) ;
111
+ }
112
+
113
+ function calcOpts ( ) {
114
+ if ( typeof cbOpt . calc === 'function' ) {
115
+ cbOpt . calc ( gd , trace , opts ) ;
116
+ } else {
117
+ opts . _fillgradient = cont . reversescale ?
118
+ flipScale ( cont . colorscale ) :
119
+ cont . colorscale ;
120
+ opts . _zrange = [ cont [ cbOpt . min ] , cont [ cbOpt . max ] ] ;
121
+ }
122
+ }
123
+
78
124
for ( var i = 0 ; i < calcdata . length ; i ++ ) {
79
125
var cd = calcdata [ i ] ;
80
- var trace = cd [ 0 ] . trace ;
126
+ trace = cd [ 0 ] . trace ;
81
127
var moduleOpts = trace . _module . colorbar ;
82
128
83
129
if ( trace . visible === true && moduleOpts ) {
84
130
var allowsMultiplotCbs = Array . isArray ( moduleOpts ) ;
85
131
var cbOpts = allowsMultiplotCbs ? moduleOpts : [ moduleOpts ] ;
86
132
87
133
for ( var j = 0 ; j < cbOpts . length ; j ++ ) {
88
- var cbOpt = cbOpts [ j ] ;
134
+ cbOpt = cbOpts [ j ] ;
89
135
var contName = cbOpt . container ;
90
- var cont = contName ? trace [ contName ] : trace ;
136
+ cont = contName ? trace [ contName ] : trace ;
91
137
92
138
if ( cont && cont . showscale ) {
93
- var opts = cont . colorbar ;
139
+ opts = initOpts ( cont . colorbar ) ;
94
140
opts . _id = 'cb' + trace . uid + ( allowsMultiplotCbs && contName ? '-' + contName : '' ) ;
95
141
opts . _traceIndex = trace . index ;
96
142
opts . _propPrefix = ( contName ? contName + '.' : '' ) + 'colorbar.' ;
97
-
98
- extendFlat ( opts , {
99
- // fillcolor can be a d3 scale, domain is z values, range is colors
100
- // or leave it out for no fill,
101
- // or set to a string constant for single-color fill
102
- _fillcolor : null ,
103
- // line.color has the same options as fillcolor
104
- _line : { color : null , width : null , dash : null } ,
105
- // levels of lines to draw.
106
- // note that this DOES NOT determine the extent of the bar
107
- // that's given by the domain of fillcolor
108
- // (or line.color if no fillcolor domain)
109
- _levels : { start : null , end : null , size : null } ,
110
- // separate fill levels (for example, heatmap coloring of a
111
- // contour map) if this is omitted, fillcolors will be
112
- // evaluated halfway between levels
113
- _filllevels : null ,
114
- // for continuous colorscales: fill with a gradient instead of explicit levels
115
- // value should be the colorscale [[0, c0], [v1, c1], ..., [1, cEnd]]
116
- _fillgradient : null ,
117
- // when using a gradient, we need the data range specified separately
118
- _zrange : null
119
- } ) ;
120
-
121
- if ( typeof cbOpt . calc === 'function' ) {
122
- cbOpt . calc ( gd , cd , opts ) ;
123
- } else {
124
- opts . _fillgradient = cont . reversescale ?
125
- flipScale ( cont . colorscale ) :
126
- cont . colorscale ;
127
- opts . _zrange = [ cont [ cbOpt . min ] , cont [ cbOpt . max ] ] ;
128
- }
129
-
143
+ calcOpts ( ) ;
130
144
out . push ( opts ) ;
131
145
}
132
146
}
133
147
}
134
148
}
135
149
150
+ for ( var k in fullLayout . _colorAxes ) {
151
+ cont = fullLayout [ k ] ;
152
+
153
+ if ( cont . showscale ) {
154
+ var colorAxOpts = fullLayout . _colorAxes [ k ] ;
155
+
156
+ opts = initOpts ( cont . colorbar ) ;
157
+ opts . _id = 'cb' + k ;
158
+
159
+ cbOpt = { min : 'cmin' , max : 'cmax' } ;
160
+ calcOpts ( ) ;
161
+ out . push ( opts ) ;
162
+ }
163
+ }
164
+
136
165
return out ;
137
166
}
138
167
0 commit comments