polar.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. """Polar charts in Recharts."""
  2. from __future__ import annotations
  3. from typing import Any, Dict, List, Optional, Union
  4. from reflex.constants import EventTriggers
  5. from reflex.vars import Var
  6. from .recharts import (
  7. LiteralAnimationEasing,
  8. LiteralGridType,
  9. LiteralPolarRadiusType,
  10. LiteralScale,
  11. Recharts,
  12. )
  13. class Pie(Recharts):
  14. """A Pie chart component in Recharts."""
  15. tag: str = "Pie"
  16. alias: str = "RechartsPie"
  17. # data
  18. data: Optional[Var[List[Dict[str, Any]]]] = None
  19. # The key of each sector's value.
  20. data_key: Optional[Var[Union[str, int]]] = None
  21. # The x-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container width.
  22. cx: Optional[Var[Union[int, str]]] = None
  23. # The y-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container height.
  24. cy: Optional[Var[Union[int, str]]] = None
  25. # The inner radius of pie, which can be set to a percent value.
  26. inner_radius: Optional[Var[Union[int, str]]] = None
  27. # The outer radius of pie, which can be set to a percent value.
  28. outer_radius: Optional[Var[Union[int, str]]] = None
  29. # The angle of first sector.
  30. start_angle: Optional[Var[int]] = None
  31. # The direction of sectors. 1 means clockwise and -1 means anticlockwise.
  32. end_angle: Optional[Var[int]] = None
  33. # The minimum angle of each unzero data.
  34. min_angle: Optional[Var[int]] = None
  35. # The angle between two sectors.
  36. padding_angle: Optional[Var[int]] = None
  37. # The key of each sector's name.
  38. name_key: Optional[Var[str]] = None
  39. # The type of icon in legend. If set to 'none', no legend item will be rendered.
  40. legend_type: Optional[Var[str]] = None
  41. # If false set, labels will not be drawn.
  42. label: Var[bool] = False # type: ignore
  43. # If false set, label lines will not be drawn.
  44. label_line: Optional[Var[bool]] = None
  45. # Valid children components
  46. _valid_children: List[str] = ["Cell", "LabelList"]
  47. # fill color
  48. fill: Optional[Var[str]] = None
  49. # stroke color
  50. stroke: Optional[Var[str]] = None
  51. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  52. """Get the event triggers that pass the component's value to the handler.
  53. Returns:
  54. A dict mapping the event trigger to the var that is passed to the handler.
  55. """
  56. return {
  57. EventTriggers.ON_CLICK: lambda: [],
  58. EventTriggers.ON_MOUSE_MOVE: lambda: [],
  59. EventTriggers.ON_MOUSE_OVER: lambda: [],
  60. EventTriggers.ON_MOUSE_OUT: lambda: [],
  61. EventTriggers.ON_MOUSE_ENTER: lambda: [],
  62. EventTriggers.ON_MOUSE_LEAVE: lambda: [],
  63. }
  64. class Radar(Recharts):
  65. """A Radar chart component in Recharts."""
  66. tag: str = "Radar"
  67. alias: str = "RechartsRadar"
  68. # The key of a group of data which should be unique in a radar chart.
  69. data_key: Optional[Var[Union[str, int]]] = None
  70. # The coordinates of all the vertexes of the radar shape, like [{ x, y }].
  71. points: Optional[Var[List[Dict[str, Any]]]] = None
  72. # If false set, dots will not be drawn
  73. dot: Optional[Var[bool]] = None
  74. # Stoke color
  75. stroke: Optional[Var[str]] = None
  76. # Fill color
  77. fill: Optional[Var[str]] = None
  78. # opacity
  79. fill_opacity: Optional[Var[float]] = None
  80. # The type of icon in legend. If set to 'none', no legend item will be rendered.
  81. legend_type: Optional[Var[str]] = None
  82. # If false set, labels will not be drawn
  83. label: Optional[Var[bool]] = None
  84. # Specifies when the animation should begin, the unit of this option is ms.
  85. animation_begin: Optional[Var[int]] = None
  86. # Specifies the duration of animation, the unit of this option is ms.
  87. animation_duration: Optional[Var[int]] = None
  88. # The type of easing function. 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear'
  89. animation_easing: Optional[Var[LiteralAnimationEasing]] = None
  90. # Valid children components
  91. _valid_children: List[str] = ["LabelList"]
  92. class RadialBar(Recharts):
  93. """A RadialBar chart component in Recharts."""
  94. tag: str = "RadialBar"
  95. alias: str = "RechartsRadialBar"
  96. # The source data which each element is an object.
  97. data: Optional[Var[List[Dict[str, Any]]]] = None
  98. # Min angle of each bar. A positive value between 0 and 360.
  99. min_angle: Optional[Var[int]] = None
  100. # Type of legend
  101. legend_type: Optional[Var[str]] = None
  102. # If false set, labels will not be drawn.
  103. label: Optional[Var[bool]] = None
  104. # If false set, background sector will not be drawn.
  105. background: Optional[Var[bool]] = None
  106. # Valid children components
  107. _valid_children: List[str] = ["LabelList"]
  108. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  109. """Get the event triggers that pass the component's value to the handler.
  110. Returns:
  111. A dict mapping the event trigger to the var that is passed to the handler.
  112. """
  113. return {
  114. EventTriggers.ON_CLICK: lambda: [],
  115. EventTriggers.ON_MOUSE_MOVE: lambda: [],
  116. EventTriggers.ON_MOUSE_OVER: lambda: [],
  117. EventTriggers.ON_MOUSE_OUT: lambda: [],
  118. EventTriggers.ON_MOUSE_ENTER: lambda: [],
  119. EventTriggers.ON_MOUSE_LEAVE: lambda: [],
  120. }
  121. class PolarAngleAxis(Recharts):
  122. """A PolarAngleAxis component in Recharts."""
  123. tag: str = "PolarAngleAxis"
  124. alias: str = "RechartsPolarAngleAxis"
  125. # The key of a group of data which should be unique to show the meaning of angle axis.
  126. data_key: Optional[Var[Union[str, int]]] = None
  127. # The x-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container width.
  128. cx: Optional[Var[Union[int, str]]] = None
  129. # The y-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container height.
  130. cy: Optional[Var[Union[int, str]]] = None
  131. # The outer radius of circle grid. If set a percentage, the final value is obtained by multiplying the percentage of maxRadius which is calculated by the width, height, cx, cy.
  132. radius: Optional[Var[Union[int, str]]] = None
  133. # If false set, axis line will not be drawn. If true set, axis line will be drawn which have the props calculated internally. If object set, axis line will be drawn which have the props mergered by the internal calculated props and the option.
  134. axis_line: Optional[Var[Union[bool, Dict[str, Any]]]] = None
  135. # The type of axis line.
  136. axis_line_type: Optional[Var[str]] = None
  137. # If false set, tick lines will not be drawn. If true set, tick lines will be drawn which have the props calculated internally. If object set, tick lines will be drawn which have the props mergered by the internal calculated props and the option.
  138. tick_line: Optional[Var[Union[bool, Dict[str, Any]]]] = None
  139. # The width or height of tick.
  140. tick: Optional[Var[Union[int, str]]] = None
  141. # The array of every tick's value and angle.
  142. ticks: Optional[Var[List[Dict[str, Any]]]] = None
  143. # The orientation of axis text.
  144. orient: Optional[Var[str]] = None
  145. # Allow the axis has duplicated categorys or not when the type of axis is "category".
  146. allow_duplicated_category: Optional[Var[bool]] = None
  147. # Valid children components
  148. _valid_children: List[str] = ["Label"]
  149. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  150. """Get the event triggers that pass the component's value to the handler.
  151. Returns:
  152. A dict mapping the event trigger to the var that is passed to the handler.
  153. """
  154. return {
  155. EventTriggers.ON_CLICK: lambda: [],
  156. EventTriggers.ON_MOUSE_MOVE: lambda: [],
  157. EventTriggers.ON_MOUSE_OVER: lambda: [],
  158. EventTriggers.ON_MOUSE_OUT: lambda: [],
  159. EventTriggers.ON_MOUSE_ENTER: lambda: [],
  160. EventTriggers.ON_MOUSE_LEAVE: lambda: [],
  161. }
  162. class PolarGrid(Recharts):
  163. """A PolarGrid component in Recharts."""
  164. tag: str = "PolarGrid"
  165. alias: str = "RechartsPolarGrid"
  166. # The x-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container width.
  167. cx: Optional[Var[Union[int, str]]] = None
  168. # The y-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container height.
  169. cy: Optional[Var[Union[int, str]]] = None
  170. # The radius of the inner polar grid.
  171. inner_radius: Optional[Var[Union[int, str]]] = None
  172. # The radius of the outer polar grid.
  173. outer_radius: Optional[Var[Union[int, str]]] = None
  174. # The array of every line grid's angle.
  175. polar_angles: Optional[Var[List[int]]] = None
  176. # The array of every line grid's radius.
  177. polar_radius: Optional[Var[List[int]]] = None
  178. # The type of polar grids. 'polygon' | 'circle'
  179. grid_type: Optional[Var[LiteralGridType]] = None
  180. # Valid children components
  181. _valid_children: List[str] = ["RadarChart", "RadiarBarChart"]
  182. class PolarRadiusAxis(Recharts):
  183. """A PolarRadiusAxis component in Recharts."""
  184. tag: str = "PolarRadiusAxis"
  185. alias: str = "RechartsPolarRadiusAxis"
  186. # The angle of radial direction line to display axis text.
  187. angle: Optional[Var[int]] = None
  188. # The type of axis line. 'number' | 'category'
  189. type_: Optional[Var[LiteralPolarRadiusType]] = None
  190. # Allow the axis has duplicated categorys or not when the type of axis is "category".
  191. allow_duplicated_category: Optional[Var[bool]] = None
  192. # The x-coordinate of center.
  193. cx: Optional[Var[Union[int, str]]] = None
  194. # The y-coordinate of center.
  195. cy: Optional[Var[Union[int, str]]] = None
  196. # If set to true, the ticks of this axis are reversed.
  197. reversed: Optional[Var[bool]] = None
  198. # The orientation of axis text.
  199. orientation: Optional[Var[str]] = None
  200. # If false set, axis line will not be drawn. If true set, axis line will be drawn which have the props calculated internally. If object set, axis line will be drawn which have the props mergered by the internal calculated props and the option.
  201. axis_line: Optional[Var[Union[bool, Dict[str, Any]]]] = None
  202. # The width or height of tick.
  203. tick: Optional[Var[Union[int, str]]] = None
  204. # The count of ticks.
  205. tick_count: Optional[Var[int]] = None
  206. # If 'auto' set, the scale funtion is linear scale. 'auto' | 'linear' | 'pow' | 'sqrt' | 'log' | 'identity' | 'time' | 'band' | 'point' | 'ordinal' | 'quantile' | 'quantize' | 'utc' | 'sequential' | 'threshold'
  207. scale: Optional[Var[LiteralScale]] = None
  208. # Valid children components
  209. _valid_children: List[str] = ["Label"]
  210. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  211. """Get the event triggers that pass the component's value to the handler.
  212. Returns:
  213. A dict mapping the event trigger to the var that is passed to the handler.
  214. """
  215. return {
  216. EventTriggers.ON_CLICK: lambda: [],
  217. EventTriggers.ON_MOUSE_MOVE: lambda: [],
  218. EventTriggers.ON_MOUSE_OVER: lambda: [],
  219. EventTriggers.ON_MOUSE_OUT: lambda: [],
  220. EventTriggers.ON_MOUSE_ENTER: lambda: [],
  221. EventTriggers.ON_MOUSE_LEAVE: lambda: [],
  222. }