2023-12-29 15:15:18 +00:00
|
|
|
from chart import Chart
|
|
|
|
from plotly.graph_objects import Figure
|
|
|
|
from plotly.subplots import make_subplots
|
|
|
|
from typing import List
|
|
|
|
|
2024-01-03 14:32:29 +00:00
|
|
|
def subplot_titles(subplots: List[List[Chart]]) -> List[str]:
|
|
|
|
subplot_titles = []
|
|
|
|
for row in subplots:
|
|
|
|
for chart in row:
|
|
|
|
subplot_titles.append(chart.title)
|
|
|
|
return subplot_titles
|
|
|
|
|
2023-12-31 14:12:37 +00:00
|
|
|
def figure_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
2023-12-29 15:15:18 +00:00
|
|
|
num_rows = len(subplots)
|
|
|
|
num_columns = len(subplots[0])
|
2024-01-03 14:32:29 +00:00
|
|
|
|
|
|
|
figure = make_subplots(rows = num_rows, cols = num_columns, subplot_titles = subplot_titles(subplots))
|
2023-12-29 15:15:18 +00:00
|
|
|
|
|
|
|
for i, row in enumerate(subplots, start = 1):
|
|
|
|
for j, chart in enumerate(row, start = 1):
|
2024-01-01 14:00:09 +00:00
|
|
|
for trace in chart.traces():
|
|
|
|
figure.add_trace(trace, row = i, col = j)
|
2024-01-02 13:36:08 +00:00
|
|
|
|
|
|
|
figure.update_xaxes(
|
|
|
|
showgrid = False,
|
|
|
|
showticklabels = True,
|
|
|
|
rangebreaks = chart.range_breaks(),
|
|
|
|
rangeslider = dict(visible = False),
|
|
|
|
row = i, col = j
|
|
|
|
)
|
|
|
|
figure.update_yaxes(
|
|
|
|
showgrid = False,
|
|
|
|
side = 'right',
|
|
|
|
row = i, col = j
|
|
|
|
)
|
2023-12-29 15:15:18 +00:00
|
|
|
|
|
|
|
# TODO: Make this configurable.
|
|
|
|
figure.update_layout(
|
2024-01-30 18:56:02 +00:00
|
|
|
bargap = 0,
|
|
|
|
bargroupgap = 0,
|
2023-12-29 15:15:18 +00:00
|
|
|
paper_bgcolor = '#0f0f0f',
|
|
|
|
plot_bgcolor = '#0f0f0f',
|
|
|
|
font_color = '#7a7c7d',
|
|
|
|
showlegend = False,
|
2024-01-30 18:56:02 +00:00
|
|
|
margin = dict(pad = 15),
|
|
|
|
xaxis = dict(zerolinecolor = '#0f0f0f'),
|
|
|
|
yaxis = dict(zerolinecolor = '#0f0f0f')
|
2023-12-29 15:15:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return figure
|
|
|
|
|
2023-12-31 14:12:37 +00:00
|
|
|
def plot(chart: Chart) -> None:
|
2023-12-31 15:15:53 +00:00
|
|
|
figure_with_subplots([[chart]]).show(config = {'displayModeBar': False})
|