Remove gaps from charts due to weekends and holidays
This commit is contained in:
parent
81ae787aa5
commit
0993aa8c3d
13
chart.py
13
chart.py
@ -1,7 +1,18 @@
|
|||||||
|
from pandas import date_range, Series
|
||||||
from plotly.basedatatypes import BaseTraceType
|
from plotly.basedatatypes import BaseTraceType
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
class Chart:
|
class Chart:
|
||||||
|
|
||||||
|
x: Series = None
|
||||||
|
|
||||||
def traces(self) -> List[BaseTraceType]:
|
def traces(self) -> List[BaseTraceType]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def range_breaks(self) -> List[dict]:
|
||||||
|
# Assuming x is either a date or timestamp.
|
||||||
|
start_date = self.x.min()
|
||||||
|
end_date = self.x.max()
|
||||||
|
all_dates = date_range(start = start_date, end = end_date)
|
||||||
|
missing_dates = all_dates.difference(self.x)
|
||||||
|
return [dict(values = missing_dates)]
|
15
plot.py
15
plot.py
@ -13,8 +13,19 @@ def figure_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
|||||||
for j, chart in enumerate(row, start = 1):
|
for j, chart in enumerate(row, start = 1):
|
||||||
for trace in chart.traces():
|
for trace in chart.traces():
|
||||||
figure.add_trace(trace, row = i, col = j)
|
figure.add_trace(trace, row = i, col = j)
|
||||||
figure.update_xaxes(showgrid = False, showticklabels = True, rangeslider = dict(visible = False), row = i, col = j)
|
|
||||||
figure.update_yaxes(showgrid = False, side = 'right', row = i, col = j)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: Make this configurable.
|
# TODO: Make this configurable.
|
||||||
figure.update_layout(
|
figure.update_layout(
|
||||||
|
Loading…
Reference in New Issue
Block a user