chart.add_drawing is not working
import time
import webbrowser
from pathlib import Path
import polars as pl
# Using the specific classes you requested
import wrchart as wrc
from wrchart.drawing.tools import Rectangle
print("1. Generating Data...")
current_time = int(time.time())
day_in_seconds = 86400
data = []
for i in range(20):
t = int(current_time + (i * day_in_seconds))
data.append({"time": t, "open": 95.0+i, "high": 115.0+i, "low": 85.0+i, "close": 105.0+i})
df = pl.DataFrame(data)
t1 = int(data[5]["time"])
t2 = int(data[12]["time"])
p_high = float(120.0)
p_low = float(90.0)
print("2. Building Chart...")
chart = wrc.Chart(title="Rectangle Class Test", theme="dark", height=700)
chart.add_candlestick(df)
print("3. Adding Rectangle...")
# Using the Rectangle class exactly as defined in tools.py
chart.add_drawing(Rectangle(
start_time=t1,
start_price=p_high,
end_time=t2,
end_price=p_low,
color="#FFD700", # Border color
fill_color="#FFD700", # Fill color
fill_opacity=0.2, # Required float
z_index=1 # Ensure it's not behind the background
))
print("4. Exporting HTML...")
# Extracting the HTML string directly to bypass .show() display issues
html_content = chart._backend.to_html()
output_file = Path("test_draw_chart.html").resolve()
with open(output_file, "w", encoding="utf-8") as f:
f.write(html_content)
print(f"SUCCESS! File created: {output_file}")
webbrowser.open(f"file://{output_file}")
chart.add_drawingis not working