TreeSeries.js 6.5 KB

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