Skip to content

Commit 7c91e16

Browse files
author
James Bradbury
authored
fix RGB function (flucoma#154)
1 parent 4b246b3 commit 7c91e16

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

jsui/fluid.plotter.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ var colorMap = {};
5353
var pointColors = {};
5454
var pointSizes = {};
5555

56-
57-
function hexToRGB(hex, a) {
58-
// Converts a HEX value to an array of RGBA values
59-
var a = a || 1.0;
60-
var r = parseInt(hex.slice(1, 3), 16) / 256.0,
61-
g = parseInt(hex.slice(3, 5), 16) / 256.0,
62-
b = parseInt(hex.slice(5, 7), 16) / 256.0;
63-
return [r, g, b, a];
56+
function hexToRGB(hex, alpha) {
57+
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
58+
return result ? [
59+
parseInt(result[1], 16) / 255.0,
60+
parseInt(result[2], 16) / 255.0,
61+
parseInt(result[3], 16) / 255.0,
62+
alpha
63+
] : [0, 0, 0, alpha];
6464
}
6565

6666
function strChunk(str, size) {
@@ -193,11 +193,8 @@ function constructColorScheme() {
193193
i = i % scheme.length;
194194
var color = hexToRGB(scheme[i], 1.0);
195195
colorMap[u] = color;
196-
post(color, '\n')
197196
});
198197
mgraphics.redraw();
199-
200-
201198
}
202199
}
203200

0 commit comments

Comments
 (0)