From 42c1d5f700614d76779040ee01bfd27c20156c82 Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Wed, 6 May 2026 22:02:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20throughput=20comparison=20layout=20?= =?UTF-8?q?=E2=80=94=20centered=20rows=20with=20proper=20Left-Right=20alig?= =?UTF-8?q?nment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- continuous_batching.py | 109 +++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/continuous_batching.py b/continuous_batching.py index 71694e9..6b7c6b6 100644 --- a/continuous_batching.py +++ b/continuous_batching.py @@ -265,69 +265,62 @@ class ContinuousBatching(Scene): self.wait(0.3) - # bars - bar_base = LEFT * 2 - bar_max_w = 4.5 - bar_h = 0.5 - - static_bar = Rectangle(width=0, height=bar_h, color=RED, - fill_opacity=0.7, stroke_width=0).move_to(bar_base, LEFT) - static_value = always_redraw( - lambda: DecimalNumber( - static_bar.get_width() / bar_max_w * 1.0, - num_decimal_places=1, font_size=24, color=WHITE, - ).next_to(static_bar, RIGHT, buff=0.2) - ) - static_rect = Rectangle(width=bar_max_w, height=bar_h, color=RED, stroke_width=1.2) - static_rect.move_to(bar_base, LEFT).shift(RIGHT * bar_max_w / 2) - - cb_bar = Rectangle(width=0, height=bar_h, color=GREEN, - fill_opacity=0.7, stroke_width=0).move_to(bar_base, LEFT) - cb_value = always_redraw( - lambda: DecimalNumber( - cb_bar.get_width() / bar_max_w * 3.4, - num_decimal_places=1, font_size=24, color=WHITE, - ).next_to(cb_bar, RIGHT, buff=0.2) - ) - cb_rect = Rectangle(width=bar_max_w, height=bar_h, color=GREEN, stroke_width=1.2) - cb_rect.move_to(bar_base, LEFT).shift(RIGHT * bar_max_w / 2) - - static_label = Text("Static Batching ", font_size=22, color=RED) \ - .next_to(static_rect, LEFT, buff=0.3) - cb_label = Text("Continuous Batching", font_size=22, color=GREEN) \ - .next_to(cb_rect, LEFT, buff=0.3) - - labels = VGroup(static_label, cb_label).arrange(DOWN, buff=0.7, aligned_edge=LEFT) - labels.shift(LEFT * 2) - - bar_group = VGroup( - static_rect, static_bar, static_value, - cb_rect, cb_bar, cb_value, - static_label, cb_label, - ) - - compare_title = Text("Throughput", font_size=30, color=BLUE).next_to(bar_group, UP, buff=0.6) - + # ---- title ---- + compare_title = Text("Throughput Comparison", font_size=30, color=BLUE) self.play(Write(compare_title)) - self.play(Create(static_rect), Create(cb_rect), - Write(static_label), Write(cb_label)) + self.wait(0.2) + self.play(compare_title.animate.to_edge(UP).scale(0.55)) + self.wait(0.2) - # grow static bar - self.play(GrowFromEdge(static_bar, LEFT), - rate_func=linear, run_time=0.6) + # ---- bar config ---- + bar_max_w = 4.5 + bar_h = 0.55 + row_gap = 0.7 + + # Static Batching row + s_label = Text("Static Batching", font_size=24, color=RED) + s_rect = Rectangle(width=bar_max_w, height=bar_h, color=RED, stroke_width=1.5) + s_bar = Rectangle(width=0, height=bar_h, color=RED, + fill_opacity=0.55, stroke_width=0) \ + .align_to(s_rect, LEFT).align_to(s_rect, UP) + s_num = Text("1.0x", font_size=24, color=RED) + + s_row = VGroup(s_label, s_rect, s_bar, s_num) + s_label.next_to(s_rect, LEFT, buff=0.4) + s_num.next_to(s_rect, RIGHT, buff=0.4) + + # Continuous Batching row + c_label = Text("Continuous Batching", font_size=24, color=GREEN) + c_rect = Rectangle(width=bar_max_w, height=bar_h, color=GREEN, stroke_width=1.5) + c_bar = Rectangle(width=0, height=bar_h, color=GREEN, + fill_opacity=0.55, stroke_width=0) \ + .align_to(c_rect, LEFT).align_to(c_rect, UP) + c_num = Text("3.4x", font_size=24, color=GREEN) + + c_row = VGroup(c_label, c_rect, c_bar, c_num) + c_label.next_to(c_rect, LEFT, buff=0.4) + c_num.next_to(c_rect, RIGHT, buff=0.4) + + # stack rows, centre + chart = VGroup(s_row, c_row).arrange(DOWN, buff=row_gap, aligned_edge=LEFT) + chart.move_to(ORIGIN).shift(DOWN * 0.25) + + self.play( + Create(s_rect), Create(c_rect), + Write(s_label), Write(c_label), + ) self.wait(0.3) - # grow cb bar significantly faster - self.play(GrowFromEdge(cb_bar, LEFT), - rate_func=linear, run_time=0.6) - self.wait(0.4) + # grow static bar + self.play(GrowFromEdge(s_bar, LEFT), rate_func=linear, run_time=0.6) + self.wait(0.3) - # labels under bars - static_num = Text("1.0x", font_size=22, color=RED) \ - .next_to(static_rect, RIGHT, buff=0.3) - cb_num = Text("3.4x", font_size=22, color=GREEN) \ - .next_to(cb_rect, RIGHT, buff=0.3) - self.play(Write(static_num), Write(cb_num)) + # grow cb bar + self.play(GrowFromEdge(c_bar, LEFT), rate_func=linear, run_time=0.6) + self.wait(0.3) + + # show values + self.play(Write(s_num), Write(c_num)) self.wait(2.5) self.play(*[FadeOut(m) for m in self.mobjects])