Skip to content

canvas

canvas

SVG renderer for Domo Magic ETL canvas layouts.

Converts the raw gui canvas data (elements + action dependsOn edges) into an SVG diagram for spatial reasoning and documentation.

Usage

layout = defn.canvas_layout() edges = defn.canvas_edges() svg = render_svg(layout, edges) Path("canvas.svg").write_text(svg)

render_svg

render_svg(
    layout: list[dict],
    edges: list[tuple[str, str]],
    title: str = "Dataflow Canvas",
) -> str

Render canvas layout + edges as an SVG string.

Parameters:

Name Type Description Default
layout list[dict]

output of DomoDataflow_Definition.canvas_layout()

required
edges list[tuple[str, str]]

output of DomoDataflow_Definition.canvas_edges() list of (source_element_id, target_element_id)

required
title str

diagram title shown at top

'Dataflow Canvas'

Returns:

Type Description
str

SVG string

Source code in src/crew_dcs/classes/DomoDataflow/canvas.py
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def render_svg(
    layout: list[dict],
    edges: list[tuple[str, str]],
    title: str = "Dataflow Canvas",
) -> str:
    """Render canvas layout + edges as an SVG string.

    Args:
        layout: output of DomoDataflow_Definition.canvas_layout()
        edges:  output of DomoDataflow_Definition.canvas_edges()
                list of (source_element_id, target_element_id)
        title:  diagram title shown at top

    Returns:
        SVG string
    """
    if not layout:
        return '<svg xmlns="http://www.w3.org/2000/svg" width="400" height="100"><text x="20" y="40">No canvas data</text></svg>'

    # Compute canvas bounds
    x_max = max(el["x"] + el["w"] for el in layout)
    y_max = max(el["y"] + el["h"] for el in layout)
    width = x_max + PADDING * 2
    height = y_max + PADDING * 2 + 30  # 30 for title

    # Build id → element lookup for edge rendering
    id_to_el = {el["id"]: el for el in layout}

    parts: list[str] = []
    parts.append(
        f'<svg xmlns="http://www.w3.org/2000/svg" '
        f'width="{width}" height="{height}" '
        f'style="font-family:sans-serif;background:#FAFAFA">'
    )

    # Title
    parts.append(
        f'<text x="{PADDING}" y="24" font-size="14" font-weight="bold" '
        f'fill="#333">{_escape(title)}</text>'
    )

    offset_y = 30  # shift everything down to make room for title

    def tx(x: int) -> int:
        return x + PADDING

    def ty(y: int) -> int:
        return y + PADDING + offset_y

    # 1 — Sections first (background layer)
    for el in layout:
        if el["type"] != "Section":
            continue
        x, y, w, h = tx(el["x"]), ty(el["y"]), el["w"], el["h"]
        label = _escape(_short_label(el["label"], 40))
        parts.append(
            f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="6" '
            f'fill="{_SECTION_FILL}" stroke="{_SECTION_STROKE}" stroke-width="1.5" '
            f'stroke-dasharray="6,3"/>'
        )
        parts.append(
            f'<text x="{x + 8}" y="{y + 18}" font-size="11" fill="{_SECTION_TEXT}" '
            f'font-style="italic">{label}</text>'
        )

    # 2 — Edges (drawn under tiles)
    for src_id, tgt_id in edges:
        src = id_to_el.get(src_id)
        tgt = id_to_el.get(tgt_id)
        if not src or not tgt:
            continue
        # right-center of source → left-center of target
        x1 = tx(src["x"]) + src["w"]
        y1 = ty(src["y"]) + src["h"] // 2
        x2 = tx(tgt["x"])
        y2 = ty(tgt["y"]) + tgt["h"] // 2
        cx = (x1 + x2) // 2
        parts.append(
            f'<path d="M{x1},{y1} C{cx},{y1} {cx},{y2} {x2},{y2}" '
            f'fill="none" stroke="{_EDGE_COLOR}" stroke-width="1.5" '
            f'marker-end="url(#arrow)"/>'
        )

    # 3 — Tiles
    for el in layout:
        if el["type"] != "Tile":
            continue
        x, y, w, h = tx(el["x"]), ty(el["y"]), el["w"], el["h"]
        color = _tile_color(el["id"])
        label = _escape(_short_label(el["label"]))
        action_type = el["id"].split("-")[0] if "-" in el["id"] else el["id"]
        type_label = _escape(_short_label(action_type, 18))
        parts.append(
            f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="4" '
            f'fill="{color}" stroke="none"/>'
        )
        # type label (small, top)
        parts.append(
            f'<text x="{x + w // 2}" y="{y + 16}" text-anchor="middle" '
            f'font-size="9" fill="{_TEXT_COLOR}" opacity="0.8">{type_label}</text>'
        )
        # name label (main)
        parts.append(
            f'<text x="{x + w // 2}" y="{y + 38}" text-anchor="middle" '
            f'font-size="11" font-weight="bold" fill="{_TEXT_COLOR}">{label}</text>'
        )

    # 4 — Comments (top layer)
    for el in layout:
        if el["type"] != "Comment":
            continue
        x, y, w, h = tx(el["x"]), ty(el["y"]), el["w"], el["h"]
        label = _escape(_short_label(el["label"], 36))
        parts.append(
            f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="3" '
            f'fill="{_COMMENT_FILL}" stroke="{_COMMENT_STROKE}" stroke-width="1.5"/>'
        )
        # dog-ear
        parts.append(
            f'<polygon points="{x + w - 12},{y} {x + w},{y + 12} {x + w - 12},{y + 12}" '
            f'fill="{_COMMENT_STROKE}"/>'
        )
        parts.append(
            f'<text x="{x + 8}" y="{y + 20}" font-size="11" '
            f'fill="{_SECTION_TEXT}">{label}</text>'
        )

    # Arrow marker def
    parts.insert(
        1,
        '<defs><marker id="arrow" markerWidth="8" markerHeight="8" '
        'refX="6" refY="3" orient="auto">'
        f'<path d="M0,0 L0,6 L8,3 z" fill="{_EDGE_COLOR}"/>'
        "</marker></defs>",
    )

    parts.append("</svg>")
    return "\n".join(parts)