Skip to content

feat: add pie-basic implementation (8 libraries)#159

Merged
MarkusNeusinger merged 9 commits intomainfrom
plot/pie-basic
Dec 3, 2025
Merged

feat: add pie-basic implementation (8 libraries)#159
MarkusNeusinger merged 9 commits intomainfrom
plot/pie-basic

Conversation

@MarkusNeusinger
Copy link
Copy Markdown
Owner

Summary

Adds pie-basic plot implementation across all 8 libraries.

Libraries Implemented

  • matplotlib
  • seaborn
  • plotly
  • bokeh
  • altair
  • plotnine
  • pygal
  • highcharts

Files

  • Spec: specs/pie-basic.md
  • Implementations: plots/{library}/pie/pie-basic/default.py

Parent Issue

Closes #142


🤖 Manually triggered after workflow E2E test

github-actions Bot and others added 9 commits December 3, 2025 22:17
## Summary
Implements `pie-basic` for **pygal** library.

**Parent Issue:** #142
**Sub-Issue:** #149
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/pygal/pie/pie-basic/default.py`

## Features
- Visualizes proportions of categorical data as colored pie slices
- Supports custom colors with PyPlots.ai palette as default
- Legend with configurable position (right, bottom, top)
- Inner radius parameter for donut chart variant
- Percentage labels displayed on each slice
- Input validation for empty data, missing columns, and negative values

## Quality Checklist
- [x] Type hints on all parameters and return type
- [x] Google-style docstring with Args, Returns, Raises, Example
- [x] Input validation for empty data and missing columns
- [x] Non-negative value validation
- [x] Colorblind-friendly palette (PyPlots.ai colors)
- [x] Tested and generates plot.png successfully
- [x] Code formatted with ruff

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **seaborn** library.

- Uses matplotlib's pie chart with seaborn styling context (seaborn has
no native pie function)
- Applies PyPlots.ai color palette with fallback for many categories
- Includes all optional parameters from spec (colors, explode, shadow,
legend, etc.)

**Parent Issue:** #142
**Sub-Issue:** #144
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/seaborn/pie/pie-basic/default.py`

## Notes
Seaborn does not have a native pie chart function. This implementation
uses `matplotlib.pyplot.pie()` within a seaborn styling context
(`sns.set_theme()`) to maintain consistent aesthetics with other seaborn
visualizations in the project.

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **plotly** library.

- Implements basic pie chart using Plotly's `go.Pie` trace
- Uses PyPlots.ai color palette for consistent visual identity
- Supports all optional parameters from spec (colors, explode, legend,
startangle, etc.)

**Parent Issue:** #142
**Sub-Issue:** #145
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/plotly/pie/pie-basic/default.py`

## Features
- Input validation for empty data, missing columns, and negative values
- Customizable percentage label formatting via autopct parameter
- Legend positioning with matplotlib-to-Plotly location mapping
- Circular aspect ratio enforcement for proper visualization
- Interactive hover tooltips showing label, value, and percentage
- Configurable slice explosion for emphasis
- White slice borders for clear visual separation

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **altair** library.

**Parent Issue:** #142
**Sub-Issue:** #147
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/altair/arc/pie-basic/default.py`

## Features
- Basic pie chart using Altair's `mark_arc()` 
- Percentage labels on slices with configurable format
- PyPlots.ai default color palette (#306998, #FFD43B, #DC2626, #059669,
#8B5CF6, #F97316)
- Legend with configurable position (right, left, top, bottom)
- Support for donut style via `inner_radius` parameter
- Configurable start angle (default: 90° - starts from 12 o'clock)
- Tooltips showing category and value
- Input validation for:
  - Empty data
  - Missing columns
  - Negative values
  - Zero sum values

## Code Quality
- Type hints on all parameters and return type
- Google-style docstring with Args, Returns, Raises, Example
- Follows PyPlots.ai style guide (colors, fonts, dimensions)

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **bokeh** library.

**Parent Issue:** #142
**Sub-Issue:** #146
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/bokeh/custom/pie-basic/default.py`

## Details
Bokeh does not have a native pie chart method, so this implementation
uses `wedge` glyphs to construct the pie chart manually. The
implementation:

- Uses wedge glyphs to draw pie slices with proper angles
- Includes percentage labels positioned inside slices (for slices >= 5%)
- Provides interactive tooltips showing category, value, and percentage
- Supports customizable colors (defaults to PyPlots style palette)
- Includes a configurable legend
- Validates input data (empty data, missing columns, non-negative
values)
- Follows PyPlots.ai style guide (colors, dimensions, typography)
- Falls back to HTML export when selenium is not available for PNG
export

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **highcharts** library.

**Parent Issue:** #142
**Sub-Issue:** #150
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/highcharts/pie/pie-basic/default.py`

## Features
- Basic pie chart with proportional slices
- PyPlots style guide colors (Python Blue, Yellow, Red, etc.)
- All optional parameters from spec:
  - `colors`: Custom color palette
  - `startangle`: Starting angle for first slice
  - `explode`: Offset distances for each slice
  - `shadow`: 3D shadow effect
  - `legend`: Toggle legend display
  - `legend_loc`: Legend positioning
  - `autopct`: Percentage label format
- Proper input validation (empty data, missing columns, negative values,
zero sum)
- Google-style docstrings with type hints
- PNG export via Selenium headless Chrome

## Testing
- Tested with sample data from spec
- Verified plot.png output (1600x761 PNG)
- Passed ruff formatting and linting

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **matplotlib** library.

**Parent Issue:** #142
**Sub-Issue:** #143
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/matplotlib/pie/pie-basic/default.py`

## Features
- Creates basic pie charts with customizable colors, labels, and legend
- Uses PyPlots.ai color palette by default (colorblind-friendly)
- Supports percentage labels with configurable format
- Includes input validation for empty data, missing columns, negative
values, and zero sums
- Equal aspect ratio ensures circular shape
- Full type hints and Google-style docstrings
- Follows all style guide requirements (font sizes, legend styling,
etc.)

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
## Summary
Implements `pie-basic` for **plotnine** library.

**Parent Issue:** #142
**Sub-Issue:** #148
**Base Branch:** `plot/pie-basic`
**Attempt:** 1/3

## Implementation
- `plots/plotnine/pie/pie-basic/default.py`

## Notes
- plotnine (ggplot2 for Python) does not support `coord_polar()` as of
version 0.15.x
- This implementation uses matplotlib directly (plotnine's underlying
rendering engine) while maintaining a compatible interface
- All spec parameters are supported: colors, startangle, autopct,
explode, shadow, labels, legend
- Uses PyPlots.ai color palette by default
- Full input validation for empty data, missing columns, and negative
values

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 3, 2025 22:30
@MarkusNeusinger MarkusNeusinger enabled auto-merge (squash) December 3, 2025 22:30
@MarkusNeusinger MarkusNeusinger merged commit 68df8d2 into main Dec 3, 2025
10 checks passed
@MarkusNeusinger MarkusNeusinger deleted the plot/pie-basic branch December 3, 2025 22:31
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 3, 2025

✅ Plot Tests Passed

Created with Python 3.14

Compatibility: 3.11 3.12 3.13

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the pie-basic specification across all 8 supported plotting libraries, following the project's specification-first design pattern. Each implementation creates a circular pie chart that visualizes categorical data proportions with customizable parameters including colors, labels, legends, and styling options.

Key Changes:

  • New specification file defining pie chart requirements, parameters, and quality criteria
  • 8 library-specific implementations with consistent API signatures and validation
  • Proper handling of edge cases (negative values, zero sums, missing columns)

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
specs/pie-basic.md Comprehensive specification defining data requirements, optional parameters, quality criteria, and implementation notes for basic pie charts
plots/matplotlib/pie/pie-basic/default.py Native matplotlib pie chart implementation using ax.pie() with PyPlots color palette and styling
plots/seaborn/pie/pie-basic/default.py Matplotlib-based implementation with seaborn styling context for aesthetic consistency
plots/plotly/pie/pie-basic/default.py Interactive Plotly pie chart with hover tooltips, customizable colors, and responsive legend positioning
plots/bokeh/custom/pie-basic/default.py Manual wedge-based implementation (bokeh lacks native pie charts) with percentage labels and legend support
plots/altair/arc/pie-basic/default.py Declarative arc mark implementation with customizable inner/outer radius for donut variants
plots/plotnine/pie/pie-basic/default.py Matplotlib-based fallback (plotnine lacks coord_polar) maintaining compatible API interface
plots/pygal/pie/pie-basic/default.py SVG-based implementation with percentage formatting and custom style configuration
plots/highcharts/pie/pie-basic/default.py Enterprise-ready implementation with Selenium-based PNG export and comprehensive configuration options

raise ValueError("Sum of values cannot be zero")

# Set seaborn style context for consistent aesthetics
sns.set_theme(style="white")
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seaborn theme is set globally via sns.set_theme() but never reset. This could affect other plots created afterward in the same process. Consider resetting the theme after creating the plot (e.g., sns.reset_defaults() or sns.set_theme() with default parameters) to avoid side effects, similar to how plots/seaborn/scatterplot/scatter-basic/default.py resets the style with sns.set_style("ticks").

Copilot uses AI. Check for mistakes.
data: pd.DataFrame,
category: str,
value: str,
figsize: tuple[int, int] = (10, 8),
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The figsize parameter is declared but never used in the function body. According to the docstring it's "legacy" in favor of width and height, but it should either be removed or actually utilized. Unused parameters can confuse users about which parameter to use. Consider removing it entirely or documenting it as deprecated.

Copilot uses AI. Check for mistakes.
# Calculate the starting angle in radians (Altair uses radians, offset from 12 o'clock)
# Altair's theta starts from 3 o'clock (0 degrees), so we need to adjust
# To start from 12 o'clock (90 degrees from 3 o'clock), we use theta2Offset
start_offset = (startangle - 90) * 3.14159 / 180
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded value 3.14159 should use math.pi for better precision and clarity. Import math and use math.pi instead of the magic number.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Basic pie chart for proportions [pie-basic]

2 participants