Enhancements:

- Added the `title` parameter to `Chart`.

Bug Fixes:
- When passing a timestamp format to `set`, `update`, or `update_from_tick`, the unit is now by default milliseconds rather than nanoseconds.
- When using `update`, if a time is passed that occurs before the current last datapoint, an error will be raised.
This commit is contained in:
louisnw
2023-11-22 17:31:35 +00:00
parent c3645ef245
commit 631afd450f
4 changed files with 18 additions and 12 deletions

View File

@ -210,7 +210,7 @@ class SeriesCommon(Pane):
def _single_datetime_format(self, arg):
if isinstance(arg, (str, int, float)) or not pd.api.types.is_datetime64_any_dtype(arg):
arg = pd.to_datetime(arg)
arg = pd.to_datetime(arg, unit='ms')
arg = self._interval * (arg.timestamp() // self._interval)+self.offset
return arg
@ -620,6 +620,11 @@ class Candlestick(SeriesCommon):
:param cumulative_volume: Adds the given volume onto the latest bar.
"""
series = self._series_datetime_format(series)
if series['time'] < self._last_bar['time']:
raise ValueError(
f'Trying to update tick of time "{pd.to_datetime(series["time"])}", '
f'which occurs before the last bar time of '
f'"{pd.to_datetime(self._last_bar["time"])}".')
bar = pd.Series()
if series['time'] == self._last_bar['time']:
bar = self._last_bar

View File

@ -16,7 +16,7 @@ class CallbackAPI:
class PyWV:
def __init__(self, q, start_ev, exit_ev, loaded, emit_queue, return_queue, html, debug,
width, height, x, y, screen, on_top, maximize):
width, height, x, y, screen, on_top, maximize, title):
self.queue = q
self.return_queue = return_queue
self.exit = exit_ev
@ -25,13 +25,13 @@ class PyWV:
self.html = html
self.windows = []
self.create_window(width, height, x, y, screen, on_top, maximize)
self.create_window(width, height, x, y, screen, on_top, maximize, title)
start_ev.wait()
webview.start(debug=debug)
self.exit.set()
def create_window(self, width, height, x, y, screen=None, on_top=False, maximize=False):
def create_window(self, width, height, x, y, screen=None, on_top=False, maximize=False, title=''):
screen = webview.screens[screen] if screen is not None else None
if maximize:
if screen is None:
@ -40,7 +40,7 @@ class PyWV:
else:
width, height = screen.width, screen.height
self.windows.append(webview.create_window(
'', html=self.html, js_api=self.callback_api,
title, html=self.html, js_api=self.callback_api,
width=width, height=height, x=x, y=y, screen=screen,
on_top=on_top, background_color='#000000'))
self.windows[-1].events.loaded += lambda: self.loop(self.loaded[len(self.windows)-1])
@ -73,9 +73,10 @@ class Chart(abstract.AbstractChart):
_q, _emit_q, _return_q = (mp.Queue() for _ in range(3))
_loaded_list = [mp.Event() for _ in range(MAX_WINDOWS)]
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None, screen: int = None,
on_top: bool = False, maximize: bool = False, debug: bool = False, toolbox: bool = False,
inner_width: float = 1.0, inner_height: float = 1.0, scale_candles_only: bool = False):
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None, title: str = '',
screen: int = None, on_top: bool = False, maximize: bool = False, debug: bool = False,
toolbox: bool = False, inner_width: float = 1.0, inner_height: float = 1.0,
scale_candles_only: bool = False):
self._i = Chart._window_num
self._loaded = Chart._loaded_list[self._i]
abstract.Window._return_q = Chart._return_q
@ -89,13 +90,13 @@ class Chart(abstract.AbstractChart):
self._process = mp.Process(target=PyWV, args=(
self._q, self._start, self._exit, Chart._loaded_list,
self._emit_q, self._return_q, abstract.TEMPLATE, debug,
width, height, x, y, screen, on_top, maximize,
width, height, x, y, screen, on_top, maximize, title
), daemon=True)
self._process.start()
else:
window.handlers = Chart._main_window_handlers
super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox)
self._q.put(('create_window', (width, height, x, y, screen, on_top, maximize)))
self._q.put(('create_window', (width, height, x, y, screen, on_top, maximize, title)))
def show(self, block: bool = False):
"""