Skip to content

Commit 5294d55

Browse files
committed
feat: add plotly link, stack components
1 parent 646b453 commit 5294d55

File tree

13 files changed

+81
-5
lines changed

13 files changed

+81
-5
lines changed

apps/dev-server/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ import { PlotType } from 'plotly.js';
107107
} as Layout;
108108

109109
plot(data, layout);
110+
plot(data, layout);
110111
})();

apps/web/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TutorialComponent } from './components/tutorial/tutorial.component';
1313
import { PlotsService } from './services/plots.service';
1414
import { MatSidenavModule } from '@angular/material/sidenav';
1515
import { MatListModule } from '@angular/material/list';
16+
import { PlotComponent } from './components/plot/plot.component';
1617

1718
@NgModule({
1819
declarations: [
@@ -21,6 +22,7 @@ import { MatListModule } from '@angular/material/list';
2122
StacksComponent,
2223
StackComponent,
2324
OverviewComponent,
25+
PlotComponent,
2426
],
2527
imports: [
2628
AppRoutingModule,

apps/web/src/app/components/app/app.component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ mat-toolbar {
2626
flex: 0 0 auto;
2727
justify-content: space-between;
2828
}
29+
30+
.info-icons {
31+
display: flex;
32+
gap: 8px;
33+
}

apps/web/src/app/components/app/app.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
<span class="brand">
33
<button mat-flat-button color="primary">NodePlotLib</button>
44
</span>
5-
<span>
5+
<span class="info-icons">
66
<a href="https://github.com/ngfelixl/nodeplotlib" target="_blank"
77
><button mat-icon-button>
88
<img src="/assets/github-light-32px.png" /></button
99
></a>
10+
<a href="https://plotly.com/javascript/" target="_blank"
11+
><button mat-icon-button>
12+
<img src="/assets/plotly.svg" /></button
13+
></a>
1014
</span>
1115
</mat-toolbar>
1216
<main>

apps/web/src/app/components/plot/plot.component.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div #plotContainer></div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, Input, ViewChild } from '@angular/core';
2+
import { PlotData } from '@npl/interfaces';
3+
4+
// eslint-disable-next-line
5+
declare const Plotly: any;
6+
7+
@Component({
8+
selector: 'npl-plot',
9+
templateUrl: './plot.component.html',
10+
styleUrls: ['./plot.component.css'],
11+
changeDetection: ChangeDetectionStrategy.OnPush
12+
})
13+
export class PlotComponent implements AfterViewInit {
14+
@Input() plotData!: PlotData;
15+
@ViewChild('plotContainer', {static: false}) plotContainer!: ElementRef;
16+
17+
ngAfterViewInit() {
18+
Plotly.newPlot(
19+
this.plotContainer.nativeElement,
20+
this.plotData.data,
21+
{...(this.plotData.layout ?? {}), autosize: true},
22+
{responsive: true}
23+
)
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:host {
2+
display: grid;
3+
grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
4+
grid-gap: 24px;
5+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p>stack works!</p>
1+
<npl-plot *ngFor="let plot of plots$ | async" [plotData]="plot"></npl-plot>
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
3+
import { combineLatest, Observable } from 'rxjs';
4+
import { map, tap } from 'rxjs/operators';
5+
import { PlotsService } from '../../services/plots.service';
26

37
@Component({
48
selector: 'npl-stack',
59
templateUrl: './stack.component.html',
610
styleUrls: ['./stack.component.css'],
711
changeDetection: ChangeDetectionStrategy.OnPush,
812
})
9-
export class StackComponent {}
13+
export class StackComponent {
14+
stackId$: Observable<number|null> = this.activatedRoute.params.pipe(map(params => params.id ? +params.id : null), tap(console.log));
15+
plots$ = combineLatest([
16+
this.stackId$,
17+
this.plotsService.data$
18+
]).pipe(
19+
tap((data) => console.log(data)),
20+
map(([stackId, { stacks, plots }]) => {
21+
if (stackId === null) {
22+
return [];
23+
}
24+
const stack = stacks.entities[stackId];
25+
if (!stack) {
26+
return [];
27+
}
28+
29+
return stack.plotIds.map(id => plots.entities[id])
30+
})
31+
);
32+
33+
constructor(
34+
private activatedRoute: ActivatedRoute,
35+
private plotsService: PlotsService
36+
) {}
37+
}

0 commit comments

Comments
 (0)