Skip to content

Commit c9ed4ba

Browse files
committed
Update Panels
1 parent e92be8e commit c9ed4ba

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

dashi/src/lib/components/DashiPlot.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ export function DashiPlot({
2424
mode: "vega-lite",
2525
spec: spec,
2626
});
27+
const handleSignal = (signalName: string, value: unknown) => {
28+
console.log("signalName", signalName, value);
29+
};
2730
const VegaChartWrapper = ({ id, style }: VegaChartWrapperProps) => {
2831
return (
2932
<div id={id} style={style}>
30-
<Plot data={datasets} />
33+
<Plot data={datasets} signalListeners={{ onClick: handleSignal }} />
3134
</div>
3235
);
3336
};

dashipy/my_extension/my_panel_1.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,21 @@ def render_panel(ctx: Context) -> Component:
4949
)
5050
def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5151
dataset = ctx.datasets[selected_dataset]
52-
fig = alt.Chart(dataset).mark_bar().encode(
52+
corner_slider = alt.binding_range(min=0, max=50, step=1)
53+
corner_var = alt.param(bind=corner_slider, value=0, name="cornerRadius")
54+
click_param = alt.selection_point(on="click", name="onClick", fields=["a", "b"])
55+
fig = alt.Chart(dataset).mark_bar(cornerRadius=corner_var).encode(
5356
x=alt.X('a:N', title='a'),
5457
y=alt.Y('b:Q', title='b'),
5558
tooltip=[
56-
alt.Tooltip('a:N', title='a'),
57-
alt.Tooltip('b:Q', title='b'),
58-
]
59+
alt.Tooltip('a:N'),
60+
alt.Tooltip('b:Q'),
61+
],
62+
color='b:Q',
5963
).properties(
60-
width=400,
61-
height=400
62-
)
64+
width=300,
65+
height=300,
66+
title="Vega charts"
67+
).add_params(corner_var, click_param)
68+
print(fig.to_json())
6369
return fig

dashipy/my_extension/my_panel_2.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import plotly.express as pe
2-
import plotly.graph_objects as go
1+
import altair as alt
32

43
from dashipy import (Component, Input, Output)
54
from dashipy.components import (Plot, Box, Dropdown)
@@ -48,8 +47,25 @@ def render_panel(ctx: Context) -> Component:
4847
Input("selected_dataset"),
4948
Output("plot", "figure"),
5049
)
51-
def make_figure(ctx: Context, selected_dataset: int) -> go.Figure:
50+
def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5251
dataset = ctx.datasets[selected_dataset]
53-
line = pe.line(x=[-1.0, 0.0, 1.0], y=dataset, title=f"DS #{selected_dataset + 1}")
54-
line.update_layout(dict(margin=dict(t=40, r=4, b=4, l=4), autosize=True))
55-
return line
52+
slider = alt.binding_range(min=0, max=100, step=1, name='Cutoff ')
53+
selector = alt.param(name='SelectorName', value=50, bind=slider)
54+
fig = alt.Chart(dataset).mark_bar().encode(
55+
x='a:N',
56+
y='b:Q',
57+
tooltip=['a:N','b:Q'],
58+
color = alt.condition(
59+
'datum.b < SelectorName',
60+
alt.value('green'),
61+
alt.value('yellow')
62+
)
63+
).properties(
64+
width=300,
65+
height=300,
66+
title="Vega charts using Shorthand syntax"
67+
).add_params(
68+
selector,
69+
).interactive()
70+
return fig
71+

0 commit comments

Comments
 (0)