@antv/g6 5.0.0-beta.3 → 5.0.0-beta.4

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.
Files changed (64) hide show
  1. package/dist/g6.min.js +1 -1
  2. package/esm/constant/shape.d.ts +2 -0
  3. package/esm/index.d.ts +2 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/node.js +8 -3
  6. package/esm/item/node.js.map +1 -1
  7. package/esm/stdlib/index.d.ts +1 -0
  8. package/esm/stdlib/index.js +2 -1
  9. package/esm/stdlib/index.js.map +1 -1
  10. package/esm/stdlib/item/node/base.js +7 -14
  11. package/esm/stdlib/item/node/base.js.map +1 -1
  12. package/esm/stdlib/item/node/diamond.js +1 -1
  13. package/esm/stdlib/item/node/ellipse.js +2 -2
  14. package/esm/stdlib/item/node/hexagon.js +6 -2
  15. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  16. package/esm/stdlib/item/node/image.d.ts +40 -0
  17. package/esm/stdlib/item/node/image.js +110 -0
  18. package/esm/stdlib/item/node/image.js.map +1 -0
  19. package/esm/stdlib/item/node/index.d.ts +1 -0
  20. package/esm/stdlib/item/node/index.js +1 -0
  21. package/esm/stdlib/item/node/index.js.map +1 -1
  22. package/esm/stdlib/theme/dark.js +42 -2
  23. package/esm/stdlib/theme/dark.js.map +1 -1
  24. package/esm/stdlib/theme/light.js +4 -4
  25. package/esm/types/item.d.ts +6 -0
  26. package/esm/types/item.js.map +1 -1
  27. package/lib/constant/shape.d.ts +2 -0
  28. package/lib/index.d.ts +2 -1
  29. package/lib/index.js +1 -1
  30. package/lib/item/node.js +8 -3
  31. package/lib/item/node.js.map +1 -1
  32. package/lib/stdlib/index.d.ts +1 -0
  33. package/lib/stdlib/index.js +2 -1
  34. package/lib/stdlib/index.js.map +1 -1
  35. package/lib/stdlib/item/node/base.js +7 -14
  36. package/lib/stdlib/item/node/base.js.map +1 -1
  37. package/lib/stdlib/item/node/diamond.js +1 -1
  38. package/lib/stdlib/item/node/ellipse.js +2 -2
  39. package/lib/stdlib/item/node/hexagon.js +6 -2
  40. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  41. package/lib/stdlib/item/node/image.d.ts +40 -0
  42. package/lib/stdlib/item/node/image.js +114 -0
  43. package/lib/stdlib/item/node/image.js.map +1 -0
  44. package/lib/stdlib/item/node/index.d.ts +1 -0
  45. package/lib/stdlib/item/node/index.js +1 -0
  46. package/lib/stdlib/item/node/index.js.map +1 -1
  47. package/lib/stdlib/theme/dark.js +42 -2
  48. package/lib/stdlib/theme/dark.js.map +1 -1
  49. package/lib/stdlib/theme/light.js +4 -4
  50. package/lib/types/item.d.ts +6 -0
  51. package/lib/types/item.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/index.ts +1 -1
  54. package/src/item/node.ts +8 -3
  55. package/src/stdlib/index.ts +2 -0
  56. package/src/stdlib/item/node/base.ts +9 -15
  57. package/src/stdlib/item/node/diamond.ts +1 -1
  58. package/src/stdlib/item/node/ellipse.ts +2 -2
  59. package/src/stdlib/item/node/hexagon.ts +6 -2
  60. package/src/stdlib/item/node/image.ts +190 -0
  61. package/src/stdlib/item/node/index.ts +1 -0
  62. package/src/stdlib/theme/dark.ts +66 -2
  63. package/src/stdlib/theme/light.ts +4 -4
  64. package/src/types/item.ts +10 -0
@@ -0,0 +1,190 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { ComboDisplayModel, NodeDisplayModel } from '../../../types';
3
+ import { State } from '../../../types/item';
4
+ import {
5
+ NodeModelData,
6
+ NodeShapeMap,
7
+ NodeShapeStyles,
8
+ } from '../../../types/node';
9
+ import { convertToNumber } from '../../../util/type';
10
+ import { BaseNode } from './base';
11
+ import { ComboModelData, ComboShapeMap } from '../../../types/combo';
12
+ import { ShapeTagMap } from '../../../util/shape';
13
+
14
+ export class ImageNode extends BaseNode {
15
+ override defaultStyles = {
16
+ keyShape: {
17
+ x: 0,
18
+ y: 0,
19
+ width: 32,
20
+ height: 32,
21
+ },
22
+ };
23
+ mergedStyles: NodeShapeStyles;
24
+ constructor(props) {
25
+ super(props);
26
+ // suggest to merge default styles like this to avoid style value missing
27
+ // this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
28
+ }
29
+
30
+ public override drawKeyShape(
31
+ model: NodeDisplayModel,
32
+ shapeMap: NodeShapeMap,
33
+ diffData?: { previous: NodeModelData; current: NodeModelData },
34
+ diffState?: { previous: State[]; current: State[] },
35
+ ): DisplayObject {
36
+ const clipCfg = this.mergedStyles.keyShape?.clipCfg;
37
+ let clipPath: DisplayObject | undefined;
38
+ if (clipCfg) {
39
+ const { type, ...rest } = clipCfg;
40
+ clipPath = new ShapeTagMap[type]();
41
+ clipPath.attr(rest);
42
+ }
43
+
44
+ const shape = this.upsertShape(
45
+ 'image',
46
+ 'keyShape',
47
+ {
48
+ ...this.mergedStyles.keyShape,
49
+ x: this.mergedStyles.keyShape!.x,
50
+ y: this.mergedStyles.keyShape!.y,
51
+ anchor: '0.5 0.5',
52
+ },
53
+ shapeMap,
54
+ model,
55
+ );
56
+
57
+ if (clipPath) {
58
+ shape.appendChild(clipPath);
59
+ shape.attr('clipPath', clipPath);
60
+ }
61
+
62
+ return shape;
63
+ }
64
+
65
+ public override calculateAnchorPosition(keyShapeStyle) {
66
+ const x = convertToNumber(keyShapeStyle.x);
67
+ const y = convertToNumber(keyShapeStyle.y);
68
+ const height = keyShapeStyle.height;
69
+ const width = keyShapeStyle.width;
70
+ const anchorPositionMap = {};
71
+ anchorPositionMap['top'] = [x, y - height / 2];
72
+ anchorPositionMap['left'] = [x - width / 2, y];
73
+ anchorPositionMap['right'] = anchorPositionMap['default'] = [
74
+ x + width / 2,
75
+ y,
76
+ ];
77
+ anchorPositionMap['bottom'] = [x, y + height / 2];
78
+ return anchorPositionMap;
79
+ }
80
+
81
+ public draw(
82
+ model: NodeDisplayModel,
83
+ shapeMap: NodeShapeMap,
84
+ diffData?: { previous: NodeModelData; current: NodeModelData },
85
+ diffState?: { previous: State[]; current: State[] },
86
+ ): NodeShapeMap {
87
+ const { data = {} } = model;
88
+ let shapes: NodeShapeMap = { keyShape: undefined };
89
+
90
+ // keyShape
91
+ shapes.keyShape = this.drawKeyShape(model, shapeMap, diffData);
92
+
93
+ // labelShape
94
+ if (data.labelShape) {
95
+ shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
96
+ }
97
+
98
+ // haloShape
99
+ if (data.haloShape && this.drawHaloShape) {
100
+ shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
101
+ }
102
+
103
+ // labelBackgroundShape
104
+ if (data.labelBackgroundShape) {
105
+ shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
106
+ model,
107
+ shapeMap,
108
+ diffData,
109
+ );
110
+ }
111
+
112
+ // anchor shapes
113
+ if (data.anchorShapes) {
114
+ const anchorShapes = this.drawAnchorShapes(
115
+ model,
116
+ shapeMap,
117
+ diffData,
118
+ diffState,
119
+ );
120
+ shapes = {
121
+ ...shapes,
122
+ ...anchorShapes,
123
+ };
124
+ }
125
+
126
+ // iconShape
127
+ if (data.iconShape) {
128
+ shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
129
+ }
130
+
131
+ // badgeShape
132
+ if (data.badgeShapes) {
133
+ const badgeShapes = this.drawBadgeShapes(
134
+ model,
135
+ shapeMap,
136
+ diffData,
137
+ diffState,
138
+ );
139
+ shapes = {
140
+ ...shapes,
141
+ ...badgeShapes,
142
+ };
143
+ }
144
+
145
+ // otherShapes
146
+ if (data.otherShapes && this.drawOtherShapes) {
147
+ shapes = {
148
+ ...shapes,
149
+ ...this.drawOtherShapes(model, shapeMap, diffData),
150
+ };
151
+ }
152
+ return shapes;
153
+ }
154
+
155
+ public drawHaloShape(
156
+ model: NodeDisplayModel | ComboDisplayModel,
157
+ shapeMap: NodeShapeMap | ComboShapeMap,
158
+ diffData?: {
159
+ previous: NodeModelData | ComboModelData;
160
+ current: NodeModelData | ComboModelData;
161
+ },
162
+ diffState?: { previous: State[]; current: State[] },
163
+ ): DisplayObject {
164
+ const { keyShape } = shapeMap;
165
+ const { haloShape: haloShapeStyle, keyShape: keyShapeStyle } =
166
+ this.mergedStyles;
167
+ if (haloShapeStyle?.visible === false) return;
168
+
169
+ const clipShape = haloShapeStyle?.clipCfg?.type || 'rect';
170
+ const { attributes } = keyShape;
171
+ const { x, y, fill } = attributes;
172
+
173
+ return this.upsertShape(
174
+ clipShape,
175
+ 'haloShape',
176
+ {
177
+ ...attributes,
178
+ ...keyShapeStyle,
179
+ x,
180
+ y,
181
+ stroke: fill,
182
+ ...haloShapeStyle,
183
+ fill: 'transparent',
184
+ batchKey: 'halo',
185
+ },
186
+ shapeMap,
187
+ model,
188
+ );
189
+ }
190
+ }
@@ -8,3 +8,4 @@ export * from './ellipse';
8
8
  export * from './donut';
9
9
  export * from './diamond';
10
10
  export * from './modelRect';
11
+ export * from './image';
@@ -7,6 +7,7 @@ const textColor = 'rgba(255,255,255,0.85)';
7
7
  const nodeColor = 'rgb(34,126,255)';
8
8
  const edgeColor = 'rgb(153, 173, 209)';
9
9
  const comboFill = 'rgb(253, 253, 253)';
10
+ const comboStroke = 'rgba(153,173,209,1)';
10
11
  const disabledFill = '#D0E4FF';
11
12
 
12
13
  const edgeMainStroke = '#637088';
@@ -105,7 +106,7 @@ export const DarkTheme = {
105
106
  },
106
107
  haloShape: {
107
108
  opacity: 0.45,
108
- lineWidth: 20,
109
+ lineWidth: 12,
109
110
  zIndex: -1,
110
111
  pointerEvents: 'none',
111
112
  visible: true,
@@ -118,7 +119,7 @@ export const DarkTheme = {
118
119
  },
119
120
  haloShape: {
120
121
  opacity: 0.25,
121
- lineWidth: 20,
122
+ lineWidth: 12,
122
123
  zIndex: -1,
123
124
  pointerEvents: 'none',
124
125
  visible: true,
@@ -301,6 +302,23 @@ export const DarkTheme = {
301
302
  height: 10,
302
303
  padding: [25, 20, 15, 20],
303
304
  },
305
+ labelShape: {
306
+ ...DEFAULT_TEXT_STYLE,
307
+ fill: textColor,
308
+ opacity: 0.85,
309
+ position: 'bottom',
310
+ zIndex: 2,
311
+ lod: 0,
312
+ maxLines: 1,
313
+ },
314
+ labelBackgroundShape: {
315
+ padding: [2, 4, 2, 4],
316
+ lineWidth: 0,
317
+ fill: '#000',
318
+ opacity: 0.75,
319
+ zIndex: 1,
320
+ lod: 0,
321
+ },
304
322
  },
305
323
  selected: {
306
324
  keyShape: {
@@ -311,12 +329,30 @@ export const DarkTheme = {
311
329
  labelShape: {
312
330
  fontWeight: 700,
313
331
  },
332
+ haloShape: {
333
+ opacity: 0.25,
334
+ lineWidth: 12,
335
+ pointerEvents: 'none',
336
+ zIndex: -1,
337
+ visible: true,
338
+ stroke: comboStroke,
339
+ droppable: false,
340
+ },
314
341
  },
315
342
  active: {
316
343
  keyShape: {
317
344
  stroke: nodeStroke,
318
345
  lineWidth: 1,
319
346
  },
347
+ haloShape: {
348
+ opacity: 0.25,
349
+ lineWidth: 12,
350
+ pointerEvents: 'none',
351
+ zIndex: -1,
352
+ visible: true,
353
+ stroke: comboStroke,
354
+ droppable: false,
355
+ },
320
356
  },
321
357
  highlight: {
322
358
  keyShape: {
@@ -334,6 +370,9 @@ export const DarkTheme = {
334
370
  fill: comboFill,
335
371
  lineWidth: 1,
336
372
  },
373
+ labelShape: {
374
+ opacity: 0.65,
375
+ },
337
376
  },
338
377
  disable: {
339
378
  keyShape: {
@@ -344,6 +383,31 @@ export const DarkTheme = {
344
383
  fill: disabledFill,
345
384
  opacity: 0.25,
346
385
  },
386
+ labelShape: {
387
+ opacity: 0.25,
388
+ },
389
+ },
390
+ collapsed: {
391
+ keyShape: {
392
+ ...DEFAULT_SHAPE_STYLE,
393
+ fill: comboFill,
394
+ lineWidth: 1,
395
+ stroke: comboStroke,
396
+ // the collapsed size
397
+ r: 16,
398
+ width: 48,
399
+ height: 24,
400
+ padding: [25, 20, 15, 20],
401
+ },
402
+ iconShape: {
403
+ ...DEFAULT_TEXT_STYLE,
404
+ fill: comboStroke,
405
+ fontSize: 12,
406
+ zIndex: 1,
407
+ lod: -1,
408
+ contentType: 'childCount',
409
+ visible: true,
410
+ },
347
411
  },
348
412
  },
349
413
  ],
@@ -108,7 +108,7 @@ export const LightTheme = {
108
108
  },
109
109
  haloShape: {
110
110
  opacity: 0.25,
111
- lineWidth: 20,
111
+ lineWidth: 12,
112
112
  pointerEvents: 'none',
113
113
  zIndex: -1,
114
114
  visible: true,
@@ -121,7 +121,7 @@ export const LightTheme = {
121
121
  },
122
122
  haloShape: {
123
123
  opacity: 0.25,
124
- lineWidth: 20,
124
+ lineWidth: 12,
125
125
  pointerEvents: 'none',
126
126
  zIndex: -1,
127
127
  visible: true,
@@ -328,7 +328,7 @@ export const LightTheme = {
328
328
  },
329
329
  haloShape: {
330
330
  opacity: 0.25,
331
- lineWidth: 20,
331
+ lineWidth: 12,
332
332
  pointerEvents: 'none',
333
333
  zIndex: -1,
334
334
  visible: true,
@@ -343,7 +343,7 @@ export const LightTheme = {
343
343
  },
344
344
  haloShape: {
345
345
  opacity: 0.25,
346
- lineWidth: 20,
346
+ lineWidth: 12,
347
347
  pointerEvents: 'none',
348
348
  zIndex: -1,
349
349
  visible: true,
package/src/types/item.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  Group,
14
14
  DisplayObject,
15
15
  IAnimation,
16
+ Shape,
16
17
  } from '@antv/g';
17
18
  import {
18
19
  CubeGeometryProps,
@@ -61,11 +62,20 @@ export type GShapeStyle = CircleStyleProps &
61
62
  interactive?: boolean;
62
63
  };
63
64
 
65
+ export type ClipCfg = {
66
+ type: SHAPE_TYPE;
67
+ show: boolean;
68
+ } & CircleStyleProps &
69
+ RectStyleProps &
70
+ EllipseStyleProps;
71
+
64
72
  export type ShapeStyle = Partial<
65
73
  GShapeStyle & {
66
74
  animates?: IAnimates;
67
75
  lod?: number;
68
76
  visible?: boolean;
77
+ } & {
78
+ clipCfg?: ClipCfg;
69
79
  }
70
80
  >;
71
81
  export interface Encode<T> {