Add Layer and Rectangle components to Recharts#6729
Conversation
Wrap the Recharts Layer (SVG <g> grouping) and Rectangle (SVG shape) components, which are used as building blocks for constructing custom node elements. Exposed as rx.recharts.layer and rx.recharts.rectangle. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XqtAPUo84EBNq6c8Ext3mC
Greptile SummaryThis PR adds Recharts wrappers for custom SVG node construction. The main changes are:
Confidence Score: 5/5This looks safe to merge after a small API-doc cleanup.
packages/reflex-components-recharts/src/reflex_components_recharts/general.py Important Files Changed
Reviews (1): Last reviewed commit: "feat(recharts): add Layer and Rectangle ..." | Re-trigger Greptile |
| is_animation_active: Var[bool] = field( | ||
| doc="If set false, animation of the rectangle will be disabled. Default: False" | ||
| ) |
There was a problem hiding this comment.
Animation Default Is Misstated
When is_animation_active is omitted, this wrapper does not emit isAnimationActive, so Recharts applies its own runtime default. The generated API docs currently say the default is False, which can lead callers to leave the prop unset and still see rectangle animations.
| is_animation_active: Var[bool] = field( | |
| doc="If set false, animation of the rectangle will be disabled. Default: False" | |
| ) | |
| is_animation_active: Var[bool] = field( | |
| doc="If set false, animation of the rectangle will be disabled." | |
| ) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Keeping the Default: False here β it's accurate. Unlike Bar/Area/Line (whose isAnimationActive defaults to true), the Rectangle shape defaults it to false in recharts 3.8.1:
// src/shape/Rectangle.tsx
export const defaultRectangleProps = {
...
isAnimationActive: false,
isUpdateAnimationActive: false,
...
} as const satisfies Partial<Props>;So when the prop is omitted, recharts applies false (no animation), which is exactly what the docstring states. The other animation defaults (is_update_animation_active: False, animation_begin: 0, animation_duration: 1500, animation_easing: "ease") come from the same object and are documented to match.
Generated by Claude Code
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a5ebe831e
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) | ||
|
|
||
|
|
||
| class Layer(Recharts): |
There was a problem hiding this comment.
Forward Layer SVG attributes instead of wrapperStyle
When users use Layer to build custom SVG nodes and pass common group attributes such as transform or style, those names are not declared on the wrapper, so Reflex treats them as style entries and this subclass then inherits Recharts._get_style, which serializes them as wrapperStyle. Recharts Layer expects normal SVG attributes on its <g> element, not wrapperStyle, so translated/styled custom node groups are silently rendered without those attributes.
Useful? React with πΒ / π.
There was a problem hiding this comment.
Good catch, and accurate β an undeclared kwarg (or style=) folds into self.style, which Recharts._get_style emits as wrapperStyle, and recharts drops that on the bare <g>/<path>. Note this is the shared behavior of every recharts SVG-element wrapper (e.g. Cell), not something specific to these two, so I've kept it consistent here rather than diverging from the base _get_style convention in this PR.
For the custom-node use case the practical paths are:
- declared props β
x/y/width/height/fill/stroke/β¦ all serialize correctly; class_nameβ merged onto the<g>/recharts-layergroup;custom_attrs={"transform": "translate(β¦)"}β raw SVG attributes pass straight through to the element.
Forwarding style to the SVG element for the whole recharts package (or just these primitives) is a reasonable follow-up, but it's a convention change I'd rather make deliberately across the package than one-off here.
Generated by Claude Code
Type of change
New Feature Submission
This PR adds two new Recharts components to support constructing custom node elements:
Layer: A wrapper around the RechartsLayercomponent that renders an SVG<g>element for grouping other SVG elements.Rectangle: A shape component for rendering rectangles with full support for positioning, sizing, styling, and animation properties.Changes
packages/reflex-components-recharts/src/reflex_components_recharts/general.py:Layerclass with tag"Layer"and alias"RechartsLayer"Rectangleclass with comprehensive properties:x,ywidth,height,radiusfill,fill_opacity,stroke,stroke_widthis_animation_active,is_update_animation_active,animation_begin,animation_duration,animation_easinglayerandrectanglefactory functionspackages/reflex-components-recharts/src/reflex_components_recharts/__init__.py:Layer,layer,Rectangle, andrectangleto the public APItests/units/components/recharts/test_general.py(new file):LayerrenderingLayerwith children (nestingRectangle)RectanglerenderingRectanglewith all supported propertiespackages/reflex-components-recharts/news/+layer_rectangle.feature.md(new file):Testing
test_general.pycovering component creation, rendering, and property handlingChecklist
pyi_hashes.jsonupdated for modified.pyifileshttps://claude.ai/code/session_01XqtAPUo84EBNq6c8Ext3mC