mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
Improve chart visibility: Added checks and increased line width
This commit is contained in:
@@ -357,7 +357,7 @@ class StockManager:
|
|||||||
# Draw mini chart on the right
|
# Draw mini chart on the right
|
||||||
chart_width = 30 # Increased from 20 to 30
|
chart_width = 30 # Increased from 20 to 30
|
||||||
chart_height = 32 # Increased from 32 to match text height
|
chart_height = 32 # Increased from 32 to match text height
|
||||||
chart_x = scroll_width - chart_width - 5 # Shift one width to the right (using scroll_width instead of width)
|
chart_x = scroll_width - chart_width - 5 # Shift one width to the right
|
||||||
chart_y = 0 # Align with top of display
|
chart_y = 0 # Align with top of display
|
||||||
|
|
||||||
# Draw chart background
|
# Draw chart background
|
||||||
@@ -366,30 +366,31 @@ class StockManager:
|
|||||||
|
|
||||||
# Get price history for chart
|
# Get price history for chart
|
||||||
price_history = data.get('price_history', [])
|
price_history = data.get('price_history', [])
|
||||||
if len(price_history) >= 2: # Need at least 2 points to draw a line
|
if price_history and len(price_history) >= 2: # Need at least 2 points to draw a line
|
||||||
# Extract prices from price history
|
# Extract prices from price history
|
||||||
prices = [p['price'] for p in price_history]
|
prices = [p['price'] for p in price_history]
|
||||||
# Calculate price range with padding to avoid flat lines
|
if prices: # Make sure we have prices
|
||||||
min_price = min(prices) * 0.99 # 1% padding below
|
# Calculate price range with padding to avoid flat lines
|
||||||
max_price = max(prices) * 1.01 # 1% padding above
|
min_price = min(prices) * 0.99 # 1% padding below
|
||||||
price_range = max_price - min_price
|
max_price = max(prices) * 1.01 # 1% padding above
|
||||||
|
price_range = max_price - min_price
|
||||||
if price_range == 0: # If all prices are the same
|
|
||||||
price_range = min_price * 0.01 # Use 1% of price as range
|
if price_range == 0: # If all prices are the same
|
||||||
|
price_range = min_price * 0.01 # Use 1% of price as range
|
||||||
# Calculate points for the line
|
|
||||||
points = []
|
# Calculate points for the line
|
||||||
for i, price_data in enumerate(price_history):
|
points = []
|
||||||
price = price_data['price']
|
for i, price_data in enumerate(price_history):
|
||||||
# Calculate x position with proper spacing
|
price = price_data['price']
|
||||||
x = chart_x + 1 + (i * (chart_width - 2) // (len(price_history) - 1))
|
# Calculate x position with proper spacing
|
||||||
# Calculate y position (inverted because y=0 is at top)
|
x = chart_x + 1 + (i * (chart_width - 2) // (len(price_history) - 1))
|
||||||
y = chart_y + chart_height - 1 - int((price - min_price) * (chart_height - 2) / price_range)
|
# Calculate y position (inverted because y=0 is at top)
|
||||||
points.append((x, y))
|
y = chart_y + chart_height - 1 - int((price - min_price) * (chart_height - 2) / price_range)
|
||||||
|
points.append((x, y))
|
||||||
# Draw the line
|
|
||||||
if len(points) >= 2:
|
# Draw the line with increased width for visibility
|
||||||
draw.line(points, fill=color, width=1)
|
if len(points) >= 2:
|
||||||
|
draw.line(points, fill=color, width=2) # Increased line width
|
||||||
|
|
||||||
# Crop to show only the visible portion based on scroll position
|
# Crop to show only the visible portion based on scroll position
|
||||||
visible_image = image.crop((scroll_position, 0, scroll_position + width, height))
|
visible_image = image.crop((scroll_position, 0, scroll_position + width, height))
|
||||||
|
|||||||
Reference in New Issue
Block a user