PieSeries.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var echarts = require("../../echarts");
  2. var List = require("../../data/List");
  3. var zrUtil = require("zrender/lib/core/util");
  4. var modelUtil = require("../../util/model");
  5. var _number = require("../../util/number");
  6. var getPercentWithPrecision = _number.getPercentWithPrecision;
  7. var completeDimensions = require("../../data/helper/completeDimensions");
  8. var dataSelectableMixin = require("../../component/helper/selectableMixin");
  9. var PieSeries = echarts.extendSeriesModel({
  10. type: 'series.pie',
  11. // Overwrite
  12. init: function (option) {
  13. PieSeries.superApply(this, 'init', arguments); // Enable legend selection for each data item
  14. // Use a function instead of direct access because data reference may changed
  15. this.legendDataProvider = function () {
  16. return this.getRawData();
  17. };
  18. this.updateSelectedMap(option.data);
  19. this._defaultLabelLine(option);
  20. },
  21. // Overwrite
  22. mergeOption: function (newOption) {
  23. PieSeries.superCall(this, 'mergeOption', newOption);
  24. this.updateSelectedMap(this.option.data);
  25. },
  26. getInitialData: function (option, ecModel) {
  27. var dimensions = completeDimensions(['value'], option.data);
  28. var list = new List(dimensions, this);
  29. list.initData(option.data);
  30. return list;
  31. },
  32. // Overwrite
  33. getDataParams: function (dataIndex) {
  34. var data = this.getData();
  35. var params = PieSeries.superCall(this, 'getDataParams', dataIndex); // FIXME toFixed?
  36. var valueList = [];
  37. data.each('value', function (value) {
  38. valueList.push(value);
  39. });
  40. params.percent = getPercentWithPrecision(valueList, dataIndex, data.hostModel.get('percentPrecision'));
  41. params.$vars.push('percent');
  42. return params;
  43. },
  44. _defaultLabelLine: function (option) {
  45. // Extend labelLine emphasis
  46. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  47. var labelLineNormalOpt = option.labelLine.normal;
  48. var labelLineEmphasisOpt = option.labelLine.emphasis; // Not show label line if `label.normal.show = false`
  49. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.normal.show;
  50. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.label.emphasis.show;
  51. },
  52. defaultOption: {
  53. zlevel: 0,
  54. z: 2,
  55. legendHoverLink: true,
  56. hoverAnimation: true,
  57. // 默认全局居中
  58. center: ['50%', '50%'],
  59. radius: [0, '75%'],
  60. // 默认顺时针
  61. clockwise: true,
  62. startAngle: 90,
  63. // 最小角度改为0
  64. minAngle: 0,
  65. // 选中时扇区偏移量
  66. selectedOffset: 10,
  67. // 高亮扇区偏移量
  68. hoverOffset: 10,
  69. // If use strategy to avoid label overlapping
  70. avoidLabelOverlap: true,
  71. // 选择模式,默认关闭,可选single,multiple
  72. // selectedMode: false,
  73. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  74. // roseType: null,
  75. percentPrecision: 2,
  76. // If still show when all data zero.
  77. stillShowZeroSum: true,
  78. // cursor: null,
  79. label: {
  80. normal: {
  81. // If rotate around circle
  82. rotate: false,
  83. show: true,
  84. // 'outer', 'inside', 'center'
  85. position: 'outer' // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  86. // 默认使用全局文本样式,详见TEXTSTYLE
  87. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  88. },
  89. emphasis: {}
  90. },
  91. // Enabled when label.normal.position is 'outer'
  92. labelLine: {
  93. normal: {
  94. show: true,
  95. // 引导线两段中的第一段长度
  96. length: 15,
  97. // 引导线两段中的第二段长度
  98. length2: 15,
  99. smooth: false,
  100. lineStyle: {
  101. // color: 各异,
  102. width: 1,
  103. type: 'solid'
  104. }
  105. }
  106. },
  107. itemStyle: {
  108. normal: {
  109. borderWidth: 1
  110. },
  111. emphasis: {}
  112. },
  113. // Animation type canbe expansion, scale
  114. animationType: 'expansion',
  115. animationEasing: 'cubicOut',
  116. data: []
  117. }
  118. });
  119. zrUtil.mixin(PieSeries, dataSelectableMixin);
  120. var _default = PieSeries;
  121. module.exports = _default;