Skip to content

Commit 2bd4c7c

Browse files
committed
Bug Fixes:
- Screen now defaults to the active screen rather than the `0` screen. - `null` values given in chart data are now removed and replaced with whitespace. - Closing the chart window now cleanly exits. - Fixed a bug causing the `offset` parameter to be greater than `0` when there is no offset.
1 parent d43e7c2 commit 2bd4c7c

6 files changed

Lines changed: 19 additions & 10 deletions

File tree

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
project = 'lightweight-charts-python'
44
copyright = '2023, louisnw'
55
author = 'louisnw'
6-
release = '1.0.17.6'
6+
release = '1.0.17.7'
77

88
extensions = [
99
"myst_parser",

docs/source/reference/abstract_chart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ ___
324324
325325
326326
327-
```{py:method} hotkey(modifier: 'ctrl' | 'alt' | 'shift' | 'meta', key: 'str' | 'int' | 'tuple', func: callable)
327+
```{py:method} hotkey(modifier: 'ctrl' | 'alt' | 'shift' | 'meta' | None, key: 'str' | 'int' | 'tuple', func: callable)
328328
329329
Adds a global hotkey to the chart window, which will execute the method or function given.
330330
331-
When using a number in `key`, it should be given as an integer. If multiple key commands are needed for the same function, a tuple can be passed to `key`.
331+
If multiple key commands are needed for the same function, a tuple can be passed to `key`.
332332
```
333333
___
334334

lightweight_charts/abstract.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def __init__(self, chart: 'AbstractChart', name: str = None):
134134
self._last_bar = None
135135
self.name = name
136136
self.num_decimals = 2
137+
self.offset = 0
137138

138139
def _set_interval(self, df: pd.DataFrame):
139140
if not pd.api.types.is_datetime64_any_dtype(df['time']):
@@ -155,7 +156,7 @@ def _set_interval(self, df: pd.DataFrame):
155156
value = value.total_seconds()
156157
if value == 0:
157158
continue
158-
elif value > self._interval:
159+
elif value >= self._interval:
159160
break
160161
self.offset = value
161162
break

lightweight_charts/chart.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def __init__(self, q, start_ev, exit_ev, loaded, emit_queue, return_queue, html,
3131
webview.start(debug=debug)
3232
self.exit.set()
3333

34-
def create_window(self, width, height, x, y, screen=0, on_top=False, maximize=False):
35-
screen = webview.screens[screen]
34+
def create_window(self, width, height, x, y, screen=None, on_top=False, maximize=False):
35+
screen = webview.screens[screen] if screen is not None else None
3636
if maximize:
3737
width, height = screen.width, screen.height
3838
self.windows.append(webview.create_window(
@@ -69,7 +69,7 @@ class Chart(abstract.AbstractChart):
6969
_q, _emit_q, _return_q = (mp.Queue() for _ in range(3))
7070
_loaded_list = [mp.Event() for _ in range(MAX_WINDOWS)]
7171

72-
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None, screen: int = 0,
72+
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None, screen: int = None,
7373
on_top: bool = False, maximize: bool = False, debug: bool = False, toolbox: bool = False,
7474
inner_width: float = 1.0, inner_height: float = 1.0, scale_candles_only: bool = False):
7575
self._i = Chart._window_num
@@ -121,6 +121,7 @@ async def show_async(self, block=False):
121121
if self._exit.is_set():
122122
self._exit.clear()
123123
self.is_alive = False
124+
self.exit()
124125
return
125126
elif not self._emit_q.empty():
126127
func, args = parse_event_message(self.win, self._emit_q.get())
@@ -146,4 +147,5 @@ def exit(self):
146147
Chart._main_window_handlers = None
147148
Chart._window_num = 0
148149
Chart._q = mp.Queue()
150+
Chart._exit.clear(), Chart._start.clear()
149151
self.is_alive = False

lightweight_charts/util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import json
23
from datetime import datetime
34
from random import choices
45
from typing import Literal, Union
@@ -34,8 +35,13 @@ def parse_event_message(window, string):
3435

3536

3637
def js_data(data: Union[pd.DataFrame, pd.Series]):
37-
orient = 'columns' if isinstance(data, pd.Series) else 'records'
38-
return data.to_json(orient=orient, default_handler=lambda x: 'null' if pd.isna(x) else x)
38+
if isinstance(data, pd.DataFrame):
39+
d = data.to_dict(orient='records')
40+
filtered_records = [{k: v for k, v in record.items() if v is not None} for record in d]
41+
else:
42+
d = data.to_dict()
43+
filtered_records = {k: v for k, v in d.items()}
44+
return json.dumps(filtered_records, indent=2)
3945

4046

4147
def jbool(b: bool): return 'true' if b is True else 'false' if b is False else None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='lightweight_charts',
8-
version='1.0.17.6',
8+
version='1.0.17.7',
99
packages=find_packages(),
1010
python_requires='>=3.8',
1111
install_requires=[

0 commit comments

Comments
 (0)