Skip to content

Commit b786b4f

Browse files
authored
Merge pull request #73 from ngfelixl/feat/plot-configuration
feat: add optional config to plot function
2 parents c52e334 + ec0016c commit b786b4f

File tree

14 files changed

+41
-23
lines changed

14 files changed

+41
-23
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# <img src="./img/nodeplotlib_64x64.png" width="22px" height="22px"> NodePlotLib
22

33
[![NodeJS CI](https://github.com/ngfelixl/nodeplotlib/workflows/Node.js%20CI/badge.svg)](https://github.com/ngfelixl/nodeplotlib/actions?query=workflow%3A%22Node.js+CI%22)
4-
[![Coverage Status](https://coveralls.io/repos/github/ngfelixl/nodeplotlib/badge.svg?branch=master)](https://coveralls.io/github/ngfelixl/nodeplotlib?branch=master)
54
[![npm](https://img.shields.io/npm/v/nodeplotlib?color=#00f800)](https://npmjs.com/package/nodeplotlib)
65
[![npm](https://img.shields.io/npm/dt/nodeplotlib.svg)](https://npmjs.com/package/nodeplotlib)
76
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
8-
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/nodeplotlib/)
97

108
[![Animation (View on Github)](https://raw.githubusercontent.com/ngfelixl/nodeplotlib/master/img/animation-next.gif)](https://raw.githubusercontent.com/ngfelixl/nodeplotlib/master/img/animation-next.gif)
119

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
77
import { AppRoutingModule } from './app-routing.module';
88
import { AppComponent } from './components/app/app.component';
99
import { TutorialComponent } from './components/tutorial/tutorial.component';
10-
import { PlotsService } from './services/plots.service';
1110
import { MatSidenavModule } from '@angular/material/sidenav';
1211
import { MatListModule } from '@angular/material/list';
1312
import { PlotComponent } from './components/plot/plot.component';
1413
import { PlotsComponent } from './components/plots/plots.component';
15-
import { SocketService } from './services/socket.service';
1614
import { DragDropModule } from '@angular/cdk/drag-drop';
1715
import { MatCardModule } from '@angular/material/card';
1816
import { MatIconModule } from '@angular/material/icon';
@@ -39,7 +37,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
3937
MatIconModule,
4038
MatTooltipModule,
4139
],
42-
providers: [PlotsService, SocketService],
40+
providers: [],
4341
bootstrap: [AppComponent],
4442
})
4543
export class AppModule {}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class PlotComponent implements AfterViewInit, OnChanges {
2828
this.plotContainer.nativeElement,
2929
this.plotData.data,
3030
{ ...(this.plotData.layout ?? {}), autosize: true },
31-
{ responsive: true }
31+
{ ...(this.plotData.config ?? {}), responsive: true }
3232
);
3333
}
3434

@@ -38,7 +38,7 @@ export class PlotComponent implements AfterViewInit, OnChanges {
3838
this.plotContainer.nativeElement,
3939
this.plotData.data,
4040
{ ...(this.plotData.layout ?? {}), autosize: true },
41-
{ responsive: true }
41+
{ ...(this.plotData.config ?? {}), responsive: true }
4242
);
4343
}
4444
}

apps/web/src/app/services/plots.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Injectable } from '@angular/core';
22
import { PlotData } from '@npl/nodeplotlib';
33
import { BehaviorSubject } from 'rxjs';
4-
import { SocketService } from './socket.service';
54
import { map } from 'rxjs/operators';
5+
import { SocketService } from './socket.service';
66

7-
@Injectable()
7+
@Injectable({ providedIn: 'root' })
88
export class PlotsService {
99
private plotDataMap$ = new BehaviorSubject<Map<number, PlotData>>(new Map());
1010
plots$ = this.plotDataMap$.pipe(

apps/web/src/app/services/socket.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable, OnDestroy } from '@angular/core';
22
import { io, Socket } from 'socket.io-client';
33
import { environment } from '../../environments/environment';
44

5-
@Injectable()
5+
@Injectable({ providedIn: 'root' })
66
export class SocketService implements OnDestroy {
77
private socket: Socket;
88

libs/nodeplotlib/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# <img src="https://raw.githubusercontent.com/ngfelixl/nodeplotlib/master/img/nodeplotlib_64x64.png" width="28px" height="28px"> NodePlotLib
22

33
[![NodeJS CI](https://github.com/ngfelixl/nodeplotlib/workflows/Node.js%20CI/badge.svg)](https://github.com/ngfelixl/nodeplotlib/actions?query=workflow%3A%22Node.js+CI%22)
4-
[![Coverage Status](https://coveralls.io/repos/github/ngfelixl/nodeplotlib/badge.svg?branch=master)](https://coveralls.io/github/ngfelixl/nodeplotlib?branch=master)
54
[![npm](https://img.shields.io/npm/v/nodeplotlib?color=#00f800)](https://npmjs.com/package/nodeplotlib)
65
[![npm](https://img.shields.io/npm/dt/nodeplotlib.svg)](https://npmjs.com/package/nodeplotlib)
76
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
8-
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/nodeplotlib/)
97

108
[![Animation (View on Github)](https://raw.githubusercontent.com/ngfelixl/nodeplotlib/master/img/animation-next.gif)](https://raw.githubusercontent.com/ngfelixl/nodeplotlib/master/img/animation-next.gif)
119

@@ -85,13 +83,17 @@ plot(stream$);
8583
There are three exports. The `plot` function and types for the Plot and for the Layout.
8684

8785
```typescript
88-
import { plot, Plot, Layout } from 'nodeplotlib';
86+
import { plot, Plot, Layout, Config } from 'nodeplotlib';
8987
```
9088

9189
The `plot` function has the following structure
9290

9391
```typescript
94-
function plot(data: Plot[] | Observable<Plot[]>, layout?: Layout): void;
92+
function plot(
93+
data: Plot[] | Observable<Plot[]>,
94+
layout?: Layout,
95+
config?: Config
96+
): void;
9597
```
9698

9799
It does not return a Subscription for the Observables because you just need to close

libs/nodeplotlib/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodeplotlib",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "NodeJS frontend-less plotting lib using plotly.js inspired by matplotlib",
55
"author": "Felix Lemke <[email protected]> (https://felixlemke.dev)",
66
"license": "MIT",

libs/nodeplotlib/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Exports required for the actual nodeplotlib
2-
export { Plot, Layout } from './lib/interfaces/plot';
2+
export { Plot, Layout, Config } from './lib/interfaces/plot';
33
export { plot } from './lib/nodeplotlib';
44

55
// Exports required for the web app
+8-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import { Layout as PlotlyLayout, PlotData as PlotlyPlotData } from 'plotly.js';
1+
import {
2+
Layout as PlotlyLayout,
3+
PlotData as PlotlyPlotData,
4+
Config as PlotlyConfig,
5+
} from 'plotly.js';
26
import { Observable } from 'rxjs';
37

48
export type Plot = Partial<PlotlyPlotData>;
59
export type Layout = Partial<PlotlyLayout>;
10+
export type Config = Partial<PlotlyConfig>;
611

712
export interface PlotDataStream {
813
id: number;
914
data: Observable<Plot[]>;
1015
layout: Observable<Layout | undefined>;
16+
config: Config | undefined;
1117
}
1218

1319
export interface PlotData {
1420
id: number;
1521
data: Plot[];
1622
layout?: Layout;
23+
config?: Config;
1724
}

libs/nodeplotlib/src/lib/nodeplotlib.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PlotsService } from './server/plots/plots.service';
66
import { ServerModule } from './server/server.module';
77
import { BridgeService } from './server/services/bridge.service';
88
import { getPort } from './utils/get-port';
9+
import { Config } from './interfaces/plot';
910
let app: INestApplication | null = null;
1011
let plotsService: PlotsService;
1112
let bridgeService: BridgeService;
@@ -26,15 +27,19 @@ const port = getPort();
2627
* @param layout
2728
* @param cb
2829
*/
29-
export function plot(data: Plot[] | Observable<Plot[]>, layout?: Layout) {
30+
export function plot(
31+
data: Plot[] | Observable<Plot[]>,
32+
layout?: Layout,
33+
config?: Config
34+
) {
3035
bootstrap(port);
3136
const bufferedPlots = plotsBuffer$.value;
3237

3338
const streamData$: Observable<Plot[]> =
3439
data instanceof Observable ? data : of(data);
3540
plotsBuffer$.next([
3641
...bufferedPlots,
37-
{ data: streamData$, layout: of(layout) },
42+
{ data: streamData$, layout: of(layout), config },
3843
]);
3944
}
4045

libs/nodeplotlib/src/lib/server/plots/plots.gateway.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export class PlotsGateway implements OnGatewayConnection, OnGatewayDisconnect {
3030
return combineLatest([
3131
plotDataStream.data,
3232
plotDataStream.layout,
33-
]).pipe(map(([data, layout]) => ({ id, data, layout })));
33+
]).pipe(
34+
map(([data, layout]) => ({
35+
id,
36+
data,
37+
layout,
38+
config: plotDataStream.config,
39+
}))
40+
);
3441
})
3542
)
3643
),

libs/nodeplotlib/src/lib/server/plots/plots.service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class PlotsService {
2222
id: this.currentPlotId++,
2323
data: plotData.data,
2424
layout: plotData.layout,
25+
config: plotData.config,
2526
};
2627

2728
this.plotEntities.set(plot.id, plot);

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodeplotlib",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"scripts": {
66
"ng": "nx",

0 commit comments

Comments
 (0)