|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eux |
| 4 | + |
| 5 | +export OUTPUT_DIRECTORY=../temp/typescript/vanilla_vite |
| 6 | + |
| 7 | +mkdir -p $OUTPUT_DIRECTORY |
| 8 | +cd $OUTPUT_DIRECTORY |
| 9 | +rm -rf * |
| 10 | + |
| 11 | +function merge-json() { |
| 12 | + # merge the second json file into the first. |
| 13 | + TEMP_FILE=$(mktemp) |
| 14 | + jq '. * input' $1 $2 > TEMP_FILE && mv TEMP_FILE $1 |
| 15 | +} |
| 16 | + |
| 17 | +# 1. Create base vite project |
| 18 | +npm create vite@latest . -- --template vanilla-ts --yes |
| 19 | + |
| 20 | +# 2. Build and run initial basic project |
| 21 | +# npm install |
| 22 | +# # npm run dev |
| 23 | +# In a web browser navigate to http://localhost:5173/ |
| 24 | + |
| 25 | +# 3. Simplify by removing some unwanted files |
| 26 | +rm public/vite.svg src/counter.ts src/style.css src/typescript.svg |
| 27 | + |
| 28 | +# 4. Replace src/main.ts with a simple hello example |
| 29 | +cat > src/main.ts << EOF |
| 30 | +document.querySelector<HTMLDivElement>('#app')!.innerHTML = \`<div>Hello</div>\` |
| 31 | +EOF |
| 32 | + |
| 33 | +# 5. Build and run the minimal example |
| 34 | +# # npm run dev |
| 35 | +# In a web browser navigate to http://localhost:5173/ |
| 36 | + |
| 37 | +# 6. Add BokehJS dependency to this project. This assumes the package has been built and copied to the root directory of this repository as outlined in the top-level README.md. |
| 38 | +npm install ../../../../bokeh-bokehjs-3.7.0-dev.5.tgz |
| 39 | + |
| 40 | +# 7. Replace src/main.ts with a simple hello example |
| 41 | +cat > src/main.ts << EOF |
| 42 | +import * as Bokeh from "@bokeh/bokehjs"; |
| 43 | +
|
| 44 | +console.info("BokehJS version:", Bokeh.version); |
| 45 | +
|
| 46 | +function create_bokehjs_plot(target_id: string) { |
| 47 | + const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); |
| 48 | +
|
| 49 | + const plot = Bokeh.Plotting.figure({ |
| 50 | + title: "Example BokehJS plot", height: 500, width: 500, |
| 51 | + x_range: [0, 1], y_range: [0, 1], sizing_mode: "stretch_width", |
| 52 | + }); |
| 53 | +
|
| 54 | + plot.scatter({ field: "x" }, { field: "y" }, {source, size: { field: "size" }}); |
| 55 | +
|
| 56 | + const button = new Bokeh.Widgets.Button({label: "Click me to add a point", button_type: "primary"}); |
| 57 | + function button_callback() { |
| 58 | + const data = source.data as any; |
| 59 | + data.x.push(Math.random()); |
| 60 | + data.y.push(Math.random()); |
| 61 | + data.size.push(10 + Math.random()*30); |
| 62 | + source.change.emit(); |
| 63 | + } |
| 64 | + button.on_click(button_callback); |
| 65 | +
|
| 66 | + const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); |
| 67 | + Bokeh.Plotting.show(column, target_id); |
| 68 | +} |
| 69 | +
|
| 70 | +document.querySelector<HTMLDivElement>('#app')!.innerHTML = \`<div id='target'>Hello</div>\`; |
| 71 | +
|
| 72 | +create_bokehjs_plot("#target"); |
| 73 | +EOF |
| 74 | + |
| 75 | +# 8. Rebuild and serve |
| 76 | +# npm run dev |
| 77 | +# In a web browser navigate to http://localhost:5173/ |
0 commit comments