Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions plots/scatter-annotated/implementations/highcharts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
""" pyplots.ai
scatter-annotated: Annotated Scatter Plot with Text Labels
Library: highcharts unknown | Python 3.13.11
Quality: 91/100 | Created: 2025-12-30
"""

import json
import tempfile
import time
import urllib.request
from pathlib import Path

import numpy as np
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


# Data - Tech companies with market metrics
np.random.seed(42)
companies = [
"TechCorp",
"DataFlow",
"CloudNet",
"ByteWorks",
"NeuralSys",
"QuantumIO",
"CyberEdge",
"AlphaCore",
"OmniSoft",
"GridLogic",
"NovaCode",
"SyncLabs",
"PrimeData",
"VectorAI",
"CoreStack",
]
revenue = np.random.uniform(50, 500, 15) # Revenue in millions
growth = revenue * 0.12 + np.random.normal(0, 15, 15) # Growth rate %

# Create data points with names (labels)
data_points = [
{"x": round(float(revenue[i]), 1), "y": round(float(growth[i]), 1), "name": companies[i]}
for i in range(len(companies))
]

# Build Highcharts configuration
chart_config = {
"chart": {
"type": "scatter",
"width": 4800,
"height": 2700,
"backgroundColor": "#ffffff",
"marginBottom": 280,
"marginTop": 120,
"marginLeft": 220,
"marginRight": 200,
},
"title": {
"text": "scatter-annotated · highcharts · pyplots.ai",
"style": {"fontSize": "48px", "fontWeight": "bold"},
},
"xAxis": {
"title": {
"text": "Annual Revenue ($ millions)",
"style": {"fontSize": "36px", "color": "#333333"},
"margin": 30,
},
"labels": {"style": {"fontSize": "28px"}, "y": 40},
"gridLineWidth": 1,
"gridLineColor": "rgba(0, 0, 0, 0.15)",
"min": 0,
"max": 550,
"tickInterval": 100,
},
"yAxis": {
"title": {"text": "Year-over-Year Growth (%)", "style": {"fontSize": "36px", "color": "#333333"}, "margin": 20},
"labels": {"style": {"fontSize": "28px"}},
"gridLineWidth": 1,
"gridLineColor": "rgba(0, 0, 0, 0.15)",
},
"legend": {"enabled": False},
"credits": {"enabled": False},
"plotOptions": {
"scatter": {
"marker": {"radius": 20, "fillColor": "rgba(48, 105, 152, 0.7)"},
"dataLabels": {
"enabled": True,
"format": "{point.name}",
"style": {"fontSize": "26px", "fontWeight": "500", "textOutline": "3px white", "color": "#333333"},
"y": -30,
"allowOverlap": False,
},
}
},
"series": [{"type": "scatter", "name": "Companies", "color": "#306998", "data": data_points}],
}

# Download Highcharts JS for inline embedding
highcharts_url = "https://code.highcharts.com/highcharts.js"
with urllib.request.urlopen(highcharts_url, timeout=30) as response:
highcharts_js = response.read().decode("utf-8")

# Generate HTML with inline scripts
chart_json = json.dumps(chart_config)
html_content = f"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>{highcharts_js}</script>
</head>
<body style="margin:0;">
<div id="container" style="width: 4800px; height: 2700px;"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {{
Highcharts.chart('container', {chart_json});
}});
</script>
</body>
</html>"""

# Write temp HTML file
with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False, encoding="utf-8") as f:
f.write(html_content)
temp_path = f.name

# Save interactive HTML
with open("plot.html", "w", encoding="utf-8") as f:
f.write(html_content)

# Setup headless Chrome
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=4800,2700")

# Take screenshot
driver = webdriver.Chrome(options=chrome_options)
driver.get(f"file://{temp_path}")
time.sleep(5)
driver.save_screenshot("plot.png")
driver.quit()

# Cleanup
Path(temp_path).unlink()
29 changes: 29 additions & 0 deletions plots/scatter-annotated/metadata/highcharts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library: highcharts
specification_id: scatter-annotated
created: '2025-12-30T17:58:18Z'
updated: '2025-12-30T18:06:31Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20602455906
issue: 0
python_version: 3.13.11
library_version: unknown
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/highcharts/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/highcharts/plot_thumb.png
preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/highcharts/plot.html
quality_score: 91
review:
strengths:
- 'Excellent use of Highcharts dataLabels with allowOverlap: false to prevent label
collisions'
- Clean, professional appearance with appropriate color choice and transparency
- 'Good text outline (textOutline: 3px white) ensures label readability over grid
lines'
- Realistic tech company business context that demonstrates the annotation use case
well
- Proper title format following spec requirements
weaknesses:
- Uses raw JSON dict configuration instead of highcharts-core Python classes as
shown in library rules
- Grid lines could be slightly more visible (alpha 0.15 is quite faint)
- Some labels could benefit from smart positioning (e.g., labels near axis edges
like DataFlow appear slightly cramped)