Polygon:
- Added async methods to polygon. - The `requests` library is no longer required, with `urllib` being used instead. - Added the `get_bar_data` function, which returns a dataframe of aggregate data from polygon. - Opened up the `subscribe` and `unsubscribe` functions Enhancements: - Tables will now scroll when the rows exceed table height. Bugs: - Fixed a bug preventing async functions being used with horizontal line event. - Fixed a bug causing the legend to show duplicate lines if the line was created after the legend. - Fixed a bug causing the line hide icon to persist within the legend after deletion (#75) - Fixed a bug causing the search box to be unfocused when the chart is loaded.
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
import random
|
||||
from typing import Union
|
||||
|
||||
from .util import jbool
|
||||
from .util import jbool, Pane, NUM
|
||||
|
||||
|
||||
class Footer:
|
||||
def __init__(self, table): self._table = table
|
||||
def __init__(self, table):
|
||||
self._table = table
|
||||
|
||||
def __setitem__(self, key, value): self._table._run_script(f'{self._table.id}.footer[{key}].innerText = "{value}"')
|
||||
def __setitem__(self, key, value):
|
||||
self._table.run_script(f'{self._table.id}.footer[{key}].innerText = "{value}"')
|
||||
|
||||
def __call__(self, number_of_text_boxes): self._table._run_script(f'{self._table.id}.makeFooter({number_of_text_boxes})')
|
||||
def __call__(self, number_of_text_boxes: int):
|
||||
self._table.run_script(f'{self._table.id}.makeFooter({number_of_text_boxes})')
|
||||
|
||||
|
||||
class Row(dict):
|
||||
def __init__(self, table, id, items):
|
||||
super().__init__()
|
||||
self.run_script = table.run_script
|
||||
self._table = table
|
||||
self._run_script = table._run_script
|
||||
self.id = id
|
||||
self.meta = {}
|
||||
self._run_script(f'''{self._table.id}.newRow({list(items.values())}, '{self.id}')''')
|
||||
self.run_script(f'{self._table.id}.newRow({list(items.values())}, "{self.id}")')
|
||||
for key, val in items.items():
|
||||
self[key] = val
|
||||
|
||||
@ -29,8 +32,7 @@ class Row(dict):
|
||||
original_value = value
|
||||
if column in self._table._formatters:
|
||||
value = self._table._formatters[column].replace(self._table.VALUE, str(value))
|
||||
self._run_script(f'{self._table.id}.updateCell("{self.id}", "{column}", "{value}")')
|
||||
|
||||
self.run_script(f'{self._table.id}.updateCell("{self.id}", "{column}", "{value}")')
|
||||
return super().__setitem__(column, original_value)
|
||||
|
||||
def background_color(self, column, color): self._style('backgroundColor', column, color)
|
||||
@ -38,30 +40,29 @@ class Row(dict):
|
||||
def text_color(self, column, color): self._style('textColor', column, color)
|
||||
|
||||
def _style(self, style, column, arg):
|
||||
self._run_script(f"{self._table.id}.rows[{self.id}]['{column}'].style.{style} = '{arg}'")
|
||||
self.run_script(f"{self._table.id}.rows[{self.id}]['{column}'].style.{style} = '{arg}'")
|
||||
|
||||
def delete(self):
|
||||
self._run_script(f"{self._table.id}.deleteRow('{self.id}')")
|
||||
self.run_script(f"{self._table.id}.deleteRow('{self.id}')")
|
||||
self._table.pop(self.id)
|
||||
|
||||
class Table(dict):
|
||||
|
||||
class Table(Pane, dict):
|
||||
VALUE = 'CELL__~__VALUE__~__PLACEHOLDER'
|
||||
|
||||
def __init__(self, chart, width, height, headings, widths=None, alignments=None, position='left', draggable=False, func=None):
|
||||
super().__init__()
|
||||
self._run_script = chart.run_script
|
||||
self._chart = chart
|
||||
self.headings = headings
|
||||
def __init__(self, window, width: NUM, height: NUM, headings: tuple, widths: tuple = None, alignments: tuple = None, position='left', draggable: bool = False, func: callable = None):
|
||||
dict.__init__(self)
|
||||
Pane.__init__(self, window)
|
||||
self._formatters = {}
|
||||
self.headings = headings
|
||||
self.is_shown = True
|
||||
self.win.handlers[self.id] = lambda rId: func(self[rId])
|
||||
headings = list(headings)
|
||||
widths = list(widths) if widths else []
|
||||
alignments = list(alignments) if alignments else []
|
||||
|
||||
self.id = chart._rand.generate()
|
||||
chart._handlers[self.id] = lambda rId: func(self[rId])
|
||||
self._run_script(f'''
|
||||
{self.id} = new Table({width}, {height}, {list(headings)}, {list(widths) if widths else []}, {list(alignments) if alignments else []},
|
||||
'{position}', {jbool(draggable)}, {chart.id})
|
||||
''')
|
||||
self._run_script(f'{self.id}.callbackName = "{self.id}"') if func else None
|
||||
self.run_script(f'{self.id} = new Table({width}, {height}, {headings}, {widths}, {alignments}, "{position}", {jbool(draggable)})')
|
||||
self.run_script(f'{self.id}.callbackName = "{self.id}"') if func else None
|
||||
self.footer = Footer(self)
|
||||
|
||||
def new_row(self, *values, id=None) -> Row:
|
||||
@ -69,7 +70,7 @@ class Table(dict):
|
||||
self[row_id] = Row(self, row_id, {heading: item for heading, item in zip(self.headings, values)})
|
||||
return self[row_id]
|
||||
|
||||
def clear(self): self._run_script(f"{self.id}.clearRows()"), super().clear()
|
||||
def clear(self): self.run_script(f"{self.id}.clearRows()"), super().clear()
|
||||
|
||||
def get(self, __key: Union[int, str]) -> Row: return super().get(int(__key))
|
||||
|
||||
@ -79,7 +80,7 @@ class Table(dict):
|
||||
|
||||
def visible(self, visible: bool):
|
||||
self.is_shown = visible
|
||||
self._run_script(f"""
|
||||
self.run_script(f"""
|
||||
{self.id}.container.style.display = '{'block' if visible else 'none'}'
|
||||
{self.id}.container.{'add' if visible else 'remove'}EventListener('mousedown', {self.id}.onMouseDown)
|
||||
""")
|
||||
|
||||
Reference in New Issue
Block a user