mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Improve stock chart: Increase size and remove outline for cleaner look
This commit is contained in:
@@ -515,7 +515,7 @@ class StockManager:
|
|||||||
PIL Image of the stock display
|
PIL Image of the stock display
|
||||||
"""
|
"""
|
||||||
# Create a wider image for scrolling
|
# Create a wider image for scrolling
|
||||||
width = self.display_manager.matrix.width * 3 # Increased from 2x to 3x for more space
|
width = self.display_manager.matrix.width * 2 # Reduced from 3x to 2x since we'll handle spacing in display_stocks
|
||||||
height = self.display_manager.matrix.height
|
height = self.display_manager.matrix.height
|
||||||
image = Image.new('RGB', (width, height), color=(0, 0, 0))
|
image = Image.new('RGB', (width, height), color=(0, 0, 0))
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
@@ -523,8 +523,8 @@ class StockManager:
|
|||||||
# Draw large stock logo on the left
|
# Draw large stock logo on the left
|
||||||
logo = self._get_stock_logo(symbol)
|
logo = self._get_stock_logo(symbol)
|
||||||
if logo:
|
if logo:
|
||||||
# Position logo on the left side with less space before the symbol
|
# Position logo on the left side with consistent spacing
|
||||||
logo_x = 2 # Reduced from 5 to 2
|
logo_x = 2
|
||||||
logo_y = (height - logo.height) // 2
|
logo_y = (height - logo.height) // 2
|
||||||
image.paste(logo, (logo_x, logo_y), logo)
|
image.paste(logo, (logo_x, logo_y), logo)
|
||||||
|
|
||||||
@@ -548,7 +548,7 @@ class StockManager:
|
|||||||
change_height = change_bbox[3] - change_bbox[1]
|
change_height = change_bbox[3] - change_bbox[1]
|
||||||
|
|
||||||
# Calculate total height needed for all text
|
# Calculate total height needed for all text
|
||||||
total_text_height = symbol_height + price_height + change_height + 2 # Reduced from 4 to 2 pixels for spacing
|
total_text_height = symbol_height + price_height + change_height + 2 # 2 pixels for spacing
|
||||||
|
|
||||||
# Calculate starting y position to center the text block
|
# Calculate starting y position to center the text block
|
||||||
start_y = (height - total_text_height) // 2
|
start_y = (height - total_text_height) // 2
|
||||||
@@ -562,13 +562,13 @@ class StockManager:
|
|||||||
# Draw price
|
# Draw price
|
||||||
price_width = price_bbox[2] - price_bbox[0]
|
price_width = price_bbox[2] - price_bbox[0]
|
||||||
price_x = width // 2 - price_width // 2
|
price_x = width // 2 - price_width // 2
|
||||||
price_y = symbol_y + symbol_height + 1 # Reduced from 2 to 1 pixel spacing
|
price_y = symbol_y + symbol_height + 1 # 1 pixel spacing
|
||||||
draw.text((price_x, price_y), price_text, font=regular_font, fill=(255, 255, 255))
|
draw.text((price_x, price_y), price_text, font=regular_font, fill=(255, 255, 255))
|
||||||
|
|
||||||
# Draw change with color based on value
|
# Draw change with color based on value
|
||||||
change_width = change_bbox[2] - change_bbox[0]
|
change_width = change_bbox[2] - change_bbox[0]
|
||||||
change_x = width // 2 - change_width // 2
|
change_x = width // 2 - change_width // 2
|
||||||
change_y = price_y + price_height + 1 # Reduced from 2 to 1 pixel spacing
|
change_y = price_y + price_height + 1 # 1 pixel spacing
|
||||||
change_color = (0, 255, 0) if change >= 0 else (255, 0, 0)
|
change_color = (0, 255, 0) if change >= 0 else (255, 0, 0)
|
||||||
draw.text((change_x, change_y), change_text, font=small_font, fill=change_color)
|
draw.text((change_x, change_y), change_text, font=small_font, fill=change_color)
|
||||||
|
|
||||||
@@ -580,9 +580,9 @@ class StockManager:
|
|||||||
chart_data = [p['price'] for p in price_history]
|
chart_data = [p['price'] for p in price_history]
|
||||||
|
|
||||||
# Calculate chart dimensions
|
# Calculate chart dimensions
|
||||||
chart_width = width // 4
|
chart_width = width // 3 # Increased from width//4 to width//3
|
||||||
chart_height = height // 2
|
chart_height = height // 1.5 # Increased from height//2 to height//1.5
|
||||||
chart_x = width - chart_width - 10 # 10 pixels from right edge
|
chart_x = width - chart_width - 5 # 5 pixels from right edge
|
||||||
chart_y = (height - chart_height) // 2
|
chart_y = (height - chart_height) // 2
|
||||||
|
|
||||||
# Find min and max prices for scaling
|
# Find min and max prices for scaling
|
||||||
@@ -596,10 +596,6 @@ class StockManager:
|
|||||||
max_price += 0.01
|
max_price += 0.01
|
||||||
price_range = 0.02
|
price_range = 0.02
|
||||||
|
|
||||||
# Draw chart background
|
|
||||||
draw.rectangle([chart_x, chart_y, chart_x + chart_width, chart_y + chart_height],
|
|
||||||
outline=(50, 50, 50))
|
|
||||||
|
|
||||||
# Calculate points for the line
|
# Calculate points for the line
|
||||||
points = []
|
points = []
|
||||||
for i, price in enumerate(chart_data):
|
for i, price in enumerate(chart_data):
|
||||||
@@ -704,15 +700,16 @@ class StockManager:
|
|||||||
height = self.display_manager.matrix.height
|
height = self.display_manager.matrix.height
|
||||||
|
|
||||||
# Calculate total width needed for all stocks
|
# Calculate total width needed for all stocks
|
||||||
# Each stock needs width*2 for scrolling, plus a larger gap between stocks
|
# Each stock needs width*2 for scrolling, plus consistent gaps between elements
|
||||||
gap = width // 2 # Increased from width//4 to width//2 for more space between stocks
|
stock_gap = width // 3 # Gap between stocks
|
||||||
total_width = sum(width * 2 for _ in symbols) + gap * (len(symbols) - 1)
|
element_gap = width // 6 # Gap between elements within a stock
|
||||||
|
total_width = sum(width * 2 for _ in symbols) + stock_gap * (len(symbols) - 1) + element_gap * (len(symbols) * 2 - 1)
|
||||||
|
|
||||||
# Create the full image
|
# Create the full image
|
||||||
full_image = Image.new('RGB', (total_width, height), (0, 0, 0))
|
full_image = Image.new('RGB', (total_width, height), (0, 0, 0))
|
||||||
draw = ImageDraw.Draw(full_image)
|
draw = ImageDraw.Draw(full_image)
|
||||||
|
|
||||||
# Draw each stock in sequence
|
# Draw each stock in sequence with consistent spacing
|
||||||
current_x = 0
|
current_x = 0
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
data = self.stock_data[symbol]
|
data = self.stock_data[symbol]
|
||||||
@@ -723,8 +720,12 @@ class StockManager:
|
|||||||
# Paste this stock image into the full image
|
# Paste this stock image into the full image
|
||||||
full_image.paste(stock_image, (current_x, 0))
|
full_image.paste(stock_image, (current_x, 0))
|
||||||
|
|
||||||
# Move to next position
|
# Move to next position with consistent spacing
|
||||||
current_x += width * 2 + gap
|
current_x += width * 2 + element_gap
|
||||||
|
|
||||||
|
# Add extra gap between stocks
|
||||||
|
if symbol != symbols[-1]: # Don't add gap after the last stock
|
||||||
|
current_x += stock_gap
|
||||||
|
|
||||||
# Cache the full image
|
# Cache the full image
|
||||||
self.cached_text_image = full_image
|
self.cached_text_image = full_image
|
||||||
|
|||||||
Reference in New Issue
Block a user