SVG Table Class


In [1]:
cd Git_quickref_project/


/home/damon/Documents/CODE/Programing/Python/IPython/Quickref/Git_quickref_project

In [2]:
from IPython.display import SVG

In [3]:
%run SVG_Table_Classes

This is a class developed to draw SVG tables with text for IPython Qick Referance.


In [4]:
test=SVG_Text_obj("testing")
SVG(test.get_SVG_text())


Out[4]:
testing

In [5]:
head=Table_Header(text="Header",width=100)
print(head.text)
print(head.get_SVG_header())
print("The bottom of the header is at {} px\n".format(head.bottom))
Text=Set_SVG_view(102, head.bottom+2, head.get_SVG_header())
print(Text)
SVG(Text)


Header
<rect  height="25" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="1" />
<text x="7" y="18" font-size= "14" font-weight = "bold" style="fill:rgb(0, 0, 0)">Header</text>

The bottom of the header is at 25 px

<svg viewBox="0 0 102 27" height="27">
<rect  height="25" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="1" />
<text x="7" y="18" font-size= "14" font-weight = "bold" style="fill:rgb(0, 0, 0)">Header</text>
</svg>
Out[5]:
Header

You should see a white rectangle the header text inside above


In [17]:
rows = Table_rows()
#rows.set_count(6)
text_list = [["Area\ntest"],["Area"],["Dog"],["Area"],["Area"]]
rows.set_text_list(text_list)
rows.column_locations=[0,40]
rows.__height__=30 #only the minimum value is set automatically
print(rows.__count__)
print(rows.bottom)
print(rows.get_SVG_rows())
Text=Set_SVG_view(rows.row_width+2*rows.line_width, rows.bottom+rows.line_width*2+60, rows.get_SVG_rows())
SVG(Text)


5
155
<rect  height="35" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="1" />
<text x="6" y="13" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area<tspan x="6" y="27">test</tspan></text>
<rect  height="35" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="36" />
<text x="6" y="57" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="35" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="71" />
<text x="6" y="92" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Dog</text>
<rect  height="35" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="106" />
<text x="6" y="127" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="35" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="141" />
<text x="6" y="162" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<line x1="40" y1="1" x2="40" y2="176" style="stroke:rgb(0, 0, 0); stroke-width:1"/>

Out[17]:
Areatest Area Dog Area Area

In [16]:
rows = Table_rows()
rows.set_count(6)
text_list = [["Area"],["Area"],["Dog"],["Area"],["Area"]]
rows.set_text_list(text_list)
rows.column_locations=[0,60]
print(rows.__count__)
print(rows.bottom)
print(rows.get_SVG_rows())
Text=Set_SVG_view(rows.row_width+2*rows.line_width, rows.bottom+rows.line_width*2+60, rows.get_SVG_rows())
SVG(Text)


6
102
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="1" />
<text x="6" y="16" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="23" />
<text x="6" y="38" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="45" />
<text x="6" y="60" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Dog</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="67" />
<text x="6" y="82" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="89" />
<text x="6" y="104" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="111" />
<line x1="60" y1="1" x2="60" y2="133" style="stroke:rgb(0, 0, 0); stroke-width:1"/>

Out[16]:
Area Area Dog Area Area

In [14]:
rows = Table_rows()
rows.set_count(6)
text_list = [["Area\n new line"],["Area"],["Dog"],["Area"],["Area"]]
rows.set_text_list(text_list)
rows.__height__=25 #only the minimum value is set automatically
rows.column_locations=[0,60]
Text=Set_SVG_view(rows.row_width+2*rows.line_width, rows.bottom+rows.line_width*2+72, rows.get_SVG_rows())
SVG(Text)


Out[14]:
Area new line Area Dog Area Area

In [15]:
head=Table_Header(text="Header",width=100)


rows = Table_rows(top_left=[0,head.bottom])
rows.set_count(6)
text_list = [["Area","blue"],["Area","blue"],["Dog","blue"],["Area","blue"],["Area","blue"]]
rows.set_text_list(text_list)
rows.column_locations=[0,50]
rows.x_shift=5
display_text=head.get_SVG_header()+rows.get_SVG_rows()
Text=Set_SVG_view(102, rows.bottom+32, display_text)
print(Text)
SVG(Text)


<svg viewBox="0 0 102 159" height="159">
<rect  height="25" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="1" />
<text x="7" y="18" font-size= "14" font-weight = "bold" style="fill:rgb(0, 0, 0)">Header</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="26" />
<text x="11" y="41" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<text x="61" y="41" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">blue</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="48" />
<text x="11" y="63" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<text x="61" y="63" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">blue</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="70" />
<text x="11" y="85" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Dog</text>
<text x="61" y="85" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">blue</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="92" />
<text x="11" y="107" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<text x="61" y="107" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">blue</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="114" />
<text x="11" y="129" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">Area</text>
<text x="61" y="129" font-size= "12" font-weight = "normal" style="fill:rgb(0, 0, 0)">blue</text>
<rect  height="22" width="100"  style=" fill:rgb(255, 255, 255); stroke:rgb(0, 0, 0); stroke-width:1"  x="1"  y="136" />
<line x1="50" y1="26" x2="50" y2="158" style="stroke:rgb(0, 0, 0); stroke-width:1"/>
</svg>
Out[15]:
Header Area blue Area blue Dog blue Area blue Area blue

In [9]: