Skip to content

Commit 899615f

Browse files
committed
wrap sankey recharts
1 parent 27bb987 commit 899615f

File tree

6 files changed

+113
-9
lines changed

6 files changed

+113
-9
lines changed

pyi_hashes.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
"reflex/components/datadisplay/code.pyi": "3d8f0ab4c2f123d7f80d15c7ebc553d9",
2626
"reflex/components/datadisplay/dataeditor.pyi": "cb03d732e2fe771a8d46c7bcda671f92",
2727
"reflex/components/datadisplay/shiki_code_block.pyi": "87db7639bfa5cd53e1709e1363f93278",
28-
"reflex/components/el/__init__.pyi": "09042a2db5e0637e99b5173430600522",
28+
"reflex/components/el/__init__.pyi": "0286a5b614420b25f59cb8ee462320df",
2929
"reflex/components/el/element.pyi": "06ac2213b062119323291fa66a1ac19e",
30-
"reflex/components/el/elements/__init__.pyi": "280ed457675f3720e34b560a3f617739",
30+
"reflex/components/el/elements/__init__.pyi": "c04167d619d9f0b00eba882fe5ab086c",
3131
"reflex/components/el/elements/base.pyi": "6e533348b5e1a88cf62fbb5a38dbd795",
3232
"reflex/components/el/elements/forms.pyi": "161f1ef847e5da8755528a7977fdcf53",
3333
"reflex/components/el/elements/inline.pyi": "33d9d860e75dd8c4769825127ed363bb",
34-
"reflex/components/el/elements/media.pyi": "addd6872281d65d44a484358b895432f",
34+
"reflex/components/el/elements/media.pyi": "58856abaf78df332b181cda887b3ae3e",
3535
"reflex/components/el/elements/metadata.pyi": "974a86d9f0662f6fc15a5bb4b3a87862",
3636
"reflex/components/el/elements/other.pyi": "995a4fbf10bfdb7f48808210dfe413bd",
3737
"reflex/components/el/elements/scripts.pyi": "cd5bd53c3a6b016fbb913aff36d63344",
@@ -114,9 +114,9 @@
114114
"reflex/components/react_player/audio.pyi": "972975ed0ba3e1dc4a867da20b11ae8e",
115115
"reflex/components/react_player/react_player.pyi": "63ffffbc24907103f797dcfd85894107",
116116
"reflex/components/react_player/video.pyi": "35ce5ad62e8bff17d9c09d27c362f8dc",
117-
"reflex/components/recharts/__init__.pyi": "a52c9055e37c6ee25ded15688d45e8a5",
117+
"reflex/components/recharts/__init__.pyi": "ea6d4bf27ea46d35f3ab447030947388",
118118
"reflex/components/recharts/cartesian.pyi": "9dd16c08abe5205c6c414474e2de2f79",
119-
"reflex/components/recharts/charts.pyi": "3570af4627c601d10ee37033f1b2329c",
119+
"reflex/components/recharts/charts.pyi": "59cbd1a7d6a6429e7df1eb807eda8fad",
120120
"reflex/components/recharts/general.pyi": "a1b846d5f2fd0a8b1969b472c5cab2e7",
121121
"reflex/components/recharts/polar.pyi": "973c3e6aa253914c4c5fd18ed32196fb",
122122
"reflex/components/recharts/recharts.pyi": "157acc830323075ffaf4f68d495d1787",

reflex/components/el/elements/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"circle",
7272
"ellipse",
7373
"rect",
74+
"g",
7475
"polygon",
7576
"path",
7677
"stop",

reflex/components/el/elements/media.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class Text(BaseHTML):
316316
length_adjust: Var[str]
317317
# A width that the text should be scaled to fit.
318318
text_length: Var[str | int]
319+
# Used to align the text with respect to the x and y attributes.
320+
text_anchor: Var[str]
319321

320322

321323
class Line(BaseHTML):
@@ -364,6 +366,12 @@ class Ellipse(BaseHTML):
364366
path_length: Var[int]
365367

366368

369+
class G(BaseHTML):
370+
"""The SVG g component."""
371+
372+
tag = "g"
373+
374+
367375
class Rect(BaseHTML):
368376
"""The SVG rect component."""
369377

@@ -492,6 +500,7 @@ class SVG(ComponentNamespace):
492500
circle = staticmethod(Circle.create)
493501
ellipse = staticmethod(Ellipse.create)
494502
rect = staticmethod(Rect.create)
503+
g = staticmethod(G.create)
495504
polygon = staticmethod(Polygon.create)
496505
path = staticmethod(Path.create)
497506
stop = staticmethod(Stop.create)
@@ -506,6 +515,7 @@ class SVG(ComponentNamespace):
506515
circle = Circle.create
507516
ellipse = Ellipse.create
508517
rect = Rect.create
518+
g = G.create
509519
polygon = Polygon.create
510520
path = Path.create
511521
stop = Stop.create

reflex/components/recharts/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"FunnelChart",
5959
"treemap",
6060
"Treemap",
61+
"sankey_chart",
62+
"SankeyChart",
6163
],
6264
"general": [
6365
"responsive_container",

reflex/components/recharts/charts.py

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from collections.abc import Sequence
6-
from typing import Any, ClassVar
6+
from typing import Any, ClassVar, TypedDict
77

88
from reflex.components.component import Component
99
from reflex.components.recharts.general import ResponsiveContainer
@@ -37,9 +37,6 @@ class ChartBase(RechartsCharts):
3737
# The customized event handler of mouseenter on the component in this chart
3838
on_mouse_enter: EventHandler[no_args_event_spec]
3939

40-
# The customized event handler of mousemove on the component in this chart
41-
on_mouse_move: EventHandler[no_args_event_spec]
42-
4340
# The customized event handler of mouseleave on the component in this chart
4441
on_mouse_leave: EventHandler[no_args_event_spec]
4542

@@ -122,6 +119,9 @@ class CategoricalChartBase(ChartBase):
122119
# 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'
123120
stack_offset: Var[LiteralStackOffset]
124121

122+
# The customized event handler of mousemove on the component in this chart
123+
on_mouse_move: EventHandler[no_args_event_spec]
124+
125125

126126
class AreaChart(CategoricalChartBase):
127127
"""An Area chart component in Recharts."""
@@ -447,6 +447,9 @@ class FunnelChart(ChartBase):
447447
# The stroke color of each bar. String | Object
448448
stroke: Var[str | Color]
449449

450+
# The customized event handler of mousemove on the component in this chart
451+
on_mouse_move: EventHandler[no_args_event_spec]
452+
450453
# Valid children components
451454
_valid_children: ClassVar[list[str]] = ["Legend", "GraphingTooltip", "Funnel"]
452455

@@ -512,6 +515,92 @@ def create(cls, *children, **props) -> Component:
512515
)
513516

514517

518+
class SankeyChartNode(TypedDict):
519+
"""A node in a Sankey chart."""
520+
521+
name: str
522+
523+
524+
class SankeyChartLink(TypedDict):
525+
"""A link in a Sankey chart."""
526+
527+
source: int
528+
target: int
529+
value: int | float
530+
531+
532+
class SankeyChartData(TypedDict):
533+
"""The data for a Sankey chart."""
534+
535+
nodes: Sequence[SankeyChartNode]
536+
links: Sequence[SankeyChartLink]
537+
538+
539+
class SankeyChart(ChartBase):
540+
"""A Sankey chart component in Recharts."""
541+
542+
tag = "Sankey"
543+
544+
alias = "RechartsSankeyChart"
545+
546+
# The key of each sector's name.
547+
name_key: Var[str]
548+
549+
# The key of a group of data which should be unique in a SankeyChart.
550+
data_key: Var[int | str]
551+
552+
# The source data, including the array of nodes, and the relationships, represented by links.
553+
data: Var[SankeyChartData]
554+
555+
# Whether to sort the nodes on th y axis, or to display them as user-defined.
556+
sort: Var[bool]
557+
558+
# The padding between the nodes.
559+
node_padding: Var[int]
560+
561+
# The width of the nodes.
562+
node_width: Var[int]
563+
564+
# The width of link.
565+
link_width: Var[int]
566+
567+
# The curvature of width.
568+
link_curvature: Var[float]
569+
570+
# The number of the iterations between the links
571+
iterations: Var[int]
572+
573+
# The sizes of whitespace around the chart, i.e. {"top": 50, "right": 30, "left": 20, "bottom": 5}.
574+
margin: Var[dict[str, Any]]
575+
576+
# Valid children components
577+
_valid_children: ClassVar[list[str]] = ["GraphingTooltip", "Defs"]
578+
579+
# The source number of X-axis
580+
source_x: Var[int]
581+
582+
# The source number of Y-axis
583+
source_y: Var[int]
584+
585+
# The source control of X-axis
586+
source_control_x: Var[int]
587+
588+
# The target control of X-axis
589+
target_control_x: Var[int]
590+
591+
# The target of X-axis
592+
target_x: Var[int]
593+
594+
# The target of Y-axis
595+
target_y: Var[int]
596+
597+
# 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.
598+
node: Var[Any]
599+
600+
# 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.
601+
link: Var[Any]
602+
603+
515604
area_chart = AreaChart.create
516605
bar_chart = BarChart.create
517606
line_chart = LineChart.create
@@ -522,3 +611,4 @@ def create(cls, *children, **props) -> Component:
522611
scatter_chart = ScatterChart.create
523612
funnel_chart = FunnelChart.create
524613
treemap = Treemap.create
614+
sankey_chart = SankeyChart.create

reflex/components/recharts/general.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ResponsiveContainer(Recharts, MemoizationLeaf):
6262
"Treemap",
6363
"ComposedChart",
6464
"FunnelChart",
65+
"SankeyChart",
6566
]
6667

6768

0 commit comments

Comments
 (0)