Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawings deleting locally only #434

Open
esteban2006 opened this issue Jul 26, 2024 · 0 comments
Open

Drawings deleting locally only #434

esteban2006 opened this issue Jul 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@esteban2006
Copy link

Expected Behavior

Drawings deleting locally only

when a drawing is rendered, and later removed or price updated it should be update on the drawing.json file as well

Current Behaviour

Any drawings on the chart will not be deleted or updated from drawings.json

drawingsNotDeleting.mp4

i am adding some data for testing
data.csv

Reproducible Example

import pandas as pd
from lightweight_charts import Chart


def get_bar_data(symbol, timeframe):
    if symbol not in ('AAPL', 'GOOGL', 'TSLA'):
        print(f'No data for "{symbol}"')
        return pd.DataFrame()
    return pd.read_csv(f'bar_data/{symbol}_{timeframe}.csv')


def on_search(chart, searched_string):
    new_data = get_bar_data(searched_string, chart.topbar['timeframe'].value)
    if new_data.empty:
        return
    chart.topbar['symbol'].set(searched_string)
    chart.set(new_data)
    
    # Load the drawings saved under the symbol.
    chart.toolbox.load_drawings(searched_string)


def on_timeframe_selection(chart):
    new_data = get_bar_data(chart.topbar['symbol'].value, chart.topbar['timeframe'].value)
    if new_data.empty:
        return
    # The symbol has not changed, so we want to re-render the drawings.
    chart.set(new_data, keep_drawings=True)


if __name__ == '__main__':
    chart = Chart(toolbox=True)
    chart.legend(True)

    chart.events.search += on_search
    chart.topbar.textbox('symbol', 'TSLA')
    chart.topbar.switcher(
        'timeframe',
        ('1min', '5min', '30min'),
        default='5min',
        func=on_timeframe_selection
    )

    df = get_bar_data('TSLA', '5min')

    chart.set(df)

    # Imports the drawings saved in the JSON file.
    chart.toolbox.import_drawings('drawings.json')
    
    # Loads the drawings under the default symbol.
    chart.toolbox.load_drawings(chart.topbar['symbol'].value)  
    
    # Saves drawings based on the symbol.
    chart.toolbox.save_drawings_under(chart.topbar['symbol'])  

    chart.show(block=True)
    
    # Exports the drawings to the JSON file upon close.
    chart.toolbox.export_drawings('drawings.json')

Environment

- OS: Window 10
- name ='lightweight_charts',
    version='2.0.1',
    python='>=3.10',
@esteban2006 esteban2006 added the bug Something isn't working label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant