@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.
- package/dist/application-config.d.ts +180 -1
- package/dist/arrow-data-container.d.ts +55 -2
- package/dist/camera-tour.d.ts +11 -0
- package/dist/camera-utils.d.ts +7 -0
- package/dist/cjs/aggregation.js +84 -0
- package/dist/cjs/aggregation.js.map +1 -0
- package/dist/cjs/application-config-types.js +6 -0
- package/dist/cjs/application-config-types.js.map +1 -0
- package/dist/cjs/application-config.js +178 -0
- package/dist/cjs/application-config.js.map +1 -0
- package/dist/cjs/arrow-data-container.js +1152 -0
- package/dist/cjs/arrow-data-container.js.map +1 -0
- package/dist/cjs/browser-utils.js +17 -0
- package/dist/cjs/browser-utils.js.map +1 -0
- package/dist/cjs/camera-tour.js +99 -0
- package/dist/cjs/camera-tour.js.map +1 -0
- package/dist/cjs/camera-utils.js +81 -0
- package/dist/cjs/camera-utils.js.map +1 -0
- package/dist/cjs/color-utils.js +462 -0
- package/dist/cjs/color-utils.js.map +1 -0
- package/dist/cjs/column-statistics.js +115 -0
- package/dist/cjs/column-statistics.js.map +1 -0
- package/dist/cjs/data-container-interface.js +6 -0
- package/dist/cjs/data-container-interface.js.map +1 -0
- package/dist/cjs/data-container-utils.js +76 -0
- package/dist/cjs/data-container-utils.js.map +1 -0
- package/dist/cjs/data-row.js +110 -0
- package/dist/cjs/data-row.js.map +1 -0
- package/dist/cjs/data-scale-utils.js +634 -0
- package/dist/cjs/data-scale-utils.js.map +1 -0
- package/dist/cjs/data-utils.js +538 -0
- package/dist/cjs/data-utils.js.map +1 -0
- package/dist/cjs/dataset-utils.js +361 -0
- package/dist/cjs/dataset-utils.js.map +1 -0
- package/dist/cjs/dom-to-image.js +433 -0
- package/dist/cjs/dom-to-image.js.map +1 -0
- package/dist/cjs/dom-utils.js +349 -0
- package/dist/cjs/dom-utils.js.map +1 -0
- package/dist/cjs/editor-feature-utils.js +177 -0
- package/dist/cjs/editor-feature-utils.js.map +1 -0
- package/dist/cjs/effect-utils.js +340 -0
- package/dist/cjs/effect-utils.js.map +1 -0
- package/dist/cjs/export-map-html.js +112 -0
- package/dist/cjs/export-map-html.js.map +1 -0
- package/dist/cjs/export-utils.js +318 -0
- package/dist/cjs/export-utils.js.map +1 -0
- package/dist/cjs/extract-dataset-utils.js +218 -0
- package/dist/cjs/extract-dataset-utils.js.map +1 -0
- package/dist/cjs/filter-utils.js +1762 -0
- package/dist/cjs/filter-utils.js.map +1 -0
- package/dist/cjs/format.js +38 -0
- package/dist/cjs/format.js.map +1 -0
- package/dist/cjs/gl-utils.js +118 -0
- package/dist/cjs/gl-utils.js.map +1 -0
- package/dist/{index.js → cjs/index.js} +391 -10
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/indexed-data-container.js +214 -0
- package/dist/cjs/indexed-data-container.js.map +1 -0
- package/dist/cjs/jenks.js +156 -0
- package/dist/cjs/jenks.js.map +1 -0
- package/dist/cjs/locale-utils.js +39 -0
- package/dist/cjs/locale-utils.js.map +1 -0
- package/dist/cjs/map-info-utils.js +41 -0
- package/dist/cjs/map-info-utils.js.map +1 -0
- package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
- package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
- package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
- package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
- package/dist/cjs/map-utils.js +76 -0
- package/dist/cjs/map-utils.js.map +1 -0
- package/dist/cjs/mapbox-utils.js +19 -0
- package/dist/cjs/mapbox-utils.js.map +1 -0
- package/dist/cjs/notifications-utils.js +69 -0
- package/dist/cjs/notifications-utils.js.map +1 -0
- package/dist/cjs/observe-dimensions.js +136 -0
- package/dist/cjs/observe-dimensions.js.map +1 -0
- package/dist/cjs/plot.js +1502 -0
- package/dist/cjs/plot.js.map +1 -0
- package/dist/cjs/position-utils.js +29 -0
- package/dist/cjs/position-utils.js.map +1 -0
- package/dist/cjs/projection-utils.js +141 -0
- package/dist/cjs/projection-utils.js.map +1 -0
- package/dist/cjs/quick-insertion-sort.js +132 -0
- package/dist/cjs/quick-insertion-sort.js.map +1 -0
- package/dist/cjs/row-data-container.js +291 -0
- package/dist/cjs/row-data-container.js.map +1 -0
- package/dist/cjs/slider-scale-utils.js +138 -0
- package/dist/cjs/slider-scale-utils.js.map +1 -0
- package/dist/cjs/split-map-utils.js +117 -0
- package/dist/cjs/split-map-utils.js.map +1 -0
- package/dist/cjs/strings.js +16 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/theme-utils.js +46 -0
- package/dist/cjs/theme-utils.js.map +1 -0
- package/dist/cjs/time.js +321 -0
- package/dist/cjs/time.js.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.js +224 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/column-statistics.d.ts +54 -0
- package/dist/data-container-interface.d.ts +16 -1
- package/dist/data-container-utils.d.ts +2 -1
- package/dist/data-scale-utils.d.ts +5 -0
- package/dist/data-utils.d.ts +3 -3
- package/dist/dataset-utils.d.ts +11 -28
- package/dist/editor-feature-utils.d.ts +30 -0
- package/dist/esm/aggregation.js +75 -0
- package/dist/esm/aggregation.js.map +1 -0
- package/dist/esm/application-config-types.js +3 -0
- package/dist/esm/application-config-types.js.map +1 -0
- package/dist/esm/application-config.js +167 -0
- package/dist/esm/application-config.js.map +1 -0
- package/dist/esm/arrow-data-container.js +1136 -0
- package/dist/esm/arrow-data-container.js.map +1 -0
- package/dist/esm/browser-utils.js +11 -0
- package/dist/esm/browser-utils.js.map +1 -0
- package/dist/esm/camera-tour.js +92 -0
- package/dist/esm/camera-tour.js.map +1 -0
- package/dist/esm/camera-utils.js +74 -0
- package/dist/esm/camera-utils.js.map +1 -0
- package/dist/esm/color-utils.js +435 -0
- package/dist/esm/color-utils.js.map +1 -0
- package/dist/esm/column-statistics.js +105 -0
- package/dist/esm/column-statistics.js.map +1 -0
- package/dist/esm/data-container-interface.js +3 -0
- package/dist/esm/data-container-interface.js.map +1 -0
- package/dist/esm/data-container-utils.js +68 -0
- package/dist/esm/data-container-utils.js.map +1 -0
- package/dist/esm/data-row.js +106 -0
- package/dist/esm/data-row.js.map +1 -0
- package/dist/esm/data-scale-utils.js +602 -0
- package/dist/esm/data-scale-utils.js.map +1 -0
- package/dist/esm/data-utils.js +504 -0
- package/dist/esm/data-utils.js.map +1 -0
- package/dist/esm/dataset-utils.js +352 -0
- package/dist/esm/dataset-utils.js.map +1 -0
- package/dist/esm/dom-to-image.js +426 -0
- package/dist/esm/dom-to-image.js.map +1 -0
- package/dist/esm/dom-utils.js +323 -0
- package/dist/esm/dom-utils.js.map +1 -0
- package/dist/esm/editor-feature-utils.js +164 -0
- package/dist/esm/editor-feature-utils.js.map +1 -0
- package/dist/esm/effect-utils.js +333 -0
- package/dist/esm/effect-utils.js.map +1 -0
- package/dist/esm/export-map-html.js +107 -0
- package/dist/esm/export-map-html.js.map +1 -0
- package/dist/esm/export-utils.js +297 -0
- package/dist/esm/export-utils.js.map +1 -0
- package/dist/esm/extract-dataset-utils.js +206 -0
- package/dist/esm/extract-dataset-utils.js.map +1 -0
- package/dist/esm/filter-utils.js +1701 -0
- package/dist/esm/filter-utils.js.map +1 -0
- package/dist/esm/format.js +31 -0
- package/dist/esm/format.js.map +1 -0
- package/dist/esm/gl-utils.js +113 -0
- package/dist/esm/gl-utils.js.map +1 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexed-data-container.js +210 -0
- package/dist/esm/indexed-data-container.js.map +1 -0
- package/dist/esm/jenks.js +149 -0
- package/dist/esm/jenks.js.map +1 -0
- package/dist/esm/locale-utils.js +36 -0
- package/dist/esm/locale-utils.js.map +1 -0
- package/dist/esm/map-info-utils.js +35 -0
- package/dist/esm/map-info-utils.js.map +1 -0
- package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
- package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
- package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
- package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
- package/dist/esm/map-utils.js +72 -0
- package/dist/esm/map-utils.js.map +1 -0
- package/dist/esm/mapbox-utils.js +13 -0
- package/dist/esm/mapbox-utils.js.map +1 -0
- package/dist/esm/notifications-utils.js +63 -0
- package/dist/esm/notifications-utils.js.map +1 -0
- package/dist/esm/observe-dimensions.js +128 -0
- package/dist/esm/observe-dimensions.js.map +1 -0
- package/dist/esm/plot.js +1460 -0
- package/dist/esm/plot.js.map +1 -0
- package/dist/esm/position-utils.js +22 -0
- package/dist/esm/position-utils.js.map +1 -0
- package/dist/esm/projection-utils.js +131 -0
- package/dist/esm/projection-utils.js.map +1 -0
- package/dist/esm/quick-insertion-sort.js +125 -0
- package/dist/esm/quick-insertion-sort.js.map +1 -0
- package/dist/esm/row-data-container.js +286 -0
- package/dist/esm/row-data-container.js.map +1 -0
- package/dist/esm/slider-scale-utils.js +129 -0
- package/dist/esm/slider-scale-utils.js.map +1 -0
- package/dist/esm/split-map-utils.js +109 -0
- package/dist/esm/split-map-utils.js.map +1 -0
- package/dist/esm/strings.js +10 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/theme-utils.js +38 -0
- package/dist/esm/theme-utils.js.map +1 -0
- package/dist/esm/time.js +308 -0
- package/dist/esm/time.js.map +1 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.js +203 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/export-map-html.d.ts +5 -0
- package/dist/export-utils.d.ts +31 -3
- package/dist/extract-dataset-utils.d.ts +79 -0
- package/dist/filter-utils.d.ts +56 -7
- package/dist/index.d.ts +20 -9
- package/dist/jenks.d.ts +5 -0
- package/dist/map-info-utils.d.ts +11 -1
- package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
- package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
- package/dist/plot.d.ts +187 -21
- package/dist/projection-utils.d.ts +6 -4
- package/dist/row-data-container.d.ts +19 -0
- package/dist/split-map-utils.d.ts +7 -0
- package/dist/theme-utils.d.ts +8 -0
- package/dist/time.d.ts +3 -3
- package/dist/types.d.ts +2 -0
- package/package.json +33 -26
- package/dist/aggregation.js +0 -84
- package/dist/application-config-types.js +0 -6
- package/dist/application-config.js +0 -113
- package/dist/arrow-data-container.js +0 -398
- package/dist/browser-utils.js +0 -17
- package/dist/color-utils.js +0 -462
- package/dist/data-container-interface.js +0 -6
- package/dist/data-container-utils.js +0 -75
- package/dist/data-row.js +0 -110
- package/dist/data-scale-utils.js +0 -620
- package/dist/data-utils.js +0 -532
- package/dist/dataset-utils.js +0 -330
- package/dist/dom-to-image.js +0 -433
- package/dist/dom-utils.js +0 -349
- package/dist/effect-utils.js +0 -318
- package/dist/export-map-html.js +0 -38
- package/dist/export-utils.js +0 -203
- package/dist/filter-utils.js +0 -1274
- package/dist/format.js +0 -38
- package/dist/gl-utils.js +0 -118
- package/dist/indexed-data-container.js +0 -214
- package/dist/locale-utils.js +0 -39
- package/dist/map-info-utils.js +0 -14
- package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
- package/dist/map-style-utils/mapbox-utils.js +0 -107
- package/dist/map-utils.js +0 -72
- package/dist/mapbox-utils.js +0 -19
- package/dist/noop.d.ts +0 -1
- package/dist/noop.js +0 -13
- package/dist/notifications-utils.js +0 -69
- package/dist/observe-dimensions.js +0 -136
- package/dist/plot.js +0 -637
- package/dist/position-utils.js +0 -26
- package/dist/projection-utils.js +0 -91
- package/dist/quick-insertion-sort.js +0 -132
- package/dist/row-data-container.js +0 -206
- package/dist/searcher-utils.d.ts +0 -1
- package/dist/searcher-utils.js +0 -25
- package/dist/slider-scale-utils.js +0 -138
- package/dist/split-map-utils.js +0 -99
- package/dist/strings.js +0 -16
- package/dist/time.js +0 -325
- package/dist/types.js +0 -6
- package/dist/utils.js +0 -224
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.addCategoricalValuesToColorMap = addCategoricalValuesToColorMap;
|
|
8
|
+
exports.colorBreaksToCategoricalColorMap = colorBreaksToCategoricalColorMap;
|
|
9
|
+
exports.colorBreaksToColorMap = colorBreaksToColorMap;
|
|
10
|
+
exports.colorMapToCategoricalColorBreaks = colorMapToCategoricalColorBreaks;
|
|
11
|
+
exports.colorMapToColorBreaks = colorMapToColorBreaks;
|
|
12
|
+
exports.getCategoricalColorMap = getCategoricalColorMap;
|
|
13
|
+
exports.getCategoricalColorScale = getCategoricalColorScale;
|
|
14
|
+
exports.getDomainStepsbyZoom = getDomainStepsbyZoom;
|
|
15
|
+
exports.getHistogramDomain = getHistogramDomain;
|
|
16
|
+
exports.getJenksDomain = getJenksDomain;
|
|
17
|
+
exports.getLayerColorScale = getLayerColorScale;
|
|
18
|
+
exports.getLegendOfScale = getLegendOfScale;
|
|
19
|
+
exports.getLinearDomain = getLinearDomain;
|
|
20
|
+
exports.getLogDomain = getLogDomain;
|
|
21
|
+
exports.getOrdinalDomain = getOrdinalDomain;
|
|
22
|
+
exports.getOrdinalLegends = getOrdinalLegends;
|
|
23
|
+
exports.getQuantLabelFormat = getQuantLabelFormat;
|
|
24
|
+
exports.getQuantLegends = getQuantLegends;
|
|
25
|
+
exports.getQuantileDomain = getQuantileDomain;
|
|
26
|
+
exports.getScaleFunction = getScaleFunction;
|
|
27
|
+
exports.getThresholdsFromQuantiles = getThresholdsFromQuantiles;
|
|
28
|
+
exports.getVisualChannelScaleByZoom = getVisualChannelScaleByZoom;
|
|
29
|
+
exports.initCustomPaletteByCustomScale = initCustomPaletteByCustomScale;
|
|
30
|
+
exports.initializeLayerColorMap = initializeLayerColorMap;
|
|
31
|
+
exports.isDomainQuantile = isDomainQuantile;
|
|
32
|
+
exports.isDomainStops = isDomainStops;
|
|
33
|
+
exports.isNumericColorBreaks = isNumericColorBreaks;
|
|
34
|
+
exports.removeCategoricalValueFromColorMap = removeCategoricalValueFromColorMap;
|
|
35
|
+
exports.resetCategoricalColorMapByIndex = resetCategoricalColorMapByIndex;
|
|
36
|
+
exports.selectRestCategoricalColorMapByIndex = selectRestCategoricalColorMapByIndex;
|
|
37
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
38
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
39
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
40
|
+
var _d3Array = require("d3-array");
|
|
41
|
+
var _uniq = _interopRequireDefault(require("es-toolkit/compat/uniq"));
|
|
42
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
43
|
+
var _commonUtils = require("@kepler.gl/common-utils");
|
|
44
|
+
var _constants = require("@kepler.gl/constants");
|
|
45
|
+
var _colorUtils = require("./color-utils");
|
|
46
|
+
var _dataUtils = require("./data-utils");
|
|
47
|
+
var _filterUtils = require("./filter-utils");
|
|
48
|
+
var _jenks = _interopRequireDefault(require("./jenks"));
|
|
49
|
+
var _utils = require("./utils");
|
|
50
|
+
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; }
|
|
51
|
+
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) { (0, _defineProperty2["default"])(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; } // SPDX-License-Identifier: MIT
|
|
52
|
+
// Copyright contributors to the kepler.gl project
|
|
53
|
+
// import {FilterProps, KeplerTable} from '@kepler.gl/layers';
|
|
54
|
+
// TODO isolate types - depends on @kepler.gl/layers
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* return quantile domain for an array of data
|
|
58
|
+
*/
|
|
59
|
+
function getQuantileDomain(data, valueAccessor, sortFunc) {
|
|
60
|
+
var values = typeof valueAccessor === 'function' ? data.map(valueAccessor) : data;
|
|
61
|
+
return values.filter(_commonUtils.notNullorUndefined).sort(sortFunc);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Return Jenks natural-break thresholds for an array of data.
|
|
66
|
+
* `k` is the number of color classes (range length).
|
|
67
|
+
*/
|
|
68
|
+
function getJenksDomain(data, valueAccessor, k) {
|
|
69
|
+
var values = typeof valueAccessor === 'function' ? data.map(valueAccessor).filter(_dataUtils.isNumber) : data.filter(_dataUtils.isNumber);
|
|
70
|
+
return (0, _jenks["default"])(values, k);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* return ordinal domain for a data container
|
|
75
|
+
*/
|
|
76
|
+
function getOrdinalDomain(dataContainer, valueAccessor) {
|
|
77
|
+
var values = dataContainer.mapIndex(valueAccessor);
|
|
78
|
+
return (0, _dataUtils.unique)(values).filter(_commonUtils.notNullorUndefined).sort();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* return linear domain for an array of data
|
|
83
|
+
*/
|
|
84
|
+
function getLinearDomain(data, valueAccessor) {
|
|
85
|
+
var range = typeof valueAccessor === 'function' ? (0, _d3Array.extent)(data, valueAccessor) : (0, _d3Array.extent)(data);
|
|
86
|
+
return range.map(function (d, i) {
|
|
87
|
+
return d === undefined ? i : d;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* return linear domain for an array of data. A log scale domain cannot contain 0
|
|
93
|
+
*/
|
|
94
|
+
function getLogDomain(data, valueAccessor) {
|
|
95
|
+
var _getLinearDomain = getLinearDomain(data, valueAccessor),
|
|
96
|
+
_getLinearDomain2 = (0, _slicedToArray2["default"])(_getLinearDomain, 2),
|
|
97
|
+
d0 = _getLinearDomain2[0],
|
|
98
|
+
d1 = _getLinearDomain2[1];
|
|
99
|
+
return [d0 === 0 ? 1e-5 : d0, d1];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* whether field domain is stops
|
|
103
|
+
*/
|
|
104
|
+
function isDomainStops(domain) {
|
|
105
|
+
return (0, _utils.isPlainObject)(domain) && Array.isArray(domain.stops) && Array.isArray(domain.z);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* whether field domain is quantiles
|
|
109
|
+
*/
|
|
110
|
+
function isDomainQuantile(domain) {
|
|
111
|
+
return (0, _utils.isPlainObject)(domain) && Array.isArray(domain.quantiles) && Array.isArray(domain.z);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* get the domain at zoom
|
|
116
|
+
*/
|
|
117
|
+
function getThresholdsFromQuantiles(quantiles, buckets) {
|
|
118
|
+
var thresholds = [];
|
|
119
|
+
if (!Number.isFinite(buckets) || buckets < 1) {
|
|
120
|
+
return [quantiles[0], quantiles[quantiles.length - 1]];
|
|
121
|
+
}
|
|
122
|
+
for (var i = 1; i < buckets; i++) {
|
|
123
|
+
// position in sorted array
|
|
124
|
+
var position = i / buckets;
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
thresholds.push((0, _d3Array.quantileSorted)(quantiles, position));
|
|
127
|
+
}
|
|
128
|
+
return thresholds;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* get the domain at zoom
|
|
133
|
+
*/
|
|
134
|
+
function getDomainStepsbyZoom(domain, steps, z) {
|
|
135
|
+
var i = (0, _d3Array.bisectLeft)(steps, z);
|
|
136
|
+
if (steps[i] === z) {
|
|
137
|
+
// If z is an integer value exactly matching a step, return the corresponding domain
|
|
138
|
+
return domain[i];
|
|
139
|
+
}
|
|
140
|
+
// Otherwise, return the next coarsest domain
|
|
141
|
+
return domain[Math.max(i - 1, 0)];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get d3 scale function
|
|
146
|
+
*/
|
|
147
|
+
function getScaleFunction(scale, range, domain, fixed) {
|
|
148
|
+
var scaleFunction = _constants.SCALE_FUNC[fixed ? 'linear' : scale]().domain(domain).range(fixed ? domain : range);
|
|
149
|
+
scaleFunction.scaleType = fixed ? 'linear' : scale;
|
|
150
|
+
return scaleFunction;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get threshold scale color labels
|
|
155
|
+
*/
|
|
156
|
+
function getThresholdLabels(scale, labelFormat) {
|
|
157
|
+
var genLength = scale.range().length;
|
|
158
|
+
return scale.range().map(function (d, i) {
|
|
159
|
+
var invert = scale.invertExtent(d);
|
|
160
|
+
var inputs = [i === 0 ? null : (0, _dataUtils.reverseFormatNumber)(labelFormat(invert[0])), i === genLength - 1 ? null : (0, _dataUtils.reverseFormatNumber)(labelFormat(invert[1]))];
|
|
161
|
+
return {
|
|
162
|
+
// raw value
|
|
163
|
+
range: invert,
|
|
164
|
+
// formatted value
|
|
165
|
+
inputs: inputs,
|
|
166
|
+
label: i === 0 ? "Less than ".concat(labelFormat(invert[1])) : i === genLength - 1 ? "".concat(labelFormat(invert[0]), " or more") : "".concat(labelFormat(invert[0]), " to ").concat(labelFormat(invert[1]))
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get linear / quant scale color labels
|
|
173
|
+
*/
|
|
174
|
+
function getScaleLabels(scale, labelFormat) {
|
|
175
|
+
return scale.range().map(function (d) {
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
var invert = scale.invertExtent(d);
|
|
178
|
+
var inputs = [(0, _dataUtils.reverseFormatNumber)(labelFormat(invert[0])), (0, _dataUtils.reverseFormatNumber)(labelFormat(invert[1]))];
|
|
179
|
+
return {
|
|
180
|
+
label: "".concat(labelFormat(invert[0]), " to ").concat(labelFormat(invert[1])),
|
|
181
|
+
// raw value
|
|
182
|
+
range: invert,
|
|
183
|
+
// formatted value
|
|
184
|
+
inputs: inputs
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
var customScaleLabelFormat = function customScaleLabelFormat(n) {
|
|
189
|
+
return n || n === 0 ? (0, _dataUtils.formatNumber)(n, 'real') : 'no value';
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Get linear / quant scale color breaks
|
|
193
|
+
*/
|
|
194
|
+
function getQuantLegends(scale, labelFormat) {
|
|
195
|
+
if (typeof scale.invertExtent !== 'function') {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
var thresholdLabelFormat = function thresholdLabelFormat(n, type) {
|
|
199
|
+
return n || n === 0 ? labelFormat ? labelFormat(n) : (0, _dataUtils.formatNumber)(n, type) : 'no value';
|
|
200
|
+
};
|
|
201
|
+
var labels = scale.scaleType === 'threshold' || scale.scaleType === _constants.SCALE_TYPES.jenks ? getThresholdLabels(scale, thresholdLabelFormat) : scale.scaleType === 'custom' ? getThresholdLabels(scale, customScaleLabelFormat) : getScaleLabels(scale, labelFormat);
|
|
202
|
+
var data = scale.range();
|
|
203
|
+
return labels.map(function (label, index) {
|
|
204
|
+
return _objectSpread({
|
|
205
|
+
data: Array.isArray(data[index]) ? (0, _colorUtils.rgbToHex)(data[index]) : data[index]
|
|
206
|
+
}, label);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get ordinal color scale legends
|
|
212
|
+
*/
|
|
213
|
+
function getOrdinalLegends(scale) {
|
|
214
|
+
var domain = scale.domain();
|
|
215
|
+
var labels = scale.domain();
|
|
216
|
+
var data = domain.map(scale);
|
|
217
|
+
return data.map(function (datum, index) {
|
|
218
|
+
return {
|
|
219
|
+
data: (0, _colorUtils.isRgbColor)(datum) ? (0, _colorUtils.rgbToHex)(datum) : datum,
|
|
220
|
+
label: labels[index]
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
var defaultFormat = function defaultFormat(d) {
|
|
225
|
+
return d;
|
|
226
|
+
};
|
|
227
|
+
var getTimeLabelFormat = function getTimeLabelFormat(domain) {
|
|
228
|
+
var formatter = (0, _filterUtils.getTimeWidgetHintFormatter)(domain);
|
|
229
|
+
return function (val) {
|
|
230
|
+
return _moment["default"].utc(val).format(formatter);
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
function getQuantLabelFormat(domain, fieldType) {
|
|
234
|
+
// quant scale can only be assigned to linear Fields: real, timestamp, integer
|
|
235
|
+
return fieldType === _constants.ALL_FIELD_TYPES.timestamp ? getTimeLabelFormat(domain) : !fieldType ? defaultFormat : function (n) {
|
|
236
|
+
return (0, _dataUtils.isNumber)(n) ? (0, _dataUtils.formatNumber)(n, fieldType) : 'no value';
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Get legends for scale
|
|
242
|
+
*/
|
|
243
|
+
function getLegendOfScale(_ref) {
|
|
244
|
+
var scale = _ref.scale,
|
|
245
|
+
scaleType = _ref.scaleType,
|
|
246
|
+
labelFormat = _ref.labelFormat,
|
|
247
|
+
fieldType = _ref.fieldType;
|
|
248
|
+
if (!scale || scale.byZoom) {
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
if (scaleType === _constants.SCALE_TYPES.ordinal || scaleType === _constants.SCALE_TYPES.customOrdinal || fieldType === _constants.ALL_FIELD_TYPES.string) {
|
|
252
|
+
return getOrdinalLegends(scale);
|
|
253
|
+
}
|
|
254
|
+
var formatLabel = labelFormat || getQuantLabelFormat(scale.domain(), fieldType);
|
|
255
|
+
if (scaleType === _constants.SCALE_TYPES.jenks) {
|
|
256
|
+
scale.scaleType = _constants.SCALE_TYPES.jenks;
|
|
257
|
+
}
|
|
258
|
+
return getQuantLegends(scale, formatLabel);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get color scale function
|
|
263
|
+
*/
|
|
264
|
+
function getLayerColorScale(_ref2) {
|
|
265
|
+
var range = _ref2.range,
|
|
266
|
+
domain = _ref2.domain,
|
|
267
|
+
scaleType = _ref2.scaleType,
|
|
268
|
+
layer = _ref2.layer;
|
|
269
|
+
if (range && domain && scaleType) {
|
|
270
|
+
return layer.getColorScale(scaleType, domain, range);
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Convert colorRange.colorMap into color breaks UI input
|
|
277
|
+
*/
|
|
278
|
+
function initializeLayerColorMap(layer, visualChannel) {
|
|
279
|
+
var domain = layer.config[visualChannel.domain];
|
|
280
|
+
var range = layer.config.visConfig[visualChannel.range];
|
|
281
|
+
var scaleType = layer.config[visualChannel.scale];
|
|
282
|
+
var field = layer.config[visualChannel.field];
|
|
283
|
+
var scale = getLayerColorScale({
|
|
284
|
+
range: range,
|
|
285
|
+
domain: domain,
|
|
286
|
+
scaleType: scaleType,
|
|
287
|
+
layer: layer
|
|
288
|
+
});
|
|
289
|
+
var colorBreaks = getLegendOfScale({
|
|
290
|
+
scale: scale !== null && scale !== void 0 && scale.byZoom ? scale(0) : scale,
|
|
291
|
+
scaleType: scaleType,
|
|
292
|
+
fieldType: field.type
|
|
293
|
+
});
|
|
294
|
+
return colorBreaksToColorMap(colorBreaks);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Get visual chanel scale function if it's based on zoom
|
|
299
|
+
*/
|
|
300
|
+
function getVisualChannelScaleByZoom(_ref3) {
|
|
301
|
+
var _scale;
|
|
302
|
+
var scale = _ref3.scale,
|
|
303
|
+
layer = _ref3.layer,
|
|
304
|
+
mapState = _ref3.mapState;
|
|
305
|
+
if ((_scale = scale) !== null && _scale !== void 0 && _scale.byZoom) {
|
|
306
|
+
var _layer$meta;
|
|
307
|
+
var z = (_layer$meta = layer.meta) !== null && _layer$meta !== void 0 && _layer$meta.getZoom ? layer.meta.getZoom(mapState) : mapState === null || mapState === void 0 ? void 0 : mapState.zoom;
|
|
308
|
+
scale = Number.isFinite(z) ? scale(z) : null;
|
|
309
|
+
}
|
|
310
|
+
return scale;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get categorical colorMap from colors and domain (unique values)
|
|
315
|
+
*/
|
|
316
|
+
function getCategoricalColorMap(colors, domain) {
|
|
317
|
+
var uniqueValues = (0, _dataUtils.unique)(domain).sort();
|
|
318
|
+
var colorMap = colors.map(function (color) {
|
|
319
|
+
return [null, color];
|
|
320
|
+
});
|
|
321
|
+
if (colors.length === 0 || uniqueValues.length === 0) {
|
|
322
|
+
return colorMap;
|
|
323
|
+
}
|
|
324
|
+
var lastIndex = colors.length - 1;
|
|
325
|
+
var assignCount = Math.min(lastIndex, uniqueValues.length);
|
|
326
|
+
|
|
327
|
+
// Assign first values one-to-one up to the penultimate color (if any)
|
|
328
|
+
for (var i = 0; i < assignCount; i++) {
|
|
329
|
+
// @ts-ignore tuple
|
|
330
|
+
colorMap[i][0] = uniqueValues[i];
|
|
331
|
+
}
|
|
332
|
+
if (uniqueValues.length > colors.length) {
|
|
333
|
+
// Aggregate the rest (including the value that would have gone to last color)
|
|
334
|
+
// Build aggregated array incrementally to match legacy behavior
|
|
335
|
+
var aggregatedValues = [];
|
|
336
|
+
for (var _i = lastIndex; _i < uniqueValues.length; _i++) {
|
|
337
|
+
var value = uniqueValues[_i];
|
|
338
|
+
if (Array.isArray(value)) {
|
|
339
|
+
// Spread array elements to match legacy flattening behavior
|
|
340
|
+
aggregatedValues.push.apply(aggregatedValues, (0, _toConsumableArray2["default"])(value));
|
|
341
|
+
} else {
|
|
342
|
+
aggregatedValues.push(value);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// @ts-ignore tuple
|
|
346
|
+
colorMap[lastIndex][0] = aggregatedValues;
|
|
347
|
+
} else if (uniqueValues.length === colors.length) {
|
|
348
|
+
// Exactly one per color
|
|
349
|
+
// @ts-ignore tuple
|
|
350
|
+
colorMap[lastIndex][0] = uniqueValues[lastIndex];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// @ts-ignore tuple
|
|
354
|
+
return colorMap;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Get categorical colorBreaks from colorMap
|
|
359
|
+
*/
|
|
360
|
+
function colorMapToCategoricalColorBreaks(colorMap) {
|
|
361
|
+
if (!colorMap) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
var colorBreaks = colorMap.map(function (_ref4) {
|
|
365
|
+
var _ref5 = (0, _slicedToArray2["default"])(_ref4, 2),
|
|
366
|
+
value = _ref5[0],
|
|
367
|
+
color = _ref5[1];
|
|
368
|
+
return {
|
|
369
|
+
data: color,
|
|
370
|
+
label: value
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
return colorBreaks;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* create categorical colorMap from colorBreaks
|
|
378
|
+
*/
|
|
379
|
+
function colorBreaksToCategoricalColorMap(colorBreaks) {
|
|
380
|
+
// colorMap: [string | string[], hexstring]
|
|
381
|
+
var colors = (0, _uniq["default"])(colorBreaks.map(function (cb) {
|
|
382
|
+
return cb.data;
|
|
383
|
+
}));
|
|
384
|
+
var values = (0, _uniq["default"])(colorBreaks.map(function (cb) {
|
|
385
|
+
return cb.label;
|
|
386
|
+
}));
|
|
387
|
+
return getCategoricalColorMap(colors, values);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Convert color breaks UI input into colorRange.colorMap
|
|
392
|
+
*/
|
|
393
|
+
function colorBreaksToColorMap(colorBreaks) {
|
|
394
|
+
var colorMap = colorBreaks.map(function (colorBreak, i) {
|
|
395
|
+
// [value, hex]
|
|
396
|
+
return [colorBreak.inputs ? i === colorBreaks.length - 1 ? null // last
|
|
397
|
+
: colorBreak.inputs[1] : colorBreak.label, colorBreak.data];
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// @ts-ignore tuple
|
|
401
|
+
return colorMap;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Convert colorRange.colorMap into color breaks UI input
|
|
406
|
+
*/
|
|
407
|
+
function colorMapToColorBreaks(colorMap) {
|
|
408
|
+
if (!colorMap) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
var colorBreaks = colorMap.map(function (_ref6, i) {
|
|
412
|
+
var _ref7 = (0, _slicedToArray2["default"])(_ref6, 2),
|
|
413
|
+
value = _ref7[0],
|
|
414
|
+
color = _ref7[1];
|
|
415
|
+
var range = i === 0 ?
|
|
416
|
+
// first
|
|
417
|
+
[-Infinity, value] :
|
|
418
|
+
// last
|
|
419
|
+
i === colorMap.length - 1 ? [colorMap[i - 1][0], Infinity] :
|
|
420
|
+
// else
|
|
421
|
+
[colorMap[i - 1][0], value];
|
|
422
|
+
return {
|
|
423
|
+
data: color,
|
|
424
|
+
range: range,
|
|
425
|
+
inputs: range,
|
|
426
|
+
label:
|
|
427
|
+
// first
|
|
428
|
+
i === 0 ? "Less than ".concat(value) :
|
|
429
|
+
// last
|
|
430
|
+
i === colorMap.length - 1 ? "".concat(colorMap[i - 1][0], " or more") : "".concat(colorMap[i - 1][0], " to ").concat(value)
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// @ts-ignore implement conversion for ordinal
|
|
435
|
+
return colorBreaks;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Whether color breaks is for numeric field
|
|
440
|
+
*/
|
|
441
|
+
function isNumericColorBreaks(colorBreaks) {
|
|
442
|
+
return Boolean(Array.isArray(colorBreaks) && colorBreaks.length && colorBreaks[0].inputs);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// return domainMin, domainMax, histogramMean
|
|
446
|
+
function getHistogramDomain(_ref8) {
|
|
447
|
+
var aggregatedBins = _ref8.aggregatedBins,
|
|
448
|
+
columnStats = _ref8.columnStats,
|
|
449
|
+
dataset = _ref8.dataset,
|
|
450
|
+
fieldValueAccessor = _ref8.fieldValueAccessor;
|
|
451
|
+
var domainMin = Number.POSITIVE_INFINITY;
|
|
452
|
+
var domainMax = Number.NEGATIVE_INFINITY;
|
|
453
|
+
var nValid = 0;
|
|
454
|
+
var domainSum = 0;
|
|
455
|
+
if (aggregatedBins) {
|
|
456
|
+
Object.values(aggregatedBins).forEach(function (bin) {
|
|
457
|
+
var val = bin.value;
|
|
458
|
+
if ((0, _dataUtils.isNumber)(val)) {
|
|
459
|
+
if (val < domainMin) domainMin = val;
|
|
460
|
+
if (val > domainMax) domainMax = val;
|
|
461
|
+
domainSum += val;
|
|
462
|
+
nValid += 1;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
} else {
|
|
466
|
+
if (columnStats && columnStats.quantiles && columnStats.mean) {
|
|
467
|
+
// no need to recalcuate min/max/mean if its already in columnStats
|
|
468
|
+
return [columnStats.quantiles[0].value, columnStats.quantiles[columnStats.quantiles.length - 1].value, columnStats.mean];
|
|
469
|
+
}
|
|
470
|
+
if (dataset && fieldValueAccessor) {
|
|
471
|
+
dataset.allIndexes.forEach(function (x) {
|
|
472
|
+
var val = fieldValueAccessor(x);
|
|
473
|
+
if ((0, _dataUtils.isNumber)(val)) {
|
|
474
|
+
if (val < domainMin) domainMin = val;
|
|
475
|
+
if (val > domainMax) domainMax = val;
|
|
476
|
+
domainSum += val;
|
|
477
|
+
nValid += 1;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
var histogramMean = nValid > 0 ? domainSum / nValid : 0;
|
|
483
|
+
return [nValid > 0 ? domainMin : 0, nValid > 0 ? domainMax : 0, histogramMean];
|
|
484
|
+
}
|
|
485
|
+
function resetCategoricalColorMapByIndex(colorMap, index) {
|
|
486
|
+
if (!colorMap) {
|
|
487
|
+
return colorMap;
|
|
488
|
+
}
|
|
489
|
+
var newColorMap = colorMap.map(function (cm, i) {
|
|
490
|
+
if (i === index) {
|
|
491
|
+
return [null, cm[1]];
|
|
492
|
+
}
|
|
493
|
+
return cm;
|
|
494
|
+
});
|
|
495
|
+
return newColorMap;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* select rest categorical values for a colorMap by its index
|
|
500
|
+
*/
|
|
501
|
+
function selectRestCategoricalColorMapByIndex(colorMap, index, uniqueValues) {
|
|
502
|
+
if (!colorMap || !uniqueValues) {
|
|
503
|
+
return colorMap;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// find unique values that has not been used in current colorMap
|
|
507
|
+
var uniqValueDict = Object.fromEntries(uniqueValues.map(function (val) {
|
|
508
|
+
return [val, false];
|
|
509
|
+
}));
|
|
510
|
+
colorMap.forEach(function (cm) {
|
|
511
|
+
(0, _commonUtils.toArray)(cm[0]).forEach(function (v) {
|
|
512
|
+
if ((0, _commonUtils.notNullorUndefined)(v)) uniqValueDict[v] = true;
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
var rest = Object.keys(uniqValueDict).filter(function (v) {
|
|
516
|
+
return !uniqValueDict[v];
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// use the not used unique values in the selected color map
|
|
520
|
+
var newColorMap = colorMap.map(function (cm, i) {
|
|
521
|
+
if (i === index) {
|
|
522
|
+
return [[].concat((0, _toConsumableArray2["default"])(rest), (0, _toConsumableArray2["default"])((0, _commonUtils.toArray)(cm[0]))), cm[1]];
|
|
523
|
+
}
|
|
524
|
+
return cm;
|
|
525
|
+
});
|
|
526
|
+
return newColorMap;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* remove a categorical value from a colorMap by its index
|
|
531
|
+
*/
|
|
532
|
+
function removeCategoricalValueFromColorMap(colorMap, item, index) {
|
|
533
|
+
if (!colorMap) {
|
|
534
|
+
return colorMap;
|
|
535
|
+
}
|
|
536
|
+
var newColorMap = colorMap.map(function (cm, i) {
|
|
537
|
+
if (i === index) {
|
|
538
|
+
if (!(0, _commonUtils.notNullorUndefined)(cm[0])) {
|
|
539
|
+
return [null, cm[1]];
|
|
540
|
+
}
|
|
541
|
+
var currentUniqueValues = (0, _commonUtils.toArray)(cm[0]);
|
|
542
|
+
var updatedUniqueValues = currentUniqueValues.filter(function (v) {
|
|
543
|
+
return v !== item;
|
|
544
|
+
});
|
|
545
|
+
return [updatedUniqueValues, cm[1]];
|
|
546
|
+
}
|
|
547
|
+
return cm;
|
|
548
|
+
});
|
|
549
|
+
return newColorMap;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* add categorical values (from multisel dropdown) to a colorMap by its index
|
|
554
|
+
*/
|
|
555
|
+
function addCategoricalValuesToColorMap(colorMap, items, index) {
|
|
556
|
+
if (!colorMap) {
|
|
557
|
+
return colorMap;
|
|
558
|
+
}
|
|
559
|
+
var newColorMap = colorMap.map(function (cm, i) {
|
|
560
|
+
if (i === index) {
|
|
561
|
+
if (!(0, _commonUtils.notNullorUndefined)(cm[0])) {
|
|
562
|
+
return [items, cm[1]];
|
|
563
|
+
}
|
|
564
|
+
var _currentUniqueValues = (0, _commonUtils.toArray)(cm[0]);
|
|
565
|
+
var updatedUniqueValues = (0, _uniq["default"])(_currentUniqueValues.concat(items));
|
|
566
|
+
return [updatedUniqueValues, cm[1]];
|
|
567
|
+
}
|
|
568
|
+
// remove value from other colorMap
|
|
569
|
+
var currentUniqueValues = cm[0];
|
|
570
|
+
if (Array.isArray(currentUniqueValues)) {
|
|
571
|
+
var _updatedUniqueValues = currentUniqueValues.filter(function (v) {
|
|
572
|
+
return !items.includes(v);
|
|
573
|
+
});
|
|
574
|
+
return [_updatedUniqueValues, cm[1]];
|
|
575
|
+
} else if ((0, _commonUtils.notNullorUndefined)(currentUniqueValues) && items.includes(currentUniqueValues)) {
|
|
576
|
+
return [null, cm[1]];
|
|
577
|
+
}
|
|
578
|
+
return cm;
|
|
579
|
+
});
|
|
580
|
+
return newColorMap;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* get a color scale func for categorical (custom ordinal) scale
|
|
585
|
+
*/
|
|
586
|
+
function getCategoricalColorScale(colorDomain, colorRange) {
|
|
587
|
+
var useRgb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
588
|
+
var cMap = colorRange.colorMap ? colorRange.colorMap : getCategoricalColorMap(colorRange.colors, colorDomain);
|
|
589
|
+
var range = [];
|
|
590
|
+
var domain = [];
|
|
591
|
+
cMap.forEach(function (cm) {
|
|
592
|
+
if (Array.isArray(cm[0])) {
|
|
593
|
+
cm[0].forEach(function (val) {
|
|
594
|
+
domain.push(val);
|
|
595
|
+
range.push(useRgb ? (0, _colorUtils.hexToRgb)(cm[1]) : cm[1]);
|
|
596
|
+
});
|
|
597
|
+
} else {
|
|
598
|
+
domain.push(cm[0]);
|
|
599
|
+
range.push(useRgb ? (0, _colorUtils.hexToRgb)(cm[1]) : cm[1]);
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
var scale = getScaleFunction(_constants.SCALE_TYPES.customOrdinal, range, domain, false);
|
|
603
|
+
scale.unknown(_constants.NO_VALUE_COLOR);
|
|
604
|
+
return scale;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* initialize customPalette by custom scale or customOrdinal scale
|
|
609
|
+
*/
|
|
610
|
+
function initCustomPaletteByCustomScale(_ref9) {
|
|
611
|
+
var scale = _ref9.scale,
|
|
612
|
+
field = _ref9.field,
|
|
613
|
+
ordinalDomain = _ref9.ordinalDomain,
|
|
614
|
+
range = _ref9.range,
|
|
615
|
+
colorBreaks = _ref9.colorBreaks;
|
|
616
|
+
var customPaletteName = "color.customPalette.".concat(scale, ".").concat((field === null || field === void 0 ? void 0 : field.name) || 'point-count');
|
|
617
|
+
// reuse range.colorMap if the field and scale not changed
|
|
618
|
+
var reuseColorMap = range.colorMap && range.name === customPaletteName && range.type === scale;
|
|
619
|
+
var colorMap = reuseColorMap ? range.colorMap : scale === _constants.SCALE_TYPES.customOrdinal && ordinalDomain ? getCategoricalColorMap(range.colors, ordinalDomain) : colorBreaks && isNumericColorBreaks(colorBreaks) ? colorBreaksToColorMap(colorBreaks) : null;
|
|
620
|
+
var colors = reuseColorMap ? range.colors : colorMap ? colorMap.map(function (cm) {
|
|
621
|
+
return cm[1];
|
|
622
|
+
}) : range.colors;
|
|
623
|
+
|
|
624
|
+
// update custom breaks
|
|
625
|
+
var customPalette = {
|
|
626
|
+
category: 'Custom',
|
|
627
|
+
name: customPaletteName,
|
|
628
|
+
type: scale,
|
|
629
|
+
colorMap: colorMap,
|
|
630
|
+
colors: colors || []
|
|
631
|
+
};
|
|
632
|
+
return customPalette;
|
|
633
|
+
}
|
|
634
|
+
//# sourceMappingURL=data-scale-utils.js.map
|