@sqlrooms/deck 0.29.0-rc.10
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/LICENSE.md +10 -0
- package/README.md +654 -0
- package/dist/BlockMapSettings.d.ts +3 -0
- package/dist/BlockMapSettings.d.ts.map +1 -0
- package/dist/BlockMapSettings.js +57 -0
- package/dist/BlockMapSettings.js.map +1 -0
- package/dist/DashboardMapSettings.d.ts +7 -0
- package/dist/DashboardMapSettings.d.ts.map +1 -0
- package/dist/DashboardMapSettings.js +52 -0
- package/dist/DashboardMapSettings.js.map +1 -0
- package/dist/DeckJsonMap.d.ts +4 -0
- package/dist/DeckJsonMap.d.ts.map +1 -0
- package/dist/DeckJsonMap.js +370 -0
- package/dist/DeckJsonMap.js.map +1 -0
- package/dist/DeckJsonMapSpec.d.ts +7617 -0
- package/dist/DeckJsonMapSpec.d.ts.map +1 -0
- package/dist/DeckJsonMapSpec.js +82 -0
- package/dist/DeckJsonMapSpec.js.map +1 -0
- package/dist/DeckMapDefaultStylesProvider.d.ts +28 -0
- package/dist/DeckMapDefaultStylesProvider.d.ts.map +1 -0
- package/dist/DeckMapDefaultStylesProvider.js +23 -0
- package/dist/DeckMapDefaultStylesProvider.js.map +1 -0
- package/dist/DeckMapSurface.d.ts +39 -0
- package/dist/DeckMapSurface.d.ts.map +1 -0
- package/dist/DeckMapSurface.js +137 -0
- package/dist/DeckMapSurface.js.map +1 -0
- package/dist/DeckMapsSlice.d.ts +99 -0
- package/dist/DeckMapsSlice.d.ts.map +1 -0
- package/dist/DeckMapsSlice.js +89 -0
- package/dist/DeckMapsSlice.js.map +1 -0
- package/dist/MapSettings.d.ts +16 -0
- package/dist/MapSettings.d.ts.map +1 -0
- package/dist/MapSettings.js +292 -0
- package/dist/MapSettings.js.map +1 -0
- package/dist/MapSettingsControls.d.ts +40 -0
- package/dist/MapSettingsControls.d.ts.map +1 -0
- package/dist/MapSettingsControls.js +54 -0
- package/dist/MapSettingsControls.js.map +1 -0
- package/dist/ai.d.ts +261 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +392 -0
- package/dist/ai.js.map +1 -0
- package/dist/block.d.ts +21 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/block.js +105 -0
- package/dist/block.js.map +1 -0
- package/dist/blockDocumentRegistration.d.ts +45 -0
- package/dist/blockDocumentRegistration.d.ts.map +1 -0
- package/dist/blockDocumentRegistration.js +68 -0
- package/dist/blockDocumentRegistration.js.map +1 -0
- package/dist/createDeckJsonSpecFromDatasets.d.ts +11 -0
- package/dist/createDeckJsonSpecFromDatasets.d.ts.map +1 -0
- package/dist/createDeckJsonSpecFromDatasets.js +85 -0
- package/dist/createDeckJsonSpecFromDatasets.js.map +1 -0
- package/dist/createOrUpdateDeckMapResource.d.ts +81 -0
- package/dist/createOrUpdateDeckMapResource.d.ts.map +1 -0
- package/dist/createOrUpdateDeckMapResource.js +82 -0
- package/dist/createOrUpdateDeckMapResource.js.map +1 -0
- package/dist/dashboard.d.ts +6 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +337 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/dashboardConfig.d.ts +25 -0
- package/dist/dashboardConfig.d.ts.map +1 -0
- package/dist/dashboardConfig.js +82 -0
- package/dist/dashboardConfig.js.map +1 -0
- package/dist/dashboardIntegration.d.ts +3 -0
- package/dist/dashboardIntegration.d.ts.map +1 -0
- package/dist/dashboardIntegration.js +16 -0
- package/dist/dashboardIntegration.js.map +1 -0
- package/dist/datasetSourceUtils.d.ts +16 -0
- package/dist/datasetSourceUtils.d.ts.map +1 -0
- package/dist/datasetSourceUtils.js +25 -0
- package/dist/datasetSourceUtils.js.map +1 -0
- package/dist/datasets/PreparedDatasetStore.d.ts +120 -0
- package/dist/datasets/PreparedDatasetStore.d.ts.map +1 -0
- package/dist/datasets/PreparedDatasetStore.js +268 -0
- package/dist/datasets/PreparedDatasetStore.js.map +1 -0
- package/dist/datasets/helpers.d.ts +57 -0
- package/dist/datasets/helpers.d.ts.map +1 -0
- package/dist/datasets/helpers.js +155 -0
- package/dist/datasets/helpers.js.map +1 -0
- package/dist/datasets/normalizeDatasets.d.ts +11 -0
- package/dist/datasets/normalizeDatasets.d.ts.map +1 -0
- package/dist/datasets/normalizeDatasets.js +50 -0
- package/dist/datasets/normalizeDatasets.js.map +1 -0
- package/dist/datasets/tableAdapter.d.ts +11 -0
- package/dist/datasets/tableAdapter.d.ts.map +1 -0
- package/dist/datasets/tableAdapter.js +11 -0
- package/dist/datasets/tableAdapter.js.map +1 -0
- package/dist/datasets/tableDatasetSql.d.ts +16 -0
- package/dist/datasets/tableDatasetSql.d.ts.map +1 -0
- package/dist/datasets/tableDatasetSql.js +49 -0
- package/dist/datasets/tableDatasetSql.js.map +1 -0
- package/dist/datasets/types.d.ts +40 -0
- package/dist/datasets/types.d.ts.map +1 -0
- package/dist/datasets/types.js +2 -0
- package/dist/datasets/types.js.map +1 -0
- package/dist/datasets/usePreparedDatasetStates.d.ts +16 -0
- package/dist/datasets/usePreparedDatasetStates.d.ts.map +1 -0
- package/dist/datasets/usePreparedDatasetStates.js +59 -0
- package/dist/datasets/usePreparedDatasetStates.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/json/aggregateWaypoints.d.ts +14 -0
- package/dist/json/aggregateWaypoints.d.ts.map +1 -0
- package/dist/json/aggregateWaypoints.js +190 -0
- package/dist/json/aggregateWaypoints.js.map +1 -0
- package/dist/json/colorScaleFunction.d.ts +27 -0
- package/dist/json/colorScaleFunction.d.ts.map +1 -0
- package/dist/json/colorScaleFunction.js +46 -0
- package/dist/json/colorScaleFunction.js.map +1 -0
- package/dist/json/compileColorScale.d.ts +12 -0
- package/dist/json/compileColorScale.d.ts.map +1 -0
- package/dist/json/compileColorScale.js +125 -0
- package/dist/json/compileColorScale.js.map +1 -0
- package/dist/json/compileGeoArrowAccessor.d.ts +18 -0
- package/dist/json/compileGeoArrowAccessor.d.ts.map +1 -0
- package/dist/json/compileGeoArrowAccessor.js +129 -0
- package/dist/json/compileGeoArrowAccessor.js.map +1 -0
- package/dist/json/createDeckJsonConfiguration.d.ts +9 -0
- package/dist/json/createDeckJsonConfiguration.d.ts.map +1 -0
- package/dist/json/createDeckJsonConfiguration.js +315 -0
- package/dist/json/createDeckJsonConfiguration.js.map +1 -0
- package/dist/json/defaultClasses.d.ts +12 -0
- package/dist/json/defaultClasses.d.ts.map +1 -0
- package/dist/json/defaultClasses.js +35 -0
- package/dist/json/defaultClasses.js.map +1 -0
- package/dist/json/extractColorScaleLegends.d.ts +8 -0
- package/dist/json/extractColorScaleLegends.d.ts.map +1 -0
- package/dist/json/extractColorScaleLegends.js +86 -0
- package/dist/json/extractColorScaleLegends.js.map +1 -0
- package/dist/json/heatmapDefaults.d.ts +8 -0
- package/dist/json/heatmapDefaults.d.ts.map +1 -0
- package/dist/json/heatmapDefaults.js +14 -0
- package/dist/json/heatmapDefaults.js.map +1 -0
- package/dist/json/layerCompatibility.d.ts +21 -0
- package/dist/json/layerCompatibility.d.ts.map +1 -0
- package/dist/json/layerCompatibility.js +168 -0
- package/dist/json/layerCompatibility.js.map +1 -0
- package/dist/json/layerConfig.d.ts +14 -0
- package/dist/json/layerConfig.d.ts.map +1 -0
- package/dist/json/layerConfig.js +54 -0
- package/dist/json/layerConfig.js.map +1 -0
- package/dist/json/layers/DeckColumnLayer.d.ts +10 -0
- package/dist/json/layers/DeckColumnLayer.d.ts.map +1 -0
- package/dist/json/layers/DeckColumnLayer.js +26 -0
- package/dist/json/layers/DeckColumnLayer.js.map +1 -0
- package/dist/json/layers/DeckH3HexagonLayer.d.ts +37 -0
- package/dist/json/layers/DeckH3HexagonLayer.d.ts.map +1 -0
- package/dist/json/layers/DeckH3HexagonLayer.js +118 -0
- package/dist/json/layers/DeckH3HexagonLayer.js.map +1 -0
- package/dist/json/layers/DeckTripsLayer.d.ts +46 -0
- package/dist/json/layers/DeckTripsLayer.d.ts.map +1 -0
- package/dist/json/layers/DeckTripsLayer.js +170 -0
- package/dist/json/layers/DeckTripsLayer.js.map +1 -0
- package/dist/json/layers/createTableToRecordBatchAdapter.d.ts +20 -0
- package/dist/json/layers/createTableToRecordBatchAdapter.d.ts.map +1 -0
- package/dist/json/layers/createTableToRecordBatchAdapter.js +81 -0
- package/dist/json/layers/createTableToRecordBatchAdapter.js.map +1 -0
- package/dist/json/layers/index.d.ts +5 -0
- package/dist/json/layers/index.d.ts.map +1 -0
- package/dist/json/layers/index.js +5 -0
- package/dist/json/layers/index.js.map +1 -0
- package/dist/json/rewriteGeoArrowAccessors.d.ts +7 -0
- package/dist/json/rewriteGeoArrowAccessors.d.ts.map +1 -0
- package/dist/json/rewriteGeoArrowAccessors.js +55 -0
- package/dist/json/rewriteGeoArrowAccessors.js.map +1 -0
- package/dist/mapAiConfig.d.ts +111 -0
- package/dist/mapAiConfig.d.ts.map +1 -0
- package/dist/mapAiConfig.js +69 -0
- package/dist/mapAiConfig.js.map +1 -0
- package/dist/mapConfig.d.ts +73 -0
- package/dist/mapConfig.d.ts.map +1 -0
- package/dist/mapConfig.js +47 -0
- package/dist/mapConfig.js.map +1 -0
- package/dist/mapConfigUtils.d.ts +111 -0
- package/dist/mapConfigUtils.d.ts.map +1 -0
- package/dist/mapConfigUtils.js +502 -0
- package/dist/mapConfigUtils.js.map +1 -0
- package/dist/mapDataPolicy.d.ts +9 -0
- package/dist/mapDataPolicy.d.ts.map +1 -0
- package/dist/mapDataPolicy.js +25 -0
- package/dist/mapDataPolicy.js.map +1 -0
- package/dist/mapFit.d.ts +62 -0
- package/dist/mapFit.d.ts.map +1 -0
- package/dist/mapFit.js +325 -0
- package/dist/mapFit.js.map +1 -0
- package/dist/mapLayerConfigUtils.d.ts +54 -0
- package/dist/mapLayerConfigUtils.d.ts.map +1 -0
- package/dist/mapLayerConfigUtils.js +296 -0
- package/dist/mapLayerConfigUtils.js.map +1 -0
- package/dist/mapResourceAuthoring.d.ts +40 -0
- package/dist/mapResourceAuthoring.d.ts.map +1 -0
- package/dist/mapResourceAuthoring.js +266 -0
- package/dist/mapResourceAuthoring.js.map +1 -0
- package/dist/mosaic.d.ts +9 -0
- package/dist/mosaic.d.ts.map +1 -0
- package/dist/mosaic.js +8 -0
- package/dist/mosaic.js.map +1 -0
- package/dist/prepare/detectGeometryColumn.d.ts +19 -0
- package/dist/prepare/detectGeometryColumn.d.ts.map +1 -0
- package/dist/prepare/detectGeometryColumn.js +126 -0
- package/dist/prepare/detectGeometryColumn.js.map +1 -0
- package/dist/prepare/geoarrow.d.ts +18 -0
- package/dist/prepare/geoarrow.d.ts.map +1 -0
- package/dist/prepare/geoarrow.js +114 -0
- package/dist/prepare/geoarrow.js.map +1 -0
- package/dist/prepare/geometryDecoder.d.ts +8 -0
- package/dist/prepare/geometryDecoder.d.ts.map +1 -0
- package/dist/prepare/geometryDecoder.js +2 -0
- package/dist/prepare/geometryDecoder.js.map +1 -0
- package/dist/prepare/prepareDeckDataset.d.ts +57 -0
- package/dist/prepare/prepareDeckDataset.d.ts.map +1 -0
- package/dist/prepare/prepareDeckDataset.js +112 -0
- package/dist/prepare/prepareDeckDataset.js.map +1 -0
- package/dist/prepare/toGeoJsonBinary.d.ts +9 -0
- package/dist/prepare/toGeoJsonBinary.d.ts.map +1 -0
- package/dist/prepare/toGeoJsonBinary.js +26 -0
- package/dist/prepare/toGeoJsonBinary.js.map +1 -0
- package/dist/prepare/types.d.ts +25 -0
- package/dist/prepare/types.d.ts.map +1 -0
- package/dist/prepare/types.js +2 -0
- package/dist/prepare/types.js.map +1 -0
- package/dist/prepare/wkbDecoder.d.ts +3 -0
- package/dist/prepare/wkbDecoder.d.ts.map +1 -0
- package/dist/prepare/wkbDecoder.js +419 -0
- package/dist/prepare/wkbDecoder.js.map +1 -0
- package/dist/prepare/wkbParser.d.ts +24 -0
- package/dist/prepare/wkbParser.d.ts.map +1 -0
- package/dist/prepare/wkbParser.js +139 -0
- package/dist/prepare/wkbParser.js.map +1 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/useDeckMapDatasetSchema.d.ts +33 -0
- package/dist/useDeckMapDatasetSchema.d.ts.map +1 -0
- package/dist/useDeckMapDatasetSchema.js +138 -0
- package/dist/useDeckMapDatasetSchema.js.map +1 -0
- package/dist/useDeckMapDatasets.d.ts +17 -0
- package/dist/useDeckMapDatasets.d.ts.map +1 -0
- package/dist/useDeckMapDatasets.js +69 -0
- package/dist/useDeckMapDatasets.js.map +1 -0
- package/dist/useDeckMapFitToBounds.d.ts +31 -0
- package/dist/useDeckMapFitToBounds.d.ts.map +1 -0
- package/dist/useDeckMapFitToBounds.js +58 -0
- package/dist/useDeckMapFitToBounds.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { isColorScaleFunction } from './json/layerConfig';
|
|
2
|
+
export const DECK_MAP_LAYER_TYPE_OPTIONS = [
|
|
3
|
+
{ value: 'GeoArrowScatterplotLayer', label: 'Point' },
|
|
4
|
+
{ value: 'GeoArrowHeatmapLayer', label: 'Heatmap' },
|
|
5
|
+
{ value: 'GeoArrowColumnLayer', label: 'Column' },
|
|
6
|
+
{ value: 'GeoArrowPathLayer', label: 'Path' },
|
|
7
|
+
{ value: 'GeoArrowPolygonLayer', label: 'Polygon' },
|
|
8
|
+
{ value: 'GeoArrowSolidPolygonLayer', label: 'Solid polygon' },
|
|
9
|
+
{ value: 'GeoArrowArcLayer', label: 'Arc' },
|
|
10
|
+
{ value: 'GeoArrowTripsLayer', label: 'Trips' },
|
|
11
|
+
{ value: 'GeoArrowH3HexagonLayer', label: 'H3 hexagon' },
|
|
12
|
+
{ value: 'GeoJsonLayer', label: 'GeoJSON' },
|
|
13
|
+
];
|
|
14
|
+
export const DECK_MAP_COLOR_ACCESSOR_OPTIONS = [
|
|
15
|
+
{ value: 'getFillColor', label: 'Fill color' },
|
|
16
|
+
{ value: 'getLineColor', label: 'Line color' },
|
|
17
|
+
{ value: 'getColor', label: 'Color' },
|
|
18
|
+
{ value: 'getSourceColor', label: 'Source color' },
|
|
19
|
+
{ value: 'getTargetColor', label: 'Target color' },
|
|
20
|
+
];
|
|
21
|
+
export const DECK_MAP_COLOR_SCALE_TYPE_OPTIONS = [
|
|
22
|
+
{ value: 'sequential', label: 'Sequential', defaultScheme: 'Viridis' },
|
|
23
|
+
{ value: 'diverging', label: 'Diverging', defaultScheme: 'RdBu' },
|
|
24
|
+
{ value: 'quantize', label: 'Quantize', defaultScheme: 'YlOrRd' },
|
|
25
|
+
{ value: 'quantile', label: 'Quantile', defaultScheme: 'YlOrRd' },
|
|
26
|
+
{ value: 'categorical', label: 'Categorical', defaultScheme: 'Tableau10' },
|
|
27
|
+
];
|
|
28
|
+
const GEOMETRY_COLUMN_LAYER_TYPES = new Set([
|
|
29
|
+
'geoarrowpolygonlayer',
|
|
30
|
+
'geoarrowsolidpolygonlayer',
|
|
31
|
+
'geoarrowpathlayer',
|
|
32
|
+
'geoarrowtripslayer',
|
|
33
|
+
'geojsonlayer',
|
|
34
|
+
'polygonlayer',
|
|
35
|
+
'solidpolygonlayer',
|
|
36
|
+
'geojson',
|
|
37
|
+
'polygon',
|
|
38
|
+
'solid polygon',
|
|
39
|
+
]);
|
|
40
|
+
const H3_LAYER_TYPES = new Set(['geoarrowh3hexagonlayer', 'h3hexagonlayer']);
|
|
41
|
+
const ARC_LAYER_TYPES = new Set(['geoarrowarclayer', 'arclayer']);
|
|
42
|
+
const TRIPS_LAYER_TYPES = new Set([
|
|
43
|
+
'geoarrowtripslayer',
|
|
44
|
+
'decktripslayer',
|
|
45
|
+
'tripslayer',
|
|
46
|
+
]);
|
|
47
|
+
const RADIUS_LAYER_TYPES = new Set([
|
|
48
|
+
'geoarrowscatterplotlayer',
|
|
49
|
+
'scatterplotlayer',
|
|
50
|
+
]);
|
|
51
|
+
const COLUMN_RADIUS_LAYER_TYPES = new Set([
|
|
52
|
+
'geoarrowcolumnlayer',
|
|
53
|
+
'columnlayer',
|
|
54
|
+
]);
|
|
55
|
+
const EXTRUDABLE_LAYER_TYPES = new Set([
|
|
56
|
+
'geoarrowh3hexagonlayer',
|
|
57
|
+
'h3hexagonlayer',
|
|
58
|
+
'geoarrowcolumnlayer',
|
|
59
|
+
'columnlayer',
|
|
60
|
+
'geoarrowpolygonlayer',
|
|
61
|
+
'polygonlayer',
|
|
62
|
+
'geoarrowsolidpolygonlayer',
|
|
63
|
+
'solidpolygonlayer',
|
|
64
|
+
]);
|
|
65
|
+
function isRecord(value) {
|
|
66
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
67
|
+
}
|
|
68
|
+
function getObjectSpec(config) {
|
|
69
|
+
return isRecord(config.spec) ? config.spec : undefined;
|
|
70
|
+
}
|
|
71
|
+
export function getDeckMapLayerRecords(config) {
|
|
72
|
+
const layers = getObjectSpec(config)?.layers;
|
|
73
|
+
return Array.isArray(layers) ? layers.filter(isRecord) : [];
|
|
74
|
+
}
|
|
75
|
+
export function getDeckMapLayerDatasetId(layer) {
|
|
76
|
+
const binding = layer?._sqlroomsBinding;
|
|
77
|
+
if (!isRecord(binding))
|
|
78
|
+
return undefined;
|
|
79
|
+
return typeof binding.dataset === 'string' ? binding.dataset : undefined;
|
|
80
|
+
}
|
|
81
|
+
export function usesGeometryColumnSetting(layerType) {
|
|
82
|
+
return (typeof layerType === 'string' &&
|
|
83
|
+
GEOMETRY_COLUMN_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
84
|
+
}
|
|
85
|
+
export function usesH3ColumnSetting(layerType) {
|
|
86
|
+
return (typeof layerType === 'string' && H3_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
87
|
+
}
|
|
88
|
+
export function usesArcColumnSetting(layerType) {
|
|
89
|
+
return (typeof layerType === 'string' &&
|
|
90
|
+
ARC_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
91
|
+
}
|
|
92
|
+
export function usesRadiusSetting(layerType) {
|
|
93
|
+
return (typeof layerType === 'string' &&
|
|
94
|
+
RADIUS_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
95
|
+
}
|
|
96
|
+
export function usesColumnRadiusSetting(layerType) {
|
|
97
|
+
return (typeof layerType === 'string' &&
|
|
98
|
+
COLUMN_RADIUS_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
99
|
+
}
|
|
100
|
+
export function usesTripsSettings(layerType) {
|
|
101
|
+
return (typeof layerType === 'string' &&
|
|
102
|
+
TRIPS_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
103
|
+
}
|
|
104
|
+
export function usesExtrusionSettings(layerType) {
|
|
105
|
+
return (typeof layerType === 'string' &&
|
|
106
|
+
EXTRUDABLE_LAYER_TYPES.has(layerType.toLowerCase()));
|
|
107
|
+
}
|
|
108
|
+
export function getDeckMapColorAccessorOptions(layerType) {
|
|
109
|
+
if (layerType === 'GeoArrowPathLayer' || layerType === 'GeoArrowTripsLayer') {
|
|
110
|
+
return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter((option) => option.value === 'getColor');
|
|
111
|
+
}
|
|
112
|
+
if (layerType === 'GeoArrowArcLayer') {
|
|
113
|
+
return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter((option) => option.value === 'getSourceColor' || option.value === 'getTargetColor');
|
|
114
|
+
}
|
|
115
|
+
if (layerType === 'GeoArrowHeatmapLayer') {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter((option) => option.value === 'getFillColor' || option.value === 'getLineColor');
|
|
119
|
+
}
|
|
120
|
+
export function updateDeckMapLayer(config, layerIndex, updater) {
|
|
121
|
+
const spec = getObjectSpec(config);
|
|
122
|
+
if (!spec || !Array.isArray(spec.layers)) {
|
|
123
|
+
return config;
|
|
124
|
+
}
|
|
125
|
+
const layer = spec.layers[layerIndex];
|
|
126
|
+
if (!isRecord(layer)) {
|
|
127
|
+
return config;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...config,
|
|
131
|
+
spec: {
|
|
132
|
+
...spec,
|
|
133
|
+
layers: spec.layers.map((candidate, index) => index === layerIndex ? updater({ ...layer }) : candidate),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export function setDeckMapLayerType(config, layerIndex, layerType) {
|
|
138
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => {
|
|
139
|
+
const nextLayer = {
|
|
140
|
+
...layer,
|
|
141
|
+
'@@type': layerType,
|
|
142
|
+
};
|
|
143
|
+
const lt = layerType.toLowerCase();
|
|
144
|
+
if (lt === 'geoarrowcolumnlayer' ||
|
|
145
|
+
lt === 'columnlayer' ||
|
|
146
|
+
lt === 'deckcolumnlayer') {
|
|
147
|
+
nextLayer.radius ??= 3;
|
|
148
|
+
nextLayer.elevationScale ??= 1;
|
|
149
|
+
}
|
|
150
|
+
return nextLayer;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export function setDeckMapLayerGeometryColumn(config, layerIndex, geometryColumn) {
|
|
154
|
+
const layer = getDeckMapLayerRecords(config)[layerIndex];
|
|
155
|
+
const datasetId = getDeckMapLayerDatasetId(layer);
|
|
156
|
+
if (!datasetId || !config.datasets?.[datasetId]) {
|
|
157
|
+
return config;
|
|
158
|
+
}
|
|
159
|
+
const updatedConfig = {
|
|
160
|
+
...config,
|
|
161
|
+
datasets: {
|
|
162
|
+
...config.datasets,
|
|
163
|
+
[datasetId]: {
|
|
164
|
+
...config.datasets[datasetId],
|
|
165
|
+
geometryColumn,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
fitToData: config.fitToData &&
|
|
169
|
+
config.fitToData.dataset === datasetId &&
|
|
170
|
+
'geometryColumn' in config.fitToData
|
|
171
|
+
? {
|
|
172
|
+
...config.fitToData,
|
|
173
|
+
geometryColumn,
|
|
174
|
+
}
|
|
175
|
+
: config.fitToData,
|
|
176
|
+
};
|
|
177
|
+
return updateDeckMapLayer(updatedConfig, layerIndex, (l) => ({
|
|
178
|
+
...l,
|
|
179
|
+
_sqlroomsBinding: {
|
|
180
|
+
...l._sqlroomsBinding,
|
|
181
|
+
geometryColumn,
|
|
182
|
+
},
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
export function setDeckMapLayerHexagonColumn(config, layerIndex, hexagonColumn) {
|
|
186
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => ({
|
|
187
|
+
...layer,
|
|
188
|
+
getHexagon: `@@=${hexagonColumn}`,
|
|
189
|
+
_sqlroomsBinding: {
|
|
190
|
+
...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),
|
|
191
|
+
hexagonColumn,
|
|
192
|
+
},
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
export function setDeckMapLayerArcColumns(config, layerIndex, columns) {
|
|
196
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => ({
|
|
197
|
+
...layer,
|
|
198
|
+
_sqlroomsBinding: {
|
|
199
|
+
...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),
|
|
200
|
+
...columns,
|
|
201
|
+
},
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
export function setDeckMapLayerTimestampColumn(config, layerIndex, timestampColumn) {
|
|
205
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => ({
|
|
206
|
+
...layer,
|
|
207
|
+
_sqlroomsBinding: {
|
|
208
|
+
...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),
|
|
209
|
+
timestampColumn,
|
|
210
|
+
},
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
export function getDeckMapLayerColorScale(layer, accessor) {
|
|
214
|
+
const value = layer?.[accessor];
|
|
215
|
+
return isColorScaleFunction(value)
|
|
216
|
+
? value
|
|
217
|
+
: undefined;
|
|
218
|
+
}
|
|
219
|
+
export function setDeckMapLayerColorScale(config, layerIndex, accessor, colorScale) {
|
|
220
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => ({
|
|
221
|
+
...layer,
|
|
222
|
+
[accessor]: colorScale,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
const DEFAULT_LAYER_FILL_COLOR = [
|
|
226
|
+
56, 189, 248, 180,
|
|
227
|
+
];
|
|
228
|
+
export function clearDeckMapLayerColorScale(config, layerIndex, accessor) {
|
|
229
|
+
return updateDeckMapLayer(config, layerIndex, (layer) => {
|
|
230
|
+
const nextLayer = { ...layer };
|
|
231
|
+
if (accessor === 'getFillColor') {
|
|
232
|
+
nextLayer[accessor] = [...DEFAULT_LAYER_FILL_COLOR];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
delete nextLayer[accessor];
|
|
236
|
+
}
|
|
237
|
+
return nextLayer;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
export function createDeckMapLayerColorScale(options) {
|
|
241
|
+
const type = options.type ?? 'sequential';
|
|
242
|
+
const scheme = options.scheme ??
|
|
243
|
+
DECK_MAP_COLOR_SCALE_TYPE_OPTIONS.find((option) => option.value === type)
|
|
244
|
+
?.defaultScheme ??
|
|
245
|
+
'Viridis';
|
|
246
|
+
const base = {
|
|
247
|
+
'@@function': 'colorScale',
|
|
248
|
+
field: options.field,
|
|
249
|
+
legend: { title: options.title ?? options.field },
|
|
250
|
+
};
|
|
251
|
+
if (type === 'categorical') {
|
|
252
|
+
return {
|
|
253
|
+
...base,
|
|
254
|
+
type,
|
|
255
|
+
scheme: scheme,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (type === 'diverging') {
|
|
259
|
+
return {
|
|
260
|
+
...base,
|
|
261
|
+
type,
|
|
262
|
+
scheme: scheme,
|
|
263
|
+
domain: 'auto',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (type === 'quantize') {
|
|
267
|
+
return {
|
|
268
|
+
...base,
|
|
269
|
+
type,
|
|
270
|
+
scheme: scheme,
|
|
271
|
+
domain: 'auto',
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (type === 'quantile') {
|
|
275
|
+
return {
|
|
276
|
+
...base,
|
|
277
|
+
type,
|
|
278
|
+
scheme: scheme,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (type === 'threshold') {
|
|
282
|
+
return {
|
|
283
|
+
...base,
|
|
284
|
+
type,
|
|
285
|
+
scheme: scheme,
|
|
286
|
+
thresholds: [],
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
...base,
|
|
291
|
+
type: 'sequential',
|
|
292
|
+
scheme: scheme,
|
|
293
|
+
domain: 'auto',
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=mapLayerConfigUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapLayerConfigUtils.js","sourceRoot":"","sources":["../src/mapLayerConfigUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AAexD,MAAM,CAAC,MAAM,2BAA2B,GAGnC;IACH,EAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,OAAO,EAAC;IACnD,EAAC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAC;IACjD,EAAC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,QAAQ,EAAC;IAC/C,EAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,EAAC;IAC3C,EAAC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAC;IACjD,EAAC,KAAK,EAAE,2BAA2B,EAAE,KAAK,EAAE,eAAe,EAAC;IAC5D,EAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAC;IACzC,EAAC,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,OAAO,EA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C1E,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,OAAO;YACL,GAAG,IAAI;YACP,IAAI;YACJ,MAAM,EAAE,MAGG;YACX,UAAU,EAAE,EAAE;SACf,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,MAAmE;QAC3E,MAAM,EAAE,MAAM;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type {ColorScaleConfig, ColorScaleScheme} from '@sqlrooms/color-scales';\nimport type {DeckMapConfig} from './mapConfig';\nimport type {DeckAutoLayerType} from './types';\nimport {isColorScaleFunction} from './json/layerConfig';\n\nexport type DeckMapLayerRecord = Record<string, unknown>;\n\nexport type DeckMapLayerColorScaleFunction = ColorScaleConfig & {\n '@@function': 'colorScale';\n};\n\nexport type DeckMapLayerColorAccessor =\n | 'getFillColor'\n | 'getLineColor'\n | 'getColor'\n | 'getSourceColor'\n | 'getTargetColor';\n\nexport const DECK_MAP_LAYER_TYPE_OPTIONS: ReadonlyArray<{\n value: DeckAutoLayerType | 'GeoArrowSolidPolygonLayer';\n label: string;\n}> = [\n {value: 'GeoArrowScatterplotLayer', label: 'Point'},\n {value: 'GeoArrowHeatmapLayer', label: 'Heatmap'},\n {value: 'GeoArrowColumnLayer', label: 'Column'},\n {value: 'GeoArrowPathLayer', label: 'Path'},\n {value: 'GeoArrowPolygonLayer', label: 'Polygon'},\n {value: 'GeoArrowSolidPolygonLayer', label: 'Solid polygon'},\n {value: 'GeoArrowArcLayer', label: 'Arc'},\n {value: 'GeoArrowTripsLayer', label: 'Trips'},\n {value: 'GeoArrowH3HexagonLayer', label: 'H3 hexagon'},\n {value: 'GeoJsonLayer', label: 'GeoJSON'},\n];\n\nexport const DECK_MAP_COLOR_ACCESSOR_OPTIONS: ReadonlyArray<{\n value: DeckMapLayerColorAccessor;\n label: string;\n}> = [\n {value: 'getFillColor', label: 'Fill color'},\n {value: 'getLineColor', label: 'Line color'},\n {value: 'getColor', label: 'Color'},\n {value: 'getSourceColor', label: 'Source color'},\n {value: 'getTargetColor', label: 'Target color'},\n];\n\nexport const DECK_MAP_COLOR_SCALE_TYPE_OPTIONS: ReadonlyArray<{\n value: ColorScaleConfig['type'];\n label: string;\n defaultScheme: ColorScaleScheme;\n}> = [\n {value: 'sequential', label: 'Sequential', defaultScheme: 'Viridis'},\n {value: 'diverging', label: 'Diverging', defaultScheme: 'RdBu'},\n {value: 'quantize', label: 'Quantize', defaultScheme: 'YlOrRd'},\n {value: 'quantile', label: 'Quantile', defaultScheme: 'YlOrRd'},\n {value: 'categorical', label: 'Categorical', defaultScheme: 'Tableau10'},\n];\n\nconst GEOMETRY_COLUMN_LAYER_TYPES = new Set([\n 'geoarrowpolygonlayer',\n 'geoarrowsolidpolygonlayer',\n 'geoarrowpathlayer',\n 'geoarrowtripslayer',\n 'geojsonlayer',\n 'polygonlayer',\n 'solidpolygonlayer',\n 'geojson',\n 'polygon',\n 'solid polygon',\n]);\n\nconst H3_LAYER_TYPES = new Set(['geoarrowh3hexagonlayer', 'h3hexagonlayer']);\n\nconst ARC_LAYER_TYPES = new Set(['geoarrowarclayer', 'arclayer']);\n\nconst TRIPS_LAYER_TYPES = new Set([\n 'geoarrowtripslayer',\n 'decktripslayer',\n 'tripslayer',\n]);\n\nconst RADIUS_LAYER_TYPES = new Set([\n 'geoarrowscatterplotlayer',\n 'scatterplotlayer',\n]);\n\nconst COLUMN_RADIUS_LAYER_TYPES = new Set([\n 'geoarrowcolumnlayer',\n 'columnlayer',\n]);\n\nconst EXTRUDABLE_LAYER_TYPES = new Set([\n 'geoarrowh3hexagonlayer',\n 'h3hexagonlayer',\n 'geoarrowcolumnlayer',\n 'columnlayer',\n 'geoarrowpolygonlayer',\n 'polygonlayer',\n 'geoarrowsolidpolygonlayer',\n 'solidpolygonlayer',\n]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === 'object' && !Array.isArray(value));\n}\n\nfunction getObjectSpec(\n config: DeckMapConfig,\n): Record<string, unknown> | undefined {\n return isRecord(config.spec) ? config.spec : undefined;\n}\n\nexport function getDeckMapLayerRecords(\n config: DeckMapConfig,\n): DeckMapLayerRecord[] {\n const layers = getObjectSpec(config)?.layers;\n return Array.isArray(layers) ? layers.filter(isRecord) : [];\n}\n\nexport function getDeckMapLayerDatasetId(\n layer: DeckMapLayerRecord | undefined,\n): string | undefined {\n const binding = layer?._sqlroomsBinding;\n if (!isRecord(binding)) return undefined;\n return typeof binding.dataset === 'string' ? binding.dataset : undefined;\n}\n\nexport function usesGeometryColumnSetting(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n GEOMETRY_COLUMN_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesH3ColumnSetting(layerType: unknown) {\n return (\n typeof layerType === 'string' && H3_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesArcColumnSetting(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n ARC_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesRadiusSetting(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n RADIUS_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesColumnRadiusSetting(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n COLUMN_RADIUS_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesTripsSettings(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n TRIPS_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function usesExtrusionSettings(layerType: unknown) {\n return (\n typeof layerType === 'string' &&\n EXTRUDABLE_LAYER_TYPES.has(layerType.toLowerCase())\n );\n}\n\nexport function getDeckMapColorAccessorOptions(\n layerType: unknown,\n): typeof DECK_MAP_COLOR_ACCESSOR_OPTIONS {\n if (layerType === 'GeoArrowPathLayer' || layerType === 'GeoArrowTripsLayer') {\n return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter(\n (option) => option.value === 'getColor',\n );\n }\n\n if (layerType === 'GeoArrowArcLayer') {\n return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter(\n (option) =>\n option.value === 'getSourceColor' || option.value === 'getTargetColor',\n );\n }\n\n if (layerType === 'GeoArrowHeatmapLayer') {\n return [];\n }\n\n return DECK_MAP_COLOR_ACCESSOR_OPTIONS.filter(\n (option) =>\n option.value === 'getFillColor' || option.value === 'getLineColor',\n );\n}\n\nexport function updateDeckMapLayer(\n config: DeckMapConfig,\n layerIndex: number,\n updater: (layer: DeckMapLayerRecord) => DeckMapLayerRecord,\n): DeckMapConfig {\n const spec = getObjectSpec(config);\n if (!spec || !Array.isArray(spec.layers)) {\n return config;\n }\n\n const layer = spec.layers[layerIndex];\n if (!isRecord(layer)) {\n return config;\n }\n\n return {\n ...config,\n spec: {\n ...spec,\n layers: spec.layers.map((candidate, index) =>\n index === layerIndex ? updater({...layer}) : candidate,\n ),\n },\n };\n}\n\nexport function setDeckMapLayerType(\n config: DeckMapConfig,\n layerIndex: number,\n layerType: string,\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => {\n const nextLayer: DeckMapLayerRecord = {\n ...layer,\n '@@type': layerType,\n };\n const lt = layerType.toLowerCase();\n if (\n lt === 'geoarrowcolumnlayer' ||\n lt === 'columnlayer' ||\n lt === 'deckcolumnlayer'\n ) {\n nextLayer.radius ??= 3;\n nextLayer.elevationScale ??= 1;\n }\n return nextLayer;\n });\n}\n\nexport function setDeckMapLayerGeometryColumn(\n config: DeckMapConfig,\n layerIndex: number,\n geometryColumn: string,\n): DeckMapConfig {\n const layer = getDeckMapLayerRecords(config)[layerIndex];\n const datasetId = getDeckMapLayerDatasetId(layer);\n if (!datasetId || !config.datasets?.[datasetId]) {\n return config;\n }\n\n const updatedConfig = {\n ...config,\n datasets: {\n ...config.datasets,\n [datasetId]: {\n ...config.datasets[datasetId],\n geometryColumn,\n },\n },\n fitToData:\n config.fitToData &&\n config.fitToData.dataset === datasetId &&\n 'geometryColumn' in config.fitToData\n ? {\n ...config.fitToData,\n geometryColumn,\n }\n : config.fitToData,\n };\n\n return updateDeckMapLayer(updatedConfig, layerIndex, (l) => ({\n ...l,\n _sqlroomsBinding: {\n ...(l._sqlroomsBinding as Record<string, unknown>),\n geometryColumn,\n },\n }));\n}\n\nexport function setDeckMapLayerHexagonColumn(\n config: DeckMapConfig,\n layerIndex: number,\n hexagonColumn: string,\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => ({\n ...layer,\n getHexagon: `@@=${hexagonColumn}`,\n _sqlroomsBinding: {\n ...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),\n hexagonColumn,\n },\n }));\n}\n\nexport function setDeckMapLayerArcColumns(\n config: DeckMapConfig,\n layerIndex: number,\n columns: {\n sourceGeometryColumn?: string;\n targetGeometryColumn?: string;\n sourceLatitudeColumn?: string;\n sourceLongitudeColumn?: string;\n targetLatitudeColumn?: string;\n targetLongitudeColumn?: string;\n },\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => ({\n ...layer,\n _sqlroomsBinding: {\n ...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),\n ...columns,\n },\n }));\n}\n\nexport function setDeckMapLayerTimestampColumn(\n config: DeckMapConfig,\n layerIndex: number,\n timestampColumn: string,\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => ({\n ...layer,\n _sqlroomsBinding: {\n ...(isRecord(layer._sqlroomsBinding) ? layer._sqlroomsBinding : {}),\n timestampColumn,\n },\n }));\n}\n\nexport function getDeckMapLayerColorScale(\n layer: DeckMapLayerRecord | undefined,\n accessor: DeckMapLayerColorAccessor,\n): DeckMapLayerColorScaleFunction | undefined {\n const value = layer?.[accessor];\n return isColorScaleFunction(value)\n ? (value as DeckMapLayerColorScaleFunction)\n : undefined;\n}\n\nexport function setDeckMapLayerColorScale(\n config: DeckMapConfig,\n layerIndex: number,\n accessor: DeckMapLayerColorAccessor,\n colorScale: DeckMapLayerColorScaleFunction,\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => ({\n ...layer,\n [accessor]: colorScale,\n }));\n}\n\nconst DEFAULT_LAYER_FILL_COLOR: [number, number, number, number] = [\n 56, 189, 248, 180,\n];\n\nexport function clearDeckMapLayerColorScale(\n config: DeckMapConfig,\n layerIndex: number,\n accessor: DeckMapLayerColorAccessor,\n): DeckMapConfig {\n return updateDeckMapLayer(config, layerIndex, (layer) => {\n const nextLayer = {...layer};\n if (accessor === 'getFillColor') {\n nextLayer[accessor] = [...DEFAULT_LAYER_FILL_COLOR];\n } else {\n delete nextLayer[accessor];\n }\n return nextLayer;\n });\n}\n\nexport function createDeckMapLayerColorScale(options: {\n field: string;\n type?: ColorScaleConfig['type'];\n scheme?: ColorScaleScheme;\n title?: string;\n}): DeckMapLayerColorScaleFunction {\n const type = options.type ?? 'sequential';\n const scheme =\n options.scheme ??\n DECK_MAP_COLOR_SCALE_TYPE_OPTIONS.find((option) => option.value === type)\n ?.defaultScheme ??\n 'Viridis';\n const base = {\n '@@function': 'colorScale' as const,\n field: options.field,\n legend: {title: options.title ?? options.field},\n };\n\n if (type === 'categorical') {\n return {\n ...base,\n type,\n scheme: scheme as Extract<\n ColorScaleConfig,\n {type: 'categorical'}\n >['scheme'],\n };\n }\n\n if (type === 'diverging') {\n return {\n ...base,\n type,\n scheme: scheme as Extract<\n ColorScaleConfig,\n {type: 'diverging'}\n >['scheme'],\n domain: 'auto',\n };\n }\n\n if (type === 'quantize') {\n return {\n ...base,\n type,\n scheme: scheme as Extract<ColorScaleConfig, {type: 'quantize'}>['scheme'],\n domain: 'auto',\n };\n }\n\n if (type === 'quantile') {\n return {\n ...base,\n type,\n scheme: scheme as Extract<ColorScaleConfig, {type: 'quantile'}>['scheme'],\n };\n }\n\n if (type === 'threshold') {\n return {\n ...base,\n type,\n scheme: scheme as Extract<\n ColorScaleConfig,\n {type: 'threshold'}\n >['scheme'],\n thresholds: [],\n };\n }\n\n return {\n ...base,\n type: 'sequential',\n scheme: scheme as Extract<ColorScaleConfig, {type: 'sequential'}>['scheme'],\n domain: 'auto',\n };\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DeckMapConfig } from './mapConfig';
|
|
2
|
+
export type DeckMapResourceConfigIssue = {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export type DeckMapResourceConfigValidationOptions = {
|
|
7
|
+
/** Empty resources are valid while waiting for a user-selected table. */
|
|
8
|
+
allowEmpty?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** Controls how an incoming map config patch is merged with durable state. */
|
|
11
|
+
export type DeckMapResourceConfigMergeOptions = {
|
|
12
|
+
/** Treat an incoming `spec.layers` array as the complete replacement list. */
|
|
13
|
+
replaceLayers?: boolean;
|
|
14
|
+
/** Treat incoming `datasets` as the complete replacement registry. */
|
|
15
|
+
replaceDatasets?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** Error raised before an invalid map resource can be durably written. */
|
|
18
|
+
export declare class DeckMapResourceConfigError extends Error {
|
|
19
|
+
readonly issues: DeckMapResourceConfigIssue[];
|
|
20
|
+
constructor(issues: DeckMapResourceConfigIssue[]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Merges a sparse map-tool patch with durable state. Empty dataset registries
|
|
24
|
+
* and layer arrays mean "preserve" only when an existing resource is present.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mergeDeckMapResourceConfigPatch(existingConfig: DeckMapConfig | undefined, incomingConfig: DeckMapConfig, options?: DeckMapResourceConfigMergeOptions): DeckMapConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Validates the post-merge invariants of a renderable, resource-native map.
|
|
29
|
+
* Patch inputs may be sparse, but the durable result must have supported
|
|
30
|
+
* dataset sources and dataset-backed layers.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getDeckMapResourceConfigIssues(config: DeckMapConfig, options?: DeckMapResourceConfigValidationOptions): DeckMapResourceConfigIssue[];
|
|
33
|
+
/** Rejects invalid durable map writes after sparse patches have been merged. */
|
|
34
|
+
export declare function assertDeckMapResourceConfig(config: DeckMapConfig): void;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the package-owned authoring contract for hosts with direct worksheet
|
|
37
|
+
* map capability. Host adapters opt into it; they do not maintain prompt copies.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getDeckMapResourceAiInstructions(): string;
|
|
40
|
+
//# sourceMappingURL=mapResourceAuthoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapResourceAuthoring.d.ts","sourceRoot":"","sources":["../src/mapResourceAuthoring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAM/C,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,yEAAyE;IACzE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,iCAAiC,GAAG;IAC9C,8EAA8E;IAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sEAAsE;IACtE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,0EAA0E;AAC1E,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,MAAM,EAAE,0BAA0B,EAAE,CAAC;gBAElC,MAAM,EAAE,0BAA0B,EAAE;CASjD;AAkHD;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,cAAc,EAAE,aAAa,GAAG,SAAS,EACzC,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,iCAAsC,GAC9C,aAAa,CAoBf;AAmCD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,sCAA2C,GACnD,0BAA0B,EAAE,CAqG9B;AAED,gFAAgF;AAChF,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAGvE;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,IAAI,MAAM,CAkBzD"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { DeckJsonMapSpec } from './DeckJsonMapSpec';
|
|
2
|
+
import { isDeckMapSqlDatasetSource, isDeckMapTableDatasetSource, } from './mapConfig';
|
|
3
|
+
/** Error raised before an invalid map resource can be durably written. */
|
|
4
|
+
export class DeckMapResourceConfigError extends Error {
|
|
5
|
+
issues;
|
|
6
|
+
constructor(issues) {
|
|
7
|
+
super(`Invalid Deck map resource config: ${issues
|
|
8
|
+
.map((issue) => `${issue.path}: ${issue.message}`)
|
|
9
|
+
.join('; ')}`);
|
|
10
|
+
this.name = 'DeckMapResourceConfigError';
|
|
11
|
+
this.issues = issues;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
16
|
+
}
|
|
17
|
+
function hasEntries(value) {
|
|
18
|
+
return isRecord(value) && Object.keys(value).length > 0;
|
|
19
|
+
}
|
|
20
|
+
function mergeOptionalRecord(existing, incoming) {
|
|
21
|
+
if (isRecord(existing) && isRecord(incoming)) {
|
|
22
|
+
return { ...existing, ...incoming };
|
|
23
|
+
}
|
|
24
|
+
if (isRecord(incoming))
|
|
25
|
+
return incoming;
|
|
26
|
+
return isRecord(existing) ? existing : undefined;
|
|
27
|
+
}
|
|
28
|
+
function mergeLayerPatch(existingLayer, incomingLayer) {
|
|
29
|
+
if (!isRecord(existingLayer) || !isRecord(incomingLayer)) {
|
|
30
|
+
return incomingLayer;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...existingLayer,
|
|
34
|
+
...incomingLayer,
|
|
35
|
+
_sqlroomsBinding: mergeOptionalRecord(existingLayer._sqlroomsBinding, incomingLayer._sqlroomsBinding),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function mergeLayerPatches(existingLayers, incomingLayers) {
|
|
39
|
+
if (!incomingLayers || incomingLayers.length === 0)
|
|
40
|
+
return existingLayers;
|
|
41
|
+
if (!existingLayers || existingLayers.length === 0)
|
|
42
|
+
return incomingLayers;
|
|
43
|
+
const nextLayers = [...existingLayers];
|
|
44
|
+
for (const [incomingIndex, incomingLayer] of incomingLayers.entries()) {
|
|
45
|
+
const incomingId = isRecord(incomingLayer)
|
|
46
|
+
? incomingLayer.id
|
|
47
|
+
: undefined;
|
|
48
|
+
const existingIndex = incomingId
|
|
49
|
+
? existingLayers.findIndex((layer) => isRecord(layer) && layer.id === incomingId)
|
|
50
|
+
: incomingIndex < existingLayers.length
|
|
51
|
+
? incomingIndex
|
|
52
|
+
: -1;
|
|
53
|
+
if (existingIndex >= 0) {
|
|
54
|
+
nextLayers[existingIndex] = mergeLayerPatch(existingLayers[existingIndex], incomingLayer);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
nextLayers.push(incomingLayer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return nextLayers;
|
|
61
|
+
}
|
|
62
|
+
function mergeSpecPatch(existingSpec, incomingSpec, options) {
|
|
63
|
+
if (typeof incomingSpec === 'string')
|
|
64
|
+
return incomingSpec;
|
|
65
|
+
const existing = isRecord(existingSpec) ? existingSpec : undefined;
|
|
66
|
+
const incoming = isRecord(incomingSpec) ? incomingSpec : undefined;
|
|
67
|
+
if (!existing && !incoming)
|
|
68
|
+
return incomingSpec ?? existingSpec;
|
|
69
|
+
const existingLayers = Array.isArray(existing?.layers)
|
|
70
|
+
? existing.layers
|
|
71
|
+
: undefined;
|
|
72
|
+
const incomingLayers = Array.isArray(incoming?.layers)
|
|
73
|
+
? incoming.layers
|
|
74
|
+
: undefined;
|
|
75
|
+
const layers = options.replaceLayers && incomingLayers !== undefined
|
|
76
|
+
? incomingLayers
|
|
77
|
+
: mergeLayerPatches(existingLayers, incomingLayers);
|
|
78
|
+
return {
|
|
79
|
+
...(existing ?? {}),
|
|
80
|
+
...(incoming ?? {}),
|
|
81
|
+
...(layers ? { layers } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function mergeDatasetRegistry(existingDatasets, incomingDatasets, replaceDatasets) {
|
|
85
|
+
if (replaceDatasets)
|
|
86
|
+
return incomingDatasets;
|
|
87
|
+
if (!hasEntries(incomingDatasets))
|
|
88
|
+
return existingDatasets;
|
|
89
|
+
const datasets = { ...existingDatasets };
|
|
90
|
+
for (const [datasetId, incomingDataset] of Object.entries(incomingDatasets)) {
|
|
91
|
+
const existingDataset = existingDatasets[datasetId];
|
|
92
|
+
datasets[datasetId] = existingDataset
|
|
93
|
+
? {
|
|
94
|
+
...existingDataset,
|
|
95
|
+
...incomingDataset,
|
|
96
|
+
source: incomingDataset.source ?? existingDataset.source,
|
|
97
|
+
}
|
|
98
|
+
: incomingDataset;
|
|
99
|
+
}
|
|
100
|
+
return datasets;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Merges a sparse map-tool patch with durable state. Empty dataset registries
|
|
104
|
+
* and layer arrays mean "preserve" only when an existing resource is present.
|
|
105
|
+
*/
|
|
106
|
+
export function mergeDeckMapResourceConfigPatch(existingConfig, incomingConfig, options = {}) {
|
|
107
|
+
if (!existingConfig)
|
|
108
|
+
return incomingConfig;
|
|
109
|
+
return {
|
|
110
|
+
...existingConfig,
|
|
111
|
+
...incomingConfig,
|
|
112
|
+
spec: mergeSpecPatch(existingConfig.spec, incomingConfig.spec, options),
|
|
113
|
+
datasets: mergeDatasetRegistry(existingConfig.datasets, incomingConfig.datasets, options.replaceDatasets === true),
|
|
114
|
+
mapProps: mergeOptionalRecord(existingConfig.mapProps, incomingConfig.mapProps),
|
|
115
|
+
dataPolicy: mergeOptionalRecord(existingConfig.dataPolicy, incomingConfig.dataPolicy),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function parseSpec(config) {
|
|
119
|
+
let spec = config.spec;
|
|
120
|
+
if (typeof spec === 'string') {
|
|
121
|
+
try {
|
|
122
|
+
spec = JSON.parse(spec);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return {
|
|
126
|
+
layers: [],
|
|
127
|
+
issues: [{ path: 'spec', message: 'must be valid JSON' }],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const parsed = DeckJsonMapSpec.safeParse(spec);
|
|
132
|
+
if (!parsed.success) {
|
|
133
|
+
return {
|
|
134
|
+
layers: [],
|
|
135
|
+
issues: parsed.error.issues.map((issue) => ({
|
|
136
|
+
path: ['spec', ...issue.path].join('.'),
|
|
137
|
+
message: issue.message,
|
|
138
|
+
})),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
layers: (parsed.data.layers ?? []),
|
|
143
|
+
issues: [],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Validates the post-merge invariants of a renderable, resource-native map.
|
|
148
|
+
* Patch inputs may be sparse, but the durable result must have supported
|
|
149
|
+
* dataset sources and dataset-backed layers.
|
|
150
|
+
*/
|
|
151
|
+
export function getDeckMapResourceConfigIssues(config, options = {}) {
|
|
152
|
+
const issues = [];
|
|
153
|
+
const datasetEntries = Object.entries(config.datasets);
|
|
154
|
+
const datasetIds = datasetEntries.map(([datasetId]) => datasetId);
|
|
155
|
+
const datasetIdSet = new Set(datasetIds);
|
|
156
|
+
const parsedSpec = parseSpec(config);
|
|
157
|
+
issues.push(...parsedSpec.issues);
|
|
158
|
+
const isEmpty = datasetEntries.length === 0 && parsedSpec.layers.length === 0;
|
|
159
|
+
if (isEmpty) {
|
|
160
|
+
return options.allowEmpty
|
|
161
|
+
? issues
|
|
162
|
+
: [
|
|
163
|
+
...issues,
|
|
164
|
+
{
|
|
165
|
+
path: 'datasets',
|
|
166
|
+
message: 'must contain at least one dataset for a map write',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
path: 'spec.layers',
|
|
170
|
+
message: 'must contain at least one dataset-backed layer',
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
if (datasetEntries.length === 0) {
|
|
175
|
+
issues.push({
|
|
176
|
+
path: 'datasets',
|
|
177
|
+
message: 'must contain at least one dataset',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
for (const [datasetId, dataset] of datasetEntries) {
|
|
181
|
+
const source = dataset.source;
|
|
182
|
+
const hasSqlSource = isDeckMapSqlDatasetSource(source) && source.sqlQuery.trim().length > 0;
|
|
183
|
+
const hasTableSource = isDeckMapTableDatasetSource(source) && source.tableName.trim().length > 0;
|
|
184
|
+
if (!hasSqlSource && !hasTableSource) {
|
|
185
|
+
const legacySql = dataset.sql;
|
|
186
|
+
issues.push({
|
|
187
|
+
path: `datasets.${datasetId}.source`,
|
|
188
|
+
message: typeof legacySql === 'string'
|
|
189
|
+
? 'must define source.tableName or source.sqlQuery; top-level sql is not supported'
|
|
190
|
+
: 'must define source.tableName or source.sqlQuery',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (parsedSpec.layers.length === 0) {
|
|
195
|
+
issues.push({
|
|
196
|
+
path: 'spec.layers',
|
|
197
|
+
message: 'must contain at least one dataset-backed layer',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
parsedSpec.layers.forEach((layer, index) => {
|
|
201
|
+
const layerType = layer['@@type'];
|
|
202
|
+
if (typeof layerType !== 'string' || layerType.trim().length === 0) {
|
|
203
|
+
issues.push({
|
|
204
|
+
path: `spec.layers.${index}.@@type`,
|
|
205
|
+
message: 'must name a Deck JSON layer class',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const binding = layer._sqlroomsBinding && typeof layer._sqlroomsBinding === 'object'
|
|
209
|
+
? layer._sqlroomsBinding
|
|
210
|
+
: undefined;
|
|
211
|
+
const boundDataset = typeof binding?.dataset === 'string' && binding.dataset.trim()
|
|
212
|
+
? binding.dataset
|
|
213
|
+
: undefined;
|
|
214
|
+
if (boundDataset) {
|
|
215
|
+
if (!datasetIdSet.has(boundDataset)) {
|
|
216
|
+
issues.push({
|
|
217
|
+
path: `spec.layers.${index}._sqlroomsBinding.dataset`,
|
|
218
|
+
message: `references unknown dataset "${boundDataset}"`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
issues.push({
|
|
224
|
+
path: `spec.layers.${index}._sqlroomsBinding.dataset`,
|
|
225
|
+
message: 'must bind the layer to a config.datasets entry; layer data references and implicit bindings are not durable resource bindings',
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
const fitDataset = config.fitToData?.dataset;
|
|
229
|
+
if (fitDataset && !datasetIdSet.has(fitDataset)) {
|
|
230
|
+
issues.push({
|
|
231
|
+
path: 'fitToData.dataset',
|
|
232
|
+
message: `references unknown dataset "${fitDataset}"`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return issues;
|
|
236
|
+
}
|
|
237
|
+
/** Rejects invalid durable map writes after sparse patches have been merged. */
|
|
238
|
+
export function assertDeckMapResourceConfig(config) {
|
|
239
|
+
const issues = getDeckMapResourceConfigIssues(config);
|
|
240
|
+
if (issues.length > 0)
|
|
241
|
+
throw new DeckMapResourceConfigError(issues);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Returns the package-owned authoring contract for hosts with direct worksheet
|
|
245
|
+
* map capability. Host adapters opt into it; they do not maintain prompt copies.
|
|
246
|
+
*/
|
|
247
|
+
export function getDeckMapResourceAiInstructions() {
|
|
248
|
+
return `## Direct worksheet Deck map resources
|
|
249
|
+
|
|
250
|
+
When authoring a worksheet map config, use the resource-native Deck JSON contract:
|
|
251
|
+
- A new map must contain at least one config.datasets entry and at least one spec.layers entry.
|
|
252
|
+
- Every dataset must define source.tableName, source.tableName plus source.transformSql, or source.sqlQuery. Never put sql directly on the dataset object.
|
|
253
|
+
- Bind every layer to a dataset with _sqlroomsBinding.dataset. Never use data: "@@#datasetId" or an implicit single-dataset binding as a durable resource binding.
|
|
254
|
+
- Use supported Deck JSON layer classes such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, GeoArrowTripsLayer, GeoArrowArcLayer, GeoArrowColumnLayer, GeoArrowH3HexagonLayer, or GeoJsonLayer.
|
|
255
|
+
- For table-backed datasets, also pass the same table through the tool's top-level tableName field. A selected table does not replace the required dataset source.
|
|
256
|
+
- transformSql must be a single SELECT and must read from __sqlrooms_source. Use source.sqlQuery only for a standalone pinned query.
|
|
257
|
+
- Use configMode "basic" for a straightforward single-layer map. Use "custom" only for advanced properties the basic settings cannot represent; custom mode does not relax dataset-source or layer-binding requirements.
|
|
258
|
+
- For a point geometry column, prefer GeoArrowScatterplotLayer with dataset.geometryColumn and _sqlroomsBinding.geometryColumn set to the exact geometry column. For longitude/latitude columns, use source.transformSql to produce WKB geometry and bind that output column.
|
|
259
|
+
- For updates, sparse config patches are allowed because they are merged with the existing resource. For creates, never send empty datasets or layers.
|
|
260
|
+
- To remove existing layers or datasets, set replaceLayers and/or replaceDatasets to true and send the complete desired list or registry. Omit them for additive sparse updates.
|
|
261
|
+
- If a map write reports an invalid resource config, repair the reported paths and retry the same direct map operation; do not replace it with a dashboard-backed map.
|
|
262
|
+
|
|
263
|
+
Minimal table-backed point map shape:
|
|
264
|
+
{"configMode":"basic","datasets":{"places":{"source":{"tableName":"places"},"geometryColumn":"geom","geometryEncodingHint":"wkb"}},"spec":{"layers":[{"@@type":"GeoArrowScatterplotLayer","id":"places","_sqlroomsBinding":{"dataset":"places","geometryColumn":"geom"},"getRadius":4,"radiusUnits":"pixels","pickable":true}]},"fitToData":{"dataset":"places","geometryColumn":"geom"}}`;
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=mapResourceAuthoring.js.map
|