Skip to content

Commit 5736290

Browse files
committed
move 3d parseColorScale to gl_format_color
1 parent ec64895 commit 5736290

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

src/lib/gl_format_color.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var isNumeric = require('fast-isnumeric');
13+
var tinycolor = require('tinycolor2');
1314
var rgba = require('color-normalize');
1415

1516
var Colorscale = require('../components/colorscale');
@@ -85,4 +86,21 @@ function formatColor(containerIn, opacityIn, len) {
8586
return colorOut;
8687
}
8788

88-
module.exports = formatColor;
89+
function parseColorScale(colorscale, alpha) {
90+
if(alpha === undefined) alpha = 1;
91+
92+
return colorscale.map(function(elem) {
93+
var index = elem[0];
94+
var color = tinycolor(elem[1]);
95+
var rgb = color.toRgb();
96+
return {
97+
index: index,
98+
rgb: [rgb.r, rgb.g, rgb.b, alpha]
99+
};
100+
});
101+
}
102+
103+
module.exports = {
104+
formatColor: formatColor,
105+
parseColorScale: parseColorScale
106+
};

src/traces/mesh3d/convert.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
'use strict';
1111

1212
var createMesh = require('gl-mesh3d');
13-
var tinycolor = require('tinycolor2');
1413
var triangulate = require('delaunay-triangulate');
1514
var alphaShape = require('alpha-shape');
1615
var convexHull = require('convex-hull');
1716

17+
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
1818
var str2RgbaArray = require('../../lib/str2rgbarray');
1919

20-
2120
function Mesh3DTrace(scene, mesh, uid) {
2221
this.scene = scene;
2322
this.uid = uid;
@@ -51,18 +50,6 @@ proto.handlePick = function(selection) {
5150
}
5251
};
5352

54-
function parseColorScale(colorscale) {
55-
return colorscale.map(function(elem) {
56-
var index = elem[0];
57-
var color = tinycolor(elem[1]);
58-
var rgb = color.toRgb();
59-
return {
60-
index: index,
61-
rgb: [rgb.r, rgb.g, rgb.b, 1]
62-
};
63-
});
64-
}
65-
6653
function parseColorArray(colors) {
6754
return colors.map(str2RgbaArray);
6855
}

src/traces/scatter3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var triangulate = require('delaunay-triangulate');
1717

1818
var Lib = require('../../lib');
1919
var str2RgbaArray = require('../../lib/str2rgbarray');
20-
var formatColor = require('../../lib/gl_format_color');
20+
var formatColor = require('../../lib/gl_format_color').formatColor;
2121
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2222
var DASH_PATTERNS = require('../../constants/gl3d_dashes');
2323
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');

src/traces/scattergl/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var Lib = require('../../lib');
1616
var Drawing = require('../../components/drawing');
1717
var AxisIDs = require('../../plots/cartesian/axis_ids');
1818

19-
var formatColor = require('../../lib/gl_format_color');
19+
var formatColor = require('../../lib/gl_format_color').formatColor;
2020
var subTypes = require('../scatter/subtypes');
2121
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2222

src/traces/surface/convert.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var ndarray = require('ndarray');
1414
var homography = require('ndarray-homography');
1515
var fill = require('ndarray-fill');
1616
var ops = require('ndarray-ops');
17-
var tinycolor = require('tinycolor2');
1817

1918
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
19+
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
2020
var str2RgbaArray = require('../../lib/str2rgbarray');
2121

2222
var MIN_RESOLUTION = 128;
@@ -92,20 +92,6 @@ proto.handlePick = function(selection) {
9292
}
9393
};
9494

95-
function parseColorScale(colorscale, alpha) {
96-
if(alpha === undefined) alpha = 1;
97-
98-
return colorscale.map(function(elem) {
99-
var index = elem[0];
100-
var color = tinycolor(elem[1]);
101-
var rgb = color.toRgb();
102-
return {
103-
index: index,
104-
rgb: [rgb.r, rgb.g, rgb.b, alpha]
105-
};
106-
});
107-
}
108-
10995
function isColormapCircular(colormap) {
11096
var first = colormap[0].rgb,
11197
last = colormap[colormap.length - 1].rgb;

0 commit comments

Comments
 (0)