MCPcopy Index your code
hub / github.com/plotly/plotly.js / makeColorScaleFunc

Function makeColorScaleFunc

src/components/colorscale/helpers.js:161–208  ·  view source on GitHub ↗

* General colorscale function generator. * * @param {object} specs output of Colorscale.extractScale or precomputed domain, range. * - domain {array} * - range {array} * * @param {object} opts * - noNumericCheck {boolean} if true, scale func bypasses numeric checks * - returnArray {boole

(specs, opts)

Source from the content-addressed store, hash-verified

159 * @return {function}
160 */
161function makeColorScaleFunc(specs, opts) {
162 opts = opts || {};
163
164 var domain = specs.domain;
165 var range = specs.range;
166 var N = range.length;
167 var _range = new Array(N);
168
169 for(var i = 0; i < N; i++) {
170 var rgba = tinycolor(range[i]).toRgb();
171 _range[i] = [rgba.r, rgba.g, rgba.b, rgba.a];
172 }
173
174 var _sclFunc = d3.scale.linear()
175 .domain(domain)
176 .range(_range)
177 .clamp(true);
178
179 var noNumericCheck = opts.noNumericCheck;
180 var returnArray = opts.returnArray;
181 var sclFunc;
182
183 if(noNumericCheck && returnArray) {
184 sclFunc = _sclFunc;
185 } else if(noNumericCheck) {
186 sclFunc = function(v) {
187 return colorArray2rbga(_sclFunc(v));
188 };
189 } else if(returnArray) {
190 sclFunc = function(v) {
191 if(isNumeric(v)) return _sclFunc(v);
192 else if(tinycolor(v).isValid()) return v;
193 else return Color.defaultLine;
194 };
195 } else {
196 sclFunc = function(v) {
197 if(isNumeric(v)) return colorArray2rbga(_sclFunc(v));
198 else if(tinycolor(v).isValid()) return v;
199 else return Color.defaultLine;
200 };
201 }
202
203 // colorbar draw looks into the d3 scale closure for domain and range
204 sclFunc.domain = _sclFunc.domain;
205 sclFunc.range = function() { return range; };
206
207 return sclFunc;
208}
209
210function makeColorScaleFuncFromTrace(trace, opts) {
211 return makeColorScaleFunc(extractScale(trace), opts);

Callers 1

Calls 1

colorArray2rbgaFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…