@deck.gl-community/graph-layers 9.2.0-beta.6 → 9.2.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/graph-engine.d.ts +3 -2
- package/dist/core/graph-engine.d.ts.map +1 -1
- package/dist/core/graph-engine.js +1 -0
- package/dist/core/graph-engine.js.map +1 -1
- package/dist/graph-style-schema.cdn.js +1 -1
- package/dist/graph-style-schema.json +1 -1
- package/dist/index.cjs +307 -202
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layers/edge-attachment-helper.d.ts.map +1 -1
- package/dist/layers/edge-attachment-helper.js.map +1 -1
- package/dist/layers/graph-layer.d.ts +4 -3
- package/dist/layers/graph-layer.d.ts.map +1 -1
- package/dist/layers/graph-layer.js +11 -6
- package/dist/layers/graph-layer.js.map +1 -1
- package/dist/loaders/dot-graph-loader.js +1 -1
- package/dist/loaders/json-graph-loader.js +1 -1
- package/dist/style/graph-layer-stylesheet.d.ts +14 -5
- package/dist/style/graph-layer-stylesheet.d.ts.map +1 -1
- package/dist/style/graph-layer-stylesheet.js +9 -3
- package/dist/style/graph-layer-stylesheet.js.map +1 -1
- package/dist/style/graph-style-engine.d.ts +4 -4
- package/dist/style/graph-style-engine.d.ts.map +1 -1
- package/dist/style/graph-style-engine.js +4 -4
- package/dist/style/graph-style-engine.js.map +1 -1
- package/dist/style/graph-stylesheet-schema.d.ts +13211 -0
- package/dist/style/graph-stylesheet-schema.d.ts.map +1 -0
- package/dist/style/graph-stylesheet-schema.js +354 -0
- package/dist/style/graph-stylesheet-schema.js.map +1 -0
- package/package.json +2 -2
- package/src/core/graph-engine.ts +7 -2
- package/src/index.ts +2 -1
- package/src/layers/edge-attachment-helper.ts +2 -5
- package/src/layers/graph-layer.ts +25 -19
- package/src/style/graph-layer-stylesheet.ts +16 -9
- package/src/style/graph-style-engine.ts +21 -13
- package/src/style/graph-stylesheet-schema.ts +538 -0
- package/dist/style/graph-stylesheet.schema.d.ts +0 -311
- package/dist/style/graph-stylesheet.schema.d.ts.map +0 -1
- package/dist/style/graph-stylesheet.schema.js +0 -238
- package/dist/style/graph-stylesheet.schema.js.map +0 -1
- package/src/style/graph-stylesheet.schema.ts +0 -344
|
@@ -1,344 +0,0 @@
|
|
|
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>;
|