SunburstSeries.js 6.7 KB

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