FunnelSeries.js 4.5 KB

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