Skip to content

Commit 502776b

Browse files
committed
Unload graphviz after use; show warning in case of graphviz error
1 parent 8cc9c3b commit 502776b

File tree

5 files changed

+57
-27
lines changed

5 files changed

+57
-27
lines changed

desktop/src/app/components/matrix/edges-builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export module EdgesBuilder {
127127
}
128128

129129

130-
131130
function getIncludedRelationTargetIds(targetId: string, graphDocuments: Array<Document>,
132131
totalDocuments: Array<Document>,
133132
relations: GraphRelationsConfiguration,

desktop/src/app/components/matrix/export-graph.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
2-
import { Graphviz } from '@hpcc-js/wasm-graphviz';
32
import { AppState } from '../../services/app-state';
43
import { getAsynchronousFs } from '../../services/get-asynchronous-fs';
54
import { M } from '../messages/m';
@@ -13,16 +12,16 @@ const remote = window.require('@electron/remote');
1312
* @author Thomas Kleinke
1413
*/
1514
export async function exportGraph(dotGraph: string, projectName: string, trenchIdentifier: string, appState: AppState,
16-
graphviz: Graphviz, modalService: NgbModal, fileFilterLabel: string) {
15+
modalService: NgbModal, fileFilterLabel: string) {
1716

1817
const filePath: string = await chooseFilepath(projectName, trenchIdentifier, appState, fileFilterLabel);
1918
if (!filePath) throw 'canceled';
2019

2120
const modalRef: NgbModalRef = openExportModal(modalService);
22-
await AngularUtility.refresh();
21+
await AngularUtility.refresh(500);
2322

2423
try {
25-
await writeFile(filePath, graphviz.dot(dotGraph, 'dot'));
24+
await writeFile(filePath, dotGraph);
2625
} catch (errWithParams) {
2726
throw errWithParams;
2827
} finally {

desktop/src/app/components/matrix/matrix-view.component.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const SUPPORTED_OPERATION_CATEGORIES = ['Trench', 'ExcavationArea'];
5050
*/
5151
export class MatrixViewComponent implements OnInit {
5252

53-
// The latest svg calculated with GraphViz via DotBuilder based on our component's current settings.
53+
public dotGraph: string|undefined;
5454
public graph: string|undefined;
5555

5656
public graphFromSelection: boolean = false;
@@ -59,12 +59,11 @@ export class MatrixViewComponent implements OnInit {
5959
public operations: Array<FieldDocument> = [];
6060
public selectedOperation: FieldDocument|undefined;
6161
public configuredOperationCategories: string[] = [];
62+
public graphvizFailure: boolean = false;
6263

63-
private graphviz: Graphviz;
6464
private featureDocuments: Array<FeatureDocument> = [];
6565
private totalFeatureDocuments: Array<FeatureDocument> = [];
6666
private operationsLoaded: boolean = false;
67-
private dotGraph: string;
6867

6968

7069
constructor(private projectConfiguration: ProjectConfiguration,
@@ -114,7 +113,6 @@ export class MatrixViewComponent implements OnInit {
114113

115114
async ngOnInit() {
116115

117-
this.graphviz = await Graphviz.load();
118116
await this.matrixState.load();
119117
await this.populateOperations();
120118

@@ -169,39 +167,57 @@ export class MatrixViewComponent implements OnInit {
169167

170168
public async calculateGraph() {
171169

170+
this.dotGraph = undefined;
172171
this.graph = undefined;
172+
this.graphvizFailure = false;
173+
let dotGraph: string;
173174

174175
this.loading.start();
175-
await AngularUtility.refresh(100);
176176

177-
const edges: { [resourceId: string]: Edges } = EdgesBuilder.build(
178-
this.featureDocuments,
179-
this.totalFeatureDocuments,
180-
MatrixViewComponent.getRelationConfiguration(this.matrixState.getRelationsMode())
181-
);
182-
183-
this.dotGraph = DotBuilder.build(
184-
this.projectConfiguration,
185-
this.getPeriodMap(this.featureDocuments, this.matrixState.getClusterMode()),
186-
edges,
187-
this.matrixState.getLineMode() === 'curved'
188-
);
189-
190-
this.graph = this.graphviz.dot(this.dotGraph);
177+
await AngularUtility.blurActiveElement();
178+
await AngularUtility.refresh(500);
191179

192-
this.loading.stop();
180+
try {
181+
const edges: { [resourceId: string]: Edges } = EdgesBuilder.build(
182+
this.featureDocuments,
183+
this.totalFeatureDocuments,
184+
MatrixViewComponent.getRelationConfiguration(this.matrixState.getRelationsMode())
185+
);
186+
187+
dotGraph = DotBuilder.build(
188+
this.projectConfiguration,
189+
this.getPeriodMap(this.featureDocuments, this.matrixState.getClusterMode()),
190+
edges,
191+
this.matrixState.getLineMode() === 'curved'
192+
);
193+
} catch (err) {
194+
console.error(err);
195+
this.messages.add([M.MATRIX_ERROR_GENERIC]);
196+
return this.loading.stop();
197+
}
198+
199+
try {
200+
const graphviz: Graphviz = await Graphviz.load();
201+
this.graph = graphviz.dot(dotGraph);
202+
} catch (err) {
203+
this.graphvizFailure = true;
204+
} finally {
205+
Graphviz.unload();
206+
this.dotGraph = dotGraph;
207+
this.loading.stop();
208+
}
193209
}
194210

195-
196211
public async exportGraph() {
197212

213+
if (!this.dotGraph) return;
214+
198215
try {
199216
await exportGraph(
200217
this.dotGraph,
201218
this.settingsProvider.getSettings().selectedProject,
202219
this.selectedOperation.resource.identifier,
203220
this.appState,
204-
this.graphviz,
205221
this.modalService,
206222
$localize `:@@matrix.export.dotFile:Graphviz-Dot-Datei`
207223
);

desktop/src/app/components/matrix/matrix-view.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119

120120
<div id="export-button"
121121
class="btn btn-primary btn-square ms-2"
122+
[class.disabled]="!dotGraph"
122123
ngbTooltip="Matrix exportieren"
123124
i18n-ngbTooltip="@@matrix.view.tooltips.export"
124125
placement="left"
@@ -166,6 +167,14 @@
166167
</em>
167168
</div>
168169

170+
<div *ngIf="graphvizFailure"
171+
class="col-8 text-center alert alert-warning matrix-alert">
172+
<em i18n="@@matrix.view.tooBigWarning">
173+
Die Matrix überschreitet die maximale Darstellungsgröße. Bitte verwenden Sie die Exportfunktion, um die
174+
Matrix zur Anzeige in einem externen Viewer zu speichern.
175+
</em>
176+
</div>
177+
169178
<graph [graph]="graph"
170179
[selection]="selection"
171180
(onSelectForEdit)="edit($event)">

desktop/src/app/components/messages/m.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ export class M extends MD { // = Messages Dictionary. For reasons of brevity of
267267
public static CONFIGURATION_ERROR_IMPORT_UNSUPPORTED_VERSION = 'configuration.error.unsupportedVersion';
268268
public static CONFIGURATION_ERROR_NO_PROJECT_LANGUAGES = 'configuration.error.noProjectLanguages';
269269

270+
// Matrix Package
271+
public static MATRIX_ERROR_GENERIC = 'matrix.error.generic';
272+
270273
public msgs : { [id: string]: MessageTemplate } = {};
271274

272275

@@ -1123,5 +1126,9 @@ export class M extends MD { // = Messages Dictionary. For reasons of brevity of
11231126
content: $localize `:@@messages.configuration.error.noProjectLanguages:Bitte wählen Sie mindestens eine Projektsprache aus.`,
11241127
level: 'danger'
11251128
};
1129+
this.msgs[M.MATRIX_ERROR_GENERIC] = {
1130+
content: $localize `:@@messages.matrix.error.generic:Bei der Generierung der Matrix ist ein Fehler aufgetreten.`,
1131+
level: 'danger'
1132+
};
11261133
}
11271134
}

0 commit comments

Comments
 (0)