| 136 | |
| 137 | |
| 138 | def svg_nd(chunks, size=200): |
| 139 | if len(chunks) % 3 == 1: |
| 140 | chunks = ((1,),) + chunks |
| 141 | shape = tuple(map(sum, chunks)) |
| 142 | sizes = draw_sizes(shape, size=size) |
| 143 | |
| 144 | chunks2 = chunks |
| 145 | sizes2 = sizes |
| 146 | out = [] |
| 147 | left = 0 |
| 148 | total_height = 0 |
| 149 | while chunks2: |
| 150 | n = len(chunks2) % 3 or 3 |
| 151 | o = svg(chunks2[:n], sizes=sizes2[:n], offset=(left, 0)) |
| 152 | chunks2 = chunks2[n:] |
| 153 | sizes2 = sizes2[n:] |
| 154 | |
| 155 | lines = o.split("\n") |
| 156 | header = lines[0] |
| 157 | height = float(re.search(r'height="(\d*\.?\d*)"', header).groups()[0]) |
| 158 | total_height = max(total_height, height) |
| 159 | width = float(re.search(r'width="(\d*\.?\d*)"', header).groups()[0]) |
| 160 | left += width + 10 |
| 161 | o = "\n".join(lines[1:-1]) # remove header and footer |
| 162 | |
| 163 | out.append(o) |
| 164 | |
| 165 | header = ( |
| 166 | '<svg width="%d" height="%d" style="stroke:rgb(0,0,0);stroke-width:1" >\n' |
| 167 | % (left, total_height) |
| 168 | ) |
| 169 | footer = "\n</svg>" |
| 170 | return header + "\n\n".join(out) + footer |
| 171 | |
| 172 | |
| 173 | def svg_lines(x1, y1, x2, y2, max_n=20): |