feat(charts): auto-enable mixed colors when color_negative is set#474
Merged
palewire merged 2 commits intochekos:mainfrom Oct 21, 2025
Merged
feat(charts): auto-enable mixed colors when color_negative is set#474palewire merged 2 commits intochekos:mainfrom
palewire merged 2 commits intochekos:mainfrom
Conversation
Add model validator to AreaFill that automatically enables use_mixed_colors when a non-default color_negative value is provided. This improves UX by eliminating the need for users to manually enable the flag when they want to use negative colors, making the feature work as expected out of the box. The validator only triggers when color_negative differs from the default "#cc0000" and use_mixed_colors is currently False. For chekos#459
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR automatically enables the use_mixed_colors flag when users provide a custom color_negative value in the AreaFill class, improving user experience by eliminating manual configuration steps.
Key Changes:
- Added a model validator to automatically set
use_mixed_colors=Truewhen a non-defaultcolor_negativeis provided - Imported
model_validatorfrom pydantic to support this functionality
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Update AreaFill model to accept both hex strings and palette indices for color fields. Changes include: - Allow `color` field to accept int (palette index) or str (hex color) - Change default `color` from "#15607a" to 0 (first palette color) - Allow `color_negative` to accept int, str, or None - Change default `color_negative` from "#cc0000" to None (disabled) - Update auto-enable logic to check for None instead of default hex value - Only serialize `colorNegative` when explicitly set (not None) - Update field descriptions to reflect new behavior This provides more flexibility for users to reference theme palette colors by index while maintaining backward compatibility with hex color strings.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
datawrapper/charts/annos.py:1
- Changing the default from
\"#cc0000\"toNoneis a breaking change. Existing code that relied on the implicit red color for negative values will now get no negative color unless explicitly set. This contradicts the PR description which states the validator 'only triggers when color_negative differs from the default "#cc0000"', but that default no longer exists.
from typing import Any, Literal
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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 model validator to AreaFill that automatically enables use_mixed_colors when a non-default color_negative value is provided. This improves UX by eliminating the need for users to manually enable the flag when they want to use negative colors, making the feature work as expected out of the box.
The validator only triggers when color_negative differs from the default "#cc0000" and use_mixed_colors is currently False.
For #459