FunnelSeries.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 * as zrUtil from 'zrender/lib/core/util.js';
  42. import createSeriesDataSimply from '../helper/createSeriesDataSimply.js';
  43. import { defaultEmphasis } from '../../util/model.js';
  44. import { makeSeriesEncodeForNameBased } from '../../data/helper/sourceHelper.js';
  45. import LegendVisualProvider from '../../visual/LegendVisualProvider.js';
  46. import SeriesModel from '../../model/Series.js';
  47. var FunnelSeriesModel =
  48. /** @class */
  49. function (_super) {
  50. __extends(FunnelSeriesModel, _super);
  51. function FunnelSeriesModel() {
  52. var _this = _super !== null && _super.apply(this, arguments) || this;
  53. _this.type = FunnelSeriesModel.type;
  54. return _this;
  55. }
  56. FunnelSeriesModel.prototype.init = function (option) {
  57. _super.prototype.init.apply(this, arguments); // Enable legend selection for each data item
  58. // Use a function instead of direct access because data reference may changed
  59. this.legendVisualProvider = new LegendVisualProvider(zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this)); // Extend labelLine emphasis
  60. this._defaultLabelLine(option);
  61. };
  62. FunnelSeriesModel.prototype.getInitialData = function (option, ecModel) {
  63. return createSeriesDataSimply(this, {
  64. coordDimensions: ['value'],
  65. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  66. });
  67. };
  68. FunnelSeriesModel.prototype._defaultLabelLine = function (option) {
  69. // Extend labelLine emphasis
  70. defaultEmphasis(option, 'labelLine', ['show']);
  71. var labelLineNormalOpt = option.labelLine;
  72. var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
  73. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  74. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  75. }; // Overwrite
  76. FunnelSeriesModel.prototype.getDataParams = function (dataIndex) {
  77. var data = this.getData();
  78. var params = _super.prototype.getDataParams.call(this, dataIndex);
  79. var valueDim = data.mapDimension('value');
  80. var sum = data.getSum(valueDim); // Percent is 0 if sum is 0
  81. params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
  82. params.$vars.push('percent');
  83. return params;
  84. };
  85. FunnelSeriesModel.type = 'series.funnel';
  86. FunnelSeriesModel.defaultOption = {
  87. // zlevel: 0, // 一级层叠
  88. z: 2,
  89. legendHoverLink: true,
  90. colorBy: 'data',
  91. left: 80,
  92. top: 60,
  93. right: 80,
  94. bottom: 60,
  95. // width: {totalWidth} - left - right,
  96. // height: {totalHeight} - top - bottom,
  97. // 默认取数据最小最大值
  98. // min: 0,
  99. // max: 100,
  100. minSize: '0%',
  101. maxSize: '100%',
  102. sort: 'descending',
  103. orient: 'vertical',
  104. gap: 0,
  105. funnelAlign: 'center',
  106. label: {
  107. show: true,
  108. position: 'outer' // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  109. },
  110. labelLine: {
  111. show: true,
  112. length: 20,
  113. lineStyle: {
  114. // color: 各异,
  115. width: 1
  116. }
  117. },
  118. itemStyle: {
  119. // color: 各异,
  120. borderColor: '#fff',
  121. borderWidth: 1
  122. },
  123. emphasis: {
  124. label: {
  125. show: true
  126. }
  127. },
  128. select: {
  129. itemStyle: {
  130. borderColor: '#212121'
  131. }
  132. }
  133. };
  134. return FunnelSeriesModel;
  135. }(SeriesModel);
  136. export default FunnelSeriesModel;