TreeSeries.js 6.3 KB

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