TreeSeries.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 SeriesModel from '../../model/Series.js';
  42. import Tree from '../../data/Tree.js';
  43. import Model from '../../model/Model.js';
  44. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  45. import { wrapTreePathInfo } from '../helper/treeHelper.js';
  46. import tokens from '../../visual/tokens.js';
  47. var TreeSeriesModel = /** @class */function (_super) {
  48. __extends(TreeSeriesModel, _super);
  49. function TreeSeriesModel() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.hasSymbolVisual = true;
  52. // Do it self.
  53. _this.ignoreStyleOnData = true;
  54. return _this;
  55. }
  56. /**
  57. * Init a tree data structure from data in option series
  58. */
  59. TreeSeriesModel.prototype.getInitialData = function (option) {
  60. // create a virtual root
  61. var root = {
  62. name: option.name,
  63. children: option.data
  64. };
  65. var leaves = option.leaves || {};
  66. var leavesModel = new Model(leaves, this, this.ecModel);
  67. var tree = Tree.createTree(root, this, beforeLink);
  68. function beforeLink(nodeData) {
  69. nodeData.wrapMethod('getItemModel', function (model, idx) {
  70. var node = tree.getNodeByDataIndex(idx);
  71. if (!(node && node.children.length && node.isExpand)) {
  72. model.parentModel = leavesModel;
  73. }
  74. return model;
  75. });
  76. }
  77. var treeDepth = 0;
  78. tree.eachNode('preorder', function (node) {
  79. if (node.depth > treeDepth) {
  80. treeDepth = node.depth;
  81. }
  82. });
  83. var expandAndCollapse = option.expandAndCollapse;
  84. var expandTreeDepth = expandAndCollapse && option.initialTreeDepth >= 0 ? option.initialTreeDepth : treeDepth;
  85. tree.root.eachNode('preorder', function (node) {
  86. var item = node.hostTree.data.getRawDataItem(node.dataIndex);
  87. // Add item.collapsed != null, because users can collapse node original in the series.data.
  88. node.isExpand = item && item.collapsed != null ? !item.collapsed : node.depth <= expandTreeDepth;
  89. });
  90. return tree.data;
  91. };
  92. /**
  93. * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'.
  94. * @returns {string} orient
  95. */
  96. TreeSeriesModel.prototype.getOrient = function () {
  97. var orient = this.get('orient');
  98. if (orient === 'horizontal') {
  99. orient = 'LR';
  100. } else if (orient === 'vertical') {
  101. orient = 'TB';
  102. }
  103. return orient;
  104. };
  105. TreeSeriesModel.prototype.setZoom = function (zoom) {
  106. this.option.zoom = zoom;
  107. };
  108. TreeSeriesModel.prototype.setCenter = function (center) {
  109. this.option.center = center;
  110. };
  111. TreeSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  112. var tree = this.getData().tree;
  113. var realRoot = tree.root.children[0];
  114. var node = tree.getNodeByDataIndex(dataIndex);
  115. var value = node.getValue();
  116. var name = node.name;
  117. while (node && node !== realRoot) {
  118. name = node.parentNode.name + '.' + name;
  119. node = node.parentNode;
  120. }
  121. return createTooltipMarkup('nameValue', {
  122. name: name,
  123. value: value,
  124. noValue: isNaN(value) || value == null
  125. });
  126. };
  127. // Add tree path to tooltip param
  128. TreeSeriesModel.prototype.getDataParams = function (dataIndex) {
  129. var params = _super.prototype.getDataParams.apply(this, arguments);
  130. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  131. params.treeAncestors = wrapTreePathInfo(node, this);
  132. params.collapsed = !node.isExpand;
  133. return params;
  134. };
  135. TreeSeriesModel.type = 'series.tree';
  136. // can support the position parameters 'left', 'top','right','bottom', 'width',
  137. // 'height' in the setOption() with 'merge' mode normal.
  138. TreeSeriesModel.layoutMode = 'box';
  139. TreeSeriesModel.defaultOption = {
  140. // zlevel: 0,
  141. z: 2,
  142. // `coordinateSystem` can be declared as 'matrix', 'calendar',
  143. // which provides box layout container.
  144. coordinateSystemUsage: 'box',
  145. // the position of the whole view
  146. left: '12%',
  147. top: '12%',
  148. right: '12%',
  149. bottom: '12%',
  150. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  151. layout: 'orthogonal',
  152. // value can be 'polyline'
  153. edgeShape: 'curve',
  154. edgeForkPosition: '50%',
  155. // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  156. roam: false,
  157. roamTrigger: 'global',
  158. // Symbol size scale ratio in roam
  159. nodeScaleRatio: 0.4,
  160. // Default on center of graph
  161. center: null,
  162. zoom: 1,
  163. orient: 'LR',
  164. symbol: 'emptyCircle',
  165. symbolSize: 7,
  166. expandAndCollapse: true,
  167. initialTreeDepth: 2,
  168. lineStyle: {
  169. color: tokens.color.borderTint,
  170. width: 1.5,
  171. curveness: 0.5
  172. },
  173. itemStyle: {
  174. color: 'lightsteelblue',
  175. // borderColor: '#c23531',
  176. borderWidth: 1.5
  177. },
  178. label: {
  179. show: true
  180. },
  181. animationEasing: 'linear',
  182. animationDuration: 700,
  183. animationDurationUpdate: 500
  184. };
  185. return TreeSeriesModel;
  186. }(SeriesModel);
  187. export default TreeSeriesModel;