Remove gaps in intraday charts when the market is not open
This commit is contained in:
parent
23d5ffb391
commit
1a76ae8c47
@ -1,4 +1,4 @@
|
||||
from pandas import date_range, Series
|
||||
from pandas import date_range, Series, to_datetime
|
||||
from plotly.basedatatypes import BaseTraceType
|
||||
from typing import List
|
||||
|
||||
@ -15,5 +15,16 @@ class Chart:
|
||||
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)]
|
||||
range_breaks = [dict(values = missing_dates)]
|
||||
|
||||
if self.is_intraday():
|
||||
# Assuming US Eastern time zone.
|
||||
range_breaks.append(dict(bounds = [16, 9.5], pattern = 'hour'))
|
||||
|
||||
return range_breaks
|
||||
|
||||
def is_intraday(self) -> bool:
|
||||
# Check if the x-axis series has a time component other than midnight.
|
||||
return any(to_datetime(self.x).dt.time != to_datetime(self.x).dt.normalize().dt.time)
|
Loading…
Reference in New Issue
Block a user