tables.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ColorMap, ColorTable, Color } from './color';
  7. export interface TableLegend {
  8. kind: 'table-legend'
  9. table: [ string, Color ][]
  10. }
  11. export function TableLegend(table: [ string, Color ][]): TableLegend {
  12. return { kind: 'table-legend', table }
  13. }
  14. /**
  15. * Brewer Color Lists
  16. *
  17. * Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
  18. * Licensed under the Apache License, Version 2.0 (the "License");
  19. */
  20. export const ColorBrewer = ColorTable({
  21. // sequential
  22. OrangeRed: [0xfff7ec, 0xfee8c8, 0xfdd49e, 0xfdbb84, 0xfc8d59, 0xef6548, 0xd7301f, 0xb30000, 0x7f0000],
  23. PurpleBlue: [0xfff7fb, 0xece7f2, 0xd0d1e6, 0xa6bddb, 0x74a9cf, 0x3690c0, 0x0570b0, 0x045a8d, 0x023858],
  24. BluePurple: [0xf7fcfd, 0xe0ecf4, 0xbfd3e6, 0x9ebcda, 0x8c96c6, 0x8c6bb1, 0x88419d, 0x810f7c, 0x4d004b],
  25. Oranges: [0xfff5eb, 0xfee6ce, 0xfdd0a2, 0xfdae6b, 0xfd8d3c, 0xf16913, 0xd94801, 0xa63603, 0x7f2704],
  26. BlueGreen: [0xf7fcfd, 0xe5f5f9, 0xccece6, 0x99d8c9, 0x66c2a4, 0x41ae76, 0x238b45, 0x006d2c, 0x00441b],
  27. YellowOrangeBrown: [0xffffe5, 0xfff7bc, 0xfee391, 0xfec44f, 0xfe9929, 0xec7014, 0xcc4c02, 0x993404, 0x662506],
  28. YellowGreen: [0xffffe5, 0xf7fcb9, 0xd9f0a3, 0xaddd8e, 0x78c679, 0x41ab5d, 0x238443, 0x006837, 0x004529],
  29. Reds: [0xfff5f0, 0xfee0d2, 0xfcbba1, 0xfc9272, 0xfb6a4a, 0xef3b2c, 0xcb181d, 0xa50f15, 0x67000d],
  30. RedPurple: [0xfff7f3, 0xfde0dd, 0xfcc5c0, 0xfa9fb5, 0xf768a1, 0xdd3497, 0xae017e, 0x7a0177, 0x49006a],
  31. Greens: [0xf7fcf5, 0xe5f5e0, 0xc7e9c0, 0xa1d99b, 0x74c476, 0x41ab5d, 0x238b45, 0x006d2c, 0x00441b],
  32. YellowGreenBlue: [0xffffd9, 0xedf8b1, 0xc7e9b4, 0x7fcdbb, 0x41b6c4, 0x1d91c0, 0x225ea8, 0x253494, 0x081d58],
  33. Purples: [0xfcfbfd, 0xefedf5, 0xdadaeb, 0xbcbddc, 0x9e9ac8, 0x807dba, 0x6a51a3, 0x54278f, 0x3f007d],
  34. GreenBlue: [0xf7fcf0, 0xe0f3db, 0xccebc5, 0xa8ddb5, 0x7bccc4, 0x4eb3d3, 0x2b8cbe, 0x0868ac, 0x084081],
  35. Greys: [0xffffff, 0xf0f0f0, 0xd9d9d9, 0xbdbdbd, 0x969696, 0x737373, 0x525252, 0x252525, 0x000000],
  36. YellowOrangeRed: [0xffffcc, 0xffeda0, 0xfed976, 0xfeb24c, 0xfd8d3c, 0xfc4e2a, 0xe31a1c, 0xbd0026, 0x800026],
  37. PurpleRed: [0xf7f4f9, 0xe7e1ef, 0xd4b9da, 0xc994c7, 0xdf65b0, 0xe7298a, 0xce1256, 0x980043, 0x67001f],
  38. Blues: [0xf7fbff, 0xdeebf7, 0xc6dbef, 0x9ecae1, 0x6baed6, 0x4292c6, 0x2171b5, 0x08519c, 0x08306b],
  39. PurpleBlueGreen: [0xfff7fb, 0xece2f0, 0xd0d1e6, 0xa6bddb, 0x67a9cf, 0x3690c0, 0x02818a, 0x016c59, 0x014636],
  40. // diverging
  41. Spectral: [0x9e0142, 0xd53e4f, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xe6f598, 0xabdda4, 0x66c2a5, 0x3288bd, 0x5e4fa2],
  42. RedYellowGreen: [0xa50026, 0xd73027, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xd9ef8b, 0xa6d96a, 0x66bd63, 0x1a9850, 0x006837],
  43. RedBlue: [0x67001f, 0xb2182b, 0xd6604d, 0xf4a582, 0xfddbc7, 0xf7f7f7, 0xd1e5f0, 0x92c5de, 0x4393c3, 0x2166ac, 0x053061],
  44. PinkYellowGreen: [0x8e0152, 0xc51b7d, 0xde77ae, 0xf1b6da, 0xfde0ef, 0xf7f7f7, 0xe6f5d0, 0xb8e186, 0x7fbc41, 0x4d9221, 0x276419],
  45. PurpleGreen: [0x40004b, 0x762a83, 0x9970ab, 0xc2a5cf, 0xe7d4e8, 0xf7f7f7, 0xd9f0d3, 0xa6dba0, 0x5aae61, 0x1b7837, 0x00441b],
  46. RedYellowBlue: [0xa50026, 0xd73027, 0xf46d43, 0xfdae61, 0xfee090, 0xffffbf, 0xe0f3f8, 0xabd9e9, 0x74add1, 0x4575b4, 0x313695],
  47. BrownWhiteGreen: [0x543005, 0x8c510a, 0xbf812d, 0xdfc27d, 0xf6e8c3, 0xf5f5f5, 0xc7eae5, 0x80cdc1, 0x35978f, 0x01665e, 0x003c30],
  48. RedGrey: [0x67001f, 0xb2182b, 0xd6604d, 0xf4a582, 0xfddbc7, 0xffffff, 0xe0e0e0, 0xbababa, 0x878787, 0x4d4d4d, 0x1a1a1a],
  49. PurpleOrange: [0x7f3b08, 0xb35806, 0xe08214, 0xfdb863, 0xfee0b6, 0xf7f7f7, 0xd8daeb, 0xb2abd2, 0x8073ac, 0x542788, 0x2d004b],
  50. // qualitative
  51. Set2: [0x66c2a5, 0xfc8d62, 0x8da0cb, 0xe78ac3, 0xa6d854, 0xffd92f, 0xe5c494, 0xb3b3b3],
  52. Accent: [0x7fc97f, 0xbeaed4, 0xfdc086, 0xffff99, 0x386cb0, 0xf0027f, 0xbf5b17, 0x666666],
  53. Set1: [0xe41a1c, 0x377eb8, 0x4daf4a, 0x984ea3, 0xff7f00, 0xffff33, 0xa65628, 0xf781bf, 0x999999],
  54. Set3: [0x8dd3c7, 0xffffb3, 0xbebada, 0xfb8072, 0x80b1d3, 0xfdb462, 0xb3de69, 0xfccde5, 0xd9d9d9, 0xbc80bd, 0xccebc5, 0xffed6f],
  55. Dark2: [0x1b9e77, 0xd95f02, 0x7570b3, 0xe7298a, 0x66a61e, 0xe6ab02, 0xa6761d, 0x666666],
  56. Paired: [0xa6cee3, 0x1f78b4, 0xb2df8a, 0x33a02c, 0xfb9a99, 0xe31a1c, 0xfdbf6f, 0xff7f00, 0xcab2d6, 0x6a3d9a, 0xffff99, 0xb15928],
  57. Pastel2: [0xb3e2cd, 0xfdcdac, 0xcbd5e8, 0xf4cae4, 0xe6f5c9, 0xfff2ae, 0xf1e2cc, 0xcccccc],
  58. Pastel1: [0xfbb4ae, 0xb3cde3, 0xccebc5, 0xdecbe4, 0xfed9a6, 0xffffcc, 0xe5d8bd, 0xfddaec, 0xf2f2f2]
  59. })
  60. /**
  61. * Matplotlib colormaps, including various perceptually uniform shades, see https://bids.github.io/colormap/
  62. */
  63. export const ColorMatplotlib = ColorTable({
  64. /** perceptually uniform shades of black-red-white */
  65. Magma: [
  66. 0x420f74, 0x4a1079, 0x52127c, 0x5a157e, 0x61187f, 0x691c80, 0x711f81, 0x792281, 0x812581, 0x892881, 0x912a80, 0x992d7f, 0xa12f7e, 0xa9327c, 0xb1357a, 0xb93778, 0xc23a75, 0xca3e72, 0xd1426e, 0xd9466a, 0xe04b66, 0xe65162, 0xec585f, 0xf0605d, 0xf4685b, 0xf7715b, 0xf97b5d, 0xfb8460, 0xfc8e63, 0xfd9768, 0xfda16e, 0xfeaa74, 0xfeb37b, 0xfebc82, 0xfec689, 0xfdcf92, 0xfdd89a, 0xfde1a3, 0xfceaac, 0xfcf3b5, 0xfbfcbf
  67. ],
  68. /** perceptually uniform shades of black-red-yellow */
  69. Inferno: [
  70. 0x480b6a, 0x500d6c, 0x58106d, 0x60136e, 0x68166e, 0x70196e, 0x781c6d, 0x801f6b, 0x88216a, 0x902468, 0x982765, 0xa02a62, 0xa72d5f, 0xaf315b, 0xb73456, 0xbe3852, 0xc53d4d, 0xcc4148, 0xd24742, 0xd94d3d, 0xde5337, 0xe45a31, 0xe8612b, 0xed6825, 0xf0701e, 0xf37918, 0xf68111, 0xf88a0b, 0xfa9306, 0xfb9d06, 0xfba60b, 0xfbb014, 0xfbb91e, 0xf9c32a, 0xf8cd37, 0xf5d745, 0xf3e056, 0xf1e968, 0xf1f27d, 0xf5f891, 0xfcfea4
  71. ],
  72. /** perceptually uniform shades of blue-red-yellow */
  73. Plasma: [
  74. 0x1b068c, 0x250591, 0x2f0495, 0x380499, 0x40039c, 0x49029f, 0x5101a2, 0x5901a4, 0x6100a6, 0x6800a7, 0x7000a8, 0x7801a8, 0x7f03a7, 0x8607a6, 0x8e0ca4, 0x9511a1, 0x9b179e, 0xa21c9a, 0xa82296, 0xae2791, 0xb42d8d, 0xb93388, 0xbe3883, 0xc33e7f, 0xc8447a, 0xcd4975, 0xd14f71, 0xd6556d, 0xda5a68, 0xde6064, 0xe26660, 0xe56c5b, 0xe97257, 0xec7853, 0xef7e4e, 0xf2854a, 0xf58b46, 0xf79241, 0xf9993d, 0xfaa039, 0xfca735, 0xfdaf31, 0xfdb62d, 0xfdbe29, 0xfdc626, 0xfcce25, 0xfad624, 0xf8df24, 0xf5e726, 0xf2f026, 0xeff821
  75. ],
  76. /** perceptually uniform shades of blue-green-yellow */
  77. Viridis: [
  78. 0x45085b, 0x470f62, 0x471669, 0x481d6f, 0x482374, 0x472a79, 0x46307d, 0x453681, 0x433c84, 0x414286, 0x3e4888, 0x3c4d8a, 0x3a538b, 0x37588c, 0x355d8c, 0x32628d, 0x30678d, 0x2e6c8e, 0x2c718e, 0x2a768e, 0x287a8e, 0x267f8e, 0x24848d, 0x23898d, 0x218d8c, 0x1f928c, 0x1e978a, 0x1e9b89, 0x1ea087, 0x20a585, 0x23a982, 0x28ae7f, 0x2eb27c, 0x35b778, 0x3dbb74, 0x45bf6f, 0x4fc369, 0x59c764, 0x64cb5d, 0x70ce56, 0x7cd24f, 0x88d547, 0x95d73f, 0xa2da37, 0xafdc2e, 0xbdde26, 0xcae01e, 0xd7e219, 0xe4e318, 0xf1e51c, 0xfde724
  79. ],
  80. /**
  81. * perceptually uniform shades of blue-green-yellow,
  82. * should look effectively identical to colorblind and non-colorblind users
  83. */
  84. Cividis: [
  85. 0x002c67, 0x003070, 0x083370, 0x16366f, 0x1f3a6e, 0x273d6d, 0x2e416c, 0x34446c, 0x39486c, 0x3f4b6b, 0x444f6b, 0x49526b, 0x4e566c, 0x52596c, 0x575d6d, 0x5b606e, 0x60646e, 0x64676f, 0x686b71, 0x6d6e72, 0x717273, 0x757575, 0x797977, 0x7e7d78, 0x838078, 0x878478, 0x8c8878, 0x918c77, 0x968f77, 0x9b9376, 0xa09775, 0xa59b73, 0xaa9f72, 0xafa370, 0xb4a76f, 0xb9ab6d, 0xbeb06a, 0xc4b468, 0xc9b865, 0xcebc62, 0xd4c15e, 0xd9c55a, 0xdfca56, 0xe4ce51, 0xead34c, 0xefd846, 0xf5dc3f, 0xfbe136, 0xfde737
  86. ],
  87. /** perceptually uniform shades of white-blue-black-red-white, cyclic */
  88. Twilight: [
  89. 0xdfd9e1, 0xd8d7dd, 0xced3d8, 0xc2cdd3, 0xb4c7ce, 0xa7c0ca, 0x9ab8c7, 0x8eb0c5, 0x83a8c3, 0x7a9fc2, 0x7297c0, 0x6b8ebf, 0x6684bd, 0x637bbb, 0x6171b9, 0x5f67b6, 0x5e5cb2, 0x5e51ad, 0x5d46a7, 0x5c3c9f, 0x5b3196, 0x58278b, 0x531e7d, 0x4d176e, 0x46135f, 0x3e1151, 0x381045, 0x32113b, 0x301336, 0x361138, 0x3e113c, 0x471240, 0x521445, 0x5e1749, 0x6a1a4d, 0x761e4f, 0x812350, 0x8b2a50, 0x95324f, 0x9d3a4f, 0xa5434f, 0xac4d50, 0xb25752, 0xb86155, 0xbc6c59, 0xc0775f, 0xc48267, 0xc78d70, 0xc9987b, 0xcca389, 0xceae97, 0xd2b8a6, 0xd6c1b5, 0xdacac4, 0xddd1d1, 0xe0d6db, 0xe1d8e1
  90. ]
  91. })
  92. export const ColorOther = ColorTable({
  93. Rainbow: [ 0x3361E1, 0x35A845, 0xF9FF00, 0xEC8711, 0xBF2222 ],
  94. RedWhiteBlue: [ 0xBF2222, 0xFFFFFF, 0x3361E1 ],
  95. })
  96. /** X11 color names http://www.w3.org/TR/css3-color/#svg-color */
  97. export const ColorNames = ColorMap({
  98. aliceblue: 0xf0f8ff,
  99. antiquewhite: 0xfaebd7,
  100. aqua: 0x00ffff,
  101. aquamarine: 0x7fffd4,
  102. azure: 0xf0ffff,
  103. beige: 0xf5f5dc,
  104. bisque: 0xffe4c4,
  105. black: 0x000000,
  106. blanchedalmond: 0xffebcd,
  107. blue: 0x0000ff,
  108. blueviolet: 0x8a2be2,
  109. brown: 0xa52a2a,
  110. burlywood: 0xdeb887,
  111. cadetblue: 0x5f9ea0,
  112. chartreuse: 0x7fff00,
  113. chocolate: 0xd2691e,
  114. coral: 0xff7f50,
  115. cornflower: 0x6495ed,
  116. cornflowerblue: 0x6495ed,
  117. cornsilk: 0xfff8dc,
  118. crimson: 0xdc143c,
  119. cyan: 0x00ffff,
  120. darkblue: 0x00008b,
  121. darkcyan: 0x008b8b,
  122. darkgoldenrod: 0xb8860b,
  123. darkgray: 0xa9a9a9,
  124. darkgreen: 0x006400,
  125. darkgrey: 0xa9a9a9,
  126. darkkhaki: 0xbdb76b,
  127. darkmagenta: 0x8b008b,
  128. darkolivegreen: 0x556b2f,
  129. darkorange: 0xff8c00,
  130. darkorchid: 0x9932cc,
  131. darkred: 0x8b0000,
  132. darksalmon: 0xe9967a,
  133. darkseagreen: 0x8fbc8f,
  134. darkslateblue: 0x483d8b,
  135. darkslategray: 0x2f4f4f,
  136. darkslategrey: 0x2f4f4f,
  137. darkturquoise: 0x00ced1,
  138. darkviolet: 0x9400d3,
  139. deeppink: 0xff1493,
  140. deepskyblue: 0x00bfff,
  141. dimgray: 0x696969,
  142. dimgrey: 0x696969,
  143. dodgerblue: 0x1e90ff,
  144. firebrick: 0xb22222,
  145. floralwhite: 0xfffaf0,
  146. forestgreen: 0x228b22,
  147. fuchsia: 0xff00ff,
  148. gainsboro: 0xdcdcdc,
  149. ghostwhite: 0xf8f8ff,
  150. gold: 0xffd700,
  151. goldenrod: 0xdaa520,
  152. gray: 0x808080,
  153. green: 0x008000,
  154. greenyellow: 0xadff2f,
  155. grey: 0x808080,
  156. honeydew: 0xf0fff0,
  157. hotpink: 0xff69b4,
  158. indianred: 0xcd5c5c,
  159. indigo: 0x4b0082,
  160. ivory: 0xfffff0,
  161. khaki: 0xf0e68c,
  162. laserlemon: 0xffff54,
  163. lavender: 0xe6e6fa,
  164. lavenderblush: 0xfff0f5,
  165. lawngreen: 0x7cfc00,
  166. lemonchiffon: 0xfffacd,
  167. lightblue: 0xadd8e6,
  168. lightcoral: 0xf08080,
  169. lightcyan: 0xe0ffff,
  170. lightgoldenrod: 0xfafad2,
  171. lightgoldenrodyellow: 0xfafad2,
  172. lightgray: 0xd3d3d3,
  173. lightgreen: 0x90ee90,
  174. lightgrey: 0xd3d3d3,
  175. lightpink: 0xffb6c1,
  176. lightsalmon: 0xffa07a,
  177. lightseagreen: 0x20b2aa,
  178. lightskyblue: 0x87cefa,
  179. lightslategray: 0x778899,
  180. lightslategrey: 0x778899,
  181. lightsteelblue: 0xb0c4de,
  182. lightyellow: 0xffffe0,
  183. lime: 0x00ff00,
  184. limegreen: 0x32cd32,
  185. linen: 0xfaf0e6,
  186. magenta: 0xff00ff,
  187. maroon: 0x800000,
  188. maroon2: 0x7f0000,
  189. maroon3: 0xb03060,
  190. mediumaquamarine: 0x66cdaa,
  191. mediumblue: 0x0000cd,
  192. mediumorchid: 0xba55d3,
  193. mediumpurple: 0x9370db,
  194. mediumseagreen: 0x3cb371,
  195. mediumslateblue: 0x7b68ee,
  196. mediumspringgreen: 0x00fa9a,
  197. mediumturquoise: 0x48d1cc,
  198. mediumvioletred: 0xc71585,
  199. midnightblue: 0x191970,
  200. mintcream: 0xf5fffa,
  201. mistyrose: 0xffe4e1,
  202. moccasin: 0xffe4b5,
  203. navajowhite: 0xffdead,
  204. navy: 0x000080,
  205. oldlace: 0xfdf5e6,
  206. olive: 0x808000,
  207. olivedrab: 0x6b8e23,
  208. orange: 0xffa500,
  209. orangered: 0xff4500,
  210. orchid: 0xda70d6,
  211. palegoldenrod: 0xeee8aa,
  212. palegreen: 0x98fb98,
  213. paleturquoise: 0xafeeee,
  214. palevioletred: 0xdb7093,
  215. papayawhip: 0xffefd5,
  216. peachpuff: 0xffdab9,
  217. peru: 0xcd853f,
  218. pink: 0xffc0cb,
  219. plum: 0xdda0dd,
  220. powderblue: 0xb0e0e6,
  221. purple: 0x800080,
  222. purple2: 0x7f007f,
  223. purple3: 0xa020f0,
  224. rebeccapurple: 0x663399,
  225. red: 0xff0000,
  226. rosybrown: 0xbc8f8f,
  227. royalblue: 0x4169e1,
  228. saddlebrown: 0x8b4513,
  229. salmon: 0xfa8072,
  230. sandybrown: 0xf4a460,
  231. seagreen: 0x2e8b57,
  232. seashell: 0xfff5ee,
  233. sienna: 0xa0522d,
  234. silver: 0xc0c0c0,
  235. skyblue: 0x87ceeb,
  236. slateblue: 0x6a5acd,
  237. slategray: 0x708090,
  238. slategrey: 0x708090,
  239. snow: 0xfffafa,
  240. springgreen: 0x00ff7f,
  241. steelblue: 0x4682b4,
  242. tan: 0xd2b48c,
  243. teal: 0x008080,
  244. thistle: 0xd8bfd8,
  245. tomato: 0xff6347,
  246. turquoise: 0x40e0d0,
  247. violet: 0xee82ee,
  248. wheat: 0xf5deb3,
  249. white: 0xffffff,
  250. whitesmoke: 0xf5f5f5,
  251. yellow: 0xffff00,
  252. yellowgreen: 0x9acd32
  253. })
  254. export type ColorNames = typeof ColorNames
  255. export type ColorName = keyof ColorNames
  256. export const ColorNamesValueMap = (function() {
  257. const map = new Map<Color, ColorName>()
  258. Object.keys(ColorNames).forEach(name => {
  259. map.set(ColorNames[name as ColorName], name as ColorName)
  260. })
  261. return map
  262. })()