graflo.plot.equivalence¶
Draw one equivalence as four small graphs, each about one thing.
An equivalence says several things at once, and one picture of all of them is a tangle of arrows. Each view here draws one of them, as a graph whose partitions read left to right:
members-- which types become the merged type: left members, the merged type, right members. A member a vocabulary joins, rather than one the equivalence names, has a dashed edge.attributes-- where each member attribute lands on the merged type: a dark edge for a declared equivalence, a blue one for a vocabulary rename, a thin grey one for a name kept as it is, a dotted one for a mapping a later declaration overrode.identity-- how a record is keyed: raw fields, the branches a record tries in order (#1,#2, ...), and the key they feed. An edge into a branch is labelled with the transform or the tag it reads with.lookups-- each member's own key, kept on the merged type as a lookup; the edge is labelled with the key space.
Attributes and raw fields are small nodes inside a box named after their type
or resource; boxes are filled by side. A figure carries no title, legend or
note, so it can be embedded anywhere: :func:plot_equivalences writes what
they would say -- the declaration, the identity in words, the findings, a
caption per view -- to summary.md, and all of it to index.json.
Attributes¶
CAPTION = {'members': 'Members. The types that become the merged type; a dashed edge marks a member a vocabulary joins rather than one the equivalence names.', 'attributes': 'Attributes. Where each member attribute lands on the merged type: dark, a declared equivalence; blue, a vocabulary rename; thin grey, the name kept as it is; dotted, a mapping a later declaration overrode.', 'identity': 'Identity. The raw fields each branch reads, labelled with the transform or the tag; a record tries the branches in order, #1 first, and the first it completes keys it.', 'lookups': "Lookups. Each member's own key, kept on the merged type as a lookup in the key space the edge names."}
module-attribute
¶
INDEX_VERSION = 2
module-attribute
¶
SIDE_FILL = {'left': '#E6EFF5', 'right': '#E7F3EA', 'merged': '#FFF1DB', '': '#F0F0F0'}
module-attribute
¶
STYLE = {'declared': {'color': _INK, 'penwidth': '1.3'}, 'vocabulary': {'color': '#1F5FBF', 'penwidth': '1.3'}, 'joined': {'color': '#1F5FBF', 'penwidth': '1.3', 'style': 'dashed'}, 'kept': {'color': '#A8A8A8', 'penwidth': '0.7'}, 'overridden': {'color': '#B0B0B0', 'penwidth': '0.9', 'style': 'dotted'}, 'source': {'color': '#B9770E', 'penwidth': '1.1'}, 'key': {'color': _INK, 'penwidth': '1.1'}, 'lookup': {'color': '#8E5A2B', 'penwidth': '1.1'}}
module-attribute
¶
VIEWS = ('members', 'attributes', 'identity', 'lookups')
module-attribute
¶
View = Literal['members', 'attributes', 'identity', 'lookups']
module-attribute
¶
__all__ = ['CAPTION', 'INDEX_VERSION', 'SIDE_FILL', 'STYLE', 'VIEWS', 'View', 'build_equivalence_view', 'plot_equivalence', 'plot_equivalences', 'select_targets']
module-attribute
¶
Classes¶
Functions:¶
build_equivalence_view(preview, target, view)
¶
One view of one equivalence as a networkx graph, or None when it shows nothing.
Every node carries the preview id it stands for as preview_id, and
every edge its style as kind. The boxes graph attribute maps a
box id to (label, side, [node, ...]); ranks lists node groups
drawn in one rank, in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview
|
MergePreview
|
The whole preview, from |
required |
target
|
str | int
|
A cluster id, or a position in the op's |
required |
view
|
View
|
One of :data: |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
target names no equivalence. |
Source code in graflo/plot/equivalence.py
plot_equivalence(preview, target, directory, *, views=VIEWS, output_format='svg', stem=None, prog='dot', dpi=None)
¶
Draw views of one equivalence into directory; a view with nothing to show is skipped.
Files are <stem>.<view>.<format>; stem defaults to
<kind>-<merged name>, e.g. vertex-Machine.identity.svg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview
|
MergePreview
|
The whole preview, from |
required |
target
|
str | int
|
A cluster id, or a position in the op's |
required |
directory
|
str | PathLike[str]
|
Where to write; created if missing. |
required |
views
|
Sequence[View]
|
Which views to draw. |
VIEWS
|
output_format
|
str
|
|
'svg'
|
stem
|
str | None
|
File name stem. |
None
|
prog
|
str
|
Graphviz layout program. |
'dot'
|
dpi
|
int | None
|
Raster resolution, for |
None
|
Returns:
| Type | Description |
|---|---|
dict[View, Path]
|
The path written per view. |
Raises:
| Type | Description |
|---|---|
KeyError
|
target names no equivalence. |
RuntimeError
|
Rendering is unavailable or failed; the message says why. |
Source code in graflo/plot/equivalence.py
plot_equivalences(preview, directory, *, select=(), views=VIEWS, output_format='svg', prog='dot', dpi=None)
¶
Draw every selected equivalence into directory, with index.json and summary.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview
|
MergePreview
|
The whole preview, after its outcome is folded in, so the
finding positions in the index match |
required |
directory
|
str | PathLike[str]
|
Where to write; created if missing. |
required |
select
|
Sequence[str]
|
Patterns restricting the equivalences (see :func: |
()
|
views
|
Sequence[View]
|
Which views to draw. |
VIEWS
|
output_format
|
str
|
|
'svg'
|
prog
|
str
|
Graphviz layout program. |
'dot'
|
dpi
|
int | None
|
Raster resolution, for |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of |
Source code in graflo/plot/equivalence.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
select_targets(preview, patterns)
¶
The cluster ids patterns select, in reading order; all of them when none.
A pattern is a merged name, a position in vertex_equivalences, or an
fnmatch pattern on the cluster id.