From acebe19813eefe000805be350b3c8bfd77eb22be Mon Sep 17 00:00:00 2001 From: yoooz Date: Mon, 23 May 2022 00:53:36 +0900 Subject: [PATCH] fix: create chart type definition (#825) --- legacy/src/Charts.js | 145 +++++++++++++++++++++++++++++++++++++++++++ legacy/src/index.js | 26 ++++++++ 2 files changed, 171 insertions(+) diff --git a/legacy/src/Charts.js b/legacy/src/Charts.js index 7a858811..68b22b06 100644 --- a/legacy/src/Charts.js +++ b/legacy/src/Charts.js @@ -25,6 +25,130 @@ import { const ANNOTATION_PLUGIN_KEY = 'annotation' +export class ChartDataProps { + /** @type object */ + type + /** @type boolean */ + required +} + +export class StringProps { + /** @type string */ + type + /** @type string */ + default +} + +export class ObjectProps { + /** @type object */ + type + /** @type () => {} */ + default +} + +export class NumberProps { + /** @type number */ + type + /** @type number */ + default +} + +export class ArrayProps { + /** @type array */ + type + /** @type () => [] */ + default +} + +export class ChartProps { + /** @type ChartDataProps */ + chartData + /** @type ObjectProps */ + chartOptions + /** @type StringProps */ + datasetIdKey + /** @type StringProps */ + chartId + /** @type NumberProps */ + width + /** @type NumberProps */ + height + /** @type StringProps */ + cssClasses + /** @type ObjectProps */ + styles + /** @type */ + plugins +} + +export class ChartDatas { + /** @type null */ + _chart +} + +export class ChartComputed { + /** @type () => boolean */ + hasAnnotationPlugin +} + +export class WatchChartData { + /** @type (any, any) => void */ + handler + /** @type boolean */ + deep +} + +export class WatchChartOptions { + /** @type (any) => void */ + handler + /** @type boolean */ + deep +} + +export class ChartWatchs { + /** @type WatchChartData */ + chartData + /** @type WatchChartOptions */ + chartOptions +} + +export class ChartMethods { + /** @type (any, any) => void */ + renderChart + /** @type (any, any) => void */ + chartDataHandler + /** @type (any) => void */ + chartOptionsHandler + /** @type () => void */ + updateChart + /** @type () => any */ + getCurrentChart + /** @type (any) => void */ + setCurrentChart +} + +export class TypedChart { + /** @type ChartProps */ + props + /** @type ChartDatas */ + data + /** @type ChartComputed */ + comuted + /** @type () => void */ + created + /** @type () => void */ + mounted + /** @type ChartWatchs */ + watch + /** @type ChartMethods */ + methods + /** @type () => void */ + beforeDestroy + /** @type (any) => void */ + render +} + +/** @type TypedChart */ export function generateChart(chartId, chartType, chartController) { let _chartRef = null @@ -223,48 +347,56 @@ export function generateChart(chartId, chartType, chartController) { } } +/** @type TypedChart */ export const Bar = /* #__PURE__ */ generateChart( 'bar-chart', 'bar', BarController ) +/** @type TypedChart */ export const Doughnut = /* #__PURE__ */ generateChart( 'doughnut-chart', 'doughnut', DoughnutController ) +/** @type TypedChart */ export const Line = /* #__PURE__ */ generateChart( 'line-chart', 'line', LineController ) +/** @type TypedChart */ export const Pie = /* #__PURE__ */ generateChart( 'pie-chart', 'pie', PieController ) +/** @type TypedChart */ export const PolarArea = /* #__PURE__ */ generateChart( 'polar-chart', 'polarArea', PolarAreaController ) +/** @type TypedChart */ export const Radar = /* #__PURE__ */ generateChart( 'radar-chart', 'radar', RadarController ) +/** @type TypedChart */ export const Bubble = /* #__PURE__ */ generateChart( 'bubble-chart', 'bubble', BubbleController ) +/** @type TypedChart */ export const Scatter = /* #__PURE__ */ generateChart( 'scatter-chart', 'scatter', @@ -272,6 +404,19 @@ export const Scatter = /* #__PURE__ */ generateChart( ) export default { + ChartDataProps, + StringProps, + ObjectProps, + NumberProps, + ArrayProps, + ChartProps, + ChartDatas, + ChartComputed, + WatchChartData, + WatchChartOptions, + ChartWatchs, + ChartMethods, + TypedChart, Bar, Bubble, Doughnut, diff --git a/legacy/src/index.js b/legacy/src/index.js index c3d07b25..f656abbe 100644 --- a/legacy/src/index.js +++ b/legacy/src/index.js @@ -1,4 +1,17 @@ import { + ChartDataProps, + StringProps, + ObjectProps, + NumberProps, + ArrayProps, + ChartProps, + ChartDatas, + ChartComputed, + WatchChartData, + WatchChartOptions, + ChartWatchs, + ChartMethods, + TypedChart, Bar, Doughnut, Line, @@ -11,6 +24,19 @@ import { } from './Charts.js' export { + ChartDataProps, + StringProps, + ObjectProps, + NumberProps, + ArrayProps, + ChartProps, + ChartDatas, + ChartComputed, + WatchChartData, + WatchChartOptions, + ChartWatchs, + ChartMethods, + TypedChart, Bar, Doughnut, Line,