@deck.gl-community/graph-layers 9.2.0-beta.5 → 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
|
@@ -15,15 +15,15 @@ import {GraphEngine} from '../core/graph-engine';
|
|
|
15
15
|
|
|
16
16
|
import {
|
|
17
17
|
GraphStylesheetEngine,
|
|
18
|
-
type GraphStylesheet
|
|
18
|
+
type GraphStylesheet,
|
|
19
|
+
type GraphStyleRule
|
|
19
20
|
} from '../style/graph-style-engine';
|
|
20
21
|
|
|
21
22
|
import {
|
|
22
|
-
|
|
23
|
+
DEFAULT_GRAPH_LAYER_STYLESHEET_INPUT,
|
|
23
24
|
normalizeGraphLayerStylesheet,
|
|
24
25
|
type GraphLayerEdgeStyle,
|
|
25
26
|
type GraphLayerNodeStyle,
|
|
26
|
-
type GraphLayerStylesheet,
|
|
27
27
|
type NormalizedGraphLayerStylesheet
|
|
28
28
|
} from '../style/graph-layer-stylesheet';
|
|
29
29
|
|
|
@@ -44,8 +44,6 @@ import {EdgeArrowLayer} from './edge-layers/edge-arrow-layer';
|
|
|
44
44
|
import {EdgeAttachmentHelper} from './edge-attachment-helper';
|
|
45
45
|
import {GridLayer, type GridLayerProps} from './common-layers/grid-layer/grid-layer';
|
|
46
46
|
|
|
47
|
-
import {JSONGraphLoader} from '../loaders/json-graph-loader';
|
|
48
|
-
|
|
49
47
|
import {mixedGetPosition} from '../utils/layer-utils';
|
|
50
48
|
import {InteractionManager} from '../core/interaction-manager';
|
|
51
49
|
import {buildCollapsedChainLayers} from '../utils/collapsed-chains';
|
|
@@ -55,6 +53,7 @@ import {
|
|
|
55
53
|
type LabelAccessor,
|
|
56
54
|
type RankAccessor
|
|
57
55
|
} from '../utils/rank-grid';
|
|
56
|
+
import {createGraphFromData} from '../graph/functions/create-graph-from-data';
|
|
58
57
|
|
|
59
58
|
import {warn} from '../utils/log';
|
|
60
59
|
|
|
@@ -106,6 +105,13 @@ let NODE_STYLE_DEPRECATION_WARNED = false;
|
|
|
106
105
|
let EDGE_STYLE_DEPRECATION_WARNED = false;
|
|
107
106
|
let GRAPH_PROP_DEPRECATION_WARNED = false;
|
|
108
107
|
let LAYOUT_REQUIRED_WARNED = false;
|
|
108
|
+
const DEFAULT_GRAPH_LOADER = ({json}: {json: unknown}) => {
|
|
109
|
+
if (!json || typeof json !== 'object') {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return createGraphFromData(json as any);
|
|
114
|
+
};
|
|
109
115
|
|
|
110
116
|
export type GraphLayerRawData = {
|
|
111
117
|
name?: string;
|
|
@@ -146,7 +152,7 @@ export type _GraphLayerProps = {
|
|
|
146
152
|
onLayoutDone?: (detail?: GraphLayoutEventDetail) => void;
|
|
147
153
|
onLayoutError?: (error?: unknown) => void;
|
|
148
154
|
|
|
149
|
-
stylesheet?:
|
|
155
|
+
stylesheet?: GraphStylesheet;
|
|
150
156
|
/** @deprecated Use `stylesheet.nodes`. */
|
|
151
157
|
nodeStyle?: GraphLayerNodeStyle[];
|
|
152
158
|
/** @deprecated Use `stylesheet.edges`. */
|
|
@@ -171,18 +177,18 @@ export type _GraphLayerProps = {
|
|
|
171
177
|
export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
172
178
|
static layerName = 'GraphLayer';
|
|
173
179
|
|
|
174
|
-
static defaultProps:
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
static defaultProps: _GraphLayerProps &
|
|
181
|
+
Pick<CompositeLayerProps, 'pickable'> & {
|
|
182
|
+
data: {type: string; value: null; async: true};
|
|
183
|
+
} = {
|
|
177
184
|
// Composite layer props
|
|
178
|
-
// @ts-expect-error composite layer props
|
|
179
185
|
pickable: true,
|
|
180
186
|
data: {type: 'object', value: null, async: true},
|
|
181
187
|
|
|
182
188
|
// Graph props
|
|
183
|
-
graphLoader:
|
|
189
|
+
graphLoader: DEFAULT_GRAPH_LOADER,
|
|
184
190
|
|
|
185
|
-
stylesheet:
|
|
191
|
+
stylesheet: DEFAULT_GRAPH_LAYER_STYLESHEET_INPUT,
|
|
186
192
|
nodeStyle: undefined as unknown as GraphLayerNodeStyle[],
|
|
187
193
|
nodeEvents: {
|
|
188
194
|
onMouseLeave: () => {},
|
|
@@ -316,7 +322,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
316
322
|
}
|
|
317
323
|
|
|
318
324
|
private _createStylesheetEngine(
|
|
319
|
-
style:
|
|
325
|
+
style: GraphStyleRule,
|
|
320
326
|
context: string
|
|
321
327
|
): GraphStylesheetEngine | null {
|
|
322
328
|
try {
|
|
@@ -485,7 +491,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
485
491
|
}
|
|
486
492
|
|
|
487
493
|
if (Array.isArray(data) || isPlainObject(data)) {
|
|
488
|
-
const loader = props.graphLoader ??
|
|
494
|
+
const loader = props.graphLoader ?? DEFAULT_GRAPH_LOADER;
|
|
489
495
|
const graph = loader({json: data});
|
|
490
496
|
if (!graph) {
|
|
491
497
|
return null;
|
|
@@ -821,7 +827,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
821
827
|
return null;
|
|
822
828
|
}
|
|
823
829
|
const stylesheet = this._createStylesheetEngine(
|
|
824
|
-
restStyle as unknown as
|
|
830
|
+
restStyle as unknown as GraphStyleRule,
|
|
825
831
|
`node stylesheet "${style.type}"`
|
|
826
832
|
);
|
|
827
833
|
if (!stylesheet) {
|
|
@@ -878,7 +884,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
878
884
|
{
|
|
879
885
|
type: 'edge',
|
|
880
886
|
...restEdgeStyle
|
|
881
|
-
} as
|
|
887
|
+
} as GraphStyleRule,
|
|
882
888
|
'edge stylesheet'
|
|
883
889
|
);
|
|
884
890
|
if (!stylesheet) {
|
|
@@ -910,7 +916,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
910
916
|
return null;
|
|
911
917
|
}
|
|
912
918
|
const decoratorStylesheet = this._createStylesheetEngine(
|
|
913
|
-
decoratorStyle as unknown as
|
|
919
|
+
decoratorStyle as unknown as GraphStyleRule,
|
|
914
920
|
`edge decorator stylesheet "${decoratorStyle.type}"`
|
|
915
921
|
);
|
|
916
922
|
if (!decoratorStylesheet) {
|
|
@@ -1018,7 +1024,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
1018
1024
|
marker: 'circle-plus-filled',
|
|
1019
1025
|
offset: [24, -24],
|
|
1020
1026
|
scaleWithZoom: false
|
|
1021
|
-
} as
|
|
1027
|
+
} as GraphStyleRule,
|
|
1022
1028
|
'collapsed chain marker stylesheet'
|
|
1023
1029
|
);
|
|
1024
1030
|
|
|
@@ -1071,7 +1077,7 @@ export class GraphLayer extends CompositeLayer<GraphLayerProps> {
|
|
|
1071
1077
|
marker: 'circle-minus-filled',
|
|
1072
1078
|
offset: [24, -24],
|
|
1073
1079
|
scaleWithZoom: false
|
|
1074
|
-
} as
|
|
1080
|
+
} as GraphStyleRule,
|
|
1075
1081
|
'expanded chain marker stylesheet'
|
|
1076
1082
|
);
|
|
1077
1083
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {GraphStylesheet, GraphStyleType} from './graph-style-engine';
|
|
5
|
+
import type {GraphStylesheet, GraphStyleRule, GraphStyleType} from './graph-style-engine';
|
|
6
6
|
|
|
7
7
|
export type GraphNodeStyleType = Exclude<
|
|
8
8
|
GraphStyleType,
|
|
@@ -11,26 +11,26 @@ export type GraphNodeStyleType = Exclude<
|
|
|
11
11
|
|
|
12
12
|
export type GraphEdgeDecoratorType = Extract<GraphStyleType, 'edge-label' | 'flow' | 'arrow'>;
|
|
13
13
|
|
|
14
|
-
export type GraphLayerNodeStyle =
|
|
14
|
+
export type GraphLayerNodeStyle = Extract<GraphStyleRule, {type: GraphNodeStyleType}> & {
|
|
15
15
|
pickable?: boolean;
|
|
16
16
|
visible?: boolean;
|
|
17
17
|
data?: (nodes: any[]) => any;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type GraphLayerEdgeDecoratorStyle =
|
|
20
|
+
export type GraphLayerEdgeDecoratorStyle = Extract<GraphStyleRule, {type: GraphEdgeDecoratorType}>;
|
|
21
21
|
|
|
22
22
|
type EdgeStyleType = Extract<GraphStyleType, 'Edge' | 'edge'>;
|
|
23
23
|
|
|
24
24
|
export type GraphLayerEdgeStyle = (
|
|
25
|
-
|
|
|
26
|
-
| (Omit<
|
|
25
|
+
| Extract<GraphStyleRule, {type: EdgeStyleType}>
|
|
26
|
+
| (Omit<Extract<GraphStyleRule, {type: EdgeStyleType}>, 'type'> & {type?: EdgeStyleType})
|
|
27
27
|
) & {
|
|
28
28
|
decorators?: GraphLayerEdgeDecoratorStyle[];
|
|
29
29
|
data?: (edges: any[]) => any;
|
|
30
30
|
visible?: boolean;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export type GraphLayerStylesheet = {
|
|
33
|
+
export type GraphLayerStylesheet = GraphStylesheet & {
|
|
34
34
|
nodes?: GraphLayerNodeStyle[];
|
|
35
35
|
edges?: GraphLayerEdgeStyle | GraphLayerEdgeStyle[];
|
|
36
36
|
};
|
|
@@ -42,10 +42,17 @@ export type NormalizedGraphLayerStylesheet = {
|
|
|
42
42
|
edges: GraphLayerEdgeStyle[];
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
export const DEFAULT_GRAPH_LAYER_STYLESHEET_INPUT: GraphLayerStylesheet = {
|
|
46
|
+
nodes: [],
|
|
47
|
+
edges: [{
|
|
48
|
+
type: 'edge',
|
|
49
|
+
stroke: 'black',
|
|
50
|
+
strokeWidth: 1
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
|
|
45
54
|
const DEFAULT_EDGE_STYLE: GraphLayerEdgeStyle = {
|
|
46
|
-
|
|
47
|
-
stroke: 'black',
|
|
48
|
-
strokeWidth: 1,
|
|
55
|
+
...DEFAULT_GRAPH_LAYER_STYLESHEET_INPUT.edges[0],
|
|
49
56
|
decorators: []
|
|
50
57
|
};
|
|
51
58
|
|
|
@@ -8,10 +8,10 @@ import {ZodError, type ZodIssue} from 'zod';
|
|
|
8
8
|
|
|
9
9
|
import {StylesheetEngine, type DeckGLUpdateTriggers} from './stylesheet-engine';
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
} from './graph-stylesheet
|
|
11
|
+
GraphStyleRuleSchema,
|
|
12
|
+
type GraphStyleRule,
|
|
13
|
+
type GraphStyleRuleParsed
|
|
14
|
+
} from './graph-stylesheet-schema';
|
|
15
15
|
import {GRAPH_DECKGL_ACCESSOR_MAP} from './graph-style-accessor-map';
|
|
16
16
|
import {warn} from '../utils/log';
|
|
17
17
|
|
|
@@ -40,13 +40,16 @@ function formatStylesheetError(error: ZodError) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export class GraphStylesheetEngine extends StylesheetEngine {
|
|
43
|
-
constructor(
|
|
44
|
-
|
|
43
|
+
constructor(
|
|
44
|
+
style: GraphStyleRule | GraphStyleRuleParsed,
|
|
45
|
+
{stateUpdateTrigger}: {stateUpdateTrigger?: unknown} = {}
|
|
46
|
+
) {
|
|
47
|
+
const result = GraphStyleRuleSchema.safeParse(style);
|
|
45
48
|
const parsedStyle = result.success
|
|
46
49
|
? result.data
|
|
47
50
|
: sanitizeStylesheet(style, result.error.issues);
|
|
48
51
|
|
|
49
|
-
super(parsedStyle as
|
|
52
|
+
super(parsedStyle as GraphStyleRule, {
|
|
50
53
|
deckglAccessorMap: GRAPH_DECKGL_ACCESSOR_MAP,
|
|
51
54
|
deckglUpdateTriggers: GRAPH_DECKGL_UPDATE_TRIGGERS,
|
|
52
55
|
stateUpdateTrigger
|
|
@@ -64,12 +67,14 @@ export {
|
|
|
64
67
|
GraphStyleLeafValueSchema,
|
|
65
68
|
GraphStyleStateMapSchema,
|
|
66
69
|
GraphStyleValueSchema,
|
|
67
|
-
GraphStylesheetSchema
|
|
68
|
-
|
|
70
|
+
GraphStylesheetSchema,
|
|
71
|
+
GraphStyleRuleSchema
|
|
72
|
+
} from './graph-stylesheet-schema';
|
|
69
73
|
|
|
70
74
|
export type {
|
|
71
75
|
GraphStylesheet,
|
|
72
|
-
|
|
76
|
+
GraphStyleRule,
|
|
77
|
+
GraphStyleRuleParsed,
|
|
73
78
|
GraphStylesheetParsed,
|
|
74
79
|
GraphStyleSelector,
|
|
75
80
|
GraphStyleType,
|
|
@@ -78,12 +83,15 @@ export type {
|
|
|
78
83
|
GraphStyleScale,
|
|
79
84
|
GraphStyleScaleType,
|
|
80
85
|
GraphStyleValue
|
|
81
|
-
} from './graph-stylesheet
|
|
86
|
+
} from './graph-stylesheet-schema';
|
|
82
87
|
|
|
83
88
|
export {GRAPH_DECKGL_ACCESSOR_MAP} from './graph-style-accessor-map';
|
|
84
89
|
|
|
85
90
|
// eslint-disable-next-line max-statements, complexity
|
|
86
|
-
function sanitizeStylesheet(
|
|
91
|
+
function sanitizeStylesheet(
|
|
92
|
+
style: GraphStyleRule | GraphStyleRuleParsed,
|
|
93
|
+
issues: ZodIssue[]
|
|
94
|
+
): GraphStyleRuleParsed {
|
|
87
95
|
if (issues.length) {
|
|
88
96
|
const details = issues
|
|
89
97
|
.map((issue) => {
|
|
@@ -139,7 +147,7 @@ function sanitizeStylesheet(style: GraphStylesheet, issues: ZodIssue[]): GraphSt
|
|
|
139
147
|
delete sanitized[rootKey];
|
|
140
148
|
}
|
|
141
149
|
|
|
142
|
-
const result =
|
|
150
|
+
const result = GraphStyleRuleSchema.safeParse(sanitized);
|
|
143
151
|
if (result.success) {
|
|
144
152
|
return result.data;
|
|
145
153
|
}
|