Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2026, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

import { NadViewerParameters } from './nad-viewer-parameters';

test('getGeometryPrecision returns undefined when unset, so the writer applies its default', () => {
expect(new NadViewerParameters(undefined).getGeometryPrecision()).toBeUndefined();
expect(new NadViewerParameters({}).getGeometryPrecision()).toBeUndefined();
});

test('getGeometryPrecision returns the configured value', () => {
expect(new NadViewerParameters({ geometryPrecision: 1 }).getGeometryPrecision()).toBe(1);
expect(new NadViewerParameters({ geometryPrecision: 0 }).getGeometryPrecision()).toBe(0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export interface NadViewerParametersOptions {

// Whether to create the SVG from diagram metadata, instead of using the SVG content provided as input
createSvgFromMetadata?: boolean;

// Number of decimal places for the SVG geometry coordinates when the SVG is (re)built from
// metadata (see createSvgFromMetadata and the adaptive zoom). Fewer decimals produce a smaller,
// faster-to-parse SVG at the cost of coordinate accuracy. Defaults to 2, which keeps the
// generated SVG identical to before this option existed.
geometryPrecision?: number;
}

export class NadViewerParameters {
Expand Down Expand Up @@ -266,4 +272,10 @@ export class NadViewerParameters {
NadViewerParameters.CREATE_SVG_FROM_METADATA_DEFAULT
);
}

// Returns the configured geometry precision, or undefined to let the SVG writer apply its own
// default (DEFAULT_GEOMETRY_PRECISION).
public getGeometryPrecision(): number | undefined {
return this.nadViewerParametersOptions?.geometryPrecision;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export class NetworkAreaDiagramViewer {
this.diagramMetadata = diagramMetadata;
this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined);
if (this.nadViewerParameters.getCreateSvgFromMetadata() && this.diagramMetadata != null) {
this.svgWriter = new SvgWriter({ diagramMetadata: this.diagramMetadata });
this.svgWriter = new SvgWriter({
diagramMetadata: this.diagramMetadata,
geometryPrecision: this.nadViewerParameters.getGeometryPrecision(),
});
this.svgContent = this.svgWriter.getEmptySvg();
}
this.width = 0;
Expand Down Expand Up @@ -2194,6 +2197,7 @@ export class NetworkAreaDiagramViewer {
diagramMetadata: this.diagramMetadata,
elementList: { nodes: nodes, edges: edges },
voltageLevels: maxDisplayedSize > nodeVlThreshold.threshold ? nodeVlThreshold.voltageLevels : undefined,
geometryPrecision: this.nadViewerParameters.getGeometryPrecision(),
});
svgWriter.addNodes(<SVGGElement>this.nodesSection!);
svgWriter.addEdgesAndInfos(<SVGGElement>this.edgesSection!);
Expand Down
Loading