Skip to content

Commit 8715dda

Browse files
committed
Added the marker_list function for setting multiple markers.
1 parent 5861da2 commit 8715dda

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

lightweight_charts/abstract.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,31 @@ def update(self, series: pd.Series):
250250
''')
251251
self.run_script(f'{self.id}.series.update({js_data(series)})')
252252

253+
def marker_list(self, markers: list):
254+
"""
255+
Creates multiple markers.\n
256+
:param markers: The list of markers to set. These should be in the format:\n
257+
[
258+
{"time": "2021-01-21", "position": "below", "shape": "circle", "color": "#2196F3", "text": ""},
259+
{"time": "2021-01-22", "position": "below", "shape": "circle", "color": "#2196F3", "text": ""},
260+
...
261+
]
262+
:return: a list of marker ids.
263+
"""
264+
markers = markers.copy()
265+
marker_ids = []
266+
for i, marker in enumerate(markers):
267+
markers[i]['time'] = self._single_datetime_format(markers[i]['time'])
268+
markers[i]['position'] = marker_position(markers[i]['position'])
269+
markers[i]['shape'] = marker_shape(markers[i]['shape'])
270+
markers[i]['id'] = self.win._id_gen.generate()
271+
marker_ids.append(markers[i]['id'])
272+
self.run_script(f"""
273+
{self.id}.markers.push(...{markers})
274+
{self.id}.series.setMarkers({self.id}.markers)
275+
""")
276+
return marker_ids
277+
253278
def marker(self, time: datetime = None, position: MARKER_POSITION = 'below',
254279
shape: MARKER_SHAPE = 'arrow_up', color: str = '#2196F3', text: str = ''
255280
) -> str:
@@ -964,7 +989,6 @@ def hotkey(self, modifier_key: Literal['ctrl', 'alt', 'shift', 'meta', None],
964989

965990
self.run_script(f'''
966991
{self.id}.commandFunctions.unshift((event) => {{
967-
console.log(event.key)
968992
if ({key_condition}) {{
969993
event.preventDefault()
970994
window.callbackFunction(`{modifier_key, keys}_~_{key}`)

0 commit comments

Comments
 (0)