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

Commita4aeb72

Browse files
authored
Merge pull requestplotly#51 from plotly/separated-bundle
Separated bundle
2 parentsa57c9b4 +e892381 commita4aeb72

File tree

7 files changed

+90
-22
lines changed

7 files changed

+90
-22
lines changed

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ Add the `PlotlyModule` into the main app module of your project
4343
import {NgModule }from'@angular/core';
4444
import {CommonModule }from'@angular/common';
4545

46+
import*asPlotlyJSfrom'plotly.js/dist/plotly.js';
4647
import {PlotlyModule }from'angular-plotly.js';
4748

49+
PlotlyModule.plotlyjs=PlotlyJS;
50+
4851
@NgModule({
4952
imports: [CommonModule,PlotlyModule],
5053
...

‎package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { CommonModule } from '@angular/common';
33
import{HttpClientModule}from'@angular/common/http';
44
import{RouterModule,Routes}from'@angular/router';
55

6+
import*asPlotlyJSfrom'plotly.js/dist/plotly.js';
7+
68
import{HomeComponent}from'./home/home.component';
79
import{DemoComponent}from'./demo.component';
810

@@ -33,12 +35,16 @@ const demoRoutes: Routes = [
3335
{path:'',redirectTo:'/home',pathMatch:'full'},
3436
];
3537

38+
39+
PlotlyModule.plotlyjs=PlotlyJS;
40+
// PlotlyViaCDNModule.plotlyVersion = 'latest';
41+
3642
@NgModule({
3743
imports:[
3844
CommonModule,
3945
HttpClientModule,
4046
PlotlyModule,
41-
// PlotlyViaCDNModule.forRoot({version: 'latest'}),
47+
// PlotlyViaCDNModule,
4248
// PlotlyViaWindowModule,
4349
RouterModule.forRoot(demoRoutes,{enableTracing:true}),
4450
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class PlotlyViaCDNModule {
5151
fn();
5252
}
5353

54-
staticforRoot(config:Partial<{version:string}>):ModuleWithProviders{
54+
staticforRoot(config:Partial<{version:string}>):ModuleWithProviders<PlotlyViaCDNModule>{
5555
if(config.version===undefined){
5656
console.warn(`It's strongly recommended that you set a plotly version when using via CDN.`);
5757
config.version='latest';

‎src/app/plotly/plotly.module.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import{PlotlyModule}from"./plotly.module";
2+
3+
4+
5+
describe('PlotlyModule',()=>{
6+
7+
it('should create',()=>{
8+
constfn=()=>{
9+
constmod=newPlotlyModule();
10+
};
11+
12+
constmsg="Invalid PlotlyJS object. Please check https://github.com/plotly/angular-plotly.js#quick-start"
13+
+" to see how to add PlotlyJS to your project.";
14+
expect(fn).toThrowError(msg);
15+
16+
17+
constfn2=()=>{
18+
PlotlyModule.plotlyjs={plot:function(){}};
19+
constmod=newPlotlyModule();
20+
};
21+
22+
expect(fn2).not.toThrowError(msg);
23+
});
24+
25+
});

‎src/app/plotly/plotly.module.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import{NgModule,ModuleWithProviders}from'@angular/core';
1+
import{NgModule}from'@angular/core';
22
import{CommonModule}from'@angular/common';
33

4-
import*asPlotlyJSfrom'plotly.js/dist/plotly.js';
5-
64
import{PlotComponent}from'../shared/plot/plot.component';
75
import{PlotlyService}from'../shared/plotly.service';
86
import{SharedModule}from'../shared/shared.module';
@@ -14,14 +12,20 @@ import { SharedModule } from '../shared/shared.module';
1412
exports:[PlotComponent]
1513
})
1614
exportclassPlotlyModule{
15+
publicstaticplotlyjs:any={};
16+
1717
constructor(){
18-
PlotlyService.setPlotly(PlotlyJS);
18+
if(!this.isValid()){
19+
constmsg="Invalid PlotlyJS object. Please check https://github.com/plotly/angular-plotly.js#quick-start"
20+
+" to see how to add PlotlyJS to your project.";
21+
thrownewError(msg);
22+
}
23+
24+
PlotlyService.setPlotly(PlotlyModule.plotlyjs);
1925
}
2026

21-
staticforRoot():ModuleWithProviders{
22-
return{
23-
ngModule:PlotlyModule,
24-
providers:[PlotlyService]
25-
};
27+
privateisValid():boolean{
28+
returnPlotlyModule.plotlyjs!==undefined
29+
&&typeofPlotlyModule.plotlyjs.plot==='function';
2630
}
2731
}

‎src/app/shared/plot/plot.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ describe('PlotComponent', () => {
141141
},13);
142142
});
143143

144+
it('should fail when plotlyInstance is undefined',()=>{
145+
component.plotlyInstance=undefined;
146+
147+
consterror=newError(`Plotly component wasn't initialized`);
148+
constfn=()=>{
149+
component.updatePlot();
150+
};
151+
152+
expect(fn).toThrow(error);
153+
});
154+
144155
it('should add handler into window.resize when useResizeHandler=true',()=>{
145156
spyOn(component,'getWindow').and.callFake(()=>windowSpy);
146157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp