diff --git a/lightweight_charts/abstract.py b/lightweight_charts/abstract.py index 30c8b55..7e2a725 100644 --- a/lightweight_charts/abstract.py +++ b/lightweight_charts/abstract.py @@ -141,6 +141,7 @@ def __init__(self, chart: 'AbstractChart', name: str = None): 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 @@ def _single_datetime_format(self, arg): 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 @@ def set(self, df: pd.DataFrame = None, format_cols: bool = True): 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 @@ def update(self, series: pd.Series): 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)})') diff --git a/lightweight_charts/chart.py b/lightweight_charts/chart.py index 2f70c25..4ac21e0 100644 --- a/lightweight_charts/chart.py +++ b/lightweight_charts/chart.py @@ -34,7 +34,11 @@ def __init__(self, q, start_ev, exit_ev, loaded, emit_queue, return_queue, html, 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: - width, height = screen.width, screen.height + 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, width=width, height=height, x=x, y=y, screen=screen, diff --git a/lightweight_charts/util.py b/lightweight_charts/util.py index 1d38f97..ef3583c 100644 --- a/lightweight_charts/util.py +++ b/lightweight_charts/util.py @@ -99,7 +99,11 @@ def __iadd__(self, other): 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: diff --git a/setup.py b/setup.py index 0dae59b..262c15f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='lightweight_charts', - version='1.0.18', + version='1.0.18.2', packages=find_packages(), python_requires='>=3.8', install_requires=[