SunburstSeries.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 SeriesModel from '../../model/Series.js';
  43. import Tree from '../../data/Tree.js';
  44. import { wrapTreePathInfo } from '../helper/treeHelper.js';
  45. import Model from '../../model/Model.js';
  46. import enableAriaDecalForTree from '../helper/enableAriaDecalForTree.js';
  47. var SunburstSeriesModel = /** @class */function (_super) {
  48. __extends(SunburstSeriesModel, _super);
  49. function SunburstSeriesModel() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = SunburstSeriesModel.type;
  52. _this.ignoreStyleOnData = true;
  53. return _this;
  54. }
  55. SunburstSeriesModel.prototype.getInitialData = function (option, ecModel) {
  56. // Create a virtual root.
  57. var root = {
  58. name: option.name,
  59. children: option.data
  60. };
  61. completeTreeValue(root);
  62. var levelModels = this._levelModels = zrUtil.map(option.levels || [], function (levelDefine) {
  63. return new Model(levelDefine, this, ecModel);
  64. }, this);
  65. // Make sure always a new tree is created when setOption,
  66. // in TreemapView, we check whether oldTree === newTree
  67. // to choose mappings approach among old shapes and new shapes.
  68. var tree = Tree.createTree(root, this, beforeLink);
  69. function beforeLink(nodeData) {
  70. nodeData.wrapMethod('getItemModel', function (model, idx) {
  71. var node = tree.getNodeByDataIndex(idx);
  72. var levelModel = levelModels[node.depth];
  73. levelModel && (model.parentModel = levelModel);
  74. return model;
  75. });
  76. }
  77. return tree.data;
  78. };
  79. SunburstSeriesModel.prototype.optionUpdated = function () {
  80. this.resetViewRoot();
  81. };
  82. /*
  83. * @override
  84. */
  85. SunburstSeriesModel.prototype.getDataParams = function (dataIndex) {
  86. var params = _super.prototype.getDataParams.apply(this, arguments);
  87. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  88. params.treePathInfo = wrapTreePathInfo(node, this);
  89. return params;
  90. };
  91. SunburstSeriesModel.prototype.getLevelModel = function (node) {
  92. return this._levelModels && this._levelModels[node.depth];
  93. };
  94. SunburstSeriesModel.prototype.getViewRoot = function () {
  95. return this._viewRoot;
  96. };
  97. SunburstSeriesModel.prototype.resetViewRoot = function (viewRoot) {
  98. viewRoot ? this._viewRoot = viewRoot : viewRoot = this._viewRoot;
  99. var root = this.getRawData().tree.root;
  100. if (!viewRoot || viewRoot !== root && !root.contains(viewRoot)) {
  101. this._viewRoot = root;
  102. }
  103. };
  104. SunburstSeriesModel.prototype.enableAriaDecal = function () {
  105. enableAriaDecalForTree(this);
  106. };
  107. SunburstSeriesModel.type = 'series.sunburst';
  108. SunburstSeriesModel.defaultOption = {
  109. // zlevel: 0,
  110. z: 2,
  111. // 默认全局居中
  112. center: ['50%', '50%'],
  113. radius: [0, '75%'],
  114. // 默认顺时针
  115. clockwise: true,
  116. startAngle: 90,
  117. // 最小角度改为0
  118. minAngle: 0,
  119. // If still show when all data zero.
  120. stillShowZeroSum: true,
  121. // 'rootToNode', 'link', or false
  122. nodeClick: 'rootToNode',
  123. renderLabelForZeroData: false,
  124. label: {
  125. // could be: 'radial', 'tangential', or 'none'
  126. rotate: 'radial',
  127. show: true,
  128. opacity: 1,
  129. // 'left' is for inner side of inside, and 'right' is for outer
  130. // side for inside
  131. align: 'center',
  132. position: 'inside',
  133. distance: 5,
  134. silent: true
  135. },
  136. itemStyle: {
  137. borderWidth: 1,
  138. borderColor: 'white',
  139. borderType: 'solid',
  140. shadowBlur: 0,
  141. shadowColor: 'rgba(0, 0, 0, 0.2)',
  142. shadowOffsetX: 0,
  143. shadowOffsetY: 0,
  144. opacity: 1
  145. },
  146. emphasis: {
  147. focus: 'descendant'
  148. },
  149. blur: {
  150. itemStyle: {
  151. opacity: 0.2
  152. },
  153. label: {
  154. opacity: 0.1
  155. }
  156. },
  157. // Animation type can be expansion, scale.
  158. animationType: 'expansion',
  159. animationDuration: 1000,
  160. animationDurationUpdate: 500,
  161. data: [],
  162. /**
  163. * Sort order.
  164. *
  165. * Valid values: 'desc', 'asc', null, or callback function.
  166. * 'desc' and 'asc' for descend and ascendant order;
  167. * null for not sorting;
  168. * example of callback function:
  169. * function(nodeA, nodeB) {
  170. * return nodeA.getValue() - nodeB.getValue();
  171. * }
  172. */
  173. sort: 'desc'
  174. };
  175. return SunburstSeriesModel;
  176. }(SeriesModel);
  177. function completeTreeValue(dataNode) {
  178. // Postorder travel tree.
  179. // If value of none-leaf node is not set,
  180. // calculate it by suming up the value of all children.
  181. var sum = 0;
  182. zrUtil.each(dataNode.children, function (child) {
  183. completeTreeValue(child);
  184. var childValue = child.value;
  185. // TODO First value of array must be a number
  186. zrUtil.isArray(childValue) && (childValue = childValue[0]);
  187. sum += childValue;
  188. });
  189. var thisValue = dataNode.value;
  190. if (zrUtil.isArray(thisValue)) {
  191. thisValue = thisValue[0];
  192. }
  193. if (thisValue == null || isNaN(thisValue)) {
  194. thisValue = sum;
  195. }
  196. // Value should not less than 0.
  197. if (thisValue < 0) {
  198. thisValue = 0;
  199. }
  200. zrUtil.isArray(dataNode.value) ? dataNode.value[0] = thisValue : dataNode.value = thisValue;
  201. }
  202. export default SunburstSeriesModel;