TreeView.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import * as graphic from '../../util/graphic.js';
  43. import { getECData } from '../../util/innerStore.js';
  44. import SymbolClz from '../helper/Symbol.js';
  45. import { radialCoordinate } from './layoutHelper.js';
  46. import * as bbox from 'zrender/lib/core/bbox.js';
  47. import { applyViewCoordSysTransToElement, calcCompensationScaleToPreserveNodeSize, VIEW_COORD_SYS_TRANS_OVERALL } from '../../coord/View.js';
  48. import RoamController from '../../component/helper/RoamController.js';
  49. import { parsePercent } from '../../util/number.js';
  50. import ChartView from '../../view/Chart.js';
  51. import { SERIES_TYPE_TREE } from './TreeSeries.js';
  52. import Path from 'zrender/lib/graphic/Path.js';
  53. import { setStatesStylesFromModel, setStatesFlag, setDefaultStateProxy, HOVER_STATE_BLUR } from '../../util/states.js';
  54. import tokens from '../../visual/tokens.js';
  55. import { createIsInSelfByPointerCheckerEl, createViewCoordSysSimply, isRoamPayloadHasZoom, updateRoamControllerSimply } from '../../component/helper/roamHelper.js';
  56. var TreeEdgeShape = /** @class */function () {
  57. function TreeEdgeShape() {
  58. this.parentPoint = [];
  59. this.childPoints = [];
  60. }
  61. return TreeEdgeShape;
  62. }();
  63. var TreePath = /** @class */function (_super) {
  64. __extends(TreePath, _super);
  65. function TreePath(opts) {
  66. return _super.call(this, opts) || this;
  67. }
  68. TreePath.prototype.getDefaultStyle = function () {
  69. return {
  70. stroke: tokens.color.neutral99,
  71. fill: null
  72. };
  73. };
  74. TreePath.prototype.getDefaultShape = function () {
  75. return new TreeEdgeShape();
  76. };
  77. TreePath.prototype.buildPath = function (ctx, shape) {
  78. var childPoints = shape.childPoints;
  79. var childLen = childPoints.length;
  80. var parentPoint = shape.parentPoint;
  81. var firstChildPos = childPoints[0];
  82. var lastChildPos = childPoints[childLen - 1];
  83. if (childLen === 1) {
  84. ctx.moveTo(parentPoint[0], parentPoint[1]);
  85. ctx.lineTo(firstChildPos[0], firstChildPos[1]);
  86. return;
  87. }
  88. var orient = shape.orient;
  89. var forkDim = orient === 'TB' || orient === 'BT' ? 0 : 1;
  90. var otherDim = 1 - forkDim;
  91. var forkPosition = parsePercent(shape.forkPosition, 1);
  92. var tmpPoint = [];
  93. tmpPoint[forkDim] = parentPoint[forkDim];
  94. tmpPoint[otherDim] = parentPoint[otherDim] + (lastChildPos[otherDim] - parentPoint[otherDim]) * forkPosition;
  95. ctx.moveTo(parentPoint[0], parentPoint[1]);
  96. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  97. ctx.moveTo(firstChildPos[0], firstChildPos[1]);
  98. tmpPoint[forkDim] = firstChildPos[forkDim];
  99. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  100. tmpPoint[forkDim] = lastChildPos[forkDim];
  101. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  102. ctx.lineTo(lastChildPos[0], lastChildPos[1]);
  103. for (var i = 1; i < childLen - 1; i++) {
  104. var point = childPoints[i];
  105. ctx.moveTo(point[0], point[1]);
  106. tmpPoint[forkDim] = point[forkDim];
  107. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  108. }
  109. };
  110. return TreePath;
  111. }(Path);
  112. var TreeView = /** @class */function (_super) {
  113. __extends(TreeView, _super);
  114. function TreeView() {
  115. var _this = _super !== null && _super.apply(this, arguments) || this;
  116. _this.type = SERIES_TYPE_TREE;
  117. _this._mainGroup = new graphic.Group();
  118. return _this;
  119. }
  120. TreeView.prototype.init = function (ecModel, api) {
  121. this._controller = new RoamController(api.getZr());
  122. this.group.add(this._mainGroup);
  123. this._firstRender = true;
  124. };
  125. TreeView.prototype.render = function (seriesModel, ecModel, api) {
  126. var data = seriesModel.getData();
  127. var layoutInfo = seriesModel.layoutInfo;
  128. var group = this._mainGroup;
  129. var layout = seriesModel.get('layout');
  130. if (layout === 'radial') {
  131. group.x = layoutInfo.x + layoutInfo.width / 2;
  132. group.y = layoutInfo.y + layoutInfo.height / 2;
  133. } else {
  134. group.x = layoutInfo.x;
  135. group.y = layoutInfo.y;
  136. }
  137. this._updateViewCoordSys(seriesModel, api);
  138. updateRoamControllerSimply(seriesModel, api, this._controller, createIsInSelfByPointerCheckerEl(this.group), null);
  139. var oldData = this._data;
  140. data.diff(oldData).add(function (newIdx) {
  141. if (symbolNeedsDraw(data, newIdx)) {
  142. // Create node and edge
  143. updateNode(data, newIdx, null, group, seriesModel);
  144. }
  145. }).update(function (newIdx, oldIdx) {
  146. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  147. if (!symbolNeedsDraw(data, newIdx)) {
  148. symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel);
  149. return;
  150. }
  151. // Update node and edge
  152. updateNode(data, newIdx, symbolEl, group, seriesModel);
  153. }).remove(function (oldIdx) {
  154. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  155. // When remove a collapsed node of subtree, since the collapsed
  156. // node haven't been initialized with a symbol element,
  157. // you can't found it's symbol element through index.
  158. // so if we want to remove the symbol element we should insure
  159. // that the symbol element is not null.
  160. if (symbolEl) {
  161. removeNode(oldData, oldIdx, symbolEl, group, seriesModel);
  162. }
  163. }).execute();
  164. this._updateNodeAndLinkScale(seriesModel);
  165. if (seriesModel.get('expandAndCollapse') === true) {
  166. data.eachItemGraphicEl(function (el, dataIndex) {
  167. el.off('click').on('click', function () {
  168. api.dispatchAction({
  169. type: 'treeExpandAndCollapse',
  170. seriesId: seriesModel.id,
  171. dataIndex: dataIndex
  172. });
  173. });
  174. });
  175. }
  176. this._data = data;
  177. this._firstRender = false;
  178. };
  179. TreeView.prototype.__updateOnOwnRoam = function (payload, seriesModel, api) {
  180. applyViewCoordSysTransToElement(this.group, VIEW_COORD_SYS_TRANS_OVERALL, seriesModel.coordinateSystem, null);
  181. if (isRoamPayloadHasZoom(payload)) {
  182. this._updateNodeAndLinkScale(seriesModel);
  183. }
  184. };
  185. TreeView.prototype._updateViewCoordSys = function (seriesModel, api) {
  186. var data = seriesModel.getData();
  187. var points = [];
  188. data.each(function (idx) {
  189. var layout = data.getItemLayout(idx);
  190. if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
  191. points.push([+layout.x, +layout.y]);
  192. }
  193. });
  194. var min = [];
  195. var max = [];
  196. bbox.fromPoints(points, min, max);
  197. // If don't Store min max when collapse the root node after roam,
  198. // the root node will disappear.
  199. var oldMin = this._min;
  200. var oldMax = this._max;
  201. // If width or height is 0
  202. if (max[0] - min[0] === 0) {
  203. min[0] = oldMin ? oldMin[0] : min[0] - 1;
  204. max[0] = oldMax ? oldMax[0] : max[0] + 1;
  205. }
  206. if (max[1] - min[1] === 0) {
  207. min[1] = oldMin ? oldMin[1] : min[1] - 1;
  208. max[1] = oldMax ? oldMax[1] : max[1] + 1;
  209. }
  210. // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group,
  211. // and 'treeRoam' action.
  212. var ownCoordSys = seriesModel.coordinateSystem = createViewCoordSysSimply(seriesModel, api, min[0], min[1], max[0] - min[0], max[1] - min[1]);
  213. applyViewCoordSysTransToElement(this.group, VIEW_COORD_SYS_TRANS_OVERALL, ownCoordSys, this._firstRender ? null : seriesModel);
  214. this._min = min;
  215. this._max = max;
  216. };
  217. TreeView.prototype._updateNodeAndLinkScale = function (seriesModel) {
  218. var data = seriesModel.getData();
  219. var nodeScale = calcCompensationScaleToPreserveNodeSize(seriesModel.coordinateSystem, seriesModel);
  220. data.eachItemGraphicEl(function (el, idx) {
  221. el.setSymbolScale(nodeScale);
  222. });
  223. };
  224. TreeView.prototype.dispose = function () {
  225. this._controller && this._controller.dispose();
  226. };
  227. TreeView.prototype.remove = function () {
  228. this._mainGroup.removeAll();
  229. this._data = null;
  230. };
  231. TreeView.type = SERIES_TYPE_TREE;
  232. return TreeView;
  233. }(ChartView);
  234. function symbolNeedsDraw(data, dataIndex) {
  235. var layout = data.getItemLayout(dataIndex);
  236. return layout && !isNaN(layout.x) && !isNaN(layout.y);
  237. }
  238. function updateNode(data, dataIndex, symbolEl, group, seriesModel) {
  239. var isInit = !symbolEl;
  240. var node = data.tree.getNodeByDataIndex(dataIndex);
  241. var itemModel = node.getModel();
  242. var visualColor = node.getVisual('style').fill;
  243. var symbolInnerColor = node.isExpand === false && node.children.length !== 0 ? visualColor : tokens.color.neutral00;
  244. var virtualRoot = data.tree.root;
  245. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  246. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  247. var sourceLayout = source.getLayout();
  248. var sourceOldLayout = sourceSymbolEl ? {
  249. x: sourceSymbolEl.__oldX,
  250. y: sourceSymbolEl.__oldY,
  251. rawX: sourceSymbolEl.__radialOldRawX,
  252. rawY: sourceSymbolEl.__radialOldRawY
  253. } : sourceLayout;
  254. var targetLayout = node.getLayout();
  255. if (isInit) {
  256. symbolEl = new SymbolClz(data, dataIndex, null, {
  257. symbolInnerColor: symbolInnerColor,
  258. useNameLabel: true
  259. });
  260. symbolEl.x = sourceOldLayout.x;
  261. symbolEl.y = sourceOldLayout.y;
  262. } else {
  263. symbolEl.updateData(data, dataIndex, null, {
  264. symbolInnerColor: symbolInnerColor,
  265. useNameLabel: true
  266. });
  267. }
  268. symbolEl.__radialOldRawX = symbolEl.__radialRawX;
  269. symbolEl.__radialOldRawY = symbolEl.__radialRawY;
  270. symbolEl.__radialRawX = targetLayout.rawX;
  271. symbolEl.__radialRawY = targetLayout.rawY;
  272. group.add(symbolEl);
  273. data.setItemGraphicEl(dataIndex, symbolEl);
  274. symbolEl.__oldX = symbolEl.x;
  275. symbolEl.__oldY = symbolEl.y;
  276. graphic.updateProps(symbolEl, {
  277. x: targetLayout.x,
  278. y: targetLayout.y
  279. }, seriesModel);
  280. var symbolPath = symbolEl.getSymbolPath();
  281. if (seriesModel.get('layout') === 'radial') {
  282. var realRoot = virtualRoot.children[0];
  283. var rootLayout = realRoot.getLayout();
  284. var length_1 = realRoot.children.length;
  285. var rad = void 0;
  286. var isLeft = void 0;
  287. if (targetLayout.x === rootLayout.x && node.isExpand === true && realRoot.children.length) {
  288. var center = {
  289. x: (realRoot.children[0].getLayout().x + realRoot.children[length_1 - 1].getLayout().x) / 2,
  290. y: (realRoot.children[0].getLayout().y + realRoot.children[length_1 - 1].getLayout().y) / 2
  291. };
  292. rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
  293. if (rad < 0) {
  294. rad = Math.PI * 2 + rad;
  295. }
  296. isLeft = center.x < rootLayout.x;
  297. if (isLeft) {
  298. rad = rad - Math.PI;
  299. }
  300. } else {
  301. rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
  302. if (rad < 0) {
  303. rad = Math.PI * 2 + rad;
  304. }
  305. if (node.children.length === 0 || node.children.length !== 0 && node.isExpand === false) {
  306. isLeft = targetLayout.x < rootLayout.x;
  307. if (isLeft) {
  308. rad = rad - Math.PI;
  309. }
  310. } else {
  311. isLeft = targetLayout.x > rootLayout.x;
  312. if (!isLeft) {
  313. rad = rad - Math.PI;
  314. }
  315. }
  316. }
  317. var textPosition = isLeft ? 'left' : 'right';
  318. var normalLabelModel = itemModel.getModel('label');
  319. var rotate = normalLabelModel.get('rotate');
  320. var labelRotateRadian = rotate * (Math.PI / 180);
  321. var textContent = symbolPath.getTextContent();
  322. if (textContent) {
  323. symbolPath.setTextConfig({
  324. position: normalLabelModel.get('position') || textPosition,
  325. rotation: rotate == null ? -rad : labelRotateRadian,
  326. origin: 'center'
  327. });
  328. textContent.setStyle('verticalAlign', 'middle');
  329. }
  330. }
  331. // Handle status
  332. var focus = itemModel.get(['emphasis', 'focus']);
  333. var focusDataIndices = focus === 'relative' ? zrUtil.concatArray(node.getAncestorsIndices(), node.getDescendantIndices()) : focus === 'ancestor' ? node.getAncestorsIndices() : focus === 'descendant' ? node.getDescendantIndices() : null;
  334. if (focusDataIndices) {
  335. // Modify the focus to data indices.
  336. getECData(symbolEl).focus = focusDataIndices;
  337. }
  338. drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group);
  339. if (symbolEl.__edge) {
  340. symbolEl.onHoverStateChange = function (toState) {
  341. if (toState !== 'blur') {
  342. // NOTE: Ensure the parent elements will been blurred firstly.
  343. // According to the return of getAncestorsIndices and getDescendantIndices
  344. // TODO: A bit tricky.
  345. var parentEl = node.parentNode && data.getItemGraphicEl(node.parentNode.dataIndex);
  346. if (!(parentEl && parentEl.hoverState === HOVER_STATE_BLUR)) {
  347. setStatesFlag(symbolEl.__edge, toState);
  348. }
  349. }
  350. };
  351. }
  352. }
  353. function drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group) {
  354. var itemModel = node.getModel();
  355. var edgeShape = seriesModel.get('edgeShape');
  356. var layout = seriesModel.get('layout');
  357. var orient = seriesModel.getOrient();
  358. var curvature = seriesModel.get(['lineStyle', 'curveness']);
  359. var edgeForkPosition = seriesModel.get('edgeForkPosition');
  360. var lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  361. var edge = symbolEl.__edge;
  362. // curve edge from node -> parent
  363. // polyline edge from node -> children
  364. if (edgeShape === 'curve') {
  365. if (node.parentNode && node.parentNode !== virtualRoot) {
  366. if (!edge) {
  367. edge = symbolEl.__edge = new graphic.BezierCurve({
  368. shape: getEdgeShape(layout, orient, curvature, sourceOldLayout, sourceOldLayout)
  369. });
  370. }
  371. graphic.updateProps(edge, {
  372. shape: getEdgeShape(layout, orient, curvature, sourceLayout, targetLayout)
  373. }, seriesModel);
  374. }
  375. } else if (edgeShape === 'polyline') {
  376. if (layout === 'orthogonal') {
  377. if (node !== virtualRoot && node.children && node.children.length !== 0 && node.isExpand === true) {
  378. var children = node.children;
  379. var childPoints = [];
  380. for (var i = 0; i < children.length; i++) {
  381. var childLayout = children[i].getLayout();
  382. childPoints.push([childLayout.x, childLayout.y]);
  383. }
  384. if (!edge) {
  385. edge = symbolEl.__edge = new TreePath({
  386. shape: {
  387. parentPoint: [targetLayout.x, targetLayout.y],
  388. childPoints: [[targetLayout.x, targetLayout.y]],
  389. orient: orient,
  390. forkPosition: edgeForkPosition
  391. }
  392. });
  393. }
  394. graphic.updateProps(edge, {
  395. shape: {
  396. parentPoint: [targetLayout.x, targetLayout.y],
  397. childPoints: childPoints
  398. }
  399. }, seriesModel);
  400. }
  401. } else {
  402. if (process.env.NODE_ENV !== 'production') {
  403. throw new Error('The polyline edgeShape can only be used in orthogonal layout');
  404. }
  405. }
  406. }
  407. // show all edge when edgeShape is 'curve', filter node `isExpand` is false when edgeShape is 'polyline'
  408. if (edge && !(edgeShape === 'polyline' && !node.isExpand)) {
  409. edge.useStyle(zrUtil.defaults({
  410. strokeNoScale: true,
  411. fill: null
  412. }, lineStyle));
  413. setStatesStylesFromModel(edge, itemModel, 'lineStyle');
  414. setDefaultStateProxy(edge);
  415. group.add(edge);
  416. }
  417. }
  418. function removeNodeEdge(node, data, group, seriesModel, removeAnimationOpt) {
  419. var virtualRoot = data.tree.root;
  420. var _a = getSourceNode(virtualRoot, node),
  421. source = _a.source,
  422. sourceLayout = _a.sourceLayout;
  423. var symbolEl = data.getItemGraphicEl(node.dataIndex);
  424. if (!symbolEl) {
  425. return;
  426. }
  427. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  428. var sourceEdge = sourceSymbolEl.__edge;
  429. // 1. when expand the sub tree, delete the children node should delete the edge of
  430. // the source at the same time. because the polyline edge shape is only owned by the source.
  431. // 2.when the node is the only children of the source, delete the node should delete the edge of
  432. // the source at the same time. the same reason as above.
  433. var edge = symbolEl.__edge || (source.isExpand === false || source.children.length === 1 ? sourceEdge : undefined);
  434. var edgeShape = seriesModel.get('edgeShape');
  435. var layoutOpt = seriesModel.get('layout');
  436. var orient = seriesModel.get('orient');
  437. var curvature = seriesModel.get(['lineStyle', 'curveness']);
  438. if (edge) {
  439. if (edgeShape === 'curve') {
  440. graphic.removeElement(edge, {
  441. shape: getEdgeShape(layoutOpt, orient, curvature, sourceLayout, sourceLayout),
  442. style: {
  443. opacity: 0
  444. }
  445. }, seriesModel, {
  446. cb: function () {
  447. group.remove(edge);
  448. },
  449. removeOpt: removeAnimationOpt
  450. });
  451. } else if (edgeShape === 'polyline' && seriesModel.get('layout') === 'orthogonal') {
  452. graphic.removeElement(edge, {
  453. shape: {
  454. parentPoint: [sourceLayout.x, sourceLayout.y],
  455. childPoints: [[sourceLayout.x, sourceLayout.y]]
  456. },
  457. style: {
  458. opacity: 0
  459. }
  460. }, seriesModel, {
  461. cb: function () {
  462. group.remove(edge);
  463. },
  464. removeOpt: removeAnimationOpt
  465. });
  466. }
  467. }
  468. }
  469. function getSourceNode(virtualRoot, node) {
  470. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  471. var sourceLayout;
  472. while (sourceLayout = source.getLayout(), sourceLayout == null) {
  473. source = source.parentNode === virtualRoot ? source : source.parentNode || source;
  474. }
  475. return {
  476. source: source,
  477. sourceLayout: sourceLayout
  478. };
  479. }
  480. function removeNode(data, dataIndex, symbolEl, group, seriesModel) {
  481. var node = data.tree.getNodeByDataIndex(dataIndex);
  482. var virtualRoot = data.tree.root;
  483. var sourceLayout = getSourceNode(virtualRoot, node).sourceLayout;
  484. // Use same duration and easing with update to have more consistent animation.
  485. var removeAnimationOpt = {
  486. duration: seriesModel.get('animationDurationUpdate'),
  487. easing: seriesModel.get('animationEasingUpdate')
  488. };
  489. graphic.removeElement(symbolEl, {
  490. x: sourceLayout.x + 1,
  491. y: sourceLayout.y + 1
  492. }, seriesModel, {
  493. cb: function () {
  494. group.remove(symbolEl);
  495. data.setItemGraphicEl(dataIndex, null);
  496. },
  497. removeOpt: removeAnimationOpt
  498. });
  499. symbolEl.fadeOut(null, data.hostModel, {
  500. fadeLabel: true,
  501. animation: removeAnimationOpt
  502. });
  503. // remove edge as parent node
  504. zrUtil.each(node.children, function (childNode) {
  505. removeNodeEdge(childNode, data, group, seriesModel, removeAnimationOpt);
  506. });
  507. // remove edge as child node
  508. removeNodeEdge(node, data, group, seriesModel, removeAnimationOpt);
  509. }
  510. function getEdgeShape(layoutOpt, orient, curvature, sourceLayout, targetLayout) {
  511. var cpx1;
  512. var cpy1;
  513. var cpx2;
  514. var cpy2;
  515. var x1;
  516. var x2;
  517. var y1;
  518. var y2;
  519. if (layoutOpt === 'radial') {
  520. x1 = sourceLayout.rawX;
  521. y1 = sourceLayout.rawY;
  522. x2 = targetLayout.rawX;
  523. y2 = targetLayout.rawY;
  524. var radialCoor1 = radialCoordinate(x1, y1);
  525. var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * curvature);
  526. var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * curvature);
  527. var radialCoor4 = radialCoordinate(x2, y2);
  528. return {
  529. x1: radialCoor1.x || 0,
  530. y1: radialCoor1.y || 0,
  531. x2: radialCoor4.x || 0,
  532. y2: radialCoor4.y || 0,
  533. cpx1: radialCoor2.x || 0,
  534. cpy1: radialCoor2.y || 0,
  535. cpx2: radialCoor3.x || 0,
  536. cpy2: radialCoor3.y || 0
  537. };
  538. } else {
  539. x1 = sourceLayout.x;
  540. y1 = sourceLayout.y;
  541. x2 = targetLayout.x;
  542. y2 = targetLayout.y;
  543. if (orient === 'LR' || orient === 'RL') {
  544. cpx1 = x1 + (x2 - x1) * curvature;
  545. cpy1 = y1;
  546. cpx2 = x2 + (x1 - x2) * curvature;
  547. cpy2 = y2;
  548. }
  549. if (orient === 'TB' || orient === 'BT') {
  550. cpx1 = x1;
  551. cpy1 = y1 + (y2 - y1) * curvature;
  552. cpx2 = x2;
  553. cpy2 = y2 + (y1 - y2) * curvature;
  554. }
  555. }
  556. return {
  557. x1: x1,
  558. y1: y1,
  559. x2: x2,
  560. y2: y2,
  561. cpx1: cpx1,
  562. cpy1: cpy1,
  563. cpx2: cpx2,
  564. cpy2: cpy2
  565. };
  566. }
  567. export default TreeView;