FunnelSeries.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var echarts = require("../../echarts");
  2. var List = require("../../data/List");
  3. var _model = require("../../util/model");
  4. var defaultEmphasis = _model.defaultEmphasis;
  5. var completeDimensions = require("../../data/helper/completeDimensions");
  6. var FunnelSeries = echarts.extendSeriesModel({
  7. type: 'series.funnel',
  8. init: function (option) {
  9. FunnelSeries.superApply(this, 'init', arguments); // Enable legend selection for each data item
  10. // Use a function instead of direct access because data reference may changed
  11. this.legendDataProvider = function () {
  12. return this.getRawData();
  13. }; // Extend labelLine emphasis
  14. this._defaultLabelLine(option);
  15. },
  16. getInitialData: function (option, ecModel) {
  17. var dimensions = completeDimensions(['value'], option.data);
  18. var list = new List(dimensions, this);
  19. list.initData(option.data);
  20. return list;
  21. },
  22. _defaultLabelLine: function (option) {
  23. // Extend labelLine emphasis
  24. defaultEmphasis(option.labelLine, ['show']);
  25. var labelLineNormalOpt = option.labelLine.normal;
  26. var labelLineEmphasisOpt = option.labelLine.emphasis; // Not show label line if `label.normal.show = false`
  27. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.normal.show;
  28. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.label.emphasis.show;
  29. },
  30. // Overwrite
  31. getDataParams: function (dataIndex) {
  32. var data = this.getData();
  33. var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
  34. var sum = data.getSum('value'); // Percent is 0 if sum is 0
  35. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  36. params.$vars.push('percent');
  37. return params;
  38. },
  39. defaultOption: {
  40. zlevel: 0,
  41. // 一级层叠
  42. z: 2,
  43. // 二级层叠
  44. legendHoverLink: true,
  45. left: 80,
  46. top: 60,
  47. right: 80,
  48. bottom: 60,
  49. // width: {totalWidth} - left - right,
  50. // height: {totalHeight} - top - bottom,
  51. // 默认取数据最小最大值
  52. // min: 0,
  53. // max: 100,
  54. minSize: '0%',
  55. maxSize: '100%',
  56. sort: 'descending',
  57. // 'ascending', 'descending'
  58. gap: 0,
  59. funnelAlign: 'center',
  60. label: {
  61. normal: {
  62. show: true,
  63. position: 'outer' // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  64. },
  65. emphasis: {
  66. show: true
  67. }
  68. },
  69. labelLine: {
  70. normal: {
  71. show: true,
  72. length: 20,
  73. lineStyle: {
  74. // color: 各异,
  75. width: 1,
  76. type: 'solid'
  77. }
  78. },
  79. emphasis: {}
  80. },
  81. itemStyle: {
  82. normal: {
  83. // color: 各异,
  84. borderColor: '#fff',
  85. borderWidth: 1
  86. },
  87. emphasis: {// color: 各异,
  88. }
  89. }
  90. }
  91. });
  92. var _default = FunnelSeries;
  93. module.exports = _default;