|
1 | 1 | """ pyplots.ai |
2 | 2 | bump-basic: Basic Bump Chart |
3 | | -Library: highcharts unknown | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-23 |
| 3 | +Library: highcharts 1.10.3 | Python 3.14.3 |
| 4 | +Quality: 91/100 | Updated: 2026-02-22 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import tempfile |
|
11 | 11 |
|
12 | 12 | from highcharts_core.chart import Chart |
13 | 13 | from highcharts_core.options import HighchartsOptions |
14 | | -from highcharts_core.options.series.area import LineSeries |
| 14 | +from highcharts_core.options.series.spline import SplineSeries |
15 | 15 | from selenium import webdriver |
16 | 16 | from selenium.webdriver.chrome.options import Options |
17 | 17 |
|
|
21 | 21 | weeks = ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6"] |
22 | 22 |
|
23 | 23 | # Rankings for each team across weeks (1 = best, 6 = worst) |
24 | | -# Designed to show various patterns: overtakes, stability, rise, fall |
| 24 | +# Shows various patterns: overtakes, stability, rise, fall, swaps |
25 | 25 | rankings = { |
26 | | - "Eagles": [3, 2, 1, 1, 2, 1], # Rise to top, brief dip, reclaim |
27 | | - "Wolves": [1, 1, 2, 3, 3, 2], # Start strong, fade then recover |
28 | | - "Tigers": [4, 3, 3, 2, 1, 3], # Steady rise to peak, then drop |
29 | | - "Bears": [2, 4, 4, 4, 4, 4], # Early drop, stabilize mid-table |
30 | | - "Sharks": [5, 5, 5, 5, 5, 5], # Consistently 5th |
31 | | - "Lions": [6, 6, 6, 6, 6, 6], # Consistently last |
| 26 | + "Eagles": [3, 2, 1, 1, 2, 1], |
| 27 | + "Wolves": [1, 1, 2, 3, 3, 2], |
| 28 | + "Tigers": [4, 3, 3, 2, 1, 3], |
| 29 | + "Bears": [2, 4, 5, 4, 4, 4], |
| 30 | + "Sharks": [5, 5, 4, 5, 6, 5], |
| 31 | + "Lions": [6, 6, 6, 6, 5, 6], |
32 | 32 | } |
33 | 33 |
|
34 | | -# Colorblind-safe palette for 6 teams |
35 | | -colors = ["#306998", "#FFD43B", "#9467BD", "#17BECF", "#E377C2", "#8C564B"] |
| 34 | +# Colorblind-safe palette starting with Python Blue |
| 35 | +# Teal replaces red for better perceptual distance from orange under colorblindness |
| 36 | +colors = ["#306998", "#FFD43B", "#9467BD", "#FF7F0E", "#17BECF", "#8C564B"] |
| 37 | + |
| 38 | +# Visual hierarchy: thicker lines for teams with dramatic rank changes |
| 39 | +line_widths = { |
| 40 | + "Eagles": 9, # rises to #1 — protagonist |
| 41 | + "Wolves": 6, |
| 42 | + "Tigers": 9, # dramatic arc #4→#1→#3 |
| 43 | + "Bears": 5, |
| 44 | + "Sharks": 4, # minor fluctuation |
| 45 | + "Lions": 4, # mostly stable at bottom |
| 46 | +} |
| 47 | + |
| 48 | +marker_radii = {"Eagles": 16, "Wolves": 12, "Tigers": 16, "Bears": 10, "Sharks": 9, "Lions": 9} |
36 | 49 |
|
37 | | -# Create chart |
| 50 | +# Chart |
38 | 51 | chart = Chart(container="container") |
39 | 52 | chart.options = HighchartsOptions() |
40 | 53 |
|
41 | | -# Chart configuration |
42 | 54 | chart.options.chart = { |
43 | | - "type": "line", |
| 55 | + "type": "spline", |
44 | 56 | "width": 4800, |
45 | 57 | "height": 2700, |
46 | 58 | "backgroundColor": "#ffffff", |
47 | | - "marginLeft": 250, |
48 | | - "marginRight": 250, |
| 59 | + "marginLeft": 200, |
| 60 | + "marginRight": 260, |
49 | 61 | "marginBottom": 250, |
50 | 62 | "spacingTop": 100, |
| 63 | + "marginTop": 300, |
51 | 64 | } |
52 | 65 |
|
53 | 66 | # Title |
54 | 67 | chart.options.title = { |
55 | | - "text": "bump-basic · highcharts · pyplots.ai", |
| 68 | + "text": "bump-basic \u00b7 highcharts \u00b7 pyplots.ai", |
56 | 69 | "style": {"fontSize": "72px", "fontWeight": "bold"}, |
57 | 70 | } |
58 | 71 |
|
59 | 72 | # Subtitle |
60 | | -chart.options.subtitle = {"text": "League Standings Over Season", "style": {"fontSize": "48px"}} |
| 73 | +chart.options.subtitle = {"text": "League Standings Over Season", "style": {"fontSize": "48px", "color": "#666666"}} |
61 | 74 |
|
62 | | -# X-axis (weeks) |
| 75 | +# X-axis |
63 | 76 | chart.options.x_axis = { |
64 | 77 | "categories": weeks, |
65 | | - "title": {"text": "Match Week", "style": {"fontSize": "48px"}, "margin": 30}, |
66 | | - "labels": {"style": {"fontSize": "36px"}, "y": 50}, |
67 | | - "lineWidth": 2, |
68 | | - "tickWidth": 2, |
69 | | - "gridLineWidth": 1, |
70 | | - "gridLineColor": "#e0e0e0", |
| 78 | + "labels": {"style": {"fontSize": "40px"}}, |
| 79 | + "lineWidth": 0, |
| 80 | + "tickWidth": 0, |
| 81 | + "gridLineWidth": 0, |
71 | 82 | } |
72 | 83 |
|
73 | | -# Y-axis (rankings - inverted so rank 1 is at top) |
| 84 | +# Y-axis (inverted so rank 1 is at top) |
74 | 85 | chart.options.y_axis = { |
75 | | - "title": {"text": "Rank Position", "style": {"fontSize": "48px"}, "margin": 30}, |
76 | | - "labels": {"style": {"fontSize": "36px"}, "x": -15}, |
77 | | - "reversed": True, # Rank 1 at top |
78 | | - "min": 1, |
79 | | - "max": 6, |
| 86 | + "title": {"text": "Rank", "style": {"fontSize": "40px", "color": "#444444"}}, |
| 87 | + "labels": {"style": {"fontSize": "40px"}, "format": "#{value}"}, |
| 88 | + "reversed": True, |
| 89 | + "lineWidth": 0, |
| 90 | + "min": 0.5, |
| 91 | + "max": 6.5, |
80 | 92 | "tickInterval": 1, |
| 93 | + "startOnTick": False, |
| 94 | + "endOnTick": False, |
81 | 95 | "gridLineWidth": 1, |
82 | | - "gridLineDashStyle": "Dash", |
| 96 | + "gridLineDashStyle": "Dot", |
83 | 97 | "gridLineColor": "#e0e0e0", |
| 98 | + "plotBands": [ |
| 99 | + { |
| 100 | + "from": 0.5, |
| 101 | + "to": 1.5, |
| 102 | + "color": "rgba(255, 215, 0, 0.06)", |
| 103 | + "label": { |
| 104 | + "text": "\u2605", |
| 105 | + "align": "left", |
| 106 | + "x": -60, |
| 107 | + "style": {"fontSize": "36px", "color": "rgba(200, 170, 0, 0.35)"}, |
| 108 | + }, |
| 109 | + } |
| 110 | + ], |
84 | 111 | } |
85 | 112 |
|
86 | | -# Legend |
87 | | -chart.options.legend = { |
88 | | - "enabled": True, |
89 | | - "layout": "vertical", |
90 | | - "align": "right", |
91 | | - "verticalAlign": "middle", |
92 | | - "itemStyle": {"fontSize": "36px"}, |
93 | | - "itemMarginBottom": 15, |
94 | | -} |
| 113 | +# Legend disabled — endpoint data labels already identify each team |
| 114 | +chart.options.legend = {"enabled": False} |
| 115 | + |
| 116 | +# Tooltip disabled for static output |
| 117 | +chart.options.tooltip = {"enabled": False} |
| 118 | + |
| 119 | +# Credits off |
| 120 | +chart.options.credits = {"enabled": False} |
95 | 121 |
|
96 | | -# Plot options for line styling - bump charts need clear markers |
97 | | -chart.options.plot_options = {"line": {"lineWidth": 6, "marker": {"enabled": True, "radius": 14, "symbol": "circle"}}} |
| 122 | +# Default plot options for spline |
| 123 | +chart.options.plot_options = {"spline": {"marker": {"enabled": True, "symbol": "circle"}}} |
98 | 124 |
|
99 | | -# Add series for each team |
| 125 | +# Series with data labels at endpoints, key-moment annotations, and visual hierarchy |
100 | 126 | series_list = [] |
101 | 127 | for i, team in enumerate(teams): |
102 | | - series = LineSeries() |
| 128 | + ranks = rankings[team] |
| 129 | + data_points = [] |
| 130 | + for j, rank in enumerate(ranks): |
| 131 | + point = {"y": rank} |
| 132 | + if j == len(ranks) - 1: |
| 133 | + # Data label at end point showing team name |
| 134 | + point["dataLabels"] = { |
| 135 | + "enabled": True, |
| 136 | + "format": "{series.name}", |
| 137 | + "align": "left", |
| 138 | + "verticalAlign": "middle", |
| 139 | + "x": 20, |
| 140 | + "style": {"fontSize": "32px", "fontWeight": "bold", "color": colors[i], "textOutline": "3px white"}, |
| 141 | + } |
| 142 | + elif team == "Eagles" and j == 2: |
| 143 | + # Storytelling: Eagles take #1 at Week 3 |
| 144 | + point["dataLabels"] = { |
| 145 | + "enabled": True, |
| 146 | + "format": "\u2191 Takes lead", |
| 147 | + "align": "center", |
| 148 | + "y": -30, |
| 149 | + "style": {"fontSize": "26px", "fontWeight": "normal", "color": "#555555", "textOutline": "2px white"}, |
| 150 | + } |
| 151 | + elif team == "Tigers" and j == 4: |
| 152 | + # Storytelling: Tigers peak at #1 at Week 5 |
| 153 | + point["dataLabels"] = { |
| 154 | + "enabled": True, |
| 155 | + "format": "\u2191 Peak", |
| 156 | + "align": "center", |
| 157 | + "y": -30, |
| 158 | + "style": {"fontSize": "26px", "fontWeight": "normal", "color": "#555555", "textOutline": "2px white"}, |
| 159 | + } |
| 160 | + data_points.append(point) |
| 161 | + |
| 162 | + series = SplineSeries() |
103 | 163 | series.name = team |
104 | | - series.data = rankings[team] |
| 164 | + series.data = data_points |
105 | 165 | series.color = colors[i] |
| 166 | + series.line_width = line_widths[team] |
| 167 | + series.marker = {"radius": marker_radii[team], "symbol": "circle"} |
106 | 168 | series_list.append(series) |
107 | 169 |
|
108 | 170 | chart.options.series = series_list |
|
126 | 188 | </body> |
127 | 189 | </html>""" |
128 | 190 |
|
129 | | -# Write temp HTML and take screenshot |
130 | 191 | with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False, encoding="utf-8") as f: |
131 | 192 | f.write(html_content) |
132 | 193 | temp_path = f.name |
133 | 194 |
|
134 | | -# Also save as plot.html for interactive version |
| 195 | +# Save interactive version |
135 | 196 | Path("plot.html").write_text(html_content, encoding="utf-8") |
136 | 197 |
|
137 | 198 | chrome_options = Options() |
|
143 | 204 |
|
144 | 205 | driver = webdriver.Chrome(options=chrome_options) |
145 | 206 | driver.get(f"file://{temp_path}") |
146 | | -time.sleep(5) # Wait for chart to render |
| 207 | +time.sleep(5) |
147 | 208 | driver.save_screenshot("plot.png") |
148 | 209 | driver.quit() |
149 | 210 |
|
150 | | -Path(temp_path).unlink() # Clean up temp file |
| 211 | +Path(temp_path).unlink() |
0 commit comments