From 2b8dfce9c982972e1b8089a0c26a45cc6043ae41 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 20 Nov 2026 08:54:12 -0800 Subject: [PATCH] Reuse self.normal_data in StackedChart.draw() --- termgraph/chart.py | 3 +-- tests/test_charts.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/termgraph/chart.py b/termgraph/chart.py index 7622b44..82c5bdb 100644 --- a/termgraph/chart.py +++ b/termgraph/chart.py @@ -339,7 +339,6 @@ def draw(self) -> None: ) val_min = self.data.find_min() - normal_data = self._normalize() for i in range(len(self.data.labels)): if self.args.get_arg("no_labels"): @@ -354,7 +353,7 @@ def draw(self) -> None: print(label, end="") values = self.data.data[i] - num_blocks = normal_data[i] + num_blocks = self.normal_data[i] for j in range(len(values)): print_row_core( diff --git a/tests/test_charts.py b/tests/test_charts.py index f6ccd5b..54c9123 100644 --- a/tests/test_charts.py +++ b/tests/test_charts.py @@ -314,3 +314,18 @@ def test_stackedchart_longest_bar_fits_width(): def test_stackedchart_bar_lengths_follow_totals(): assert _stacked_bar_lengths([[1, 1], [2, 2]], width=20) == [10, 20] assert _stacked_bar_lengths([[30, 10], [10, 30]], width=8) == [8, 8] + + +def test_stackedchart_draw_reuses_normal_data(monkeypatch, capsys): + chart = StackedChart( + Data([[10, 20], [20, 40]], ["A", "B"]), + Args(width=12, custom_tick="X", no_values=True), + ) + + def fail_normalize(): + raise AssertionError("StackedChart.draw() should reuse self.normal_data") + + monkeypatch.setattr(chart, "_normalize", fail_normalize) + chart.draw() + assert "X" in capsys.readouterr().out +