chroma.js 55 KB

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