Skip to content

Commit

Permalink
feat: metric color (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT authored Dec 11, 2024
1 parent ebf9cf2 commit 451f886
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions swankit/callback/models/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,45 @@ def __init__(
chart_name: Optional[str] = None,
chart_index: Optional[str] = None,
metric_name: Optional[str] = None,
metric_color: Optional[Tuple[str, str]] = None,
):
"""
生成的列信息配置对象
:param y_range: y轴范围
:param chart_name: 图表名称
:param chart_index: 图表索引
:param metric_name: 指标名称
:param metric_color: 指标颜色
"""
self.y_range: YRange = y_range
self.chart_name: Optional[str] = chart_name
self.chart_index: Optional[str] = chart_index
self.metric_name: Optional[str] = metric_name
self.metric_color: Optional[Tuple[str, str]] = metric_color

def clone(
self,
y_range: YRange = None,
chart_name: Optional[str] = None,
chart_index: Optional[str] = None,
metric_name: Optional[str] = None,
metric_color: Optional[Tuple[str, str]] = None,
):
"""
克隆一个新的ColumnConfig对象,并且可以修改其中的参数
:param y_range: y轴范围
:param chart_name: 图表名称
:param chart_index: 图表索引
:param metric_name: 指标名称
:param metric_color: 指标颜色
:return: 新的ColumnConfig对象
"""
return ColumnConfig(
y_range=y_range if y_range is not None else self.y_range,
chart_name=chart_name if chart_name is not None else self.chart_name,
metric_name=metric_name if metric_name is not None else self.metric_name,
chart_index=chart_index if chart_index is not None else self.chart_index,
metric_color=metric_color if metric_color is not None else self.metric_color,
)


Expand Down
6 changes: 6 additions & 0 deletions test/unit/callback/models/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def test_column_config():
assert c.chart_name == "CPU Utilization (%)"
assert c.metric_name == "12345"
assert c.chart_index == "1"
c = c.clone(metric_color=("red", "blue"))
assert c.y_range == (0, 100)
assert c.chart_name == "CPU Utilization (%)"
assert c.metric_name == "12345"
assert c.chart_index == "1"
assert c.metric_color == ("red", "blue")


def test_column_info():
Expand Down

0 comments on commit 451f886

Please sign in to comment.