diff --git a/pyi_hashes.json b/pyi_hashes.json index a1a0cec8aa7..86f0fd9a420 100644 --- a/pyi_hashes.json +++ b/pyi_hashes.json @@ -31,7 +31,7 @@ "reflex/components/el/elements/base.pyi": "697cd6716e3b1127b35299435c3d4e69", "reflex/components/el/elements/forms.pyi": "14f2ac656d37c4a5343c77e89ad9107b", "reflex/components/el/elements/inline.pyi": "ab31eec758f1cff8a9d51bf0935b9fca", - "reflex/components/el/elements/media.pyi": "c191a9e00223a97e26a0d6ab99a1919b", + "reflex/components/el/elements/media.pyi": "ea3721092a9d3975a2e35b53c03a6ab0", "reflex/components/el/elements/metadata.pyi": "eda94a3283bae6a9b61b4cb1e20c1dbd", "reflex/components/el/elements/other.pyi": "960bdac0bb9bf6b3cffd241f9b66c0fc", "reflex/components/el/elements/scripts.pyi": "ac3b8bfbd7777f33fb2c6aa109a5c627", @@ -114,9 +114,9 @@ "reflex/components/react_player/audio.pyi": "231e9338b19330a6963928f7e90cb40f", "reflex/components/react_player/react_player.pyi": "40db798bcb7fa40207d24f49722135ae", "reflex/components/react_player/video.pyi": "f92885d49cdc565b95b20820d09e2ca2", - "reflex/components/recharts/__init__.pyi": "a060a4abcd018165bc499173e723cf9e", + "reflex/components/recharts/__init__.pyi": "4116c508e344f79d945613b336a5003e", "reflex/components/recharts/cartesian.pyi": "601e1acb0ad6bd93ce371d763220aabe", - "reflex/components/recharts/charts.pyi": "2f0a39f9c02de83d9e2d97763b4411af", + "reflex/components/recharts/charts.pyi": "f02b8d86534efc79ec3077056017e47b", "reflex/components/recharts/general.pyi": "06d0e97776cc82b946fed465ab36fba4", "reflex/components/recharts/polar.pyi": "77ca6e0d992f5d5c0479de73db4f71ba", "reflex/components/recharts/recharts.pyi": "bbaec232c2da035b31b5d0e3888f4801", diff --git a/reflex/components/el/elements/media.py b/reflex/components/el/elements/media.py index 3b2aac70ecb..fa6925ea1bd 100644 --- a/reflex/components/el/elements/media.py +++ b/reflex/components/el/elements/media.py @@ -316,6 +316,8 @@ class Text(BaseHTML): length_adjust: Var[str] # A width that the text should be scaled to fit. text_length: Var[str | int] + # Used to align the text with respect to the x and y attributes. + text_anchor: Var[str] class Line(BaseHTML): diff --git a/reflex/components/recharts/__init__.py b/reflex/components/recharts/__init__.py index 6b4b358095b..817946ee9ef 100644 --- a/reflex/components/recharts/__init__.py +++ b/reflex/components/recharts/__init__.py @@ -58,6 +58,8 @@ "FunnelChart", "treemap", "Treemap", + "sankey_chart", + "SankeyChart", ], "general": [ "responsive_container", diff --git a/reflex/components/recharts/charts.py b/reflex/components/recharts/charts.py index 7356dd453b6..21d92b7209a 100644 --- a/reflex/components/recharts/charts.py +++ b/reflex/components/recharts/charts.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Sequence -from typing import Any, ClassVar +from typing import Any, ClassVar, TypedDict from reflex.components.component import Component from reflex.components.recharts.general import ResponsiveContainer @@ -37,9 +37,6 @@ class ChartBase(RechartsCharts): # The customized event handler of mouseenter on the component in this chart on_mouse_enter: EventHandler[no_args_event_spec] - # The customized event handler of mousemove on the component in this chart - on_mouse_move: EventHandler[no_args_event_spec] - # The customized event handler of mouseleave on the component in this chart on_mouse_leave: EventHandler[no_args_event_spec] @@ -123,6 +120,9 @@ class CategoricalChartBase(ChartBase): # The type of offset function used to generate the lower and upper values in the series array. The four types are built-in offsets in d3-shape. 'expand' | 'none' | 'wiggle' | 'silhouette' stack_offset: Var[LiteralStackOffset] + # The customized event handler of mousemove on the component in this chart + on_mouse_move: EventHandler[no_args_event_spec] + class AreaChart(CategoricalChartBase): """An Area chart component in Recharts.""" @@ -448,6 +448,9 @@ class FunnelChart(ChartBase): # The stroke color of each bar. String | Object stroke: Var[str | Color] + # The customized event handler of mousemove on the component in this chart + on_mouse_move: EventHandler[no_args_event_spec] + # Valid children components _valid_children: ClassVar[list[str]] = ["Legend", "GraphingTooltip", "Funnel"] @@ -513,6 +516,92 @@ def create(cls, *children, **props) -> Component: ) +class SankeyChartNode(TypedDict): + """A node in a Sankey chart.""" + + name: str + + +class SankeyChartLink(TypedDict): + """A link in a Sankey chart.""" + + source: int + target: int + value: int | float + + +class SankeyChartData(TypedDict): + """The data for a Sankey chart.""" + + nodes: Sequence[SankeyChartNode] + links: Sequence[SankeyChartLink] + + +class SankeyChart(ChartBase): + """A Sankey chart component in Recharts.""" + + tag = "Sankey" + + alias = "RechartsSankeyChart" + + # The key of each sector's name. + name_key: Var[str] + + # The key of a group of data which should be unique in a SankeyChart. + data_key: Var[int | str] + + # The source data, including the array of nodes, and the relationships, represented by links. + data: Var[SankeyChartData] + + # Whether to sort the nodes on th y axis, or to display them as user-defined. + sort: Var[bool] + + # The padding between the nodes. + node_padding: Var[int] + + # The width of the nodes. + node_width: Var[int] + + # The width of link. + link_width: Var[int] + + # The curvature of width. + link_curvature: Var[float] + + # The number of the iterations between the links + iterations: Var[int] + + # The sizes of whitespace around the chart, i.e. {"top": 50, "right": 30, "left": 20, "bottom": 5}. + margin: Var[dict[str, Any]] + + # Valid children components + _valid_children: ClassVar[list[str]] = ["GraphingTooltip", "Defs"] + + # The source number of X-axis + source_x: Var[int] + + # The source number of Y-axis + source_y: Var[int] + + # The source control of X-axis + source_control_x: Var[int] + + # The target control of X-axis + target_control_x: Var[int] + + # The target of X-axis + target_x: Var[int] + + # The target of Y-axis + target_y: Var[int] + + # If set a object, the option is the configuration of nodes. If set a React element, the option is the custom react element of drawing the nodes. + node: Var[Any] + + # If set a object, the option is the configuration of links. If set a React element, the option is the custom react element of drawing the links. + link: Var[Any] + + area_chart = AreaChart.create bar_chart = BarChart.create line_chart = LineChart.create @@ -523,3 +612,4 @@ def create(cls, *children, **props) -> Component: scatter_chart = ScatterChart.create funnel_chart = FunnelChart.create treemap = Treemap.create +sankey_chart = SankeyChart.create diff --git a/reflex/components/recharts/general.py b/reflex/components/recharts/general.py index bde06719e25..a706448d917 100644 --- a/reflex/components/recharts/general.py +++ b/reflex/components/recharts/general.py @@ -62,6 +62,7 @@ class ResponsiveContainer(Recharts, MemoizationLeaf): "Treemap", "ComposedChart", "FunnelChart", + "SankeyChart", ]