FunnelSeries.js 4.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

S
sushuang 已提交
20
import * as echarts from '../../echarts';
S
fix:  
SHUANG SU 已提交
21
import * as zrUtil from 'zrender/src/core/util';
22
import createListSimply from '../helper/createListSimply';
S
sushuang 已提交
23
import {defaultEmphasis} from '../../util/model';
S
fix:  
SHUANG SU 已提交
24
import {makeSeriesEncodeForNameBased} from '../../data/helper/sourceHelper';
25
import LegendVisualProvider from '../../visual/LegendVisualProvider';
L
lang 已提交
26

S
sushuang 已提交
27
var FunnelSeries = echarts.extendSeriesModel({
L
lang 已提交
28

S
sushuang 已提交
29
    type: 'series.funnel',
L
lang 已提交
30

S
sushuang 已提交
31 32
    init: function (option) {
        FunnelSeries.superApply(this, 'init', arguments);
L
lang 已提交
33

S
sushuang 已提交
34 35
        // Enable legend selection for each data item
        // Use a function instead of direct access because data reference may changed
36
        this.legendVisualProvider = new LegendVisualProvider(
S
susiwen 已提交
37
            zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this)
38
        );
S
sushuang 已提交
39 40 41
        // Extend labelLine emphasis
        this._defaultLabelLine(option);
    },
L
lang 已提交
42

S
sushuang 已提交
43
    getInitialData: function (option, ecModel) {
S
fix:  
SHUANG SU 已提交
44 45 46 47
        return createListSimply(this, {
            coordDimensions: ['value'],
            encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
        });
S
sushuang 已提交
48
    },
L
lang 已提交
49

S
sushuang 已提交
50 51
    _defaultLabelLine: function (option) {
        // Extend labelLine emphasis
52
        defaultEmphasis(option, 'labelLine', ['show']);
L
lang 已提交
53

54 55
        var labelLineNormalOpt = option.labelLine;
        var labelLineEmphasisOpt = option.emphasis.labelLine;
S
sushuang 已提交
56 57
        // Not show label line if `label.normal.show = false`
        labelLineNormalOpt.show = labelLineNormalOpt.show
58
            && option.label.show;
S
sushuang 已提交
59
        labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
60
            && option.emphasis.label.show;
S
sushuang 已提交
61
    },
L
lang 已提交
62

S
sushuang 已提交
63 64 65 66
    // Overwrite
    getDataParams: function (dataIndex) {
        var data = this.getData();
        var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
67 68
        var valueDim = data.mapDimension('value');
        var sum = data.getSum(valueDim);
S
sushuang 已提交
69
        // Percent is 0 if sum is 0
70
        params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
L
Tweak  
lang 已提交
71

S
sushuang 已提交
72 73 74
        params.$vars.push('percent');
        return params;
    },
75

S
sushuang 已提交
76 77 78 79 80 81 82 83 84 85
    defaultOption: {
        zlevel: 0,                  // 一级层叠
        z: 2,                       // 二级层叠
        legendHoverLink: true,
        left: 80,
        top: 60,
        right: 80,
        bottom: 60,
        // width: {totalWidth} - left - right,
        // height: {totalHeight} - top - bottom,
L
Tweak  
lang 已提交
86

S
sushuang 已提交
87 88 89 90 91 92 93 94 95
        // 默认取数据最小最大值
        // min: 0,
        // max: 100,
        minSize: '0%',
        maxSize: '100%',
        sort: 'descending', // 'ascending', 'descending'
        gap: 0,
        funnelAlign: 'center',
        label: {
96 97 98
            show: true,
            position: 'outer'
            // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
99
        },
S
sushuang 已提交
100
        labelLine: {
101 102 103 104 105 106 107
            show: true,
            length: 20,
            lineStyle: {
                // color: 各异,
                width: 1,
                type: 'solid'
            }
S
sushuang 已提交
108 109
        },
        itemStyle: {
110 111 112 113 114 115 116
            // color: 各异,
            borderColor: '#fff',
            borderWidth: 1
        },
        emphasis: {
            label: {
                show: true
L
lang 已提交
117 118
            }
        }
S
sushuang 已提交
119
    }
120
});
S
sushuang 已提交
121 122

export default FunnelSeries;