Skip to content

Commit 74b5161

Browse files
committed
Update based on reviewer's comments
1 parent 3cc50d8 commit 74b5161

File tree

8 files changed

+28
-38
lines changed

8 files changed

+28
-38
lines changed

dashi/src/lib/actions/applyPropertyChange.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const componentState: ComponentState = {
1717
type: "Box",
1818
id: "b1",
1919
components: [
20-
{ type: "Plot", id: "p1", figure: null } as PlotState,
20+
{ type: "Plot", id: "p1", chart: null } as PlotState,
2121
{
2222
type: "Box",
2323
id: "b2",
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
1-
import { createClassFromSpec } from "react-vega";
1+
import { VegaLite } from "react-vega";
22

33
import { type PlotState } from "@/lib/types/state/component";
44
import { type PropertyChangeHandler } from "@/lib/types/model/event";
5-
import type { CSSProperties } from "react";
65

76
export interface DashiPlotProps extends Omit<PlotState, "type"> {
87
onPropertyChange: PropertyChangeHandler;
98
}
109

11-
interface VegaChartWrapperProps {
12-
id?: string;
13-
style?: CSSProperties;
14-
}
15-
1610
export function DashiPlot({
1711
id,
1812
style,
19-
figure,
13+
chart,
2014
onPropertyChange,
2115
}: DashiPlotProps) {
22-
if (!figure) {
16+
if (!chart) {
2317
return <div id={id} style={style} />;
2418
}
25-
const { datasets, ...spec } = figure;
26-
const Plot = createClassFromSpec({
27-
mode: "vega-lite",
28-
spec: spec,
29-
});
19+
const { datasets, ...spec } = chart;
3020
const handleSignal = (_signalName: string, value: unknown) => {
3121
if (id) {
3222
return onPropertyChange({
@@ -37,12 +27,13 @@ export function DashiPlot({
3727
});
3828
}
3929
};
40-
const VegaChartWrapper = ({ id, style }: VegaChartWrapperProps) => {
41-
return (
42-
<div id={id} style={style}>
43-
<Plot data={datasets} signalListeners={{ onClick: handleSignal }} />
44-
</div>
45-
);
46-
};
47-
return <VegaChartWrapper id={id} style={style} />;
30+
return (
31+
<VegaLite
32+
spec={spec}
33+
data={datasets}
34+
style={style}
35+
signalListeners={{ onClick: handleSignal }}
36+
actions={false}
37+
/>
38+
);
4839
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface CheckboxState extends ComponentState {
3737

3838
export interface PlotState extends ComponentState {
3939
type: "Plot";
40-
figure:
40+
chart:
4141
| (VisualizationSpec & {
4242
datasets?: Record<string, unknown>; // Add the datasets property
4343
})

dashipy/dashipy/callback.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def _parameter_to_dict(parameter: inspect.Parameter) -> dict[str, Any]:
205205
}
206206

207207
_object_types = {
208-
"Figure": "Figure",
209208
"Component": "Component",
210209
"Chart": "Chart"
211210
}

dashipy/dashipy/components/plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
@dataclass(frozen=True)
1010
class Plot(Component):
11-
figure: alt.Chart | None = None
11+
chart: alt.Chart | None = None
1212

1313
def to_dict(self) -> dict[str, Any]:
1414
d = super().to_dict()
15-
if self.figure is not None:
16-
d.update(figure=self.figure.to_dict())
15+
if self.chart is not None:
16+
d.update(chart=self.chart.to_dict())
1717
else:
18-
d.update(figure=None)
18+
d.update(chart=None)
1919
return d

dashipy/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: dashi
22
channels:
33
- conda-forge
44
dependencies:
5-
- python
5+
- python >=3.12,<3.13
66
# Dependencies
77
- pandas
88
- altair

dashipy/my_extension/my_panel_1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def render_panel(ctx: Context) -> Component:
1414
selected_dataset: int = 0
1515
plot = Plot(
16-
id="plot", figure=make_figure(ctx, selected_dataset), style={"flexGrow": 1}
16+
id="plot", chart=make_figure(ctx, selected_dataset), style={"flexGrow": 1}
1717
)
1818
dropdown = Dropdown(
1919
id="selected_dataset",
@@ -45,7 +45,7 @@ def render_panel(ctx: Context) -> Component:
4545

4646
@panel.callback(
4747
Input("selected_dataset"),
48-
Output("plot", "figure"),
48+
Output("plot", "chart"),
4949
)
5050
def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5151
dataset = ctx.datasets[selected_dataset]
@@ -60,7 +60,7 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
6060
fields=["a", "b"])
6161
# Create a chart type using mark_* where * could be any kind of chart
6262
# supported by Vega. We can add properties and parameters as shown below.
63-
fig = alt.Chart(dataset).mark_bar(cornerRadius=corner_var).encode(
63+
chart = alt.Chart(dataset).mark_bar(cornerRadius=corner_var).encode(
6464
x=alt.X('a:N', title='a'),
6565
y=alt.Y('b:Q', title='b'),
6666
tooltip=[
@@ -74,4 +74,4 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
7474
title="Vega charts"
7575
).add_params(corner_var, click_param)
7676

77-
return fig
77+
return chart

dashipy/my_extension/my_panel_2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def render_panel(ctx: Context) -> Component:
1414
selected_dataset: int = 0
1515
plot = Plot(
16-
id="plot", figure=make_figure(ctx, selected_dataset), style={"flexGrow": 1}
16+
id="plot", chart=make_figure(ctx, selected_dataset), style={"flexGrow": 1}
1717
)
1818
dropdown = Dropdown(
1919
id="selected_dataset",
@@ -45,7 +45,7 @@ def render_panel(ctx: Context) -> Component:
4545

4646
@panel.callback(
4747
Input("selected_dataset"),
48-
Output("plot", "figure"),
48+
Output("plot", "chart"),
4949
)
5050
def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5151
dataset = ctx.datasets[selected_dataset]
@@ -55,7 +55,7 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5555
# notation for setting x,y and the tooltip, although they both give the
5656
# same output. We also call interactive() on this chart object which allows
5757
# to zoom in and out as well as move the chart around.
58-
fig = alt.Chart(dataset).mark_bar().encode(
58+
chart = alt.Chart(dataset).mark_bar().encode(
5959
x='a:N',
6060
y='b:Q',
6161
tooltip=['a:N','b:Q'],
@@ -71,5 +71,5 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
7171
).add_params(
7272
selector
7373
).interactive()
74-
return fig
74+
return chart
7575

0 commit comments

Comments
 (0)