-
Notifications
You must be signed in to change notification settings - Fork 345
/
shape.ts
142 lines (130 loc) 路 4.5 KB
/
shape.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
*/
import Chart from "../../Chart/Chart";
import ChartInternal from "../../ChartInternal/ChartInternal";
import Options from "../Options/Options";
import {TYPE} from "../const";
import {extend} from "../../module/util";
// Axis
import {
api as axisAPI,
internal as axisInternal,
options as axisOptions
} from "./axis";
// Shape
import shapeArc from "../../ChartInternal/shape/arc";
import shapeArea from "../../ChartInternal/shape/area";
import shapeBar from "../../ChartInternal/shape/bar";
import shapeCandlestick from "../../ChartInternal/shape/candlestick";
import shapeGauge from "../../ChartInternal/shape/gauge";
import shapeBubble from "../../ChartInternal/shape/bubble";
import shapeLine from "../../ChartInternal/shape/line";
import shapePoint from "../../ChartInternal/shape/point";
import shapePolar from "../../ChartInternal/shape/polar";
import shapeRadar from "../../ChartInternal/shape/radar";
// Options
import optPoint from "../Options/common/point";
import optArea from "../Options/shape/area";
import optBar from "../Options/shape/bar";
import optBubble from "../Options/shape/bubble";
import optCandlestick from "../Options/shape/candlestick";
import optLine from "../Options/shape/line";
import optScatter from "../Options/shape/scatter";
import optSpline from "../Options/shape/spline";
// Non-Axis based
import optDonut from "../Options/shape/donut";
import optGauge from "../Options/shape/gauge";
import optPie from "../Options/shape/pie";
import optPolar from "../Options/shape/polar";
import optRadar from "../Options/shape/radar";
export {
area,
areaLineRange,
areaSpline,
areaSplineRange,
areaStep,
bar,
bubble,
candlestick,
donut,
gauge,
line,
pie,
polar,
radar,
scatter,
spline,
step
};
/**
* Extend Axis
* @param {Array} module Module to be extended
* @param {Array} option Option object to be extended
* @private
*/
function extendAxis(module, option?): void {
extend(ChartInternal.prototype, axisInternal.concat(module));
extend(Chart.prototype, axisAPI);
Options.setOptions(axisOptions.concat(option || []));
}
/**
* Extend Line type modules
* @param {object} module Module to be extended
* @param {Array} option Option object to be extended
* @private
*/
function extendLine(module?, option?): void {
extendAxis([shapePoint, shapeLine].concat(module || []));
Options.setOptions([optPoint, optLine].concat(option || []));
}
/**
* Extend Arc type modules
* @param {Array} module Module to be extended
* @param {Array} option Option object to be extended
* @private
*/
function extendArc(module?, option?): void {
extend(ChartInternal.prototype, [shapeArc].concat(module || []));
Options.setOptions(option);
}
// Area types
let area = (): string => (
extendLine(shapeArea, [optArea]), (area = () => TYPE.AREA)()
);
let areaLineRange = (): string => (
extendLine(shapeArea, [optArea]), (areaLineRange = () => TYPE.AREA_LINE_RANGE)()
);
let areaSpline = () => (
extendLine(shapeArea, [optArea, optSpline]), (areaSpline = () => TYPE.AREA_SPLINE)()
);
let areaSplineRange = (): string => (
extendLine(shapeArea, [optArea, optSpline]), (areaSplineRange = () => TYPE.AREA_SPLINE_RANGE)()
);
let areaStep = (): string => (
extendLine(shapeArea, [optArea]), (areaStep = () => TYPE.AREA_STEP)()
);
// Line types
let line = (): string => (extendLine(), (line = () => TYPE.LINE)());
let spline = (): string => (extendLine(undefined, [optSpline]), (spline = () => TYPE.SPLINE)());
let step = (): string => (extendLine(), (step = () => TYPE.STEP)());
// Arc types
let donut = (): string => (extendArc(undefined, [optDonut]), (donut = () => TYPE.DONUT)());
let gauge = (): string => (extendArc([shapeGauge], [optGauge]), (gauge = () => TYPE.GAUGE)());
let pie = (): string => (extendArc(undefined, [optPie]), (pie = () => TYPE.PIE)());
let polar = (): string => (extendArc([shapePolar], [optPolar]), (polar = () => TYPE.POLAR)());
let radar = (): string => (
extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = () => TYPE.RADAR)()
);
// Axis based types
let bar = (): string => (extendAxis([shapeBar], optBar), (bar = () => TYPE.BAR)());
let bubble = (): string => (
extendAxis([shapePoint, shapeBubble], [optBubble, optPoint]), (bubble = () => TYPE.BUBBLE)()
);
let candlestick = (): string => (
extendAxis([shapeCandlestick], [optCandlestick]), (candlestick = () => TYPE.CANDLESTICK)()
);
let scatter = (): string => (
extendAxis([shapePoint], [optPoint, optScatter]), (scatter = () => TYPE.SCATTER)()
);