FunnelSeries.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. var echarts = require("../../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var bind = zrUtil.bind;
  22. var createListSimply = require("../helper/createListSimply");
  23. var _model = require("../../util/model");
  24. var defaultEmphasis = _model.defaultEmphasis;
  25. var _sourceHelper = require("../../data/helper/sourceHelper");
  26. var makeSeriesEncodeForNameBased = _sourceHelper.makeSeriesEncodeForNameBased;
  27. var LegendVisualProvider = require("../../visual/LegendVisualProvider");
  28. /*
  29. * Licensed to the Apache Software Foundation (ASF) under one
  30. * or more contributor license agreements. See the NOTICE file
  31. * distributed with this work for additional information
  32. * regarding copyright ownership. The ASF licenses this file
  33. * to you under the Apache License, Version 2.0 (the
  34. * "License"); you may not use this file except in compliance
  35. * with the License. You may obtain a copy of the License at
  36. *
  37. * http://www.apache.org/licenses/LICENSE-2.0
  38. *
  39. * Unless required by applicable law or agreed to in writing,
  40. * software distributed under the License is distributed on an
  41. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42. * KIND, either express or implied. See the License for the
  43. * specific language governing permissions and limitations
  44. * under the License.
  45. */
  46. var FunnelSeries = echarts.extendSeriesModel({
  47. type: 'series.funnel',
  48. init: function (option) {
  49. FunnelSeries.superApply(this, 'init', arguments); // Enable legend selection for each data item
  50. // Use a function instead of direct access because data reference may changed
  51. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this)); // Extend labelLine emphasis
  52. this._defaultLabelLine(option);
  53. },
  54. getInitialData: function (option, ecModel) {
  55. return createListSimply(this, {
  56. coordDimensions: ['value'],
  57. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  58. });
  59. },
  60. _defaultLabelLine: function (option) {
  61. // Extend labelLine emphasis
  62. defaultEmphasis(option, 'labelLine', ['show']);
  63. var labelLineNormalOpt = option.labelLine;
  64. var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
  65. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  66. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  67. },
  68. // Overwrite
  69. getDataParams: function (dataIndex) {
  70. var data = this.getData();
  71. var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
  72. var valueDim = data.mapDimension('value');
  73. var sum = data.getSum(valueDim); // Percent is 0 if sum is 0
  74. params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
  75. params.$vars.push('percent');
  76. return params;
  77. },
  78. defaultOption: {
  79. zlevel: 0,
  80. // 一级层叠
  81. z: 2,
  82. // 二级层叠
  83. legendHoverLink: true,
  84. left: 80,
  85. top: 60,
  86. right: 80,
  87. bottom: 60,
  88. // width: {totalWidth} - left - right,
  89. // height: {totalHeight} - top - bottom,
  90. // 默认取数据最小最大值
  91. // min: 0,
  92. // max: 100,
  93. minSize: '0%',
  94. maxSize: '100%',
  95. sort: 'descending',
  96. // 'ascending', 'descending'
  97. gap: 0,
  98. funnelAlign: 'center',
  99. label: {
  100. show: true,
  101. position: 'outer' // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  102. },
  103. labelLine: {
  104. show: true,
  105. length: 20,
  106. lineStyle: {
  107. // color: 各异,
  108. width: 1,
  109. type: 'solid'
  110. }
  111. },
  112. itemStyle: {
  113. // color: 各异,
  114. borderColor: '#fff',
  115. borderWidth: 1
  116. },
  117. emphasis: {
  118. label: {
  119. show: true
  120. }
  121. }
  122. }
  123. });
  124. var _default = FunnelSeries;
  125. module.exports = _default;