Skip to content

Commit 897991c

Browse files
feat(highcharts): implement scatter-basic (#503)
## Summary Implements `scatter-basic` for **highcharts** library. **Parent Issue:** #207 **Sub-Issue:** #491 **Base Branch:** `plot/scatter-basic` **Attempt:** 1/3 ## Implementation - `plots/highcharts/scatter/scatter-basic/default.py` ## Changes - Uses spec example data (8 data points) for the scatter plot - Screenshots the chart container element directly for exact 4800x2700 dimensions - Removed PIL dependency by using Selenium element screenshot - Adjusted font sizes for better readability at high resolution (60px title, 48px axis labels, 40px tick labels) - Uses Python Blue (#306998) color from the style guide Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent 54689e5 commit 897991c

1 file changed

Lines changed: 17 additions & 33 deletions

File tree

plots/highcharts/scatter/scatter-basic/default.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,49 @@
88
import urllib.request
99
from pathlib import Path
1010

11-
import numpy as np
1211
from highcharts_core.chart import Chart
1312
from highcharts_core.options import HighchartsOptions
1413
from highcharts_core.options.series.scatter import ScatterSeries
15-
from PIL import Image
1614
from selenium import webdriver
1715
from selenium.webdriver.chrome.options import Options
1816

1917

2018
# Data
21-
np.random.seed(42)
22-
x = np.random.randn(100) * 2 + 10
23-
y = x * 0.8 + np.random.randn(100) * 2
19+
x = [1, 2, 3, 4, 5, 6, 7, 8]
20+
y = [2.1, 4.3, 3.2, 5.8, 4.9, 7.2, 6.1, 8.5]
2421

25-
# Create chart
22+
# Create chart with container
2623
chart = Chart(container="container")
2724
chart.options = HighchartsOptions()
2825

2926
# Chart configuration
30-
chart.options.chart = {
31-
"type": "scatter",
32-
"width": 4800,
33-
"height": 2700,
34-
"backgroundColor": "#ffffff",
35-
"spacing": [20, 20, 60, 20],
36-
}
27+
chart.options.chart = {"type": "scatter", "width": 4800, "height": 2700, "backgroundColor": "#ffffff"}
3728

3829
# Title
39-
chart.options.title = {"text": "Basic Scatter Plot", "style": {"fontSize": "48px"}}
30+
chart.options.title = {"text": "Basic Scatter Plot", "style": {"fontSize": "60px"}}
4031

4132
# Axes
4233
chart.options.x_axis = {
43-
"title": {"text": "X Value", "style": {"fontSize": "40px"}},
44-
"labels": {"style": {"fontSize": "32px"}},
34+
"title": {"text": "X Value", "style": {"fontSize": "48px"}},
35+
"labels": {"style": {"fontSize": "40px"}},
4536
"gridLineWidth": 1,
4637
"gridLineColor": "rgba(0, 0, 0, 0.1)",
4738
}
4839
chart.options.y_axis = {
49-
"title": {"text": "Y Value", "style": {"fontSize": "40px"}},
50-
"labels": {"style": {"fontSize": "32px"}},
40+
"title": {"text": "Y Value", "style": {"fontSize": "48px"}},
41+
"labels": {"style": {"fontSize": "40px"}},
5142
"gridLineWidth": 1,
5243
"gridLineColor": "rgba(0, 0, 0, 0.1)",
5344
}
5445

55-
# Legend (not needed for single series but show it for clarity)
46+
# Legend (not needed for single series, but kept minimal)
5647
chart.options.legend = {"enabled": False}
5748

58-
# Series
49+
# Add series
5950
series = ScatterSeries()
60-
series.data = [[float(xi), float(yi)] for xi, yi in zip(x, y, strict=True)]
51+
series.data = list(zip(x, y, strict=False))
6152
series.name = "Data"
62-
series.color = "#306998"
63-
series.marker = {"radius": 8, "fillColor": "#306998", "lineWidth": 0, "states": {"hover": {"enabled": True}}}
64-
53+
series.marker = {"radius": 20, "fillColor": "#306998", "lineWidth": 2, "lineColor": "#306998"}
6554
chart.add_series(series)
6655

6756
# Download Highcharts JS for inline embedding
@@ -93,20 +82,15 @@
9382
chrome_options.add_argument("--no-sandbox")
9483
chrome_options.add_argument("--disable-dev-shm-usage")
9584
chrome_options.add_argument("--disable-gpu")
96-
chrome_options.add_argument("--window-size=4900,2800")
85+
chrome_options.add_argument("--window-size=5000,3000")
9786

9887
driver = webdriver.Chrome(options=chrome_options)
9988
driver.get(f"file://{temp_path}")
10089
time.sleep(5)
10190

102-
# Screenshot the full window and crop to exact dimensions
103-
driver.save_screenshot("plot_raw.png")
91+
# Screenshot the chart container element for exact dimensions
92+
container = driver.find_element("id", "container")
93+
container.screenshot("plot.png")
10494
driver.quit()
10595

106-
# Crop to exact dimensions (4800 x 2700)
107-
with Image.open("plot_raw.png") as img:
108-
cropped = img.crop((0, 0, 4800, 2700))
109-
cropped.save("plot.png")
110-
Path("plot_raw.png").unlink()
111-
11296
Path(temp_path).unlink()

0 commit comments

Comments
 (0)