@@ -11,8 +11,18 @@ import { SharedModule } from '../shared/shared.module';
11
11
exports : [ PlotComponent ]
12
12
} )
13
13
export class PlotlyViaCDNModule {
14
+ static plotlyBundle ?: string ;
14
15
static plotlyVersion ?: string = 'latest' ;
15
16
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
+
16
26
static setPlotlyVersion ( version : string ) {
17
27
const isOk = version === 'latest' || / ^ \d \. \d { 1 , 2 } \. \d { 1 , 2 } $ / . test ( version ) ;
18
28
if ( ! isOk ) {
@@ -24,7 +34,7 @@ export class PlotlyViaCDNModule {
24
34
25
35
static loadViaCDN ( ) {
26
36
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`;
28
38
29
39
const script : HTMLScriptElement = document . createElement ( 'script' ) ;
30
40
script . type = 'text/javascript' ;
@@ -51,12 +61,13 @@ export class PlotlyViaCDNModule {
51
61
fn ( ) ;
52
62
}
53
63
54
- static forRoot ( config : Partial < { version : string } > ) : ModuleWithProviders < PlotlyViaCDNModule > {
64
+ static forRoot ( config : Partial < { version : string , bundle : string } > ) : ModuleWithProviders < PlotlyViaCDNModule > {
55
65
if ( config . version === undefined ) {
56
66
console . warn ( `It's strongly recommended that you set a plotly version when using via CDN.` ) ;
57
67
config . version = 'latest' ;
58
68
}
59
69
70
+ PlotlyViaCDNModule . setPlotlyBundle ( config . bundle ) ;
60
71
PlotlyViaCDNModule . setPlotlyVersion ( config . version ) ;
61
72
PlotlyViaCDNModule . loadViaCDN ( ) ;
62
73
0 commit comments