@@ -44,6 +44,66 @@ function hasColorscale(trace, containerStr) {
44
44
) ;
45
45
}
46
46
47
+ var constantAttrs = [ 'showscale' , 'autocolorscale' , 'colorscale' , 'reversescale' , 'colorbar' ] ;
48
+ var letterAttrs = [ 'min' , 'max' , 'mid' , 'auto' ] ;
49
+
50
+ /**
51
+ * Extract 'c' / 'z', trace / color axis colorscale options
52
+ *
53
+ * Note that it would be nice to replace all z* with c* equivalents in v2
54
+ *
55
+ * @param {object } cont : attribute container
56
+ * @return {object }:
57
+ * - min: cmin or zmin
58
+ * - max: cmax or zmax
59
+ * - mid: cmid or zmid
60
+ * - auto: cauto or zauto
61
+ * - *scale: *scale attrs
62
+ * - colorbar: colorbar
63
+ * - _sync: function syncing attr and underscore dual (useful when calc'ing min/max)
64
+ */
65
+ function extractOpts ( cont ) {
66
+ var colorAx = cont . _colorAx ;
67
+ var cont2 = colorAx ? colorAx : cont ;
68
+ var out = { } ;
69
+ var cLetter ;
70
+ var i , k ;
71
+
72
+ for ( i = 0 ; i < constantAttrs . length ; i ++ ) {
73
+ k = constantAttrs [ i ] ;
74
+ out [ k ] = cont2 [ k ] ;
75
+ }
76
+
77
+ if ( colorAx ) {
78
+ cLetter = 'c' ;
79
+ for ( i = 0 ; i < letterAttrs . length ; i ++ ) {
80
+ k = letterAttrs [ i ] ;
81
+ out [ k ] = cont2 [ 'c' + k ] ;
82
+ }
83
+ } else {
84
+ var k2 ;
85
+ for ( i = 0 ; i < letterAttrs . length ; i ++ ) {
86
+ k = letterAttrs [ i ] ;
87
+ k2 = 'c' + k ;
88
+ if ( k2 in cont2 ) {
89
+ out [ k ] = cont2 [ k2 ] ;
90
+ continue ;
91
+ }
92
+ k2 = 'z' + k ;
93
+ if ( k2 in cont2 ) {
94
+ out [ k ] = cont2 [ k2 ] ;
95
+ }
96
+ }
97
+ cLetter = k2 . charAt ( 0 ) ;
98
+ }
99
+
100
+ out . _sync = function ( k , v ) {
101
+ var k2 = letterAttrs . indexOf ( k ) !== - 1 ? cLetter + k : k ;
102
+ cont2 [ k2 ] = cont2 [ '_' + k2 ] = v ;
103
+ } ;
104
+
105
+ return out ;
106
+ }
47
107
/**
48
108
* Extract colorscale into numeric domain and color range.
49
109
*
@@ -173,6 +233,7 @@ function colorArray2rbga(colorArray) {
173
233
174
234
module . exports = {
175
235
hasColorscale : hasColorscale ,
236
+ extractOpts : extractOpts ,
176
237
extractScale : extractScale ,
177
238
flipScale : flipScale ,
178
239
makeColorScaleFunc : makeColorScaleFunc
0 commit comments