Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions termgraph/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ def _prepare_vertical(self, value: float, num_blocks: int):

def draw(self) -> None:
"""Draws the vertical chart"""
self.value_list.clear()
self.zipped_list.clear()
self.vertical_list.clear()
self.maxi = 0
self._print_header()

colors = self.args.get_arg("colors")
Expand Down
20 changes: 20 additions & 0 deletions tests/test_chart_redraw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from termgraph.args import Args
from termgraph.chart import BarChart, StackedChart, VerticalChart
from termgraph.data import Data


@pytest.mark.parametrize("chart_type", [BarChart, StackedChart, VerticalChart])
@pytest.mark.parametrize("options", [{}, {"no_values": True}, {"no_labels": True}])
def test_drawing_chart_again_preserves_output(capsys, chart_type, options):
data = Data([[3], [5]], ["A", "B"])
chart = chart_type(data, Args(width=5, **options))

chart.draw()
expected = capsys.readouterr().out
assert "▇" in expected

for _ in range(2):
chart.draw()
assert capsys.readouterr().out == expected
Loading