Skip to content

Commit 0c28385

Browse files
authored
extends NadProfile with style customizations (#976)
Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
1 parent fd7f452 commit 0c28385

File tree

9 files changed

+256
-109
lines changed

9 files changed

+256
-109
lines changed

cpp/powsybl-cpp/powsybl-cpp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,11 @@ std::vector<std::string> getMatrixMultiSubstationSvgAndMetadata(const JavaHandle
723723
}
724724

725725
void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
726-
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions) {
726+
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions, dataframe* bus_node_styles, dataframe* edge_styles, dataframe* three_wt_styles) {
727727
auto c_parameters = parameters.to_c_struct();
728728
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
729729
PowsyblCaller::get()->callJava(::writeNetworkAreaDiagramSvg, network, (char*) svgFile.data(), (char*) metadataFile.data(),
730-
voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions);
730+
voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions, bus_node_styles, edge_styles, three_wt_styles);
731731
}
732732

733733
std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters) {
@@ -737,10 +737,10 @@ std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vecto
737737
}
738738

739739
std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
740-
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions) {
740+
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions, dataframe* bus_node_styles, dataframe* edge_styles, dataframe* three_wt_styles) {
741741
auto c_parameters = parameters.to_c_struct();
742742
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
743-
auto svgAndMetadataArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramSvgAndMetadata, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions);
743+
auto svgAndMetadataArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramSvgAndMetadata, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions, bus_node_styles, edge_styles, three_wt_styles);
744744
ToStringVector svgAndMetadata(svgAndMetadataArrayPtr);
745745
return svgAndMetadata.get();
746746
}

cpp/powsybl-cpp/powsybl-cpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ std::vector<std::string> getMatrixMultiSubstationSvgAndMetadata(const JavaHandle
581581
std::vector<std::string> getSingleLineDiagramComponentLibraryNames();
582582

583583
void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
584-
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions);
584+
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions, dataframe* bus_node_styles, dataframe* edge_styles, dataframe* three_wt_styles);
585585

586586
std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters);
587587

588588
std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
589-
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions);
589+
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions, dataframe* bus_node_styles, dataframe* edge_styles, dataframe* three_wt_styles);
590590

591591
std::vector<std::string> getNetworkAreaDiagramDisplayedVoltageLevels(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth);
592592

cpp/pypowsybl-cpp/bindings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,15 @@ PYBIND11_MODULE(_pypowsybl, m) {
687687
m.def("write_network_area_diagram_svg", &pypowsybl::writeNetworkAreaDiagramSvg, "Write network area diagram SVG",
688688
py::arg("network"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("voltage_level_ids"),
689689
py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"), py::arg("fixed_positions"),
690-
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"));
690+
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"),
691+
py::arg("bus_node_styles"), py::arg("edge_styles"), py::arg("three_wt_styles"));
691692

692693
m.def("get_network_area_diagram_svg", &pypowsybl::getNetworkAreaDiagramSvg, "Get network area diagram SVG as a string",
693694
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"));
694695

695696
m.def("get_network_area_diagram_svg_and_metadata", &pypowsybl::getNetworkAreaDiagramSvgAndMetadata, "Get network area diagram SVG and its metadata as a list of strings",
696697
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"), py::arg("fixed_positions"),
697-
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"));
698+
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"), py::arg("bus_node_styles"), py::arg("edge_styles"), py::arg("three_wt_styles"));
698699

699700
m.def("get_network_area_diagram_displayed_voltage_levels", &pypowsybl::getNetworkAreaDiagramDisplayedVoltageLevels, "Get network area diagram displayed voltage level",
700701
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"));

docs/user_guide/network_visualization.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,20 @@ by using dataframes:
352352
{'id': 'S2VL1_0', 'description': 'BUS C'},
353353
{'id': 'S3VL1_0', 'description': 'BUS D'}
354354
])
355-
>>> diagram_profile=pp.network.NadProfile(branch_labels=labels_df, vl_descriptions=vl_descriptions_df, bus_descriptions=bus_descriptions_df)
355+
>>> bus_node_style_df = pd.DataFrame.from_records(index='id',
356+
data=[
357+
{'id': 'S1VL1_0', 'fill': 'red', 'edge': 'black', 'edge-width': '4px'},
358+
{'id': 'S1VL2_0', 'fill': 'blue', 'edge': 'black', 'edge-width': '4px'},
359+
{'id': 'S2VL1_0', 'fill': 'yellow', 'edge': 'black', 'edge-width': '4px'},
360+
])
361+
>>> edge_style_df = pd.DataFrame.from_records(index='id',
362+
data=[
363+
{'id': 'LINE_S2S3', 'edge1': 'blue', 'width1': '16px', 'dash1': '12,12' ,'edge2': 'blue', 'width2': '16px', 'dash2': '12,12'},
364+
{'id': 'LINE_S3S4', 'edge1': 'green', 'width1': '3px', 'edge2': 'green', 'width2': '3px'},
365+
{'id': 'TWT' , 'edge1': 'yellow', 'width1': '4px', 'edge2': 'blue', 'width2': '4px'},
366+
])
367+
>>> diagram_profile=pp.network.NadProfile(branch_labels=labels_df, vl_descriptions=vl_descriptions_df, bus_descriptions=bus_descriptions_df,
368+
bus_node_styles=bus_node_style_df, edge_styles=edge_style_df)
356369
>>> pars=pp.network.NadParameters(edge_name_displayed=True)
357370
>>> network.get_network_area_diagram(voltage_level_ids='S1VL1', depth=2, nad_parameters=pars, nad_profile=diagram_profile)
358371
@@ -371,11 +384,30 @@ In the bus_descriptions dataframe parameter:
371384
- id is the BUS id
372385
- description define a label for the BUS
373386
387+
In the bus_node_styles dataframe parameter:
388+
- id is the BUS id
389+
- fill is the fill color for the node
390+
- edge is the edge color for the node
391+
- width is the width of the edge for the node
392+
393+
In the edge_styles dataframe parameter:
394+
- id is the branch id
395+
- edge1, width1 and dash1 is the color, the width and the dash pattern for the first branch's edge
396+
- edge2, width2 and dash2 is the color, the width and the dash pattern for the second branch's edge
397+
398+
The dash pattern string specifies the lengths of alternating dashes and gaps in the edge, separated by commas and/or spaces
399+
374400
An additional three_wt_labels dataframe parameter can be used to set the labels and the arrows direction for three winding transformers:
375401
- id is the three winding transformer id
376402
- side1, side2, and side3 define the labels along the three winding transformer legs
377403
- arrow1, arrow2, and arrow3 define the direction of the arrows at the ends of the three winding transformer legs: 'IN' or 'OUT'. None (or an empty string) does not display the arrow.
378404
405+
Similarly to the edge_styles, the three_wt_styles parameter can be used to set the style for the three winding transformers:
406+
- id is the three winding transformer id
407+
- edge1, width1 and dash1 is the color, the width and the dash pattern for the first transformer's leg
408+
- edge2, width2 and dash2 is the color, the width and the dash pattern for the second transformer's leg
409+
- edge3, width3 and dash3 is the color, the width and the dash pattern for the third transformer's leg
410+
379411
The optional parameter nad_profile can also be set in the write_network_area_diagram function.
380412
381413
Network area diagram using geographical data

0 commit comments

Comments
 (0)