diff --git a/ci/typescript/create_vanilla_rspack.sh b/ci/typescript/create_vanilla_rspack.sh index 598000f..edef0ac 100755 --- a/ci/typescript/create_vanilla_rspack.sh +++ b/ci/typescript/create_vanilla_rspack.sh @@ -109,7 +109,7 @@ import * as Bokeh from "@bokeh/bokehjs"; console.info("BokehJS version:", Bokeh.version); -function create_bokehjs_plot(target_id: string) { +function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -129,11 +129,10 @@ function create_bokehjs_plot(target_id: string) { } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } -create_bokehjs_plot("#target"); +Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); EOF # 11. Rebuild and serve diff --git a/ci/typescript/create_vanilla_vite.sh b/ci/typescript/create_vanilla_vite.sh index d4bc436..f1c7cb6 100755 --- a/ci/typescript/create_vanilla_vite.sh +++ b/ci/typescript/create_vanilla_vite.sh @@ -43,7 +43,7 @@ import * as Bokeh from "@bokeh/bokehjs"; console.info("BokehJS version:", Bokeh.version); -function create_bokehjs_plot(target_id: string) { +function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -63,13 +63,12 @@ function create_bokehjs_plot(target_id: string) { } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } document.querySelector('#app')!.innerHTML = \`
Hello
\`; -create_bokehjs_plot("#target"); +Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); EOF # 8. Rebuild and serve diff --git a/ci/typescript/create_vanilla_webpack.sh b/ci/typescript/create_vanilla_webpack.sh index 109495b..4a8baed 100755 --- a/ci/typescript/create_vanilla_webpack.sh +++ b/ci/typescript/create_vanilla_webpack.sh @@ -110,7 +110,7 @@ import * as Bokeh from "@bokeh/bokehjs"; console.info("BokehJS version:", Bokeh.version); -function create_bokehjs_plot(target_id: string) { +function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -130,11 +130,10 @@ function create_bokehjs_plot(target_id: string) { } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } -create_bokehjs_plot("#target"); +Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); EOF # 11. Rebuild and serve diff --git a/recipes/src/recipes/typescript/common.ts b/recipes/src/recipes/typescript/common.ts index f9bf3a8..590eccb 100644 --- a/recipes/src/recipes/typescript/common.ts +++ b/recipes/src/recipes/typescript/common.ts @@ -13,10 +13,9 @@ export const baseTSConfig = export const baseTypeScriptExample = { import: 'import * as Bokeh from "@bokeh/bokehjs";\n', + version: 'console.info("BokehJS version:", Bokeh.version);\n', function: -`console.info("BokehJS version:", Bokeh.version); - -function create_bokehjs_plot(target_id: string) { +`function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -36,9 +35,8 @@ function create_bokehjs_plot(target_id: string) { } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } `, - create: 'create_bokehjs_plot("#target");' + show: 'Bokeh.Plotting.show(create_bokehjs_plot(), "#target");\n' }; diff --git a/recipes/src/recipes/typescript/vanilla_rspack_recipe.ts b/recipes/src/recipes/typescript/vanilla_rspack_recipe.ts index feb6a87..fe22f95 100644 --- a/recipes/src/recipes/typescript/vanilla_rspack_recipe.ts +++ b/recipes/src/recipes/typescript/vanilla_rspack_recipe.ts @@ -103,8 +103,9 @@ export default config;`) 'Replace contents of `src/index.ts` with code to create BokehJS plot', 'src/index.ts', baseTypeScriptExample.import + "\n" + + baseTypeScriptExample.version + "\n" + baseTypeScriptExample.function + "\n" + - baseTypeScriptExample.create + baseTypeScriptExample.show )); this.add(new CommandStep( diff --git a/recipes/src/recipes/typescript/vanilla_vite_recipe.ts b/recipes/src/recipes/typescript/vanilla_vite_recipe.ts index 0bc638a..3fec4f7 100644 --- a/recipes/src/recipes/typescript/vanilla_vite_recipe.ts +++ b/recipes/src/recipes/typescript/vanilla_vite_recipe.ts @@ -51,9 +51,10 @@ export class VanillaViteRecipe extends Recipe { 'Replace `src/main.ts` with a simple hello example', 'src/main.ts', baseTypeScriptExample.import + "\n" + + baseTypeScriptExample.version + "\n" + baseTypeScriptExample.function + "\n" + "document.querySelector('#app')!.innerHTML = \\`
Hello
\\`;\n\n" + - 'create_bokehjs_plot("#target");' + baseTypeScriptExample.show )); this.add(new CommandStep( diff --git a/recipes/src/recipes/typescript/vanilla_webpack_recipe.ts b/recipes/src/recipes/typescript/vanilla_webpack_recipe.ts index 75fd180..907a4e5 100644 --- a/recipes/src/recipes/typescript/vanilla_webpack_recipe.ts +++ b/recipes/src/recipes/typescript/vanilla_webpack_recipe.ts @@ -102,8 +102,9 @@ export default config;`) 'Replace contents of `src/index.ts` with code to create BokehJS plot', 'src/index.ts', baseTypeScriptExample.import + "\n" + + baseTypeScriptExample.version + "\n" + baseTypeScriptExample.function + "\n" + - baseTypeScriptExample.create + baseTypeScriptExample.show )); this.add(new CommandStep( diff --git a/typescript/vanilla_rspack/README.md b/typescript/vanilla_rspack/README.md index d37bc5a..8d118a4 100644 --- a/typescript/vanilla_rspack/README.md +++ b/typescript/vanilla_rspack/README.md @@ -111,7 +111,7 @@ This is almost identical to the vanilla webpack example, as `rspack` is designed console.info("BokehJS version:", Bokeh.version); - function create_bokehjs_plot(target_id: string) { + function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -131,11 +131,11 @@ This is almost identical to the vanilla webpack example, as `rspack` is designed } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } - create_bokehjs_plot("#target"); + Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); + ``` 11. Rebuild and serve diff --git a/typescript/vanilla_vite/README.md b/typescript/vanilla_vite/README.md index d953c4f..11d53e4 100644 --- a/typescript/vanilla_vite/README.md +++ b/typescript/vanilla_vite/README.md @@ -50,7 +50,7 @@ Create an initial basic project using `create-vite`. console.info("BokehJS version:", Bokeh.version); - function create_bokehjs_plot(target_id: string) { + function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -70,13 +70,13 @@ Create an initial basic project using `create-vite`. } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } document.querySelector('#app')!.innerHTML = `
Hello
`; - create_bokehjs_plot("#target"); + Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); + ``` 8. Rebuild and serve diff --git a/typescript/vanilla_webpack/README.md b/typescript/vanilla_webpack/README.md index b532406..e817b42 100644 --- a/typescript/vanilla_webpack/README.md +++ b/typescript/vanilla_webpack/README.md @@ -110,7 +110,7 @@ console.info("BokehJS version:", Bokeh.version); - function create_bokehjs_plot(target_id: string) { + function create_bokehjs_plot(): Bokeh.Column { const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); const plot = Bokeh.Plotting.figure({ @@ -130,11 +130,11 @@ } button.on_click(button_callback); - const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); - Bokeh.Plotting.show(column, target_id); + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); } - create_bokehjs_plot("#target"); + Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); + ``` 11. Rebuild and serve