mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Update Sparkline.summary_func -> summary_function
This commit is contained in:
@@ -19,7 +19,7 @@ class Sparkline:
|
|||||||
width (int, optional): The width of the sparkline/the number of buckets to partition the data into.
|
width (int, optional): The width of the sparkline/the number of buckets to partition the data into.
|
||||||
min_color (Color, optional): The color of values equal to the min value in data.
|
min_color (Color, optional): The color of values equal to the min value in data.
|
||||||
max_color (Color, optional): The color of values equal to the max value in data.
|
max_color (Color, optional): The color of values equal to the max value in data.
|
||||||
summary_func (Callable[list[T]]): Function that will be applied to each bucket.
|
summary_function (Callable[list[T]]): Function that will be applied to each bucket.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
BARS = "▁▂▃▄▅▆▇█"
|
BARS = "▁▂▃▄▅▆▇█"
|
||||||
@@ -31,13 +31,13 @@ class Sparkline:
|
|||||||
width: int | None,
|
width: int | None,
|
||||||
min_color: Color = Color.from_rgb(0, 255, 0),
|
min_color: Color = Color.from_rgb(0, 255, 0),
|
||||||
max_color: Color = Color.from_rgb(255, 0, 0),
|
max_color: Color = Color.from_rgb(255, 0, 0),
|
||||||
summary_func: Callable[[list[T]], float] = max,
|
summary_function: Callable[[list[T]], float] = max,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.data = data
|
self.data = data
|
||||||
self.width = width
|
self.width = width
|
||||||
self.min_color = Style.from_color(min_color)
|
self.min_color = Style.from_color(min_color)
|
||||||
self.max_color = Style.from_color(max_color)
|
self.max_color = Style.from_color(max_color)
|
||||||
self.summary_func = summary_func
|
self.summary_func = summary_function
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _buckets(cls, data: Sequence[T], num_buckets: int) -> Iterable[list[T]]:
|
def _buckets(cls, data: Sequence[T], num_buckets: int) -> Iterable[list[T]]:
|
||||||
@@ -122,6 +122,6 @@ if __name__ == "__main__":
|
|||||||
console.print(f"data = {nums}\n")
|
console.print(f"data = {nums}\n")
|
||||||
for f in funcs:
|
for f in funcs:
|
||||||
console.print(
|
console.print(
|
||||||
f"{f.__name__}:\t", Sparkline(nums, width=12, summary_func=f), end=""
|
f"{f.__name__}:\t", Sparkline(nums, width=12, summary_function=f), end=""
|
||||||
)
|
)
|
||||||
console.print("\n")
|
console.print("\n")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def test_sparkline_shrink_data_to_width():
|
|||||||
|
|
||||||
def test_sparkline_shrink_data_to_width_non_divisible():
|
def test_sparkline_shrink_data_to_width_non_divisible():
|
||||||
assert render(
|
assert render(
|
||||||
Sparkline([1, 2, 3, 4, 5], width=3, summary_func=min)) == f"{GREEN}▁{STOP}{BLENDED}▄{STOP}{RED}█{STOP}"
|
Sparkline([1, 2, 3, 4, 5], width=3, summary_function=min)) == f"{GREEN}▁{STOP}{BLENDED}▄{STOP}{RED}█{STOP}"
|
||||||
|
|
||||||
|
|
||||||
def test_sparkline_color_blend():
|
def test_sparkline_color_blend():
|
||||||
|
|||||||
Reference in New Issue
Block a user