Skip to content

Commit ab9f0ad

Browse files
author
Yuriy Peshkichev
committed
interactive graph vis
1 parent 30043bc commit ab9f0ad

File tree

12 files changed

+6659
-55
lines changed

12 files changed

+6659
-55
lines changed

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,34 @@ poetry init
7474
- Include docstrings for functions and classes
7575
- Write unit tests for new features or bug fixes
7676
77+
### Docstrings
78+
Use this Google style docstrings format:
79+
https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html
80+
Example from Dialog2graph:
81+
```python
82+
class ModelStorage(BaseModel):
83+
"""
84+
ModelStorage is a class for managing the storage of model configurations and instances.
85+
It provides functionality to load configurations from a YAML file, add new models to the storage,
86+
and save the current storage state back to a YAML file.
87+
88+
Attributes:
89+
storage (Dict[str, StoredData]): A dictionary that holds the stored model configurations
90+
and their corresponding instances.
91+
"""
92+
93+
storage: Dict[str, StoredData] = Field(default_factory=dict)
94+
95+
def load(self, path: Path):
96+
"""
97+
Load model configurations from a YAML file into the storage.
98+
99+
Args:
100+
path (str): The file path to the YAML file containing model configurations.
101+
"""
102+
...
103+
```
104+
77105
## Pull Request Format
78106
79107
- Name of your PR (keep it simple yet meaningful)

dialog2graph/pipelines/core/graph.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from datetime import datetime
99
import networkx as nx
10+
import gravis as gv
1011
from pydantic import BaseModel
1112
from typing import Optional, Any
1213
import matplotlib.pyplot as plt
@@ -238,7 +239,7 @@ def visualise(self, *args, **kwargs):
238239
plt.axis("off")
239240
plt.show()
240241

241-
def visualise_short(self, name, *args, **kwargs):
242+
def visualise_short(self, name="", *args, **kwargs):
242243
"""Create a compact visualization of the graph.
243244
244245
Args:
@@ -285,6 +286,37 @@ def visualise_short(self, name, *args, **kwargs):
285286
plt.axis("off")
286287
plt.show()
287288

289+
def visualise_interactive(self, *args, **kwargs) -> gv._internal.plotting.data_structures.Figure:
290+
291+
"""
292+
Visualises the graph using interactive visualisation library "gravis".
293+
Returns:
294+
A figure object representing the interactive graph visualization.
295+
"""
296+
graph = self.graph.copy()
297+
298+
node_labels = nx.get_node_attributes(graph, "utterances")
299+
edge_labels = nx.get_edge_attributes(graph, "utterances")
300+
301+
for edge_id in graph.edges:
302+
edge = graph.edges[edge_id]
303+
edge['label'] = len(edge_labels[edge_id])
304+
edge['hover'] = edge_labels[edge_id]
305+
306+
for node_id in graph.nodes:
307+
node = graph.nodes[node_id]
308+
node['label'] = f"{node_id}:{len(node_labels[node_id])}"
309+
node['hover'] = node_labels[node_id]
310+
311+
return gv.vis(
312+
graph, show_node_label=True, show_edge_label=True,
313+
node_label_data_source='label',
314+
edge_label_data_source='label', edge_label_size_factor=1.7,
315+
layout_algorithm="hierarchicalRepulsion"
316+
)
317+
318+
319+
288320
def find_nodes_by_utterance(self, utterance: str) -> list[dict]:
289321
"""Find nodes containing a specific utterance.
290322

experiments/exp2025_03_20_d2g_pipeline/exp2025_03_20_d2g_pipeline/test_pipeline.ipynb

Lines changed: 3597 additions & 53 deletions
Large diffs are not rendered by default.

experiments/exp2025_05_06_plotly/README.md

Whitespace-only changes.

experiments/exp2025_05_06_plotly/exp2025_05_06_plotly/__init__.py

Whitespace-only changes.

experiments/exp2025_05_06_plotly/exp2025_05_06_plotly/plotly.ipynb

Whitespace-only changes.

0 commit comments

Comments
 (0)