|
10 | 10 | ArrowBox, |
11 | 11 | BezierCurveBox, |
12 | 12 | FilledCurveBox, |
13 | | - # GraphicsBox, |
| 13 | + GraphicsBox, |
14 | 14 | GraphicsElements, |
15 | 15 | InsetBox, |
16 | 16 | LineBox, |
@@ -111,60 +111,60 @@ def components(): |
111 | 111 | add_conversion_fn(FilledCurveBox) |
112 | 112 |
|
113 | 113 | # FIXME figure out how we can add this. |
114 | | -# def graphicsbox(self, leaves=None, **options) -> str: |
115 | | -# if not leaves: |
116 | | -# leaves = self._leaves |
117 | | -# |
118 | | -# data = options.get("data", None) |
119 | | -# if data: |
120 | | -# elements, xmin, xmax, ymin, ymax, w, h, width, height = data |
121 | | -# else: |
122 | | -# elements, calc_dimensions = self._prepare_elements( |
123 | | -# leaves, options, neg_y=True |
124 | | -# ) |
125 | | -# xmin, xmax, ymin, ymax, w, h, width, height = calc_dimensions() |
126 | | -# |
127 | | -# elements.view_width = w |
128 | | -# |
129 | | -# format_fn = lookup_method(elements, "svg") |
130 | | -# if format_fn is not None: |
131 | | -# svg_body = format_fn(elements, offset=options.get("offset", None)) |
132 | | -# else: |
133 | | -# svg_body = elements.to_svg(offset=options.get("offset", None)) |
134 | | -# |
135 | | -# if self.background_color is not None: |
136 | | -# # Wrap svg_elements in a rectangle |
137 | | -# svg_body = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % ( |
138 | | -# xmin, |
139 | | -# ymin, |
140 | | -# w, |
141 | | -# h, |
142 | | -# self.background_color.to_css()[0], |
143 | | -# svg_body, |
144 | | -# ) |
145 | | -# |
146 | | -# xmin -= 1 |
147 | | -# ymin -= 1 |
148 | | -# w += 2 |
149 | | -# h += 2 |
150 | | -# |
151 | | -# if options.get("noheader", False): |
152 | | -# return svg_body |
153 | | -# svg_main = """ |
154 | | -# <svg xmlns:svg="http://www.w3.org/2000/svg" |
155 | | -# xmlns="http://www.w3.org/2000/svg" |
156 | | -# version="1.1" |
157 | | -# viewBox="%s"> |
158 | | -# %s |
159 | | -# </svg> |
160 | | -# """ % ( |
161 | | -# " ".join("%f" % t for t in (xmin, ymin, w, h)), |
162 | | -# svg_body, |
163 | | -# ) |
164 | | -# return svg_main # , width, height |
165 | | -# |
166 | | -# |
167 | | -# add_conversion_fn(GraphicsBox) |
| 114 | +def graphicsbox(self, leaves=None, **options) -> str: |
| 115 | + if not leaves: |
| 116 | + leaves = self._leaves |
| 117 | + |
| 118 | + data = options.get("data", None) |
| 119 | + if data: |
| 120 | + elements, xmin, xmax, ymin, ymax, w, h, width, height = data |
| 121 | + else: |
| 122 | + elements, calc_dimensions = self._prepare_elements( |
| 123 | + leaves, options, neg_y=True |
| 124 | + ) |
| 125 | + xmin, xmax, ymin, ymax, w, h, width, height = calc_dimensions() |
| 126 | + |
| 127 | + elements.view_width = w |
| 128 | + |
| 129 | + format_fn = lookup_method(elements, "svg") |
| 130 | + if format_fn is not None: |
| 131 | + svg_body = format_fn(elements, offset=options.get("offset", None)) |
| 132 | + else: |
| 133 | + svg_body = elements.to_svg(offset=options.get("offset", None)) |
| 134 | + |
| 135 | + if self.background_color is not None: |
| 136 | + # Wrap svg_elements in a rectangle |
| 137 | + svg_body = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % ( |
| 138 | + xmin, |
| 139 | + ymin, |
| 140 | + w, |
| 141 | + h, |
| 142 | + self.background_color.to_css()[0], |
| 143 | + svg_body, |
| 144 | + ) |
| 145 | + |
| 146 | + xmin -= 1 |
| 147 | + ymin -= 1 |
| 148 | + w += 2 |
| 149 | + h += 2 |
| 150 | + |
| 151 | + if options.get("noheader", False): |
| 152 | + return svg_body |
| 153 | + svg_main = """ |
| 154 | + <svg xmlns:svg="http://www.w3.org/2000/svg" |
| 155 | + xmlns="http://www.w3.org/2000/svg" |
| 156 | + version="1.1" |
| 157 | + viewBox="%s"> |
| 158 | + %s |
| 159 | + </svg> |
| 160 | + """ % ( |
| 161 | + " ".join("%f" % t for t in (xmin, ymin, w, h)), |
| 162 | + svg_body, |
| 163 | + ) |
| 164 | + return svg_main # , width, height |
| 165 | + |
| 166 | + |
| 167 | +add_conversion_fn(GraphicsBox) |
168 | 168 |
|
169 | 169 |
|
170 | 170 | def graphicselements(self, offset=None): |
|
0 commit comments