@@ -104,6 +104,7 @@ function extractOpts(cont) {
104104
105105 return out ;
106106}
107+
107108/**
108109 * Extract colorscale into numeric domain and color range.
109110 *
@@ -112,24 +113,19 @@ function extractOpts(cont) {
112113 * - cmin/zmin {number}
113114 * - cmax/zmax {number}
114115 * - reversescale {boolean}
115- * @param {object } opts
116- * - cLetter {string} 'c' (for cmin/cmax) or 'z' (for zmin/zmax)
117116 *
118117 * @return {object }
119118 * - domain {array}
120119 * - range {array}
121120 */
122- function extractScale ( cont , opts ) {
123- var cLetter = opts . cLetter ;
124-
125- var scl = cont . reversescale ?
126- flipScale ( cont . colorscale ) :
127- cont . colorscale ;
121+ function extractScale ( cont ) {
122+ var cOpts = extractOpts ( cont ) ;
123+ var cmin = cOpts . min ;
124+ var cmax = cOpts . max ;
128125
129- // minimum color value (used to clamp scale)
130- var cmin = cont [ cLetter + 'min' ] ;
131- // maximum color value (used to clamp scale)
132- var cmax = cont [ cLetter + 'max' ] ;
126+ var scl = cOpts . reversescale ?
127+ flipScale ( cOpts . colorscale ) :
128+ cOpts . colorscale ;
133129
134130 var N = scl . length ;
135131 var domain = new Array ( N ) ;
@@ -141,10 +137,7 @@ function extractScale(cont, opts) {
141137 range [ i ] = si [ 1 ] ;
142138 }
143139
144- return {
145- domain : domain ,
146- range : range
147- } ;
140+ return { domain : domain , range : range } ;
148141}
149142
150143function flipScale ( scl ) {
@@ -220,6 +213,10 @@ function makeColorScaleFunc(specs, opts) {
220213 return sclFunc ;
221214}
222215
216+ function makeColorScaleFuncFromTrace ( trace , opts ) {
217+ return makeColorScaleFunc ( extractScale ( trace ) , opts ) ;
218+ }
219+
223220function colorArray2rbga ( colorArray ) {
224221 var colorObj = {
225222 r : colorArray [ 0 ] ,
@@ -236,5 +233,6 @@ module.exports = {
236233 extractOpts : extractOpts ,
237234 extractScale : extractScale ,
238235 flipScale : flipScale ,
239- makeColorScaleFunc : makeColorScaleFunc
236+ makeColorScaleFunc : makeColorScaleFunc ,
237+ makeColorScaleFuncFromTrace : makeColorScaleFuncFromTrace
240238} ;
0 commit comments