SVG Renderer¶
SVG rendering engine for converting diagrams to SVG files.
render_svg ¶
SVG rendering for GPIO diagrams.
SVGRenderer ¶
Render GPIO wiring diagrams to SVG format.
Converts a Diagram object into a scalable SVG image showing the Raspberry Pi board, connected devices, wire connections, and optional GPIO reference diagram.
The renderer handles
- Board SVG asset embedding
- Device box rendering with labeled pins
- Wire routing with rounded corners
- Inline component symbols (resistors, capacitors, diodes)
- GPIO pin numbering and color coding
- Optional GPIO reference diagram
- Automatic layout via LayoutEngine
Examples:
>>> from pinviz import boards, devices, Connection, Diagram, SVGRenderer
>>>
>>> diagram = Diagram(
... title="LED Circuit",
... board=boards.raspberry_pi_5(),
... devices=[devices.led()],
... connections=[
... Connection(11, "LED", "Anode"),
... Connection(6, "LED", "Cathode")
... ]
... )
>>>
>>> renderer = SVGRenderer()
>>> renderer.render(diagram, "led_circuit.svg")
Initialize SVG renderer with optional layout configuration.
| PARAMETER | DESCRIPTION |
|---|---|
layout_config
|
Layout configuration for spacing and margins. If None, uses default LayoutConfig.
TYPE:
|
Source code in src/pinviz/render_svg.py
draw_gpio_pin_numbers ¶
Draw pin numbers on GPIO header with color-coded backgrounds.
Creates small circles at each pin location with the physical pin number (1-40) and color-coded background based on pin role (power, ground, GPIO, I2C, SPI, etc.).
| PARAMETER | DESCRIPTION |
|---|---|
dwg
|
The SVG drawing object
TYPE:
|
board
|
The board containing pin definitions
TYPE:
|
x
|
Board X offset
TYPE:
|
y
|
Board Y offset
TYPE:
|
color_scheme
|
Theme color scheme
|
Source code in src/pinviz/render_svg.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
draw_specs_table ¶
draw_specs_table(
dwg: Drawing,
devices_with_specs: list[Device],
table_x: float,
table_y: float,
table_width: float,
color_scheme,
) -> None
Draw the "Device Specifications" table at a given position and width.
Source code in src/pinviz/render_svg.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
inline_svg_elements ¶
Inline SVG elements from external SVG file.
Recursively processes all elements in the SVG and adds them to the parent group.
| PARAMETER | DESCRIPTION |
|---|---|
parent_group
|
Parent drawing group to add elements to
|
svg_root
|
Root element of the SVG to inline
|
dwg
|
Main drawing object
TYPE:
|
show_board_name
|
Whether to include board name text from SVG
TYPE:
|
Source code in src/pinviz/render_svg.py
render ¶
Render a diagram to an SVG file.
| PARAMETER | DESCRIPTION |
|---|---|
diagram
|
The diagram to render
TYPE:
|
output_path
|
Output file path
TYPE:
|
Source code in src/pinviz/render_svg.py
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
render_to_string ¶
Render a diagram to an SVG string.
| PARAMETER | DESCRIPTION |
|---|---|
diagram
|
The diagram to render
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
SVG content as string |
Source code in src/pinviz/render_svg.py
specs_table_height ¶
Height of the specifications table for these devices at this width.