Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
2 : import type { IChartWidget } from '@comfyorg/graph-model/widgets'
3 : import { isChartInputSpec } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
4 : import type { InputSpec as InputSpecV2 } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
5 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
6 :
7 2356 : export const useChartWidget = (): ComfyWidgetConstructorV2 => {
8 2356 : return (node: LGraphNode, inputSpec: InputSpecV2): IChartWidget => {
9 0 : if (!isChartInputSpec(inputSpec)) {
10 0 : throw new Error('Invalid input spec for chart widget')
11 : }
12 :
13 0 : const { name, options } = inputSpec
14 0 : const chartType = inputSpec.chartType ?? options?.type ?? 'line'
15 0 : const data = inputSpec.data ?? options?.data ?? {}
16 :
17 0 : const widgetOptions = { serialize: true, type: chartType }
18 :
19 : const widget = node.addWidget(
20 : 'chart',
21 : name,
22 : data,
23 : () => {},
24 : widgetOptions
25 : ) as IChartWidget
26 :
27 0 : return widget
28 : }
29 : }
|