textual icon indicating copy to clipboard operation
textual copied to clipboard

Allow Sparkline to be of any height

Open uriyyo opened this issue 2 months ago • 2 comments

Make Sparkline be able to use not only 1 as a height value.

Demo app:

import random
from statistics import mean

from textual.containers import Grid

from textual.app import App, ComposeResult
from textual.widgets import Sparkline

random.seed(73)
data = [random.expovariate(1 / 3) for _ in range(1000)]


class SparklineAnyHeightApp(App[None]):
    DEFAULT_CSS = """
    SparklineAnyHeightApp {
        Sparkline {
            height: 1fr;
            border: round white;
        }
    }
    """

    def compose(self) -> ComposeResult:
        with Grid():
            yield Sparkline(data, summary_function=max)
            yield Sparkline(data, summary_function=mean)
            yield Sparkline(data, summary_function=min)
            yield Sparkline([*range(len(data))])
            yield Sparkline([1])
            yield Sparkline([])


if __name__ == "__main__":
    app = SparklineAnyHeightApp()
    app.run()

Result: image

Please review the following checklist.

  • [x] Docstrings on all new or modified functions / classes
  • [x] Updated documentation
  • [x] Updated CHANGELOG.md (where appropriate)

uriyyo avatar Oct 10 '25 12:10 uriyyo

@willmcgugan Added snapshot test, hope I did it right 🙏

uriyyo avatar Nov 10 '25 20:11 uriyyo

@willmcgugan Any chance you can take a look?

uriyyo avatar Nov 28 '25 13:11 uriyyo