UNPKG

4.4 kBPlain TextView Raw
1/**
2 * Copyright (c) 2017 ~ present NAVER Corp.
3 * billboard.js project is licensed under the MIT license
4 */
5import Chart from "../../Chart/Chart";
6import ChartInternal from "../../ChartInternal/ChartInternal";
7import Options from "../Options/Options";
8import {TYPE} from "../const";
9import {extend} from "../../module/util";
10
11// Axis
12import {
13 api as axisAPI,
14 internal as axisInternal,
15 options as axisOptions
16} from "./axis";
17
18// Shape
19import shapeArc from "../../ChartInternal/shape/arc";
20import shapeArea from "../../ChartInternal/shape/area";
21import shapeBar from "../../ChartInternal/shape/bar";
22import shapeCandlestick from "../../ChartInternal/shape/candlestick";
23import shapeGauge from "../../ChartInternal/shape/gauge";
24import shapeBubble from "../../ChartInternal/shape/bubble";
25import shapeLine from "../../ChartInternal/shape/line";
26import shapePoint from "../../ChartInternal/shape/point";
27import shapeRadar from "../../ChartInternal/shape/radar";
28
29// Options
30import optPoint from "../Options/common/point";
31import optArea from "../Options/shape/area";
32import optBar from "../Options/shape/bar";
33import optBubble from "../Options/shape/bubble";
34import optCandlestick from "../Options/shape/candlestick";
35import optLine from "../Options/shape/line";
36import optScatter from "../Options/shape/scatter";
37import optSpline from "../Options/shape/spline";
38
39// Non-Axis based
40import optDonut from "../Options/shape/donut";
41import optGauge from "../Options/shape/gauge";
42import optPie from "../Options/shape/pie";
43import optRadar from "../Options/shape/radar";
44
45export {
46 area,
47 areaLineRange,
48 areaSpline,
49 areaSplineRange,
50 areaStep,
51 bar,
52 bubble,
53 candlestick,
54 donut,
55 gauge,
56 line,
57 pie,
58 radar,
59 scatter,
60 spline,
61 step
62};
63
64/**
65 * Extend Axis
66 * @param {Array} module Module to be extended
67 * @param {Array} option Option object to be extended
68 * @private
69 */
70function extendAxis(module, option?): void {
71 extend(ChartInternal.prototype, axisInternal.concat(module));
72 extend(Chart.prototype, axisAPI);
73 Options.setOptions(axisOptions.concat(option || []));
74}
75
76/**
77 * Extend Line type modules
78 * @param {object} module Module to be extended
79 * @param {Array} option Option object to be extended
80 * @private
81 */
82function extendLine(module?, option?): void {
83 extendAxis([shapePoint, shapeLine].concat(module || []));
84 Options.setOptions([optPoint, optLine].concat(option || []));
85}
86
87/**
88 * Extend Arc type modules
89 * @param {Array} module Module to be extended
90 * @param {Array} option Option object to be extended
91 * @private
92 */
93function extendArc(module?, option?): void {
94 extend(ChartInternal.prototype, [shapeArc].concat(module || []));
95 Options.setOptions(option);
96}
97
98// Area types
99let area = (): string => (
100 extendLine(shapeArea, [optArea]), (area = () => TYPE.AREA)()
101);
102let areaLineRange = (): string => (
103 extendLine(shapeArea, [optArea]), (areaLineRange = () => TYPE.AREA_LINE_RANGE)()
104);
105let areaSpline = () => (
106 extendLine(shapeArea, [optArea, optSpline]), (areaSpline = () => TYPE.AREA_SPLINE)()
107);
108let areaSplineRange = (): string => (
109 extendLine(shapeArea, [optArea, optSpline]), (areaSplineRange = () => TYPE.AREA_SPLINE_RANGE)()
110);
111let areaStep = (): string => (
112 extendLine(shapeArea, [optArea]), (areaStep = () => TYPE.AREA_STEP)()
113);
114
115// Line types
116let line = (): string => (extendLine(), (line = () => TYPE.LINE)());
117let spline = (): string => (extendLine(undefined, [optSpline]), (spline = () => TYPE.SPLINE)());
118let step = (): string => (extendLine(), (step = () => TYPE.STEP)());
119
120// Arc types
121let donut = (): string => (extendArc(undefined, [optDonut]), (donut = () => TYPE.DONUT)());
122let gauge = (): string => (extendArc([shapeGauge], [optGauge]), (gauge = () => TYPE.GAUGE)());
123let pie = (): string => (extendArc(undefined, [optPie]), (pie = () => TYPE.PIE)());
124let radar = (): string => (
125 extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = () => TYPE.RADAR)()
126);
127
128// Axis based types
129let bar = (): string => (extendAxis([shapeBar], optBar), (bar = () => TYPE.BAR)());
130let bubble = (): string => (
131 extendAxis([shapePoint, shapeBubble], [optBubble, optPoint]), (bubble = () => TYPE.BUBBLE)()
132);
133let candlestick = (): string => (
134 extendAxis([shapeCandlestick], [optCandlestick]), (candlestick = () => TYPE.CANDLESTICK)()
135);
136let scatter = (): string => (
137 extendAxis([shapePoint], [optPoint, optScatter]), (scatter = () => TYPE.SCATTER)()
138);