Skip to content

Commit ee7fa62

Browse files
committed
coupling? I've never heard of it
1 parent 63d6ee2 commit ee7fa62

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/components/graph/vueWidgets/WidgetChart.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import type { ChartData } from 'chart.js'
1313
import Chart from 'primevue/chart'
1414
import { computed } from 'vue'
1515
16+
import type { ChartInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
1617
import type { SimplifiedWidget } from '@/types/simplifiedWidget'
1718
19+
type ChartWidgetOptions = NonNullable<ChartInputSpec['options']>
20+
1821
const value = defineModel<ChartData>({ required: true })
1922
2023
const props = defineProps<{
21-
widget: SimplifiedWidget<ChartData>
24+
widget: SimplifiedWidget<ChartData, ChartWidgetOptions>
2225
readonly?: boolean
2326
}>()
2427
25-
const chartType = computed(() => {
26-
const type = props.widget.options?.type
27-
return type === 'line' ? 'line' : 'bar'
28-
})
28+
const chartType = computed(() => props.widget.options?.type ?? 'line')
2929
3030
const chartData = computed(() => value.value || { labels: [], datasets: [] })
3131

src/composables/widgets/useChartWidget.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import type { LGraphNode } from '@comfyorg/litegraph'
22
import type { IChartWidget } from '@comfyorg/litegraph/dist/types/widgets'
33

4-
import type {
5-
ChartInputSpec,
6-
InputSpec as InputSpecV2
4+
import {
5+
type ChartInputSpec,
6+
type InputSpec as InputSpecV2,
7+
isChartInputSpec
78
} from '@/schemas/nodeDef/nodeDefSchemaV2'
89
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
910

1011
export const useChartWidget = (): ComfyWidgetConstructorV2 => {
1112
return (node: LGraphNode, inputSpec: InputSpecV2): IChartWidget => {
13+
if (!isChartInputSpec(inputSpec)) {
14+
throw new Error('Invalid input spec for chart widget')
15+
}
16+
1217
const { name, options = {} } = inputSpec as ChartInputSpec
1318

19+
const chartType = options.type || 'line'
20+
1421
const widget = node.addWidget('chart', name, options.data || {}, () => {}, {
1522
serialize: true,
16-
type: options.type || 'line',
23+
type: chartType,
1724
...options
1825
}) as IChartWidget
1926

0 commit comments

Comments
 (0)