@@ -97,51 +97,23 @@ rm temp.json
9797# 9. Add BokehJS dependency
9898npm install ../../../../bokeh-bokehjs-3.7.0-dev.5.tgz
9999
100- # 10. tsconfig.json needs workaround for @bokehjs paths
101- cat > temp.json << EOF
102- {
103- "compilerOptions": {
104- "paths": {
105- "@bokehjs/*": ["./node_modules/@bokeh/bokehjs/build/js/lib/*"]
106- }
107- }
108- }
109- EOF
110- npx json-merger --output tsconfig.json --pretty tsconfig.json temp.json
111- rm temp.json
112-
113- # 11. webpack.config.ts needs workaround to resolve @bokehjs alias
114- # TODO: use proper ts parser to parse, add new code, write back out
115- head -13 webpack.config.ts > temp.ts
116- cat >> temp.ts << EOF
117- resolve: {
118- alias: {
119- "@bokehjs": path.resolve(__dirname, "node_modules/@bokeh/bokehjs/build/js/lib/")
120- }
121- },
122- EOF
123- tail -9 webpack.config.ts >> temp.ts
124- mv temp.ts webpack.config.ts
125-
126- # 12. Replace src/index.ts with code to create BokehJS plot
100+ # 10. Replace src/index.ts with code to create BokehJS plot
127101cat > src/index.ts << EOF
128- import { Column, ColumnDataSource, version } from "@bokehjs/bokeh";
129- import { figure, show } from "@bokehjs/api/plotting";
130- import { Button } from "@bokehjs/models/widgets";
102+ import * as Bokeh from "@bokeh/bokehjs";
131103
132- console.info("BokehJS version:", version);
104+ console.info("BokehJS version:", Bokeh. version);
133105
134106function create_bokehjs_plot(target_id: string) {
135- const source = new ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }});
107+ const source = new Bokeh. ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }});
136108
137- const plot = figure({
109+ const plot = Bokeh.Plotting. figure({
138110 title: "Example BokehJS plot", height: 500, width: 500,
139111 x_range: [0, 1], y_range: [0, 1], sizing_mode: "stretch_width",
140112 });
141113
142114 plot.scatter({ field: "x" }, { field: "y" }, {source, size: { field: "size" }});
143115
144- const button = new Button({label: "Click me to add a point", button_type: "primary"});
116+ const button = new Bokeh.Widgets. Button({label: "Click me to add a point", button_type: "primary"});
145117 function button_callback() {
146118 const data = source.data as any;
147119 data.x.push(Math.random());
@@ -151,14 +123,14 @@ function create_bokehjs_plot(target_id: string) {
151123 }
152124 button.on_click(button_callback);
153125
154- const column = new Column({children: [plot, button], sizing_mode: "stretch_width"});
155- show(column, target_id);
126+ const column = new Bokeh. Column({children: [plot, button], sizing_mode: "stretch_width"});
127+ Bokeh.Plotting. show(column, target_id);
156128}
157129
158130create_bokehjs_plot("#target");
159131EOF
160132
161- # 13 . Rebuild and serve
133+ # 11 . Rebuild and serve
162134npm install
163135npm run build
164136# npm run serve
0 commit comments