RadarSeries.ts 4.8 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 SeriesModel from '../../model/Series';
21
import createListSimply from '../helper/createListSimply';
S
sushuang 已提交
22
import * as zrUtil from 'zrender/src/core/util';
S
sushuang 已提交
23
import {encodeHTML} from '../../util/format';
24
import LegendVisualProvider from '../../visual/LegendVisualProvider';
P
pissang 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
import {
    SeriesOption,
    LineStyleOption,
    LabelOption,
    SymbolOptionMixin,
    ItemStyleOption,
    AreaStyleOption,
    OptionDataValue
} from '../../util/types';
import GlobalModel from '../../model/Global';
import List from '../../data/List';
import Radar from '../../coord/radar/Radar';

type RadarSeriesDataValue = OptionDataValue[];

export interface RadarSeriesDataItemOption extends SymbolOptionMixin {
    lineStyle?: LineStyleOption
    areaStyle?: AreaStyleOption
    label?: LabelOption
    itemStyle?: ItemStyleOption

    emphasis?: {
        lineStyle?: LineStyleOption
        areaStyle?: AreaStyleOption
        label?: LabelOption
        itemStyle?: ItemStyleOption
    }

    value?: RadarSeriesDataValue
}

export interface RadarSeriesOption extends SeriesOption, SymbolOptionMixin {
    type?: 'radar'
    coordinateSystem: 'radar'

    radarIndex?: number
    radarId?: string
L
lang 已提交
62

P
pissang 已提交
63 64 65 66
    lineStyle?: LineStyleOption
    areaStyle?: AreaStyleOption
    label?: LabelOption
    itemStyle?: ItemStyleOption
L
lang 已提交
67

P
pissang 已提交
68 69 70 71 72 73 74 75 76
    emphasis?: {
        lineStyle?: LineStyleOption
        areaStyle?: AreaStyleOption
        label?: LabelOption
        itemStyle?: ItemStyleOption
    }
}

class RadarSeriesModel extends SeriesModel<RadarSeriesOption> {
L
lang 已提交
77

P
pissang 已提交
78 79
    static readonly type = 'series.radar'
    readonly type = RadarSeriesModel.type
L
lang 已提交
80

P
pissang 已提交
81 82 83
    dependencies = ['radar']

    coordinateSystem: Radar
L
lang 已提交
84

S
sushuang 已提交
85
    // Overwrite
P
pissang 已提交
86 87
    init(option: RadarSeriesOption) {
        super.init.apply(this, arguments as any);
L
lang 已提交
88

S
sushuang 已提交
89 90
        // Enable legend selection for each data item
        // Use a function instead of direct access because data reference may changed
91 92 93 94
        this.legendVisualProvider = new LegendVisualProvider(
            zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this)
        );

P
pissang 已提交
95
    }
96

P
pissang 已提交
97
    getInitialData(option: RadarSeriesOption, ecModel: GlobalModel): List {
98
        return createListSimply(this, {
S
sushuang 已提交
99 100
            generateCoord: 'indicator_',
            generateCoordCount: Infinity
101
        });
P
pissang 已提交
102
    }
L
lang 已提交
103

P
pissang 已提交
104
    formatTooltip(dataIndex: number) {
105
        var data = this.getData();
S
sushuang 已提交
106 107 108
        var coordSys = this.coordinateSystem;
        var indicatorAxes = coordSys.getIndicatorAxes();
        var name = this.getData().getName(dataIndex);
S
sushuang 已提交
109
        return encodeHTML(name === '' ? this.name : name) + '<br/>'
S
sushuang 已提交
110
            + zrUtil.map(indicatorAxes, function (axis, idx) {
111 112
                var val = data.get(data.mapDimension(axis.dim), dataIndex);
                return encodeHTML(axis.name + ' : ' + val);
S
sushuang 已提交
113
            }).join('<br />');
P
pissang 已提交
114
    }
L
lang 已提交
115

116 117 118
    /**
     * @implement
     */
P
pissang 已提交
119
    getTooltipPosition(dataIndex: number) {
120 121 122 123 124 125
        if (dataIndex != null) {
            var data = this.getData();
            var coordSys = this.coordinateSystem;
            var values = data.getValues(
                zrUtil.map(coordSys.dimensions, function (dim) {
                    return data.mapDimension(dim);
P
pissang 已提交
126
                }), dataIndex
127 128 129
            );

            for (var i = 0, len = values.length; i < len; i++) {
P
pissang 已提交
130
                if (!isNaN(values[i] as number)) {
131 132
                    var indicatorAxes = coordSys.getIndicatorAxes();
                    return coordSys.coordToPoint(indicatorAxes[i].dataToCoord(values[i]), i);
133 134 135
                }
            }
        }
P
pissang 已提交
136
    }
137

P
pissang 已提交
138
    static defaultOption: RadarSeriesOption = {
S
sushuang 已提交
139 140 141 142 143 144
        zlevel: 0,
        z: 2,
        coordinateSystem: 'radar',
        legendHoverLink: true,
        radarIndex: 0,
        lineStyle: {
145 146
            width: 2,
            type: 'solid'
L
lang 已提交
147
        },
S
sushuang 已提交
148
        label: {
149
            position: 'top'
L
lang 已提交
150
        },
S
sushuang 已提交
151 152 153 154 155 156 157
        // areaStyle: {
        // },
        // itemStyle: {}
        symbol: 'emptyCircle',
        symbolSize: 4
        // symbolRotate: null
    }
P
pissang 已提交
158 159 160
}

SeriesModel.registerClass(RadarSeriesModel);
L
lang 已提交
161

P
pissang 已提交
162
export default RadarSeriesModel;