Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] adds a branch_labels df param to the get NAD and write NAD methods #942

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

CBiasuzzi
Copy link
Contributor

@CBiasuzzi CBiasuzzi commented Feb 7, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

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?
No label customization available

What is the new behavior (if this is a feature change)?
Adds a branch_labels parameter to the get_network_area_diagram and write_network_area_diagram.
Allows you to set branch labels (on the branch and on the branch edges) from the branch_labels dataframe parameter.

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

@CBiasuzzi CBiasuzzi changed the title [WIP] adds a branch_labels df param to the get NAD and write NAD methods adds a branch_labels df param to the get NAD and write NAD methods Feb 10, 2025
Copy link
Contributor

@flo-dup flo-dup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Comment on lines +1235 to +1253
return (network, svgParameters) -> new DefaultLabelProvider(network, svgParameters) {
@Override
public Optional<EdgeInfo> getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side) {
CustomBranchLabels bl = branchLabels.get(edge.getEquipmentId());
String label = null;
EdgeInfo.Direction arrowDirection = null;
if (bl != null) {
label = side == BranchEdge.Side.ONE ? bl.side1 : bl.side2;
arrowDirection = side == BranchEdge.Side.ONE ? bl.arrow1 : bl.arrow2;
}
return Optional.of(new EdgeInfo("ActivePower", arrowDirection, null, label));
}

@Override
public String getLabel(Edge edge) {
CustomBranchLabels bl = branchLabels.get(edge.getEquipmentId());
return (bl != null) ? bl.middle : null;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you open a PR on powsybl-diagram to add such a LabelProvider, with a constructor based on the given map? So that after next powsybl-diagram release we remove this code here.

docs/user_guide/network_visualization.rst Show resolved Hide resolved
docs/user_guide/network_visualization.rst Outdated Show resolved Hide resolved
docs/user_guide/network_visualization.rst Outdated Show resolved Hide resolved
pypowsybl/network/impl/network.py Outdated Show resolved Hide resolved
@@ -416,6 +429,7 @@ def get_network_area_diagram(self, voltage_level_ids: Union[str, List[str]] = No
low_nominal_voltage_bound: low bound to filter voltage level according to nominal voltage
nad_parameters: parameters for network area diagram
fixed_positions: optional dataframe used to set fixed coordinates for diagram elements. Positions for elements not specified in the dataframe will be computed using the current layout.
branch_labels: optional dataframe used to set the labels on a branch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next step should be the other parameters of the LabelProvider: a dataframe with buses description (bus id / description), a dataframe with voltage level description (vl id / description / details). And then comes the dataframe for the styles. Should we encapsulate all these dataframes in a bigger config object, or would it be ok to have these four dataframes as input at the end?

…ompletes documentation

Signed-off-by: Christian Biasuzzi <[email protected]>
Copy link

Copy link

@flo-dup
Copy link
Contributor

flo-dup commented Feb 13, 2025

After some discussing and thinking, could you encapsulate the branch_labels dataframe in an object? I think we could call it something like diagram customizer.

Indeed, at the end there will be specific customization for specific usecases, each one customizing all the dataframes mentioned in above comment. To that end, we will provide for each usecase a method to build this object. This object would make it easier to use those predefinite customization than if it remains in separated arguments.

@CBiasuzzi CBiasuzzi changed the title adds a branch_labels df param to the get NAD and write NAD methods [WIP] adds a branch_labels df param to the get NAD and write NAD methods Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants