@kepler.gl/utils 3.3.0-alpha.2 → 3.3.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/dist/application-config.d.ts +180 -1
  2. package/dist/arrow-data-container.d.ts +55 -2
  3. package/dist/camera-tour.d.ts +11 -0
  4. package/dist/camera-utils.d.ts +7 -0
  5. package/dist/cjs/aggregation.js +84 -0
  6. package/dist/cjs/aggregation.js.map +1 -0
  7. package/dist/cjs/application-config-types.js +6 -0
  8. package/dist/cjs/application-config-types.js.map +1 -0
  9. package/dist/cjs/application-config.js +178 -0
  10. package/dist/cjs/application-config.js.map +1 -0
  11. package/dist/cjs/arrow-data-container.js +1152 -0
  12. package/dist/cjs/arrow-data-container.js.map +1 -0
  13. package/dist/cjs/browser-utils.js +17 -0
  14. package/dist/cjs/browser-utils.js.map +1 -0
  15. package/dist/cjs/camera-tour.js +99 -0
  16. package/dist/cjs/camera-tour.js.map +1 -0
  17. package/dist/cjs/camera-utils.js +81 -0
  18. package/dist/cjs/camera-utils.js.map +1 -0
  19. package/dist/cjs/color-utils.js +462 -0
  20. package/dist/cjs/color-utils.js.map +1 -0
  21. package/dist/cjs/column-statistics.js +115 -0
  22. package/dist/cjs/column-statistics.js.map +1 -0
  23. package/dist/cjs/data-container-interface.js +6 -0
  24. package/dist/cjs/data-container-interface.js.map +1 -0
  25. package/dist/cjs/data-container-utils.js +76 -0
  26. package/dist/cjs/data-container-utils.js.map +1 -0
  27. package/dist/cjs/data-row.js +110 -0
  28. package/dist/cjs/data-row.js.map +1 -0
  29. package/dist/cjs/data-scale-utils.js +634 -0
  30. package/dist/cjs/data-scale-utils.js.map +1 -0
  31. package/dist/cjs/data-utils.js +538 -0
  32. package/dist/cjs/data-utils.js.map +1 -0
  33. package/dist/cjs/dataset-utils.js +361 -0
  34. package/dist/cjs/dataset-utils.js.map +1 -0
  35. package/dist/cjs/dom-to-image.js +433 -0
  36. package/dist/cjs/dom-to-image.js.map +1 -0
  37. package/dist/cjs/dom-utils.js +349 -0
  38. package/dist/cjs/dom-utils.js.map +1 -0
  39. package/dist/cjs/editor-feature-utils.js +177 -0
  40. package/dist/cjs/editor-feature-utils.js.map +1 -0
  41. package/dist/cjs/effect-utils.js +340 -0
  42. package/dist/cjs/effect-utils.js.map +1 -0
  43. package/dist/cjs/export-map-html.js +112 -0
  44. package/dist/cjs/export-map-html.js.map +1 -0
  45. package/dist/cjs/export-utils.js +318 -0
  46. package/dist/cjs/export-utils.js.map +1 -0
  47. package/dist/cjs/extract-dataset-utils.js +218 -0
  48. package/dist/cjs/extract-dataset-utils.js.map +1 -0
  49. package/dist/cjs/filter-utils.js +1762 -0
  50. package/dist/cjs/filter-utils.js.map +1 -0
  51. package/dist/cjs/format.js +38 -0
  52. package/dist/cjs/format.js.map +1 -0
  53. package/dist/cjs/gl-utils.js +118 -0
  54. package/dist/cjs/gl-utils.js.map +1 -0
  55. package/dist/{index.js → cjs/index.js} +391 -10
  56. package/dist/cjs/index.js.map +1 -0
  57. package/dist/cjs/indexed-data-container.js +214 -0
  58. package/dist/cjs/indexed-data-container.js.map +1 -0
  59. package/dist/cjs/jenks.js +156 -0
  60. package/dist/cjs/jenks.js.map +1 -0
  61. package/dist/cjs/locale-utils.js +39 -0
  62. package/dist/cjs/locale-utils.js.map +1 -0
  63. package/dist/cjs/map-info-utils.js +41 -0
  64. package/dist/cjs/map-info-utils.js.map +1 -0
  65. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
  66. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  67. package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
  68. package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
  69. package/dist/cjs/map-utils.js +76 -0
  70. package/dist/cjs/map-utils.js.map +1 -0
  71. package/dist/cjs/mapbox-utils.js +19 -0
  72. package/dist/cjs/mapbox-utils.js.map +1 -0
  73. package/dist/cjs/notifications-utils.js +69 -0
  74. package/dist/cjs/notifications-utils.js.map +1 -0
  75. package/dist/cjs/observe-dimensions.js +136 -0
  76. package/dist/cjs/observe-dimensions.js.map +1 -0
  77. package/dist/cjs/plot.js +1502 -0
  78. package/dist/cjs/plot.js.map +1 -0
  79. package/dist/cjs/position-utils.js +29 -0
  80. package/dist/cjs/position-utils.js.map +1 -0
  81. package/dist/cjs/projection-utils.js +141 -0
  82. package/dist/cjs/projection-utils.js.map +1 -0
  83. package/dist/cjs/quick-insertion-sort.js +132 -0
  84. package/dist/cjs/quick-insertion-sort.js.map +1 -0
  85. package/dist/cjs/row-data-container.js +291 -0
  86. package/dist/cjs/row-data-container.js.map +1 -0
  87. package/dist/cjs/slider-scale-utils.js +138 -0
  88. package/dist/cjs/slider-scale-utils.js.map +1 -0
  89. package/dist/cjs/split-map-utils.js +117 -0
  90. package/dist/cjs/split-map-utils.js.map +1 -0
  91. package/dist/cjs/strings.js +16 -0
  92. package/dist/cjs/strings.js.map +1 -0
  93. package/dist/cjs/theme-utils.js +46 -0
  94. package/dist/cjs/theme-utils.js.map +1 -0
  95. package/dist/cjs/time.js +321 -0
  96. package/dist/cjs/time.js.map +1 -0
  97. package/dist/cjs/types.js +6 -0
  98. package/dist/cjs/types.js.map +1 -0
  99. package/dist/cjs/utils.js +224 -0
  100. package/dist/cjs/utils.js.map +1 -0
  101. package/dist/column-statistics.d.ts +54 -0
  102. package/dist/data-container-interface.d.ts +16 -1
  103. package/dist/data-container-utils.d.ts +2 -1
  104. package/dist/data-scale-utils.d.ts +5 -0
  105. package/dist/data-utils.d.ts +3 -3
  106. package/dist/dataset-utils.d.ts +11 -28
  107. package/dist/editor-feature-utils.d.ts +30 -0
  108. package/dist/esm/aggregation.js +75 -0
  109. package/dist/esm/aggregation.js.map +1 -0
  110. package/dist/esm/application-config-types.js +3 -0
  111. package/dist/esm/application-config-types.js.map +1 -0
  112. package/dist/esm/application-config.js +167 -0
  113. package/dist/esm/application-config.js.map +1 -0
  114. package/dist/esm/arrow-data-container.js +1136 -0
  115. package/dist/esm/arrow-data-container.js.map +1 -0
  116. package/dist/esm/browser-utils.js +11 -0
  117. package/dist/esm/browser-utils.js.map +1 -0
  118. package/dist/esm/camera-tour.js +92 -0
  119. package/dist/esm/camera-tour.js.map +1 -0
  120. package/dist/esm/camera-utils.js +74 -0
  121. package/dist/esm/camera-utils.js.map +1 -0
  122. package/dist/esm/color-utils.js +435 -0
  123. package/dist/esm/color-utils.js.map +1 -0
  124. package/dist/esm/column-statistics.js +105 -0
  125. package/dist/esm/column-statistics.js.map +1 -0
  126. package/dist/esm/data-container-interface.js +3 -0
  127. package/dist/esm/data-container-interface.js.map +1 -0
  128. package/dist/esm/data-container-utils.js +68 -0
  129. package/dist/esm/data-container-utils.js.map +1 -0
  130. package/dist/esm/data-row.js +106 -0
  131. package/dist/esm/data-row.js.map +1 -0
  132. package/dist/esm/data-scale-utils.js +602 -0
  133. package/dist/esm/data-scale-utils.js.map +1 -0
  134. package/dist/esm/data-utils.js +504 -0
  135. package/dist/esm/data-utils.js.map +1 -0
  136. package/dist/esm/dataset-utils.js +352 -0
  137. package/dist/esm/dataset-utils.js.map +1 -0
  138. package/dist/esm/dom-to-image.js +426 -0
  139. package/dist/esm/dom-to-image.js.map +1 -0
  140. package/dist/esm/dom-utils.js +323 -0
  141. package/dist/esm/dom-utils.js.map +1 -0
  142. package/dist/esm/editor-feature-utils.js +164 -0
  143. package/dist/esm/editor-feature-utils.js.map +1 -0
  144. package/dist/esm/effect-utils.js +333 -0
  145. package/dist/esm/effect-utils.js.map +1 -0
  146. package/dist/esm/export-map-html.js +107 -0
  147. package/dist/esm/export-map-html.js.map +1 -0
  148. package/dist/esm/export-utils.js +297 -0
  149. package/dist/esm/export-utils.js.map +1 -0
  150. package/dist/esm/extract-dataset-utils.js +206 -0
  151. package/dist/esm/extract-dataset-utils.js.map +1 -0
  152. package/dist/esm/filter-utils.js +1701 -0
  153. package/dist/esm/filter-utils.js.map +1 -0
  154. package/dist/esm/format.js +31 -0
  155. package/dist/esm/format.js.map +1 -0
  156. package/dist/esm/gl-utils.js +113 -0
  157. package/dist/esm/gl-utils.js.map +1 -0
  158. package/dist/esm/index.js +55 -0
  159. package/dist/esm/index.js.map +1 -0
  160. package/dist/esm/indexed-data-container.js +210 -0
  161. package/dist/esm/indexed-data-container.js.map +1 -0
  162. package/dist/esm/jenks.js +149 -0
  163. package/dist/esm/jenks.js.map +1 -0
  164. package/dist/esm/locale-utils.js +36 -0
  165. package/dist/esm/locale-utils.js.map +1 -0
  166. package/dist/esm/map-info-utils.js +35 -0
  167. package/dist/esm/map-info-utils.js.map +1 -0
  168. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
  169. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  170. package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
  171. package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
  172. package/dist/esm/map-utils.js +72 -0
  173. package/dist/esm/map-utils.js.map +1 -0
  174. package/dist/esm/mapbox-utils.js +13 -0
  175. package/dist/esm/mapbox-utils.js.map +1 -0
  176. package/dist/esm/notifications-utils.js +63 -0
  177. package/dist/esm/notifications-utils.js.map +1 -0
  178. package/dist/esm/observe-dimensions.js +128 -0
  179. package/dist/esm/observe-dimensions.js.map +1 -0
  180. package/dist/esm/plot.js +1460 -0
  181. package/dist/esm/plot.js.map +1 -0
  182. package/dist/esm/position-utils.js +22 -0
  183. package/dist/esm/position-utils.js.map +1 -0
  184. package/dist/esm/projection-utils.js +131 -0
  185. package/dist/esm/projection-utils.js.map +1 -0
  186. package/dist/esm/quick-insertion-sort.js +125 -0
  187. package/dist/esm/quick-insertion-sort.js.map +1 -0
  188. package/dist/esm/row-data-container.js +286 -0
  189. package/dist/esm/row-data-container.js.map +1 -0
  190. package/dist/esm/slider-scale-utils.js +129 -0
  191. package/dist/esm/slider-scale-utils.js.map +1 -0
  192. package/dist/esm/split-map-utils.js +109 -0
  193. package/dist/esm/split-map-utils.js.map +1 -0
  194. package/dist/esm/strings.js +10 -0
  195. package/dist/esm/strings.js.map +1 -0
  196. package/dist/esm/theme-utils.js +38 -0
  197. package/dist/esm/theme-utils.js.map +1 -0
  198. package/dist/esm/time.js +308 -0
  199. package/dist/esm/time.js.map +1 -0
  200. package/dist/esm/types.js +3 -0
  201. package/dist/esm/types.js.map +1 -0
  202. package/dist/esm/utils.js +203 -0
  203. package/dist/esm/utils.js.map +1 -0
  204. package/dist/export-map-html.d.ts +5 -0
  205. package/dist/export-utils.d.ts +31 -3
  206. package/dist/extract-dataset-utils.d.ts +79 -0
  207. package/dist/filter-utils.d.ts +56 -7
  208. package/dist/index.d.ts +20 -9
  209. package/dist/jenks.d.ts +5 -0
  210. package/dist/map-info-utils.d.ts +11 -1
  211. package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
  212. package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
  213. package/dist/plot.d.ts +187 -21
  214. package/dist/projection-utils.d.ts +6 -4
  215. package/dist/row-data-container.d.ts +19 -0
  216. package/dist/split-map-utils.d.ts +7 -0
  217. package/dist/theme-utils.d.ts +8 -0
  218. package/dist/time.d.ts +3 -3
  219. package/dist/types.d.ts +2 -0
  220. package/package.json +33 -26
  221. package/dist/aggregation.js +0 -84
  222. package/dist/application-config-types.js +0 -6
  223. package/dist/application-config.js +0 -113
  224. package/dist/arrow-data-container.js +0 -398
  225. package/dist/browser-utils.js +0 -17
  226. package/dist/color-utils.js +0 -462
  227. package/dist/data-container-interface.js +0 -6
  228. package/dist/data-container-utils.js +0 -75
  229. package/dist/data-row.js +0 -110
  230. package/dist/data-scale-utils.js +0 -620
  231. package/dist/data-utils.js +0 -532
  232. package/dist/dataset-utils.js +0 -330
  233. package/dist/dom-to-image.js +0 -433
  234. package/dist/dom-utils.js +0 -349
  235. package/dist/effect-utils.js +0 -318
  236. package/dist/export-map-html.js +0 -38
  237. package/dist/export-utils.js +0 -203
  238. package/dist/filter-utils.js +0 -1274
  239. package/dist/format.js +0 -38
  240. package/dist/gl-utils.js +0 -118
  241. package/dist/indexed-data-container.js +0 -214
  242. package/dist/locale-utils.js +0 -39
  243. package/dist/map-info-utils.js +0 -14
  244. package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
  245. package/dist/map-style-utils/mapbox-utils.js +0 -107
  246. package/dist/map-utils.js +0 -72
  247. package/dist/mapbox-utils.js +0 -19
  248. package/dist/noop.d.ts +0 -1
  249. package/dist/noop.js +0 -13
  250. package/dist/notifications-utils.js +0 -69
  251. package/dist/observe-dimensions.js +0 -136
  252. package/dist/plot.js +0 -637
  253. package/dist/position-utils.js +0 -26
  254. package/dist/projection-utils.js +0 -91
  255. package/dist/quick-insertion-sort.js +0 -132
  256. package/dist/row-data-container.js +0 -206
  257. package/dist/searcher-utils.d.ts +0 -1
  258. package/dist/searcher-utils.js +0 -25
  259. package/dist/slider-scale-utils.js +0 -138
  260. package/dist/split-map-utils.js +0 -99
  261. package/dist/strings.js +0 -16
  262. package/dist/time.js +0 -325
  263. package/dist/types.js +0 -6
  264. package/dist/utils.js +0 -224
@@ -0,0 +1,435 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ var _excluded = ["colors"];
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ // SPDX-License-Identifier: MIT
9
+ // Copyright contributors to the kepler.gl project
10
+
11
+ import { DEFAULT_CUSTOM_PALETTE, colorPaletteToColorRange } from '@kepler.gl/constants';
12
+ import { arrayMove } from '@kepler.gl/common-utils';
13
+ import { rgb as d3Rgb } from 'd3-color';
14
+ import { interpolate } from 'd3-interpolate';
15
+ import { arrayInsert } from './utils';
16
+ import Console from 'global/console';
17
+ import { KEPLER_COLOR_PALETTES, PALETTE_TYPES, SCALE_TYPES } from '@kepler.gl/constants';
18
+
19
+ /**
20
+ * get r g b from hex code
21
+ *
22
+ * @param hex
23
+ * @returns array of r g bs
24
+ */
25
+ export function hexToRgb(hex) {
26
+ var result = isHexColor(hex);
27
+ if (!result) {
28
+ return [0, 0, 0];
29
+ }
30
+ var r = parseInt(result[1], 16);
31
+ var g = parseInt(result[2], 16);
32
+ var b = parseInt(result[3], 16);
33
+ return [r, g, b];
34
+ }
35
+ export function isHexColor(hex) {
36
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
37
+ return result;
38
+ }
39
+ function PadNum(c) {
40
+ var hex = c.toString(16);
41
+ return hex.length === 1 ? "0".concat(hex) : hex;
42
+ }
43
+
44
+ /**
45
+ * get hex from r g b
46
+ *
47
+ * @param rgb
48
+ * @returns hex string
49
+ */
50
+ export function rgbToHex(_ref) {
51
+ var _ref2 = _slicedToArray(_ref, 3),
52
+ r = _ref2[0],
53
+ g = _ref2[1],
54
+ b = _ref2[2];
55
+ return "#".concat([r, g, b].map(function (n) {
56
+ return PadNum(n);
57
+ }).join('')).toUpperCase();
58
+ }
59
+
60
+ /**
61
+ * Whether color range has custom color map
62
+ */
63
+ export function hasColorMap(colorRange) {
64
+ return Array.isArray(colorRange.colorMap) && Boolean(colorRange.colorMap.length);
65
+ }
66
+
67
+ /**
68
+ * given a list of rgb arrays it will generate a linear gradient css rule
69
+ * @param direction
70
+ * @param colors
71
+ * @return
72
+ */
73
+ export function createLinearGradient(direction, colors) {
74
+ var step = parseFloat((100.0 / colors.length).toFixed(2));
75
+ var bands = colors.map(function (rgb, index) {
76
+ return "rgba(".concat(rgb.join(','), ", 1) ").concat(step * index, "%, rgba(").concat(rgb.join(','), ", 1) ").concat(step * (index + 1), "%");
77
+ });
78
+ return "linear-gradient(to ".concat(direction, ", ").concat(bands.join(','), ")");
79
+ }
80
+
81
+ /**
82
+ * Convert color to RGB
83
+ */
84
+ export function colorMaybeToRGB(color) {
85
+ if (isRgbColor(color)) {
86
+ return color;
87
+ }
88
+ if (typeof color === 'string') {
89
+ var rgbObj = d3Rgb(color);
90
+ if (Number.isFinite(rgbObj === null || rgbObj === void 0 ? void 0 : rgbObj.r) && Number.isFinite(rgbObj === null || rgbObj === void 0 ? void 0 : rgbObj.g) && Number.isFinite(rgbObj === null || rgbObj === void 0 ? void 0 : rgbObj.b)) {
91
+ return [rgbObj.r, rgbObj.g, rgbObj.b];
92
+ }
93
+ }
94
+ return null;
95
+ }
96
+
97
+ /**
98
+ * Whether color is rgb
99
+ * @returns
100
+ */
101
+ export function isRgbColor(color) {
102
+ return Boolean(color && Array.isArray(color) && color.length === 3 && color.every(function (n) {
103
+ return Number.isFinite(n) && n <= 255 && n >= 0;
104
+ }));
105
+ }
106
+
107
+ /**
108
+ * Take color values in 0-255 range and map to [0, 1]
109
+ */
110
+ export function normalizeColor(color) {
111
+ return color.map(function (component) {
112
+ return component / 255.0;
113
+ });
114
+ }
115
+
116
+ /**
117
+ * Convert color to Hex
118
+ */
119
+ export function colorMaybeToHex(color) {
120
+ var rgbColor = colorMaybeToRGB(color);
121
+ if (rgbColor) return rgbToHex(rgbColor);
122
+ return '#000000';
123
+ }
124
+
125
+ /**
126
+ * Convert color to Hex
127
+ */
128
+
129
+ export function interpolateHex(hex1, hex2) {
130
+ return d3Rgb(interpolate(hex1, hex2)(0.5)).formatHex().toUpperCase();
131
+ }
132
+ function addNewCategoricalStepAtIndex(colorMap, index, newColor) {
133
+ if (!Array.isArray(colorMap) || !colorMap.length) {
134
+ return colorMap;
135
+ }
136
+ var newColorMap = colorMap.map(function (_ref3) {
137
+ var _ref4 = _slicedToArray(_ref3, 2),
138
+ val = _ref4[0],
139
+ c = _ref4[1];
140
+ return [Array.isArray(val) ? _toConsumableArray(val) : val, c];
141
+ });
142
+ newColorMap = arrayInsert(newColorMap, index + 1, [null, newColor]);
143
+ return newColorMap;
144
+ }
145
+ export function addNewQuantativeColorBreakAtIndex(colorMap, index, newColors) {
146
+ if (!Array.isArray(colorMap) || !colorMap.length) {
147
+ return colorMap;
148
+ }
149
+ if (colorMap.length < 2) {
150
+ // less then 2, add 1 at end
151
+ // however shouldn't allow delete when there are 2
152
+ return newColors.map(function (c, i) {
153
+ return i === 0 ? colorMap[i] : [null, c];
154
+ });
155
+ }
156
+
157
+ // breaks should be 1 less than colors
158
+ var breaks = colorMap.map(function (cm) {
159
+ return cm[0];
160
+ }).slice(0, colorMap.length - 1);
161
+
162
+ // insert new break
163
+ var newValue = index >= breaks.length - 1 ? breaks[breaks.length - 1] + (breaks.length > 1 ? breaks[breaks.length - 1] - breaks[breaks.length - 2] : 0) : (breaks[index] + breaks[index + 1]) / 2;
164
+ var newBreaks = arrayInsert(breaks, index + 1, newValue);
165
+
166
+ // asign breaks to color
167
+ return newColors.map(function (c, i) {
168
+ return i === newColors.length - 1 ? [null, c] : [newBreaks[i] === undefined ? null : newBreaks[i], c];
169
+ });
170
+ }
171
+
172
+ /**
173
+ * Add a new color to custom palette
174
+ */
175
+ export function addCustomPaletteColor(customPalette, index) {
176
+ var colors = customPalette.colors,
177
+ colorMap = customPalette.colorMap;
178
+ var update = {};
179
+ var newColor = index === colors.length - 1 ? colors[index] : interpolateHex(colors[index], colors[index + 1]);
180
+ update.colors = arrayInsert(colors, index + 1, newColor);
181
+
182
+ // add color to colorMap
183
+ if (colorMap) {
184
+ update.colorMap = customPalette.type === 'customOrdinal' ? addNewCategoricalStepAtIndex(colorMap, index, newColor) : addNewQuantativeColorBreakAtIndex(colorMap, index, update.colors);
185
+ }
186
+ return _objectSpread(_objectSpread({}, customPalette), update);
187
+ }
188
+ function replaceColorsInColorRange(colorRange, newColors) {
189
+ var oldColors = colorRange.colors;
190
+ var updated = _objectSpread(_objectSpread({}, colorRange), {}, {
191
+ colors: newColors
192
+ });
193
+
194
+ // update color map
195
+ // keep value, replace color
196
+ if (Array.isArray(updated.colorMap)) {
197
+ updated.colorMap = updated.colorMap.map(function (cm, i) {
198
+ return [cm[0], newColors[i]];
199
+ });
200
+ }
201
+ // update colorlegends
202
+ // keep value, replace color
203
+ if (updated.colorLegends) {
204
+ updated.colorLegends = Object.keys(updated.colorLegends).reduce(function (accu, key) {
205
+ var colorIdx = oldColors.findIndex(function (c) {
206
+ return c === key;
207
+ });
208
+ var newColor = newColors[colorIdx];
209
+ return newColor ? _objectSpread(_objectSpread({}, accu), {}, _defineProperty({}, newColor, updated.colorLegends[key])) : accu;
210
+ }, {});
211
+ }
212
+ return updated;
213
+ }
214
+
215
+ /**
216
+ * Sort custom palette
217
+ */
218
+ export function sortCustomPaletteColor(customPalette, oldIndex, newIndex) {
219
+ var colors = customPalette.colors;
220
+ var newColors = arrayMove(colors, oldIndex, newIndex);
221
+ var update = replaceColorsInColorRange(customPalette, newColors);
222
+
223
+ // @ts-ignore
224
+ return _objectSpread(_objectSpread({}, customPalette), update);
225
+ }
226
+
227
+ /**
228
+ * remove a color in custom palette at index
229
+ */
230
+ export function removeCustomPaletteColor(customPalette, index) {
231
+ var colors = customPalette.colors,
232
+ colorMap = customPalette.colorMap,
233
+ colorLegends = customPalette.colorLegends;
234
+ var oldValue = colors[index];
235
+ var update = {};
236
+ update.colors = _toConsumableArray(colors);
237
+ if (update.colors.length > 1) {
238
+ update.colors.splice(index, 1);
239
+ }
240
+ // update color map
241
+ if (Array.isArray(colorMap)) {
242
+ // find colorMap index
243
+ var colorMapIndex = colorMap.findIndex(function (cm) {
244
+ return cm[1] === oldValue;
245
+ });
246
+ if (colorMapIndex >= 0) {
247
+ update.colorMap = _toConsumableArray(colorMap);
248
+ update.colorMap.splice(colorMapIndex, 1);
249
+ }
250
+ }
251
+ // update color legend
252
+ if (colorLegends !== null && colorLegends !== void 0 && colorLegends[oldValue]) {
253
+ update.colorLegends = _objectSpread({}, colorLegends);
254
+ delete update.colorLegends[oldValue];
255
+ }
256
+ return _objectSpread(_objectSpread({}, customPalette), update);
257
+ }
258
+
259
+ /**
260
+ * Update a color in custom palette at index
261
+ */
262
+ export function updateCustomPaletteColor(customPalette, index, newValue) {
263
+ var colors = customPalette.colors;
264
+ var hex = newValue.toUpperCase();
265
+ var newColors = _toConsumableArray(colors);
266
+ newColors[index] = hex;
267
+ var update = replaceColorsInColorRange(customPalette, newColors);
268
+
269
+ // @ts-ignore
270
+ return _objectSpread(_objectSpread({}, customPalette), update);
271
+ }
272
+
273
+ /**
274
+ * Get a reversed colorRange
275
+ */
276
+ export function reverseColorRange(reversed, colorRange) {
277
+ var newColors = colorRange === null || colorRange === void 0 ? void 0 : colorRange.colors.slice().reverse();
278
+ var updated = replaceColorsInColorRange(colorRange, newColors);
279
+ updated.reversed = reversed;
280
+ return updated;
281
+ }
282
+
283
+ /**
284
+ * Whether palette matches current ColorBlindSafe config
285
+ */
286
+ export function paletteIsColorBlindSafe(palette, colorBlindSafe) {
287
+ return !colorBlindSafe || colorBlindSafe && palette.colorBlindSafe;
288
+ }
289
+
290
+ /**
291
+ * Whether palette matches current steps config
292
+ */
293
+ export function isQuaPalette(palette) {
294
+ return palette.type === PALETTE_TYPES.QUA;
295
+ }
296
+
297
+ /**
298
+ * Whether palette matches current steps config
299
+ */
300
+ export function paletteIsSteps(palette, steps) {
301
+ return !isQuaPalette(palette) || palette.maxStep >= steps;
302
+ }
303
+
304
+ /**
305
+ * Whether palette matches current type config
306
+ */
307
+ export function paletteIsType(palette, type) {
308
+ return type === 'all' || type === palette.type;
309
+ }
310
+ /**
311
+ * Find best match palette based on config, update color range by it
312
+ */
313
+ export function updateColorRangeByMatchingPalette(currentColorRange, config) {
314
+ var steps = config.steps,
315
+ colorBlindSafe = config.colorBlindSafe,
316
+ type = config.type;
317
+ var matchingPalette = KEPLER_COLOR_PALETTES.filter(function (palette) {
318
+ return (
319
+ // palette match type
320
+ paletteIsType(palette, type) &&
321
+ // palette has same step
322
+ paletteIsSteps(palette, steps) &&
323
+ // palette is colorBlindSafe
324
+ paletteIsColorBlindSafe(palette, colorBlindSafe)
325
+ );
326
+ });
327
+ var bestMatch = matchingPalette.length ? matchingPalette.find(function (p) {
328
+ return p.name === currentColorRange.name;
329
+ }) || matchingPalette[0] : null;
330
+ if (bestMatch) {
331
+ return updateColorRangeBySelectedPalette(currentColorRange, bestMatch, config);
332
+ }
333
+ // we do nothing
334
+ Console.warn("we cant find any preset palette matches requirments: steps=".concat(steps, " && colorBlindSafe=").concat(colorBlindSafe));
335
+ return currentColorRange;
336
+ }
337
+
338
+ /**
339
+ * Update custom palette when reverse the colors in custom palette, since changing 'steps',
340
+ * 'colorBindSafe', 'type' should fall back to predefined palette.
341
+ */
342
+ export function updateCustomColorRangeByColorUI(oldColorRange, colorConfig) {
343
+ var reversed = colorConfig.reversed;
344
+ var colors = _toConsumableArray(oldColorRange.colors);
345
+ // for custom palette, one can only 'reverse' the colors in custom palette.
346
+ colors.reverse();
347
+ var colorRange = _objectSpread(_objectSpread(_objectSpread({
348
+ name: oldColorRange.name,
349
+ type: oldColorRange.type,
350
+ category: oldColorRange.category,
351
+ colors: colors
352
+ }, reversed ? {
353
+ reversed: reversed
354
+ } : {}), oldColorRange.colorMap ? {
355
+ colorMap: oldColorRange.colorMap
356
+ } : {}), oldColorRange.colorLegends ? {
357
+ colorLegends: oldColorRange.colorLegends
358
+ } : {});
359
+ return replaceColorsInColorRange(colorRange, colorRange.colors);
360
+ }
361
+
362
+ /**
363
+ * Update color range after selecting a palette from color range selectoer
364
+ * Copy over colorMap and colorLegends
365
+ */
366
+ export function updateColorRangeBySelectedPalette(oldColorRange, colorPalette, colorConfig) {
367
+ var _colorPaletteToColorR = colorPaletteToColorRange(colorPalette, colorConfig),
368
+ newColors = _colorPaletteToColorR.colors,
369
+ newColorRange = _objectWithoutProperties(_colorPaletteToColorR, _excluded);
370
+ var colorRange = _objectSpread(_objectSpread(_objectSpread({
371
+ colors: oldColorRange.colors
372
+ }, newColorRange), oldColorRange.colorMap ? {
373
+ colorMap: oldColorRange.colorMap
374
+ } : {}), oldColorRange.colorLegends ? {
375
+ colorLegends: oldColorRange.colorLegends
376
+ } : {});
377
+ return replaceColorsInColorRange(colorRange, newColors);
378
+ }
379
+ var UberNameRegex = new RegExp(/^([A-Za-z ])+/g);
380
+ var ColorBrewerRegex = new RegExp(/^ColorBrewer ([A-Za-z1-9])+/g);
381
+
382
+ /**
383
+ * convert saved colorRange to colorPalette objevt type/name/category/isColorBlind
384
+ */
385
+ export function colorRangeBackwardCompatibility(colorRange) {
386
+ if (!colorRange || colorRange.type === 'custom' || colorRange.colorMap) {
387
+ // don't do anything to custom color palette, or palette with custom breaks
388
+ return colorRange;
389
+ }
390
+ var trimName;
391
+ if (colorRange.category === 'Uber') {
392
+ var _colorRange$name;
393
+ var matchName = ((_colorRange$name = colorRange.name) !== null && _colorRange$name !== void 0 ? _colorRange$name : '').match(UberNameRegex);
394
+ trimName = matchName ? matchName[0].trim() : null;
395
+ // match Uber Viz Qualitative 1.4 -> Uber Viz Qualitative
396
+ } else if (colorRange.category === 'ColorBrewer') {
397
+ var _colorRange$name2;
398
+ var _matchName = ((_colorRange$name2 = colorRange.name) !== null && _colorRange$name2 !== void 0 ? _colorRange$name2 : '').match(ColorBrewerRegex);
399
+ trimName = _matchName ? _matchName[0].replace('ColorBrewer ', '').trim() : null;
400
+ }
401
+ if (trimName) {
402
+ var matchingPalette = KEPLER_COLOR_PALETTES.find(function (p) {
403
+ return p.name === trimName;
404
+ });
405
+ if (matchingPalette) {
406
+ return _objectSpread(_objectSpread({}, colorRange), {}, {
407
+ name: trimName,
408
+ type: matchingPalette === null || matchingPalette === void 0 ? void 0 : matchingPalette.type,
409
+ category: matchingPalette.category
410
+ });
411
+ }
412
+ }
413
+ return colorRange;
414
+ }
415
+
416
+ /**
417
+ * Initialize custom palette from current standard color range object
418
+ */
419
+ export function initializeCustomPalette(colorRange, colorMap) {
420
+ // TODO: check on `isReversed` key, whether we can remove it here
421
+ var customPalette = _objectSpread(_objectSpread({}, colorRange), {}, {
422
+ name: DEFAULT_CUSTOM_PALETTE.name,
423
+ type: DEFAULT_CUSTOM_PALETTE.type,
424
+ category: DEFAULT_CUSTOM_PALETTE.category
425
+ }, colorMap ? {
426
+ colorMap: colorMap
427
+ } : {});
428
+
429
+ // only customPalette.colors are needed for custom palette editor with custom ordinal scale
430
+ if (!colorMap && colorRange.type === SCALE_TYPES.customOrdinal) {
431
+ delete customPalette.colorMap;
432
+ }
433
+ return customPalette;
434
+ }
435
+ //# sourceMappingURL=color-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-utils.js","names":["DEFAULT_CUSTOM_PALETTE","colorPaletteToColorRange","arrayMove","rgb","d3Rgb","interpolate","arrayInsert","Console","KEPLER_COLOR_PALETTES","PALETTE_TYPES","SCALE_TYPES","hexToRgb","hex","result","isHexColor","r","parseInt","g","b","exec","PadNum","c","toString","length","concat","rgbToHex","_ref","_ref2","_slicedToArray","map","n","join","toUpperCase","hasColorMap","colorRange","Array","isArray","colorMap","Boolean","createLinearGradient","direction","colors","step","parseFloat","toFixed","bands","index","colorMaybeToRGB","color","isRgbColor","rgbObj","Number","isFinite","every","normalizeColor","component","colorMaybeToHex","rgbColor","interpolateHex","hex1","hex2","formatHex","addNewCategoricalStepAtIndex","newColor","newColorMap","_ref3","_ref4","val","_toConsumableArray","addNewQuantativeColorBreakAtIndex","newColors","i","breaks","cm","slice","newValue","newBreaks","undefined","addCustomPaletteColor","customPalette","update","type","_objectSpread","replaceColorsInColorRange","oldColors","updated","colorLegends","Object","keys","reduce","accu","key","colorIdx","findIndex","_defineProperty","sortCustomPaletteColor","oldIndex","newIndex","removeCustomPaletteColor","oldValue","splice","colorMapIndex","updateCustomPaletteColor","reverseColorRange","reversed","reverse","paletteIsColorBlindSafe","palette","colorBlindSafe","isQuaPalette","QUA","paletteIsSteps","steps","maxStep","paletteIsType","updateColorRangeByMatchingPalette","currentColorRange","config","matchingPalette","filter","bestMatch","find","p","name","updateColorRangeBySelectedPalette","warn","updateCustomColorRangeByColorUI","oldColorRange","colorConfig","category","colorPalette","_colorPaletteToColorR","newColorRange","_objectWithoutProperties","_excluded","UberNameRegex","RegExp","ColorBrewerRegex","colorRangeBackwardCompatibility","trimName","_colorRange$name","matchName","match","trim","_colorRange$name2","replace","initializeCustomPalette","customOrdinal"],"sources":["../../src/color-utils.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {\n CategoricalPalette,\n ColorPalette,\n DEFAULT_CUSTOM_PALETTE,\n colorPaletteToColorRange\n} from '@kepler.gl/constants';\nimport {arrayMove} from '@kepler.gl/common-utils';\nimport {\n ColorMap,\n ColorRange,\n ColorRangeConfig,\n HexColor,\n RGBAColor,\n RGBColor\n} from '@kepler.gl/types';\nimport {rgb as d3Rgb} from 'd3-color';\nimport {interpolate} from 'd3-interpolate';\nimport {arrayInsert} from './utils';\nimport Console from 'global/console';\nimport {KEPLER_COLOR_PALETTES, PALETTE_TYPES, SCALE_TYPES} from '@kepler.gl/constants';\n\n/**\n * get r g b from hex code\n *\n * @param hex\n * @returns array of r g bs\n */\nexport function hexToRgb(hex: string): RGBColor {\n const result = isHexColor(hex);\n\n if (!result) {\n return [0, 0, 0];\n }\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n}\n\nexport function isHexColor(hex: string): RegExpExecArray | null {\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\n return result;\n}\n\nfunction PadNum(c) {\n const hex = c.toString(16);\n return hex.length === 1 ? `0${hex}` : hex;\n}\n\n/**\n * get hex from r g b\n *\n * @param rgb\n * @returns hex string\n */\nexport function rgbToHex([r, g, b]: RGBColor | RGBAColor): HexColor {\n return `#${[r, g, b].map(n => PadNum(n)).join('')}`.toUpperCase();\n}\n\n/**\n * Whether color range has custom color map\n */\nexport function hasColorMap(colorRange: ColorRange): boolean {\n return Array.isArray(colorRange.colorMap) && Boolean(colorRange.colorMap.length);\n}\n\n/**\n * given a list of rgb arrays it will generate a linear gradient css rule\n * @param direction\n * @param colors\n * @return\n */\nexport function createLinearGradient(direction: string, colors: RGBColor[]): string {\n const step = parseFloat((100.0 / colors.length).toFixed(2));\n const bands = colors.map((rgb, index) => {\n return `rgba(${rgb.join(',')}, 1) ${step * index}%, rgba(${rgb.join(',')}, 1) ${\n step * (index + 1)\n }%`;\n });\n\n return `linear-gradient(to ${direction}, ${bands.join(',')})`;\n}\n\n/**\n * Convert color to RGB\n */\nexport function colorMaybeToRGB(color: unknown): RGBColor | null {\n if (isRgbColor(color)) {\n return color as RGBColor;\n }\n\n if (typeof color === 'string') {\n const rgbObj = d3Rgb(color);\n if (Number.isFinite(rgbObj?.r) && Number.isFinite(rgbObj?.g) && Number.isFinite(rgbObj?.b)) {\n return [rgbObj.r, rgbObj.g, rgbObj.b];\n }\n }\n\n return null;\n}\n\n/**\n * Whether color is rgb\n * @returns\n */\nexport function isRgbColor(color: unknown): boolean {\n return Boolean(\n color &&\n Array.isArray(color) &&\n color.length === 3 &&\n color.every(n => Number.isFinite(n) && n <= 255 && n >= 0)\n );\n}\n\n/**\n * Take color values in 0-255 range and map to [0, 1]\n */\nexport function normalizeColor(color: number[]): number[] {\n return color.map(component => component / 255.0);\n}\n\n/**\n * Convert color to Hex\n */\nexport function colorMaybeToHex(color: unknown): HexColor {\n const rgbColor = colorMaybeToRGB(color);\n if (rgbColor) return rgbToHex(rgbColor);\n return '#000000';\n}\n\n/**\n * Convert color to Hex\n */\n\nexport function interpolateHex(hex1: HexColor, hex2: HexColor): HexColor {\n return d3Rgb(interpolate(hex1, hex2)(0.5)).formatHex().toUpperCase();\n}\n\nfunction addNewCategoricalStepAtIndex(colorMap, index, newColor) {\n if (!Array.isArray(colorMap) || !colorMap.length) {\n return colorMap;\n }\n\n let newColorMap = colorMap.map(([val, c]) => [Array.isArray(val) ? [...val] : val, c]);\n newColorMap = arrayInsert(newColorMap, index + 1, [null, newColor]);\n\n return newColorMap;\n}\n\nexport function addNewQuantativeColorBreakAtIndex(colorMap, index, newColors) {\n if (!Array.isArray(colorMap) || !colorMap.length) {\n return colorMap;\n }\n\n if (colorMap.length < 2) {\n // less then 2, add 1 at end\n // however shouldn't allow delete when there are 2\n return newColors.map((c, i) => (i === 0 ? colorMap[i] : [null, c]));\n }\n\n // breaks should be 1 less than colors\n const breaks = colorMap.map(cm => cm[0]).slice(0, colorMap.length - 1);\n\n // insert new break\n const newValue =\n index >= breaks.length - 1\n ? breaks[breaks.length - 1] +\n (breaks.length > 1 ? breaks[breaks.length - 1] - breaks[breaks.length - 2] : 0)\n : (breaks[index] + breaks[index + 1]) / 2;\n\n const newBreaks = arrayInsert(breaks, index + 1, newValue);\n\n // asign breaks to color\n return newColors.map((c, i) =>\n i === newColors.length - 1 ? [null, c] : [newBreaks[i] === undefined ? null : newBreaks[i], c]\n );\n}\n\n/**\n * Add a new color to custom palette\n */\nexport function addCustomPaletteColor(customPalette: ColorRange, index: number): ColorRange {\n const {colors, colorMap} = customPalette;\n const update: Partial<ColorRange> = {};\n\n const newColor =\n index === colors.length - 1 ? colors[index] : interpolateHex(colors[index], colors[index + 1]);\n\n update.colors = arrayInsert(colors, index + 1, newColor);\n\n // add color to colorMap\n if (colorMap) {\n update.colorMap =\n customPalette.type === 'customOrdinal'\n ? addNewCategoricalStepAtIndex(colorMap, index, newColor)\n : addNewQuantativeColorBreakAtIndex(colorMap, index, update.colors);\n }\n\n return {\n ...customPalette,\n ...update\n };\n}\n\nfunction replaceColorsInColorRange(colorRange, newColors) {\n const oldColors = colorRange.colors;\n const updated = {\n ...colorRange,\n colors: newColors\n };\n\n // update color map\n // keep value, replace color\n if (Array.isArray(updated.colorMap)) {\n updated.colorMap = updated.colorMap.map((cm, i) => [cm[0], newColors[i]]);\n }\n // update colorlegends\n // keep value, replace color\n if (updated.colorLegends) {\n updated.colorLegends = Object.keys(updated.colorLegends).reduce((accu, key) => {\n const colorIdx = oldColors.findIndex(c => c === key);\n const newColor = newColors[colorIdx];\n\n return newColor\n ? {\n ...accu,\n [newColor]: updated.colorLegends[key]\n }\n : accu;\n }, {});\n }\n\n return updated;\n}\n\n/**\n * Sort custom palette\n */\nexport function sortCustomPaletteColor(\n customPalette: ColorRange,\n oldIndex: number,\n newIndex: number\n): ColorRange {\n const {colors} = customPalette;\n\n const newColors = arrayMove(colors, oldIndex, newIndex);\n const update = replaceColorsInColorRange(customPalette, newColors);\n\n // @ts-ignore\n return {\n ...customPalette,\n ...update\n };\n}\n\n/**\n * remove a color in custom palette at index\n */\nexport function removeCustomPaletteColor(customPalette: ColorRange, index: number): ColorRange {\n const {colors, colorMap, colorLegends} = customPalette;\n const oldValue = colors[index];\n const update: Partial<ColorRange> = {};\n update.colors = [...colors];\n\n if (update.colors.length > 1) {\n update.colors.splice(index, 1);\n }\n // update color map\n if (Array.isArray(colorMap)) {\n // find colorMap index\n const colorMapIndex = colorMap.findIndex(cm => cm[1] === oldValue);\n if (colorMapIndex >= 0) {\n update.colorMap = [...colorMap];\n update.colorMap.splice(colorMapIndex, 1);\n }\n }\n // update color legend\n if (colorLegends?.[oldValue]) {\n update.colorLegends = {...colorLegends};\n delete update.colorLegends[oldValue];\n }\n\n return {\n ...customPalette,\n ...update\n };\n}\n\n/**\n * Update a color in custom palette at index\n */\nexport function updateCustomPaletteColor(\n customPalette: ColorRange,\n index: number,\n newValue: HexColor\n): ColorRange {\n const {colors} = customPalette;\n const hex = newValue.toUpperCase();\n const newColors = [...colors];\n newColors[index] = hex;\n\n const update = replaceColorsInColorRange(customPalette, newColors);\n\n // @ts-ignore\n return {\n ...customPalette,\n ...update\n };\n}\n\n/**\n * Get a reversed colorRange\n */\nexport function reverseColorRange(reversed: boolean, colorRange: ColorRange): ColorRange {\n const newColors = colorRange?.colors.slice().reverse();\n const updated = replaceColorsInColorRange(colorRange, newColors);\n updated.reversed = reversed;\n\n return updated;\n}\n\n/**\n * Whether palette matches current ColorBlindSafe config\n */\nexport function paletteIsColorBlindSafe(palette: ColorPalette, colorBlindSafe: boolean) {\n return !colorBlindSafe || (colorBlindSafe && palette.colorBlindSafe);\n}\n\n/**\n * Whether palette matches current steps config\n */\nexport function isQuaPalette(palette: ColorPalette): palette is CategoricalPalette {\n return palette.type === PALETTE_TYPES.QUA;\n}\n\n/**\n * Whether palette matches current steps config\n */\nexport function paletteIsSteps(palette: ColorPalette, steps: number): boolean {\n return !isQuaPalette(palette) || palette.maxStep >= steps;\n}\n\n/**\n * Whether palette matches current type config\n */\nexport function paletteIsType(palette: ColorPalette, type: string): boolean {\n return type === 'all' || type === palette.type;\n}\n/**\n * Find best match palette based on config, update color range by it\n */\nexport function updateColorRangeByMatchingPalette(\n currentColorRange: ColorRange,\n config: ColorRangeConfig\n): ColorRange {\n const {steps, colorBlindSafe, type} = config;\n\n const matchingPalette = KEPLER_COLOR_PALETTES.filter(\n palette =>\n // palette match type\n paletteIsType(palette, type) &&\n // palette has same step\n paletteIsSteps(palette, steps) &&\n // palette is colorBlindSafe\n paletteIsColorBlindSafe(palette, colorBlindSafe)\n );\n\n const bestMatch = matchingPalette.length\n ? matchingPalette.find(p => p.name === currentColorRange.name) || matchingPalette[0]\n : null;\n\n if (bestMatch) {\n return updateColorRangeBySelectedPalette(currentColorRange, bestMatch, config);\n }\n // we do nothing\n Console.warn(\n `we cant find any preset palette matches requirments: steps=${steps} && colorBlindSafe=${colorBlindSafe}`\n );\n\n return currentColorRange;\n}\n\n/**\n * Update custom palette when reverse the colors in custom palette, since changing 'steps',\n * 'colorBindSafe', 'type' should fall back to predefined palette.\n */\nexport function updateCustomColorRangeByColorUI(\n oldColorRange: ColorRange,\n colorConfig: ColorRangeConfig\n): ColorRange {\n const {reversed} = colorConfig;\n const colors = [...oldColorRange.colors];\n // for custom palette, one can only 'reverse' the colors in custom palette.\n colors.reverse();\n\n const colorRange = {\n name: oldColorRange.name,\n type: oldColorRange.type,\n category: oldColorRange.category,\n colors,\n ...(reversed ? {reversed} : {}),\n ...(oldColorRange.colorMap ? {colorMap: oldColorRange.colorMap} : {}),\n ...(oldColorRange.colorLegends ? {colorLegends: oldColorRange.colorLegends} : {})\n };\n\n return replaceColorsInColorRange(colorRange, colorRange.colors);\n}\n\n/**\n * Update color range after selecting a palette from color range selectoer\n * Copy over colorMap and colorLegends\n */\nexport function updateColorRangeBySelectedPalette(oldColorRange, colorPalette, colorConfig) {\n const {colors: newColors, ...newColorRange} = colorPaletteToColorRange(colorPalette, colorConfig);\n\n const colorRange = {\n colors: oldColorRange.colors,\n ...newColorRange,\n ...(oldColorRange.colorMap ? {colorMap: oldColorRange.colorMap} : {}),\n ...(oldColorRange.colorLegends ? {colorLegends: oldColorRange.colorLegends} : {})\n };\n\n return replaceColorsInColorRange(colorRange, newColors);\n}\n\nconst UberNameRegex = new RegExp(/^([A-Za-z ])+/g);\nconst ColorBrewerRegex = new RegExp(/^ColorBrewer ([A-Za-z1-9])+/g);\n\n/**\n * convert saved colorRange to colorPalette objevt type/name/category/isColorBlind\n */\nexport function colorRangeBackwardCompatibility(colorRange: ColorRange): ColorRange {\n if (!colorRange || colorRange.type === 'custom' || colorRange.colorMap) {\n // don't do anything to custom color palette, or palette with custom breaks\n return colorRange;\n }\n let trimName;\n if (colorRange.category === 'Uber') {\n const matchName = (colorRange.name ?? '').match(UberNameRegex);\n trimName = matchName ? matchName[0].trim() : null;\n // match Uber Viz Qualitative 1.4 -> Uber Viz Qualitative\n } else if (colorRange.category === 'ColorBrewer') {\n const matchName = (colorRange.name ?? '').match(ColorBrewerRegex);\n trimName = matchName ? matchName[0].replace('ColorBrewer ', '').trim() : null;\n }\n\n if (trimName) {\n const matchingPalette = KEPLER_COLOR_PALETTES.find(p => p.name === trimName);\n if (matchingPalette) {\n return {\n ...colorRange,\n name: trimName,\n type: matchingPalette?.type,\n category: matchingPalette.category\n };\n }\n }\n\n return colorRange;\n}\n\n/**\n * Initialize custom palette from current standard color range object\n */\nexport function initializeCustomPalette(colorRange: ColorRange, colorMap?: ColorMap): ColorRange {\n // TODO: check on `isReversed` key, whether we can remove it here\n const customPalette = {\n ...colorRange,\n name: DEFAULT_CUSTOM_PALETTE.name,\n type: DEFAULT_CUSTOM_PALETTE.type,\n category: DEFAULT_CUSTOM_PALETTE.category,\n ...(colorMap ? {colorMap} : {})\n };\n\n // only customPalette.colors are needed for custom palette editor with custom ordinal scale\n if (!colorMap && colorRange.type === SCALE_TYPES.customOrdinal) {\n delete customPalette.colorMap;\n }\n return customPalette;\n}\n"],"mappings":";;;;;;;AAAA;AACA;;AAEA,SAGEA,sBAAsB,EACtBC,wBAAwB,QACnB,sBAAsB;AAC7B,SAAQC,SAAS,QAAO,yBAAyB;AASjD,SAAQC,GAAG,IAAIC,KAAK,QAAO,UAAU;AACrC,SAAQC,WAAW,QAAO,gBAAgB;AAC1C,SAAQC,WAAW,QAAO,SAAS;AACnC,OAAOC,OAAO,MAAM,gBAAgB;AACpC,SAAQC,qBAAqB,EAAEC,aAAa,EAAEC,WAAW,QAAO,sBAAsB;;AAEtF;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAACC,GAAW,EAAY;EAC9C,IAAMC,MAAM,GAAGC,UAAU,CAACF,GAAG,CAAC;EAE9B,IAAI,CAACC,MAAM,EAAE;IACX,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EAClB;EAEA,IAAME,CAAC,GAAGC,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,C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AAS,CAAC,CAAC,CAAC,CAACI,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAACF,IAAI,CAAC,CAAC,GAAG,IAAI;EAC/E;EAEA,IAAIJ,QAAQ,EAAE;IACZ,IAAMrB,eAAe,GAAG9G,qBAAqB,CAACiH,IAAI,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACC,IAAI,KAAKgB,QAAQ;IAAA,EAAC;IAC5E,IAAIrB,eAAe,EAAE;MACnB,OAAApC,aAAA,CAAAA,aAAA,KACKhD,UAAU;QACbyF,IAAI,EAAEgB,QAAQ;QACd1D,IAAI,EAAEqC,eAAe,aAAfA,eAAe,uBAAfA,eAAe,CAAErC,IAAI;QAC3BgD,QAAQ,EAAEX,eAAe,CAACW;MAAQ;IAEtC;EACF;EAEA,OAAO/F,UAAU;AACnB;;AAEA;AACA;AACA;AACA,OAAO,SAASgH,uBAAuBA,CAAChH,UAAsB,EAAEG,QAAmB,EAAc;EAC/F;EACA,IAAM0C,aAAa,GAAAG,aAAA,CAAAA,aAAA,KACdhD,UAAU;IACbyF,IAAI,EAAE3H,sBAAsB,CAAC2H,IAAI;IACjC1C,IAAI,EAAEjF,sBAAsB,CAACiF,IAAI;IACjCgD,QAAQ,EAAEjI,sBAAsB,CAACiI;EAAQ,GACrC5F,QAAQ,GAAG;IAACA,QAAQ,EAARA;EAAQ,CAAC,GAAG,CAAC,CAAC,CAC/B;;EAED;EACA,IAAI,CAACA,QAAQ,IAAIH,UAAU,CAAC+C,IAAI,KAAKvE,WAAW,CAACyI,aAAa,EAAE;IAC9D,OAAOpE,aAAa,CAAC1C,QAAQ;EAC/B;EACA,OAAO0C,aAAa;AACtB","ignoreList":[]}
@@ -0,0 +1,105 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright contributors to the kepler.gl project
3
+
4
+ import { deviation, mean, quantileSorted } from 'd3-array';
5
+ import { ALL_FIELD_TYPES } from '@kepler.gl/constants';
6
+ import { isNumber } from './data-utils';
7
+ import { histogramFromValues } from './plot';
8
+ import quickInsertionSort from './quick-insertion-sort';
9
+ export var NUMERIC_BIN_COUNT = 20;
10
+ export var ColumnStatsType = /*#__PURE__*/function (ColumnStatsType) {
11
+ ColumnStatsType["numeric"] = "numeric";
12
+ ColumnStatsType["categorical"] = "categorical";
13
+ ColumnStatsType["boolean"] = "boolean";
14
+ ColumnStatsType["time"] = "time";
15
+ ColumnStatsType["geo"] = "geo";
16
+ ColumnStatsType["other"] = "other";
17
+ return ColumnStatsType;
18
+ }({});
19
+ var QUANTILE_STOPS = [0, 0.25, 0.5, 0.75, 1];
20
+ function percentNulls(total, valid) {
21
+ return total > 0 ? (total - valid) / total : null;
22
+ }
23
+ function getNumericStats(values) {
24
+ var _mean, _deviation;
25
+ var filtered = values.filter(isNumber);
26
+ quickInsertionSort(filtered);
27
+ var quantiles = QUANTILE_STOPS.map(function (p) {
28
+ var _quantileSorted;
29
+ return {
30
+ label: p === 0 ? 'Min' : p === 1 ? 'Max' : "".concat(p * 100, "%"),
31
+ value: filtered.length ? (_quantileSorted = quantileSorted(filtered, p)) !== null && _quantileSorted !== void 0 ? _quantileSorted : null : null
32
+ };
33
+ });
34
+ return {
35
+ type: ColumnStatsType.numeric,
36
+ bins: histogramFromValues(filtered, NUMERIC_BIN_COUNT),
37
+ quantiles: quantiles,
38
+ percentNulls: percentNulls(values.length, filtered.length),
39
+ mean: filtered.length ? (_mean = mean(filtered)) !== null && _mean !== void 0 ? _mean : null : null,
40
+ std: filtered.length ? (_deviation = deviation(filtered)) !== null && _deviation !== void 0 ? _deviation : null : null
41
+ };
42
+ }
43
+ function isPresentCategoricalValue(v) {
44
+ return v !== null && v !== undefined && v !== '';
45
+ }
46
+ function getCategoricalStats(values) {
47
+ var filtered = values.filter(isPresentCategoricalValue);
48
+ return {
49
+ type: ColumnStatsType.categorical,
50
+ uniqueValues: new Set(filtered).size,
51
+ percentNulls: percentNulls(values.length, filtered.length)
52
+ };
53
+ }
54
+ function getTimeStats(values) {
55
+ var filtered = values.filter(isNumber);
56
+ var bins = histogramFromValues(filtered, NUMERIC_BIN_COUNT);
57
+ return {
58
+ type: ColumnStatsType.time,
59
+ bins: bins,
60
+ min: filtered.length ? filtered.reduce(function (a, b) {
61
+ return a < b ? a : b;
62
+ }) : null,
63
+ max: filtered.length ? filtered.reduce(function (a, b) {
64
+ return a > b ? a : b;
65
+ }) : null,
66
+ percentNulls: percentNulls(values.length, filtered.length)
67
+ };
68
+ }
69
+ export function collectColumnValues(dataContainer, fieldIdx) {
70
+ var n = dataContainer.numRows();
71
+ var values = new Array(n);
72
+ for (var i = 0; i < n; i++) {
73
+ values[i] = dataContainer.valueAt(i, fieldIdx);
74
+ }
75
+ return values;
76
+ }
77
+ export function computeColumnStats(values, fieldType) {
78
+ switch (fieldType) {
79
+ case ALL_FIELD_TYPES.real:
80
+ case ALL_FIELD_TYPES.integer:
81
+ return getNumericStats(values);
82
+ case ALL_FIELD_TYPES.string:
83
+ case ALL_FIELD_TYPES.date:
84
+ case ALL_FIELD_TYPES["boolean"]:
85
+ return getCategoricalStats(values);
86
+ case ALL_FIELD_TYPES.timestamp:
87
+ return getTimeStats(values);
88
+ default:
89
+ return {
90
+ type: ColumnStatsType.other
91
+ };
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Compute column statistics asynchronously so the UI can paint a loading state first.
97
+ */
98
+ export function getColumnStatistics(_ref) {
99
+ var values = _ref.values,
100
+ fieldType = _ref.fieldType;
101
+ return new Promise(function (resolve) {
102
+ resolve(computeColumnStats(values, fieldType));
103
+ });
104
+ }
105
+ //# sourceMappingURL=column-statistics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-statistics.js","names":["deviation","mean","quantileSorted","ALL_FIELD_TYPES","isNumber","histogramFromValues","quickInsertionSort","NUMERIC_BIN_COUNT","ColumnStatsType","QUANTILE_STOPS","percentNulls","total","valid","getNumericStats","values","_mean","_deviation","filtered","filter","quantiles","map","p","_quantileSorted","label","concat","value","length","type","numeric","bins","std","isPresentCategoricalValue","v","undefined","getCategoricalStats","categorical","uniqueValues","Set","size","getTimeStats","time","min","reduce","a","b","max","collectColumnValues","dataContainer","fieldIdx","n","numRows","Array","i","valueAt","computeColumnStats","fieldType","real","integer","string","date","timestamp","other","getColumnStatistics","_ref","Promise","resolve"],"sources":["../../src/column-statistics.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {deviation, mean, quantileSorted} from 'd3-array';\n\nimport {ALL_FIELD_TYPES} from '@kepler.gl/constants';\nimport {Bin} from '@kepler.gl/types';\n\nimport {isNumber} from './data-utils';\nimport {histogramFromValues} from './plot';\nimport quickInsertionSort from './quick-insertion-sort';\nimport {DataContainerInterface} from './data-container-interface';\n\nexport const NUMERIC_BIN_COUNT = 20;\n\nexport enum ColumnStatsType {\n numeric = 'numeric',\n categorical = 'categorical',\n boolean = 'boolean',\n time = 'time',\n geo = 'geo',\n other = 'other'\n}\n\nexport type Quantile = {label: string; value: number | null};\n\nexport type NumericColumnStats = {\n type: ColumnStatsType.numeric;\n bins: Bin[];\n quantiles: Quantile[];\n mean: number | null;\n std: number | null;\n percentNulls: number | null;\n};\n\nexport type CategoricalColumnStats = {\n type: ColumnStatsType.categorical;\n uniqueValues: number;\n percentNulls: number | null;\n};\n\nexport type TimeColumnStats = {\n type: ColumnStatsType.time;\n bins: Bin[];\n min: number | null;\n max: number | null;\n percentNulls: number | null;\n};\n\nexport type BooleanColumnStats = {\n type: ColumnStatsType.boolean;\n};\n\nexport type GeometryColumnStats = {\n type: ColumnStatsType.geo;\n};\n\nexport type UnknownColumnStats = {\n type: ColumnStatsType.other;\n};\n\nexport type ColumnStats =\n | NumericColumnStats\n | BooleanColumnStats\n | CategoricalColumnStats\n | TimeColumnStats\n | GeometryColumnStats\n | UnknownColumnStats;\n\nconst QUANTILE_STOPS = [0, 0.25, 0.5, 0.75, 1];\n\nfunction percentNulls(total: number, valid: number): number | null {\n return total > 0 ? (total - valid) / total : null;\n}\n\nfunction getNumericStats(values: readonly unknown[]): NumericColumnStats {\n const filtered = values.filter(isNumber);\n quickInsertionSort(filtered);\n\n const quantiles = QUANTILE_STOPS.map(p => ({\n label: p === 0 ? 'Min' : p === 1 ? 'Max' : `${p * 100}%`,\n value: filtered.length ? quantileSorted(filtered, p) ?? null : null\n }));\n\n return {\n type: ColumnStatsType.numeric,\n bins: histogramFromValues(filtered, NUMERIC_BIN_COUNT),\n quantiles,\n percentNulls: percentNulls(values.length, filtered.length),\n mean: filtered.length ? mean(filtered) ?? null : null,\n std: filtered.length ? deviation(filtered) ?? null : null\n };\n}\n\nfunction isPresentCategoricalValue(v: unknown): boolean {\n return v !== null && v !== undefined && v !== '';\n}\n\nfunction getCategoricalStats(values: readonly unknown[]): CategoricalColumnStats {\n const filtered = values.filter(isPresentCategoricalValue);\n return {\n type: ColumnStatsType.categorical,\n uniqueValues: new Set(filtered).size,\n percentNulls: percentNulls(values.length, filtered.length)\n };\n}\n\nfunction getTimeStats(values: readonly unknown[]): TimeColumnStats {\n const filtered = values.filter(isNumber);\n const bins = histogramFromValues(filtered, NUMERIC_BIN_COUNT);\n\n return {\n type: ColumnStatsType.time,\n bins,\n min: filtered.length ? filtered.reduce((a, b) => (a < b ? a : b)) : null,\n max: filtered.length ? filtered.reduce((a, b) => (a > b ? a : b)) : null,\n percentNulls: percentNulls(values.length, filtered.length)\n };\n}\n\nexport function collectColumnValues(\n dataContainer: DataContainerInterface,\n fieldIdx: number\n): unknown[] {\n const n = dataContainer.numRows();\n const values = new Array(n);\n for (let i = 0; i < n; i++) {\n values[i] = dataContainer.valueAt(i, fieldIdx);\n }\n return values;\n}\n\nexport function computeColumnStats(values: readonly unknown[], fieldType: string): ColumnStats {\n switch (fieldType) {\n case ALL_FIELD_TYPES.real:\n case ALL_FIELD_TYPES.integer:\n return getNumericStats(values);\n case ALL_FIELD_TYPES.string:\n case ALL_FIELD_TYPES.date:\n case ALL_FIELD_TYPES.boolean:\n return getCategoricalStats(values);\n case ALL_FIELD_TYPES.timestamp:\n return getTimeStats(values);\n default:\n return {type: ColumnStatsType.other};\n }\n}\n\n/**\n * Compute column statistics asynchronously so the UI can paint a loading state first.\n */\nexport function getColumnStatistics({\n values,\n fieldType\n}: {\n values: readonly unknown[];\n fieldType: string;\n}): Promise<ColumnStats> {\n return new Promise(resolve => {\n resolve(computeColumnStats(values, fieldType));\n });\n}\n"],"mappings":"AAAA;AACA;;AAEA,SAAQA,SAAS,EAAEC,IAAI,EAAEC,cAAc,QAAO,UAAU;AAExD,SAAQC,eAAe,QAAO,sBAAsB;AAGpD,SAAQC,QAAQ,QAAO,cAAc;AACrC,SAAQC,mBAAmB,QAAO,QAAQ;AAC1C,OAAOC,kBAAkB,MAAM,wBAAwB;AAGvD,OAAO,IAAMC,iBAAiB,GAAG,EAAE;AAEnC,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAsD3B,IAAMC,cAAc,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAE9C,SAASC,YAAYA,CAACC,KAAa,EAAEC,KAAa,EAAiB;EACjE,OAAOD,KAAK,GAAG,CAAC,GAAG,CAACA,KAAK,GAAGC,KAAK,IAAID,KAAK,GAAG,IAAI;AACnD;AAEA,SAASE,eAAeA,CAACC,MAA0B,EAAsB;EAAA,IAAAC,KAAA,EAAAC,UAAA;EACvE,IAAMC,QAAQ,GAAGH,MAAM,CAACI,MAAM,CAACd,QAAQ,CAAC;EACxCE,kBAAkB,CAACW,QAAQ,CAAC;EAE5B,IAAME,SAAS,GAAGV,cAAc,CAACW,GAAG,CAAC,UAAAC,CAAC;IAAA,IAAAC,eAAA;IAAA,OAAK;MACzCC,KAAK,EAAEF,CAAC,KAAK,CAAC,GAAG,KAAK,GAAGA,CAAC,KAAK,CAAC,GAAG,KAA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B,OAAO5C,eAAe,CAACC,MAAM,CAAC;IAChC,KAAKX,eAAe,CAACuD,MAAM;IAC3B,KAAKvD,eAAe,CAACwD,IAAI;IACzB,KAAKxD,eAAe,WAAQ;MAC1B,OAAO+B,mBAAmB,CAACpB,MAAM,CAAC;IACpC,KAAKX,eAAe,CAACyD,SAAS;MAC5B,OAAOrB,YAAY,CAACzB,MAAM,CAAC;IAC7B;MACE,OAAO;QAACa,IAAI,EAAEnB,eAAe,CAACqD;MAAK,CAAC;EACxC;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAAC,IAAA,EAMV;EAAA,IALvBjD,MAAM,GAAAiD,IAAA,CAANjD,MAAM;IACNyC,SAAS,GAAAQ,IAAA,CAATR,SAAS;EAKT,OAAO,IAAIS,OAAO,CAAC,UAAAC,OAAO,EAAI;IAC5BA,OAAO,CAACX,kBAAkB,CAACxC,MAAM,EAAEyC,SAAS,CAAC,CAAC;EAChD,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export {};
2
+ export {};
3
+ //# sourceMappingURL=data-container-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-container-interface.js","names":[],"sources":["../../src/data-container-interface.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {ProtoDatasetField} from '@kepler.gl/types';\nimport {DataRow, SharedRowOptions} from './data-row';\nimport * as arrow from 'apache-arrow';\n\n/**\n * Specifies a range of rows of a data container that should be processed.\n */\nexport type RangeOptions = {\n start?: number;\n end?: number;\n};\nexport interface DataContainerInterface {\n /**\n * Updates the data container with new data.\n * @param updateData updated data, e.g. for arrow data container, it's an array of arrow columns or an arrow.Table; for row data container, it's an array of rows.\n */\n update?(updateData: any[] | arrow.Table, options?: Record<string, unknown>): void;\n\n /**\n * Append rows in place. Implemented by row and Arrow containers.\n * @returns false when the rows are rejected (wrong shape or unsupported Arrow type) and the container is unchanged.\n */\n append?(rows: any[][]): boolean;\n\n /**\n * Replace one row in place. Implemented by row and Arrow containers.\n * @returns false when the index or row is rejected and the container is unchanged.\n */\n replace?(index: number, row: any[]): boolean;\n\n /**\n * Remove rows by index in place. Implemented by row and Arrow containers.\n * @returns false when any index is invalid and the container is unchanged.\n */\n remove?(indexes: number[]): boolean;\n\n /**\n * Returns the number of rows in the data container.\n * @returns Number of rows in the data container.\n */\n numRows(): number;\n\n /**\n * Returns the number of columns in the data container.\n * @returns Number of columns in the data container.\n */\n numColumns(): number;\n\n /**\n * Returns the value stored at the specified cell in the data container.\n * @param rowIndex Row index.\n * @param columnIndex Column index.\n * @returns Value at the specified cell.\n */\n valueAt(rowIndex: number, columnIndex: number): any;\n\n /**\n * Returns the row at the specified index.\n * @param rowIndex Row index.\n * @param sharedRow Passed row is filled with contents from the specified index and returned without extra row allocations.\n * @returns A row object.\n */\n row(rowIndex: number, sharedRow?: SharedRowOptions): DataRow;\n\n /**\n * Returns the specified row of the data container represented as an array.\n * @param rowIndex Row index.\n * @returns The specified row represented as an array.\n */\n rowAsArray(rowIndex: number): any[];\n\n /**\n * Returns an iterator to sequentially access all rows in the data container.\n * @param sharedRow Indicates that a temporary row object should be used.\n * If enabled, the returned row object is shared between calls\n * and mustn't be stored without cloning.\n * Passed row is filled with contents of the specified row and returned on each iteration.\n * @returns An iterator to sequentially access all rows in the data container.\n */\n rows(sharedRow?: SharedRowOptions): Generator<DataRow, void, any>;\n\n /**\n * Returns an iterator to sequentially access all values in the specified column of the data container.\n * @param columnIndex Column index.\n * @returns An iterator to all values in the specified column of the data container.\n */\n column(columnIndex: number): Generator<any, void, any>;\n\n /**\n * Returns the column object at the specified index.\n * @param columnIndex Column index.\n * @returns The column object at the specified index.\n */\n getColumn?(columnIndex: number): unknown;\n\n /**\n * Returns the field object at the specified index.\n * @param columnIndex Column index.\n * @returns The field object at the specified index.\n */\n getField?(columnIndex: number): ProtoDatasetField;\n\n /**\n * Returns the underlying data object.\n * @returns Returns the underlying data object.\n */\n getTable?(): unknown;\n\n /**\n * Returns contents of the data container as a two-dimensional array.\n * @returns Data.\n */\n flattenData(): any[][];\n\n /**\n * Generates an array of indices where each index represents a row in the data container.\n * @returns An array of indices.\n */\n getPlainIndex(): number[];\n\n /**\n * Creates a new array populated with the results of calling the provided callback\n * on every row in the data container.\n * @param func Callback that is called for every row of the data container.\n * The callback is called with the following arguments:\n * - row: The current row being processed in the data container.\n * - index: The index of the current row being processed in the data container.\n * @param sharedRow Truthy value indicates that a shared row object should be used.\n * Make sure the func callback doesn't store the row object in such case,\n * and clone the row in case you need to store it.\n * @param options Specify start and end row indices that should be mapped.\n * @returns A new array with each element being the result of the func callback.\n */\n map(\n func: (row: DataRow, index: number) => any,\n sharedRow?: SharedRowOptions,\n options?: RangeOptions\n ): any[];\n\n /**\n * Creates a new array populated with the results of calling the provided callback.\n * The callback is called for every row in the dataset, but only {index} object is passed.\n * @param func Callback that is called for every row of the data container.\n * @param options Specify start and end row indices that should be mapped.\n * @returns A new array with each element being the result of the func callback.\n */\n mapIndex(\n func: ({index}: {index: number}, dataContainer: DataContainerInterface) => any,\n options?: RangeOptions\n ): any[];\n\n /**\n * Returns the value of the first row in the provided data container that satisfies the provided testing function.\n * @param func Function to execute on each value in the array.\n * The function is called with the following arguments:\n * - row: The current row being processed in the data container.\n * - index: The index of the current row being processed in the data container.\n * @param sharedRow Truthy value indicates that a shared row object should be used.\n * Make sure the func callback doesn't store the row object in such case,\n * and clone the row in case you need to store it.\n * @returns First matching row or undefined if no rows satisfy the testing function.\n */\n find(\n func: (row: DataRow, index: number) => any,\n sharedRow?: SharedRowOptions\n ): DataRow | undefined;\n\n /**\n * Executes a reducer function on each element of the data container, resulting in single output value.\n * @param func A function to execute on each row in the data container.\n * The function is called with the following arguments:\n * - acc: The accumulator accumulates func's return values.\n * - row: The current row being processed in the data container.\n * - index: The index of the current row being processed in the data container.\n * @param initialValue A value to use as the first argument to the first call of the func.\n * @param sharedRow Truthy value indicates that a shared row object should be used.\n * Make sure the func callback doesn't store the row object in such case,\n * and clone the row in case you need to store it.\n * @returns The single value that results from the reduction.\n */\n reduce(\n func: (acc: any, row: DataRow, index: number) => any,\n initialValue: any,\n sharedRow?: SharedRowOptions\n ): any;\n}\n"],"mappings":"","ignoreList":[]}