PieSeries.js 7.8 KB

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