PieSeries.js 7.7 KB

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