|
1 | | -import { createClassFromSpec, type VisualizationSpec } from "react-vega"; |
| 1 | +import { createClassFromSpec } from "react-vega"; |
2 | 2 |
|
3 | 3 | 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"; |
5 | 5 | import type { CSSProperties } from "react"; |
6 | 6 |
|
7 | | -export interface DashiPlotProps |
8 | | - extends Omit<PlotState, "type">, |
9 | | - Omit<PlotState, "onPropertyChange"> { |
10 | | - onPropertyChange: PropertyChangeHandler; |
| 7 | +export interface DashiPlotProps extends Omit<PlotState, "type"> { |
| 8 | + // onPropertyChange: PropertyChangeHandler; |
11 | 9 | } |
12 | 10 |
|
13 | 11 | interface VegaChartWrapperProps { |
14 | 12 | id?: string; |
15 | 13 | style?: CSSProperties; |
16 | 14 | } |
17 | 15 |
|
18 | | -const specification: VisualizationSpec = { |
19 | | - config: { view: { continuousWidth: 300, continuousHeight: 300 } }, |
20 | | - data: { name: "myData" }, |
21 | | - mark: { type: "bar" }, |
22 | | - description: "A simple bar chart with embedded data.", |
23 | | - encoding: { |
24 | | - tooltip: [ |
25 | | - { field: "a", title: "a", type: "nominal" }, |
26 | | - { field: "b", title: "b", type: "quantitative" }, |
27 | | - ], |
28 | | - x: { field: "a", title: "a", type: "nominal" }, |
29 | | - y: { field: "b", title: "b", type: "quantitative" }, |
30 | | - }, |
31 | | - params: [{ name: "click", select: { type: "point", on: "click" } }], |
32 | | - $schema: "https://vega.github.io/schema/vega-lite/v5.20.1.json", |
33 | | - datasets: {}, |
34 | | -}; |
35 | | - |
36 | | -const data = { |
37 | | - myData: [ |
38 | | - { a: "A", b: 28 }, |
39 | | - { a: "B", b: 55 }, |
40 | | - { a: "C", b: 43 }, |
41 | | - { a: "D", b: 91 }, |
42 | | - { a: "E", b: 81 }, |
43 | | - { a: "F", b: 53 }, |
44 | | - { a: "G", b: 19 }, |
45 | | - { a: "H", b: 87 }, |
46 | | - { a: "I", b: 52 }, |
47 | | - ], |
48 | | -}; |
49 | | - |
50 | 16 | export function DashiPlot({ |
51 | 17 | id, |
52 | 18 | style, |
| 19 | + figure, |
53 | 20 | // onPropertyChange, |
54 | 21 | }: DashiPlotProps) { |
| 22 | + const { datasets, ...spec } = figure; |
55 | 23 | const Plot = createClassFromSpec({ |
56 | 24 | mode: "vega-lite", |
57 | | - spec: specification, |
| 25 | + spec: spec, |
58 | 26 | }); |
59 | 27 | const VegaChartWrapper = ({ id, style }: VegaChartWrapperProps) => { |
60 | 28 | return ( |
61 | 29 | <div id={id} style={style}> |
62 | | - <Plot data={data} /> |
| 30 | + <Plot data={datasets} /> |
63 | 31 | </div> |
64 | 32 | ); |
65 | 33 | }; |
|
0 commit comments