mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-13 05:53:00 +00:00
Fix chart drawing: Properly handle price history data structure
This commit is contained in:
@@ -365,11 +365,13 @@ class StockManager:
|
|||||||
outline=color)
|
outline=color)
|
||||||
|
|
||||||
# Get price history for chart
|
# Get price history for chart
|
||||||
price_history = data['price_history']
|
price_history = data.get('price_history', [])
|
||||||
if len(price_history) >= 2: # Need at least 2 points to draw a line
|
if len(price_history) >= 2: # Need at least 2 points to draw a line
|
||||||
|
# Extract prices from price history
|
||||||
|
prices = [p['price'] for p in price_history]
|
||||||
# Calculate price range with padding to avoid flat lines
|
# Calculate price range with padding to avoid flat lines
|
||||||
min_price = min(price_history) * 0.99 # 1% padding below
|
min_price = min(prices) * 0.99 # 1% padding below
|
||||||
max_price = max(price_history) * 1.01 # 1% padding above
|
max_price = max(prices) * 1.01 # 1% padding above
|
||||||
price_range = max_price - min_price
|
price_range = max_price - min_price
|
||||||
|
|
||||||
if price_range == 0: # If all prices are the same
|
if price_range == 0: # If all prices are the same
|
||||||
@@ -377,7 +379,8 @@ class StockManager:
|
|||||||
|
|
||||||
# Calculate points for the line
|
# Calculate points for the line
|
||||||
points = []
|
points = []
|
||||||
for i, price in enumerate(price_history):
|
for i, price_data in enumerate(price_history):
|
||||||
|
price = price_data['price']
|
||||||
# Calculate x position with proper spacing
|
# Calculate x position with proper spacing
|
||||||
x = chart_x + 1 + (i * (chart_width - 2) // (len(price_history) - 1))
|
x = chart_x + 1 + (i * (chart_width - 2) // (len(price_history) - 1))
|
||||||
# Calculate y position (inverted because y=0 is at top)
|
# Calculate y position (inverted because y=0 is at top)
|
||||||
|
|||||||
Reference in New Issue
Block a user