ensembl.vep.render.graph package#
Graph model, layout and emitters. Domain-free: nothing here imports the rest of the package.
Submodules#
ensembl.vep.render.graph.dot module#
Rendering a graph as Graphviz DOT.
ensembl.vep.render.graph.layout module#
Placing a layered graph on a canvas.
These graphs are small – tens of facts and rules – and already carry the layer each node belongs to, so laying them out is arithmetic rather than a general graph-drawing problem. Layers become columns, and a node’s position within its column follows declaration order.
- class ensembl.vep.render.graph.layout.Layout(*, graph, placements, width, height)[source]#
Bases:
objectA graph with a position for every node.
- Variables:
- height: int#
- placement(identifier)[source]#
Return the placement of one node.
- Raises:
KeyError – If no node has that identifier.
- Return type:
- width: int#
- class ensembl.vep.render.graph.layout.Placement(*, node, x, y, width=170, height=34)[source]#
Bases:
objectWhere one node sits on the canvas.
- Variables:
node (Node) – The node placed.
x (int) – Left edge, in pixels.
y (int) – Top edge, in pixels.
width (int) – Box width, in pixels.
height (int) – Box height, in pixels.
- property centre_y: int#
Return the vertical midpoint, where an edge attaches.
- height: int#
- property right: int#
Return the right edge, where an outgoing edge leaves.
- width: int#
- x: int#
- y: int#
- ensembl.vep.render.graph.layout.layered(graph)[source]#
Lay a graph out in columns, one per layer.
Layers are taken from the nodes themselves rather than inferred, because the domain already knows the answer: a fact’s layer is its cost tier, a rule’s is its rank.
- Return type:
- ensembl.vep.render.graph.layout.tree(graph)[source]#
Lay a child-to-parent tree out with every parent centred on its children.
Edges must point from an operand towards its parent. The one node with no outgoing edge is the root. Leaves keep graph declaration order, making the result stable while preserving sibling order from the source expression.
- Raises:
ValueError – If the graph is disconnected, cyclic, or gives a node more than one parent.
- Return type:
ensembl.vep.render.graph.mermaid module#
Rendering a graph as Mermaid flowchart source.
ensembl.vep.render.graph.model module#
A directed graph carrying semantics, not styling.
A builder describes what a node is – its kind, which layer it belongs to, what state it ended in – and never what colour it should be. Renderers map those semantics onto an appearance, so every styling decision stays in one package and a builder needs no knowledge of the theme.
- class ensembl.vep.render.graph.model.Edge(*, source, target, kind='', label='')[source]#
Bases:
objectOne directed connection between two nodes.
- Variables:
source (str) – The identifier the edge leaves.
target (str) – The identifier the edge enters.
kind (str) – What the connection means, e.g. “depends”, “requires”, “subsumes”.
label (str) – Optional text drawn along the edge.
- kind: str#
- label: str#
- source: str#
- target: str#
- class ensembl.vep.render.graph.model.Graph(*, nodes=(), edges=(), title='')[source]#
Bases:
objectA set of nodes and the edges between them.
- Variables:
- layers()[source]#
Return the distinct layer numbers present, in ascending order.
- Return type:
tuple[int,...]
- node(identifier)[source]#
Return one node by its identifier.
- Raises:
KeyError – If no node has that identifier.
- Return type:
- nodes_in_layer(layer)[source]#
Return the nodes of one layer, in declaration order.
- Return type:
tuple[Node,...]
- title: str#
- class ensembl.vep.render.graph.model.Node(*, identifier, label, kind='', layer=0, state='', hits=0, detail='')[source]#
Bases:
objectOne vertex.
- Variables:
identifier (str) – Unique within a graph, and what edges refer to.
label (str) – The text a renderer draws.
kind (str) – What the node represents, e.g. “fact”, “rule”, “term”.
layer (int) – Which column or row the node belongs to. Layered layouts read this directly; it comes from something meaningful in the domain, such as a fact’s cost tier or a rule’s rank.
state (str) – How the node ended up, e.g. “computed”, “forced_false”, “fired”.
hits (int) – How many times the node was reached, for a corpus-reach overlay.
detail (str) – Optional secondary text, e.g. a value or a reason.
- detail: str#
- hits: int#
- identifier: str#
- kind: str#
- label: str#
- layer: int#
- state: str#
ensembl.vep.render.graph.svg module#
Rendering a laid-out graph as inline SVG.
The one place node semantics become an appearance: a builder says a node was forced false, this module decides that means a dashed grey box.
- ensembl.vep.render.graph.svg.STATE_COLOURS = {'cached': Colour.NEON_BLUE, 'computed': Colour.ICE_BLUE, 'emitted': Colour.BLUE, 'false': Colour.RED, 'fired': Colour.LIGHT_BLUE, 'forced_false': Colour.LIGHT_GREY, 'impact_high': Colour.DARK_PINK, 'impact_low': Colour.DUCKEGG_BLUE, 'impact_moderate': Colour.ORANGE, 'impact_modifier': Colour.LIGHT_GREY, 'operator': Colour.LIGHT_GREY, 'prefilled': Colour.DUCKEGG_BLUE, 'pruned': Colour.MEDIUM_LIGHT_GREY, 'subsumed': Colour.DUCKEGG_BLUE, 'suppressor': Colour.DARK_PINK, 'term': Colour.LIGHT_BLUE, 'true': Colour.LIGHT_BLUE, 'unreached': Colour.WHITE}#
Node state -> fill colour. A state absent from here falls back to the neutral fill.
The one place a builder’s semantics become an appearance:
subsumedandsuppressorare the two directions of suppression, and they are coloured apart so which way it runs is readable without following the arrowheads.