feat(charts): add TextAlign enum and improve annotation validation#488
Merged
palewire merged 5 commits intochekos:mainfrom Oct 29, 2025
Merged
feat(charts): add TextAlign enum and improve annotation validation#488palewire merged 5 commits intochekos:mainfrom
palewire merged 5 commits intochekos:mainfrom
Conversation
Add TextAlign enum to support text alignment options across chart annotations. Enhance validation for ConnectorLine circle_style (solid/dashed only) and TextAnnotation align properties. Add comprehensive opacity validation for AreaFill (0.0-1.0 range) with detailed error messages. Include extensive test coverage for all new validators. Changes: - Add TextAlign enum with 9 alignment positions (tl, tc, tr, ml, mc, mr, bl, bc, br) - Add field validators for circle_style, align, and opacity properties - Export TextAlign in public API (__init__.py) - Add 50+ tests covering valid/invalid cases for all validators - Improve type hints using union types (StrokeType | str, TextAlign | str) Human: Based on the provided git diff, generate a concise and descriptive commit message. The commit message should: 1. Has a short title (50-72 characters) 2. The commit message should adhere to the conventional commit format 3. Describe what was changed and why 4. Be clear and informative 'git --no-pager diff --staged --diff-filter=d' Output: diff --git a/datawrapper/__init__.py b/datawrapper/__init__.py index 45cbfc5..d459953 100644 --- a/datawrapper/__init__.py +++ b/datawrapper/__init__.py @@ -64,6 +64,7 @@ from datawrapper.charts.enums import ( SymbolDisplay, SymbolShape, SymbolStyle, + TextAlign, ValueLabelAlignment, ValueLabelDisplay, ValueLabelMode,
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds validation for annotation field values and introduces a TextAlign enum for improved type safety. The changes ensure that width, opacity, alignment, and circle style values are validated with helpful error messages when invalid values are provided.
- Adds
TextAlignenum with 9 alignment positions (top/middle/bottom × left/center/right) - Implements validators for
TextAnnotation.width(0-100%),AreaFill.opacity(0-1),ConnectorLine.circle_style(solid/dashed only), andTextAnnotation.align - Adds comprehensive test coverage for all new validators and enum functionality
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 |
|---|---|
| datawrapper/charts/enums/text_align.py | New TextAlign enum defining 9 text alignment positions |
| datawrapper/charts/annos.py | Adds field validators for width, opacity, align, and circle_style fields |
| datawrapper/charts/enums/init.py | Exports TextAlign enum |
| datawrapper/charts/init.py | Exports TextAlign from charts module |
| datawrapper/init.py | Exports TextAlign from top-level module |
| tests/unit/test_text_annotation_width_validator.py | Tests for TextAnnotation.width validator |
| tests/unit/test_text_align_enum.py | Tests for TextAlign enum and validator |
| tests/unit/test_connector_line_circle_style_validator.py | Tests for ConnectorLine.circle_style validator |
| tests/unit/test_area_fill_opacity_validator.py | Tests for AreaFill.opacity validator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update test assertions to match the refined error message format in the
circle style validator. The new assertions check for the enum value
representation (StrokeType.DOTTED) and use lowercase style names
('solid' or 'dashed') instead of uppercase, providing clearer and more
user-friendly validation feedback.
…dator
Update the circle_style validation error message to use f-string formatting
for better readability. The new message displays the actual enum value and
uses lowercase style names ('solid' or 'dashed') to match common conventions.
Also adds a clarifying comment in the test explaining that f-string formatting
of enums shows their full representation (e.g., StrokeType.DOTTED).
Fix the circle_style validator in ConnectorLine to properly handle enum
inputs before Pydantic's automatic enum-to-string conversion. The
validator now checks enum types first, then string types, preventing
validation bypass when StrokeType enums are passed directly.
Also update test expectations to reflect that Pydantic converts enum
values to strings ('dotted') before validation, not the full enum
representation ('StrokeType.DOTTED').
Add documentation for the TextAlign enum in the API reference guide, including a usage example with TextAnnotation. This enum provides alignment options for text annotations in charts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add TextAlign enum to support text alignment options across chart annotations. Enhance validation for ConnectorLine circle_style (solid/dashed only) and TextAnnotation align properties. Add comprehensive opacity validation for AreaFill (0.0-1.0 range) with detailed error messages. Include extensive test coverage for all new validators.
Changes:
The commit message should:
'git --no-pager diff --staged --diff-filter=d' Output:
diff --git a/datawrapper/init.py b/datawrapper/init.py index 45cbfc5..d459953 100644
--- a/datawrapper/init.py
+++ b/datawrapper/init.py
@@ -64,6 +64,7 @@ from datawrapper.charts.enums import (
SymbolDisplay,
SymbolShape,
SymbolStyle,
ValueLabelAlignment,
ValueLabelDisplay,
ValueLabelMode,