AxisModel.ts 2.9 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 zrUtil from 'zrender/src/core/util';
S
sushuang 已提交
21 22
import ComponentModel from '../../model/Component';
import axisModelCreator from '../axisModelCreator';
1
100pah 已提交
23
import {AxisModelCommonMixin} from '../axisModelCommonMixin';
P
pissang 已提交
24 25 26
import { AxisBaseOption } from '../axisCommonTypes';
import AngleAxis from './AngleAxis';
import RadiusAxis from './RadiusAxis';
L
lang 已提交
27

P
pissang 已提交
28 29 30 31 32 33 34 35 36
export interface AngleAxisOption extends AxisBaseOption {
    /**
     * Index of host polar component
     */
    polarIndex?: number
    /**
     * Id of host polar component
     */
    polarId?: string
L
lang 已提交
37

P
pissang 已提交
38 39
    startAngle?: number
    clockwise?: boolean
40

P
pissang 已提交
41 42 43 44 45 46 47 48
    splitNumber?: number

    axisLabel?: Omit<AxisBaseOption['axisLabel'], 'rotate'> & {
        rotate?: AxisBaseOption['axisLabel']['rotate'] | false
    }
}

export interface RadiusAxisOption extends AxisBaseOption {
S
sushuang 已提交
49
    /**
P
pissang 已提交
50
     * Index of host polar component
S
sushuang 已提交
51
     */
P
pissang 已提交
52
    polarIndex?: number
S
sushuang 已提交
53
    /**
P
pissang 已提交
54
     * Id of host polar component
S
sushuang 已提交
55
     */
P
pissang 已提交
56 57 58 59 60 61 62 63 64
    polarId?: string
}

type PolarAxisOption = AngleAxisOption | RadiusAxisOption;

class PolarAxisModel<T extends PolarAxisOption = PolarAxisOption> extends ComponentModel<T> {
    static type = 'polarAxis'

    getCoordSysModel(): ComponentModel {
S
sushuang 已提交
65 66 67 68 69 70
        return this.ecModel.queryComponents({
            mainType: 'polar',
            index: this.option.polarIndex,
            id: this.option.polarId
        })[0];
    }
P
pissang 已提交
71
}
L
lang 已提交
72

P
pissang 已提交
73
interface PolarAxisModel<T extends PolarAxisOption = PolarAxisOption> extends AxisModelCommonMixin<T> {}
1
100pah 已提交
74
zrUtil.mixin(PolarAxisModel, AxisModelCommonMixin);
P
pah100 已提交
75

P
pissang 已提交
76
export {PolarAxisModel};
77

P
pissang 已提交
78 79 80 81 82 83
export class AngleAxisModel extends PolarAxisModel<AngleAxisOption> {
    axis: AngleAxis
}
export class RadiusAxisModel extends PolarAxisModel<RadiusAxisOption> {
    axis: RadiusAxis
}
L
lang 已提交
84

P
pissang 已提交
85
ComponentModel.registerClass(PolarAxisModel);
L
lang 已提交
86

P
pissang 已提交
87 88
const angleAxisExtraOption: AngleAxisOption = {
    startAngle: 90,
P
pah100 已提交
89

P
pissang 已提交
90
    clockwise: true,
L
lang 已提交
91

P
pissang 已提交
92 93 94 95
    splitNumber: 12,

    axisLabel: {
        rotate: false
L
lang 已提交
96
    }
S
sushuang 已提交
97
};
L
lang 已提交
98

P
pissang 已提交
99 100 101 102 103 104 105
const radiusAxisExtraOption: RadiusAxisOption = {
    splitNumber: 5
};


axisModelCreator('angle', AngleAxisModel, angleAxisExtraOption);
axisModelCreator('radius', RadiusAxisModel, radiusAxisExtraOption);