@kepler.gl/utils 3.3.0-alpha.14 → 3.3.0-alpha.16

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.
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright contributors to the kepler.gl project
3
+
4
+ import { THEME } from '@kepler.gl/constants';
5
+ import { getApplicationConfig } from './application-config';
6
+
7
+ /** Configured UI theme names, in cycle order. Empty when unset. */
8
+ export function getConfiguredThemes() {
9
+ var _getApplicationConfig = getApplicationConfig(),
10
+ themes = _getApplicationConfig.themes;
11
+ if (!Array.isArray(themes)) {
12
+ return [];
13
+ }
14
+ return themes.filter(function (name) {
15
+ return typeof name === 'string' && name.length > 0;
16
+ });
17
+ }
18
+
19
+ /** True when the map control should cycle themes (two or more names). */
20
+ export function shouldShowThemeSwitcher() {
21
+ return getConfiguredThemes().length > 1;
22
+ }
23
+
24
+ /** First configured theme, or dark when none are set. */
25
+ export function getDefaultUiTheme() {
26
+ return getConfiguredThemes()[0] || THEME.dark;
27
+ }
28
+
29
+ /** Next theme in the configured cycle. */
30
+ export function getNextUiTheme(current) {
31
+ var themes = getConfiguredThemes();
32
+ if (themes.length === 0) {
33
+ return THEME.dark;
34
+ }
35
+ var index = current ? themes.indexOf(current) : -1;
36
+ return themes[index === -1 ? 0 : (index + 1) % themes.length];
37
+ }
38
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJUSEVNRSIsImdldEFwcGxpY2F0aW9uQ29uZmlnIiwiZ2V0Q29uZmlndXJlZFRoZW1lcyIsIl9nZXRBcHBsaWNhdGlvbkNvbmZpZyIsInRoZW1lcyIsIkFycmF5IiwiaXNBcnJheSIsImZpbHRlciIsIm5hbWUiLCJsZW5ndGgiLCJzaG91bGRTaG93VGhlbWVTd2l0Y2hlciIsImdldERlZmF1bHRVaVRoZW1lIiwiZGFyayIsImdldE5leHRVaVRoZW1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xJQUFJLEtBQUssUUFBUSxJQUFJQSxJQUFJLENBQUNDLE1BQU0sR0FBRyxDQUFDO0VBQUEsRUFBQztBQUM3Rjs7QUFFQTtBQUNBLE9BQU8sU0FBU0MsdUJBQXVCQSxDQUFBLEVBQVk7RUFDakQsT0FBT1IsbUJBQW1CLENBQUMsQ0FBQyxDQUFDTyxNQUFNLEdBQUcsQ0FBQztBQUN6Qzs7QUFFQTtBQUNBLE9BQU8sU0FBU0UsaUJBQWlCQSxDQUFBLEVBQVc7RUFDMUMsT0FBT1QsbUJBQW1CLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJRixLQUFLLENBQUNZLElBQUk7QUFDL0M7O0FBRUE7QUFDQSxPQUFPLFNBQVNDLGNBQWNBLENBQUNDLE9BQWdCLEVBQVU7RUFDdkQsSUFBTVYsTUFBTSxHQUFHRixtQkFBbUIsQ0FBQyxDQUFDO0VBQ3BDLElBQUlFLE1BQU0sQ0FBQ0ssTUFBTSxLQUFLLENBQUMsRUFBRTtJQUN2QixPQUFPVCxLQUFLLENBQUNZLElBQUk7RUFDbkI7RUFDQSxJQUFNRyxLQUFLLEdBQUdELE9BQU8sR0FBR1YsTUFBTSxDQUFDWSxPQUFPLENBQUNGLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztFQUNwRCxPQUFPVixNQUFNLENBQUNXLEtBQUssS0FBSyxDQUFDLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQ0EsS0FBSyxHQUFHLENBQUMsSUFBSVgsTUFBTSxDQUFDSyxNQUFNLENBQUM7QUFDL0QiLCJpZ25vcmVMaXN0IjpbXX0=
@@ -16,6 +16,16 @@ export declare function calculateExportImageSize({ mapW, mapH, ratio, resolution
16
16
  } | null;
17
17
  export declare function convertToPng(sourceElem: HTMLElement, options: any): Promise<any>;
18
18
  export declare function dataURItoBlob(dataURI: string): Blob;
19
+ /**
20
+ * Turn a user-entered export name into a safe basename.
21
+ * Empty input falls back to `fallback`. Known extensions are stripped so the
22
+ * caller can add the format-specific suffix.
23
+ */
24
+ export declare function getExportFileNameBase(name: string | undefined, fallback: string): string;
25
+ /**
26
+ * Resolve a download filename with the given extension.
27
+ */
28
+ export declare function getExportFileName(name: string | undefined, fallback: string, extension: string): string;
19
29
  export declare function downloadFile(fileBlob: Blob, fileName: string): void;
20
30
  /**
21
31
  * Whether color is rgb
@@ -23,9 +33,17 @@ export declare function downloadFile(fileBlob: Blob, fileName: string): void;
23
33
  */
24
34
  export declare function exportImage(uiStateExportImage: ExportImage, filename?: string): void;
25
35
  export declare function exportToJsonString(data: any): any;
26
- export declare function getMapJSON(state: any, options?: {
36
+ /**
37
+ * Remove access tokens stored on layer datasets. The tileset URL and the rest
38
+ * of the metadata stay so the map can be reopened and a new key entered.
39
+ */
40
+ export declare function omitLayerApiKeys<T>(mapToSave: T): T;
41
+ type MapJsonOptions = {
27
42
  hasData?: boolean;
28
- }): any;
43
+ /** When false, access tokens stored on layer datasets are removed. */
44
+ includeLayerApiKeys?: boolean;
45
+ };
46
+ export declare function getMapJSON(state: any, options?: MapJsonOptions): any;
29
47
  export declare function exportJson(state: any, options?: any): void;
30
48
  export declare function exportHtml(state: any, options: any): void;
31
49
  export declare function exportMap(state: any, options?: {
@@ -51,6 +51,7 @@ export type ExtractResult = ExtractedTable | ExtractedGeojson;
51
51
  */
52
52
  export declare function isExtractableDataset(dataset?: ExtractableDataset | null): boolean;
53
53
  export declare function isVectorTileExtractLayer(layer?: ExtractableLayer | null): boolean;
54
+ export declare function isRasterTileExtractLayer(layer?: ExtractableLayer | null): boolean;
54
55
  export declare function isExtractableLayer(layer: ExtractableLayer, datasets: Record<string, ExtractableDataset | undefined>): boolean;
55
56
  /**
56
57
  * Copy GeoJSON features from currently loaded vector tiles that intersect a drawing.
@@ -60,11 +61,16 @@ export declare function extractVectorTileFeaturesInsideFeature({ layer, feature
60
61
  layer: ExtractableLayer;
61
62
  feature: Feature | null;
62
63
  }): ExtractedGeojson | null;
64
+ export declare function extractRasterInsideFeature({ layer, feature }: {
65
+ layer: ExtractableLayer;
66
+ feature: Feature | null;
67
+ }): ExtractedGeojson | null;
63
68
  /**
64
69
  * Copy in-memory rows whose geometry falls inside a drawn polygon.
65
70
  * Existing table filters (range/select/time), including GPU-backed ones via
66
71
  * `filteredIdxCPU`, are applied; the polygon clip is extra.
67
72
  * Vector tiles use currently loaded viewport tiles instead of dataset.rows.
73
+ * Raster tiles report whether any loaded pixels fall inside the drawing.
68
74
  */
69
75
  export declare function extractRowsInsideFeature({ layer, dataset, feature }: {
70
76
  layer: ExtractableLayer;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { default as domtoimage } from './dom-to-image';
6
6
  export { getFrequency, getMode, aggregate } from './aggregation';
7
7
  export { ColumnStatsType, NUMERIC_BIN_COUNT, collectColumnValues, computeColumnStats, getColumnStatistics } from './column-statistics';
8
8
  export type { ColumnStats, NumericColumnStats, CategoricalColumnStats, TimeColumnStats, Quantile } from './column-statistics';
9
- export { adjustValueToAnimationWindow, getBinThresholds, histogramFromThreshold, histogramFromValues, histogramFromDomain, histogramFromOrdinal, histogramFromTimeIntervals, mergePolygonLayerIndexes, runGpuFilterForPlot, updateTimeFilterPlotType } from './plot';
9
+ export { adjustValueToAnimationWindow, getBinThresholds, intervalBinFromMarks, histogramFromThreshold, histogramFromValues, histogramFromDomain, histogramFromOrdinal, histogramFromTimeIntervals, mergePolygonLayerIndexes, runGpuFilterForPlot, updateTimeFilterPlotType, getLineChart, mergePlotGroupBy, lineChartSeriesLegend, defaultPlotGroupColorRange, PLOT_GROUP_OTHERS_NAME, PLOT_NUM_GROUPS_ALL, PLOT_NUM_GROUPS_OPTIONS, DEFAULT_PLOT_NUM_GROUPS, MAX_PLOT_NUM_GROUPS } from './plot';
10
10
  export * from './data-utils';
11
11
  export type { FieldFormatter } from './data-utils';
12
12
  export * from './strings';
@@ -14,7 +14,7 @@ export { SAMPLE_TIMELINE, TIMELINE_MODES, TIME_INTERVALS_ORDERED, LayerToFilterT
14
14
  export { maybeHexToGeo, getPositionFromHexValue } from './position-utils';
15
15
  export { datasetColorMaker, findDefaultColorField, getFieldFormatLabels, getFormatLabels, validateInputData } from './dataset-utils';
16
16
  export { exportMapToHTML } from './export-map-html';
17
- export { calculateExportImageSize, convertToPng, dataURItoBlob, downloadFile, exportHtml, exportImage, exportJson, exportMap, exportToJsonString, default as exporters, getMapJSON, getScaleFromImageSize, isMSEdge } from './export-utils';
17
+ export { calculateExportImageSize, convertToPng, dataURItoBlob, downloadFile, exportHtml, exportImage, exportJson, exportMap, exportToJsonString, default as exporters, getExportFileName, getExportFileNameBase, getMapJSON, getScaleFromImageSize, isMSEdge, omitLayerApiKeys } from './export-utils';
18
18
  export { getFormatValue, getDefaultTimeFormat } from './format';
19
19
  export { getLayerBlendingParameters, patchDeckRendererForPostProcessing } from './gl-utils';
20
20
  export { flattenMessages, mergeMessages } from './locale-utils';
@@ -38,12 +38,13 @@ export * from './filter-utils';
38
38
  export type { FilterChanged, FilterResult, dataValueAccessor } from './filter-utils';
39
39
  export * from './editor-feature-utils';
40
40
  export type { EditorFeatureCollection } from './editor-feature-utils';
41
- export { extractRowsInsideFeature, extractVectorTileFeaturesInsideFeature, isExtractableDataset, isExtractableLayer, isVectorTileExtractLayer } from './extract-dataset-utils';
41
+ export { extractRowsInsideFeature, extractVectorTileFeaturesInsideFeature, extractRasterInsideFeature, isExtractableDataset, isExtractableLayer, isRasterTileExtractLayer, isVectorTileExtractLayer } from './extract-dataset-utils';
42
42
  export type { ExtractableDataset, ExtractableLayer, ExtractedGeojson, ExtractedTable, ExtractResult } from './extract-dataset-utils';
43
43
  export { colorMapToColorBreaks, colorBreaksToColorMap, getLayerColorScale, getLegendOfScale, getJenksDomain, getLinearDomain, getLogDomain, getOrdinalDomain, getQuantileDomain, getScaleFunction, getVisualChannelScaleByZoom, initializeLayerColorMap, isNumericColorBreaks, isDomainStops, isDomainQuantile, getDomainStepsbyZoom, getThresholdsFromQuantiles, getQuantLabelFormat, getHistogramDomain, getQuantLegends, getCategoricalColorMap, getCategoricalColorScale, initCustomPaletteByCustomScale, colorMapToCategoricalColorBreaks, resetCategoricalColorMapByIndex, selectRestCategoricalColorMapByIndex, removeCategoricalValueFromColorMap, addCategoricalValuesToColorMap } from './data-scale-utils';
44
44
  export type { ColorBreak, ColorBreakOrdinal, DomainQuantiles, DomainStops } from './data-scale-utils';
45
45
  export { DataRow } from './data-row';
46
46
  export { getApplicationConfig, initApplicationConfig } from './application-config';
47
+ export { getConfiguredThemes, shouldShowThemeSwitcher, getDefaultUiTheme, getNextUiTheme } from './theme-utils';
47
48
  export type { KeplerApplicationConfig, KeplerAcceptedFileFormat, BaseMapLibraryConfig, MapLibInstance, GetMapRef, SvgIcon, ReduxLogLevel } from './application-config';
48
49
  export type { DatabaseAdapter, DatabaseConnection } from './application-config-types';
49
50
  export { isAppleDevice } from './browser-utils';
package/dist/plot.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bin, TimeBins, Millisecond, TimeRangeFilter, RangeFilter, PlotType, Filter, LineChart, Field, ValueOf } from '@kepler.gl/types';
1
+ import { Bin, TimeBins, Millisecond, TimeRangeFilter, RangeFilter, PlotType, PlotGroupBy, Filter, LineChart, Field, ValueOf, ColorRange } from '@kepler.gl/types';
2
2
  import { AggregationTypes } from '@kepler.gl/constants';
3
3
  import { DataContainerInterface } from '.';
4
4
  import { KeplerTableModel } from './types';
@@ -57,11 +57,12 @@ export declare function runGpuFilterForPlot<K extends KeplerTableModel<K, L>, L>
57
57
  export declare function getFilterDataFunc(filterRange: any, getFilterValue: any, dataContainer: DataContainerInterface, skips: any): (index: any) => any;
58
58
  export declare function validBin(b: any): boolean;
59
59
  /**
60
- * Use in slider, given a number and an array of numbers, return the nears number from the array.
61
- * Takes a value, timesteps and return the actual step.
62
- * @param value
63
- * @param marks
60
+ * Turn a histogram brush or slider position into one bin.
61
+ * Interval playback steps by bin, and the filter comparison is inclusive, so
62
+ * the window is [binStart, nextBinStart - 1]. The last threshold is the end
63
+ * of the domain, not the start of another bin.
64
64
  */
65
+ export declare function intervalBinFromMarks(marks: number[], value: number): [number, number];
65
66
  export declare function snapToMarks(value: number, marks: number[]): number;
66
67
  export declare function normalizeValue(val: any, minValue: any, step: any, marks: any): number;
67
68
  export declare function isPercentField(field: any): any;
@@ -69,6 +70,23 @@ export declare function updateAggregationByField(field: Field, aggregation: Valu
69
70
  export declare const getValueAggrFunc: (field: Field | string | null, aggregation: string, dataset: KeplerTableModel<any, any>) => ((bin: Bin) => number);
70
71
  export declare const getAggregationOptiosnBasedOnField: (field: any) => import("@kepler.gl/constants").TimeAggregation[];
71
72
  export declare function getPctChange(y: unknown, y0: unknown): number | null;
73
+ export declare const PLOT_GROUP_OTHERS_NAME = "Others";
74
+ export declare const PLOT_NUM_GROUPS_ALL: "ALL";
75
+ export declare const DEFAULT_PLOT_NUM_GROUPS = 10;
76
+ /** Qualitative palettes stop at 20. All uses this cap instead of one series per value. */
77
+ export declare const MAX_PLOT_NUM_GROUPS = 20;
78
+ export declare const PLOT_NUM_GROUPS_OPTIONS: number[];
79
+ export declare function plotGroupColorSteps(numGroups: number | typeof PLOT_NUM_GROUPS_ALL | undefined): number;
80
+ export declare function defaultPlotGroupColorRange(numGroups?: number | typeof PLOT_NUM_GROUPS_ALL): ColorRange;
81
+ /**
82
+ * Merge a partial timeline group-by onto the previous one.
83
+ * `null` clears grouping. Missing fields keep the previous value, then defaults.
84
+ */
85
+ export declare function mergePlotGroupBy(prev: PlotGroupBy | null | undefined, next: Partial<PlotGroupBy> | null | undefined): PlotGroupBy | null;
86
+ export declare function lineChartSeriesLegend(lineChart?: LineChart | null): {
87
+ name: string;
88
+ color: string;
89
+ }[];
72
90
  /**
73
91
  *
74
92
  * @param datasets
@@ -0,0 +1,8 @@
1
+ /** Configured UI theme names, in cycle order. Empty when unset. */
2
+ export declare function getConfiguredThemes(): string[];
3
+ /** True when the map control should cycle themes (two or more names). */
4
+ export declare function shouldShowThemeSwitcher(): boolean;
5
+ /** First configured theme, or dark when none are set. */
6
+ export declare function getDefaultUiTheme(): string;
7
+ /** Next theme in the configured cycle. */
8
+ export declare function getNextUiTheme(current?: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kepler.gl/utils",
3
3
  "author": "Shan He <shan@uber.com>",
4
- "version": "3.3.0-alpha.14",
4
+ "version": "3.3.0-alpha.16",
5
5
  "description": "kepler.gl constants used by kepler.gl components, actions and reducers",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
@@ -29,9 +29,9 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "@deck.gl/core": "^9.3.1",
32
- "@kepler.gl/common-utils": "3.3.0-alpha.14",
33
- "@kepler.gl/constants": "3.3.0-alpha.14",
34
- "@kepler.gl/types": "3.3.0-alpha.14",
32
+ "@kepler.gl/common-utils": "3.3.0-alpha.16",
33
+ "@kepler.gl/constants": "3.3.0-alpha.16",
34
+ "@kepler.gl/types": "3.3.0-alpha.16",
35
35
  "@loaders.gl/gis": "^4.4.1",
36
36
  "@luma.gl/constants": "^9.3.2",
37
37
  "@luma.gl/core": "^9.3.2",