Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08fec29

Browse files
authored
Merge pull requestplotly#62 from plotly/issue-61
Quickfix on PlotlyViaCDNModule
2 parents4822d7d +8f8832c commit08fec29

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

‎src/app/demo/demo.module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as PlotlyJS from 'plotly.js/dist/plotly.js';
88
import{HomeComponent}from'./home/home.component';
99
import{DemoComponent}from'./demo.component';
1010

11-
import{PlotlyModule}from'../plotly/plotly.module';
12-
//import { PlotlyViaCDNModule } from '../plotly-via-cdn/plotly-via-cdn.module';
11+
//import { PlotlyModule } from '../plotly/plotly.module';
12+
import{PlotlyViaCDNModule}from'../plotly-via-cdn/plotly-via-cdn.module';
1313
// import { PlotlyViaWindowModule } from '../plotly-via-window/plotly-via-window.module';
1414

1515
// Examples
@@ -38,15 +38,16 @@ const demoRoutes: Routes = [
3838
];
3939

4040

41-
PlotlyModule.plotlyjs=PlotlyJS;
42-
// PlotlyViaCDNModule.plotlyVersion = 'latest';
41+
// PlotlyModule.plotlyjs = PlotlyJS;
42+
PlotlyViaCDNModule.plotlyVersion='1.5.0';
43+
// PlotlyViaCDNModule.plotlyBundle = 'cartesian';
4344

4445
@NgModule({
4546
imports:[
4647
CommonModule,
4748
HttpClientModule,
48-
PlotlyModule,
49-
//PlotlyViaCDNModule,
49+
//PlotlyModule,
50+
PlotlyViaCDNModule,
5051
// PlotlyViaWindowModule,
5152
RouterModule.forRoot(demoRoutes,{enableTracing:true}),
5253
],

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export class PlotlyViaCDNModule {
1818
privatestatic_plotlyVersion:string='latest';
1919
staticplotlyBundleNames:PlotlyBundleName[]=['basic','cartesian','geo','gl3d','gl2d','mapbox','finance'];
2020

21+
constructor(publicplotlyService:PlotlyService){
22+
PlotlyService.setModuleName('ViaCDN');
23+
}
24+
2125
staticsetplotlyVersion(version:string){
2226
constisOk=version==='latest'||/^\d\.\d{1,2}\.\d{1,2}$/.test(version);
2327
if(!isOk){
2428
thrownewError(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)`);
2529
}
2630

31+
PlotlyViaCDNModule.loadViaCDN();
2732
PlotlyViaCDNModule._plotlyVersion=version;
2833
}
2934

@@ -39,33 +44,38 @@ export class PlotlyViaCDNModule {
3944

4045
staticloadViaCDN(){
4146
PlotlyService.setPlotly('waiting');
42-
constsrc=PlotlyViaCDNModule._plotlyBundle==null
43-
?`https://cdn.plot.ly/plotly-${PlotlyViaCDNModule._plotlyVersion}.min.js`
44-
:`https://cdn.plot.ly/plotly-${PlotlyViaCDNModule._plotlyBundle}-${PlotlyViaCDNModule._plotlyBundle}.min.js`;
45-
46-
constscript:HTMLScriptElement=document.createElement('script');
47-
script.type='text/javascript';
48-
script.src=src;
49-
script.onerror=()=>console.error(`Error loading plotly.js library from${src}`);
50-
51-
consthead:HTMLHeadElement=document.getElementsByTagName('head')[0];
52-
head.appendChild(script);
53-
54-
letcounter=200;// equivalent of 10 seconds...
55-
56-
constfn=()=>{
57-
constplotly=(windowasany).Plotly;
58-
if(plotly){
59-
PlotlyService.setPlotly(plotly);
60-
}elseif(counter>0){
61-
counter--;
62-
setTimeout(fn,50);
63-
}else{
64-
thrownewError(`Error loading plotly.js library from${src}. Timeout.`);
65-
}
47+
48+
constinit=()=>{
49+
constsrc=PlotlyViaCDNModule._plotlyBundle==null
50+
?`https://cdn.plot.ly/plotly-${PlotlyViaCDNModule._plotlyVersion}.min.js`
51+
:`https://cdn.plot.ly/plotly-${PlotlyViaCDNModule._plotlyBundle}-${PlotlyViaCDNModule._plotlyVersion}.min.js`;
52+
53+
constscript:HTMLScriptElement=document.createElement('script');
54+
script.type='text/javascript';
55+
script.src=src;
56+
script.onerror=()=>console.error(`Error loading plotly.js library from${src}`);
57+
58+
consthead:HTMLHeadElement=document.getElementsByTagName('head')[0];
59+
head.appendChild(script);
60+
61+
letcounter=200;// equivalent of 10 seconds...
62+
63+
constfn=()=>{
64+
constplotly=(windowasany).Plotly;
65+
if(plotly){
66+
PlotlyService.setPlotly(plotly);
67+
}elseif(counter>0){
68+
counter--;
69+
setTimeout(fn,50);
70+
}else{
71+
thrownewError(`Error loading plotly.js library from${src}. Timeout.`);
72+
}
73+
};
74+
75+
fn();
6676
};
6777

68-
fn();
78+
setTimeout(init);
6979
}
7080

7181
staticforRoot(config:Partial<{version:string}>):never{

‎src/app/shared/plotly.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import{Injectable}from'@angular/core';
22
import{Plotly}from'./plotly.interface';
33

4+
typePlotlyName='Plotly'|'ViaCDN'|'ViaWindow';
5+
46

57
@Injectable({
68
providedIn:'root'
79
})
810
exportclassPlotlyService{
911
protectedstaticinstances:Plotly.PlotlyHTMLElement[]=[];
1012
protectedstatic_plotly?:any=undefined;
13+
protectedstatic_moduleName?:PlotlyName;
14+
15+
publicstaticsetModuleName(moduleName:PlotlyName){
16+
PlotlyService._moduleName=moduleName;
17+
}
1118

1219
publicstaticsetPlotly(plotly:any){
1320
PlotlyService._plotly=plotly;
@@ -40,7 +47,11 @@ export class PlotlyService {
4047

4148
publicgetPlotly(){
4249
if(typeofPlotlyService._plotly==='undefined'){
43-
thrownewError(`Peer dependency plotly.js isn't installed`);
50+
constmsg=PlotlyService._moduleName==='ViaCDN'
51+
?`Error loading Peer dependency plotly.js from CDN url`
52+
:`Peer dependency plotly.js isn't installed`;
53+
54+
thrownewError(msg);
4455
}
4556

4657
returnPlotlyService._plotly;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp