Skip to content

Commit 0de0a82

Browse files
authored
Fix imports of @bokeh/bokehjs (#23)
1 parent df99469 commit 0de0a82

File tree

2 files changed

+18
-70
lines changed

2 files changed

+18
-70
lines changed

ci/typescript/create_vanilla_webpack.sh

+9-37
Original file line numberDiff line numberDiff line change
@@ -97,51 +97,23 @@ rm temp.json
9797
# 9. Add BokehJS dependency
9898
npm 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
127101
cat > 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
134106
function 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
158130
create_bokehjs_plot("#target");
159131
EOF
160132

161-
# 13. Rebuild and serve
133+
# 11. Rebuild and serve
162134
npm install
163135
npm run build
164136
#npm run serve

typescript/vanilla_webpack/README.md

+9-33
Original file line numberDiff line numberDiff line change
@@ -103,48 +103,24 @@
103103
npm install ../../../../bokeh-bokehjs-3.7.0-dev.5.tgz
104104
```
105105
106-
10. `tsconfig.json` needs workaround for `@bokehjs` paths, added to the `compilerOptions` section:
107-
108-
```json
109-
"compilerOptions": {
110-
"paths": {
111-
"@bokehjs/*": ["./node_modules/@bokeh/bokehjs/build/js/lib/*"]
112-
}
113-
}
114-
```
115-
116-
11. `webpack.config.ts` needs workaround to resolve `@bokehjs` alias also, added to the top-level of the `config`:
117-
118-
```typescript
119-
const config: webpack.Configuration = {
120-
resolve: {
121-
alias: {
122-
"@bokehjs": path.resolve(__dirname, "node_modules/@bokeh/bokehjs/build/js/lib/")
123-
}
124-
},
125-
}
126-
````
127-
128-
12. Remove contents of `src/index.ts` and replace with code to create BokehJS plot:
106+
10. Remove contents of `src/index.ts` and replace with code to create BokehJS plot:
129107
130108
```typescript
131-
import { Column, ColumnDataSource, version } from "@bokehjs/bokeh";
132-
import { figure, show } from "@bokehjs/api/plotting";
133-
import { Button } from "@bokehjs/models/widgets";
109+
import * as Bokeh from "@bokeh/bokehjs";
134110
135-
console.info("BokehJS version:", version);
111+
console.info("BokehJS version:", Bokeh.version);
136112
137113
function create_bokehjs_plot(target_id: string) {
138-
const source = new ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }});
114+
const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }});
139115
140-
const plot = figure({
116+
const plot = Bokeh.Plotting.figure({
141117
title: "Example BokehJS plot", height: 500, width: 500,
142118
x_range: [0, 1], y_range: [0, 1], sizing_mode: "stretch_width",
143119
});
144120
145121
plot.scatter({ field: "x" }, { field: "y" }, {source, size: { field: "size" }});
146122
147-
const button = new Button({label: "Click me to add a point", button_type: "primary"});
123+
const button = new Bokeh.Widgets.Button({label: "Click me to add a point", button_type: "primary"});
148124
function button_callback() {
149125
const data = source.data as any;
150126
data.x.push(Math.random());
@@ -154,14 +130,14 @@
154130
}
155131
button.on_click(button_callback);
156132
157-
const column = new Column({children: [plot, button], sizing_mode: "stretch_width"});
158-
show(column, target_id);
133+
const column = new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"});
134+
Bokeh.Plotting.show(column, target_id);
159135
}
160136
161137
create_bokehjs_plot("#target");
162138
```
163139
164-
13. Rebuild and serve
140+
11. Rebuild and serve
165141
166142
```bash
167143
npm install

0 commit comments

Comments
 (0)