diff options
Diffstat (limited to 'web/js/nms-color-util.js')
-rw-r--r-- | web/js/nms-color-util.js | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/web/js/nms-color-util.js b/web/js/nms-color-util.js index 0f50126..d1336c3 100644 --- a/web/js/nms-color-util.js +++ b/web/js/nms-color-util.js @@ -7,32 +7,36 @@ */ var nmsColor = nmsColor || { - _cache: [], - lightblue: "#d9edf7", - lightgreen: "#dff0d8", - lightred: "#f2dede", - lightorange: "#fcf8e3", - blue: "#337ab7", - green: "#5cb85c", - teal: "#5bc0de", - orange: "#f0ad4e", - red: "#d9534f", - white: "#ffffff" -} + _cache: [], + cyan: "#0dcaf0", + blue: "#0d6efd", + green: "#198754", + teal: "#20c997", + orange: "#fd7e14", + red: "#dc3545", + white: "#fff", +}; /* * Return a random-ish color (for testing) */ -nmsColor.random = function() -{ - var colors = [ "white", nmsColor.red, nmsColor.teal, nmsColor.orange, nmsColor.green, nmsColor.blue ]; - var i = Math.round(Math.random() * (colors.length-1)); - return colors[i]; -} +nmsColor.random = function () { + var colors = [ + nmsColor.white, + nmsColor.red, + nmsColor.teal, + nmsColor.orange, + nmsColor.green, + nmsColor.blue, + nmsColor.cyan, + ]; + var i = Math.round(Math.random() * (colors.length - 1)); + return colors[i]; +}; /* * Set up the hidden gradient canvas, using an array as input. - * + * * This gives us a flexible way to get gradients between any number of * colors (green to red, or blue to green to orange to red to white to pink * to black and so on). @@ -44,57 +48,52 @@ nmsColor.random = function() * resize for the moment, because this canvas is also re-sized (which isn't * really necessary, but avoids special handling). */ -nmsColor.drawGradient = function(gradients) { - var ctx = nmsMap._c.hidden.ctx; // FIXME: Move it away... - var gradient = ctx.createLinearGradient(0,0,1000,0); - var stops = gradients.length - 1; - nmsColor._cache = []; - nms.gradients = gradients; - for (var color in gradients) { - var i = color / stops; - gradient.addColorStop(i, gradients[color]); - } - ctx.beginPath(); - ctx.strokeStyle = gradient; - ctx.moveTo(0,0); - ctx.lineTo(1000,0); - ctx.lineWidth = 10; - ctx.closePath(); - ctx.stroke(); - ctx.moveTo(0,0); -} +nmsColor.drawGradient = function (gradients) { + var ctx = nmsMap._c.hidden.ctx; // FIXME: Move it away... + var gradient = ctx.createLinearGradient(0, 0, 1000, 0); + var stops = gradients.length - 1; + nmsColor._cache = []; + nms.gradients = gradients; + for (var color in gradients) { + var i = color / stops; + gradient.addColorStop(i, gradients[color]); + } + ctx.beginPath(); + ctx.strokeStyle = gradient; + ctx.moveTo(0, 0); + ctx.lineTo(1000, 0); + ctx.lineWidth = 10; + ctx.closePath(); + ctx.stroke(); + ctx.moveTo(0, 0); +}; /* * Get the color of a gradient, range is from 0 to 999 (inclusive). */ -nmsColor.getColorStop = function(x) { - x = parseInt(x); - if (isNaN(x)) - x = 0; - if (x > 999) - x = 999; - if (x < 0) - x = 0; - return nmsColor._getColor(x,0); -} +nmsColor.getColorStop = function (x) { + x = parseInt(x); + if (isNaN(x)) x = 0; + if (x > 999) x = 999; + if (x < 0) x = 0; + return nmsColor._getColor(x, 0); +}; /* * Get the color on the hidden canvas at a specific point. Could easily be * made generic. */ -nmsColor._getColor = function(x,y) { - if (nmsColor._cache[x] != undefined) - return nmsColor._cache[x]; - var ctx = nmsMap._c.hidden.ctx; // FIXME: Move it away... - try { - var imageData = ctx.getImageData(x, y, 1, 1); - } catch(e) { - console.log("x: " + x); - console.log(e); - } - var data = imageData.data; - if (data.length < 4) - return false; - nmsColor._cache[x] = 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')'; - return nmsColor._cache[x]; -} +nmsColor._getColor = function (x, y) { + if (nmsColor._cache[x] != undefined) return nmsColor._cache[x]; + var ctx = nmsMap._c.hidden.ctx; // FIXME: Move it away... + try { + var imageData = ctx.getImageData(x, y, 1, 1); + } catch (e) { + console.log("x: " + x); + console.log(e); + } + var data = imageData.data; + if (data.length < 4) return false; + nmsColor._cache[x] = "rgb(" + data[0] + "," + data[1] + "," + data[2] + ")"; + return nmsColor._cache[x]; +}; |