Skip to content

Commit 3818147

Browse files
authored
Merge pull request plotly#55 from jraadt/master
Add bundle config option when loading from CDN.
2 parents 84c4189 + b134534 commit 3818147

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/app/plotly-via-cdn/plotly-via-cdn.module.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ import { SharedModule } from '../shared/shared.module';
1111
exports: [PlotComponent]
1212
})
1313
export class PlotlyViaCDNModule {
14+
static plotlyBundle?: string;
1415
static plotlyVersion?: string = 'latest';
1516

17+
static setPlotlyBundle(bundle: string) {
18+
const isOk = bundle == null || bundle === 'basic' || bundle == 'cartesian' || bundle == 'geo' || bundle == 'gl3d' || bundle == 'gl2d' || bundle == 'mapbox' || bundle == 'finance';
19+
if (!isOk) {
20+
throw new Error(`Invalid plotly bundle. Please set null for full or 'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox', 'finance' for a partial bundle.`);
21+
}
22+
23+
PlotlyViaCDNModule.plotlyBundle = bundle;
24+
}
25+
1626
static setPlotlyVersion(version: string) {
1727
const isOk = version === 'latest' || /^\d\.\d{1,2}\.\d{1,2}$/.test(version);
1828
if (!isOk) {
@@ -24,7 +34,7 @@ export class PlotlyViaCDNModule {
2434

2535
static loadViaCDN() {
2636
PlotlyService.setPlotly('waiting');
27-
const src = `https://cdn.plot.ly/plotly-${PlotlyViaCDNModule.plotlyVersion}.min.js`;
37+
const src = PlotlyViaCDNModule.plotlyBundle == null ? `https://cdn.plot.ly/plotly-${PlotlyViaCDNModule.plotlyVersion}.min.js` : `https://cdn.plot.ly/plotly-${PlotlyViaCDNModule.plotlyBundle}-${PlotlyViaCDNModule.plotlyVersion}.min.js`;
2838

2939
const script: HTMLScriptElement = document.createElement('script');
3040
script.type = 'text/javascript';
@@ -51,12 +61,13 @@ export class PlotlyViaCDNModule {
5161
fn();
5262
}
5363

54-
static forRoot(config: Partial<{version: string}>): ModuleWithProviders<PlotlyViaCDNModule> {
64+
static forRoot(config: Partial<{version: string, bundle: string}>): ModuleWithProviders<PlotlyViaCDNModule> {
5565
if (config.version === undefined) {
5666
console.warn(`It's strongly recommended that you set a plotly version when using via CDN.`);
5767
config.version = 'latest';
5868
}
5969

70+
PlotlyViaCDNModule.setPlotlyBundle(config.bundle);
6071
PlotlyViaCDNModule.setPlotlyVersion(config.version);
6172
PlotlyViaCDNModule.loadViaCDN();
6273

0 commit comments

Comments
 (0)