Skip to content

Commit

Permalink
feat: add DrilldownPie
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Sep 9, 2024
1 parent f219626 commit 81d1ea7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ bStats Metrics for Endstone Plugins

## Features

- [ ] Metrics Class
- [x] Metrics Class
- Custom Charts
- [x] Simple Pie
- [x] Advanced Pie
- [ ] Drilldown Pie
- [x] Drilldown Pie
- [ ] Single Line
- [ ] Multi Line
- [ ] Simple Bar
Expand Down
4 changes: 1 addition & 3 deletions src/endstone_bstats/_charts/advanced_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def get_chart_data(self) -> dict | None:
dict | None: A dictionary with the chart data.
"""

data = {}
values = {}
map_values = self.get_values()
if not map_values:
Expand All @@ -42,5 +41,4 @@ def get_chart_data(self) -> dict | None:
if not values:
return None

data["values"] = values
return data
return {"values": values}
44 changes: 44 additions & 0 deletions src/endstone_bstats/_charts/drilldown_pie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __future__ import annotations

from typing import Callable, Dict

from endstone_bstats._charts.custom_chart import CustomChart


class DrilldownPie(CustomChart):
def __init__(
self, chart_id: str, get_values: Callable[[], Dict[str, Dict[str, int]] | None]
) -> None:
"""
Class constructor.
Args:
chart_id (str): The id of the chart.
get_values (Callable[[], Dict[str, Dict[str, int]] | None]): The callable which is used to request the chart data.
"""

super().__init__(chart_id)
self.get_values = get_values

def get_chart_data(self) -> dict | None:
"""
Gets the data for the advanced pie chart.
Returns:
dict | None: A dictionary with the chart data.
"""

values = {}
map_values = self.get_values()
if not map_values:
return None

for key, value in map_values.items():
if not value:
continue
values[key] = value

if not values:
return None

return {"values": values}
4 changes: 1 addition & 3 deletions src/endstone_bstats/_charts/simple_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def get_chart_data(self) -> dict | None:
dict | None: A dictionary with the chart data.
"""

data = {}
value = self.get_value()
if not value:
return None # skip the chart

data["value"] = value
return data
return {"value": value}

0 comments on commit 81d1ea7

Please sign in to comment.