TreeSeries.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 =
  47. /** @class */
  48. function (_super) {
  49. __extends(TreeSeriesModel, _super);
  50. function TreeSeriesModel() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.hasSymbolVisual = true; // 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); // 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. }; // Add tree path to tooltip param
  126. TreeSeriesModel.prototype.getDataParams = function (dataIndex) {
  127. var params = _super.prototype.getDataParams.apply(this, arguments);
  128. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  129. params.treeAncestors = wrapTreePathInfo(node, this);
  130. params.collapsed = !node.isExpand;
  131. return params;
  132. };
  133. TreeSeriesModel.type = 'series.tree'; // can support the position parameters 'left', 'top','right','bottom', 'width',
  134. // 'height' in the setOption() with 'merge' mode normal.
  135. TreeSeriesModel.layoutMode = 'box';
  136. TreeSeriesModel.defaultOption = {
  137. // zlevel: 0,
  138. z: 2,
  139. coordinateSystem: 'view',
  140. // the position of the whole view
  141. left: '12%',
  142. top: '12%',
  143. right: '12%',
  144. bottom: '12%',
  145. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  146. layout: 'orthogonal',
  147. // value can be 'polyline'
  148. edgeShape: 'curve',
  149. edgeForkPosition: '50%',
  150. // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  151. roam: false,
  152. // Symbol size scale ratio in roam
  153. nodeScaleRatio: 0.4,
  154. // Default on center of graph
  155. center: null,
  156. zoom: 1,
  157. orient: 'LR',
  158. symbol: 'emptyCircle',
  159. symbolSize: 7,
  160. expandAndCollapse: true,
  161. initialTreeDepth: 2,
  162. lineStyle: {
  163. color: '#ccc',
  164. width: 1.5,
  165. curveness: 0.5
  166. },
  167. itemStyle: {
  168. color: 'lightsteelblue',
  169. // borderColor: '#c23531',
  170. borderWidth: 1.5
  171. },
  172. label: {
  173. show: true
  174. },
  175. animationEasing: 'linear',
  176. animationDuration: 700,
  177. animationDurationUpdate: 500
  178. };
  179. return TreeSeriesModel;
  180. }(SeriesModel);
  181. export default TreeSeriesModel;