···
animation_config: Optional[SyncedAnimationConfig] = None
-
def drawing_creation_hook(self, d):
-
'''Called by Drawing on initialization.'''
if self.animation_config:
-
self.animation_config.drawing_creation_hook(d, context=self)
def override_view_box(self, view_box):
···
view_box = (x, -y-h, w, h)
def override_args(self, args):
···
-
def write_svg_document_args(self, args, output_file):
'''Called by Drawing during SVG output of the <svg> tag.'''
args['viewBox'] = self.override_view_box(args['viewBox'])
self._write_tag_args(args, output_file)
-
def write_tag_args(self, args, output_file, id_map=None):
-
'''Called by an element during SVG output of its tag.'''
-
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))
'''Base class for drawing elements.
Subclasses must implement write_svg_element.
-
def write_svg_element(self, id_map, is_duplicate, output_file, context,
dry_run, force_dup=False):
raise NotImplementedError('Abstract base class')
def get_linked_elems(self):
-
def write_svg_defs(self, id_map, is_duplicate, output_file, context,
for defn in self.get_svg_defs():
-
id_map, is_duplicate, output_file, context, dry_run)
-
id_map, is_duplicate, output_file, context, dry_run,
···
'{} does not support children'.format(type(self)))
-
def _extra_children_with_context_avoid_recompute(self, context=None):
if (self._cached_extra_children_with_context is not None
-
and self._cached_context == context):
return self._cached_extra_children_with_context
-
self._cached_context = context
self._cached_extra_children_with_context = (
-
self.extra_children_with_context(context))
return self._cached_extra_children_with_context
-
def extra_children_with_context(self, context=None):
-
return self.animation_data.children_with_context(context)
-
def all_children(self, context=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])
-
self._extra_children_with_context_avoid_recompute(context))
return self.args.get('id', None)
-
def write_svg_element(self, id_map, is_duplicate, output_file, context,
dry_run, force_dup=False):
-
children = self.all_children(context=context)
if is_duplicate(self) and self.id is None:
···
-
id_map, is_duplicate, output_file, context, dry_run)
if children is not None and len(children):
self.write_children_content(
-
id_map, is_duplicate, output_file, context, dry_run)
if is_duplicate(self) and not force_dup:
···
override_args = dict(override_args)
override_args['id'] = id_map[id(self)]
-
context.write_tag_args(override_args, output_file, id_map)
if not self.has_content and (children is None or len(children) == 0):
-
id_map, is_duplicate, output_file, context, dry_run)
if children is not None and len(children):
self.write_children_content(
-
id_map, is_duplicate, output_file, context, dry_run)
output_file.write(self.TAG_NAME)
-
def write_content(self, id_map, is_duplicate, output_file, context,
'''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')
-
def write_children_content(self, id_map, is_duplicate, output_file, context,
'''Override in a subclass to add data between the start and end tags.
This will not be called if has_content is False.
-
children = self.all_children(context=context)
-
id_map, is_duplicate, output_file, context, dry_run)
-
child.write_svg_element(id_map, is_duplicate, output_file, context, dry_run)
return [v for v in self.args.values()
if isinstance(v, DrawingElement)]
-
def write_svg_defs(self, id_map, is_duplicate, output_file, context,
-
id_map, is_duplicate, output_file, context, dry_run)
-
for child in self.all_children(context=context):
-
id_map, is_duplicate, output_file, context, 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)
-
def write_content(self, id_map, is_duplicate, output_file, context,
···
animation_config: Optional[SyncedAnimationConfig] = None
+
def extra_prepost_drawing_elements(self, d):
+
if self.animation_config:
+
post.extend(self.animation_config.extra_drawing_elements(
+
def extra_css(self, d):
if self.animation_config:
+
return self.animation_config.extra_css(d, context=self)
+
def extra_javascript(self, d):
+
if self.animation_config:
+
return self.animation_config.extra_javascript(d, context=self)
+
def extra_onload_js(self, d):
+
if self.animation_config:
+
return self.animation_config.extra_onload_js(d, context=self)
def override_view_box(self, view_box):
···
view_box = (x, -y-h, w, h)
+
def is_attr_inverted(self, name):
+
return self.invert_y and name in ('y', 'cy', 'y1', 'y2')
def override_args(self, args):
···
+
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'])
+
onload_list = self.extra_onload_js(d)
+
onload_list.extend(args.get('onload', '').split(';'))
+
onload = ';'.join(onload_list)
+
args['onload'] = onload
self._write_tag_args(args, output_file)
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))
+
@dataclasses.dataclass(frozen=True)
+
element: 'DrawingElement'
+
parent: Union['DrawingElement', 'Drawing']
+
siblings: Sequence['DrawingElement'] = ()
+
def write_tag_args(self, args, output_file, id_map=None):
+
'''Called by an element during SVG output of its tag.'''
+
self.context._write_tag_args(
+
self.context.override_args(args), output_file, id_map=id_map)
'''Base class for drawing elements.
Subclasses must implement write_svg_element.
+
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):
+
def write_svg_defs(self, id_map, is_duplicate, output_file, lcontext,
for defn in self.get_svg_defs():
+
local = LocalContext(lcontext.context, defn, self, ())
+
id_map, is_duplicate, output_file, local, dry_run)
+
id_map, is_duplicate, output_file, local, dry_run,
···
'{} does not support children'.format(type(self)))
+
def _extra_children_with_context_avoid_recompute(self, lcontext=None):
if (self._cached_extra_children_with_context is not None
+
and self._cached_context == lcontext.context):
return self._cached_extra_children_with_context
+
self._cached_context = lcontext.context
self._cached_extra_children_with_context = (
+
self.extra_children_with_context(lcontext))
return self._cached_extra_children_with_context
+
def extra_children_with_context(self, lcontext=None):
+
return self.animation_data.children_with_context(lcontext)
+
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])
+
self._extra_children_with_context_avoid_recompute(lcontext))
return self.args.get('id', None)
+
def write_svg_element(self, id_map, is_duplicate, output_file, lcontext,
dry_run, force_dup=False):
+
children = self.all_children(lcontext=lcontext)
if is_duplicate(self) and self.id is None:
···
+
id_map, is_duplicate, output_file, lcontext, dry_run)
if children is not None and len(children):
self.write_children_content(
+
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)]
+
lcontext.write_tag_args(override_args, output_file, id_map)
if not self.has_content and (children is None or len(children) == 0):
+
id_map, is_duplicate, output_file, lcontext, dry_run)
if children is not None and len(children):
self.write_children_content(
+
id_map, is_duplicate, output_file, lcontext, dry_run)
output_file.write(self.TAG_NAME)
+
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')
+
def write_children_content(self, id_map, is_duplicate, output_file,
'''Override in a subclass to add data between the start and end tags.
This will not be called if has_content is False.
+
children = self.all_children(lcontext=lcontext)
+
local = LocalContext(lcontext.context, child, self, children)
+
id_map, is_duplicate, output_file, local, dry_run)
+
local = LocalContext(lcontext.context, child, self, children)
+
child.write_svg_element(
+
id_map, is_duplicate, output_file, local, dry_run)
return [v for v in self.args.values()
if isinstance(v, DrawingElement)]
+
def write_svg_defs(self, id_map, is_duplicate, output_file, lcontext,
+
id_map, is_duplicate, output_file, lcontext, dry_run)
+
children = self.all_children(lcontext=lcontext)
+
local = LocalContext(lcontext.context, child, self, children)
+
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)
+
def write_content(self, id_map, is_duplicate, output_file, lcontext,