Skip to content

Commit 7b44804

Browse files
feat(pygal): implement line-interactive (#2836)
## Implementation: `line-interactive` - pygal Implements the **pygal** version of `line-interactive`. **File:** `plots/line-interactive/implementations/pygal.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20603328451)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 77e55b3 commit 7b44804

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
""" pyplots.ai
2+
line-interactive: Interactive Line Chart with Hover and Zoom
3+
Library: pygal 3.1.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
import pygal
10+
from pygal.style import Style
11+
12+
13+
# Data - Daily temperature readings for a weather station
14+
np.random.seed(42)
15+
dates = pd.date_range("2024-01-01", periods=365, freq="D")
16+
17+
# Generate realistic temperature pattern with seasonal variation
18+
day_of_year = np.arange(365)
19+
base_temp = 15 + 12 * np.sin(2 * np.pi * (day_of_year - 80) / 365) # Seasonal pattern
20+
noise = np.random.randn(365) * 3 # Daily variation
21+
temperature = base_temp + noise
22+
23+
# Format dates for labels
24+
date_labels = [d.strftime("%b %d") for d in dates]
25+
26+
# Custom style for pyplots
27+
custom_style = Style(
28+
background="white",
29+
plot_background="white",
30+
foreground="#333333",
31+
foreground_strong="#333333",
32+
foreground_subtle="#666666",
33+
colors=("#306998",), # Python Blue
34+
title_font_size=72,
35+
label_font_size=48,
36+
major_label_font_size=42,
37+
legend_font_size=48,
38+
value_font_size=36,
39+
stroke_width=4,
40+
opacity=".9",
41+
opacity_hover=".95",
42+
transition="400ms ease-in",
43+
tooltip_font_size=36,
44+
value_label_font_size=36,
45+
)
46+
47+
# Create interactive line chart
48+
chart = pygal.Line(
49+
width=4800,
50+
height=2700,
51+
style=custom_style,
52+
title="Daily Temperature 2024 · line-interactive · pygal · pyplots.ai",
53+
x_title="Date",
54+
y_title="Temperature (°C)",
55+
show_dots=True,
56+
dots_size=6,
57+
stroke_style={"width": 4, "linecap": "round", "linejoin": "round"},
58+
show_x_guides=False,
59+
show_y_guides=True,
60+
x_label_rotation=45,
61+
truncate_label=12,
62+
show_legend=True,
63+
legend_at_bottom=True,
64+
legend_at_bottom_columns=1,
65+
margin=60,
66+
spacing=40,
67+
x_labels_major_every=30, # Show label every 30 days
68+
show_minor_x_labels=False,
69+
tooltip_border_radius=10,
70+
js=[], # Enable default JS for interactivity
71+
)
72+
73+
# Add x-axis labels (show every 30 days for readability)
74+
chart.x_labels = date_labels
75+
76+
# Add temperature data
77+
chart.add(
78+
"Temperature", [{"value": float(t), "label": f"{date_labels[i]}: {t:.1f}°C"} for i, t in enumerate(temperature)]
79+
)
80+
81+
# Save as PNG and HTML (interactive)
82+
chart.render_to_png("plot.png")
83+
chart.render_to_file("plot.html")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library: pygal
2+
specification_id: line-interactive
3+
created: '2025-12-30T18:38:15Z'
4+
updated: '2025-12-30T18:40:27Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20603328451
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.1.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-interactive/pygal/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-interactive/pygal/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-interactive/pygal/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Clean seasonal temperature pattern with realistic daily variation demonstrates
17+
time series well
18+
- Excellent custom Style configuration with appropriate font sizes for large canvas
19+
- Proper tooltip customization with formatted date and temperature values
20+
- Good axis labeling with units (°C) and descriptive titles
21+
- Smart x-axis label management showing only major labels every 30 days to prevent
22+
clutter
23+
- Outputs both PNG and HTML for static/interactive versions
24+
weaknesses:
25+
- PNG output is inherently static; the interactive features (hover, zoom, pan, range
26+
selection) specified in the spec are only available in the HTML output - this
27+
is a limitation of the PNG format, not a code issue
28+
- Single data series limits feature demonstration; could show multiple locations
29+
or metrics for comparison

0 commit comments

Comments
 (0)