@@ -15,28 +15,20 @@ export const baseTypeScriptExample = {
15
15
import : 'import * as Bokeh from "@bokeh/bokehjs";\n' ,
16
16
version : 'console.info("BokehJS version:", Bokeh.version);\n' ,
17
17
function :
18
- `function create_bokehjs_plot(): Bokeh.Column {
19
- const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }});
20
-
18
+ `function create_bokehjs_plot(): Bokeh.Plotting.Figure {
19
+ // Create figure
21
20
const plot = Bokeh.Plotting.figure({
22
- title: "Example BokehJS plot", height: 500, width: 500,
23
- x_range: [0, 1], y_range: [0, 1], sizing_mode: "stretch_width",
21
+ title: "Example BokehJS plot", height: 500, sizing_mode: "stretch_width"
24
22
});
25
23
26
- plot.scatter({ field: "x" }, { field: "y" }, {source, size: { field: "size" }});
24
+ // Calculate x, y value of sine curve
25
+ const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
26
+ const y = x.map(x => Math.sin(Math.PI*x/6));
27
27
28
- const button = new Bokeh.Widgets.Button({label: "Click me to add a point", button_type: "primary"});
29
- function button_callback() {
30
- const data = source.data as any;
31
- data.x.push(Math.random());
32
- data.y.push(Math.random());
33
- data.size.push(10 + Math.random()*30);
34
- source.change.emit();
35
- }
36
- button.on_click(button_callback);
28
+ // Plot circles
29
+ plot.scatter(x, y, {color: "blue", size: 30, fill_alpha: 0.4});
37
30
38
- return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"});
39
- }
40
- ` ,
31
+ return plot;
32
+ }` ,
41
33
show : ( target : string = '"#target"' ) => 'Bokeh.Plotting.show(create_bokehjs_plot(), ' + target + ');\n'
42
34
} ;
0 commit comments