@antv/g6 5.0.0-beta.5 → 5.0.0-beta.6

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 (147) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +13 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.d.ts +1 -1
  5. package/esm/item/combo.js +16 -9
  6. package/esm/item/combo.js.map +1 -1
  7. package/esm/item/edge.d.ts +1 -1
  8. package/esm/item/edge.js +15 -7
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/node.d.ts +1 -1
  11. package/esm/item/node.js +16 -9
  12. package/esm/item/node.js.map +1 -1
  13. package/esm/runtime/controller/item.d.ts +1 -0
  14. package/esm/runtime/controller/item.js +19 -3
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +82 -4
  17. package/esm/runtime/graph.js +361 -47
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/brush-select.js +1 -2
  20. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  21. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  22. package/esm/stdlib/behavior/create-edge.js +206 -0
  23. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  24. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
  25. package/esm/stdlib/behavior/drag-canvas.js +7 -7
  26. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  27. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  28. package/esm/stdlib/behavior/drag-combo.js +35 -24
  29. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  30. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  31. package/esm/stdlib/behavior/drag-node.js +70 -57
  32. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  33. package/esm/stdlib/behavior/index.d.ts +2 -0
  34. package/esm/stdlib/behavior/index.js +2 -0
  35. package/esm/stdlib/behavior/index.js.map +1 -1
  36. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  37. package/esm/stdlib/behavior/lasso-select.js +1 -2
  38. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  39. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  40. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  41. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  42. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -1
  43. package/esm/stdlib/behavior/zoom-canvas.js +7 -7
  44. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  45. package/esm/stdlib/index.d.ts +4 -0
  46. package/esm/stdlib/index.js +5 -1
  47. package/esm/stdlib/index.js.map +1 -1
  48. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  49. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  50. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  51. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  52. package/esm/stdlib/plugin/minimap/index.js +109 -8
  53. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  54. package/esm/types/graph.d.ts +31 -5
  55. package/esm/types/hook.d.ts +16 -2
  56. package/esm/types/spec.d.ts +6 -3
  57. package/esm/util/item.d.ts +16 -1
  58. package/esm/util/item.js +31 -8
  59. package/esm/util/item.js.map +1 -1
  60. package/esm/util/warn.d.ts +14 -0
  61. package/esm/util/warn.js +4 -0
  62. package/esm/util/warn.js.map +1 -0
  63. package/lib/index.d.ts +13 -1
  64. package/lib/index.js +1 -1
  65. package/lib/item/combo.d.ts +1 -1
  66. package/lib/item/combo.js +16 -9
  67. package/lib/item/combo.js.map +1 -1
  68. package/lib/item/edge.d.ts +1 -1
  69. package/lib/item/edge.js +15 -7
  70. package/lib/item/edge.js.map +1 -1
  71. package/lib/item/node.d.ts +1 -1
  72. package/lib/item/node.js +16 -9
  73. package/lib/item/node.js.map +1 -1
  74. package/lib/runtime/controller/item.d.ts +1 -0
  75. package/lib/runtime/controller/item.js +19 -3
  76. package/lib/runtime/controller/item.js.map +1 -1
  77. package/lib/runtime/graph.d.ts +82 -4
  78. package/lib/runtime/graph.js +361 -47
  79. package/lib/runtime/graph.js.map +1 -1
  80. package/lib/stdlib/behavior/brush-select.js +1 -2
  81. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  82. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  83. package/lib/stdlib/behavior/create-edge.js +210 -0
  84. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  85. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
  86. package/lib/stdlib/behavior/drag-canvas.js +7 -7
  87. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  88. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  89. package/lib/stdlib/behavior/drag-combo.js +35 -24
  90. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  91. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  92. package/lib/stdlib/behavior/drag-node.js +70 -57
  93. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  94. package/lib/stdlib/behavior/index.d.ts +2 -0
  95. package/lib/stdlib/behavior/index.js +2 -0
  96. package/lib/stdlib/behavior/index.js.map +1 -1
  97. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  98. package/lib/stdlib/behavior/lasso-select.js +1 -2
  99. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  100. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  101. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  102. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  103. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -1
  104. package/lib/stdlib/behavior/zoom-canvas.js +7 -7
  105. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  106. package/lib/stdlib/index.d.ts +4 -0
  107. package/lib/stdlib/index.js +5 -1
  108. package/lib/stdlib/index.js.map +1 -1
  109. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  110. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  111. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  112. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  113. package/lib/stdlib/plugin/minimap/index.js +109 -8
  114. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  115. package/lib/types/graph.d.ts +31 -5
  116. package/lib/types/hook.d.ts +16 -2
  117. package/lib/types/spec.d.ts +6 -3
  118. package/lib/util/item.d.ts +16 -1
  119. package/lib/util/item.js +33 -9
  120. package/lib/util/item.js.map +1 -1
  121. package/lib/util/warn.d.ts +14 -0
  122. package/lib/util/warn.js +8 -0
  123. package/lib/util/warn.js.map +1 -0
  124. package/package.json +1 -1
  125. package/src/index.ts +1 -1
  126. package/src/item/combo.ts +14 -9
  127. package/src/item/edge.ts +13 -7
  128. package/src/item/node.ts +14 -9
  129. package/src/runtime/controller/item.ts +28 -6
  130. package/src/runtime/graph.ts +445 -51
  131. package/src/stdlib/behavior/brush-select.ts +4 -2
  132. package/src/stdlib/behavior/create-edge.ts +295 -0
  133. package/src/stdlib/behavior/drag-canvas.ts +8 -8
  134. package/src/stdlib/behavior/drag-combo.ts +2 -2
  135. package/src/stdlib/behavior/drag-node.ts +8 -8
  136. package/src/stdlib/behavior/index.ts +2 -0
  137. package/src/stdlib/behavior/lasso-select.ts +5 -3
  138. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  139. package/src/stdlib/behavior/zoom-canvas.ts +8 -8
  140. package/src/stdlib/index.ts +6 -0
  141. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  142. package/src/stdlib/plugin/minimap/index.ts +113 -9
  143. package/src/types/graph.ts +31 -5
  144. package/src/types/hook.ts +16 -2
  145. package/src/types/spec.ts +9 -3
  146. package/src/util/item.ts +65 -28
  147. package/src/util/warn.ts +20 -0
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from '@antv/event-emitter';
2
- import { AABB, Canvas, DisplayObject, PointLike } from '@antv/g';
2
+ import { AABB, Canvas, DataURLType, DisplayObject, PointLike, Cursor } from '@antv/g';
3
3
  import { ID } from '@antv/graphlib';
4
4
  import { Command } from '../stdlib/plugin/history/command';
5
5
  import type { ComboUserModel, EdgeUserModel, IGraph, NodeUserModel, Specification } from '../types';
@@ -18,6 +18,7 @@ import type { RendererName } from '../types/render';
18
18
  import type { ThemeOptionsOf, ThemeRegistry } from '../types/theme';
19
19
  import { FitViewRules, GraphTransformOptions } from '../types/view';
20
20
  import { Plugin as PluginBase } from '../types/plugin';
21
+ import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
21
22
  export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry> extends EventEmitter implements IGraph<B, T> {
22
23
  hooks: Hooks;
23
24
  canvas: Canvas;
@@ -63,6 +64,12 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
63
64
  * Update the theme specs (configurations).
64
65
  */
65
66
  updateTheme(theme: ThemeOptionsOf<T>): void;
67
+ /**
68
+ * Update the item display mapper for a specific item type.
69
+ * @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
70
+ * @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
71
+ * */
72
+ updateMapper(type: ITEM_TYPE, mapper: NodeMapper | EdgeMapper | ComboMapper): void;
66
73
  /**
67
74
  * Get the copy of specs(configurations).
68
75
  * @returns graph specs
@@ -469,6 +476,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
469
476
  * @group Interaction
470
477
  */
471
478
  getMode(): string;
479
+ /**
480
+ * Set the cursor. But the cursor in item's style has higher priority.
481
+ * @param cursor
482
+ */
483
+ setCursor(cursor: Cursor): void;
472
484
  /**
473
485
  * Add behavior(s) to mode(s).
474
486
  * @param behaviors behavior names or configs
@@ -530,11 +542,77 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
530
542
  * @group Interaction
531
543
  */
532
544
  drawTransient(type: ITEM_TYPE | SHAPE_TYPE, id: ID, config: {
533
- action: 'remove' | 'add' | 'update' | undefined;
534
- style: ShapeStyle;
535
- onlyDrawKeyShape?: boolean;
545
+ action?: 'remove' | 'add' | 'update' | undefined;
546
+ /** Data to be merged into the transient item. */
547
+ data?: Record<string, any>;
548
+ /** Style to be merged into the transient shape. */
549
+ style?: ShapeStyle;
550
+ /** For type: 'edge' */
551
+ drawSource?: boolean;
552
+ /** For type: 'edge' */
553
+ drawTarget?: boolean;
554
+ /** Only shape with id in shapeIds will be cloned while type is ITEM_TYPE. If shapeIds is not assigned, the whole item will be cloned. */
555
+ shapeIds?: string[];
556
+ /** Whether show the shapes in shapeIds. True by default. */
557
+ visible?: boolean;
536
558
  upsertAncestors?: boolean;
537
559
  }, canvas?: Canvas): DisplayObject;
560
+ /**
561
+ * Asynchronously generates a Data URL representation of the canvas content, including
562
+ * background, main content, and transient canvas.
563
+ * @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
564
+ * @returns A Promise that resolves to the Data URL string.
565
+ */
566
+ toDataURL(type?: DataURLType): Promise<string>;
567
+ /**
568
+ * Asynchronously generates a Data URL representation of the full canvas content,
569
+ * including background, main content, and transient canvas, with optional padding.
570
+ * @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
571
+ * @param imageConfig Configuration options for the image (optional).
572
+ * @returns A Promise that resolves to the Data URL string.
573
+ */
574
+ toFullDataURL(type?: DataURLType, imageConfig?: {
575
+ padding?: number | number[];
576
+ }): Promise<string>;
577
+ /**
578
+ * Converts a Data URL to an image file and handles the download of the image.
579
+ * @param dataURL The Data URL of the image to be converted and downloaded.
580
+ * @param renderer The renderer type ('svg' or other) used for the canvas.
581
+ * @param link The HTML link element used for image download.
582
+ * @param fileName The desired name for the downloaded image file.
583
+ */
584
+ private dataURLToImage;
585
+ /**
586
+ * Initiates the download of the graph as an image with an optional name and type.
587
+ * @param name The desired name for the downloaded image file (optional).
588
+ * @param type The type of the image to download (optional, defaults to 'image/png').
589
+ */
590
+ downloadImage(name?: string, type?: DataURLType): void;
591
+ /**
592
+ * Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
593
+ * @param name The desired name for the downloaded image file (optional).
594
+ * @param type The type of the image to download (optional, defaults to 'image/png').
595
+ * @param imageConfig Configuration options for the image (optional).
596
+ */
597
+ downloadFullImage(name?: string, type?: DataURLType, imageConfig?: {
598
+ padding?: number | number[];
599
+ }): void;
600
+ /**
601
+ * Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
602
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
603
+ * @param callback A callback function to handle the Data URL (optional).
604
+ */
605
+ protected asyncToDataUrl(type?: DataURLType, callback?: Function): void;
606
+ /**
607
+ * Asynchronously converts the entire canvas content to a Data URL of the specified type
608
+ * with optional padding, and invokes the provided callback.
609
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
610
+ * @param imageConfig Configuration options for the image (optional).
611
+ * @param callback A callback function to handle the Data URL (optional).
612
+ */
613
+ protected asyncToFullDataUrl(type?: DataURLType, imageConfig?: {
614
+ padding?: number | number[];
615
+ }, callback?: (dataUrl: string) => void): void;
538
616
  /**
539
617
  * Determine if history (redo/undo) is enabled.
540
618
  */
@@ -24,7 +24,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const event_emitter_1 = __importDefault(require("@antv/event-emitter"));
27
+ const g_1 = require("@antv/g");
27
28
  const util_1 = require("@antv/util");
29
+ const dom_util_1 = require("@antv/dom-util");
28
30
  const canvas_1 = require("../util/canvas");
29
31
  const shape_1 = require("../util/shape");
30
32
  const controller_1 = require("./controller");
@@ -198,7 +200,8 @@ class Graph extends event_emitter_1.default {
198
200
  }),
199
201
  transientupdate: new hooks_1.default({ name: 'transientupdate' }),
200
202
  pluginchange: new hooks_1.default({ name: 'pluginchange' }),
201
- themechange: new hooks_1.default({ name: 'init' }),
203
+ themechange: new hooks_1.default({ name: 'themechange' }),
204
+ mapperchange: new hooks_1.default({ name: 'mapperchange' }),
202
205
  treecollapseexpand: new hooks_1.default({ name: 'treecollapseexpand' }),
203
206
  destroy: new hooks_1.default({ name: 'destroy' }),
204
207
  };
@@ -233,6 +236,28 @@ class Graph extends event_emitter_1.default {
233
236
  theme: this.themeController.specification,
234
237
  });
235
238
  }
239
+ /**
240
+ * Update the item display mapper for a specific item type.
241
+ * @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
242
+ * @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
243
+ * */
244
+ updateMapper(type, mapper) {
245
+ switch (type) {
246
+ case 'node':
247
+ this.specification.node = mapper;
248
+ break;
249
+ case 'edge':
250
+ this.specification.edge = mapper;
251
+ break;
252
+ case 'combo':
253
+ this.specification.combo = mapper;
254
+ break;
255
+ }
256
+ this.hooks.mapperchange.emit({
257
+ type,
258
+ mapper,
259
+ });
260
+ }
236
261
  /**
237
262
  * Get the copy of specs(configurations).
238
263
  * @returns graph specs
@@ -754,23 +779,26 @@ class Graph extends event_emitter_1.default {
754
779
  // data controller and item controller subscribe additem in order
755
780
  const { graphCore } = this.dataController;
756
781
  const { specification } = this.themeController;
782
+ // debugger;
757
783
  graphCore.once('changed', (event) => {
758
784
  if (!event.changes.length)
759
785
  return;
760
786
  const changes = event.changes;
761
- this.hooks.itemchange.emit({
762
- type: itemType,
763
- changes: graphCore.reduceChanges(event.changes),
764
- graphCore,
765
- theme: specification,
766
- });
767
- this.emit('afteritemchange', {
787
+ const timingParameters = {
768
788
  type: itemType,
769
789
  action: 'add',
770
790
  models,
771
791
  apiName: 'addData',
772
792
  changes,
793
+ };
794
+ this.emit('beforeitemchange', timingParameters);
795
+ this.hooks.itemchange.emit({
796
+ type: itemType,
797
+ changes: graphCore.reduceChanges(event.changes),
798
+ graphCore,
799
+ theme: specification,
773
800
  });
801
+ this.emit('afteritemchange', timingParameters);
774
802
  });
775
803
  const modelArr = (0, util_1.isArray)(models) ? models : [models];
776
804
  const data = { nodes: [], edges: [], combos: [] };
@@ -799,19 +827,21 @@ class Graph extends event_emitter_1.default {
799
827
  if (!event.changes.length)
800
828
  return;
801
829
  const changes = event.changes;
802
- this.hooks.itemchange.emit({
803
- type: itemType,
804
- changes: event.changes,
805
- graphCore,
806
- theme: specification,
807
- });
808
- this.emit('afteritemchange', {
830
+ const timingParameters = {
809
831
  type: itemType,
810
832
  action: 'remove',
811
833
  ids: idArr,
812
834
  apiName: 'removeData',
813
835
  changes,
836
+ };
837
+ this.emit('beforeitemchange', timingParameters);
838
+ this.hooks.itemchange.emit({
839
+ type: itemType,
840
+ changes: event.changes,
841
+ graphCore,
842
+ theme: specification,
814
843
  });
844
+ this.emit('afteritemchange', timingParameters);
815
845
  });
816
846
  this.hooks.datachange.emit({
817
847
  data,
@@ -879,19 +909,21 @@ class Graph extends event_emitter_1.default {
879
909
  const { specification } = this.themeController;
880
910
  graphCore.once('changed', (event) => {
881
911
  const changes = this.extendChanges((0, util_1.clone)(event.changes));
882
- this.hooks.itemchange.emit({
883
- type: itemType,
884
- changes: event.changes,
885
- graphCore,
886
- theme: specification,
887
- });
888
- this.emit('afteritemchange', {
912
+ const timingParameters = {
889
913
  type: itemType,
890
914
  action: 'update',
891
915
  models,
892
916
  apiName: 'updateData',
893
917
  changes,
918
+ };
919
+ this.emit('beforeitemchange', timingParameters);
920
+ this.hooks.itemchange.emit({
921
+ type: itemType,
922
+ changes: event.changes,
923
+ graphCore,
924
+ theme: specification,
894
925
  });
926
+ this.emit('afteritemchange', timingParameters);
895
927
  });
896
928
  this.hooks.datachange.emit({
897
929
  data,
@@ -938,6 +970,15 @@ class Graph extends event_emitter_1.default {
938
970
  if (!event.changes.length)
939
971
  return;
940
972
  const changes = event.changes.filter((change) => !(0, util_1.isEqual)(change.newValue, change.oldValue));
973
+ const timingParameters = {
974
+ type,
975
+ action: 'updatePosition',
976
+ upsertAncestors,
977
+ models,
978
+ apiName: 'updatePosition',
979
+ changes,
980
+ };
981
+ this.emit('beforeitemchange', timingParameters);
941
982
  this.hooks.itemchange.emit({
942
983
  type,
943
984
  changes: event.changes,
@@ -948,14 +989,7 @@ class Graph extends event_emitter_1.default {
948
989
  animate: !disableAnimate,
949
990
  callback,
950
991
  });
951
- this.emit('afteritemchange', {
952
- type,
953
- action: 'updatePosition',
954
- upsertAncestors,
955
- models,
956
- apiName: 'updatePosition',
957
- changes,
958
- });
992
+ this.emit('afteritemchange', timingParameters);
959
993
  });
960
994
  this.hooks.datachange.emit({
961
995
  data: {
@@ -1204,19 +1238,21 @@ class Graph extends event_emitter_1.default {
1204
1238
  if (!event.changes.length)
1205
1239
  return;
1206
1240
  const changes = event.changes;
1207
- this.hooks.itemchange.emit({
1208
- type: 'combo',
1209
- changes: graphCore.reduceChanges(event.changes),
1210
- graphCore,
1211
- theme: specification,
1212
- });
1213
- this.emit('afteritemchange', {
1241
+ const timingParameters = {
1214
1242
  type: 'combo',
1215
1243
  action: 'add',
1216
1244
  models: [model],
1217
1245
  apiName: 'addCombo',
1218
1246
  changes,
1247
+ };
1248
+ this.emit('beforeitemchange', timingParameters);
1249
+ this.hooks.itemchange.emit({
1250
+ type: 'combo',
1251
+ changes: graphCore.reduceChanges(event.changes),
1252
+ graphCore,
1253
+ theme: specification,
1219
1254
  });
1255
+ this.emit('afteritemchange', timingParameters);
1220
1256
  });
1221
1257
  const data = {
1222
1258
  nodes: [],
@@ -1280,16 +1316,7 @@ class Graph extends event_emitter_1.default {
1280
1316
  if (!event.changes.length)
1281
1317
  return;
1282
1318
  const changes = this.extendChanges((0, util_1.clone)(event.changes));
1283
- this.hooks.itemchange.emit({
1284
- type: 'combo',
1285
- changes: event.changes,
1286
- graphCore,
1287
- theme: specification,
1288
- upsertAncestors,
1289
- action: 'updatePosition',
1290
- callback,
1291
- });
1292
- this.emit('afteritemchange', {
1319
+ const timingParameters = {
1293
1320
  type: 'combo',
1294
1321
  ids: idArr,
1295
1322
  dx,
@@ -1298,7 +1325,18 @@ class Graph extends event_emitter_1.default {
1298
1325
  upsertAncestors,
1299
1326
  apiName: 'moveCombo',
1300
1327
  changes,
1328
+ };
1329
+ this.emit('beforeitemchange', timingParameters);
1330
+ this.hooks.itemchange.emit({
1331
+ type: 'combo',
1332
+ changes: event.changes,
1333
+ graphCore,
1334
+ theme: specification,
1335
+ upsertAncestors,
1336
+ action: 'updatePosition',
1337
+ callback,
1301
1338
  });
1339
+ this.emit('afteritemchange', timingParameters);
1302
1340
  });
1303
1341
  this.hooks.datachange.emit({
1304
1342
  data: {
@@ -1383,6 +1421,14 @@ class Graph extends event_emitter_1.default {
1383
1421
  getMode() {
1384
1422
  return this.interactionController.getMode();
1385
1423
  }
1424
+ /**
1425
+ * Set the cursor. But the cursor in item's style has higher priority.
1426
+ * @param cursor
1427
+ */
1428
+ setCursor(cursor) {
1429
+ this.canvas.setCursor(cursor);
1430
+ this.transientCanvas.setCursor(cursor);
1431
+ }
1386
1432
  /**
1387
1433
  * Add behavior(s) to mode(s).
1388
1434
  * @param behaviors behavior names or configs
@@ -1553,6 +1599,274 @@ class Graph extends event_emitter_1.default {
1553
1599
  });
1554
1600
  return this.itemController.getTransient(String(id));
1555
1601
  }
1602
+ // ===== download operations =====
1603
+ /**
1604
+ * Asynchronously generates a Data URL representation of the canvas content, including
1605
+ * background, main content, and transient canvas.
1606
+ * @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
1607
+ * @returns A Promise that resolves to the Data URL string.
1608
+ */
1609
+ toDataURL(type) {
1610
+ return __awaiter(this, void 0, void 0, function* () {
1611
+ const backgroundCanvas = this.backgroundCanvas;
1612
+ const canvas = this.canvas;
1613
+ const transientCanvas = this.transientCanvas;
1614
+ const rendererType = this.rendererType;
1615
+ const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
1616
+ const width = this.getSize()[0];
1617
+ const height = this.getSize()[1];
1618
+ const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
1619
+ const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, width, height, pixelRatio);
1620
+ const vCanvasContextService = vCanvas.getContextService();
1621
+ let bgRect;
1622
+ if (rendererType !== 'svg') {
1623
+ bgRect = new g_1.Rect({
1624
+ style: {
1625
+ x: 0,
1626
+ y: 0,
1627
+ z: -1,
1628
+ width: vCanvasContextService.getDomElement().width,
1629
+ height: vCanvasContextService.getDomElement().height,
1630
+ //@ts-ignore
1631
+ fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
1632
+ },
1633
+ });
1634
+ vCanvas.appendChild(bgRect);
1635
+ }
1636
+ const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
1637
+ const clonedGroup = canvas.getRoot().cloneNode(true);
1638
+ const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
1639
+ vCanvas.appendChild(backgroundClonedGroup);
1640
+ vCanvas.appendChild(clonedGroup);
1641
+ vCanvas.appendChild(transientClonedGroup);
1642
+ vCanvas.render();
1643
+ if (!type)
1644
+ type = 'image/png';
1645
+ let dataURL = '';
1646
+ yield vCanvasContextService.toDataURL({ type }).then((url) => {
1647
+ dataURL = url;
1648
+ });
1649
+ return dataURL;
1650
+ });
1651
+ }
1652
+ /**
1653
+ * Asynchronously generates a Data URL representation of the full canvas content,
1654
+ * including background, main content, and transient canvas, with optional padding.
1655
+ * @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
1656
+ * @param imageConfig Configuration options for the image (optional).
1657
+ * @returns A Promise that resolves to the Data URL string.
1658
+ */
1659
+ toFullDataURL(type, imageConfig) {
1660
+ return __awaiter(this, void 0, void 0, function* () {
1661
+ const backgroundCanvas = this.backgroundCanvas;
1662
+ const canvas = this.canvas;
1663
+ const transientCanvas = this.transientCanvas;
1664
+ const backgroundRoot = canvas.getRoot();
1665
+ const root = canvas.getRoot();
1666
+ const transientRoot = transientCanvas.getRoot();
1667
+ const rendererType = this.rendererType;
1668
+ const backgroundBBox = backgroundRoot.getBBox();
1669
+ const BBox = root.getBBox();
1670
+ const transientBBox = transientRoot.getBBox();
1671
+ let padding = imageConfig ? imageConfig.padding : undefined;
1672
+ if (!padding) {
1673
+ padding = [0, 0, 0, 0];
1674
+ }
1675
+ else if ((0, util_1.isNumber)(padding)) {
1676
+ padding = [padding, padding, padding, padding];
1677
+ }
1678
+ const left = (transientBBox.left
1679
+ ? backgroundBBox.left
1680
+ ? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
1681
+ : Math.min(BBox.left, transientBBox.left)
1682
+ : BBox.left) - padding[3];
1683
+ const right = (transientBBox.right
1684
+ ? backgroundBBox.right
1685
+ ? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
1686
+ : Math.max(BBox.right, transientBBox.right)
1687
+ : BBox.right) + padding[1];
1688
+ const top = (transientBBox.top
1689
+ ? backgroundBBox.top
1690
+ ? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
1691
+ : Math.min(BBox.top, transientBBox.top)
1692
+ : BBox.top) - padding[0];
1693
+ const bottom = (transientBBox.bottom
1694
+ ? backgroundBBox.bottom
1695
+ ? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
1696
+ : Math.max(BBox.bottom, transientBBox.bottom)
1697
+ : BBox.bottom) + padding[2];
1698
+ const graphCenterX = (left + right) / 2;
1699
+ const graphCenterY = (top + bottom) / 2;
1700
+ const halfX = (right - left) / 2;
1701
+ const halfY = (bottom - top) / 2;
1702
+ const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
1703
+ const vWidth = halfX * 2;
1704
+ const vHeight = halfY * 2;
1705
+ const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
1706
+ const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
1707
+ const vCanvasContextService = vCanvas.getContextService();
1708
+ if (rendererType !== 'svg') {
1709
+ const bgRect = new g_1.Rect({
1710
+ style: {
1711
+ x: 0,
1712
+ y: 0,
1713
+ z: -1,
1714
+ width: vCanvasContextService.getDomElement().width,
1715
+ height: vCanvasContextService.getDomElement().height,
1716
+ //@ts-ignore
1717
+ fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
1718
+ },
1719
+ });
1720
+ vCanvas.appendChild(bgRect);
1721
+ }
1722
+ const backgroundClonedGroup = backgroundRoot.cloneNode(true);
1723
+ const clonedGroup = root.cloneNode(true);
1724
+ const transientClonedGroup = transientRoot.cloneNode(true);
1725
+ const transPosition = [
1726
+ -graphCenterX + halfX,
1727
+ -graphCenterY + halfY,
1728
+ ];
1729
+ backgroundClonedGroup.setPosition(transPosition);
1730
+ clonedGroup.setPosition(transPosition);
1731
+ transientClonedGroup.setPosition(transPosition);
1732
+ vCanvas.appendChild(backgroundClonedGroup);
1733
+ vCanvas.appendChild(clonedGroup);
1734
+ vCanvas.appendChild(transientClonedGroup);
1735
+ vCanvas.render();
1736
+ if (!type)
1737
+ type = 'image/png';
1738
+ let dataURL = '';
1739
+ yield vCanvasContextService.toDataURL({ type }).then((url) => {
1740
+ dataURL = url;
1741
+ });
1742
+ return dataURL;
1743
+ });
1744
+ }
1745
+ /**
1746
+ * Converts a Data URL to an image file and handles the download of the image.
1747
+ * @param dataURL The Data URL of the image to be converted and downloaded.
1748
+ * @param renderer The renderer type ('svg' or other) used for the canvas.
1749
+ * @param link The HTML link element used for image download.
1750
+ * @param fileName The desired name for the downloaded image file.
1751
+ */
1752
+ dataURLToImage(dataURL, renderer, link, fileName) {
1753
+ if (!dataURL || dataURL === 'data:') {
1754
+ console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
1755
+ return;
1756
+ }
1757
+ if (typeof window !== 'undefined') {
1758
+ if (window.Blob && window.URL && renderer !== 'svg') {
1759
+ const arr = dataURL.split(',');
1760
+ let mime = '';
1761
+ if (arr && arr.length > 0) {
1762
+ const match = arr[0].match(/:(.*?);/);
1763
+ // eslint-disable-next-line prefer-destructuring
1764
+ if (match && match.length >= 2)
1765
+ mime = match[1];
1766
+ }
1767
+ const bstr = atob(arr[1]);
1768
+ let n = bstr.length;
1769
+ const u8arr = new Uint8Array(n);
1770
+ while (n--) {
1771
+ u8arr[n] = bstr.charCodeAt(n);
1772
+ }
1773
+ const blobObj = new Blob([u8arr], { type: mime });
1774
+ if (window.navigator.msSaveBlob) {
1775
+ window.navigator.msSaveBlob(blobObj, fileName);
1776
+ }
1777
+ else {
1778
+ link.addEventListener('click', () => {
1779
+ link.download = fileName;
1780
+ link.href = window.URL.createObjectURL(blobObj);
1781
+ });
1782
+ }
1783
+ }
1784
+ else {
1785
+ link.addEventListener('click', () => {
1786
+ link.download = fileName;
1787
+ link.href = dataURL;
1788
+ });
1789
+ }
1790
+ }
1791
+ }
1792
+ /**
1793
+ * Initiates the download of the graph as an image with an optional name and type.
1794
+ * @param name The desired name for the downloaded image file (optional).
1795
+ * @param type The type of the image to download (optional, defaults to 'image/png').
1796
+ */
1797
+ downloadImage(name, type) {
1798
+ const self = this;
1799
+ // self.stopAnimate();
1800
+ const rendererType = this.rendererType;
1801
+ if (!type)
1802
+ type = 'image/png';
1803
+ const fileName = (name || 'graph') +
1804
+ (rendererType === 'svg' ? '.svg' : type.split('/')[1]);
1805
+ const link = document.createElement('a');
1806
+ self.asyncToDataUrl(type, (dataURL) => {
1807
+ this.dataURLToImage(dataURL, rendererType, link, fileName);
1808
+ const e = document.createEvent('MouseEvents');
1809
+ e.initEvent('click', false, false);
1810
+ link.dispatchEvent(e);
1811
+ });
1812
+ }
1813
+ /**
1814
+ * Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
1815
+ * @param name The desired name for the downloaded image file (optional).
1816
+ * @param type The type of the image to download (optional, defaults to 'image/png').
1817
+ * @param imageConfig Configuration options for the image (optional).
1818
+ */
1819
+ downloadFullImage(name, type, imageConfig) {
1820
+ const self = this;
1821
+ const rendererType = this.rendererType;
1822
+ if (!type)
1823
+ type = 'image/png';
1824
+ const fileName = (name || 'graph') +
1825
+ (rendererType === 'svg' ? '.svg' : type.split('/')[1]);
1826
+ const link = document.createElement('a');
1827
+ self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
1828
+ this.dataURLToImage(dataURL, rendererType, link, fileName);
1829
+ const e = document.createEvent('MouseEvents');
1830
+ e.initEvent('click', false, false);
1831
+ link.dispatchEvent(e);
1832
+ });
1833
+ }
1834
+ /**
1835
+ * Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
1836
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
1837
+ * @param callback A callback function to handle the Data URL (optional).
1838
+ */
1839
+ asyncToDataUrl(type, callback) {
1840
+ let dataURL = '';
1841
+ if (!type)
1842
+ type = 'image/png';
1843
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
1844
+ yield this.toDataURL(type).then((url) => {
1845
+ dataURL = url;
1846
+ });
1847
+ if (callback)
1848
+ callback(dataURL);
1849
+ }), 16);
1850
+ }
1851
+ /**
1852
+ * Asynchronously converts the entire canvas content to a Data URL of the specified type
1853
+ * with optional padding, and invokes the provided callback.
1854
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
1855
+ * @param imageConfig Configuration options for the image (optional).
1856
+ * @param callback A callback function to handle the Data URL (optional).
1857
+ */
1858
+ asyncToFullDataUrl(type, imageConfig, callback) {
1859
+ let dataURL = '';
1860
+ if (!type)
1861
+ type = 'image/png';
1862
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
1863
+ yield this.toFullDataURL(type, imageConfig).then((url) => {
1864
+ dataURL = url;
1865
+ });
1866
+ if (callback)
1867
+ callback(dataURL);
1868
+ }), 16);
1869
+ }
1556
1870
  // ===== history operations =====
1557
1871
  /**
1558
1872
  * Determine if history (redo/undo) is enabled.