Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite code to typescript
- Loading branch information
1 parent
a0afa95
commit 84f0995
Showing
5 changed files
with
357 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Chart as ChartJS } from 'chart.js' | ||
import type { | ||
ChartType, | ||
ChartData, | ||
ChartOptions, | ||
PluginChartOptions, | ||
DefaultDataPoint, | ||
PluginOptionsByType | ||
} from 'chart.js' | ||
|
||
import { | ||
ComponentOptionsMixin, | ||
ComputedOptions, | ||
DefineComponent, | ||
MethodOptions, | ||
Ref, | ||
ShallowRef | ||
} from 'vue' | ||
|
||
import { ChartEmits } from './utils' | ||
|
||
export type TChartData< | ||
TType extends ChartType = ChartType, | ||
TData = DefaultDataPoint<TType>, | ||
TLabel = unknown | ||
> = ChartData<TType, TData, TLabel> | ||
|
||
export type TChartOptions<TType extends ChartType> = ChartOptions<TType> | ||
|
||
export type TChartPlugins<TType extends ChartType> = PluginChartOptions<TType> | ||
|
||
export type TypedChartJS< | ||
TType extends ChartType = ChartType, | ||
TData = DefaultDataPoint<TType>, | ||
TLabel = unknown | ||
> = ChartJS<TType, TData, TLabel> | ||
|
||
export interface IChartProps< | ||
TType extends ChartType, | ||
TData = DefaultDataPoint<TType>, | ||
TLabel = unknown | ||
> { | ||
chartData: TChartData<TType, TData, TLabel> | ||
datasetIdKey: string | ||
chartOptions: TChartOptions<TType> | ||
chartId: string | ||
width: number | ||
height: number | ||
cssClasses: string | ||
styles: Partial<CSSStyleDeclaration> | ||
plugins: PluginOptionsByType<TType> | ||
} | ||
|
||
export interface TypedChartComponentData< | ||
TType extends ChartType, | ||
TData = DefaultDataPoint<TType>, | ||
TLabel = unknown | ||
> { | ||
_chart: ShallowRef<TypedChartJS<TType, TData, TLabel> | null> | ||
canvasEl: Ref<HTMLCanvasElement | null> | ||
renderChart: ( | ||
data: TChartData<TType, TData, TLabel>, | ||
options: TChartOptions<TType> | ||
) => void | ||
chartDataHandler: ( | ||
newValue: TChartData<TType, TData, TLabel>, | ||
oldValue: TChartData<TType, TData, TLabel> | ||
) => void | ||
} | ||
|
||
export type TypedChartEmits = { | ||
[ChartEmits.ChartRendered]: () => true | ||
[ChartEmits.ChartUpdated]: () => true | ||
[ChartEmits.ChartDestroyed]: () => true | ||
[ChartEmits.LabelsUpdated]: () => true | ||
} | ||
|
||
export type TypedChartComponent< | ||
TType extends ChartType, | ||
TData = DefaultDataPoint<TType>, | ||
TLabel = unknown | ||
> = DefineComponent< | ||
IChartProps<TType, TData, TLabel>, | ||
TypedChartComponentData<TType, TData, TLabel>, | ||
unknown, | ||
ComputedOptions, | ||
MethodOptions, | ||
ComponentOptionsMixin, | ||
ComponentOptionsMixin, | ||
TypedChartEmits | ||
> |
Oops, something went wrong.