2023-12-30 14:15:30 +00:00
|
|
|
from chart import Chart
|
2024-01-04 13:26:58 +00:00
|
|
|
from line import Line
|
2023-12-30 14:15:30 +00:00
|
|
|
from pandas import Series
|
|
|
|
from plotly.graph_objects import Scatter
|
2024-01-01 14:00:09 +00:00
|
|
|
from typing import List
|
2023-12-30 14:15:30 +00:00
|
|
|
|
|
|
|
class LineChart(Chart):
|
|
|
|
|
2024-01-04 13:26:58 +00:00
|
|
|
def __init__(self, x: Series, lines: List[Line], title: str = ''):
|
2023-12-30 14:15:30 +00:00
|
|
|
self.x = x
|
2024-01-04 13:26:58 +00:00
|
|
|
self.lines = lines
|
2024-01-03 14:32:29 +00:00
|
|
|
self.title = title
|
2023-12-30 14:15:30 +00:00
|
|
|
|
2024-01-01 14:00:09 +00:00
|
|
|
def traces(self) -> List[Scatter]:
|
|
|
|
traces = []
|
2024-01-04 13:26:58 +00:00
|
|
|
for line in self.lines:
|
2024-01-01 14:00:09 +00:00
|
|
|
traces.append(Scatter(
|
|
|
|
x = self.x,
|
2024-01-04 13:26:58 +00:00
|
|
|
y = line.values,
|
2024-01-01 14:00:09 +00:00
|
|
|
mode = 'lines',
|
2024-01-04 13:26:58 +00:00
|
|
|
name = line.name,
|
|
|
|
line = dict(color = line.color)
|
2024-01-01 14:00:09 +00:00
|
|
|
))
|
|
|
|
return traces
|