chroma-js 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f0b20b20011078c4d989060e5ee8e2593ac7580
4
- data.tar.gz: ef73aa3b5747e1cc7304337c12b8c8dc85c0bf59
3
+ metadata.gz: 2c0076bcd8f1e85c74208b5efcd1def0d159b6a1
4
+ data.tar.gz: 2ea4087e646867f200ccd99412aba75a93b8a330
5
5
  SHA512:
6
- metadata.gz: 9495053968fa39790d2c525b3e1710d2d901083dd2f6b3cec2ef6f58bc8ed8d2319026afa6043ce2d339e32b88a269ffc9c1594c5c44ec96612b1b690fb769bf
7
- data.tar.gz: ca5be78de3abf108977fbc41b54504b12c582e162173d9f935eab06446577212bca4e0a8b4675aa24643e0dee3f877a6ff5e4d1d3496cec7196dac9bf8341f5e
6
+ metadata.gz: e76bb76b7e6afbde0d7d7f0c13ecfbb6d820bf7ee2ffef979ce2f693092beab9dae2c10efb289f824dd428159d2dc8435bf62570511d7cd0e1a651110eb2723d
7
+ data.tar.gz: af6a945a7643d091c66808d499c5337b95108d93ceca332d43a7f754ec3c60e1d9f41a49beb5515bd11863a8d18c1bf98bf1821cb220d14873c98736b8186f8b
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source :rubygems
2
2
 
3
- # Specify your gem's dependencies in chroma.js-rails.gemspec
4
3
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,28 @@
1
+ chroma.js - JavaScript library for color conversions
2
+
3
+ Copyright (c) 2011-2013, Gregor Aisch
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. The name Gregor Aisch may not be used to endorse or promote products
17
+ derived from this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,22 @@
1
+
2
+ chroma.js includes colors from colorbrewer2.org,
3
+ which are released under the following license:
4
+
5
+
6
+ Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
7
+ and The Pennsylvania State University.
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing,
15
+ software distributed under the License is distributed on an
16
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17
+ either express or implied. See the License for the specific
18
+ language governing permissions and limitations under the License.
19
+
20
+
21
+ Named colors are taken from X11 Color Names.
22
+ http://www.w3.org/TR/css3-color/#svg-color
@@ -0,0 +1,1863 @@
1
+ // Generated by CoffeeScript 1.6.2
2
+ /** echo * @license echo * while read i do echo * done echo
3
+ */
4
+
5
+
6
+ (function() {
7
+ var Color, K, PITHIRD, TWOPI, X, Y, Z, bezier, brewer, chroma, clip_rgb, colors, cos, css2rgb, hex2rgb, hsi2rgb, hsl2rgb, hsv2rgb, lab2lch, lab2rgb, lab_xyz, lch2lab, lch2rgb, limit, luminance, luminance_x, rgb2hex, rgb2hsi, rgb2hsl, rgb2hsv, rgb2lab, rgb2lch, rgb_xyz, root, type, unpack, xyz_lab, xyz_rgb, _ref;
8
+
9
+ chroma = function(x, y, z, m) {
10
+ return new Color(x, y, z, m);
11
+ };
12
+
13
+ if ((typeof module !== "undefined" && module !== null) && (module.exports != null)) {
14
+ module.exports = chroma;
15
+ }
16
+
17
+ if (typeof define === 'function' && define.amd) {
18
+ define([], function() {
19
+ return chroma;
20
+ });
21
+ } else {
22
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
23
+ root.chroma = chroma;
24
+ }
25
+
26
+ chroma.color = function(x, y, z, m) {
27
+ return new Color(x, y, z, m);
28
+ };
29
+
30
+ chroma.hsl = function(h, s, l, a) {
31
+ return new Color(h, s, l, a, 'hsl');
32
+ };
33
+
34
+ chroma.hsv = function(h, s, v, a) {
35
+ return new Color(h, s, v, a, 'hsv');
36
+ };
37
+
38
+ chroma.rgb = function(r, g, b, a) {
39
+ return new Color(r, g, b, a, 'rgb');
40
+ };
41
+
42
+ chroma.hex = function(x) {
43
+ return new Color(x);
44
+ };
45
+
46
+ chroma.css = function(x) {
47
+ return new Color(x);
48
+ };
49
+
50
+ chroma.lab = function(l, a, b) {
51
+ return new Color(l, a, b, 'lab');
52
+ };
53
+
54
+ chroma.lch = function(l, c, h) {
55
+ return new Color(l, c, h, 'lch');
56
+ };
57
+
58
+ chroma.hsi = function(h, s, i) {
59
+ return new Color(h, s, i, 'hsi');
60
+ };
61
+
62
+ chroma.gl = function(r, g, b, a) {
63
+ return new Color(r * 255, g * 255, b * 255, a, 'gl');
64
+ };
65
+
66
+ chroma.interpolate = function(a, b, f, m) {
67
+ if ((a == null) || (b == null)) {
68
+ return '#000';
69
+ }
70
+ if (type(a) === 'string') {
71
+ a = new Color(a);
72
+ }
73
+ if (type(b) === 'string') {
74
+ b = new Color(b);
75
+ }
76
+ return a.interpolate(f, b, m);
77
+ };
78
+
79
+ chroma.mix = chroma.interpolate;
80
+
81
+ chroma.contrast = function(a, b) {
82
+ var l1, l2;
83
+
84
+ if (type(a) === 'string') {
85
+ a = new Color(a);
86
+ }
87
+ if (type(b) === 'string') {
88
+ b = new Color(b);
89
+ }
90
+ l1 = a.luminance();
91
+ l2 = b.luminance();
92
+ if (l1 > l2) {
93
+ return (l1 + 0.05) / (l2 + 0.05);
94
+ } else {
95
+ return (l2 + 0.05) / (l1 + 0.05);
96
+ }
97
+ };
98
+
99
+ chroma.luminance = function(color) {
100
+ return chroma(color).luminance();
101
+ };
102
+
103
+ chroma._Color = Color;
104
+
105
+ /**
106
+ chroma.js
107
+
108
+ Copyright (c) 2011-2013, Gregor Aisch
109
+ All rights reserved.
110
+
111
+ Redistribution and use in source and binary forms, with or without
112
+ modification, are permitted provided that the following conditions are met:
113
+
114
+ * Redistributions of source code must retain the above copyright notice, this
115
+ list of conditions and the following disclaimer.
116
+
117
+ * Redistributions in binary form must reproduce the above copyright notice,
118
+ this list of conditions and the following disclaimer in the documentation
119
+ and/or other materials provided with the distribution.
120
+
121
+ * The name Gregor Aisch may not be used to endorse or promote products
122
+ derived from this software without specific prior written permission.
123
+
124
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
125
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
126
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
127
+ DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
128
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
129
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
130
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
131
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
132
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
133
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134
+
135
+ @source: https://github.com/gka/chroma.js
136
+ */
137
+
138
+
139
+ Color = (function() {
140
+ function Color() {
141
+ var a, arg, args, m, me, me_rgb, x, y, z, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4;
142
+
143
+ me = this;
144
+ args = [];
145
+ for (_i = 0, _len = arguments.length; _i < _len; _i++) {
146
+ arg = arguments[_i];
147
+ if (arg != null) {
148
+ args.push(arg);
149
+ }
150
+ }
151
+ if (args.length === 0) {
152
+ _ref = [255, 0, 255, 1, 'rgb'], x = _ref[0], y = _ref[1], z = _ref[2], a = _ref[3], m = _ref[4];
153
+ } else if (type(args[0]) === "array") {
154
+ if (args[0].length === 3) {
155
+ _ref1 = args[0], x = _ref1[0], y = _ref1[1], z = _ref1[2];
156
+ a = 1;
157
+ } else if (args[0].length === 4) {
158
+ _ref2 = args[0], x = _ref2[0], y = _ref2[1], z = _ref2[2], a = _ref2[3];
159
+ } else {
160
+ throw 'unknown input argument';
161
+ }
162
+ m = (_ref3 = args[1]) != null ? _ref3 : 'rgb';
163
+ } else if (type(args[0]) === "string") {
164
+ x = args[0];
165
+ m = 'hex';
166
+ } else if (type(args[0]) === "object") {
167
+ _ref4 = args[0]._rgb, x = _ref4[0], y = _ref4[1], z = _ref4[2], a = _ref4[3];
168
+ m = 'rgb';
169
+ } else if (args.length >= 3) {
170
+ x = args[0];
171
+ y = args[1];
172
+ z = args[2];
173
+ }
174
+ if (args.length === 3) {
175
+ m = 'rgb';
176
+ a = 1;
177
+ } else if (args.length === 4) {
178
+ if (type(args[3]) === "string") {
179
+ m = args[3];
180
+ a = 1;
181
+ } else if (type(args[3]) === "number") {
182
+ m = 'rgb';
183
+ a = args[3];
184
+ }
185
+ } else if (args.length === 5) {
186
+ a = args[3];
187
+ m = args[4];
188
+ }
189
+ if (a == null) {
190
+ a = 1;
191
+ }
192
+ if (m === 'rgb') {
193
+ me._rgb = [x, y, z, a];
194
+ } else if (m === 'gl') {
195
+ me._rgb = [x * 255, y * 255, z * 255, a];
196
+ } else if (m === 'hsl') {
197
+ me._rgb = hsl2rgb(x, y, z);
198
+ me._rgb[3] = a;
199
+ } else if (m === 'hsv') {
200
+ me._rgb = hsv2rgb(x, y, z);
201
+ me._rgb[3] = a;
202
+ } else if (m === 'hex') {
203
+ me._rgb = hex2rgb(x);
204
+ } else if (m === 'lab') {
205
+ me._rgb = lab2rgb(x, y, z);
206
+ me._rgb[3] = a;
207
+ } else if (m === 'lch') {
208
+ me._rgb = lch2rgb(x, y, z);
209
+ me._rgb[3] = a;
210
+ } else if (m === 'hsi') {
211
+ me._rgb = hsi2rgb(x, y, z);
212
+ me._rgb[3] = a;
213
+ }
214
+ me_rgb = clip_rgb(me._rgb);
215
+ }
216
+
217
+ Color.prototype.rgb = function() {
218
+ return this._rgb.slice(0, 3);
219
+ };
220
+
221
+ Color.prototype.rgba = function() {
222
+ return this._rgb;
223
+ };
224
+
225
+ Color.prototype.hex = function() {
226
+ return rgb2hex(this._rgb);
227
+ };
228
+
229
+ Color.prototype.toString = function() {
230
+ return this.name();
231
+ };
232
+
233
+ Color.prototype.hsl = function() {
234
+ return rgb2hsl(this._rgb);
235
+ };
236
+
237
+ Color.prototype.hsv = function() {
238
+ return rgb2hsv(this._rgb);
239
+ };
240
+
241
+ Color.prototype.lab = function() {
242
+ return rgb2lab(this._rgb);
243
+ };
244
+
245
+ Color.prototype.lch = function() {
246
+ return rgb2lch(this._rgb);
247
+ };
248
+
249
+ Color.prototype.hsi = function() {
250
+ return rgb2hsi(this._rgb);
251
+ };
252
+
253
+ Color.prototype.gl = function() {
254
+ return [this._rgb[0] / 255, this._rgb[1] / 255, this._rgb[2] / 255, this._rgb[3]];
255
+ };
256
+
257
+ Color.prototype.luminance = function() {
258
+ return luminance(this._rgb);
259
+ };
260
+
261
+ Color.prototype.name = function() {
262
+ var h, k;
263
+
264
+ h = this.hex();
265
+ for (k in chroma.colors) {
266
+ if (h === chroma.colors[k]) {
267
+ return k;
268
+ }
269
+ }
270
+ return h;
271
+ };
272
+
273
+ Color.prototype.alpha = function(alpha) {
274
+ if (arguments.length) {
275
+ this._rgb[3] = alpha;
276
+ return this;
277
+ }
278
+ return this._rgb[3];
279
+ };
280
+
281
+ Color.prototype.css = function(mode) {
282
+ var hsl, me, rgb, rnd;
283
+
284
+ if (mode == null) {
285
+ mode = 'rgb';
286
+ }
287
+ me = this;
288
+ rgb = me._rgb;
289
+ if (mode.length === 3 && rgb[3] < 1) {
290
+ mode += 'a';
291
+ }
292
+ if (mode === 'rgb') {
293
+ return mode + '(' + rgb.slice(0, 3).map(Math.round).join(',') + ')';
294
+ } else if (mode === 'rgba') {
295
+ return mode + '(' + rgb.slice(0, 3).map(Math.round).join(',') + ',' + rgb[3] + ')';
296
+ } else if (mode === 'hsl' || mode === 'hsla') {
297
+ hsl = me.hsl();
298
+ rnd = function(a) {
299
+ return Math.round(a * 100) / 100;
300
+ };
301
+ hsl[0] = rnd(hsl[0]);
302
+ hsl[1] = rnd(hsl[1] * 100) + '%';
303
+ hsl[2] = rnd(hsl[2] * 100) + '%';
304
+ if (mode.length === 4) {
305
+ hsl[3] = rgb[3];
306
+ }
307
+ return mode + '(' + hsl.join(',') + ')';
308
+ }
309
+ };
310
+
311
+ Color.prototype.interpolate = function(f, col, m) {
312
+ /*
313
+ interpolates between colors
314
+ f = 0 --> me
315
+ f = 1 --> col
316
+ */
317
+
318
+ var dh, hue, hue0, hue1, lbv, lbv0, lbv1, me, res, sat, sat0, sat1, xyz0, xyz1;
319
+
320
+ me = this;
321
+ if (m == null) {
322
+ m = 'rgb';
323
+ }
324
+ if (type(col) === "string") {
325
+ col = new Color(col);
326
+ }
327
+ if (m === 'hsl' || m === 'hsv' || m === 'lch' || m === 'hsi') {
328
+ if (m === 'hsl') {
329
+ xyz0 = me.hsl();
330
+ xyz1 = col.hsl();
331
+ } else if (m === 'hsv') {
332
+ xyz0 = me.hsv();
333
+ xyz1 = col.hsv();
334
+ } else if (m === 'hsi') {
335
+ xyz0 = me.hsi();
336
+ xyz1 = col.hsi();
337
+ } else if (m === 'lch') {
338
+ xyz0 = me.lch();
339
+ xyz1 = col.lch();
340
+ }
341
+ if (m.substr(0, 1) === 'h') {
342
+ hue0 = xyz0[0], sat0 = xyz0[1], lbv0 = xyz0[2];
343
+ hue1 = xyz1[0], sat1 = xyz1[1], lbv1 = xyz1[2];
344
+ } else {
345
+ lbv0 = xyz0[0], sat0 = xyz0[1], hue0 = xyz0[2];
346
+ lbv1 = xyz1[0], sat1 = xyz1[1], hue1 = xyz1[2];
347
+ }
348
+ if (!isNaN(hue0) && !isNaN(hue1)) {
349
+ if (hue1 > hue0 && hue1 - hue0 > 180) {
350
+ dh = hue1 - (hue0 + 360);
351
+ } else if (hue1 < hue0 && hue0 - hue1 > 180) {
352
+ dh = hue1 + 360 - hue0;
353
+ } else {
354
+ dh = hue1 - hue0;
355
+ }
356
+ hue = hue0 + f * dh;
357
+ } else if (!isNaN(hue0)) {
358
+ hue = hue0;
359
+ if ((lbv1 === 1 || lbv1 === 0) && m !== 'hsv') {
360
+ sat = sat0;
361
+ }
362
+ } else if (!isNaN(hue1)) {
363
+ hue = hue1;
364
+ if ((lbv0 === 1 || lbv0 === 0) && m !== 'hsv') {
365
+ sat = sat1;
366
+ }
367
+ } else {
368
+ hue = Number.NaN;
369
+ }
370
+ if (sat == null) {
371
+ sat = sat0 + f * (sat1 - sat0);
372
+ }
373
+ lbv = lbv0 + f * (lbv1 - lbv0);
374
+ if (m.substr(0, 1) === 'h') {
375
+ res = new Color(hue, sat, lbv, m);
376
+ } else {
377
+ res = new Color(lbv, sat, hue, m);
378
+ }
379
+ } else if (m === 'rgb') {
380
+ xyz0 = me._rgb;
381
+ xyz1 = col._rgb;
382
+ res = new Color(xyz0[0] + f * (xyz1[0] - xyz0[0]), xyz0[1] + f * (xyz1[1] - xyz0[1]), xyz0[2] + f * (xyz1[2] - xyz0[2]), m);
383
+ } else if (m === 'lab') {
384
+ xyz0 = me.lab();
385
+ xyz1 = col.lab();
386
+ res = new Color(xyz0[0] + f * (xyz1[0] - xyz0[0]), xyz0[1] + f * (xyz1[1] - xyz0[1]), xyz0[2] + f * (xyz1[2] - xyz0[2]), m);
387
+ } else {
388
+ throw "color mode " + m + " is not supported";
389
+ }
390
+ res.alpha(me.alpha() + f * (col.alpha() - me.alpha()));
391
+ return res;
392
+ };
393
+
394
+ Color.prototype.premultiply = function() {
395
+ var a, rgb;
396
+
397
+ rgb = this.rgb();
398
+ a = this.alpha();
399
+ return chroma(rgb[0] * a, rgb[1] * a, rgb[2] * a, a);
400
+ };
401
+
402
+ Color.prototype.darken = function(amount) {
403
+ var lch, me;
404
+
405
+ if (amount == null) {
406
+ amount = 20;
407
+ }
408
+ me = this;
409
+ lch = me.lch();
410
+ lch[0] -= amount;
411
+ return chroma.lch(lch).alpha(me.alpha());
412
+ };
413
+
414
+ Color.prototype.darker = function(amount) {
415
+ return this.darken(amount);
416
+ };
417
+
418
+ Color.prototype.brighten = function(amount) {
419
+ if (amount == null) {
420
+ amount = 20;
421
+ }
422
+ return this.darken(-amount);
423
+ };
424
+
425
+ Color.prototype.brighter = function(amount) {
426
+ return this.brighten(amount);
427
+ };
428
+
429
+ Color.prototype.saturate = function(amount) {
430
+ var lch, me;
431
+
432
+ if (amount == null) {
433
+ amount = 20;
434
+ }
435
+ me = this;
436
+ lch = me.lch();
437
+ lch[1] += amount;
438
+ return chroma.lch(lch).alpha(me.alpha());
439
+ };
440
+
441
+ Color.prototype.desaturate = function(amount) {
442
+ if (amount == null) {
443
+ amount = 20;
444
+ }
445
+ return this.saturate(-amount);
446
+ };
447
+
448
+ return Color;
449
+
450
+ })();
451
+
452
+ clip_rgb = function(rgb) {
453
+ var i;
454
+
455
+ for (i in rgb) {
456
+ if (i < 3) {
457
+ if (rgb[i] < 0) {
458
+ rgb[i] = 0;
459
+ }
460
+ if (rgb[i] > 255) {
461
+ rgb[i] = 255;
462
+ }
463
+ } else if (i === 3) {
464
+ if (rgb[i] < 0) {
465
+ rgb[i] = 0;
466
+ }
467
+ if (rgb[i] > 1) {
468
+ rgb[i] = 1;
469
+ }
470
+ }
471
+ }
472
+ return rgb;
473
+ };
474
+
475
+ css2rgb = function(css) {
476
+ var hsl, i, m, rgb, _i, _j, _k, _l;
477
+
478
+ css = css.toLowerCase();
479
+ if ((chroma.colors != null) && chroma.colors[css]) {
480
+ return hex2rgb(chroma.colors[css]);
481
+ }
482
+ if (m = css.match(/rgb\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*\)/)) {
483
+ rgb = m.slice(1, 4);
484
+ for (i = _i = 0; _i <= 2; i = ++_i) {
485
+ rgb[i] = +rgb[i];
486
+ }
487
+ rgb[3] = 1;
488
+ } else if (m = css.match(/rgba\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*,\s*([01]|[01]?\.\d+)\)/)) {
489
+ rgb = m.slice(1, 5);
490
+ for (i = _j = 0; _j <= 3; i = ++_j) {
491
+ rgb[i] = +rgb[i];
492
+ }
493
+ } else if (m = css.match(/rgb\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/)) {
494
+ rgb = m.slice(1, 4);
495
+ for (i = _k = 0; _k <= 2; i = ++_k) {
496
+ rgb[i] = Math.round(rgb[i] * 2.55);
497
+ }
498
+ rgb[3] = 1;
499
+ } else if (m = css.match(/rgba\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/)) {
500
+ rgb = m.slice(1, 5);
501
+ for (i = _l = 0; _l <= 2; i = ++_l) {
502
+ rgb[i] = Math.round(rgb[i] * 2.55);
503
+ }
504
+ rgb[3] = +rgb[3];
505
+ } else if (m = css.match(/hsl\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/)) {
506
+ hsl = m.slice(1, 4);
507
+ hsl[1] *= 0.01;
508
+ hsl[2] *= 0.01;
509
+ rgb = hsl2rgb(hsl);
510
+ rgb[3] = 1;
511
+ } else if (m = css.match(/hsla\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/)) {
512
+ hsl = m.slice(1, 4);
513
+ hsl[1] *= 0.01;
514
+ hsl[2] *= 0.01;
515
+ rgb = hsl2rgb(hsl);
516
+ rgb[3] = +m[4];
517
+ }
518
+ return rgb;
519
+ };
520
+
521
+ hex2rgb = function(hex) {
522
+ var a, b, g, r, rgb, u;
523
+
524
+ if (hex.match(/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)) {
525
+ if (hex.length === 4 || hex.length === 7) {
526
+ hex = hex.substr(1);
527
+ }
528
+ if (hex.length === 3) {
529
+ hex = hex.split("");
530
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
531
+ }
532
+ u = parseInt(hex, 16);
533
+ r = u >> 16;
534
+ g = u >> 8 & 0xFF;
535
+ b = u & 0xFF;
536
+ return [r, g, b, 1];
537
+ }
538
+ if (hex.match(/^#?([A-Fa-f0-9]{8})$/)) {
539
+ if (hex.length === 9) {
540
+ hex = hex.substr(1);
541
+ }
542
+ u = parseInt(hex, 16);
543
+ r = u >> 24 & 0xFF;
544
+ g = u >> 16 & 0xFF;
545
+ b = u >> 8 & 0xFF;
546
+ a = u & 0xFF;
547
+ return [r, g, b, a];
548
+ }
549
+ if (rgb = css2rgb(hex)) {
550
+ return rgb;
551
+ }
552
+ throw "unknown color: " + hex;
553
+ };
554
+
555
+ hsi2rgb = function(h, s, i) {
556
+ /*
557
+ borrowed from here:
558
+ http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/hsi2rgb.cpp
559
+ */
560
+
561
+ var b, g, r, _ref;
562
+
563
+ _ref = unpack(arguments), h = _ref[0], s = _ref[1], i = _ref[2];
564
+ h /= 360;
565
+ if (h < 1 / 3) {
566
+ b = (1 - s) / 3;
567
+ r = (1 + s * cos(TWOPI * h) / cos(PITHIRD - TWOPI * h)) / 3;
568
+ g = 1 - (b + r);
569
+ } else if (h < 2 / 3) {
570
+ h -= 1 / 3;
571
+ r = (1 - s) / 3;
572
+ g = (1 + s * cos(TWOPI * h) / cos(PITHIRD - TWOPI * h)) / 3;
573
+ b = 1 - (r + g);
574
+ } else {
575
+ h -= 2 / 3;
576
+ g = (1 - s) / 3;
577
+ b = (1 + s * cos(TWOPI * h) / cos(PITHIRD - TWOPI * h)) / 3;
578
+ r = 1 - (g + b);
579
+ }
580
+ r = limit(i * r * 3);
581
+ g = limit(i * g * 3);
582
+ b = limit(i * b * 3);
583
+ return [r * 255, g * 255, b * 255];
584
+ };
585
+
586
+ hsl2rgb = function() {
587
+ var b, c, g, h, i, l, r, s, t1, t2, t3, _i, _ref, _ref1;
588
+
589
+ _ref = unpack(arguments), h = _ref[0], s = _ref[1], l = _ref[2];
590
+ if (s === 0) {
591
+ r = g = b = l * 255;
592
+ } else {
593
+ t3 = [0, 0, 0];
594
+ c = [0, 0, 0];
595
+ t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
596
+ t1 = 2 * l - t2;
597
+ h /= 360;
598
+ t3[0] = h + 1 / 3;
599
+ t3[1] = h;
600
+ t3[2] = h - 1 / 3;
601
+ for (i = _i = 0; _i <= 2; i = ++_i) {
602
+ if (t3[i] < 0) {
603
+ t3[i] += 1;
604
+ }
605
+ if (t3[i] > 1) {
606
+ t3[i] -= 1;
607
+ }
608
+ if (6 * t3[i] < 1) {
609
+ c[i] = t1 + (t2 - t1) * 6 * t3[i];
610
+ } else if (2 * t3[i] < 1) {
611
+ c[i] = t2;
612
+ } else if (3 * t3[i] < 2) {
613
+ c[i] = t1 + (t2 - t1) * ((2 / 3) - t3[i]) * 6;
614
+ } else {
615
+ c[i] = t1;
616
+ }
617
+ }
618
+ _ref1 = [Math.round(c[0] * 255), Math.round(c[1] * 255), Math.round(c[2] * 255)], r = _ref1[0], g = _ref1[1], b = _ref1[2];
619
+ }
620
+ return [r, g, b];
621
+ };
622
+
623
+ hsv2rgb = function() {
624
+ var b, f, g, h, i, p, q, r, s, t, v, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
625
+
626
+ _ref = unpack(arguments), h = _ref[0], s = _ref[1], v = _ref[2];
627
+ v *= 255;
628
+ if (s === 0) {
629
+ r = g = b = v;
630
+ } else {
631
+ if (h === 360) {
632
+ h = 0;
633
+ }
634
+ if (h > 360) {
635
+ h -= 360;
636
+ }
637
+ if (h < 0) {
638
+ h += 360;
639
+ }
640
+ h /= 60;
641
+ i = Math.floor(h);
642
+ f = h - i;
643
+ p = v * (1 - s);
644
+ q = v * (1 - s * f);
645
+ t = v * (1 - s * (1 - f));
646
+ switch (i) {
647
+ case 0:
648
+ _ref1 = [v, t, p], r = _ref1[0], g = _ref1[1], b = _ref1[2];
649
+ break;
650
+ case 1:
651
+ _ref2 = [q, v, p], r = _ref2[0], g = _ref2[1], b = _ref2[2];
652
+ break;
653
+ case 2:
654
+ _ref3 = [p, v, t], r = _ref3[0], g = _ref3[1], b = _ref3[2];
655
+ break;
656
+ case 3:
657
+ _ref4 = [p, q, v], r = _ref4[0], g = _ref4[1], b = _ref4[2];
658
+ break;
659
+ case 4:
660
+ _ref5 = [t, p, v], r = _ref5[0], g = _ref5[1], b = _ref5[2];
661
+ break;
662
+ case 5:
663
+ _ref6 = [v, p, q], r = _ref6[0], g = _ref6[1], b = _ref6[2];
664
+ }
665
+ }
666
+ r = Math.round(r);
667
+ g = Math.round(g);
668
+ b = Math.round(b);
669
+ return [r, g, b];
670
+ };
671
+
672
+ K = 18;
673
+
674
+ X = 0.950470;
675
+
676
+ Y = 1;
677
+
678
+ Z = 1.088830;
679
+
680
+ lab2lch = function() {
681
+ var a, b, c, h, l, _ref;
682
+
683
+ _ref = unpack(arguments), l = _ref[0], a = _ref[1], b = _ref[2];
684
+ c = Math.sqrt(a * a + b * b);
685
+ h = Math.atan2(b, a) / Math.PI * 180;
686
+ return [l, c, h];
687
+ };
688
+
689
+ lab2rgb = function(l, a, b) {
690
+ /*
691
+ adapted to match d3 implementation
692
+ */
693
+
694
+ var g, r, x, y, z, _ref, _ref1;
695
+
696
+ if (l !== void 0 && l.length === 3) {
697
+ _ref = l, l = _ref[0], a = _ref[1], b = _ref[2];
698
+ }
699
+ if (l !== void 0 && l.length === 3) {
700
+ _ref1 = l, l = _ref1[0], a = _ref1[1], b = _ref1[2];
701
+ }
702
+ y = (l + 16) / 116;
703
+ x = y + a / 500;
704
+ z = y - b / 200;
705
+ x = lab_xyz(x) * X;
706
+ y = lab_xyz(y) * Y;
707
+ z = lab_xyz(z) * Z;
708
+ r = xyz_rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z);
709
+ g = xyz_rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z);
710
+ b = xyz_rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z);
711
+ return [limit(r, 0, 255), limit(g, 0, 255), limit(b, 0, 255), 1];
712
+ };
713
+
714
+ lab_xyz = function(x) {
715
+ if (x > 0.206893034) {
716
+ return x * x * x;
717
+ } else {
718
+ return (x - 4 / 29) / 7.787037;
719
+ }
720
+ };
721
+
722
+ xyz_rgb = function(r) {
723
+ return Math.round(255 * (r <= 0.00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - 0.055));
724
+ };
725
+
726
+ lch2lab = function() {
727
+ /*
728
+ Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel. These formulas were invented by David Dalrymple to obtain maximum contrast without going out of gamut if the parameters are in the range 0-1.
729
+ A saturation multiplier was added by Gregor Aisch
730
+ */
731
+
732
+ var c, h, l, _ref;
733
+
734
+ _ref = unpack(arguments), l = _ref[0], c = _ref[1], h = _ref[2];
735
+ h = h * Math.PI / 180;
736
+ return [l, Math.cos(h) * c, Math.sin(h) * c];
737
+ };
738
+
739
+ lch2rgb = function(l, c, h) {
740
+ var L, a, b, g, r, _ref, _ref1;
741
+
742
+ _ref = lch2lab(l, c, h), L = _ref[0], a = _ref[1], b = _ref[2];
743
+ _ref1 = lab2rgb(L, a, b), r = _ref1[0], g = _ref1[1], b = _ref1[2];
744
+ return [limit(r, 0, 255), limit(g, 0, 255), limit(b, 0, 255)];
745
+ };
746
+
747
+ luminance = function(r, g, b) {
748
+ var _ref;
749
+
750
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
751
+ r = luminance_x(r);
752
+ g = luminance_x(g);
753
+ b = luminance_x(b);
754
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
755
+ };
756
+
757
+ luminance_x = function(x) {
758
+ x /= 255;
759
+ if (x <= 0.03928) {
760
+ return x / 12.92;
761
+ } else {
762
+ return Math.pow((x + 0.055) / 1.055, 2.4);
763
+ }
764
+ };
765
+
766
+ rgb2hex = function() {
767
+ var b, g, r, str, u, _ref;
768
+
769
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
770
+ u = r << 16 | g << 8 | b;
771
+ str = "000000" + u.toString(16);
772
+ return "#" + str.substr(str.length - 6);
773
+ };
774
+
775
+ rgb2hsi = function() {
776
+ /*
777
+ borrowed from here:
778
+ http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/rgb2hsi.cpp
779
+ */
780
+
781
+ var TWOPI, b, g, h, i, min, r, s, _ref;
782
+
783
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
784
+ TWOPI = Math.PI * 2;
785
+ r /= 255;
786
+ g /= 255;
787
+ b /= 255;
788
+ min = Math.min(r, g, b);
789
+ i = (r + g + b) / 3;
790
+ s = 1 - min / i;
791
+ if (s === 0) {
792
+ h = 0;
793
+ } else {
794
+ h = ((r - g) + (r - b)) / 2;
795
+ h /= Math.sqrt((r - g) * (r - g) + (r - b) * (g - b));
796
+ h = Math.acos(h);
797
+ if (b > g) {
798
+ h = TWOPI - h;
799
+ }
800
+ h /= TWOPI;
801
+ }
802
+ return [h * 360, s, i];
803
+ };
804
+
805
+ rgb2hsl = function(r, g, b) {
806
+ var h, l, max, min, s, _ref;
807
+
808
+ if (r !== void 0 && r.length >= 3) {
809
+ _ref = r, r = _ref[0], g = _ref[1], b = _ref[2];
810
+ }
811
+ r /= 255;
812
+ g /= 255;
813
+ b /= 255;
814
+ min = Math.min(r, g, b);
815
+ max = Math.max(r, g, b);
816
+ l = (max + min) / 2;
817
+ if (max === min) {
818
+ s = 0;
819
+ h = Number.NaN;
820
+ } else {
821
+ s = l < 0.5 ? (max - min) / (max + min) : (max - min) / (2 - max - min);
822
+ }
823
+ if (r === max) {
824
+ h = (g - b) / (max - min);
825
+ } else if (g === max) {
826
+ h = 2 + (b - r) / (max - min);
827
+ } else if (b === max) {
828
+ h = 4 + (r - g) / (max - min);
829
+ }
830
+ h *= 60;
831
+ if (h < 0) {
832
+ h += 360;
833
+ }
834
+ return [h, s, l];
835
+ };
836
+
837
+ rgb2hsv = function() {
838
+ var b, delta, g, h, max, min, r, s, v, _ref;
839
+
840
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
841
+ min = Math.min(r, g, b);
842
+ max = Math.max(r, g, b);
843
+ delta = max - min;
844
+ v = max / 255.0;
845
+ if (max === 0) {
846
+ h = Number.NaN;
847
+ s = 0;
848
+ } else {
849
+ s = delta / max;
850
+ if (r === max) {
851
+ h = (g - b) / delta;
852
+ }
853
+ if (g === max) {
854
+ h = 2 + (b - r) / delta;
855
+ }
856
+ if (b === max) {
857
+ h = 4 + (r - g) / delta;
858
+ }
859
+ h *= 60;
860
+ if (h < 0) {
861
+ h += 360;
862
+ }
863
+ }
864
+ return [h, s, v];
865
+ };
866
+
867
+ rgb2lab = function() {
868
+ var b, g, r, x, y, z, _ref;
869
+
870
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
871
+ r = rgb_xyz(r);
872
+ g = rgb_xyz(g);
873
+ b = rgb_xyz(b);
874
+ x = xyz_lab((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / X);
875
+ y = xyz_lab((0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / Y);
876
+ z = xyz_lab((0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / Z);
877
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
878
+ };
879
+
880
+ rgb_xyz = function(r) {
881
+ if ((r /= 255) <= 0.04045) {
882
+ return r / 12.92;
883
+ } else {
884
+ return Math.pow((r + 0.055) / 1.055, 2.4);
885
+ }
886
+ };
887
+
888
+ xyz_lab = function(x) {
889
+ if (x > 0.008856) {
890
+ return Math.pow(x, 1 / 3);
891
+ } else {
892
+ return 7.787037 * x + 4 / 29;
893
+ }
894
+ };
895
+
896
+ rgb2lch = function() {
897
+ var a, b, g, l, r, _ref, _ref1;
898
+
899
+ _ref = unpack(arguments), r = _ref[0], g = _ref[1], b = _ref[2];
900
+ _ref1 = rgb2lab(r, g, b), l = _ref1[0], a = _ref1[1], b = _ref1[2];
901
+ return lab2lch(l, a, b);
902
+ };
903
+
904
+ /*
905
+ chroma.js
906
+
907
+ Copyright (c) 2011-2013, Gregor Aisch
908
+ All rights reserved.
909
+
910
+ Redistribution and use in source and binary forms, with or without
911
+ modification, are permitted provided that the following conditions are met:
912
+
913
+ * Redistributions of source code must retain the above copyright notice, this
914
+ list of conditions and the following disclaimer.
915
+
916
+ * Redistributions in binary form must reproduce the above copyright notice,
917
+ this list of conditions and the following disclaimer in the documentation
918
+ and/or other materials provided with the distribution.
919
+
920
+ * The name Gregor Aisch may not be used to endorse or promote products
921
+ derived from this software without specific prior written permission.
922
+
923
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
924
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
925
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
926
+ DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
927
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
928
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
929
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
930
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
931
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
932
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
933
+
934
+ @source: https://github.com/gka/chroma.js
935
+ */
936
+
937
+
938
+ chroma.scale = function(colors, positions) {
939
+ var classifyValue, f, getClass, getColor, resetCache, setColors, setDomain, tmap, _colorCache, _colors, _correctLightness, _domain, _fixed, _max, _min, _mode, _nacol, _numClasses, _out, _pos, _spread;
940
+
941
+ _mode = 'rgb';
942
+ _nacol = chroma('#ccc');
943
+ _spread = 0;
944
+ _fixed = false;
945
+ _domain = [0, 1];
946
+ _colors = [];
947
+ _out = false;
948
+ _pos = [];
949
+ _min = 0;
950
+ _max = 1;
951
+ _correctLightness = false;
952
+ _numClasses = 0;
953
+ _colorCache = {};
954
+ setColors = function(colors, positions) {
955
+ var c, col, _i, _j, _ref, _ref1, _ref2;
956
+
957
+ if (colors == null) {
958
+ colors = ['#ddd', '#222'];
959
+ }
960
+ if ((colors != null) && type(colors) === 'string' && (((_ref = chroma.brewer) != null ? _ref[colors] : void 0) != null)) {
961
+ colors = chroma.brewer[colors];
962
+ }
963
+ if (type(colors) === 'array') {
964
+ colors = colors.slice(0);
965
+ for (c = _i = 0, _ref1 = colors.length - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; c = 0 <= _ref1 ? ++_i : --_i) {
966
+ col = colors[c];
967
+ if (type(col) === "string") {
968
+ colors[c] = chroma(col);
969
+ }
970
+ }
971
+ if (positions != null) {
972
+ _pos = positions;
973
+ } else {
974
+ _pos = [];
975
+ for (c = _j = 0, _ref2 = colors.length - 1; 0 <= _ref2 ? _j <= _ref2 : _j >= _ref2; c = 0 <= _ref2 ? ++_j : --_j) {
976
+ _pos.push(c / (colors.length - 1));
977
+ }
978
+ }
979
+ }
980
+ resetCache();
981
+ return _colors = colors;
982
+ };
983
+ setDomain = function(domain) {
984
+ if (domain == null) {
985
+ domain = [];
986
+ }
987
+ /*
988
+ # use this if you want to display a limited number of data classes
989
+ # possible methods are "equalinterval", "quantiles", "custom"
990
+ */
991
+
992
+ _domain = domain;
993
+ _min = domain[0];
994
+ _max = domain[domain.length - 1];
995
+ resetCache();
996
+ if (domain.length === 2) {
997
+ return _numClasses = 0;
998
+ } else {
999
+ return _numClasses = domain.length - 1;
1000
+ }
1001
+ };
1002
+ getClass = function(value) {
1003
+ var i, n;
1004
+
1005
+ if (_domain != null) {
1006
+ n = _domain.length - 1;
1007
+ i = 0;
1008
+ while (i < n && value >= _domain[i]) {
1009
+ i++;
1010
+ }
1011
+ return i - 1;
1012
+ }
1013
+ return 0;
1014
+ };
1015
+ tmap = function(t) {
1016
+ return t;
1017
+ };
1018
+ classifyValue = function(value) {
1019
+ var i, maxc, minc, n, val;
1020
+
1021
+ val = value;
1022
+ if (_domain.length > 2) {
1023
+ n = _domain.length - 1;
1024
+ i = getClass(value);
1025
+ minc = _domain[0] + (_domain[1] - _domain[0]) * (0 + _spread * 0.5);
1026
+ maxc = _domain[n - 1] + (_domain[n] - _domain[n - 1]) * (1 - _spread * 0.5);
1027
+ val = _min + ((_domain[i] + (_domain[i + 1] - _domain[i]) * 0.5 - minc) / (maxc - minc)) * (_max - _min);
1028
+ }
1029
+ return val;
1030
+ };
1031
+ getColor = function(val, bypassMap) {
1032
+ var c, col, f0, i, k, p, t, _i, _ref;
1033
+
1034
+ if (bypassMap == null) {
1035
+ bypassMap = false;
1036
+ }
1037
+ if (isNaN(val)) {
1038
+ return _nacol;
1039
+ }
1040
+ if (!bypassMap) {
1041
+ if (_domain.length > 2) {
1042
+ c = getClass(val);
1043
+ t = c / (_numClasses - 1);
1044
+ } else {
1045
+ t = f0 = (val - _min) / (_max - _min);
1046
+ t = Math.min(1, Math.max(0, t));
1047
+ }
1048
+ } else {
1049
+ t = val;
1050
+ }
1051
+ if (!bypassMap) {
1052
+ t = tmap(t);
1053
+ }
1054
+ k = Math.floor(t * 10000);
1055
+ if (_colorCache[k]) {
1056
+ col = _colorCache[k];
1057
+ } else {
1058
+ if (type(_colors) === 'array') {
1059
+ for (i = _i = 0, _ref = _pos.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
1060
+ p = _pos[i];
1061
+ if (t <= p) {
1062
+ col = _colors[i];
1063
+ break;
1064
+ }
1065
+ if (t >= p && i === _pos.length - 1) {
1066
+ col = _colors[i];
1067
+ break;
1068
+ }
1069
+ if (t > p && t < _pos[i + 1]) {
1070
+ t = (t - p) / (_pos[i + 1] - p);
1071
+ col = chroma.interpolate(_colors[i], _colors[i + 1], t, _mode);
1072
+ break;
1073
+ }
1074
+ }
1075
+ } else if (type(_colors) === 'function') {
1076
+ col = _colors(t);
1077
+ }
1078
+ _colorCache[k] = col;
1079
+ }
1080
+ return col;
1081
+ };
1082
+ resetCache = function() {
1083
+ return _colorCache = {};
1084
+ };
1085
+ setColors(colors, positions);
1086
+ f = function(v) {
1087
+ var c;
1088
+
1089
+ c = getColor(v);
1090
+ if (_out && c[_out]) {
1091
+ return c[_out]();
1092
+ } else {
1093
+ return c;
1094
+ }
1095
+ };
1096
+ f.domain = function(domain, classes, mode, key) {
1097
+ var d;
1098
+
1099
+ if (mode == null) {
1100
+ mode = 'e';
1101
+ }
1102
+ if (!arguments.length) {
1103
+ return _domain;
1104
+ }
1105
+ if (classes != null) {
1106
+ d = chroma.analyze(domain, key);
1107
+ if (classes === 0) {
1108
+ domain = [d.min, d.max];
1109
+ } else {
1110
+ domain = chroma.limits(d, mode, classes);
1111
+ }
1112
+ }
1113
+ setDomain(domain);
1114
+ return f;
1115
+ };
1116
+ f.mode = function(_m) {
1117
+ if (!arguments.length) {
1118
+ return _mode;
1119
+ }
1120
+ _mode = _m;
1121
+ resetCache();
1122
+ return f;
1123
+ };
1124
+ f.range = function(colors, _pos) {
1125
+ setColors(colors, _pos);
1126
+ return f;
1127
+ };
1128
+ f.out = function(_o) {
1129
+ _out = _o;
1130
+ return f;
1131
+ };
1132
+ f.spread = function(val) {
1133
+ if (!arguments.length) {
1134
+ return _spread;
1135
+ }
1136
+ _spread = val;
1137
+ return f;
1138
+ };
1139
+ f.correctLightness = function(v) {
1140
+ if (!arguments.length) {
1141
+ return _correctLightness;
1142
+ }
1143
+ _correctLightness = v;
1144
+ resetCache();
1145
+ if (_correctLightness) {
1146
+ tmap = function(t) {
1147
+ var L0, L1, L_actual, L_diff, L_ideal, max_iter, pol, t0, t1;
1148
+
1149
+ L0 = getColor(0, true).lab()[0];
1150
+ L1 = getColor(1, true).lab()[0];
1151
+ pol = L0 > L1;
1152
+ L_actual = getColor(t, true).lab()[0];
1153
+ L_ideal = L0 + (L1 - L0) * t;
1154
+ L_diff = L_actual - L_ideal;
1155
+ t0 = 0;
1156
+ t1 = 1;
1157
+ max_iter = 20;
1158
+ while (Math.abs(L_diff) > 1e-2 && max_iter-- > 0) {
1159
+ (function() {
1160
+ if (pol) {
1161
+ L_diff *= -1;
1162
+ }
1163
+ if (L_diff < 0) {
1164
+ t0 = t;
1165
+ t += (t1 - t) * 0.5;
1166
+ } else {
1167
+ t1 = t;
1168
+ t += (t0 - t) * 0.5;
1169
+ }
1170
+ L_actual = getColor(t, true).lab()[0];
1171
+ return L_diff = L_actual - L_ideal;
1172
+ })();
1173
+ }
1174
+ return t;
1175
+ };
1176
+ } else {
1177
+ tmap = function(t) {
1178
+ return t;
1179
+ };
1180
+ }
1181
+ return f;
1182
+ };
1183
+ f.colors = function(out) {
1184
+ var i, samples, _i, _j, _len, _ref;
1185
+
1186
+ if (out == null) {
1187
+ out = 'hex';
1188
+ }
1189
+ colors = [];
1190
+ samples = [];
1191
+ if (_domain.length > 2) {
1192
+ for (i = _i = 1, _ref = _domain.length; 1 <= _ref ? _i < _ref : _i > _ref; i = 1 <= _ref ? ++_i : --_i) {
1193
+ samples.push((_domain[i - 1] + _domain[i]) * 0.5);
1194
+ }
1195
+ } else {
1196
+ samples = _domain;
1197
+ }
1198
+ for (_j = 0, _len = samples.length; _j < _len; _j++) {
1199
+ i = samples[_j];
1200
+ colors.push(f(i)[out]());
1201
+ }
1202
+ return colors;
1203
+ };
1204
+ return f;
1205
+ };
1206
+
1207
+ if ((_ref = chroma.scales) == null) {
1208
+ chroma.scales = {};
1209
+ }
1210
+
1211
+ chroma.scales.cool = function() {
1212
+ return chroma.scale([chroma.hsl(180, 1, .9), chroma.hsl(250, .7, .4)]);
1213
+ };
1214
+
1215
+ chroma.scales.hot = function() {
1216
+ return chroma.scale(['#000', '#f00', '#ff0', '#fff'], [0, .25, .75, 1]).mode('rgb');
1217
+ };
1218
+
1219
+ /*
1220
+ chroma.js
1221
+
1222
+ Copyright (c) 2011-2013, Gregor Aisch
1223
+ All rights reserved.
1224
+
1225
+ Redistribution and use in source and binary forms, with or without
1226
+ modification, are permitted provided that the following conditions are met:
1227
+
1228
+ * Redistributions of source code must retain the above copyright notice, this
1229
+ list of conditions and the following disclaimer.
1230
+
1231
+ * Redistributions in binary form must reproduce the above copyright notice,
1232
+ this list of conditions and the following disclaimer in the documentation
1233
+ and/or other materials provided with the distribution.
1234
+
1235
+ * The name Gregor Aisch may not be used to endorse or promote products
1236
+ derived from this software without specific prior written permission.
1237
+
1238
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1239
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1240
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1241
+ DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
1242
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1243
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1244
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1245
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1246
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
1247
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1248
+
1249
+ @source: https://github.com/gka/chroma.js
1250
+ */
1251
+
1252
+
1253
+ chroma.analyze = function(data, key, filter) {
1254
+ var add, k, r, val, visit, _i, _len;
1255
+
1256
+ r = {
1257
+ min: Number.MAX_VALUE,
1258
+ max: Number.MAX_VALUE * -1,
1259
+ sum: 0,
1260
+ values: [],
1261
+ count: 0
1262
+ };
1263
+ if (filter == null) {
1264
+ filter = function() {
1265
+ return true;
1266
+ };
1267
+ }
1268
+ add = function(val) {
1269
+ if ((val != null) && !isNaN(val)) {
1270
+ r.values.push(val);
1271
+ r.sum += val;
1272
+ if (val < r.min) {
1273
+ r.min = val;
1274
+ }
1275
+ if (val > r.max) {
1276
+ r.max = val;
1277
+ }
1278
+ r.count += 1;
1279
+ }
1280
+ };
1281
+ visit = function(val, k) {
1282
+ if (filter(val, k)) {
1283
+ if ((key != null) && type(key) === 'function') {
1284
+ return add(key(val));
1285
+ } else if ((key != null) && type(key) === 'string' || type(key) === 'number') {
1286
+ return add(val[key]);
1287
+ } else {
1288
+ return add(val);
1289
+ }
1290
+ }
1291
+ };
1292
+ if (type(data) === 'array') {
1293
+ for (_i = 0, _len = data.length; _i < _len; _i++) {
1294
+ val = data[_i];
1295
+ visit(val);
1296
+ }
1297
+ } else {
1298
+ for (k in data) {
1299
+ val = data[k];
1300
+ visit(val, k);
1301
+ }
1302
+ }
1303
+ r.domain = [r.min, r.max];
1304
+ r.limits = function(mode, num) {
1305
+ return chroma.limits(r, mode, num);
1306
+ };
1307
+ return r;
1308
+ };
1309
+
1310
+ chroma.limits = function(data, mode, num) {
1311
+ var assignments, best, centroids, cluster, clusterSizes, dist, i, j, kClusters, limits, max, max_log, min, min_log, mindist, n, nb_iters, newCentroids, p, pb, pr, repeat, sum, tmpKMeansBreaks, value, values, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _s, _t, _u, _v, _w;
1312
+
1313
+ if (mode == null) {
1314
+ mode = 'equal';
1315
+ }
1316
+ if (num == null) {
1317
+ num = 7;
1318
+ }
1319
+ if (type(data) === 'array') {
1320
+ data = chroma.analyze(data);
1321
+ }
1322
+ min = data.min;
1323
+ max = data.max;
1324
+ sum = data.sum;
1325
+ values = data.values.sort(function(a, b) {
1326
+ return a - b;
1327
+ });
1328
+ limits = [];
1329
+ if (mode.substr(0, 1) === 'c') {
1330
+ limits.push(min);
1331
+ limits.push(max);
1332
+ }
1333
+ if (mode.substr(0, 1) === 'e') {
1334
+ limits.push(min);
1335
+ for (i = _i = 1, _ref1 = num - 1; 1 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 1 <= _ref1 ? ++_i : --_i) {
1336
+ limits.push(min + (i / num) * (max - min));
1337
+ }
1338
+ limits.push(max);
1339
+ } else if (mode.substr(0, 1) === 'l') {
1340
+ if (min <= 0) {
1341
+ throw 'Logarithmic scales are only possible for values > 0';
1342
+ }
1343
+ min_log = Math.LOG10E * Math.log(min);
1344
+ max_log = Math.LOG10E * Math.log(max);
1345
+ limits.push(min);
1346
+ for (i = _j = 1, _ref2 = num - 1; 1 <= _ref2 ? _j <= _ref2 : _j >= _ref2; i = 1 <= _ref2 ? ++_j : --_j) {
1347
+ limits.push(Math.pow(10, min_log + (i / num) * (max_log - min_log)));
1348
+ }
1349
+ limits.push(max);
1350
+ } else if (mode.substr(0, 1) === 'q') {
1351
+ limits.push(min);
1352
+ for (i = _k = 1, _ref3 = num - 1; 1 <= _ref3 ? _k <= _ref3 : _k >= _ref3; i = 1 <= _ref3 ? ++_k : --_k) {
1353
+ p = values.length * i / num;
1354
+ pb = Math.floor(p);
1355
+ if (pb === p) {
1356
+ limits.push(values[pb]);
1357
+ } else {
1358
+ pr = p - pb;
1359
+ limits.push(values[pb] * pr + values[pb + 1] * (1 - pr));
1360
+ }
1361
+ }
1362
+ limits.push(max);
1363
+ } else if (mode.substr(0, 1) === 'k') {
1364
+ /*
1365
+ implementation based on
1366
+ http://code.google.com/p/figue/source/browse/trunk/figue.js#336
1367
+ simplified for 1-d input values
1368
+ */
1369
+
1370
+ n = values.length;
1371
+ assignments = new Array(n);
1372
+ clusterSizes = new Array(num);
1373
+ repeat = true;
1374
+ nb_iters = 0;
1375
+ centroids = null;
1376
+ centroids = [];
1377
+ centroids.push(min);
1378
+ for (i = _l = 1, _ref4 = num - 1; 1 <= _ref4 ? _l <= _ref4 : _l >= _ref4; i = 1 <= _ref4 ? ++_l : --_l) {
1379
+ centroids.push(min + (i / num) * (max - min));
1380
+ }
1381
+ centroids.push(max);
1382
+ while (repeat) {
1383
+ for (j = _m = 0, _ref5 = num - 1; 0 <= _ref5 ? _m <= _ref5 : _m >= _ref5; j = 0 <= _ref5 ? ++_m : --_m) {
1384
+ clusterSizes[j] = 0;
1385
+ }
1386
+ for (i = _n = 0, _ref6 = n - 1; 0 <= _ref6 ? _n <= _ref6 : _n >= _ref6; i = 0 <= _ref6 ? ++_n : --_n) {
1387
+ value = values[i];
1388
+ mindist = Number.MAX_VALUE;
1389
+ for (j = _o = 0, _ref7 = num - 1; 0 <= _ref7 ? _o <= _ref7 : _o >= _ref7; j = 0 <= _ref7 ? ++_o : --_o) {
1390
+ dist = Math.abs(centroids[j] - value);
1391
+ if (dist < mindist) {
1392
+ mindist = dist;
1393
+ best = j;
1394
+ }
1395
+ }
1396
+ clusterSizes[best]++;
1397
+ assignments[i] = best;
1398
+ }
1399
+ newCentroids = new Array(num);
1400
+ for (j = _p = 0, _ref8 = num - 1; 0 <= _ref8 ? _p <= _ref8 : _p >= _ref8; j = 0 <= _ref8 ? ++_p : --_p) {
1401
+ newCentroids[j] = null;
1402
+ }
1403
+ for (i = _q = 0, _ref9 = n - 1; 0 <= _ref9 ? _q <= _ref9 : _q >= _ref9; i = 0 <= _ref9 ? ++_q : --_q) {
1404
+ cluster = assignments[i];
1405
+ if (newCentroids[cluster] === null) {
1406
+ newCentroids[cluster] = values[i];
1407
+ } else {
1408
+ newCentroids[cluster] += values[i];
1409
+ }
1410
+ }
1411
+ for (j = _r = 0, _ref10 = num - 1; 0 <= _ref10 ? _r <= _ref10 : _r >= _ref10; j = 0 <= _ref10 ? ++_r : --_r) {
1412
+ newCentroids[j] *= 1 / clusterSizes[j];
1413
+ }
1414
+ repeat = false;
1415
+ for (j = _s = 0, _ref11 = num - 1; 0 <= _ref11 ? _s <= _ref11 : _s >= _ref11; j = 0 <= _ref11 ? ++_s : --_s) {
1416
+ if (newCentroids[j] !== centroids[i]) {
1417
+ repeat = true;
1418
+ break;
1419
+ }
1420
+ }
1421
+ centroids = newCentroids;
1422
+ nb_iters++;
1423
+ if (nb_iters > 200) {
1424
+ repeat = false;
1425
+ }
1426
+ }
1427
+ kClusters = {};
1428
+ for (j = _t = 0, _ref12 = num - 1; 0 <= _ref12 ? _t <= _ref12 : _t >= _ref12; j = 0 <= _ref12 ? ++_t : --_t) {
1429
+ kClusters[j] = [];
1430
+ }
1431
+ for (i = _u = 0, _ref13 = n - 1; 0 <= _ref13 ? _u <= _ref13 : _u >= _ref13; i = 0 <= _ref13 ? ++_u : --_u) {
1432
+ cluster = assignments[i];
1433
+ kClusters[cluster].push(values[i]);
1434
+ }
1435
+ tmpKMeansBreaks = [];
1436
+ for (j = _v = 0, _ref14 = num - 1; 0 <= _ref14 ? _v <= _ref14 : _v >= _ref14; j = 0 <= _ref14 ? ++_v : --_v) {
1437
+ tmpKMeansBreaks.push(kClusters[j][0]);
1438
+ tmpKMeansBreaks.push(kClusters[j][kClusters[j].length - 1]);
1439
+ }
1440
+ tmpKMeansBreaks = tmpKMeansBreaks.sort(function(a, b) {
1441
+ return a - b;
1442
+ });
1443
+ limits.push(tmpKMeansBreaks[0]);
1444
+ for (i = _w = 1, _ref15 = tmpKMeansBreaks.length - 1; _w <= _ref15; i = _w += 2) {
1445
+ if (!isNaN(tmpKMeansBreaks[i])) {
1446
+ limits.push(tmpKMeansBreaks[i]);
1447
+ }
1448
+ }
1449
+ }
1450
+ return limits;
1451
+ };
1452
+
1453
+ /**
1454
+ ColorBrewer colors for chroma.js
1455
+
1456
+ Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The
1457
+ Pennsylvania State University.
1458
+
1459
+ Licensed under the Apache License, Version 2.0 (the "License");
1460
+ you may not use this file except in compliance with the License.
1461
+ You may obtain a copy of the License at
1462
+ http://www.apache.org/licenses/LICENSE-2.0
1463
+
1464
+ Unless required by applicable law or agreed to in writing, software distributed
1465
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
1466
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
1467
+ specific language governing permissions and limitations under the License.
1468
+
1469
+ @preserve
1470
+ */
1471
+
1472
+
1473
+ chroma.brewer = brewer = {
1474
+ OrRd: ['#fff7ec', '#fee8c8', '#fdd49e', '#fdbb84', '#fc8d59', '#ef6548', '#d7301f', '#b30000', '#7f0000'],
1475
+ PuBu: ['#fff7fb', '#ece7f2', '#d0d1e6', '#a6bddb', '#74a9cf', '#3690c0', '#0570b0', '#045a8d', '#023858'],
1476
+ BuPu: ['#f7fcfd', '#e0ecf4', '#bfd3e6', '#9ebcda', '#8c96c6', '#8c6bb1', '#88419d', '#810f7c', '#4d004b'],
1477
+ Oranges: ['#fff5eb', '#fee6ce', '#fdd0a2', '#fdae6b', '#fd8d3c', '#f16913', '#d94801', '#a63603', '#7f2704'],
1478
+ BuGn: ['#f7fcfd', '#e5f5f9', '#ccece6', '#99d8c9', '#66c2a4', '#41ae76', '#238b45', '#006d2c', '#00441b'],
1479
+ YlOrBr: ['#ffffe5', '#fff7bc', '#fee391', '#fec44f', '#fe9929', '#ec7014', '#cc4c02', '#993404', '#662506'],
1480
+ YlGn: ['#ffffe5', '#f7fcb9', '#d9f0a3', '#addd8e', '#78c679', '#41ab5d', '#238443', '#006837', '#004529'],
1481
+ Reds: ['#fff5f0', '#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#a50f15', '#67000d'],
1482
+ RdPu: ['#fff7f3', '#fde0dd', '#fcc5c0', '#fa9fb5', '#f768a1', '#dd3497', '#ae017e', '#7a0177', '#49006a'],
1483
+ Greens: ['#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'],
1484
+ YlGnBu: ['#ffffd9', '#edf8b1', '#c7e9b4', '#7fcdbb', '#41b6c4', '#1d91c0', '#225ea8', '#253494', '#081d58'],
1485
+ Purples: ['#fcfbfd', '#efedf5', '#dadaeb', '#bcbddc', '#9e9ac8', '#807dba', '#6a51a3', '#54278f', '#3f007d'],
1486
+ GnBu: ['#f7fcf0', '#e0f3db', '#ccebc5', '#a8ddb5', '#7bccc4', '#4eb3d3', '#2b8cbe', '#0868ac', '#084081'],
1487
+ Greys: ['#ffffff', '#f0f0f0', '#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525', '#000000'],
1488
+ YlOrRd: ['#ffffcc', '#ffeda0', '#fed976', '#feb24c', '#fd8d3c', '#fc4e2a', '#e31a1c', '#bd0026', '#800026'],
1489
+ PuRd: ['#f7f4f9', '#e7e1ef', '#d4b9da', '#c994c7', '#df65b0', '#e7298a', '#ce1256', '#980043', '#67001f'],
1490
+ Blues: ['#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'],
1491
+ PuBuGn: ['#fff7fb', '#ece2f0', '#d0d1e6', '#a6bddb', '#67a9cf', '#3690c0', '#02818a', '#016c59', '#014636'],
1492
+ Spectral: ['#9e0142', '#d53e4f', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#e6f598', '#abdda4', '#66c2a5', '#3288bd', '#5e4fa2'],
1493
+ RdYlGn: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850', '#006837'],
1494
+ RdBu: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'],
1495
+ PiYG: ['#8e0152', '#c51b7d', '#de77ae', '#f1b6da', '#fde0ef', '#f7f7f7', '#e6f5d0', '#b8e186', '#7fbc41', '#4d9221', '#276419'],
1496
+ PRGn: ['#40004b', '#762a83', '#9970ab', '#c2a5cf', '#e7d4e8', '#f7f7f7', '#d9f0d3', '#a6dba0', '#5aae61', '#1b7837', '#00441b'],
1497
+ RdYlBu: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8', '#abd9e9', '#74add1', '#4575b4', '#313695'],
1498
+ BrBG: ['#543005', '#8c510a', '#bf812d', '#dfc27d', '#f6e8c3', '#f5f5f5', '#c7eae5', '#80cdc1', '#35978f', '#01665e', '#003c30'],
1499
+ RdGy: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#ffffff', '#e0e0e0', '#bababa', '#878787', '#4d4d4d', '#1a1a1a'],
1500
+ PuOr: ['#7f3b08', '#b35806', '#e08214', '#fdb863', '#fee0b6', '#f7f7f7', '#d8daeb', '#b2abd2', '#8073ac', '#542788', '#2d004b'],
1501
+ Set2: ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494', '#b3b3b3'],
1502
+ Accent: ['#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f', '#bf5b17', '#666666'],
1503
+ Set1: ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'],
1504
+ Set3: ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f'],
1505
+ Dark2: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'],
1506
+ Paired: ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'],
1507
+ Pastel2: ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'],
1508
+ Pastel1: ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec', '#f2f2f2']
1509
+ };
1510
+
1511
+ /**
1512
+ X11 color names
1513
+
1514
+ http://www.w3.org/TR/css3-color/#svg-color
1515
+ */
1516
+
1517
+
1518
+ chroma.colors = colors = {
1519
+ indigo: "#4b0082",
1520
+ gold: "#ffd700",
1521
+ hotpink: "#ff69b4",
1522
+ firebrick: "#b22222",
1523
+ indianred: "#cd5c5c",
1524
+ yellow: "#ffff00",
1525
+ mistyrose: "#ffe4e1",
1526
+ darkolivegreen: "#556b2f",
1527
+ olive: "#808000",
1528
+ darkseagreen: "#8fbc8f",
1529
+ pink: "#ffc0cb",
1530
+ tomato: "#ff6347",
1531
+ lightcoral: "#f08080",
1532
+ orangered: "#ff4500",
1533
+ navajowhite: "#ffdead",
1534
+ lime: "#00ff00",
1535
+ palegreen: "#98fb98",
1536
+ darkslategrey: "#2f4f4f",
1537
+ greenyellow: "#adff2f",
1538
+ burlywood: "#deb887",
1539
+ seashell: "#fff5ee",
1540
+ mediumspringgreen: "#00fa9a",
1541
+ fuchsia: "#ff00ff",
1542
+ papayawhip: "#ffefd5",
1543
+ blanchedalmond: "#ffebcd",
1544
+ chartreuse: "#7fff00",
1545
+ dimgray: "#696969",
1546
+ black: "#000000",
1547
+ peachpuff: "#ffdab9",
1548
+ springgreen: "#00ff7f",
1549
+ aquamarine: "#7fffd4",
1550
+ white: "#ffffff",
1551
+ orange: "#ffa500",
1552
+ lightsalmon: "#ffa07a",
1553
+ darkslategray: "#2f4f4f",
1554
+ brown: "#a52a2a",
1555
+ ivory: "#fffff0",
1556
+ dodgerblue: "#1e90ff",
1557
+ peru: "#cd853f",
1558
+ lawngreen: "#7cfc00",
1559
+ chocolate: "#d2691e",
1560
+ crimson: "#dc143c",
1561
+ forestgreen: "#228b22",
1562
+ darkgrey: "#a9a9a9",
1563
+ lightseagreen: "#20b2aa",
1564
+ cyan: "#00ffff",
1565
+ mintcream: "#f5fffa",
1566
+ silver: "#c0c0c0",
1567
+ antiquewhite: "#faebd7",
1568
+ mediumorchid: "#ba55d3",
1569
+ skyblue: "#87ceeb",
1570
+ gray: "#808080",
1571
+ darkturquoise: "#00ced1",
1572
+ goldenrod: "#daa520",
1573
+ darkgreen: "#006400",
1574
+ floralwhite: "#fffaf0",
1575
+ darkviolet: "#9400d3",
1576
+ darkgray: "#a9a9a9",
1577
+ moccasin: "#ffe4b5",
1578
+ saddlebrown: "#8b4513",
1579
+ grey: "#808080",
1580
+ darkslateblue: "#483d8b",
1581
+ lightskyblue: "#87cefa",
1582
+ lightpink: "#ffb6c1",
1583
+ mediumvioletred: "#c71585",
1584
+ slategrey: "#708090",
1585
+ red: "#ff0000",
1586
+ deeppink: "#ff1493",
1587
+ limegreen: "#32cd32",
1588
+ darkmagenta: "#8b008b",
1589
+ palegoldenrod: "#eee8aa",
1590
+ plum: "#dda0dd",
1591
+ turquoise: "#40e0d0",
1592
+ lightgrey: "#d3d3d3",
1593
+ lightgoldenrodyellow: "#fafad2",
1594
+ darkgoldenrod: "#b8860b",
1595
+ lavender: "#e6e6fa",
1596
+ maroon: "#800000",
1597
+ yellowgreen: "#9acd32",
1598
+ sandybrown: "#f4a460",
1599
+ thistle: "#d8bfd8",
1600
+ violet: "#ee82ee",
1601
+ navy: "#000080",
1602
+ magenta: "#ff00ff",
1603
+ dimgrey: "#696969",
1604
+ tan: "#d2b48c",
1605
+ rosybrown: "#bc8f8f",
1606
+ olivedrab: "#6b8e23",
1607
+ blue: "#0000ff",
1608
+ lightblue: "#add8e6",
1609
+ ghostwhite: "#f8f8ff",
1610
+ honeydew: "#f0fff0",
1611
+ cornflowerblue: "#6495ed",
1612
+ slateblue: "#6a5acd",
1613
+ linen: "#faf0e6",
1614
+ darkblue: "#00008b",
1615
+ powderblue: "#b0e0e6",
1616
+ seagreen: "#2e8b57",
1617
+ darkkhaki: "#bdb76b",
1618
+ snow: "#fffafa",
1619
+ sienna: "#a0522d",
1620
+ mediumblue: "#0000cd",
1621
+ royalblue: "#4169e1",
1622
+ lightcyan: "#e0ffff",
1623
+ green: "#008000",
1624
+ mediumpurple: "#9370db",
1625
+ midnightblue: "#191970",
1626
+ cornsilk: "#fff8dc",
1627
+ paleturquoise: "#afeeee",
1628
+ bisque: "#ffe4c4",
1629
+ slategray: "#708090",
1630
+ darkcyan: "#008b8b",
1631
+ khaki: "#f0e68c",
1632
+ wheat: "#f5deb3",
1633
+ teal: "#008080",
1634
+ darkorchid: "#9932cc",
1635
+ deepskyblue: "#00bfff",
1636
+ salmon: "#fa8072",
1637
+ darkred: "#8b0000",
1638
+ steelblue: "#4682b4",
1639
+ palevioletred: "#db7093",
1640
+ lightslategray: "#778899",
1641
+ aliceblue: "#f0f8ff",
1642
+ lightslategrey: "#778899",
1643
+ lightgreen: "#90ee90",
1644
+ orchid: "#da70d6",
1645
+ gainsboro: "#dcdcdc",
1646
+ mediumseagreen: "#3cb371",
1647
+ lightgray: "#d3d3d3",
1648
+ mediumturquoise: "#48d1cc",
1649
+ lemonchiffon: "#fffacd",
1650
+ cadetblue: "#5f9ea0",
1651
+ lightyellow: "#ffffe0",
1652
+ lavenderblush: "#fff0f5",
1653
+ coral: "#ff7f50",
1654
+ purple: "#800080",
1655
+ aqua: "#00ffff",
1656
+ whitesmoke: "#f5f5f5",
1657
+ mediumslateblue: "#7b68ee",
1658
+ darkorange: "#ff8c00",
1659
+ mediumaquamarine: "#66cdaa",
1660
+ darksalmon: "#e9967a",
1661
+ beige: "#f5f5dc",
1662
+ blueviolet: "#8a2be2",
1663
+ azure: "#f0ffff",
1664
+ lightsteelblue: "#b0c4de",
1665
+ oldlace: "#fdf5e6"
1666
+ };
1667
+
1668
+ /*
1669
+ chroma.js
1670
+
1671
+ Copyright (c) 2011-2013, Gregor Aisch
1672
+ All rights reserved.
1673
+
1674
+ Redistribution and use in source and binary forms, with or without
1675
+ modification, are permitted provided that the following conditions are met:
1676
+
1677
+ * Redistributions of source code must retain the above copyright notice, this
1678
+ list of conditions and the following disclaimer.
1679
+
1680
+ * Redistributions in binary form must reproduce the above copyright notice,
1681
+ this list of conditions and the following disclaimer in the documentation
1682
+ and/or other materials provided with the distribution.
1683
+
1684
+ * The name Gregor Aisch may not be used to endorse or promote products
1685
+ derived from this software without specific prior written permission.
1686
+
1687
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1688
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1689
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1690
+ DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
1691
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1692
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1693
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1694
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1695
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
1696
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1697
+
1698
+ @source: https://github.com/gka/chroma.js
1699
+ */
1700
+
1701
+
1702
+ type = (function() {
1703
+ /*
1704
+ for browser-safe type checking+
1705
+ ported from jQuery's $.type
1706
+ */
1707
+
1708
+ var classToType, name, _i, _len, _ref1;
1709
+
1710
+ classToType = {};
1711
+ _ref1 = "Boolean Number String Function Array Date RegExp Undefined Null".split(" ");
1712
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1713
+ name = _ref1[_i];
1714
+ classToType["[object " + name + "]"] = name.toLowerCase();
1715
+ }
1716
+ return function(obj) {
1717
+ var strType;
1718
+
1719
+ strType = Object.prototype.toString.call(obj);
1720
+ return classToType[strType] || "object";
1721
+ };
1722
+ })();
1723
+
1724
+ limit = function(x, min, max) {
1725
+ if (min == null) {
1726
+ min = 0;
1727
+ }
1728
+ if (max == null) {
1729
+ max = 1;
1730
+ }
1731
+ if (x < min) {
1732
+ x = min;
1733
+ }
1734
+ if (x > max) {
1735
+ x = max;
1736
+ }
1737
+ return x;
1738
+ };
1739
+
1740
+ unpack = function(args) {
1741
+ if (args.length >= 3) {
1742
+ return args;
1743
+ } else {
1744
+ return args[0];
1745
+ }
1746
+ };
1747
+
1748
+ TWOPI = Math.PI * 2;
1749
+
1750
+ PITHIRD = Math.PI / 3;
1751
+
1752
+ cos = Math.cos;
1753
+
1754
+ /*
1755
+ interpolates between a set of colors uzing a bezier spline
1756
+ */
1757
+
1758
+
1759
+ bezier = function(colors) {
1760
+ var I, I0, I1, c, lab0, lab1, lab2, lab3, _ref1, _ref2, _ref3;
1761
+
1762
+ colors = (function() {
1763
+ var _i, _len, _results;
1764
+
1765
+ _results = [];
1766
+ for (_i = 0, _len = colors.length; _i < _len; _i++) {
1767
+ c = colors[_i];
1768
+ _results.push(chroma(c));
1769
+ }
1770
+ return _results;
1771
+ })();
1772
+ if (colors.length === 2) {
1773
+ _ref1 = (function() {
1774
+ var _i, _len, _results;
1775
+
1776
+ _results = [];
1777
+ for (_i = 0, _len = colors.length; _i < _len; _i++) {
1778
+ c = colors[_i];
1779
+ _results.push(c.lab());
1780
+ }
1781
+ return _results;
1782
+ })(), lab0 = _ref1[0], lab1 = _ref1[1];
1783
+ I = function(t) {
1784
+ var i, lab;
1785
+
1786
+ lab = (function() {
1787
+ var _i, _results;
1788
+
1789
+ _results = [];
1790
+ for (i = _i = 0; _i <= 2; i = ++_i) {
1791
+ _results.push(lab0[i] + t * (lab1[i] - lab0[i]));
1792
+ }
1793
+ return _results;
1794
+ })();
1795
+ return chroma.lab.apply(chroma, lab);
1796
+ };
1797
+ } else if (colors.length === 3) {
1798
+ _ref2 = (function() {
1799
+ var _i, _len, _results;
1800
+
1801
+ _results = [];
1802
+ for (_i = 0, _len = colors.length; _i < _len; _i++) {
1803
+ c = colors[_i];
1804
+ _results.push(c.lab());
1805
+ }
1806
+ return _results;
1807
+ })(), lab0 = _ref2[0], lab1 = _ref2[1], lab2 = _ref2[2];
1808
+ I = function(t) {
1809
+ var i, lab;
1810
+
1811
+ lab = (function() {
1812
+ var _i, _results;
1813
+
1814
+ _results = [];
1815
+ for (i = _i = 0; _i <= 2; i = ++_i) {
1816
+ _results.push((1 - t) * (1 - t) * lab0[i] + 2 * (1 - t) * t * lab1[i] + t * t * lab2[i]);
1817
+ }
1818
+ return _results;
1819
+ })();
1820
+ return chroma.lab.apply(chroma, lab);
1821
+ };
1822
+ } else if (colors.length === 4) {
1823
+ _ref3 = (function() {
1824
+ var _i, _len, _results;
1825
+
1826
+ _results = [];
1827
+ for (_i = 0, _len = colors.length; _i < _len; _i++) {
1828
+ c = colors[_i];
1829
+ _results.push(c.lab());
1830
+ }
1831
+ return _results;
1832
+ })(), lab0 = _ref3[0], lab1 = _ref3[1], lab2 = _ref3[2], lab3 = _ref3[3];
1833
+ I = function(t) {
1834
+ var i, lab;
1835
+
1836
+ lab = (function() {
1837
+ var _i, _results;
1838
+
1839
+ _results = [];
1840
+ for (i = _i = 0; _i <= 2; i = ++_i) {
1841
+ _results.push((1 - t) * (1 - t) * (1 - t) * lab0[i] + 3 * (1 - t) * (1 - t) * t * lab1[i] + 3 * (1 - t) * t * t * lab2[i] + t * t * t * lab3[i]);
1842
+ }
1843
+ return _results;
1844
+ })();
1845
+ return chroma.lab.apply(chroma, lab);
1846
+ };
1847
+ } else if (colors.length === 5) {
1848
+ I0 = bezier(colors.slice(0, 3));
1849
+ I1 = bezier(colors.slice(2, 5));
1850
+ I = function(t) {
1851
+ if (t < 0.5) {
1852
+ return I0(t * 2);
1853
+ } else {
1854
+ return I1((t - 0.5) * 2);
1855
+ }
1856
+ };
1857
+ }
1858
+ return I;
1859
+ };
1860
+
1861
+ chroma.interpolate.bezier = bezier;
1862
+
1863
+ }).call(this);