Skip to content

Commit

Permalink
feat(sdk): add linearChart into sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dvalleri committed Dec 11, 2024
1 parent cd10360 commit e7ca03c
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .binary_chart import BinaryChart
from .binary_chart_data import BinaryChartData, Binary_Data
from .binary_chart_data import BinaryDistributionChartData, BinaryLinearChartData

__all__ = [
'BinaryChart',
'BinaryChartData',
'Binary_Data'
'BinaryDistributionChartData',
'BinaryLinearChartData'
]
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from ipecharts import EChartsRawWidget

from .binary_chart_data import BinaryChartData
from .binary_chart_data import BinaryDistributionChartData, BinaryLinearChartData
from ..utils import get_chart_header


class BinaryChart:
def __init__(self) -> None:
pass

def distribution_chart(self, data: BinaryChartData) -> EChartsRawWidget:
def distribution_chart(self, data: BinaryDistributionChartData) -> EChartsRawWidget:
assert len(data.reference_data) <= 2
assert len(data.y_axis_label) <= 2

if data.current_data:
assert len(data.current_data) <= 2

reference_json_data = data.model_dump().get('reference_data')
current_data_json = data.model_dump().get('current_data')
current_data_json = data.model_dump().get('current_data')

reference_series_data = {
"title": data.title,
Expand Down Expand Up @@ -50,7 +50,8 @@ def distribution_chart(self, data: BinaryChartData) -> EChartsRawWidget:
}
}

series = [reference_series_data] if not data.current_data else [reference_series_data, current_series_data]
series = [reference_series_data] if not data.current_data else [
reference_series_data, current_series_data]

option = {
"grid": {
Expand Down Expand Up @@ -105,3 +106,106 @@ def distribution_chart(self, data: BinaryChartData) -> EChartsRawWidget:

return EChartsRawWidget(option=option)

def linear_chart(self, data: BinaryLinearChartData) -> EChartsRawWidget:

reference_json_data = data.model_dump().get('reference_data')
current_data_json = data.model_dump().get('current_data')

reference_series_data = {
"name": "Reference",
"type": "line",
"lineStyle": {
"width": 2.2,
"color": "#9B99A1",
"type": "dotted"
},
"symbol": "none",
"data": reference_json_data,
"itemStyle": {
"color": "#9B99A1"
},
"endLabel": {
"show": True,
"color": "#9B99A1"
},
"color": "#9B99A1"
}

current_series_data = {
"name": data.title,
"type": "line",
"lineStyle": {
"width": 2.2,
"color": "#73B2E0"
},
"symbol": "none",
"data": current_data_json,
"itemStyle": {
"color": "#73B2E0"
}
}

series = [reference_series_data, current_series_data]

options = {

"tooltip": {
"trigger": "axis",
"crosshairs": True,
"axisPointer": {
"type": "cross",
"label": {
"show": True
}
}
},
"yAxis": {
"type": "value",
"axisLabel": {
"fontSize": 9,
"color": "#9b99a1"
},
"splitLine": {
"lineStyle": {
"color": "#9f9f9f54"
}
},
"scale": True
},
"xAxis": {
"type": "time",
"axisTick": {
"show": False
},
"axisLine": {
"show": False
},
"splitLine": {
"show": False
},
"axisLabel": {
"fontSize": 12,
"color": "#9b99a1"
},
"scale": True
},
"grid": {
"bottom": 0,
"top": 32,
"left": 0,
"right": 64,
"containLabel": True
},
"series": series,
"legend": {
"show": True,
"textStyle": {
"color": "#9B99A1"
},
}
}

options.update(get_chart_header(title=data.title))

return EChartsRawWidget(option=options)

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
from pydantic import BaseModel


class Binary_Data(BaseModel):
class BinaryDistributionData(BaseModel):
percentage: float
count: float
value: float

class BinaryChartData(BaseModel):
class BinaryDistributionChartData(BaseModel):
title: str
y_axis_label: List[str]
reference_data: List[Binary_Data]
current_data: Optional[List[Binary_Data]] = None
reference_data: List[BinaryDistributionData]
current_data: Optional[List[BinaryDistributionData]] = None

class BinaryLinearChartData(BaseModel):
title: str
reference_data: List[List[str]]
current_data: List[List[str]]
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .multi_class_chart import MultiClassificationChart
from .multi_class_chart_data import MultiClassificationData, MultiClassificationChartData
from .multi_class_chart_data import MultiClassificationDistributionChartData, MultiClassificationLinearChartData, MultiClassificationLinearData

__all__ = [
'MultiClassificationChart',
'MultiClassificationData',
'MultiClassificationChartData'
'MultiClassificationDistributionChartData',
'MultiClassificationLinearChartData',
'MultiClassificationLinearData'
]
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from ipecharts import EChartsRawWidget

from .multi_class_chart_data import MultiClassificationChartData
from .multi_class_chart_data import MultiClassificationDistributionChartData, MultiClassificationLinearChartData
from ..utils import get_chart_header


class MultiClassificationChart:
def __init__(self) -> None:
pass

def distribution_chart(self, data: MultiClassificationChartData) -> EChartsRawWidget:
def distribution_chart(self, data: MultiClassificationDistributionChartData) -> EChartsRawWidget:

reference_json_data = data.model_dump().get('reference_data')
current_data_json = data.model_dump().get('current_data')
Expand All @@ -33,7 +33,8 @@ def distribution_chart(self, data: MultiClassificationChartData) -> EChartsRawWi
"data": current_data_json
}

series = [reference_series_data] if not data.current_data else [reference_series_data, current_series_data]
series = [reference_series_data] if not data.current_data else [
reference_series_data, current_series_data]

option = {
"grid": {
Expand Down Expand Up @@ -99,3 +100,119 @@ def distribution_chart(self, data: MultiClassificationChartData) -> EChartsRawWi
option.update(get_chart_header(title=data.title))

return EChartsRawWidget(option=option)

def linear_chart(self, data: MultiClassificationLinearChartData) -> EChartsRawWidget:

series = []

for element in data.current_data:
series.append({
"name": element.name,
"type": "line",
"lineStyle": {
"width": 2.2
},
"symbol": "none",
"data": element.values
})

for element in data.reference_data:
series.append({
"name": element.name,
"type": "line",
"lineStyle": {
"width": 2,
"type": "dotted"
},
"symbol": "none",
"data": element.values,
"endLabel": {
"show": False,
"color": "#9B99A1",
}
})

options = {
"yAxis": {
"type": "value",
"axisLabel": {
"fontSize": 9,
"color": "#9b99a1"
},
"splitLine": {
"lineStyle": {
"color": "#9f9f9f54"
}
}
},
"xAxis": {
"type": "time",
"axisTick": {
"show": False
},
"axisLine": {
"show": False
},
"splitLine": {
"show": False
},
"axisLabel": {
"fontSize": 12,
"color": "#9b99a1"
}
},
"grid": {
"bottom": 0,
"top": 32,
"left": 0,
"right": 140,
"containLabel": True
},
"color": [
"#00BFFF",
"#1E90FF",
"#00CED1",
"#20B2AA",
"#4169E1",
"#6A5ACD",
"#8A2BE2",
"#9400D3",
"#BA55D3"
],
"legend": {
"right": 0,
"top": 16,
"bottom": 0,
"orient": "vertical",
"type": "scroll",
"scrollDataIndex": "scroll",
"pageIconSize": 8,
"pageTextStyle": {
"fontSize": 9,
"color": "#9b99a1"
},
"textStyle": {
"fontSize": 9,
"color": "#9B99A1",
"fontWeight": "300"
},
},
"tooltip": {
"trigger": "axis"
},
"emphasis": {
"focus": "series"
},
"title": {
"text": "••• Reference",
"textStyle": {
"fontSize": 10,
"fontWeight": "300",
"color": "#9B99A1"
},
"right": 0
},
"series": series
}
print('\033[1m' + data.title)
return EChartsRawWidget(option=options)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

from pydantic import BaseModel

class MultiClassificationData(BaseModel):
class MultiClassificationDistributionData(BaseModel):
percentage: float
count: float
value: float

class MultiClassificationChartData(BaseModel):
class MultiClassificationDistributionChartData(BaseModel):
title: str
x_axis_label: List[str]
reference_data: List[MultiClassificationData]
current_data: Optional[List[MultiClassificationData]] = None
reference_data: List[MultiClassificationDistributionData]
current_data: Optional[List[MultiClassificationDistributionData]] = None

class MultiClassificationLinearData(BaseModel):
name: str
values: List[List[str]]


class MultiClassificationLinearChartData(BaseModel):
title: str
reference_data: List[MultiClassificationLinearData]
current_data: List[MultiClassificationLinearData]




Loading

0 comments on commit e7ca03c

Please sign in to comment.