Skip to content

Commit 669859b

Browse files
committed
Add onPropertyChange
1 parent c9ed4ba commit 669859b

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

dashi/src/lib/components/DashiPlot.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createClassFromSpec } from "react-vega";
22

33
import { type PlotState } from "@/lib/types/state/component";
4-
// import { type PropertyChangeHandler } from "@/lib/types/model/event";
4+
import { type PropertyChangeHandler } from "@/lib/types/model/event";
55
import type { CSSProperties } from "react";
66

77
export interface DashiPlotProps extends Omit<PlotState, "type"> {
8-
// onPropertyChange: PropertyChangeHandler;
8+
onPropertyChange: PropertyChangeHandler;
99
}
1010

1111
interface VegaChartWrapperProps {
@@ -17,15 +17,30 @@ export function DashiPlot({
1717
id,
1818
style,
1919
figure,
20-
// onPropertyChange,
20+
onPropertyChange,
2121
}: DashiPlotProps) {
22+
if (!figure) {
23+
console.error(
24+
"Rendering DashiPlot failed:",
25+
"Expected figure, got",
26+
figure,
27+
);
28+
return null;
29+
}
2230
const { datasets, ...spec } = figure;
2331
const Plot = createClassFromSpec({
2432
mode: "vega-lite",
2533
spec: spec,
2634
});
27-
const handleSignal = (signalName: string, value: unknown) => {
28-
console.log("signalName", signalName, value);
35+
const handleSignal = (_signalName: string, value: unknown) => {
36+
if (id) {
37+
return onPropertyChange({
38+
componentType: "Plot",
39+
componentId: id,
40+
propertyName: "points",
41+
propertyValue: value,
42+
});
43+
}
2944
};
3045
const VegaChartWrapper = ({ id, style }: VegaChartWrapperProps) => {
3146
return (

dashi/src/lib/types/state/component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ export interface CheckboxState extends ComponentState {
3737

3838
export interface PlotState extends ComponentState {
3939
type: "Plot";
40-
figure: VisualizationSpec & {
41-
datasets?: Record<string, unknown>; // Add the datasets property
42-
};
40+
figure:
41+
| (VisualizationSpec & {
42+
datasets?: Record<string, unknown>; // Add the datasets property
43+
})
44+
| null;
4345
}
4446

4547
export interface BoxState extends ContainerState {

0 commit comments

Comments
 (0)