Skip to content

feat(charts): add TextAlign enum and improve annotation validation#488

Merged
palewire merged 5 commits intochekos:mainfrom
palewire:main
Oct 29, 2025
Merged

feat(charts): add TextAlign enum and improve annotation validation#488
palewire merged 5 commits intochekos:mainfrom
palewire:main

Conversation

@palewire
Copy link
Copy Markdown
Collaborator

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,

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,
@palewire palewire requested a review from Copilot October 28, 2025 23:55
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 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 TextAlign enum 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), and TextAnnotation.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.

Comment thread datawrapper/charts/annos.py
Comment thread datawrapper/charts/annos.py
Comment thread tests/unit/test_text_align_enum.py
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.
@palewire palewire merged commit fc43a5a into chekos:main Oct 29, 2025
9 checks passed
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.

2 participants