Skip to content

Commit a8d65bf

Browse files
committed
Add comments
1 parent 669859b commit a8d65bf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

dashipy/my_extension/my_panel_1.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ 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+
53+
# Create a slider
5254
corner_slider = alt.binding_range(min=0, max=50, step=1)
55+
# Create a parameter and bind that to the slider
5356
corner_var = alt.param(bind=corner_slider, value=0, name="cornerRadius")
54-
click_param = alt.selection_point(on="click", name="onClick", fields=["a", "b"])
57+
# Create another parameter to handle the click events and send the data as
58+
# specified in the fields
59+
click_param = alt.selection_point(on="click", name="onClick",
60+
fields=["a", "b"])
61+
# Create a chart type using mark_* where * could be any kind of chart
62+
# supported by Vega. We can add properties and parameters as shown below.
5563
fig = alt.Chart(dataset).mark_bar(cornerRadius=corner_var).encode(
5664
x=alt.X('a:N', title='a'),
5765
y=alt.Y('b:Q', title='b'),
@@ -65,5 +73,5 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
6573
height=300,
6674
title="Vega charts"
6775
).add_params(corner_var, click_param)
68-
print(fig.to_json())
76+
6977
return fig

dashipy/my_extension/my_panel_2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5151
dataset = ctx.datasets[selected_dataset]
5252
slider = alt.binding_range(min=0, max=100, step=1, name='Cutoff ')
5353
selector = alt.param(name='SelectorName', value=50, bind=slider)
54+
# Almost same as the chart in Panel 1, but here we use the Shorthand
55+
# notation for setting x,y and the tooltip, although they both give the
56+
# same output. We also call interactive() on this chart object which allows
57+
# to zoom in and out as well as move the chart around.
5458
fig = alt.Chart(dataset).mark_bar().encode(
5559
x='a:N',
5660
y='b:Q',
@@ -65,7 +69,7 @@ def make_figure(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
6569
height=300,
6670
title="Vega charts using Shorthand syntax"
6771
).add_params(
68-
selector,
72+
selector
6973
).interactive()
7074
return fig
7175

0 commit comments

Comments
 (0)