galactic.algebras.relational.renderer#

Defines renderers for relational algebra visualizations.

Classes

Renderers:

Graph visualizations:

Tables:


class GraphRenderer(**data)#

Bases: Resource, Generic[_E, _F]

Renders Graphviz graph attributes.

Notes

See https://www.graphviz.org/doc/info/attrs.html for available attributes.

add_source(elem, domain, co_domain, *, index=None, current=False, successors=None, predecessors=None)#

Add a source node to the graph.

Parameters:
  • elem (TypeVar(_E)) – The source element to add

  • index (int | None, default: None) – The index of the source

  • current (bool, default: False) – Whether the element is the current one

  • domain (Collection[TypeVar(_E)]) – The domain

  • co_domain (Collection[TypeVar(_F)]) – The co-domain

  • successors (Collection[TypeVar(_F)] | None, default: None) – The successors of the source

  • predecessors (Collection[TypeVar(_F)] | None, default: None) – The predecessors of the source

Return type:

None

add_destination(elem, domain, co_domain, *, index=None, current=False, successors=None, predecessors=None)#

Add a destination node to the graph.

Parameters:
  • elem (TypeVar(_F)) – The destination element to add

  • index (int | None, default: None) – The index of the destination

  • current (bool, default: False) – Whether the element is the current one

  • domain (Collection[TypeVar(_E)]) – The domain

  • co_domain (Collection[TypeVar(_F)]) – The co-domain

  • successors (Collection[TypeVar(_E)] | None, default: None) – The successors of the destination

  • predecessors (Collection[TypeVar(_E)] | None, default: None) – The predecessors of the destination

Return type:

None

add_edge(source, destination, domain, co_domain, *, successors=None, predecessors=None)#

Add an edge to the graph.

Parameters:
  • source (TypeVar(_E)) – The source of the edge

  • destination (TypeVar(_F)) – The destination of the edge

  • relation – The relation

  • successors (Collection[TypeVar(_F)] | None, default: None) – The successors of the source (including the current destination)

  • predecessors (Collection[TypeVar(_E)] | None, default: None) – The predecessors of the destination (including the current source)

Return type:

None

graph_attributes()#

Return the Graphviz attributes for the graph.

Returns:

A dictionary of Graphviz attributes

Return type:

dict[str, str]

node_attributes()#

Return the common attributes for the nodes.

Returns:

A dictionary of Graphviz attributes

Return type:

dict[str, str]

edge_attributes()#

Return the common attributes for the edges.

Returns:

A dictionary of Graphviz attributes

Return type:

dict[str, str]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class NodeRenderer(**data)#

Bases: Resource, Generic[_E, _F]

Renders Graphviz nodes.

Notes

See https://www.graphviz.org/doc/info/attrs.html for available attributes.

attributes(elem, domain, co_domain, *, index=None, current=False, successors=None, predecessors=None)#

Return a dictionary of Graphviz attributes for a node.

Parameters:
  • elem (TypeVar(_E)) – The element to render

  • index (int | None, default: None) – The index of the element

  • current (bool, default: False) – Whether the element is the current one

  • domain (Collection[TypeVar(_E)]) – The domain

  • co_domain (Collection[TypeVar(_F)]) – The co-domain

  • successors (Collection[TypeVar(_F)] | None, default: None) – The successors of the element

  • predecessors (Collection[TypeVar(_F)] | None, default: None) – The predecessors of the element

Returns:

A dictionary of Graphviz attributes

Return type:

dict[str, str]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EdgeRenderer(**data)#

Bases: Resource, Generic[_E, _F]

Renders Graphviz edge attributes.

Notes

See https://www.graphviz.org/doc/info/attrs.html for available attributes.

attributes(source, destination, domain, co_domain, *, successors=None, predecessors=None)#

Return a dictionary of Graphviz attributes for an edge.

Parameters:
  • source (TypeVar(_E)) – The source of the edge

  • destination (TypeVar(_F)) – The destination of the edge

  • domain (Collection[TypeVar(_E)]) – The domain

  • co_domain (Collection[TypeVar(_F)]) – The co-domain

  • successors (Collection[TypeVar(_F)] | None, default: None) – The successors of the source (including the current destination)

  • predecessors (Collection[TypeVar(_E)] | None, default: None) – The predecessors of the destination (including the current source)

Returns:

A dictionary of Graphviz attributes.

Return type:

dict[str, str]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SagittalDiagramRenderer(**data)#

Bases: GraphRenderer, Generic[_E, _F]

Renders attributes for sagittal diagrams.

Notes

See https://www.graphviz.org/doc/info/attrs.html for available attributes.

graph_attributes()#

Return the Graphviz attributes for the graph.

Returns:

A dictionary of Graphviz attributes for the graph

Return type:

dict[str, str]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SagittalDiagramDrawer(**data)#

Bases: Resource, Generic[_E, _F]

Draws sagittal diagrams.

Useful for visualizing binary relations in Jupyter notebooks.

Parameters:
  • graph_renderer – The graph renderer

  • domain_renderer – The domain renderer

  • co_domain_renderer – The codomain renderer

  • edge_renderer – The edge renderer

export(relation, path)#

Render the diagram in a file.

Parameters:
Return type:

None

draw(relation)#

Draw the diagram.

Parameters:

relation (BinaryRelation[TypeVar(_E), TypeVar(_F)]) – The relation to draw

Returns:

The diagram.

Return type:

SagittalDiagram[TypeVar(_E), TypeVar(_F)]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SagittalDiagram(relation, drawer)#

Bases: Generic[_E, _F]

Draws sagittal diagrams.

Useful for visualizing binary relations in Jupyter notebooks.

Parameters:
property relation: BinaryRelation[_E, _F]#

Get the relation.

Returns:

The underlying relation

Return type:

BinaryRelation[_E, _F]

render(path)#

Render the diagram in a file.

Parameters:

path (Path) – A file path.

Return type:

None

pipe(output='svg')#

Pipe the diagram.

Parameters:

output (str, default: 'svg') – The format used

Returns:

The image of the diagram.

Return type:

bytes

property digraph: Digraph#

Get the Graphviz Digraph for the diagram.

Returns:

The digraph

Return type:

Digraph

class EndoDiagramDrawer(**data)#

Bases: Resource, Generic[_E]

Draws endo diagrams.

Useful for visualizing endo-relations in Jupyter notebooks.

Parameters:
  • graph_renderer – The graph renderer

  • domain_renderer – The domain renderer

  • edge_renderer – The edge renderer

export(relation, path)#

Render the diagram in a file.

Parameters:
Return type:

None

draw(relation)#

Draw the diagram.

Parameters:

relation (EndoRelation[TypeVar(_E)]) – The relation to draw

Returns:

The diagram.

Return type:

EndoDiagram[TypeVar(_E)]

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EndoDiagram(relation, drawer)#

Bases: Generic[_E]

Draws endo diagrams.

Useful for visualizing endo-relations in Jupyter notebooks.

Parameters:
property relation: EndoRelation[_E]#

Get the relation.

Returns:

The underlying relation

Return type:

EndoRelation[_E]

render(path)#

Render the diagram in a file.

Parameters:

path (Path) – A file path.

Return type:

None

pipe(output='svg')#

Pipe the diagram.

Parameters:

output (str, default: 'svg') – The format used

Returns:

The image of the diagram.

Return type:

bytes

property digraph: Digraph#

Get the Graphviz Digraph for the diagram.

Returns:

The Graphviz Digraph representing the diagram

Return type:

Digraph

class BinaryTable(relation, domain_renderer=None, co_domain_renderer=None)#

Bases: Generic[_E, _F]

Renders a binary relation as a table in Jupyter notebooks.

Parameters:
property relation: BinaryRelation[_E, _F]#

Get the relation.

Returns:

The underlying relation

Return type:

BinaryRelation[_E, _F]

property domain_renderer: CellRenderer[_E, _F]#

Get the domain renderer.

Returns:

The domain renderer

Return type:

CellRenderer[_E, _F]

property co_domain_renderer: CellRenderer[_E, _F]#

Get the co-domain renderer.

Returns:

The co-domain renderer

Return type:

CellRenderer[_E, _F]

class CellRenderer#

Bases: Generic[_E, _F]

Renders cell elements for a binary table.

render_row(elem, relation, index)#

Render an element as a string for a table in the rows.

Parameters:
Returns:

The string representation of the element for the table

Return type:

str

render_col(elem, relation, index)#

Render an element as a string for a table in the columns.

Parameters:
Returns:

The string representation of the element for the table

Return type:

str