diff --git a/swankit/callback/models/key.py b/swankit/callback/models/key.py index 78a74ef..ed2e2ab 100644 --- a/swankit/callback/models/key.py +++ b/swankit/callback/models/key.py @@ -29,6 +29,7 @@ def __init__( chart_name: Optional[str] = None, chart_index: Optional[str] = None, metric_name: Optional[str] = None, + metric_color: Optional[Tuple[str, str]] = None, ): """ 生成的列信息配置对象 @@ -36,11 +37,13 @@ def __init__( :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, @@ -48,6 +51,7 @@ def clone( chart_name: Optional[str] = None, chart_index: Optional[str] = None, metric_name: Optional[str] = None, + metric_color: Optional[Tuple[str, str]] = None, ): """ 克隆一个新的ColumnConfig对象,并且可以修改其中的参数 @@ -55,12 +59,15 @@ def clone( :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, ) diff --git a/test/unit/callback/models/test_key.py b/test/unit/callback/models/test_key.py index 7ee6049..e1f6c0e 100644 --- a/test/unit/callback/models/test_key.py +++ b/test/unit/callback/models/test_key.py @@ -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():