|
| 1 | +""" pyplots.ai |
| 2 | +venn-basic: Venn Diagram |
| 3 | +Library: highcharts unknown | Python 3.13.11 |
| 4 | +Quality: 91/100 | Created: 2025-12-29 |
| 5 | +""" |
| 6 | + |
| 7 | +import tempfile |
| 8 | +import time |
| 9 | +import urllib.request |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +from highcharts_core.chart import Chart |
| 13 | +from highcharts_core.options import HighchartsOptions |
| 14 | +from highcharts_core.options.series.venn import VennSeries |
| 15 | +from selenium import webdriver |
| 16 | +from selenium.webdriver.chrome.options import Options |
| 17 | + |
| 18 | + |
| 19 | +# Download Highcharts JS and Venn module (required for headless Chrome) |
| 20 | +highcharts_url = "https://code.highcharts.com/highcharts.js" |
| 21 | +with urllib.request.urlopen(highcharts_url, timeout=30) as response: |
| 22 | + highcharts_js = response.read().decode("utf-8") |
| 23 | + |
| 24 | +venn_url = "https://code.highcharts.com/modules/venn.js" |
| 25 | +with urllib.request.urlopen(venn_url, timeout=30) as response: |
| 26 | + venn_js = response.read().decode("utf-8") |
| 27 | + |
| 28 | +# Data: Three programming skill sets with realistic overlaps |
| 29 | +# Set A: Backend developers (100), Set B: Frontend developers (80), Set C: DevOps engineers (60) |
| 30 | +venn_data = [ |
| 31 | + {"sets": ["Backend"], "value": 100}, |
| 32 | + {"sets": ["Frontend"], "value": 80}, |
| 33 | + {"sets": ["DevOps"], "value": 60}, |
| 34 | + {"sets": ["Backend", "Frontend"], "value": 30}, |
| 35 | + {"sets": ["Backend", "DevOps"], "value": 20}, |
| 36 | + {"sets": ["Frontend", "DevOps"], "value": 15}, |
| 37 | + {"sets": ["Backend", "Frontend", "DevOps"], "value": 10}, |
| 38 | +] |
| 39 | + |
| 40 | +# Create chart |
| 41 | +chart = Chart(container="container") |
| 42 | +chart.options = HighchartsOptions() |
| 43 | + |
| 44 | +# Chart settings |
| 45 | +chart.options.chart = {"type": "venn", "width": 4800, "height": 2700, "backgroundColor": "#ffffff"} |
| 46 | + |
| 47 | +# Title |
| 48 | +chart.options.title = { |
| 49 | + "text": "venn-basic \u00b7 highcharts \u00b7 pyplots.ai", |
| 50 | + "style": {"fontSize": "48px", "fontWeight": "bold"}, |
| 51 | +} |
| 52 | + |
| 53 | +# Subtitle |
| 54 | +chart.options.subtitle = {"text": "Developer Skill Distribution (Team of 150)", "style": {"fontSize": "32px"}} |
| 55 | + |
| 56 | +# Create Venn series |
| 57 | +series = VennSeries() |
| 58 | +series.data = venn_data |
| 59 | +series.name = "Team Skills" |
| 60 | + |
| 61 | +# Series styling |
| 62 | +series.data_labels = { |
| 63 | + "enabled": True, |
| 64 | + "style": {"fontSize": "28px", "fontWeight": "normal", "textOutline": "none"}, |
| 65 | + "format": "{point.name}: {point.value}", |
| 66 | +} |
| 67 | + |
| 68 | +# Colors: Python Blue, Python Yellow, and a complementary purple |
| 69 | +chart.options.colors = ["#306998", "#FFD43B", "#9467BD"] |
| 70 | + |
| 71 | +chart.add_series(series) |
| 72 | + |
| 73 | +# Legend |
| 74 | +chart.options.legend = {"enabled": True, "itemStyle": {"fontSize": "24px"}} |
| 75 | + |
| 76 | +# Accessibility |
| 77 | +chart.options.accessibility = {"enabled": False} |
| 78 | + |
| 79 | +# Generate HTML with inline scripts |
| 80 | +html_str = chart.to_js_literal() |
| 81 | +html_content = f"""<!DOCTYPE html> |
| 82 | +<html> |
| 83 | +<head> |
| 84 | + <meta charset="utf-8"> |
| 85 | + <script>{highcharts_js}</script> |
| 86 | + <script>{venn_js}</script> |
| 87 | +</head> |
| 88 | +<body style="margin:0;"> |
| 89 | + <div id="container" style="width: 4800px; height: 2700px;"></div> |
| 90 | + <script>{html_str}</script> |
| 91 | +</body> |
| 92 | +</html>""" |
| 93 | + |
| 94 | +# Write temp HTML and take screenshot |
| 95 | +with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False, encoding="utf-8") as f: |
| 96 | + f.write(html_content) |
| 97 | + temp_path = f.name |
| 98 | + |
| 99 | +chrome_options = Options() |
| 100 | +chrome_options.add_argument("--headless") |
| 101 | +chrome_options.add_argument("--no-sandbox") |
| 102 | +chrome_options.add_argument("--disable-dev-shm-usage") |
| 103 | +chrome_options.add_argument("--disable-gpu") |
| 104 | +chrome_options.add_argument("--window-size=4800,2700") |
| 105 | + |
| 106 | +driver = webdriver.Chrome(options=chrome_options) |
| 107 | +driver.get(f"file://{temp_path}") |
| 108 | +time.sleep(5) |
| 109 | +driver.save_screenshot("plot.png") |
| 110 | +driver.quit() |
| 111 | + |
| 112 | +Path(temp_path).unlink() |
| 113 | + |
| 114 | +# Also save HTML for interactive version |
| 115 | +with open("plot.html", "w", encoding="utf-8") as f: |
| 116 | + # Use CDN for the HTML file (works in browsers) |
| 117 | + interactive_html = f"""<!DOCTYPE html> |
| 118 | +<html> |
| 119 | +<head> |
| 120 | + <meta charset="utf-8"> |
| 121 | + <title>venn-basic - highcharts - pyplots.ai</title> |
| 122 | + <script src="https://code.highcharts.com/highcharts.js"></script> |
| 123 | + <script src="https://code.highcharts.com/modules/venn.js"></script> |
| 124 | +</head> |
| 125 | +<body style="margin:0;"> |
| 126 | + <div id="container" style="width: 100%; height: 100vh;"></div> |
| 127 | + <script>{html_str}</script> |
| 128 | +</body> |
| 129 | +</html>""" |
| 130 | + f.write(interactive_html) |
0 commit comments