A community-maintained Python framework for creating mathematical animations.
Feature: SVGMobject("unpack_groups" = False) preserve the hierarchy of groups in the file.
mirefek8cf2214d15d6
diff --git a/mobject/svg_mobject.py b/mobject/svg_mobject.pyindex 81d7c7c8d..0b3b0b6ca 100644--- a/mobject/svg_mobject.py+++ b/mobject/svg_mobject.py@@ -1,7 +1,7 @@from xml.dom import minidomimport warnings-from vectorized_mobject import VMobject+from vectorized_mobject import VMobject, VGroupfrom topics.geometry import Rectangle, Circlefrom helpers import *@@ -21,6 +21,7 @@ class SVGMobject(VMobject):"width" : None,#Must be filled in in a subclass, or when called"file_name" : None,+ "unpack_groups" : True, # if False, creates a hierarchy of VGroups"stroke_width" : 0,"fill_opacity" : 1,# "fill_color" : LIGHT_GREY,@@ -50,7 +51,9 @@ class SVGMobject(VMobject):doc = minidom.parse(self.file_path)self.ref_to_element = {}for svg in doc.getElementsByTagName("svg"):- self.add(*self.get_mobjects_from(svg))+ mobjects = self.get_mobjects_from(svg)+ if self.unpack_groups: self.add(*mobjects)+ else: self.add(*mobjects[0].submobjects)doc.unlink()def get_mobjects_from(self, element):@@ -85,6 +88,9 @@ class SVGMobject(VMobject):# warnings.warn("Unknown element type: " + element.tagName)result = filter(lambda m : m is not None, result)self.handle_transforms(element, VMobject(*result))+ if len(result) > 1 and not self.unpack_groups:+ result = [VGroup(*result)]+return resultdef g_to_mobjects(self, g_element):