general.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. """General components for Recharts."""
  2. from __future__ import annotations
  3. from typing import Any, Dict, List, Union
  4. from reflex.components.component import MemoizationLeaf
  5. from reflex.event import EventHandler
  6. from reflex.vars import Var
  7. from .recharts import (
  8. LiteralAnimationEasing,
  9. LiteralIconType,
  10. LiteralLayout,
  11. LiteralLegendAlign,
  12. LiteralPosition,
  13. LiteralVerticalAlign,
  14. Recharts,
  15. )
  16. class ResponsiveContainer(Recharts, MemoizationLeaf):
  17. """A base class for responsive containers in Recharts."""
  18. tag = "ResponsiveContainer"
  19. alias = "RechartsResponsiveContainer"
  20. # The aspect ratio of the container. The final aspect ratio of the SVG element will be (width / height) * aspect. Number
  21. aspect: Var[int]
  22. # The width of chart container. Can be a number or string
  23. width: Var[Union[int, str]]
  24. # The height of chart container. Number
  25. height: Var[Union[int, str]]
  26. # The minimum width of chart container.
  27. min_width: Var[int]
  28. # The minimum height of chart container. Number
  29. min_height: Var[int]
  30. # If specified a positive number, debounced function will be used to handle the resize event.
  31. debounce: Var[int]
  32. # Valid children components
  33. _valid_children: List[str] = [
  34. "AreaChart",
  35. "BarChart",
  36. "LineChart",
  37. "PieChart",
  38. "RadarChart",
  39. "RadialBarChart",
  40. "ScatterChart",
  41. "Treemap",
  42. "ComposedChart",
  43. "FunnelChart",
  44. ]
  45. class Legend(Recharts):
  46. """A Legend component in Recharts."""
  47. tag = "Legend"
  48. alias = "RechartsLegend"
  49. # The width of legend container. Number
  50. width: Var[int]
  51. # The height of legend container. Number
  52. height: Var[int]
  53. # The layout of legend items. 'horizontal' | 'vertical'
  54. layout: Var[LiteralLayout]
  55. # The alignment of legend items in 'horizontal' direction, which can be 'left', 'center', 'right'.
  56. align: Var[LiteralLegendAlign]
  57. # The alignment of legend items in 'vertical' direction, which can be 'top', 'middle', 'bottom'.
  58. vertical_align: Var[LiteralVerticalAlign]
  59. # The size of icon in each legend item.
  60. icon_size: Var[int]
  61. # The type of icon in each legend item. 'line' | 'plainline' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye'
  62. icon_type: Var[LiteralIconType]
  63. # The width of chart container, usually calculated internally.
  64. chart_width: Var[int]
  65. # The height of chart container, usually calculated internally.
  66. chart_height: Var[int]
  67. # The margin of chart container, usually calculated internally.
  68. margin: Var[Dict[str, Any]]
  69. # The customized event handler of click on the items in this group
  70. on_click: EventHandler[lambda: []]
  71. # The customized event handler of mousedown on the items in this group
  72. on_mouse_down: EventHandler[lambda: []]
  73. # The customized event handler of mouseup on the items in this group
  74. on_mouse_up: EventHandler[lambda: []]
  75. # The customized event handler of mousemove on the items in this group
  76. on_mouse_move: EventHandler[lambda: []]
  77. # The customized event handler of mouseover on the items in this group
  78. on_mouse_over: EventHandler[lambda: []]
  79. # The customized event handler of mouseout on the items in this group
  80. on_mouse_out: EventHandler[lambda: []]
  81. # The customized event handler of mouseenter on the items in this group
  82. on_mouse_enter: EventHandler[lambda: []]
  83. # The customized event handler of mouseleave on the items in this group
  84. on_mouse_leave: EventHandler[lambda: []]
  85. class GraphingTooltip(Recharts):
  86. """A Tooltip component in Recharts."""
  87. tag = "Tooltip"
  88. alias = "RechartsTooltip"
  89. # The separator between name and value.
  90. separator: Var[str]
  91. # The offset size of tooltip. Number
  92. offset: Var[int]
  93. # When an item of the payload has value null or undefined, this item won't be displayed.
  94. filter_null: Var[bool]
  95. # If set false, no cursor will be drawn when tooltip is active.
  96. cursor: Var[bool]
  97. # The box of viewing area, which has the shape of {x: someVal, y: someVal, width: someVal, height: someVal}, usually calculated internally.
  98. view_box: Var[Dict[str, Any]]
  99. # The style of default tooltip content item which is a li element. DEFAULT: {}
  100. item_style: Var[Dict[str, Any]]
  101. # The style of tooltip wrapper which is a dom element. DEFAULT: {}
  102. wrapper_style: Var[Dict[str, Any]]
  103. # The style of tooltip content which is a dom element. DEFAULT: {}
  104. content_style: Var[Dict[str, Any]]
  105. # The style of default tooltip label which is a p element. DEFAULT: {}
  106. label_style: Var[Dict[str, Any]]
  107. # This option allows the tooltip to extend beyond the viewBox of the chart itself. DEFAULT: { x: false, y: false }
  108. allow_escape_view_box: Var[Dict[str, bool]] = Var.create_safe(
  109. {"x": False, "y": False}
  110. )
  111. # If set true, the tooltip is displayed. If set false, the tooltip is hidden, usually calculated internally.
  112. active: Var[bool]
  113. # If this field is set, the tooltip position will be fixed and will not move anymore.
  114. position: Var[Dict[str, Any]]
  115. # The coordinate of tooltip which is usually calculated internally.
  116. coordinate: Var[Dict[str, Any]]
  117. # If set false, animation of tooltip will be disabled. DEFAULT: true in CSR, and false in SSR
  118. is_animation_active: Var[bool]
  119. # Specifies the duration of animation, the unit of this option is ms. DEFAULT: 1500
  120. animation_duration: Var[int]
  121. # The type of easing function. DEFAULT: 'ease'
  122. animation_easing: Var[LiteralAnimationEasing]
  123. class Label(Recharts):
  124. """A Label component in Recharts."""
  125. tag = "Label"
  126. alias = "RechartsLabel"
  127. # The box of viewing area, which has the shape of {x: someVal, y: someVal, width: someVal, height: someVal}, usually calculated internally.
  128. view_box: Var[Dict[str, Any]]
  129. # The value of label, which can be specified by this props or the children of <Label />
  130. value: Var[str]
  131. # The offset of label which can be specified by this props or the children of <Label />
  132. offset: Var[int]
  133. # The position of label which can be specified by this props or the children of <Label />
  134. position: Var[LiteralPosition]
  135. class LabelList(Recharts):
  136. """A LabelList component in Recharts."""
  137. tag = "LabelList"
  138. alias = "RechartsLabelList"
  139. # The key of a group of label values in data.
  140. data_key: Var[Union[str, int]]
  141. # The position of each label relative to it view box。"Top" | "left" | "right" | "bottom" | "inside" | "outside" | "insideLeft" | "insideRight" | "insideTop" | "insideBottom" | "insideTopLeft" | "insideBottomLeft" | "insideTopRight" | "insideBottomRight" | "insideStart" | "insideEnd" | "end" | "center"
  142. position: Var[LiteralPosition]
  143. # The offset to the specified "position"
  144. offset: Var[int]
  145. responsive_container = ResponsiveContainer.create
  146. legend = Legend.create
  147. graphing_tooltip = GraphingTooltip.create
  148. label = Label.create
  149. label_list = LabelList.create