|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eux |
| 4 | + |
| 5 | +export OUTPUT_DIRECTORY=../temp/typescript/angular_ng |
| 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. Install @angular/cli |
| 18 | +npm install -g @angular/cli |
| 19 | + |
| 20 | +# 2. Create Angular application |
| 21 | +ng new angular_ng --directory ./ --minimal --routing=false --skip-git --ssr=false --style=css |
| 22 | + |
| 23 | +# 3. Build and serve the initial project |
| 24 | +# npm run build |
| 25 | +# # npm run start |
| 26 | +# In a web browser navigate to http://localhost:4200/ |
| 27 | + |
| 28 | +# 4. 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. |
| 29 | +npm install ../../../../bokeh-bokehjs-3.8.0-dev.1.tgz |
| 30 | + |
| 31 | +# 5. Create a new file src/app/bokeh-js/bokeh-js.component.ts containing a BokehJS plot component |
| 32 | +mkdir -p src/app/bokeh-js |
| 33 | +cat > src/app/bokeh-js/bokeh-js.component.ts << EOF |
| 34 | +import { Component, OnInit } from '@angular/core' |
| 35 | +import * as Bokeh from "@bokeh/bokehjs"; |
| 36 | +
|
| 37 | +function create_bokehjs_plot(): Bokeh.Column { |
| 38 | + const source = new Bokeh.ColumnDataSource({data: { x: [0.1, 0.9], y: [0.1, 0.9], size: [40, 10] }}); |
| 39 | +
|
| 40 | + const plot = Bokeh.Plotting.figure({ |
| 41 | + title: "Example BokehJS plot", height: 500, width: 500, |
| 42 | + x_range: [0, 1], y_range: [0, 1], sizing_mode: "stretch_width", |
| 43 | + }); |
| 44 | +
|
| 45 | + plot.scatter({ field: "x" }, { field: "y" }, {source, size: { field: "size" }}); |
| 46 | +
|
| 47 | + const button = new Bokeh.Widgets.Button({label: "Click me to add a point", button_type: "primary"}); |
| 48 | + function button_callback() { |
| 49 | + const data = source.data as any; |
| 50 | + data.x.push(Math.random()); |
| 51 | + data.y.push(Math.random()); |
| 52 | + data.size.push(10 + Math.random()*30); |
| 53 | + source.change.emit(); |
| 54 | + } |
| 55 | + button.on_click(button_callback); |
| 56 | +
|
| 57 | + return new Bokeh.Column({children: [plot, button], sizing_mode: "stretch_width"}); |
| 58 | +} |
| 59 | +
|
| 60 | +@Component({ |
| 61 | + selector: 'app-bokeh-js', |
| 62 | + imports: [], |
| 63 | + template: \`<div id="target"></div>\`, |
| 64 | + styles: \`\` |
| 65 | +}) |
| 66 | +
|
| 67 | +export class BokehJSComponent implements OnInit { |
| 68 | + ngOnInit() { |
| 69 | + console.info("BokehJS version:", Bokeh.version); |
| 70 | + Bokeh.Plotting.show(create_bokehjs_plot(), "#target"); |
| 71 | + } |
| 72 | +} |
| 73 | +EOF |
| 74 | + |
| 75 | +# 6. Replace src/app/app.component.ts so that it uses the BokehJSComponent |
| 76 | +cat > src/app/app.component.ts << EOF |
| 77 | +import { Component } from '@angular/core' |
| 78 | +import { BokehJSComponent } from './bokeh-js/bokeh-js.component'; |
| 79 | +
|
| 80 | +@Component({ |
| 81 | + selector: 'app-root', |
| 82 | + imports: [BokehJSComponent], |
| 83 | + template: \`<app-bokeh-js></app-bokeh-js>\`, |
| 84 | + styles: [], |
| 85 | +}) |
| 86 | +
|
| 87 | +export class AppComponent {} |
| 88 | +EOF |
| 89 | + |
| 90 | +# 7. Remove some build warnings by allowing non ESM imports by adding to angular.json |
| 91 | +cat > temp.json << EOF |
| 92 | +{ |
| 93 | + "projects": { |
| 94 | + "angular_ng": { |
| 95 | + "architect": { |
| 96 | + "build": { |
| 97 | + "options": { |
| 98 | + "allowedCommonJsDependencies": [ |
| 99 | + "@bokeh/bokehjs", |
| 100 | + "mathjax-full", |
| 101 | + "regl" |
| 102 | + ] |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | +EOF |
| 110 | +merge-json angular.json temp.json |
| 111 | +rm temp.json |
| 112 | + |
| 113 | +# 8. Remove bundle size limits in angular.json by setting the "budgets" to an empty array |
| 114 | +cat > temp.json << EOF |
| 115 | +{ |
| 116 | + "projects": { |
| 117 | + "angular_ng": { |
| 118 | + "architect": { |
| 119 | + "build": { |
| 120 | + "configurations": { |
| 121 | + "production": { |
| 122 | + "budgets": [ |
| 123 | + ] |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | +EOF |
| 132 | +merge-json angular.json temp.json |
| 133 | +rm temp.json |
| 134 | + |
| 135 | +# 9. Rebuild and Serve the project |
| 136 | +npm run build |
| 137 | +# npm run start |
| 138 | +# In a web browser navigate to http://localhost:4200/ |
0 commit comments