MCPcopy
hub / github.com/plotly/plotly.js / formatColor

Function formatColor

src/lib/gl_format_color.js:32–71  ·  view source on GitHub ↗
(containerIn, opacityIn, len)

Source from the content-addressed store, hash-verified

30}
31
32function formatColor(containerIn, opacityIn, len) {
33 var colorIn = containerIn.color;
34 if(colorIn && colorIn._inputArray) colorIn = colorIn._inputArray;
35
36 var isArrayColorIn = isArrayOrTypedArray(colorIn);
37 var isArrayOpacityIn = isArrayOrTypedArray(opacityIn);
38 var cOpts = Colorscale.extractOpts(containerIn);
39 var colorOut = [];
40
41 var sclFunc, getColor, getOpacity, colori, opacityi;
42
43 if(cOpts.colorscale !== undefined) {
44 sclFunc = Colorscale.makeColorScaleFuncFromTrace(containerIn);
45 } else {
46 sclFunc = validateColor;
47 }
48
49 if(isArrayColorIn) {
50 getColor = function(c, i) {
51 // FIXME: there is double work, considering that sclFunc does the opposite
52 return c[i] === undefined ? colorDfltRgba : rgba(sclFunc(c[i]));
53 };
54 } else getColor = validateColor;
55
56 if(isArrayOpacityIn) {
57 getOpacity = function(o, i) {
58 return o[i] === undefined ? opacityDflt : validateOpacity(o[i]);
59 };
60 } else getOpacity = validateOpacity;
61
62 if(isArrayColorIn || isArrayOpacityIn) {
63 for(var i = 0; i < len; i++) {
64 colori = getColor(colorIn, i);
65 opacityi = getOpacity(opacityIn, i);
66 colorOut[i] = calculateColor(colori, opacityi);
67 }
68 } else colorOut = calculateColor(rgba(colorIn), opacityIn);
69
70 return colorOut;
71}
72
73function parseColorScale(cont) {
74 var cOpts = Colorscale.extractOpts(cont);

Callers 2

convertPlotlyOptionsFunction · 0.85
convertMarkerStyleFunction · 0.85

Calls 5

validateOpacityFunction · 0.85
getColorFunction · 0.85
getOpacityFunction · 0.85
calculateColorFunction · 0.85
isArrayOrTypedArrayFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…