Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06f2cf1

Browse files
committed
Updating README.md
1 parent f1f6943 commit 06f2cf1

File tree

1 file changed

+105
-2
lines changed

1 file changed

+105
-2
lines changed

README.md

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ import { CommonModule } from '@angular/common';
4949
import * as PlotlyJS from 'plotly.js-dist-min';
5050
import { PlotlyModule } from 'angular-plotly.js';
5151

52-
PlotlyModule.plotlyjs = PlotlyJS;
5352

5453
@NgModule({
55-
imports: [CommonModule, PlotlyModule],
54+
imports: [
55+
CommonModule,
56+
PlotlyModule.forRoot(PlotlyJS)
57+
],
5658
...
5759
})
5860
export class AppModule { }
@@ -182,6 +184,107 @@ will put the user template into the root *\<div\>* of the resulting *plotly.js*
182184
in front of any plotly-generated elements. This could be useful for implementing plot overlays.
183185

184186

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:
197+
198+
```typescript
199+
import { NgModule } from '@angular/core';
200+
import { CommonModule } from '@angular/common';
201+
202+
import { PlotlyViaCDNModule } from 'angular-plotly.js';
203+
204+
205+
@NgModule({
206+
imports: [
207+
CommonModule,
208+
PlotlyViaCDNModule.forRoot({
209+
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+
export class AppModule { }
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:
269+
270+
271+
```typescript
272+
import { NgModule } from '@angular/core';
273+
import { CommonModule } from '@angular/common';
274+
275+
import { PlotlyViaWindowModule } from 'angular-plotly.js';
276+
277+
@NgModule({
278+
imports: [CommonModule, PlotlyViaWindowModule],
279+
...
280+
})
281+
export class AppModule { }
282+
```
283+
284+
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.
285+
286+
287+
185288
## Development
186289

187290
To get started:

0 commit comments

Comments
 (0)