[Fixed Position] Add color chooser

Add color picker for fill color, WTD-881
This commit is contained in:
Victor Woeltjen
2015-02-23 16:47:52 -08:00
parent 6c7dfb878b
commit 00f85447a2
4 changed files with 122 additions and 4 deletions

View File

@ -0,0 +1,81 @@
/*global define*/
define(
[],
function () {
"use strict";
var BASE_COLORS = [
[ 136, 32, 32 ],
[ 224, 64, 64 ],
[ 240, 160, 72 ],
[ 255, 248, 96 ],
[ 128, 240, 72 ],
[ 128, 248, 248 ],
[ 88, 144, 224 ],
[ 0, 72, 240 ],
[ 136, 80, 240 ],
[ 224, 96, 248 ]
],
GRADIENTS = [0.75, 0.50, 0.25, -0.25, -0.50, -0.75],
GROUPS = [];
function toWebColor(triplet) {
return '#' + triplet.map(function (v) {
return (v < 16 ? '0' : '') + v.toString(16);
}).join('');
}
function toGradient(triplet, value) {
return triplet.map(function (v) {
return Math.round(value > 0 ?
(v + (255 - v) * value) :
(v * (1 + value))
);
});
}
function initializeGroups() {
var i, group;
// Ten grayscale colors
group = [];
while (group.length < 10) {
group.push(toWebColor([
Math.round(28.3333 * group.length),
Math.round(28.3333 * group.length),
Math.round(28.3333 * group.length)
]));
}
GROUPS.push(group);
// Ten basic colors
GROUPS.push(BASE_COLORS.map(toWebColor));
// ...and some gradients of those colors
group = [];
GRADIENTS.forEach(function (v) {
group = group.concat(BASE_COLORS.map(function (c) {
return toWebColor(toGradient(c, v));
}));
});
GROUPS.push(group);
}
function ColorController() {
if (GROUPS.length === 0) {
initializeGroups();
}
return {
groups: function () {
return GROUPS;
}
};
}
return ColorController;
}
);