Enhancements & Bug Fixes

- Line, and histogram data can now be accessed from their `data` methods.
- Fixed a bug causing `maximize` to fail if a screen is not specified
- Global events can now be coroutines or functions.
This commit is contained in:
louisnw
2023-10-21 14:13:11 +01:00
parent 2c27ad66eb
commit 5bb3739a40
4 changed files with 17 additions and 3 deletions

View File

@ -141,6 +141,7 @@ class SeriesCommon(Pane):
self.name = name
self.num_decimals = 2
self.offset = 0
self.data = pd.DataFrame()
def _set_interval(self, df: pd.DataFrame):
if not pd.api.types.is_datetime64_any_dtype(df['time']):
@ -216,6 +217,7 @@ class SeriesCommon(Pane):
def set(self, df: pd.DataFrame = None, format_cols: bool = True):
if df is None or df.empty:
self.run_script(f'{self.id}.series.setData([])')
self.data = pd.DataFrame()
return
if format_cols:
df = self._df_datetime_format(df, exclude_lowercase=self.name)
@ -223,6 +225,7 @@ class SeriesCommon(Pane):
if self.name not in df:
raise NameError(f'No column named "{self.name}".')
df = df.rename(columns={self.name: 'value'})
self.data = df.copy()
self._last_bar = df.iloc[-1]
self.run_script(f'{self.id}.series.setData({js_data(df)})')
@ -230,6 +233,9 @@ class SeriesCommon(Pane):
series = self._series_datetime_format(series, exclude_lowercase=self.name)
if self.name in series.index:
series.rename({self.name: 'value'}, inplace=True)
if series['time'] != self._last_bar['time']:
self.data.loc[self.data.index[-1]] = self._last_bar
self.data = pd.concat([self.data, series.to_frame().T], ignore_index=True)
self._last_bar = series
self.run_script(f'{self.id}.series.update({js_data(series)})')