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)})')

View File

@ -34,6 +34,10 @@ class PyWV:
def create_window(self, width, height, x, y, screen=None, on_top=False, maximize=False):
screen = webview.screens[screen] if screen is not None else None
if maximize:
if screen is None:
active_screen = webview.screens[0]
width, height = active_screen.width, active_screen.height
else:
width, height = screen.width, screen.height
self.windows.append(webview.create_window(
'', html=self.html, js_api=self.callback_api,

View File

@ -99,7 +99,11 @@ class Emitter:
return self
def _emit(self, *args):
self._callable(*args) if self._callable else None
if self._callable:
if asyncio.iscoroutinefunction(self._callable):
asyncio.create_task(self._callable(*args))
else:
self._callable(*args)
class JSEmitter:

View File

@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
setup(
name='lightweight_charts',
version='1.0.18',
version='1.0.18.2',
packages=find_packages(),
python_requires='>=3.8',
install_requires=[