-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6185f22
commit d11ba8a
Showing
19 changed files
with
250 additions
and
128 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
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
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
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
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
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,2 @@ | ||
export * from './component.builder'; | ||
export * from './component.types'; |
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,65 @@ | ||
import { defineChartComponent } from '../core/component.builder'; | ||
|
||
/** | ||
* A bar chart provides a way of showing data values represented as vertical bars. It is sometimes used to show trend data, and the comparison of multiple data sets side by side. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/bar.html} | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const BarChart = defineChartComponent('bar-chart', 'bar'); | ||
|
||
/** | ||
* Pie and doughnut charts are probably the most commonly used charts. They are divided into segments, the arc of each segment shows the proportional value of each piece of data. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/doughnut.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const DoughnutChart = defineChartComponent('doughnut-chart', 'doughnut'); | ||
|
||
/** | ||
* A line chart is a way of plotting data points on a line. Often, it is used to show trend data, or the comparison of two data sets. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/line.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const LineChart = defineChartComponent('line-chart', 'line'); | ||
|
||
/** | ||
* Pie and doughnut charts are probably the most commonly used charts. They are divided into segments, the arc of each segment shows the proportional value of each piece of data. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/doughnut.html#pie } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const PieChart = defineChartComponent('pie-chart', 'pie'); | ||
|
||
/** | ||
* Polar area charts are similar to pie charts, but each segment has the same angle - the radius of the segment differs depending on the value. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/polar.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const PolarAreaChart = defineChartComponent('polar-chart', 'polarArea'); | ||
|
||
/** | ||
* A radar chart is a way of showing multiple data points and the variation between them. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/radar.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const RadarChart = defineChartComponent('radar-chart', 'radar'); | ||
|
||
/** | ||
* A bubble chart is used to display three dimensions of data at the same time. The location of the bubble is determined by the first two dimensions and the corresponding horizontal and vertical axes. The third dimension is represented by the size of the individual bubbles. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/bubble.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const BubbleChart = defineChartComponent('bubble-chart', 'bubble'); | ||
|
||
/** | ||
* Scatter charts are based on basic line charts with the x axis changed to a linear axis. To use a scatter chart, data must be passed as objects containing X and Y properties. The example below creates a scatter chart with 4 points. | ||
* | ||
* {@link - https://www.chartjs.org/docs/latest/charts/scatter.html } | ||
* {@link - https://vue-chart-3.netlify.app/components/#list-of-all-components} | ||
*/ | ||
export const ScatterChart = defineChartComponent('scatter-chart', 'scatter'); |
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,57 @@ | ||
import { defineChartHook } from '../hooks'; | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useDoughnutChart = defineChartHook('doughnut'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useBarChart = defineChartHook('bar'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useLineChart = defineChartHook('line'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const usePieChart = defineChartHook('pie'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const usePolarAreaChart = defineChartHook('polarArea'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useRadarChart = defineChartHook('radar'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useBubbleChart = defineChartHook('bubble'); | ||
|
||
/** | ||
* {@link - https://vue-chart-3.netlify.app/components/hooks/#guide} | ||
* | ||
* ❗️ Still in beta, API can change in future updates | ||
*/ | ||
export const useScatterChart = defineChartHook('scatter'); |
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,2 @@ | ||
export * from './component.exports'; | ||
export * from './hooks.exports'; |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { Chart, ChartData, ChartType, Plugin } from 'chart.js'; | ||
import { computed, ref, unref } from 'vue'; | ||
import type { StyleValue } from '../misc'; | ||
import { MaybeRef } from '../utils'; | ||
import type { ChartHookReturnType } from './hooks.types'; | ||
|
||
export const defineChartHook = <TType extends ChartType = ChartType, TJSX = false>( | ||
chartType: TType | ||
) => { | ||
return (params: { | ||
chartData: MaybeRef<ChartData<TType>>; | ||
options?: MaybeRef<Record<string, any>>; | ||
width?: number; | ||
height?: number; | ||
cssClasses?: string; | ||
styles?: StyleValue; | ||
plugins?: Plugin[]; | ||
onLabelsUpdate?: () => void; | ||
onChartUpdate?: (chartInstance: Chart<TType>) => void; | ||
onChartDestroy?: () => void; | ||
onChartRender?: (chartInstance: Chart<TType>) => void; | ||
}): ChartHookReturnType<TType, TJSX> => { | ||
const CHART_REF_NAME = `${chartType}ChartRef`; | ||
const jsxRef = { | ||
[CHART_REF_NAME]: ref(null), | ||
}; | ||
const reactiveProps = computed(() => ({ | ||
...params, | ||
ref: CHART_REF_NAME, | ||
chartData: unref(params.chartData), | ||
options: unref(params.options), | ||
})); | ||
|
||
return { | ||
[`${chartType}ChartProps`]: reactiveProps, | ||
[CHART_REF_NAME]: ref(null), | ||
}; | ||
}; | ||
}; |
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,19 @@ | ||
import type { ChartType } from 'chart.js'; | ||
import type { ComponentPublicInstance, ExtractPropTypes, Ref } from 'vue'; | ||
import type { ChartPropsOptions, ComponentData } from '../core'; | ||
|
||
export interface HookOptions<TType extends ChartType, TJSX = false> | ||
extends ChartPropsOptions<TType> { | ||
ref?: TJSX extends true ? Ref<any> : string; | ||
} | ||
|
||
type DumbTypescript = 0; | ||
|
||
export type ChartHookReturnType<TType extends ChartType, TJSX = false> = { | ||
[K in DumbTypescript as `${TType}ChartRef`]: Ref<ComponentPublicInstance< | ||
ChartPropsOptions<TType>, | ||
ComponentData<TType> | ||
> | null>; | ||
} & { | ||
[K in DumbTypescript as `${TType}ChartProps`]: Ref<ExtractPropTypes<HookOptions<TType, TJSX>>>; | ||
}; |
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,2 @@ | ||
export * from './hooks.builder'; | ||
export * from './hooks.types'; |
Oops, something went wrong.