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