Skip to content

Commit 6d503b2

Browse files
committed
- feat: give minimap an optional margin
- fix: blocker for drawing minimap in some instances - fix: restyle minimap colors - fix: drawComplete should fire when all nodes are ready
1 parent 5501254 commit 6d503b2

4 files changed

Lines changed: 49 additions & 13 deletions

File tree

projects/swimlane/ngx-graph/src/lib/enums/mini-map-position.enum.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ export enum MiniMapPosition {
44
LowerLeft = 'LowerLeft',
55
LowerRight = 'LowerRight'
66
}
7+
8+
export interface MiniMapMargin {
9+
top: number;
10+
right: number;
11+
bottom: number;
12+
left: number;
13+
}
14+
15+
export const DefaultMiniMapMargin = {
16+
top: 0,
17+
right: 0,
18+
bottom: 0,
19+
left: 0
20+
};

projects/swimlane/ngx-graph/src/lib/graph/graph.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"
169169
>
170170
<svg:g class="minimap-nodes" [style.transform]="'scale(' + 1 / minimapScaleCoefficient + ')'">
171-
@for (node of graph.nodes; track trackNodeBy($index, node)) {
171+
@for (node of graph?.nodes ?? []; track trackNodeBy($index, node)) {
172172
<svg:g
173173
#nodeElement
174174
class="node-group"

projects/swimlane/ngx-graph/src/lib/graph/graph.component.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414

1515
.minimap {
1616
.minimap-background {
17-
fill: rgba(0, 0, 0, 0.1);
17+
fill: rgba(33, 38, 49, 0.5);
1818
}
1919

2020
.minimap-drag {
21-
fill: rgba(0, 0, 0, 0.2);
22-
stroke: rgba(255, 255, 255, 1);
21+
fill: rgba(0, 0, 0, 0.1);
22+
stroke: rgba(114, 129, 159, 1);
2323
stroke-width: 1px;
2424
stroke-dasharray: 2px;
2525
stroke-dashoffset: 2px;
2626
cursor: pointer;
2727

2828
&.panning {
29-
fill: rgba(0, 0, 0, 0.3);
29+
fill: rgba(0, 0, 0, 0.1);
3030
}
3131
}
3232

projects/swimlane/ngx-graph/src/lib/graph/graph.component.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { Node, ClusterNode, CompoundNode } from '../models/node.model';
3838
import { Graph } from '../models/graph.model';
3939
import { id } from '../utils/id';
4040
import { PanningAxis } from '../enums/panning.enum';
41-
import { MiniMapPosition } from '../enums/mini-map-position.enum';
41+
import { MiniMapPosition, DefaultMiniMapMargin, MiniMapMargin } from '../enums/mini-map-position.enum';
4242
import { throttleable } from '../utils/throttle';
4343
import { ColorHelper } from '../utils/color.helper';
4444
import { ViewDimensions, calculateViewDimensions } from '../utils/view-dimensions.helper';
@@ -139,6 +139,7 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
139139
readonly miniMapMaxWidth = input<number>(100);
140140
readonly miniMapMaxHeight = input<number>(undefined);
141141
readonly miniMapPosition = input<MiniMapPosition>(MiniMapPosition.UpperRight);
142+
readonly miniMapMargin = input<MiniMapMargin>(DefaultMiniMapMargin);
142143
readonly view = input<[number, number]>(undefined);
143144
readonly scheme = input<any>('cool');
144145
readonly customColors = input<any>(undefined);
@@ -229,6 +230,7 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
229230
height: number;
230231
resizeSubscription: any;
231232
visibilityObserver: VisibilityObserver;
233+
private waitForGraphDims: ReturnType<typeof setInterval>;
232234
private destroy$ = new Subject<void>();
233235

234236
/** Latest requestAnimationFrame id per edge for imperative path morphing (cancel on relayout / drag). */
@@ -375,6 +377,13 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
375377
});
376378
}
377379

380+
this.waitForGraphDims = setInterval(() => {
381+
if (this.hasDims()) {
382+
clearInterval(this.waitForGraphDims);
383+
this.drawComplete.emit();
384+
}
385+
}, 1000);
386+
378387
this.minimapClipPathId = `minimapClip${id()}`;
379388
this.stateChange.emit({ state: NgxGraphStates.Subscribe });
380389
}
@@ -432,6 +441,9 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
432441
this.visibilityObserver.visible.unsubscribe();
433442
this.visibilityObserver.destroy();
434443
}
444+
if (this.waitForGraphDims) {
445+
clearInterval(this.waitForGraphDims);
446+
}
435447
this.destroy$.next();
436448
this.destroy$.complete();
437449
}
@@ -1480,20 +1492,32 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
14801492
getMinimapTransform(): string {
14811493
switch (this.miniMapPosition()) {
14821494
case MiniMapPosition.UpperLeft: {
1483-
return '';
1495+
return 'translate(' + this.miniMapMargin().left + ',' + this.miniMapMargin().top + ')';
14841496
}
14851497
case MiniMapPosition.UpperRight: {
1486-
return 'translate(' + (this.dims.width - this.graphDims.width / this.minimapScaleCoefficient) + ',' + 0 + ')';
1498+
return (
1499+
'translate(' +
1500+
(this.dims.width - this.graphDims.width / this.minimapScaleCoefficient - this.miniMapMargin().right) +
1501+
',' +
1502+
this.miniMapMargin().top +
1503+
')'
1504+
);
14871505
}
14881506
case MiniMapPosition.LowerLeft: {
1489-
return 'translate(' + 0 + ',' + (this.dims.height - this.graphDims.height / this.minimapScaleCoefficient) + ')';
1507+
return (
1508+
'translate(' +
1509+
this.miniMapMargin().left +
1510+
',' +
1511+
(this.dims.height - this.graphDims.height / this.minimapScaleCoefficient - this.miniMapMargin().bottom) +
1512+
')'
1513+
);
14901514
}
14911515
case MiniMapPosition.LowerRight: {
14921516
return (
14931517
'translate(' +
1494-
(this.dims.width - this.graphDims.width / this.minimapScaleCoefficient) +
1518+
(this.dims.width - this.graphDims.width / this.minimapScaleCoefficient - this.miniMapMargin().right) +
14951519
',' +
1496-
(this.dims.height - this.graphDims.height / this.minimapScaleCoefficient) +
1520+
(this.dims.height - this.graphDims.height / this.minimapScaleCoefficient - this.miniMapMargin().bottom) +
14971521
')'
14981522
);
14991523
}
@@ -1797,8 +1821,6 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
17971821
return;
17981822
}
17991823
this.stateChange.emit({ state: NgxGraphStates.Output });
1800-
// TODO: The 'emit' function requires a mandatory void argument
1801-
this.drawComplete.emit();
18021824
}
18031825

18041826
private cancelEdgePathAnimation(edgeId: string): void {

0 commit comments

Comments
 (0)