···
animation_config: Optional[SyncedAnimationConfig] = None
16
-
def drawing_creation_hook(self, d):
17
-
'''Called by Drawing on initialization.'''
16
+
def extra_prepost_drawing_elements(self, d):
18
+
if self.animation_config:
19
+
post.extend(self.animation_config.extra_drawing_elements(
23
+
def extra_css(self, d):
if self.animation_config:
19
-
self.animation_config.drawing_creation_hook(d, context=self)
25
+
return self.animation_config.extra_css(d, context=self)
28
+
def extra_javascript(self, d):
29
+
if self.animation_config:
30
+
return self.animation_config.extra_javascript(d, context=self)
33
+
def extra_onload_js(self, d):
34
+
if self.animation_config:
35
+
return self.animation_config.extra_onload_js(d, context=self)
def override_view_box(self, view_box):
···
view_box = (x, -y-h, w, h)
47
+
def is_attr_inverted(self, name):
48
+
return self.invert_y and name in ('y', 'cy', 'y1', 'y2')
def override_args(self, args):
···
93
-
def write_svg_document_args(self, args, output_file):
113
+
def write_svg_document_args(self, d, args, output_file):
'''Called by Drawing during SVG output of the <svg> tag.'''
args['viewBox'] = self.override_view_box(args['viewBox'])
116
+
onload_list = self.extra_onload_js(d)
117
+
onload_list.extend(args.get('onload', '').split(';'))
118
+
onload = ';'.join(onload_list)
120
+
args['onload'] = onload
self._write_tag_args(args, output_file)
98
-
def write_tag_args(self, args, output_file, id_map=None):
99
-
'''Called by an element during SVG output of its tag.'''
100
-
self._write_tag_args(
101
-
self.override_args(args), output_file, id_map=id_map)
def _write_tag_args(self, args, output_file, id_map=None):
'''Called by an element during SVG output of its tag.'''
···
output_file.write(' {}="{}"'.format(k,v))
140
+
@dataclasses.dataclass(frozen=True)
141
+
class LocalContext:
143
+
element: 'DrawingElement'
144
+
parent: Union['DrawingElement', 'Drawing']
145
+
siblings: Sequence['DrawingElement'] = ()
147
+
def write_tag_args(self, args, output_file, id_map=None):
148
+
'''Called by an element during SVG output of its tag.'''
149
+
self.context._write_tag_args(
150
+
self.context.override_args(args), output_file, id_map=id_map)
'''Base class for drawing elements.
Subclasses must implement write_svg_element.
125
-
def write_svg_element(self, id_map, is_duplicate, output_file, context,
158
+
def write_svg_element(self, id_map, is_duplicate, output_file, lcontext,
dry_run, force_dup=False):
raise NotImplementedError('Abstract base class')
def get_linked_elems(self):
132
-
def write_svg_defs(self, id_map, is_duplicate, output_file, context,
165
+
def write_svg_defs(self, id_map, is_duplicate, output_file, lcontext,
for defn in self.get_svg_defs():
168
+
local = LocalContext(lcontext.context, defn, self, ())
138
-
id_map, is_duplicate, output_file, context, dry_run)
172
+
id_map, is_duplicate, output_file, local, dry_run)
142
-
id_map, is_duplicate, output_file, context, dry_run,
176
+
id_map, is_duplicate, output_file, local, dry_run,
···
'{} does not support children'.format(type(self)))
169
-
def _extra_children_with_context_avoid_recompute(self, context=None):
203
+
def _extra_children_with_context_avoid_recompute(self, lcontext=None):
if (self._cached_extra_children_with_context is not None
171
-
and self._cached_context == context):
205
+
and self._cached_context == lcontext.context):
return self._cached_extra_children_with_context
173
-
self._cached_context = context
207
+
self._cached_context = lcontext.context
self._cached_extra_children_with_context = (
175
-
self.extra_children_with_context(context))
209
+
self.extra_children_with_context(lcontext))
return self._cached_extra_children_with_context
177
-
def extra_children_with_context(self, context=None):
178
-
return self.animation_data.children_with_context(context)
179
-
def all_children(self, context=None):
211
+
def extra_children_with_context(self, lcontext=None):
212
+
return self.animation_data.children_with_context(lcontext)
213
+
def all_children(self, lcontext=None):
'''Return self.children and self.ordered_children as a single list.'''
output = list(self.children)
for z in sorted(self.ordered_children):
output.extend(self.ordered_children[z])
185
-
self._extra_children_with_context_avoid_recompute(context))
219
+
self._extra_children_with_context_avoid_recompute(lcontext))
return self.args.get('id', None)
190
-
def write_svg_element(self, id_map, is_duplicate, output_file, context,
224
+
def write_svg_element(self, id_map, is_duplicate, output_file, lcontext,
dry_run, force_dup=False):
192
-
children = self.all_children(context=context)
226
+
children = self.all_children(lcontext=lcontext)
if is_duplicate(self) and self.id is None:
···
201
-
id_map, is_duplicate, output_file, context, dry_run)
235
+
id_map, is_duplicate, output_file, lcontext, dry_run)
if children is not None and len(children):
self.write_children_content(
204
-
id_map, is_duplicate, output_file, context, dry_run)
238
+
id_map, is_duplicate, output_file, lcontext, dry_run)
if is_duplicate(self) and not force_dup:
···
override_args = dict(override_args)
override_args['id'] = id_map[id(self)]
218
-
context.write_tag_args(override_args, output_file, id_map)
252
+
lcontext.write_tag_args(override_args, output_file, id_map)
if not self.has_content and (children is None or len(children) == 0):
225
-
id_map, is_duplicate, output_file, context, dry_run)
259
+
id_map, is_duplicate, output_file, lcontext, dry_run)
if children is not None and len(children):
self.write_children_content(
228
-
id_map, is_duplicate, output_file, context, dry_run)
262
+
id_map, is_duplicate, output_file, lcontext, dry_run)
output_file.write(self.TAG_NAME)
232
-
def write_content(self, id_map, is_duplicate, output_file, context,
266
+
def write_content(self, id_map, is_duplicate, output_file, lcontext,
'''Override in a subclass to add data between the start and end tags.
This will not be called if has_content is False.
raise RuntimeError('This element has no content')
239
-
def write_children_content(self, id_map, is_duplicate, output_file, context,
273
+
def write_children_content(self, id_map, is_duplicate, output_file,
274
+
lcontext, dry_run):
'''Override in a subclass to add data between the start and end tags.
This will not be called if has_content is False.
245
-
children = self.all_children(context=context)
279
+
children = self.all_children(lcontext=lcontext)
282
+
local = LocalContext(lcontext.context, child, self, children)
249
-
id_map, is_duplicate, output_file, context, dry_run)
284
+
id_map, is_duplicate, output_file, local, dry_run)
253
-
child.write_svg_element(id_map, is_duplicate, output_file, context, dry_run)
288
+
local = LocalContext(lcontext.context, child, self, children)
289
+
child.write_svg_element(
290
+
id_map, is_duplicate, output_file, local, dry_run)
return [v for v in self.args.values()
if isinstance(v, DrawingElement)]
258
-
def write_svg_defs(self, id_map, is_duplicate, output_file, context,
295
+
def write_svg_defs(self, id_map, is_duplicate, output_file, lcontext,
261
-
id_map, is_duplicate, output_file, context, dry_run)
262
-
for child in self.all_children(context=context):
298
+
id_map, is_duplicate, output_file, lcontext, dry_run)
299
+
children = self.all_children(lcontext=lcontext)
300
+
for child in children:
301
+
local = LocalContext(lcontext.context, child, self, children)
264
-
id_map, is_duplicate, output_file, context, dry_run)
303
+
id_map, is_duplicate, output_file, local, dry_run)
if isinstance(other, type(self)):
return (self.TAG_NAME == other.TAG_NAME and
···
self.ordered_children[z].extend(iterable)
self.children.extend(iterable)
325
-
def write_content(self, id_map, is_duplicate, output_file, context,
364
+
def write_content(self, id_map, is_duplicate, output_file, lcontext,