graph.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. var __importStar = (this && this.__importStar) || function (mod) {
  25. if (mod && mod.__esModule) return mod;
  26. var result = {};
  27. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  28. __setModuleDefault(result, mod);
  29. return result;
  30. };
  31. Object.defineProperty(exports, "__esModule", { value: true });
  32. exports.Graph = void 0;
  33. const x6_common_1 = require("@antv/x6-common");
  34. const x6_geometry_1 = require("@antv/x6-geometry");
  35. const model_1 = require("../model");
  36. const view_1 = require("../view");
  37. const Registry = __importStar(require("../registry"));
  38. const view_2 = require("./view");
  39. const css_1 = require("./css");
  40. const options_1 = require("./options");
  41. const grid_1 = require("./grid");
  42. const transform_1 = require("./transform");
  43. const background_1 = require("./background");
  44. const panning_1 = require("./panning");
  45. const mousewheel_1 = require("./mousewheel");
  46. const virtual_render_1 = require("./virtual-render");
  47. const renderer_1 = require("../renderer");
  48. const defs_1 = require("./defs");
  49. const coord_1 = require("./coord");
  50. const highlight_1 = require("./highlight");
  51. const size_1 = require("./size");
  52. class Graph extends x6_common_1.Basecoat {
  53. get container() {
  54. return this.options.container;
  55. }
  56. get [Symbol.toStringTag]() {
  57. return Graph.toStringTag;
  58. }
  59. constructor(options) {
  60. super();
  61. this.installedPlugins = new Set();
  62. this.options = options_1.Options.get(options);
  63. this.css = new css_1.CSSManager(this);
  64. this.view = new view_2.GraphView(this);
  65. this.defs = new defs_1.DefsManager(this);
  66. this.coord = new coord_1.CoordManager(this);
  67. this.transform = new transform_1.TransformManager(this);
  68. this.highlight = new highlight_1.HighlightManager(this);
  69. this.grid = new grid_1.GridManager(this);
  70. this.background = new background_1.BackgroundManager(this);
  71. if (this.options.model) {
  72. this.model = this.options.model;
  73. }
  74. else {
  75. this.model = new model_1.Model();
  76. this.model.graph = this;
  77. }
  78. this.renderer = new renderer_1.Renderer(this);
  79. this.panning = new panning_1.PanningManager(this);
  80. this.mousewheel = new mousewheel_1.MouseWheel(this);
  81. this.virtualRender = new virtual_render_1.VirtualRenderManager(this);
  82. this.size = new size_1.SizeManager(this);
  83. }
  84. // #region model
  85. isNode(cell) {
  86. return cell.isNode();
  87. }
  88. isEdge(cell) {
  89. return cell.isEdge();
  90. }
  91. resetCells(cells, options = {}) {
  92. this.model.resetCells(cells, options);
  93. return this;
  94. }
  95. clearCells(options = {}) {
  96. this.model.clear(options);
  97. return this;
  98. }
  99. toJSON(options = {}) {
  100. return this.model.toJSON(options);
  101. }
  102. parseJSON(data) {
  103. return this.model.parseJSON(data);
  104. }
  105. fromJSON(data, options = {}) {
  106. this.model.fromJSON(data, options);
  107. return this;
  108. }
  109. getCellById(id) {
  110. return this.model.getCell(id);
  111. }
  112. addNode(node, options = {}) {
  113. return this.model.addNode(node, options);
  114. }
  115. addNodes(nodes, options = {}) {
  116. return this.addCell(nodes.map((node) => (model_1.Node.isNode(node) ? node : this.createNode(node))), options);
  117. }
  118. createNode(metadata) {
  119. return this.model.createNode(metadata);
  120. }
  121. removeNode(node, options = {}) {
  122. return this.model.removeCell(node, options);
  123. }
  124. addEdge(edge, options = {}) {
  125. return this.model.addEdge(edge, options);
  126. }
  127. addEdges(edges, options = {}) {
  128. return this.addCell(edges.map((edge) => (model_1.Edge.isEdge(edge) ? edge : this.createEdge(edge))), options);
  129. }
  130. removeEdge(edge, options = {}) {
  131. return this.model.removeCell(edge, options);
  132. }
  133. createEdge(metadata) {
  134. return this.model.createEdge(metadata);
  135. }
  136. addCell(cell, options = {}) {
  137. this.model.addCell(cell, options);
  138. return this;
  139. }
  140. removeCell(cell, options = {}) {
  141. return this.model.removeCell(cell, options);
  142. }
  143. removeCells(cells, options = {}) {
  144. return this.model.removeCells(cells, options);
  145. }
  146. removeConnectedEdges(cell, options = {}) {
  147. return this.model.removeConnectedEdges(cell, options);
  148. }
  149. disconnectConnectedEdges(cell, options = {}) {
  150. this.model.disconnectConnectedEdges(cell, options);
  151. return this;
  152. }
  153. hasCell(cell) {
  154. return this.model.has(cell);
  155. }
  156. getCells() {
  157. return this.model.getCells();
  158. }
  159. getCellCount() {
  160. return this.model.total();
  161. }
  162. /**
  163. * Returns all the nodes in the graph.
  164. */
  165. getNodes() {
  166. return this.model.getNodes();
  167. }
  168. /**
  169. * Returns all the edges in the graph.
  170. */
  171. getEdges() {
  172. return this.model.getEdges();
  173. }
  174. /**
  175. * Returns all outgoing edges for the node.
  176. */
  177. getOutgoingEdges(cell) {
  178. return this.model.getOutgoingEdges(cell);
  179. }
  180. /**
  181. * Returns all incoming edges for the node.
  182. */
  183. getIncomingEdges(cell) {
  184. return this.model.getIncomingEdges(cell);
  185. }
  186. /**
  187. * Returns edges connected with cell.
  188. */
  189. getConnectedEdges(cell, options = {}) {
  190. return this.model.getConnectedEdges(cell, options);
  191. }
  192. /**
  193. * Returns an array of all the roots of the graph.
  194. */
  195. getRootNodes() {
  196. return this.model.getRoots();
  197. }
  198. /**
  199. * Returns an array of all the leafs of the graph.
  200. */
  201. getLeafNodes() {
  202. return this.model.getLeafs();
  203. }
  204. /**
  205. * Returns `true` if the node is a root node, i.e.
  206. * there is no edges coming to the node.
  207. */
  208. isRootNode(cell) {
  209. return this.model.isRoot(cell);
  210. }
  211. /**
  212. * Returns `true` if the node is a leaf node, i.e.
  213. * there is no edges going out from the node.
  214. */
  215. isLeafNode(cell) {
  216. return this.model.isLeaf(cell);
  217. }
  218. /**
  219. * Returns all the neighbors of node in the graph. Neighbors are all
  220. * the nodes connected to node via either incoming or outgoing edge.
  221. */
  222. getNeighbors(cell, options = {}) {
  223. return this.model.getNeighbors(cell, options);
  224. }
  225. /**
  226. * Returns `true` if `cell2` is a neighbor of `cell1`.
  227. */
  228. isNeighbor(cell1, cell2, options = {}) {
  229. return this.model.isNeighbor(cell1, cell2, options);
  230. }
  231. getSuccessors(cell, options = {}) {
  232. return this.model.getSuccessors(cell, options);
  233. }
  234. /**
  235. * Returns `true` if `cell2` is a successor of `cell1`.
  236. */
  237. isSuccessor(cell1, cell2, options = {}) {
  238. return this.model.isSuccessor(cell1, cell2, options);
  239. }
  240. getPredecessors(cell, options = {}) {
  241. return this.model.getPredecessors(cell, options);
  242. }
  243. /**
  244. * Returns `true` if `cell2` is a predecessor of `cell1`.
  245. */
  246. isPredecessor(cell1, cell2, options = {}) {
  247. return this.model.isPredecessor(cell1, cell2, options);
  248. }
  249. getCommonAncestor(...cells) {
  250. return this.model.getCommonAncestor(...cells);
  251. }
  252. /**
  253. * Returns an array of cells that result from finding nodes/edges that
  254. * are connected to any of the cells in the cells array. This function
  255. * loops over cells and if the current cell is a edge, it collects its
  256. * source/target nodes; if it is an node, it collects its incoming and
  257. * outgoing edges if both the edge terminal (source/target) are in the
  258. * cells array.
  259. */
  260. getSubGraph(cells, options = {}) {
  261. return this.model.getSubGraph(cells, options);
  262. }
  263. /**
  264. * Clones the whole subgraph (including all the connected links whose
  265. * source/target is in the subgraph). If `options.deep` is `true`, also
  266. * take into account all the embedded cells of all the subgraph cells.
  267. *
  268. * Returns a map of the form: { [original cell ID]: [clone] }.
  269. */
  270. cloneSubGraph(cells, options = {}) {
  271. return this.model.cloneSubGraph(cells, options);
  272. }
  273. cloneCells(cells) {
  274. return this.model.cloneCells(cells);
  275. }
  276. getNodesFromPoint(x, y) {
  277. return this.model.getNodesFromPoint(x, y);
  278. }
  279. getNodesInArea(x, y, w, h, options) {
  280. return this.model.getNodesInArea(x, y, w, h, options);
  281. }
  282. getNodesUnderNode(node, options = {}) {
  283. return this.model.getNodesUnderNode(node, options);
  284. }
  285. searchCell(cell, iterator, options = {}) {
  286. this.model.search(cell, iterator, options);
  287. return this;
  288. }
  289. /** *
  290. * Returns an array of IDs of nodes on the shortest
  291. * path between source and target.
  292. */
  293. getShortestPath(source, target, options = {}) {
  294. return this.model.getShortestPath(source, target, options);
  295. }
  296. /**
  297. * Returns the bounding box that surrounds all cells in the graph.
  298. */
  299. getAllCellsBBox() {
  300. return this.model.getAllCellsBBox();
  301. }
  302. /**
  303. * Returns the bounding box that surrounds all the given cells.
  304. */
  305. getCellsBBox(cells, options = {}) {
  306. return this.model.getCellsBBox(cells, options);
  307. }
  308. startBatch(name, data = {}) {
  309. this.model.startBatch(name, data);
  310. }
  311. stopBatch(name, data = {}) {
  312. this.model.stopBatch(name, data);
  313. }
  314. batchUpdate(arg1, arg2, arg3) {
  315. const name = typeof arg1 === 'string' ? arg1 : 'update';
  316. const execute = typeof arg1 === 'string' ? arg2 : arg1;
  317. const data = typeof arg2 === 'function' ? arg3 : arg2;
  318. this.startBatch(name, data);
  319. const result = execute();
  320. this.stopBatch(name, data);
  321. return result;
  322. }
  323. updateCellId(cell, newId) {
  324. return this.model.updateCellId(cell, newId);
  325. }
  326. // #endregion
  327. // #region view
  328. findView(ref) {
  329. if (model_1.Cell.isCell(ref)) {
  330. return this.findViewByCell(ref);
  331. }
  332. return this.findViewByElem(ref);
  333. }
  334. findViews(ref) {
  335. if (x6_geometry_1.Rectangle.isRectangleLike(ref)) {
  336. return this.findViewsInArea(ref);
  337. }
  338. if (x6_geometry_1.Point.isPointLike(ref)) {
  339. return this.findViewsFromPoint(ref);
  340. }
  341. return [];
  342. }
  343. findViewByCell(cell) {
  344. return this.renderer.findViewByCell(cell);
  345. }
  346. findViewByElem(elem) {
  347. return this.renderer.findViewByElem(elem);
  348. }
  349. findViewsFromPoint(x, y) {
  350. const p = typeof x === 'number' ? { x, y: y } : x;
  351. return this.renderer.findViewsFromPoint(p);
  352. }
  353. findViewsInArea(x, y, width, height, options) {
  354. const rect = typeof x === 'number'
  355. ? {
  356. x,
  357. y: y,
  358. width: width,
  359. height: height,
  360. }
  361. : x;
  362. const localOptions = typeof x === 'number'
  363. ? options
  364. : y;
  365. return this.renderer.findViewsInArea(rect, localOptions);
  366. }
  367. matrix(mat) {
  368. if (typeof mat === 'undefined') {
  369. return this.transform.getMatrix();
  370. }
  371. this.transform.setMatrix(mat);
  372. return this;
  373. }
  374. resize(width, height) {
  375. const scroller = this.getPlugin('scroller');
  376. if (scroller) {
  377. scroller.resize(width, height);
  378. }
  379. else {
  380. this.transform.resize(width, height);
  381. }
  382. return this;
  383. }
  384. scale(sx, sy = sx, cx = 0, cy = 0) {
  385. if (typeof sx === 'undefined') {
  386. return this.transform.getScale();
  387. }
  388. this.transform.scale(sx, sy, cx, cy);
  389. return this;
  390. }
  391. zoom(factor, options) {
  392. const scroller = this.getPlugin('scroller');
  393. if (scroller) {
  394. if (typeof factor === 'undefined') {
  395. return scroller.zoom();
  396. }
  397. scroller.zoom(factor, options);
  398. }
  399. else {
  400. if (typeof factor === 'undefined') {
  401. return this.transform.getZoom();
  402. }
  403. this.transform.zoom(factor, options);
  404. }
  405. return this;
  406. }
  407. zoomTo(factor, options = {}) {
  408. const scroller = this.getPlugin('scroller');
  409. if (scroller) {
  410. scroller.zoom(factor, Object.assign(Object.assign({}, options), { absolute: true }));
  411. }
  412. else {
  413. this.transform.zoom(factor, Object.assign(Object.assign({}, options), { absolute: true }));
  414. }
  415. return this;
  416. }
  417. zoomToRect(rect, options = {}) {
  418. const scroller = this.getPlugin('scroller');
  419. if (scroller) {
  420. scroller.zoomToRect(rect, options);
  421. }
  422. else {
  423. this.transform.zoomToRect(rect, options);
  424. }
  425. return this;
  426. }
  427. zoomToFit(options = {}) {
  428. const scroller = this.getPlugin('scroller');
  429. if (scroller) {
  430. scroller.zoomToFit(options);
  431. }
  432. else {
  433. this.transform.zoomToFit(options);
  434. }
  435. return this;
  436. }
  437. rotate(angle, cx, cy) {
  438. if (typeof angle === 'undefined') {
  439. return this.transform.getRotation();
  440. }
  441. this.transform.rotate(angle, cx, cy);
  442. return this;
  443. }
  444. translate(tx, ty) {
  445. if (typeof tx === 'undefined') {
  446. return this.transform.getTranslation();
  447. }
  448. this.transform.translate(tx, ty);
  449. return this;
  450. }
  451. translateBy(dx, dy) {
  452. const ts = this.translate();
  453. const tx = ts.tx + dx;
  454. const ty = ts.ty + dy;
  455. return this.translate(tx, ty);
  456. }
  457. getGraphArea() {
  458. return this.transform.getGraphArea();
  459. }
  460. getContentArea(options = {}) {
  461. return this.transform.getContentArea(options);
  462. }
  463. getContentBBox(options = {}) {
  464. return this.transform.getContentBBox(options);
  465. }
  466. fitToContent(gridWidth, gridHeight, padding, options) {
  467. return this.transform.fitToContent(gridWidth, gridHeight, padding, options);
  468. }
  469. scaleContentToFit(options = {}) {
  470. this.transform.scaleContentToFit(options);
  471. return this;
  472. }
  473. /**
  474. * Position the center of graph to the center of the viewport.
  475. */
  476. center(options) {
  477. return this.centerPoint(options);
  478. }
  479. centerPoint(x, y, options) {
  480. const scroller = this.getPlugin('scroller');
  481. if (scroller) {
  482. scroller.centerPoint(x, y, options);
  483. }
  484. else {
  485. this.transform.centerPoint(x, y);
  486. }
  487. return this;
  488. }
  489. centerContent(options) {
  490. const scroller = this.getPlugin('scroller');
  491. if (scroller) {
  492. scroller.centerContent(options);
  493. }
  494. else {
  495. this.transform.centerContent(options);
  496. }
  497. return this;
  498. }
  499. centerCell(cell, options) {
  500. const scroller = this.getPlugin('scroller');
  501. if (scroller) {
  502. scroller.centerCell(cell, options);
  503. }
  504. else {
  505. this.transform.centerCell(cell);
  506. }
  507. return this;
  508. }
  509. positionPoint(point, x, y, options = {}) {
  510. const scroller = this.getPlugin('scroller');
  511. if (scroller) {
  512. scroller.positionPoint(point, x, y, options);
  513. }
  514. else {
  515. this.transform.positionPoint(point, x, y);
  516. }
  517. return this;
  518. }
  519. positionRect(rect, direction, options) {
  520. const scroller = this.getPlugin('scroller');
  521. if (scroller) {
  522. scroller.positionRect(rect, direction, options);
  523. }
  524. else {
  525. this.transform.positionRect(rect, direction);
  526. }
  527. return this;
  528. }
  529. positionCell(cell, direction, options) {
  530. const scroller = this.getPlugin('scroller');
  531. if (scroller) {
  532. scroller.positionCell(cell, direction, options);
  533. }
  534. else {
  535. this.transform.positionCell(cell, direction);
  536. }
  537. return this;
  538. }
  539. positionContent(pos, options) {
  540. const scroller = this.getPlugin('scroller');
  541. if (scroller) {
  542. scroller.positionContent(pos, options);
  543. }
  544. else {
  545. this.transform.positionContent(pos, options);
  546. }
  547. return this;
  548. }
  549. snapToGrid(x, y) {
  550. return this.coord.snapToGrid(x, y);
  551. }
  552. pageToLocal(x, y, width, height) {
  553. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  554. return this.coord.pageToLocalRect(x);
  555. }
  556. if (typeof x === 'number' &&
  557. typeof y === 'number' &&
  558. typeof width === 'number' &&
  559. typeof height === 'number') {
  560. return this.coord.pageToLocalRect(x, y, width, height);
  561. }
  562. return this.coord.pageToLocalPoint(x, y);
  563. }
  564. localToPage(x, y, width, height) {
  565. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  566. return this.coord.localToPageRect(x);
  567. }
  568. if (typeof x === 'number' &&
  569. typeof y === 'number' &&
  570. typeof width === 'number' &&
  571. typeof height === 'number') {
  572. return this.coord.localToPageRect(x, y, width, height);
  573. }
  574. return this.coord.localToPagePoint(x, y);
  575. }
  576. clientToLocal(x, y, width, height) {
  577. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  578. return this.coord.clientToLocalRect(x);
  579. }
  580. if (typeof x === 'number' &&
  581. typeof y === 'number' &&
  582. typeof width === 'number' &&
  583. typeof height === 'number') {
  584. return this.coord.clientToLocalRect(x, y, width, height);
  585. }
  586. return this.coord.clientToLocalPoint(x, y);
  587. }
  588. localToClient(x, y, width, height) {
  589. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  590. return this.coord.localToClientRect(x);
  591. }
  592. if (typeof x === 'number' &&
  593. typeof y === 'number' &&
  594. typeof width === 'number' &&
  595. typeof height === 'number') {
  596. return this.coord.localToClientRect(x, y, width, height);
  597. }
  598. return this.coord.localToClientPoint(x, y);
  599. }
  600. localToGraph(x, y, width, height) {
  601. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  602. return this.coord.localToGraphRect(x);
  603. }
  604. if (typeof x === 'number' &&
  605. typeof y === 'number' &&
  606. typeof width === 'number' &&
  607. typeof height === 'number') {
  608. return this.coord.localToGraphRect(x, y, width, height);
  609. }
  610. return this.coord.localToGraphPoint(x, y);
  611. }
  612. graphToLocal(x, y, width, height) {
  613. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  614. return this.coord.graphToLocalRect(x);
  615. }
  616. if (typeof x === 'number' &&
  617. typeof y === 'number' &&
  618. typeof width === 'number' &&
  619. typeof height === 'number') {
  620. return this.coord.graphToLocalRect(x, y, width, height);
  621. }
  622. return this.coord.graphToLocalPoint(x, y);
  623. }
  624. clientToGraph(x, y, width, height) {
  625. if (x6_geometry_1.Rectangle.isRectangleLike(x)) {
  626. return this.coord.clientToGraphRect(x);
  627. }
  628. if (typeof x === 'number' &&
  629. typeof y === 'number' &&
  630. typeof width === 'number' &&
  631. typeof height === 'number') {
  632. return this.coord.clientToGraphRect(x, y, width, height);
  633. }
  634. return this.coord.clientToGraphPoint(x, y);
  635. }
  636. // #endregion
  637. // #region defs
  638. defineFilter(options) {
  639. return this.defs.filter(options);
  640. }
  641. defineGradient(options) {
  642. return this.defs.gradient(options);
  643. }
  644. defineMarker(options) {
  645. return this.defs.marker(options);
  646. }
  647. // #endregion
  648. // #region grid
  649. getGridSize() {
  650. return this.grid.getGridSize();
  651. }
  652. setGridSize(gridSize) {
  653. this.grid.setGridSize(gridSize);
  654. return this;
  655. }
  656. showGrid() {
  657. this.grid.show();
  658. return this;
  659. }
  660. hideGrid() {
  661. this.grid.hide();
  662. return this;
  663. }
  664. clearGrid() {
  665. this.grid.clear();
  666. return this;
  667. }
  668. drawGrid(options) {
  669. this.grid.draw(options);
  670. return this;
  671. }
  672. // #endregion
  673. // #region background
  674. updateBackground() {
  675. this.background.update();
  676. return this;
  677. }
  678. drawBackground(options, onGraph) {
  679. const scroller = this.getPlugin('scroller');
  680. if (scroller != null && (this.options.background == null || !onGraph)) {
  681. scroller.drawBackground(options, onGraph);
  682. }
  683. else {
  684. this.background.draw(options);
  685. }
  686. return this;
  687. }
  688. clearBackground(onGraph) {
  689. const scroller = this.getPlugin('scroller');
  690. if (scroller != null && (this.options.background == null || !onGraph)) {
  691. scroller.clearBackground(onGraph);
  692. }
  693. else {
  694. this.background.clear();
  695. }
  696. return this;
  697. }
  698. // #endregion
  699. // #region virtual-render
  700. enableVirtualRender() {
  701. this.virtualRender.enableVirtualRender();
  702. return this;
  703. }
  704. disableVirtualRender() {
  705. this.virtualRender.disableVirtualRender();
  706. return this;
  707. }
  708. // #endregion
  709. // #region mousewheel
  710. isMouseWheelEnabled() {
  711. return !this.mousewheel.disabled;
  712. }
  713. enableMouseWheel() {
  714. this.mousewheel.enable();
  715. return this;
  716. }
  717. disableMouseWheel() {
  718. this.mousewheel.disable();
  719. return this;
  720. }
  721. toggleMouseWheel(enabled) {
  722. if (enabled == null) {
  723. if (this.isMouseWheelEnabled()) {
  724. this.disableMouseWheel();
  725. }
  726. else {
  727. this.enableMouseWheel();
  728. }
  729. }
  730. else if (enabled) {
  731. this.enableMouseWheel();
  732. }
  733. else {
  734. this.disableMouseWheel();
  735. }
  736. return this;
  737. }
  738. // #endregion
  739. // #region panning
  740. isPannable() {
  741. const scroller = this.getPlugin('scroller');
  742. if (scroller) {
  743. return scroller.isPannable();
  744. }
  745. return this.panning.pannable;
  746. }
  747. enablePanning() {
  748. const scroller = this.getPlugin('scroller');
  749. if (scroller) {
  750. scroller.enablePanning();
  751. }
  752. else {
  753. this.panning.enablePanning();
  754. }
  755. return this;
  756. }
  757. disablePanning() {
  758. const scroller = this.getPlugin('scroller');
  759. if (scroller) {
  760. scroller.disablePanning();
  761. }
  762. else {
  763. this.panning.disablePanning();
  764. }
  765. return this;
  766. }
  767. togglePanning(pannable) {
  768. if (pannable == null) {
  769. if (this.isPannable()) {
  770. this.disablePanning();
  771. }
  772. else {
  773. this.enablePanning();
  774. }
  775. }
  776. else if (pannable !== this.isPannable()) {
  777. if (pannable) {
  778. this.enablePanning();
  779. }
  780. else {
  781. this.disablePanning();
  782. }
  783. }
  784. return this;
  785. }
  786. // #endregion
  787. // #region plugin
  788. use(plugin, ...options) {
  789. if (!this.installedPlugins.has(plugin)) {
  790. this.installedPlugins.add(plugin);
  791. plugin.init(this, ...options);
  792. }
  793. return this;
  794. }
  795. getPlugin(pluginName) {
  796. return Array.from(this.installedPlugins).find((plugin) => plugin.name === pluginName);
  797. }
  798. getPlugins(pluginName) {
  799. return Array.from(this.installedPlugins).filter((plugin) => pluginName.includes(plugin.name));
  800. }
  801. enablePlugins(plugins) {
  802. let postPlugins = plugins;
  803. if (!Array.isArray(postPlugins)) {
  804. postPlugins = [postPlugins];
  805. }
  806. const aboutToChangePlugins = this.getPlugins(postPlugins);
  807. aboutToChangePlugins === null || aboutToChangePlugins === void 0 ? void 0 : aboutToChangePlugins.forEach((plugin) => {
  808. var _a;
  809. (_a = plugin === null || plugin === void 0 ? void 0 : plugin.enable) === null || _a === void 0 ? void 0 : _a.call(plugin);
  810. });
  811. return this;
  812. }
  813. disablePlugins(plugins) {
  814. let postPlugins = plugins;
  815. if (!Array.isArray(postPlugins)) {
  816. postPlugins = [postPlugins];
  817. }
  818. const aboutToChangePlugins = this.getPlugins(postPlugins);
  819. aboutToChangePlugins === null || aboutToChangePlugins === void 0 ? void 0 : aboutToChangePlugins.forEach((plugin) => {
  820. var _a;
  821. (_a = plugin === null || plugin === void 0 ? void 0 : plugin.disable) === null || _a === void 0 ? void 0 : _a.call(plugin);
  822. });
  823. return this;
  824. }
  825. isPluginEnabled(pluginName) {
  826. var _a;
  827. const pluginIns = this.getPlugin(pluginName);
  828. return (_a = pluginIns === null || pluginIns === void 0 ? void 0 : pluginIns.isEnabled) === null || _a === void 0 ? void 0 : _a.call(pluginIns);
  829. }
  830. disposePlugins(plugins) {
  831. let postPlugins = plugins;
  832. if (!Array.isArray(postPlugins)) {
  833. postPlugins = [postPlugins];
  834. }
  835. const aboutToChangePlugins = this.getPlugins(postPlugins);
  836. aboutToChangePlugins === null || aboutToChangePlugins === void 0 ? void 0 : aboutToChangePlugins.forEach((plugin) => {
  837. plugin.dispose();
  838. this.installedPlugins.delete(plugin);
  839. });
  840. return this;
  841. }
  842. // #endregion
  843. // #region dispose
  844. dispose(clean = true) {
  845. if (clean) {
  846. this.model.dispose();
  847. }
  848. this.css.dispose();
  849. this.defs.dispose();
  850. this.grid.dispose();
  851. this.coord.dispose();
  852. this.transform.dispose();
  853. this.highlight.dispose();
  854. this.background.dispose();
  855. this.mousewheel.dispose();
  856. this.panning.dispose();
  857. this.view.dispose();
  858. this.renderer.dispose();
  859. this.installedPlugins.forEach((plugin) => {
  860. plugin.dispose();
  861. });
  862. }
  863. }
  864. __decorate([
  865. x6_common_1.Basecoat.dispose()
  866. ], Graph.prototype, "dispose", null);
  867. exports.Graph = Graph;
  868. (function (Graph) {
  869. /* eslint-disable @typescript-eslint/no-unused-vars */
  870. Graph.View = view_2.GraphView;
  871. Graph.Renderer = renderer_1.Renderer;
  872. Graph.MouseWheel = mousewheel_1.MouseWheel;
  873. Graph.DefsManager = defs_1.DefsManager;
  874. Graph.GridManager = grid_1.GridManager;
  875. Graph.CoordManager = coord_1.CoordManager;
  876. Graph.TransformManager = transform_1.TransformManager;
  877. Graph.HighlightManager = highlight_1.HighlightManager;
  878. Graph.BackgroundManager = background_1.BackgroundManager;
  879. Graph.PanningManager = panning_1.PanningManager;
  880. })(Graph = exports.Graph || (exports.Graph = {}));
  881. (function (Graph) {
  882. Graph.toStringTag = `X6.${Graph.name}`;
  883. function isGraph(instance) {
  884. if (instance == null) {
  885. return false;
  886. }
  887. if (instance instanceof Graph) {
  888. return true;
  889. }
  890. const tag = instance[Symbol.toStringTag];
  891. if (tag == null || tag === Graph.toStringTag) {
  892. return true;
  893. }
  894. return false;
  895. }
  896. Graph.isGraph = isGraph;
  897. })(Graph = exports.Graph || (exports.Graph = {}));
  898. (function (Graph) {
  899. function render(options, data) {
  900. const graph = options instanceof HTMLElement
  901. ? new Graph({ container: options })
  902. : new Graph(options);
  903. if (data != null) {
  904. graph.fromJSON(data);
  905. }
  906. return graph;
  907. }
  908. Graph.render = render;
  909. })(Graph = exports.Graph || (exports.Graph = {}));
  910. (function (Graph) {
  911. Graph.registerNode = model_1.Node.registry.register;
  912. Graph.registerEdge = model_1.Edge.registry.register;
  913. Graph.registerView = view_1.CellView.registry.register;
  914. Graph.registerAttr = Registry.Attr.registry.register;
  915. Graph.registerGrid = Registry.Grid.registry.register;
  916. Graph.registerFilter = Registry.Filter.registry.register;
  917. Graph.registerNodeTool = Registry.NodeTool.registry.register;
  918. Graph.registerEdgeTool = Registry.EdgeTool.registry.register;
  919. Graph.registerBackground = Registry.Background.registry.register;
  920. Graph.registerHighlighter = Registry.Highlighter.registry.register;
  921. Graph.registerPortLayout = Registry.PortLayout.registry.register;
  922. Graph.registerPortLabelLayout = Registry.PortLabelLayout.registry.register;
  923. Graph.registerMarker = Registry.Marker.registry.register;
  924. Graph.registerRouter = Registry.Router.registry.register;
  925. Graph.registerConnector = Registry.Connector.registry.register;
  926. Graph.registerAnchor = Registry.NodeAnchor.registry.register;
  927. Graph.registerEdgeAnchor = Registry.EdgeAnchor.registry.register;
  928. Graph.registerConnectionPoint = Registry.ConnectionPoint.registry.register;
  929. })(Graph = exports.Graph || (exports.Graph = {}));
  930. (function (Graph) {
  931. Graph.unregisterNode = model_1.Node.registry.unregister;
  932. Graph.unregisterEdge = model_1.Edge.registry.unregister;
  933. Graph.unregisterView = view_1.CellView.registry.unregister;
  934. Graph.unregisterAttr = Registry.Attr.registry.unregister;
  935. Graph.unregisterGrid = Registry.Grid.registry.unregister;
  936. Graph.unregisterFilter = Registry.Filter.registry.unregister;
  937. Graph.unregisterNodeTool = Registry.NodeTool.registry.unregister;
  938. Graph.unregisterEdgeTool = Registry.EdgeTool.registry.unregister;
  939. Graph.unregisterBackground = Registry.Background.registry.unregister;
  940. Graph.unregisterHighlighter = Registry.Highlighter.registry.unregister;
  941. Graph.unregisterPortLayout = Registry.PortLayout.registry.unregister;
  942. Graph.unregisterPortLabelLayout = Registry.PortLabelLayout.registry.unregister;
  943. Graph.unregisterMarker = Registry.Marker.registry.unregister;
  944. Graph.unregisterRouter = Registry.Router.registry.unregister;
  945. Graph.unregisterConnector = Registry.Connector.registry.unregister;
  946. Graph.unregisterAnchor = Registry.NodeAnchor.registry.unregister;
  947. Graph.unregisterEdgeAnchor = Registry.EdgeAnchor.registry.unregister;
  948. Graph.unregisterConnectionPoint = Registry.ConnectionPoint.registry.unregister;
  949. })(Graph = exports.Graph || (exports.Graph = {}));
  950. //# sourceMappingURL=graph.js.map