Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Nov 29, 2024
1 parent 816bacc commit 17d5eca
Show file tree
Hide file tree
Showing 7 changed files with 887 additions and 503 deletions.
4 changes: 2 additions & 2 deletions extensions/chart/src/utils/useSimpleChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export function useSimpleChart<T extends BaseSimpleChartOptions>(props: T) {

const mixedData = inject<Ref<MixedChartData[]>>(
"mixedChartData",
ref<MixedChartData[]>([]),
ref<MixedChartData[]>([]) as Ref<MixedChartData[]>,
);
let data = inject<Ref<BaseSimpleChartData>>("chartData");
if (!data) {
data = ref<BaseSimpleChartData>({
labels: (options as BaseSimpleChartOptions).labels,
datasets: [],
});
}) as Ref<BaseSimpleChartData>;
mixedData.value.push({
data: unref(data) as BaseSimpleChartData,
options: options as BaseSimpleChartOptions,
Expand Down
14 changes: 7 additions & 7 deletions extensions/chart/src/widgets/barChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ onMounted(() => {
() => {
if (!layoutConfig.value.done) return;
barSets.value = data.value.datasets.map((set, setIndex) => {
barSets.value = data!.value.datasets.map((set, setIndex) => {
set.style ??= {};
set.style.backgroundColor ??=
data?.value.style?.backgroundColor ?? ColorEnum.WHITE;
Expand All @@ -69,7 +69,7 @@ onMounted(() => {
layoutConfig.value.width!;
const categorySize = gridSize * options.categoryPercentage!;
const barSize =
(categorySize / data?.value.datasets.length) *
(categorySize / data!.value.datasets.length) *
options.barPercentage!;
return {
Expand All @@ -89,8 +89,8 @@ onMounted(() => {
layoutConfig.value.index!.min)) *
layoutConfig.value.width! +
(gridSize - categorySize) / 2 +
(setIndex * categorySize) / data?.value.datasets.length +
(categorySize / data?.value.datasets.length - barSize) / 2,
(setIndex * categorySize) / data!.value.datasets.length +
(categorySize / data!.value.datasets.length - barSize) / 2,
y:
layoutConfig.value.height! -
((0 - layoutConfig.value.cross!.min) /
Expand All @@ -116,7 +116,7 @@ onMounted(() => {
layoutConfig.value.height!;
const categorySize = gridSize * options.categoryPercentage!;
const barSize =
(categorySize / data?.value.datasets.length) *
(categorySize / data!.value.datasets.length) *
options.barPercentage!;
return {
width:
Expand All @@ -141,8 +141,8 @@ onMounted(() => {
layoutConfig.value.index!.min)) *
layoutConfig.value.height! +
(gridSize + categorySize) / 2 -
(setIndex * categorySize) / data?.value.datasets.length -
(categorySize / data?.value.datasets.length - barSize) / 2),
(setIndex * categorySize) / data!.value.datasets.length -
(categorySize / data!.value.datasets.length - barSize) / 2),
style: {
fillColor:
unit.style?.backgroundColor ?? set.style!.backgroundColor!,
Expand Down
44 changes: 22 additions & 22 deletions extensions/chart/src/widgets/chartDataset.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
<script setup lang="ts">
import type { WidgetOptions } from '@vue-motion/lib'
import { widget } from '@vue-motion/lib'
import type { ReturnWidget } from '@vue-motion/core'
import { defineWidget } from '@vue-motion/core'
import type { Ref } from 'vue'
import { inject, provide, ref, unref } from 'vue'
import type { WidgetOptions } from "@vue-motion/lib";
import { widget } from "@vue-motion/lib";
import type { ReturnWidget } from "@vue-motion/core";
import { defineWidget } from "@vue-motion/core";
import type { Ref } from "vue";
import { inject, provide, ref, unref } from "vue";
import type { ChartDataOptions, ChartStyle } from '..'
import type { BaseSimpleChartData } from './baseSimpleChart.vue'
import type { ChartDataOptions, ChartStyle } from "..";
import type { BaseSimpleChartData } from "./baseSimpleChart.vue";
export interface ChartDatasetOptions extends WidgetOptions {
label: string
style?: ChartStyle
label: string;
style?: ChartStyle;
}
export interface BaseChartDataSet<SpecificChartStyle> {
label: string
data: ReturnWidget<ChartDataOptions>[]
style?: SpecificChartStyle
label: string;
data: ReturnWidget<ChartDataOptions>[];
style?: SpecificChartStyle;
}
const props = defineProps<ChartDatasetOptions>()
const options = defineWidget<ChartDatasetOptions>(props)
const props = defineProps<ChartDatasetOptions>();
const options = defineWidget<ChartDatasetOptions>(props);
const dataset = ref<BaseChartDataSet<ChartStyle>>({
label: options.label,
data: [],
style: options.style,
})
provide('chartDataset', dataset)
});
provide("chartDataset", dataset);
const datasetList = inject<Ref<BaseSimpleChartData>>('chartData')
datasetList?.value.datasets.push(unref(dataset))
const datasetList = inject<Ref<BaseSimpleChartData>>("chartData");
datasetList?.value.datasets.push(
unref(dataset) as BaseChartDataSet<ChartStyle>,
);
</script>

<template>
Expand All @@ -40,6 +42,4 @@ datasetList?.value.datasets.push(unref(dataset))
</g>
</template>

<style scoped>
</style>
<style scoped></style>
Loading

0 comments on commit 17d5eca

Please sign in to comment.