textual
textual copied to clipboard
Allow Sparkline to be of any height
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:
Please review the following checklist.
- [x] Docstrings on all new or modified functions / classes
- [x] Updated documentation
- [x] Updated CHANGELOG.md (where appropriate)
@willmcgugan Added snapshot test, hope I did it right 🙏
@willmcgugan Any chance you can take a look?