Skip to content

Commit

Permalink
fix: create chart type definition (apertureless#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoooz authored and yoooz committed May 23, 2022
1 parent abce7dd commit acebe19
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
145 changes: 145 additions & 0 deletions legacy/src/Charts.js
Expand Up @@ -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

Expand Down Expand Up @@ -223,55 +347,76 @@ 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',
ScatterController
)

export default {
ChartDataProps,
StringProps,
ObjectProps,
NumberProps,
ArrayProps,
ChartProps,
ChartDatas,
ChartComputed,
WatchChartData,
WatchChartOptions,
ChartWatchs,
ChartMethods,
TypedChart,
Bar,
Bubble,
Doughnut,
Expand Down
26 changes: 26 additions & 0 deletions 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,
Expand All @@ -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,
Expand Down

0 comments on commit acebe19

Please sign in to comment.