Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-4406] cell component wrapper #4670

Merged
merged 2 commits into from
Jan 22, 2025
Merged

[ENG-4406] cell component wrapper #4670

merged 2 commits into from
Jan 22, 2025

Conversation

LineIndent
Copy link
Contributor

@Lendemor

import reflex as rx
from reflex import Var, Color

from reflex.components.recharts.recharts import Recharts


class Cell(Recharts):
    """A Cell component in Recharts."""

    tag = "Cell"

    alias = "RechartsCell"

    # The presentation attribute of a rectangle in bar or a sector in pie.
    fill: Var[str | Color]

    # The presentation attribute of a rectangle in bar or a sector in pie.
    stroke: Var[str]


cell = Cell.create



class State:
    data: list[dict[str, int]] = [
        {"browser": "chrome", "visitors": 275},
        {"browser": "safari", "visitors": 200},
        {"browser": "firefox", "visitors": 187},
        {"browser": "edge", "visitors": 173},
        {"browser": "other", "visitors": 90},
    ]


def piechart_v1():
    return rx.vstack(
        rx.recharts.pie_chart(
            rx.recharts.pie(
                rx.foreach(
                    State.data,
                    lambda item, index: cell(
                        fill=rx.color('red', index + 4)
                    )
                ),
                data=State.data,
                data_key="visitors",
                name_key="browser",
                stroke="0",
                is_animation_active=False,
            ),
            width="100%",
            height=250,
        ),
        width="100%",
        align="center",
        padding="0.5em",
    )


app = rx.App()
app.add_page(piechart_v1(), "/")

Copy link

linear bot commented Jan 21, 2025

@LineIndent LineIndent merged commit 80966db into main Jan 22, 2025
41 checks passed
@LineIndent LineIndent deleted the LineIndent/cell-wrap branch January 22, 2025 07:00
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.

3 participants