Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/source/api-reference/node.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.. autoclass:: neo4j_viz.Node
:members:
:exclude-members: model_config
1 change: 1 addition & 0 deletions docs/source/api-reference/relationship.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.. autoclass:: neo4j_viz.Relationship
:members:
:exclude-members: model_config
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
# -- Options for notebook extension -------------------------------------------
nbsphinx_execute = "never"

# -- Options for autodoc extension -------------------------------------------
autodoc_typehints = "description"


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

Expand Down
1 change: 1 addition & 0 deletions python-wrapper/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"ipython >=8, <9",
"pydantic >=2 , <3",
"pydantic-extra-types >=2, <3",
"enum-tools==0.12.0"
]
requires-python = ">=3.9"

Expand Down
9 changes: 9 additions & 0 deletions python-wrapper/src/neo4j_viz/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@ class Node(BaseModel, extra="allow"):
All options available in the NVL library (see https://neo4j.com/docs/nvl/current/base-library/#_nodes)
"""

#: Unique identifier for the node
id: NodeIdType = Field(
validation_alias=AliasChoices("id", "nodeId", "node_id"), description="Unique identifier for the node"
)
#: The caption of the node
caption: Optional[str] = Field(None, description="The caption of the node")
#: The alignment of the caption text
caption_align: Optional[CaptionAlignment] = Field(
None, serialization_alias="captionAlign", description="The alignment of the caption text"
)
#: The size of the caption text. The font size to node radius ratio
caption_size: Optional[int] = Field(
None,
ge=1,
le=3,
serialization_alias="captionSize",
description="The size of the caption text. The font size to node radius ratio",
)
#: The size of the node as radius in pixel
size: Optional[RealNumber] = Field(None, ge=0, description="The size of the node as radius in pixel")
#: The color of the node
color: Optional[ColorType] = Field(None, description="The color of the node")
#: Whether the node is pinned in the visualization
pinned: Optional[bool] = Field(None, description="Whether the node is pinned in the visualization")
#: The x-coordinate of the node
x: Optional[RealNumber] = Field(None, description="The x-coordinate of the node")
#: The y-coordinate of the node
y: Optional[RealNumber] = Field(None, description="The y-coordinate of the node")

@field_serializer("color")
Expand Down
15 changes: 13 additions & 2 deletions python-wrapper/src/neo4j_viz/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@
from enum import Enum
from typing import Any, Optional

import enum_tools.documentation
from pydantic import BaseModel, Field


@enum_tools.documentation.document_enum
class CaptionAlignment(str, Enum):
"""
The alignment of the caption text for nodes and relationships.
"""

TOP = "top"
CENTER = "center"
BOTTOM = "bottom"


@enum_tools.documentation.document_enum
class Layout(str, Enum):
FORCE_DIRECTED = "forcedirected"
HIERARCHICAL = "hierarchical"
GRID = "grid"
"""
The nodes are then arranged by the directionality of their relationships
"""
COORDINATE = "free"
""""
"""
The coordinate layout sets the position of each node based on the `x` and `y` properties of the node.
"""
GRID = "grid"


@enum_tools.documentation.document_enum
class Renderer(str, Enum):
"""
The renderer used to render the visualization.
Expand Down
7 changes: 7 additions & 0 deletions python-wrapper/src/neo4j_viz/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ class Relationship(BaseModel, extra="allow"):
All options available in the NVL library (see https://neo4j.com/docs/nvl/current/base-library/#_relationships)
"""

#: Unique identifier for the relationship
id: Union[str, int] = Field(
default_factory=lambda: uuid4().hex, description="Unique identifier for the relationship"
)
#: Node ID where the relationship points from
source: Union[str, int] = Field(
serialization_alias="from",
validation_alias=AliasChoices("source", "sourceNodeId", "source_node_id", "from"),
description="Node ID where the relationship points from",
)
#: Node ID where the relationship points to
target: Union[str, int] = Field(
serialization_alias="to",
validation_alias=AliasChoices("target", "targetNodeId", "target_node_id", "to"),
description="Node ID where the relationship points to",
)
#: The caption of the relationship
caption: Optional[str] = Field(None, description="The caption of the relationship")
#: The alignment of the caption text
caption_align: Optional[CaptionAlignment] = Field(
None, serialization_alias="captionAlign", description="The alignment of the caption text"
)
#: The size of the caption text
caption_size: Optional[Union[int, float]] = Field(
None, gt=0.0, serialization_alias="captionSize", description="The size of the caption text"
)
#: The color of the relationship
color: Optional[ColorType] = Field(None, description="The color of the relationship")

@field_serializer("color")
Expand Down
23 changes: 19 additions & 4 deletions python-wrapper/src/neo4j_viz/visualization_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional

from IPython.display import HTML
from pydantic import BaseModel, Field
from pydantic_extra_types.color import Color, ColorType

from .colors import ColorsType, neo4j_colors
Expand All @@ -16,13 +15,29 @@
from .relationship import Relationship


class VisualizationGraph(BaseModel):
class VisualizationGraph:
"""
A graph to visualize.
"""

nodes: list[Node] = Field(description="The nodes in the graph")
relationships: list[Relationship] = Field(description="The relationships in the graph")
#: "The nodes in the graph"
nodes: list[Node]
#: "The relationships in the graph"
relationships: list[Relationship]

def __init__(self, nodes: list[Node], relationships: list[Relationship]) -> None:
""" "
Create a new `VisualizationGraph`.

Parameters
----------
nodes:
The nodes in the graph.
relationships:
The relationships in the graph.
"""
self.nodes = nodes
self.relationships = relationships

def render(
self,
Expand Down
Loading