Skip to content
Snippets Groups Projects
Commit 83875913 authored by Tomáš Orviský's avatar Tomáš Orviský
Browse files

DiagramClass redraw and draw merge

parent e4f14495
No related merge requests found
...@@ -95,46 +95,31 @@ class DiagramClass(DiagramObject): ...@@ -95,46 +95,31 @@ class DiagramClass(DiagramObject):
self.__show_icon = show_icon self.__show_icon = show_icon
self.redraw() self.redraw()
def draw(self): def redraw(self):
header = self.__prepare_header() if self.do_draw:
attr_body = self.__prepare_attributes_body() header = self.__prepare_header()
method_body = self.__prepare_methods_body() attr_body = self.__prepare_attributes_body()
method_body = self.__prepare_methods_body()
max_width = max(self.__mg_header.width, self.__mg_attributes.width, self.__mg_methods.width) max_width = max(self.__mg_header.width, self.__mg_attributes.width, self.__mg_methods.width)
header.stretch_to_fit_width(max_width) header.stretch_to_fit_width(max_width)
attr_body.stretch_to_fit_width(max_width) attr_body.stretch_to_fit_width(max_width)
method_body.stretch_to_fit_width(max_width) method_body.stretch_to_fit_width(max_width)
mgroup = VGroup( mgroup = VGroup(
self.__mg_header, self.__mg_header,
self.__mg_attributes, self.__mg_attributes,
self.__mg_methods self.__mg_methods
).arrange(DOWN, buff=0) ).arrange(DOWN, buff=0)
if self.__generics: if self.__generics:
self.__mg_header.add(self.__prepare_generics()) self.__mg_header.add(self.__prepare_generics())
if self.notes: if self.notes:
self.__prepare_notes(mgroup) self.__prepare_notes(mgroup)
return mgroup self.add(mgroup)
def __prepare_notes(self, parent: VGroup):
note_groups = VGroup()
for _dir, notes in self.notes.items():
vect = _dir.get_manim_vect_dir()
note_groups.add(
VGroup(*notes)
.arrange(-vect)
.next_to(parent, vect)
)
parent.add(note_groups)
def redraw(self):
if self.do_draw:
self.become(self.draw(), match_center=True)
def __prepare_header(self): def __prepare_header(self):
mo_title = self.__prepare_title() mo_title = self.__prepare_title()
...@@ -177,6 +162,22 @@ class DiagramClass(DiagramObject): ...@@ -177,6 +162,22 @@ class DiagramClass(DiagramObject):
return border return border
@staticmethod
def __prepare_attributes(attributes: List[ClassAttribute]):
attr_group = VGroup()
for a in attributes:
text = Text(a.text, color=BLACK, slant=ITALIC if a.is_abstract else NORMAL)
if a.is_static:
text = VGroup(text, Underline(text, color=BLACK, buff=0, stroke_width=1))
attr_group.add(VGroup(
Text(a.modifier.value, color=BLACK),
text
).arrange(RIGHT, buff=0.1).scale(0.75))
return attr_group.arrange(DOWN, buff=0.1)
def __prepare_generics(self): def __prepare_generics(self):
g_text = Text(self.__generics, color=BLACK).scale(0.6) g_text = Text(self.__generics, color=BLACK).scale(0.6)
...@@ -193,21 +194,17 @@ class DiagramClass(DiagramObject): ...@@ -193,21 +194,17 @@ class DiagramClass(DiagramObject):
return g_group return g_group
@staticmethod def __prepare_notes(self, parent: VGroup):
def __prepare_attributes(attributes: List[ClassAttribute]): note_groups = VGroup()
attr_group = VGroup() for _dir, notes in self.notes.items():
for a in attributes: vect = _dir.get_manim_vect_dir()
text = Text(a.text, color=BLACK, slant=ITALIC if a.is_abstract else NORMAL) note_groups.add(
VGroup(*notes)
if a.is_static: .arrange(-vect)
text = VGroup(text, Underline(text, color=BLACK, buff=0, stroke_width=1)) .next_to(parent, vect)
)
attr_group.add(VGroup(
Text(a.modifier.value, color=BLACK),
text
).arrange(RIGHT, buff=0.1).scale(0.75))
return attr_group.arrange(DOWN, buff=0.1) parent.add(note_groups)
@staticmethod @staticmethod
def get_icon(text: str, colour) -> VMobject: def get_icon(text: str, colour) -> VMobject:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment