Grid

class visigoth.containers.grid.Grid(stroke=None, stroke_width=0, padding=10, fill=None)

A grid layout

Keyword Arguments
  • stroke_width (int) – width of the grid lines in pixels

  • stroke (str) – colour of the grid lines

  • padding (int) – width of the cell padding in pixels

  • fill (str) – fill colour for the cells

Note: use the add method to add elements to the grid

add(row, col, element)

Add an element into the grid

Parameters
  • row (int) – the number of the row (numbering starts at 0, top to bottom)

  • col (int) – the number of the column (numbering starts at 0, left to right)

  • element (DiagramElement) – the element to add

Example

Screenshot (Link to open SVG for interactive features):

../_images/example15.png

Source Code (Link to Github):


import os
import sys
import argparse

from visigoth import Diagram

from visigoth.containers.grid import Grid
from visigoth.common.text import Text

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    d = Diagram(fill="white")

    d.add(Text("Simple Grid"))

    g = Grid()
    g.add(0,0,Text("Top-Left Cell in Grid"))
    g.add(1,0,Text("Bottom-Left").setRightJustified())
    g.add(0,1,Text("Top-Right").setLeftJustified())
    g.add(1,1,Text("Bottom-Right Cell in Grid"))
    d.add(g)

    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()