Skip to content
Open
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
Expand Up @@ -326,7 +326,7 @@
return this.enableDragInteraction || this.onRightClickCallback != null || this.onSelectNodeCallback != null;
}

public init() {

Check failure on line 329 in packages/network-viewer-core/src/network-area-diagram-viewer/network-area-diagram-viewer.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=powsybl_powsybl-network-viewer&issues=AZ9GwBgJuvxbwEcy-UdJ&open=AZ9GwBgJuvxbwEcy-UdJ&pullRequest=424
if (!this.container || !this.svgContent) return;

const dimensions: Dimensions | null = this.getDimensionsFromSvg();
Expand Down Expand Up @@ -377,7 +377,21 @@

this.textNodesSection = this.getOrCreateTextNodesSection();
this.textEdgesSection = this.getOrCreateTextEdgesSection();
this.edgeInfosSection = this.getOrCreateEdgeInfosSection();
// Ignore nad-edge-infos from the SVG in the AdaptiveTextZoom mode at init
// It will be fullfilled later in the updateAdaptiveEdgeInfos
if (this.nadViewerParameters.getAdaptiveTextZoom().enabled) {
// if the nad-edge-infos section exists in the SVG, replace it by an empty one
const existingEdgeInfos = <SVGElement>this.innerSvg?.querySelector(':scope > g.nad-edge-infos');
if (existingEdgeInfos) {
existingEdgeInfos.remove();
console.warn(
'AdaptiveTextZoom mode activated: creating nad-edge-infos from metadata and ignoring it from the SVG'
);
}
this.edgeInfosSection = this.createEmptyEdgeInfosSection();
} else {
this.edgeInfosSection = this.getOrCreateEdgeInfosSection();
}

// add events
const hasMetadata = this.diagramMetadata !== null;
Expand Down Expand Up @@ -502,12 +516,17 @@
return legendEdgesSection;
}

private createEmptyEdgeInfosSection(): SVGElement {
const edgeInfos = document.createElementNS('http://www.w3.org/2000/svg', 'g');
edgeInfos.classList.add('nad-edge-infos');
this.innerSvg?.appendChild(edgeInfos);
return edgeInfos;
}

private getOrCreateEdgeInfosSection(): SVGElement {
let edgeInfos = <SVGElement>this.innerSvg?.querySelector(':scope > g.nad-edge-infos');
const edgeInfos = <SVGElement>this.innerSvg?.querySelector(':scope > g.nad-edge-infos');
if (!edgeInfos) {
edgeInfos = document.createElementNS('http://www.w3.org/2000/svg', 'g');
edgeInfos.classList.add('nad-edge-infos');
this.innerSvg?.appendChild(edgeInfos);
return this.createEmptyEdgeInfosSection();
}
return edgeInfos;
}
Expand Down
Loading