[nad-viewer] Use SVG writer for creating nodes and edges in adaptive zoom functionality#423
[nad-viewer] Use SVG writer for creating nodes and edges in adaptive zoom functionality#423massimo-ferraro wants to merge 5 commits into
Conversation
…zoom functionality Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
|
It looks very promising, great work @massimo-ferraro ! 👏 Some quick comments on this draft, you are probably aware already but here it comes:
But all that seems to be minor bugs, it's a very promising work! 👌 It was the goal of your long work on integration/nad_create_svg and of @CBiasuzzi work on adaptive zoom text and powsybl-diagram metadata, congratulations already for these first results to both of you - can't wait to see that work merged and integrated. |
| const vlThreshold = DiagramUtils.getVLThreshold(adaptiveTextZoom.nodeThresholds, maxDisplayedSize); | ||
| const previousVlThreshold = DiagramUtils.getVLThreshold( | ||
| adaptiveTextZoom.edgeThresholds, | ||
| this.getPreviousMaxDisplayedSize() | ||
| ); |
There was a problem hiding this comment.
why is vlThreshold calculated with nodeThresholds but previousVlThreshold is calculated with edgeThreshold ?
There was a problem hiding this comment.
You are right, I should have used the edgeThresholds for the edges filtering, not the nodeThresholds (the previousVlThreshold is needed only for the edge filtering). Fixed,
| }; | ||
| } | ||
|
|
||
| export function getMaxThreshold(voltageLevelThreshols: VoltageLevelThreshold[]): VoltageLevelThreshold { |
There was a problem hiding this comment.
| export function getMaxThreshold(voltageLevelThreshols: VoltageLevelThreshold[]): VoltageLevelThreshold { | |
| export function getMaxThreshold(voltageLevelThresholds: VoltageLevelThreshold[]): VoltageLevelThreshold { |
There was a problem hiding this comment.
fixed the typo
| ); | ||
| } | ||
|
|
||
| export function getMinThreshold(voltageLevelThreshols: VoltageLevelThreshold[]): VoltageLevelThreshold { |
There was a problem hiding this comment.
| export function getMinThreshold(voltageLevelThreshols: VoltageLevelThreshold[]): VoltageLevelThreshold { | |
| export function getMinThreshold(voltageLevelThresholds: VoltageLevelThreshold[]): VoltageLevelThreshold { |
There was a problem hiding this comment.
fixed the typo
| } | ||
|
|
||
| export function getVLThreshold( | ||
| voltageLevelThreshols: VoltageLevelThreshold[], |
There was a problem hiding this comment.
| voltageLevelThreshols: VoltageLevelThreshold[], | |
| voltageLevelThresholds: VoltageLevelThreshold[], |
There was a problem hiding this comment.
fixed the typo
| return (voltageLevelThreshols.length == 0 ? [{ threshold: 500000 }] : voltageLevelThreshols).reduce( | ||
| (a, b) => (a.threshold > b.threshold ? a : b), | ||
| voltageLevelThreshols[0] ?? [{ threshold: 500000 }] | ||
| ); |
There was a problem hiding this comment.
how about something like that:
if (length === 0) {
return {threshold: 500000}
} else {
return voltageLevelThresholds.reduce(...)
}
There was a problem hiding this comment.
Changed for using the if else, even if in the short-hand version, but anyway it avoids to reduce an array with only one element
| } | ||
|
|
||
| export function getMaxThreshold(voltageLevelThreshols: VoltageLevelThreshold[]): VoltageLevelThreshold { | ||
| return (voltageLevelThreshols.length == 0 ? [{ threshold: 500000 }] : voltageLevelThreshols).reduce( |
There was a problem hiding this comment.
the 500000 is already defined in nad-viewer-parameters:
static readonly THRESHOLD_NODES_ADAPTIVE_ZOOM_DEFAULT = 500000;
static readonly THRESHOLD_EDGES_ADAPTIVE_ZOOM_DEFAULT = 500000;Why not use this static value ?
There was a problem hiding this comment.
Now I use the static value
| this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined); | ||
| if (this.nadViewerParameters.getCreateSvgFromMetadata() && this.diagramMetadata != null) { | ||
| this.svgWriter = new SvgWriter({ diagramMetadata: this.diagramMetadata }); | ||
| this.svgContent = this.svgWriter.getEmptySvg(); | ||
| } | ||
| this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined); |
There was a problem hiding this comment.
| this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined); | |
| if (this.nadViewerParameters.getCreateSvgFromMetadata() && this.diagramMetadata != null) { | |
| this.svgWriter = new SvgWriter({ diagramMetadata: this.diagramMetadata }); | |
| this.svgContent = this.svgWriter.getEmptySvg(); | |
| } | |
| this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined); | |
| this.nadViewerParameters = new NadViewerParameters(nadViewerParametersOptions ?? undefined); | |
| if (this.nadViewerParameters.getCreateSvgFromMetadata() && this.diagramMetadata != null) { | |
| this.svgWriter = new SvgWriter({ diagramMetadata: this.diagramMetadata }); | |
| this.svgContent = this.svgWriter.getEmptySvg(); | |
| } |
There was a problem hiding this comment.
the second new NadViewerParameters overwrites the first one, I don't think this is intended, correct me if I'm wrong
There was a problem hiding this comment.
You are right, removed the duplicated line
| } | ||
| } | ||
|
|
||
| filterNodes(nodes: NodeMetadata[], vlThreshold: VoltageLevelThreshold, maxDisplayedSize: number): NodeMetadata[] { |
There was a problem hiding this comment.
Likely created by the IDE, I now made it private
| return nodes; | ||
| } | ||
|
|
||
| filterEdges( |
There was a problem hiding this comment.
Likely created by the IDE, I now made it private
| export function getVLThresholdClasses(voltageLevels: string[]): string { | ||
| return '.' + voltageLevels.join(',.'); | ||
| } |
There was a problem hiding this comment.
I don't see this used anywhere, do you plan to use it for something later ?
There was a problem hiding this comment.
You are right, I created and used this method during my developments. In the end I removed the usage, but forgot to remove the function. Removed now
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
Thanks
Now, in this branch, we have:
If you would like to start without the content, and create what is needed in the init, adapting the first situation (the svg writer that creates the whole svg) to work with filtered elements and some voltage levels would require some time and some work.
Fixed
If this parameter is added, it could be used by the adaptive zoom, and also for the whole SVG creation from metadata
I saw something like that with some combination of
|
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
|





Please check if the PR fulfills these requirements
Does this PR already have an issue describing the problem?
no
What kind of change does this PR introduce?
feature
What is the current behavior?
The adaptive zoom functionality handles text boxes and edge infos, removing and redrawing them according to thresholds. It doesn't handle nodes and edges.
What is the new behavior (if this is a feature change)?
The adaptive zoom functionality handles also nodes and edges, removing and redrawing them according to thresholds. The thresholds could also be associated to voltage levels, for removing and redrawing nodes and edges according to their voltage level
Does this PR introduce a breaking change or deprecate an API?
If yes, please check if the following requirements are fulfilled
What changes might users need to make in their application due to this PR? (migration steps)
The adaptive zoom functionality has been changed for handling nodes and edges. New sections of the
AdaptiveTextZoomOptionshas been added for configuring the handling of nodes and edges, an example of configuration can be found in realgrid.ts file in the demo.A new parameter for choosing the creation of the SVG from the diagram metadata has also been added to the NAD parameters