@deck.gl-community/graph-layers 9.1.0-beta.8 → 9.2.0-beta.2
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 +1 -1
- package/dist/_deprecated/old-constants.d.ts +107 -0
- package/dist/_deprecated/old-constants.d.ts.map +1 -0
- package/dist/_deprecated/old-constants.js +111 -0
- package/dist/_deprecated/old-constants.js.map +1 -0
- package/dist/core/cache.d.ts +0 -1
- package/dist/core/cache.js +0 -1
- package/dist/core/constants.d.ts +12 -100
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +3 -44
- package/dist/core/constants.js.map +1 -1
- package/dist/core/graph-engine.d.ts +12 -11
- package/dist/core/graph-engine.d.ts.map +1 -1
- package/dist/core/graph-engine.js +22 -11
- package/dist/core/graph-engine.js.map +1 -1
- package/dist/core/graph-layout.d.ts +48 -21
- package/dist/core/graph-layout.d.ts.map +1 -1
- package/dist/core/graph-layout.js +91 -24
- package/dist/core/graph-layout.js.map +1 -1
- package/dist/core/interaction-manager.d.ts +6 -4
- package/dist/core/interaction-manager.d.ts.map +1 -1
- package/dist/core/interaction-manager.js +59 -17
- package/dist/core/interaction-manager.js.map +1 -1
- package/dist/graph/edge.d.ts +7 -7
- package/dist/graph/edge.d.ts.map +1 -1
- package/dist/graph/edge.js +3 -6
- package/dist/graph/edge.js.map +1 -1
- package/dist/graph/graph.d.ts +2 -3
- package/dist/graph/graph.js +8 -9
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/node.d.ts +7 -8
- package/dist/graph/node.d.ts.map +1 -1
- package/dist/graph/node.js +3 -5
- package/dist/graph/node.js.map +1 -1
- package/dist/graph-style-schema.cdn.d.ts +2 -0
- package/dist/graph-style-schema.cdn.js +2 -0
- package/dist/graph-style-schema.json +12 -0
- package/dist/index.cjs +2821 -549
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +28 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -21
- package/dist/index.js.map +1 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.d.ts +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.js +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.d.ts +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.js +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.d.ts +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.js +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer.d.ts +0 -1
- package/dist/layers/common-layers/flow-path-layer/flow-path-layer.js +0 -1
- package/dist/layers/common-layers/marker-layer/atlas-data-url.d.ts +0 -1
- package/dist/layers/common-layers/marker-layer/atlas-data-url.js +0 -1
- package/dist/layers/common-layers/marker-layer/marker-layer.d.ts +0 -1
- package/dist/layers/common-layers/marker-layer/marker-layer.js +2 -3
- package/dist/layers/common-layers/marker-layer/marker-list.d.ts +2 -63
- package/dist/layers/common-layers/marker-layer/marker-list.d.ts.map +1 -1
- package/dist/layers/common-layers/marker-layer/marker-list.js +1 -65
- package/dist/layers/common-layers/marker-layer/marker-list.js.map +1 -1
- package/dist/layers/common-layers/marker-layer/marker-mapping.d.ts +0 -1
- package/dist/layers/common-layers/marker-layer/marker-mapping.js +0 -1
- package/dist/layers/common-layers/spline-layer/spline-layer.d.ts +0 -1
- package/dist/layers/common-layers/spline-layer/spline-layer.js +0 -1
- package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.d.ts +0 -1
- package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.js +0 -1
- package/dist/layers/edge-attachment-helper.d.ts +15 -0
- package/dist/layers/edge-attachment-helper.d.ts.map +1 -0
- package/dist/layers/edge-attachment-helper.js +230 -0
- package/dist/layers/edge-attachment-helper.js.map +1 -0
- package/dist/layers/edge-layer.d.ts +1 -5
- package/dist/layers/edge-layer.d.ts.map +1 -1
- package/dist/layers/edge-layer.js +9 -11
- package/dist/layers/edge-layer.js.map +1 -1
- package/dist/layers/edge-layers/arrow-2d-geometry.d.ts +4 -0
- package/dist/layers/edge-layers/arrow-2d-geometry.d.ts.map +1 -0
- package/dist/layers/edge-layers/arrow-2d-geometry.js +42 -0
- package/dist/layers/edge-layers/arrow-2d-geometry.js.map +1 -0
- package/dist/layers/edge-layers/curved-edge-layer.d.ts +1 -2
- package/dist/layers/edge-layers/curved-edge-layer.js +1 -2
- package/dist/layers/edge-layers/edge-arrow-layer.d.ts +21 -0
- package/dist/layers/edge-layers/edge-arrow-layer.d.ts.map +1 -0
- package/dist/layers/edge-layers/edge-arrow-layer.js +131 -0
- package/dist/layers/edge-layers/edge-arrow-layer.js.map +1 -0
- package/dist/layers/edge-layers/edge-label-layer.d.ts +1 -2
- package/dist/layers/edge-layers/edge-label-layer.js +1 -2
- package/dist/layers/edge-layers/flow-layer.d.ts +1 -2
- package/dist/layers/edge-layers/flow-layer.js +1 -2
- package/dist/layers/edge-layers/path-edge-layer.d.ts +0 -1
- package/dist/layers/edge-layers/path-edge-layer.js +0 -1
- package/dist/layers/edge-layers/straight-line-edge-layer.d.ts +0 -1
- package/dist/layers/edge-layers/straight-line-edge-layer.js +0 -1
- package/dist/layers/graph-layer.d.ts +22 -23
- package/dist/layers/graph-layer.d.ts.map +1 -1
- package/dist/layers/graph-layer.js +218 -62
- package/dist/layers/graph-layer.js.map +1 -1
- package/dist/layers/node-layers/circle-layer.d.ts +0 -1
- package/dist/layers/node-layers/circle-layer.js +0 -1
- package/dist/layers/node-layers/image-layer.d.ts +0 -1
- package/dist/layers/node-layers/image-layer.js +0 -1
- package/dist/layers/node-layers/label-layer.d.ts +1 -2
- package/dist/layers/node-layers/label-layer.js +1 -2
- package/dist/layers/node-layers/path-rounded-rectangle-layer.d.ts +0 -1
- package/dist/layers/node-layers/path-rounded-rectangle-layer.js +1 -2
- package/dist/layers/node-layers/rectangle-layer.d.ts +0 -1
- package/dist/layers/node-layers/rectangle-layer.js +0 -1
- package/dist/layers/node-layers/rounded-rectangle-layer-fragment.d.ts +0 -1
- package/dist/layers/node-layers/rounded-rectangle-layer-fragment.js +0 -1
- package/dist/layers/node-layers/rounded-rectangle-layer.d.ts +1 -2
- package/dist/layers/node-layers/rounded-rectangle-layer.js +2 -3
- package/dist/layers/node-layers/zoomable-marker-layer.d.ts +1 -2
- package/dist/layers/node-layers/zoomable-marker-layer.js +1 -2
- package/dist/layouts/d3-dag/d3-dag-layout.d.ts +117 -0
- package/dist/layouts/d3-dag/d3-dag-layout.d.ts.map +1 -0
- package/dist/layouts/d3-dag/d3-dag-layout.js +716 -0
- package/dist/layouts/d3-dag/d3-dag-layout.js.map +1 -0
- package/dist/layouts/d3-force/d3-force-layout.d.ts +4 -4
- package/dist/layouts/d3-force/d3-force-layout.d.ts.map +1 -1
- package/dist/layouts/d3-force/d3-force-layout.js +25 -10
- package/dist/layouts/d3-force/d3-force-layout.js.map +1 -1
- package/dist/layouts/d3-force/worker.d.ts +0 -1
- package/dist/layouts/d3-force/worker.js +0 -1
- package/dist/layouts/experimental/force-multi-graph-layout.d.ts +9 -8
- package/dist/layouts/experimental/force-multi-graph-layout.d.ts.map +1 -1
- package/dist/layouts/experimental/force-multi-graph-layout.js +15 -11
- package/dist/layouts/experimental/force-multi-graph-layout.js.map +1 -1
- package/dist/layouts/experimental/hive-plot-layout.d.ts +11 -8
- package/dist/layouts/experimental/hive-plot-layout.d.ts.map +1 -1
- package/dist/layouts/experimental/hive-plot-layout.js +12 -7
- package/dist/layouts/experimental/hive-plot-layout.js.map +1 -1
- package/dist/layouts/experimental/radial-layout.d.ts +10 -7
- package/dist/layouts/experimental/radial-layout.d.ts.map +1 -1
- package/dist/layouts/experimental/radial-layout.js +11 -6
- package/dist/layouts/experimental/radial-layout.js.map +1 -1
- package/dist/layouts/gpu-force/gpu-force-layout.d.ts +4 -4
- package/dist/layouts/gpu-force/gpu-force-layout.d.ts.map +1 -1
- package/dist/layouts/gpu-force/gpu-force-layout.js +18 -9
- package/dist/layouts/gpu-force/gpu-force-layout.js.map +1 -1
- package/dist/layouts/gpu-force/worker.d.ts +0 -1
- package/dist/layouts/gpu-force/worker.js +0 -1
- package/dist/layouts/simple-layout.d.ts +19 -12
- package/dist/layouts/simple-layout.d.ts.map +1 -1
- package/dist/layouts/simple-layout.js +26 -15
- package/dist/layouts/simple-layout.js.map +1 -1
- package/dist/loaders/create-graph.d.ts +1 -2
- package/dist/loaders/create-graph.js +3 -4
- package/dist/loaders/edge-parsers.d.ts +1 -2
- package/dist/loaders/edge-parsers.js +2 -3
- package/dist/loaders/edge-parsers.js.map +1 -1
- package/dist/loaders/json-loader.d.ts +2 -3
- package/dist/loaders/json-loader.d.ts.map +1 -1
- package/dist/loaders/json-loader.js +5 -6
- package/dist/loaders/json-loader.js.map +1 -1
- package/dist/loaders/node-parsers.d.ts +1 -2
- package/dist/loaders/node-parsers.js +2 -3
- package/dist/loaders/node-parsers.js.map +1 -1
- package/dist/loaders/simple-json-graph-loader.d.ts +0 -1
- package/dist/loaders/simple-json-graph-loader.d.ts.map +1 -1
- package/dist/loaders/simple-json-graph-loader.js +5 -6
- package/dist/loaders/simple-json-graph-loader.js.map +1 -1
- package/dist/loaders/table-graph-loader.d.ts +3 -4
- package/dist/loaders/table-graph-loader.js +5 -6
- package/dist/loaders/table-graph-loader.js.map +1 -1
- package/dist/style/graph-layer-stylesheet.d.ts +34 -0
- package/dist/style/graph-layer-stylesheet.d.ts.map +1 -0
- package/dist/style/graph-layer-stylesheet.js +39 -0
- package/dist/style/graph-layer-stylesheet.js.map +1 -0
- package/dist/style/graph-style-accessor-map.d.ts +93 -0
- package/dist/style/graph-style-accessor-map.d.ts.map +1 -0
- package/dist/style/graph-style-accessor-map.js +93 -0
- package/dist/style/graph-style-accessor-map.js.map +1 -0
- package/dist/style/graph-style-engine.d.ts +10 -0
- package/dist/style/graph-style-engine.d.ts.map +1 -0
- package/dist/style/graph-style-engine.js +163 -0
- package/dist/style/graph-style-engine.js.map +1 -0
- package/dist/style/graph-stylesheet.schema.d.ts +310 -0
- package/dist/style/graph-stylesheet.schema.d.ts.map +1 -0
- package/dist/style/graph-stylesheet.schema.js +237 -0
- package/dist/style/graph-stylesheet.schema.js.map +1 -0
- package/dist/style/style-engine.d.ts +33 -0
- package/dist/style/style-engine.d.ts.map +1 -0
- package/dist/style/style-engine.js +121 -0
- package/dist/style/style-engine.js.map +1 -0
- package/dist/style/style-property.d.ts +2 -3
- package/dist/style/style-property.d.ts.map +1 -1
- package/dist/style/style-property.js +224 -48
- package/dist/style/style-property.js.map +1 -1
- package/dist/utils/collapsed-chains.d.ts +17 -0
- package/dist/utils/collapsed-chains.d.ts.map +1 -0
- package/dist/utils/collapsed-chains.js +197 -0
- package/dist/utils/collapsed-chains.js.map +1 -0
- package/dist/utils/layer-utils.d.ts +0 -1
- package/dist/utils/layer-utils.d.ts.map +1 -1
- package/dist/utils/layer-utils.js +0 -1
- package/dist/utils/log.d.ts +2 -1
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +12 -2
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/node-boundary.d.ts +10 -0
- package/dist/utils/node-boundary.d.ts.map +1 -0
- package/dist/utils/node-boundary.js +130 -0
- package/dist/utils/node-boundary.js.map +1 -0
- package/dist/utils/polygon-calculations.d.ts +0 -1
- package/dist/utils/polygon-calculations.js +0 -1
- package/dist/widgets/long-press-button.d.ts +0 -1
- package/dist/widgets/long-press-button.js +0 -1
- package/dist/widgets/view-control-widget.d.ts +4 -5
- package/dist/widgets/view-control-widget.d.ts.map +1 -1
- package/dist/widgets/view-control-widget.js +10 -8
- package/dist/widgets/view-control-widget.js.map +1 -1
- package/package.json +23 -7
- package/src/_deprecated/old-constants.ts +122 -0
- package/src/core/constants.ts +21 -43
- package/src/core/graph-engine.ts +24 -9
- package/src/core/graph-layout.ts +133 -28
- package/src/core/interaction-manager.ts +80 -20
- package/src/graph/edge.ts +6 -6
- package/src/graph/graph.ts +7 -7
- package/src/graph/node.ts +6 -6
- package/src/index.ts +31 -6
- package/src/layers/common-layers/marker-layer/marker-list.ts +62 -64
- package/src/layers/edge-attachment-helper.ts +355 -0
- package/src/layers/edge-layer.ts +6 -7
- package/src/layers/edge-layers/arrow-2d-geometry.ts +51 -0
- package/src/layers/edge-layers/edge-arrow-layer.ts +171 -0
- package/src/layers/graph-layer.ts +304 -86
- package/src/layouts/d3-dag/d3-dag-layout.ts +969 -0
- package/src/layouts/d3-force/d3-force-layout.ts +33 -11
- package/src/layouts/experimental/force-multi-graph-layout.ts +22 -13
- package/src/layouts/experimental/hive-plot-layout.ts +22 -10
- package/src/layouts/experimental/radial-layout.ts +20 -8
- package/src/layouts/gpu-force/gpu-force-layout.ts +22 -10
- package/src/layouts/simple-layout.ts +48 -25
- package/src/loaders/edge-parsers.ts +2 -2
- package/src/loaders/json-loader.ts +2 -2
- package/src/loaders/node-parsers.ts +2 -2
- package/src/loaders/simple-json-graph-loader.ts +2 -2
- package/src/loaders/table-graph-loader.ts +2 -2
- package/src/style/graph-layer-stylesheet.ts +99 -0
- package/src/style/graph-style-accessor-map.ts +103 -0
- package/src/style/graph-style-engine.ts +229 -0
- package/src/style/graph-stylesheet.schema.ts +344 -0
- package/src/style/style-engine.ts +168 -0
- package/src/style/style-property.ts +314 -51
- package/src/utils/collapsed-chains.ts +261 -0
- package/src/utils/log.ts +15 -1
- package/src/utils/node-boundary.ts +238 -0
- package/src/widgets/view-control-widget.tsx +15 -13
- package/dist/style/style-sheet.d.ts +0 -11
- package/dist/style/style-sheet.d.ts.map +0 -1
- package/dist/style/style-sheet.js +0 -253
- package/dist/style/style-sheet.js.map +0 -1
- package/src/style/style-sheet.ts +0 -277
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-continue */
|
|
6
|
+
|
|
7
|
+
import {z, type ZodTypeAny} from 'zod';
|
|
8
|
+
|
|
9
|
+
const GraphStylePrimitiveSchema = z.union([
|
|
10
|
+
z.string(),
|
|
11
|
+
z.number(),
|
|
12
|
+
z.boolean(),
|
|
13
|
+
z.null(),
|
|
14
|
+
z.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const GraphStyleFunctionSchema = z.custom<(...args: unknown[]) => unknown>(
|
|
18
|
+
(value) => typeof value === 'function',
|
|
19
|
+
{
|
|
20
|
+
message: 'Style functions must be callable.'
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Supported scale identifiers for mapping data values to visual encodings.
|
|
26
|
+
*/
|
|
27
|
+
export const GraphStyleScaleTypeEnum = z.enum([
|
|
28
|
+
'linear',
|
|
29
|
+
'log',
|
|
30
|
+
'pow',
|
|
31
|
+
'sqrt',
|
|
32
|
+
'quantize',
|
|
33
|
+
'quantile',
|
|
34
|
+
'ordinal'
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TypeScript union of {@link GraphStyleScaleTypeEnum} values.
|
|
39
|
+
*/
|
|
40
|
+
export type GraphStyleScaleType = z.infer<typeof GraphStyleScaleTypeEnum>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Configuration for data-driven style scaling. Supports deck.gl compatible numeric and
|
|
44
|
+
* categorical scaling with optional d3-scale like parameters.
|
|
45
|
+
*/
|
|
46
|
+
export const GraphStyleScaleSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
type: GraphStyleScaleTypeEnum.optional(),
|
|
49
|
+
domain: z.array(z.union([z.number(), z.string()])).optional(),
|
|
50
|
+
range: z.array(z.any()).optional(),
|
|
51
|
+
clamp: z.boolean().optional(),
|
|
52
|
+
nice: z.union([z.boolean(), z.number()]).optional(),
|
|
53
|
+
base: z.number().optional(),
|
|
54
|
+
exponent: z.number().optional(),
|
|
55
|
+
unknown: z.any().optional()
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* TypeScript view of {@link GraphStyleScaleSchema} after parsing.
|
|
61
|
+
*/
|
|
62
|
+
export type GraphStyleScale = z.infer<typeof GraphStyleScaleSchema>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reference to node/edge attributes, optionally including fallback values and scale
|
|
66
|
+
* configuration for data-driven styling.
|
|
67
|
+
*/
|
|
68
|
+
export const GraphStyleAttributeReferenceSchema = z.union([
|
|
69
|
+
z
|
|
70
|
+
.string()
|
|
71
|
+
.regex(/^@.+/, 'Attribute reference strings must start with "@" and include an attribute name.'),
|
|
72
|
+
z
|
|
73
|
+
.object({
|
|
74
|
+
attribute: z.string().min(1, 'Attribute name is required.'),
|
|
75
|
+
fallback: GraphStylePrimitiveSchema.optional(),
|
|
76
|
+
scale: z.union([GraphStyleScaleSchema, GraphStyleFunctionSchema]).optional()
|
|
77
|
+
})
|
|
78
|
+
.strict()
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Parsed value produced by {@link GraphStyleAttributeReferenceSchema}.
|
|
83
|
+
*/
|
|
84
|
+
export type GraphStyleAttributeReference = z.infer<typeof GraphStyleAttributeReferenceSchema>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Primitive value allowed in stylesheet definitions. Supports literal values, attribute
|
|
88
|
+
* references and imperative resolver functions.
|
|
89
|
+
*/
|
|
90
|
+
export const GraphStyleLeafValueSchema = z.union([
|
|
91
|
+
GraphStylePrimitiveSchema,
|
|
92
|
+
GraphStyleAttributeReferenceSchema,
|
|
93
|
+
GraphStyleFunctionSchema
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Union of literal, attribute-driven and functional style values.
|
|
98
|
+
*/
|
|
99
|
+
export type GraphStyleLeafValue = z.infer<typeof GraphStyleLeafValueSchema>;
|
|
100
|
+
|
|
101
|
+
const RESERVED_STATE_KEYS = new Set(['attribute', 'fallback', 'scale']);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Mapping of interaction or application state keys to leaf style values.
|
|
105
|
+
*/
|
|
106
|
+
export const GraphStyleStateMapSchema = z.record(
|
|
107
|
+
z
|
|
108
|
+
.string()
|
|
109
|
+
.refine((key) => !RESERVED_STATE_KEYS.has(key), 'State overrides must not use reserved keys.'),
|
|
110
|
+
GraphStyleLeafValueSchema
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Style value that may be either a simple leaf value or a keyed map of overrides.
|
|
115
|
+
*/
|
|
116
|
+
export const GraphStyleValueSchema = z.union([
|
|
117
|
+
GraphStyleLeafValueSchema,
|
|
118
|
+
GraphStyleStateMapSchema
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Parsed style property value that may include state overrides.
|
|
123
|
+
*/
|
|
124
|
+
export type GraphStyleValue = z.infer<typeof GraphStyleValueSchema>;
|
|
125
|
+
|
|
126
|
+
const COMMON_DECKGL_PROPS = {
|
|
127
|
+
getOffset: 'offset',
|
|
128
|
+
opacity: 'opacity'
|
|
129
|
+
} as const;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Translation table between graph style properties and the underlying deck.gl accessors for
|
|
133
|
+
* each supported style primitive type.
|
|
134
|
+
*/
|
|
135
|
+
export const GRAPH_DECKGL_ACCESSOR_MAP = {
|
|
136
|
+
circle: {
|
|
137
|
+
...COMMON_DECKGL_PROPS,
|
|
138
|
+
getFillColor: 'fill',
|
|
139
|
+
getLineColor: 'stroke',
|
|
140
|
+
getLineWidth: 'strokeWidth',
|
|
141
|
+
getRadius: 'radius'
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
rectangle: {
|
|
145
|
+
...COMMON_DECKGL_PROPS,
|
|
146
|
+
getWidth: 'width',
|
|
147
|
+
getHeight: 'height',
|
|
148
|
+
getFillColor: 'fill',
|
|
149
|
+
getLineColor: 'stroke',
|
|
150
|
+
getLineWidth: 'strokeWidth'
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
'rounded-rectangle': {
|
|
154
|
+
...COMMON_DECKGL_PROPS,
|
|
155
|
+
getCornerRadius: 'cornerRadius',
|
|
156
|
+
getRadius: 'radius',
|
|
157
|
+
getWidth: 'width',
|
|
158
|
+
getHeight: 'height',
|
|
159
|
+
getFillColor: 'fill',
|
|
160
|
+
getLineColor: 'stroke',
|
|
161
|
+
getLineWidth: 'strokeWidth'
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
'path-rounded-rectangle': {
|
|
165
|
+
...COMMON_DECKGL_PROPS,
|
|
166
|
+
getWidth: 'width',
|
|
167
|
+
getHeight: 'height',
|
|
168
|
+
getFillColor: 'fill',
|
|
169
|
+
getLineColor: 'stroke',
|
|
170
|
+
getLineWidth: 'strokeWidth',
|
|
171
|
+
getCornerRadius: 'cornerRadius'
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
label: {
|
|
175
|
+
...COMMON_DECKGL_PROPS,
|
|
176
|
+
getColor: 'color',
|
|
177
|
+
getText: 'text',
|
|
178
|
+
getSize: 'fontSize',
|
|
179
|
+
getTextAnchor: 'textAnchor',
|
|
180
|
+
getAlignmentBaseline: 'alignmentBaseline',
|
|
181
|
+
getAngle: 'angle',
|
|
182
|
+
scaleWithZoom: 'scaleWithZoom',
|
|
183
|
+
textMaxWidth: 'textMaxWidth',
|
|
184
|
+
textWordBreak: 'textWordBreak',
|
|
185
|
+
textSizeMinPixels: 'textSizeMinPixels'
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
marker: {
|
|
189
|
+
...COMMON_DECKGL_PROPS,
|
|
190
|
+
getColor: 'fill',
|
|
191
|
+
getSize: 'size',
|
|
192
|
+
getMarker: 'marker',
|
|
193
|
+
scaleWithZoom: 'scaleWithZoom'
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
Edge: {
|
|
197
|
+
getColor: 'stroke',
|
|
198
|
+
getWidth: 'strokeWidth'
|
|
199
|
+
},
|
|
200
|
+
edge: {
|
|
201
|
+
getColor: 'stroke',
|
|
202
|
+
getWidth: 'strokeWidth'
|
|
203
|
+
},
|
|
204
|
+
'edge-label': {
|
|
205
|
+
getColor: 'color',
|
|
206
|
+
getText: 'text',
|
|
207
|
+
getSize: 'fontSize',
|
|
208
|
+
getTextAnchor: 'textAnchor',
|
|
209
|
+
getAlignmentBaseline: 'alignmentBaseline',
|
|
210
|
+
scaleWithZoom: 'scaleWithZoom',
|
|
211
|
+
textMaxWidth: 'textMaxWidth',
|
|
212
|
+
textWordBreak: 'textWordBreak',
|
|
213
|
+
textSizeMinPixels: 'textSizeMinPixels'
|
|
214
|
+
},
|
|
215
|
+
flow: {
|
|
216
|
+
getColor: 'color',
|
|
217
|
+
getWidth: 'width',
|
|
218
|
+
getSpeed: 'speed',
|
|
219
|
+
getTailLength: 'tailLength'
|
|
220
|
+
},
|
|
221
|
+
arrow: {
|
|
222
|
+
getColor: 'color',
|
|
223
|
+
getSize: 'size',
|
|
224
|
+
getOffset: 'offset'
|
|
225
|
+
}
|
|
226
|
+
} as const;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Supported graph style primitive identifiers (e.g. `circle`, `edge`).
|
|
230
|
+
*/
|
|
231
|
+
export type GraphStyleType = keyof typeof GRAPH_DECKGL_ACCESSOR_MAP;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* CSS-like pseudo selector supported by the stylesheet for state overrides.
|
|
235
|
+
*/
|
|
236
|
+
export type GraphStyleSelector = `:${string}`;
|
|
237
|
+
|
|
238
|
+
type GraphStylePropertyKey<TType extends GraphStyleType> = Extract<
|
|
239
|
+
(typeof GRAPH_DECKGL_ACCESSOR_MAP)[TType][keyof (typeof GRAPH_DECKGL_ACCESSOR_MAP)[TType]],
|
|
240
|
+
PropertyKey
|
|
241
|
+
>;
|
|
242
|
+
|
|
243
|
+
type GraphStyleStatefulValue<TValue> = TValue | {[state: string]: TValue};
|
|
244
|
+
|
|
245
|
+
type GraphStylePropertyMap<TType extends GraphStyleType, TValue> = Partial<
|
|
246
|
+
Record<GraphStylePropertyKey<TType>, GraphStyleStatefulValue<TValue>>
|
|
247
|
+
>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Typed representation of a stylesheet definition for a specific graph primitive.
|
|
251
|
+
*/
|
|
252
|
+
export type GraphStylesheet<
|
|
253
|
+
TType extends GraphStyleType = GraphStyleType,
|
|
254
|
+
TValue = GraphStyleLeafValue
|
|
255
|
+
> = {type: TType} &
|
|
256
|
+
GraphStylePropertyMap<TType, TValue> &
|
|
257
|
+
Partial<Record<GraphStyleSelector, GraphStylePropertyMap<TType, TValue>>>;
|
|
258
|
+
|
|
259
|
+
const GraphStyleSelectorKeySchema = z.string().regex(/^:[^\s]+/, 'Selectors must start with ":".');
|
|
260
|
+
|
|
261
|
+
function createPropertiesSchema(keys: readonly string[]) {
|
|
262
|
+
const shape = keys.reduce<Record<string, ZodTypeAny>>((acc, key) => {
|
|
263
|
+
acc[key] = GraphStyleValueSchema.optional();
|
|
264
|
+
return acc;
|
|
265
|
+
}, {});
|
|
266
|
+
return z.object(shape).partial().strict();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const GraphStylesheetVariants = (
|
|
270
|
+
Object.entries(GRAPH_DECKGL_ACCESSOR_MAP) as Array<
|
|
271
|
+
[GraphStyleType, (typeof GRAPH_DECKGL_ACCESSOR_MAP)[GraphStyleType]]
|
|
272
|
+
>
|
|
273
|
+
).map(([type, accessors]) => {
|
|
274
|
+
const propertyKeys = Object.values(accessors);
|
|
275
|
+
const propertyKeySet = new Set<string>(propertyKeys);
|
|
276
|
+
const propertiesSchema = createPropertiesSchema(propertyKeys);
|
|
277
|
+
const baseShape: Record<string, ZodTypeAny> = {
|
|
278
|
+
type: z.literal(type)
|
|
279
|
+
};
|
|
280
|
+
for (const key of propertyKeys) {
|
|
281
|
+
baseShape[key] = GraphStyleValueSchema.optional();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return z
|
|
285
|
+
.object(baseShape)
|
|
286
|
+
.catchall(z.unknown())
|
|
287
|
+
.superRefine((value, ctx) => {
|
|
288
|
+
for (const key of Object.keys(value)) {
|
|
289
|
+
if (key === 'type') {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (propertyKeySet.has(key)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (!key.startsWith(':')) {
|
|
296
|
+
ctx.addIssue({
|
|
297
|
+
code: z.ZodIssueCode.custom,
|
|
298
|
+
path: [key],
|
|
299
|
+
message: `Unknown style property "${key}".`
|
|
300
|
+
});
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (!GraphStyleSelectorKeySchema.safeParse(key).success) {
|
|
304
|
+
ctx.addIssue({
|
|
305
|
+
code: z.ZodIssueCode.custom,
|
|
306
|
+
path: [key],
|
|
307
|
+
message: 'Selectors must start with ":".'
|
|
308
|
+
});
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const selectorResult = propertiesSchema.safeParse(value[key]);
|
|
312
|
+
if (!selectorResult.success) {
|
|
313
|
+
for (const issue of selectorResult.error.issues) {
|
|
314
|
+
ctx.addIssue({
|
|
315
|
+
...issue,
|
|
316
|
+
path: [key, ...(issue.path ?? [])]
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
type GraphStylesheetVariantSchema = (typeof GraphStylesheetVariants)[number];
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Schema that validates stylesheet definitions for all graph style primitives.
|
|
328
|
+
*/
|
|
329
|
+
export const GraphStylesheetSchema = z.discriminatedUnion(
|
|
330
|
+
'type',
|
|
331
|
+
GraphStylesheetVariants as [
|
|
332
|
+
GraphStylesheetVariantSchema,
|
|
333
|
+
...GraphStylesheetVariantSchema[]
|
|
334
|
+
]
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Runtime type accepted by {@link GraphStylesheetSchema} before validation.
|
|
339
|
+
*/
|
|
340
|
+
export type GraphStylesheetInput = z.input<typeof GraphStylesheetSchema>;
|
|
341
|
+
/**
|
|
342
|
+
* Type returned by {@link GraphStylesheetSchema} after successful parsing.
|
|
343
|
+
*/
|
|
344
|
+
export type GraphStylesheetParsed = z.infer<typeof GraphStylesheetSchema>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {StyleProperty} from './style-property';
|
|
6
|
+
import {error} from '../utils/log';
|
|
7
|
+
|
|
8
|
+
export type DeckGLAccessorMap = Record<string, Record<string, string>>;
|
|
9
|
+
export type DeckGLUpdateTriggers = Record<string, string[]>;
|
|
10
|
+
|
|
11
|
+
export type StylePropertyConstructor<T extends StyleProperty = StyleProperty> = new (args: {
|
|
12
|
+
key: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
updateTrigger: unknown;
|
|
15
|
+
}) => T;
|
|
16
|
+
|
|
17
|
+
export type DefaultStyleValueFn = (property: string) => unknown;
|
|
18
|
+
|
|
19
|
+
export type StyleEngineOptions<T extends StyleProperty = StyleProperty> = {
|
|
20
|
+
deckglAccessorMap: DeckGLAccessorMap;
|
|
21
|
+
deckglUpdateTriggers?: DeckGLUpdateTriggers;
|
|
22
|
+
stateUpdateTrigger?: unknown;
|
|
23
|
+
StylePropertyClass?: StylePropertyConstructor<T>;
|
|
24
|
+
getDefaultStyleValue?: DefaultStyleValueFn;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const DEFAULT_UPDATE_TRIGGERS: DeckGLUpdateTriggers = {};
|
|
28
|
+
|
|
29
|
+
export class StyleEngine<TStyleProperty extends StyleProperty = StyleProperty> {
|
|
30
|
+
type: string;
|
|
31
|
+
properties: Record<string, TStyleProperty>;
|
|
32
|
+
|
|
33
|
+
protected readonly deckglAccessorMap: DeckGLAccessorMap;
|
|
34
|
+
protected readonly deckglUpdateTriggers: DeckGLUpdateTriggers;
|
|
35
|
+
protected readonly stateUpdateTrigger: unknown;
|
|
36
|
+
protected readonly StylePropertyClass: StylePropertyConstructor<TStyleProperty>;
|
|
37
|
+
protected readonly getDefaultStyleValue: DefaultStyleValueFn;
|
|
38
|
+
|
|
39
|
+
constructor(style: Record<string, any>, options: StyleEngineOptions<TStyleProperty>) {
|
|
40
|
+
const {
|
|
41
|
+
deckglAccessorMap,
|
|
42
|
+
deckglUpdateTriggers = DEFAULT_UPDATE_TRIGGERS,
|
|
43
|
+
stateUpdateTrigger = false,
|
|
44
|
+
StylePropertyClass = StyleProperty as unknown as StylePropertyConstructor<TStyleProperty>,
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
46
|
+
getDefaultStyleValue = StyleProperty.getDefault
|
|
47
|
+
} = options;
|
|
48
|
+
|
|
49
|
+
const {type: layerType, ...restStyle} = style;
|
|
50
|
+
|
|
51
|
+
if (!layerType || !(layerType in deckglAccessorMap)) {
|
|
52
|
+
throw new Error(`illegal type: ${layerType}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.type = layerType;
|
|
56
|
+
this.deckglAccessorMap = deckglAccessorMap;
|
|
57
|
+
this.deckglUpdateTriggers = deckglUpdateTriggers;
|
|
58
|
+
this.stateUpdateTrigger = stateUpdateTrigger;
|
|
59
|
+
this.StylePropertyClass = StylePropertyClass;
|
|
60
|
+
this.getDefaultStyleValue = getDefaultStyleValue;
|
|
61
|
+
|
|
62
|
+
const rules = Object.keys(restStyle).reduce(
|
|
63
|
+
(res, key) => {
|
|
64
|
+
const isSelector = key.startsWith(':');
|
|
65
|
+
if (isSelector) {
|
|
66
|
+
const state = key.substring(1);
|
|
67
|
+
res[state] = restStyle[key];
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
res.default[key] = restStyle[key];
|
|
71
|
+
return res;
|
|
72
|
+
},
|
|
73
|
+
{default: {}} as Record<string, Record<string, unknown>>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const attributes = Object.values(rules).reduce<string[]>((res, rule) => {
|
|
77
|
+
const attrs = Object.keys(rule || {});
|
|
78
|
+
const set = new Set([...(res), ...attrs]);
|
|
79
|
+
return Array.from(set);
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const attrMap = attributes.reduce((res, attr) => {
|
|
83
|
+
res[attr] = Object.entries(rules).reduce((acc, entry) => {
|
|
84
|
+
const [state, rule] = entry;
|
|
85
|
+
if (rule && typeof (rule as any)[attr] !== 'undefined') {
|
|
86
|
+
(acc as any)[state] = (rule as any)[attr];
|
|
87
|
+
}
|
|
88
|
+
return acc;
|
|
89
|
+
}, {} as Record<string, unknown>);
|
|
90
|
+
return res;
|
|
91
|
+
}, {} as Record<string, any>);
|
|
92
|
+
|
|
93
|
+
const simplifiedStyleMap = Object.entries(attrMap).reduce((res, entry) => {
|
|
94
|
+
const [attr, valueMap] = entry as [string, Record<string, unknown>];
|
|
95
|
+
const states = Object.keys(valueMap);
|
|
96
|
+
const onlyDefault = states.length === 1 && valueMap.default !== undefined;
|
|
97
|
+
if (onlyDefault) {
|
|
98
|
+
res[attr] = valueMap.default;
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
res[attr] = valueMap;
|
|
102
|
+
return res;
|
|
103
|
+
}, {} as Record<string, unknown>);
|
|
104
|
+
|
|
105
|
+
this.properties = {} as Record<string, TStyleProperty>;
|
|
106
|
+
for (const key in simplifiedStyleMap) {
|
|
107
|
+
this.properties[key] = new this.StylePropertyClass({
|
|
108
|
+
key,
|
|
109
|
+
value: simplifiedStyleMap[key],
|
|
110
|
+
updateTrigger: this.stateUpdateTrigger
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protected getDeckGLAccessorMapForType() {
|
|
116
|
+
return this.deckglAccessorMap[this.type];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected getDeckGLUpdateTriggersForType() {
|
|
120
|
+
return this.deckglUpdateTriggers[this.type] || [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
protected _getProperty(deckglAccessor: string) {
|
|
124
|
+
const map = this.getDeckGLAccessorMapForType();
|
|
125
|
+
if (!map) {
|
|
126
|
+
throw new Error(`illegal type: ${this.type}`);
|
|
127
|
+
}
|
|
128
|
+
const styleProp = map[deckglAccessor];
|
|
129
|
+
if (!styleProp) {
|
|
130
|
+
error(`Invalid DeckGL accessor: ${deckglAccessor}`);
|
|
131
|
+
throw new Error(`Invalid DeckGL accessor: ${deckglAccessor}`);
|
|
132
|
+
}
|
|
133
|
+
return this.properties[styleProp];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getDeckGLAccessor(deckglAccessor: string) {
|
|
137
|
+
const property = this._getProperty(deckglAccessor);
|
|
138
|
+
if (property) {
|
|
139
|
+
const value = property.getValue();
|
|
140
|
+
return typeof value === 'function' ? value : () => value;
|
|
141
|
+
}
|
|
142
|
+
const styleProp = this.getDeckGLAccessorMapForType()?.[deckglAccessor];
|
|
143
|
+
return this.getDefaultStyleValue(styleProp);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getDeckGLAccessorUpdateTrigger(deckglAccessor: string) {
|
|
147
|
+
const property = this._getProperty(deckglAccessor);
|
|
148
|
+
if (property) {
|
|
149
|
+
return property.getUpdateTrigger();
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
getDeckGLAccessors() {
|
|
155
|
+
const accessorMap = this.getDeckGLAccessorMapForType();
|
|
156
|
+
return Object.keys(accessorMap).reduce((res, accessor) => {
|
|
157
|
+
res[accessor] = this.getDeckGLAccessor(accessor);
|
|
158
|
+
return res;
|
|
159
|
+
}, {} as Record<string, (...args: any[]) => unknown>);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getDeckGLUpdateTriggers() {
|
|
163
|
+
return this.getDeckGLUpdateTriggersForType().reduce((res, accessor) => {
|
|
164
|
+
res[accessor] = this.getDeckGLAccessorUpdateTrigger(accessor);
|
|
165
|
+
return res;
|
|
166
|
+
}, {} as Record<string, unknown>);
|
|
167
|
+
}
|
|
168
|
+
}
|