PieSeries.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 createSeriesDataSimply from '../helper/createSeriesDataSimply.js';
  42. import * as zrUtil from 'zrender/lib/core/util.js';
  43. import * as modelUtil from '../../util/model.js';
  44. import { getPercentSeats } from '../../util/number.js';
  45. import { makeSeriesEncodeForNameBased } from '../../data/helper/sourceHelper.js';
  46. import LegendVisualProvider from '../../visual/LegendVisualProvider.js';
  47. import SeriesModel from '../../model/Series.js';
  48. var innerData = modelUtil.makeInner();
  49. var PieSeriesModel =
  50. /** @class */
  51. function (_super) {
  52. __extends(PieSeriesModel, _super);
  53. function PieSeriesModel() {
  54. return _super !== null && _super.apply(this, arguments) || this;
  55. }
  56. /**
  57. * @overwrite
  58. */
  59. PieSeriesModel.prototype.init = function (option) {
  60. _super.prototype.init.apply(this, arguments); // Enable legend selection for each data item
  61. // Use a function instead of direct access because data reference may changed
  62. this.legendVisualProvider = new LegendVisualProvider(zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this));
  63. this._defaultLabelLine(option);
  64. };
  65. /**
  66. * @overwrite
  67. */
  68. PieSeriesModel.prototype.mergeOption = function () {
  69. _super.prototype.mergeOption.apply(this, arguments);
  70. };
  71. /**
  72. * @overwrite
  73. */
  74. PieSeriesModel.prototype.getInitialData = function () {
  75. return createSeriesDataSimply(this, {
  76. coordDimensions: ['value'],
  77. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  78. });
  79. };
  80. /**
  81. * @overwrite
  82. */
  83. PieSeriesModel.prototype.getDataParams = function (dataIndex) {
  84. var data = this.getData(); // update seats when data is changed
  85. var dataInner = innerData(data);
  86. var seats = dataInner.seats;
  87. if (!seats) {
  88. var valueList_1 = [];
  89. data.each(data.mapDimension('value'), function (value) {
  90. valueList_1.push(value);
  91. });
  92. seats = dataInner.seats = getPercentSeats(valueList_1, data.hostModel.get('percentPrecision'));
  93. }
  94. var params = _super.prototype.getDataParams.call(this, dataIndex); // seats may be empty when sum is 0
  95. params.percent = seats[dataIndex] || 0;
  96. params.$vars.push('percent');
  97. return params;
  98. };
  99. PieSeriesModel.prototype._defaultLabelLine = function (option) {
  100. // Extend labelLine emphasis
  101. modelUtil.defaultEmphasis(option, 'labelLine', ['show']);
  102. var labelLineNormalOpt = option.labelLine;
  103. var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
  104. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  105. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  106. };
  107. PieSeriesModel.type = 'series.pie';
  108. PieSeriesModel.defaultOption = {
  109. // zlevel: 0,
  110. z: 2,
  111. legendHoverLink: true,
  112. colorBy: 'data',
  113. // 默认全局居中
  114. center: ['50%', '50%'],
  115. radius: [0, '75%'],
  116. // 默认顺时针
  117. clockwise: true,
  118. startAngle: 90,
  119. // 最小角度改为0
  120. minAngle: 0,
  121. // If the angle of a sector less than `minShowLabelAngle`,
  122. // the label will not be displayed.
  123. minShowLabelAngle: 0,
  124. // 选中时扇区偏移量
  125. selectedOffset: 10,
  126. // 选择模式,默认关闭,可选single,multiple
  127. // selectedMode: false,
  128. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  129. // roseType: null,
  130. percentPrecision: 2,
  131. // If still show when all data zero.
  132. stillShowZeroSum: true,
  133. // cursor: null,
  134. left: 0,
  135. top: 0,
  136. right: 0,
  137. bottom: 0,
  138. width: null,
  139. height: null,
  140. label: {
  141. // color: 'inherit',
  142. // If rotate around circle
  143. rotate: 0,
  144. show: true,
  145. overflow: 'truncate',
  146. // 'outer', 'inside', 'center'
  147. position: 'outer',
  148. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  149. alignTo: 'none',
  150. // Closest distance between label and chart edge.
  151. // Works only position is 'outer' and alignTo is 'edge'.
  152. edgeDistance: '25%',
  153. // Works only position is 'outer' and alignTo is not 'edge'.
  154. bleedMargin: 10,
  155. // Distance between text and label line.
  156. distanceToLabelLine: 5 // formatter: 标签文本格式器,同 tooltip.formatter,不支持异步回调
  157. // 默认使用全局文本样式,详见 textStyle
  158. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  159. },
  160. // Enabled when label.normal.position is 'outer'
  161. labelLine: {
  162. show: true,
  163. // 引导线两段中的第一段长度
  164. length: 15,
  165. // 引导线两段中的第二段长度
  166. length2: 15,
  167. smooth: false,
  168. minTurnAngle: 90,
  169. maxSurfaceAngle: 90,
  170. lineStyle: {
  171. // color: 各异,
  172. width: 1,
  173. type: 'solid'
  174. }
  175. },
  176. itemStyle: {
  177. borderWidth: 1,
  178. borderJoin: 'round'
  179. },
  180. showEmptyCircle: true,
  181. emptyCircleStyle: {
  182. color: 'lightgray',
  183. opacity: 1
  184. },
  185. labelLayout: {
  186. // Hide the overlapped label.
  187. hideOverlap: true
  188. },
  189. emphasis: {
  190. scale: true,
  191. scaleSize: 5
  192. },
  193. // If use strategy to avoid label overlapping
  194. avoidLabelOverlap: true,
  195. // Animation type. Valid values: expansion, scale
  196. animationType: 'expansion',
  197. animationDuration: 1000,
  198. // Animation type when update. Valid values: transition, expansion
  199. animationTypeUpdate: 'transition',
  200. animationEasingUpdate: 'cubicInOut',
  201. animationDurationUpdate: 500,
  202. animationEasing: 'cubicInOut'
  203. };
  204. return PieSeriesModel;
  205. }(SeriesModel);
  206. export default PieSeriesModel;