@@ -49,9 +49,17 @@ def render_panel(ctx: Context) -> Component:
4949)
5050def 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
0 commit comments