You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+105-2Lines changed: 105 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -49,10 +49,12 @@ import { CommonModule } from '@angular/common';
49
49
import*asPlotlyJSfrom'plotly.js-dist-min';
50
50
import { PlotlyModule } from'angular-plotly.js';
51
51
52
-
PlotlyModule.plotlyjs=PlotlyJS;
53
52
54
53
@NgModule({
55
-
imports: [CommonModule, PlotlyModule],
54
+
imports: [
55
+
CommonModule,
56
+
PlotlyModule.forRoot(PlotlyJS)
57
+
],
56
58
...
57
59
})
58
60
exportclassAppModule { }
@@ -182,6 +184,107 @@ will put the user template into the root *\<div\>* of the resulting *plotly.js*
182
184
in front of any plotly-generated elements. This could be useful for implementing plot overlays.
183
185
184
186
187
+
## Customizing the `plotly.js` bundle
188
+
189
+
By default, this library bundles `plotly.js` from the peer dependency together within the output. This results on huge outputs, for `plotly.js` itself is ~3MB when bundled. It also makes the build (with `ng serve --prod`) really slow, for it minifies everything together.
190
+
191
+
If you wish to optimize loading `plotly.js` in a different way, please check both [`PlotlyViaCDNModule`](#plotly-via-cdn-module) and [`PlotlyViaWindowModule`](#plotly-via-window-module) modules below.
192
+
193
+
194
+
### Plotly Via CDN Module
195
+
196
+
If you want to load `plotly.js`[from a CDN](https://github.com/plotly/plotly.js?tab=readme-ov-file#load-via-script-tag), use the `PlotlyViaCDNModule` and set on the `version` argument the plotly.js's version you want to use and, optionally, you can also set on the `bundleName` argument the plotly.js's build you want to use:
version: '1.55.2'// can be `latest` or any version number (i.e.: '1.40.0')
210
+
bundleName: 'basic'// optional: can be null (for full) or 'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox' or 'finance'
211
+
}),
212
+
],
213
+
...
214
+
})
215
+
exportclassAppModule { }
216
+
```
217
+
218
+
By default, plotly's CDN is used to fetch the requested bundle.js. However, you can either choose `plotly`, `cloudflare` or `custom`.
219
+
220
+
```typescript
221
+
...
222
+
223
+
// For cloudflare
224
+
PlotlyViaCDNModule.forRoot({
225
+
version: '1.55.2',
226
+
cdnProvider: 'cloudflare', // cloudflare doesn't support `latest`. It is mandatory to supply version.
227
+
bundleName: 'basic'// optional: can be null (for full) or 'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox' or 'finance'
228
+
});
229
+
230
+
231
+
// For custom CDN URL
232
+
PlotlyViaCDNModule.loadViaCDN('custom', );
233
+
PlotlyViaCDNModule.forRoot({
234
+
cdnProvider: 'custom', // cloudflare doesn't support `latest`. It is mandatory to supply version.
235
+
customUrl: 'https://custom.cdn/url'// can be used directly for any self hosted plotly bundle
236
+
});
237
+
238
+
...
239
+
```
240
+
241
+
### Plotly Via Window Module
242
+
243
+
`plotly.js` can be added as a [global script on angular.json](https://github.com/angular/angular-cli/wiki/stories-global-scripts#global-scripts) to avoid it being bundled into the final project's code. To make this happen, you must first add `plotly.js` path into `angular.json` file as shown below:
244
+
245
+
```javascript
246
+
// angular.json
247
+
{
248
+
...
249
+
"projects": {
250
+
"project-name": { // This is your project's name
251
+
...
252
+
"architect": {
253
+
"build": {
254
+
...
255
+
"options": {
256
+
"scripts": [
257
+
"node_modules/plotly.js-dist-min/plotly.min.js"// add this
258
+
]
259
+
}
260
+
}
261
+
}
262
+
...
263
+
}
264
+
}
265
+
}
266
+
```
267
+
268
+
This will include `plotly.js` into the `vendor.js` file generated by angular CLI build process, and `plotly.js` library will be loaded before angular and your project's code. The `window.Plotly` will be available. Thus, you must use `PlotlyViaWindowModule` module to force `angular-plotly.js` to use `window.Plotly` object:
If you want to use a [different precompiled bundle](https://github.com/plotly/plotly.js/blob/master/dist/README.md#partial-bundles) or if you wish to [assemble you own customized bundle](https://github.com/plotly/plotly.js#modules), you can use `PlotlyViaWindowModule` to force the use of `window.Plotly` object as shown above.
0 commit comments