general.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. """General components for Recharts."""
  2. from __future__ import annotations
  3. from typing import Any, Dict, List, Union
  4. from reflex.constants import EventTriggers
  5. from reflex.vars import Var
  6. from .recharts import Recharts
  7. class ResponsiveContainer(Recharts):
  8. """A base class for responsive containers in Recharts."""
  9. tag = "ResponsiveContainer"
  10. alias = "RechartsResponsiveContainer"
  11. # The aspect ratio of the container. The final aspect ratio of the SVG element will be (width / height) * aspect. Number
  12. aspect: Var[int]
  13. # The width of chart container. Can be a number or string
  14. width: Var[Union[int, str]]
  15. # The height of chart container. Number
  16. height: Var[Union[int, str]]
  17. # The minimum width of chart container.
  18. min_width: Var[int]
  19. # The minimum height of chart container. Number
  20. min_height: Var[int]
  21. # If specified a positive number, debounced function will be used to handle the resize event.
  22. debounce: Var[int]
  23. # Valid children components
  24. valid_children: List[str] = [
  25. "AreaChart",
  26. "BarChart",
  27. "LineChart",
  28. "PieChart",
  29. "RadarChart",
  30. "RadialBarChart",
  31. "ScatterChart",
  32. "Treemap",
  33. "ComposedChart",
  34. ]
  35. class Legend(Recharts):
  36. """A Legend component in Recharts."""
  37. tag = "Legend"
  38. alias = "RechartsLegend"
  39. # The width of legend container. Number
  40. width: Var[int]
  41. # The height of legend container. Number
  42. height: Var[int]
  43. # The layout of legend items. 'horizontal' | 'vertical'
  44. layout: Var[str]
  45. # The alignment of legend items in 'horizontal' direction, which can be 'left', 'center', 'right'.
  46. align: Var[str]
  47. # The alignment of legend items in 'vertical' direction, which can be 'top', 'middle', 'bottom'.
  48. vertical_align: Var[str]
  49. # The size of icon in each legend item.
  50. icon_size: Var[int]
  51. # The type of icon in each legend item. 'line' | 'plainline' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye'
  52. icon_type: Var[str]
  53. # The width of chart container, usually calculated internally.
  54. chart_width: Var[int]
  55. # The height of chart container, usually calculated internally.
  56. chart_height: Var[int]
  57. # The margin of chart container, usually calculated internally.
  58. margin: Var[Dict[str, Any]]
  59. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  60. """Get the event triggers that pass the component's value to the handler.
  61. Returns:
  62. A dict mapping the event trigger to the var that is passed to the handler.
  63. """
  64. return {
  65. EventTriggers.ON_CLICK: lambda: [],
  66. EventTriggers.ON_MOUSE_MOVE: lambda: [],
  67. EventTriggers.ON_MOUSE_OVER: lambda: [],
  68. EventTriggers.ON_MOUSE_OUT: lambda: [],
  69. EventTriggers.ON_MOUSE_ENTER: lambda: [],
  70. EventTriggers.ON_MOUSE_LEAVE: lambda: [],
  71. }
  72. class GraphingTooltip(Recharts):
  73. """A Tooltip component in Recharts."""
  74. tag = "Tooltip"
  75. alias = "RechartsTooltip"
  76. # The separator between name and value.
  77. separator: Var[str]
  78. # The offset size of tooltip. Number
  79. offset: Var[int]
  80. # When an item of the payload has value null or undefined, this item won't be displayed.
  81. filter_null: Var[bool]
  82. # If set false, no cursor will be drawn when tooltip is active.
  83. cursor: Var[bool]
  84. # The box of viewing area, which has the shape of {x: someVal, y: someVal, width: someVal, height: someVal}, usually calculated internally.
  85. view_box: Var[Dict[str, Any]]
  86. # If set true, the tooltip is displayed. If set false, the tooltip is hidden, usually calculated internally.
  87. active: Var[bool]
  88. # If this field is set, the tooltip position will be fixed and will not move anymore.
  89. position: Var[Dict[str, Any]]
  90. # The coordinate of tooltip which is usually calculated internally.
  91. coordinate: Var[Dict[str, Any]]
  92. class Label(Recharts):
  93. """A Label component in Recharts."""
  94. tag = "Label"
  95. alias = "RechartsLabel"
  96. # The box of viewing area, which has the shape of {x: someVal, y: someVal, width: someVal, height: someVal}, usually calculated internally.
  97. view_box: Var[Dict[str, Any]]
  98. # The value of label, which can be specified by this props or the children of <Label />
  99. value: Var[str]
  100. # The offset of label which can be specified by this props or the children of <Label />
  101. offset: Var[int]
  102. # The position of label which can be specified by this props or the children of <Label />
  103. position: Var[str]
  104. class LabelList(Recharts):
  105. """A LabelList component in Recharts."""
  106. tag = "LabelList"
  107. alias = "RechartsLabelList"
  108. # The key of a group of label values in data.
  109. data_key: Var[Union[str, int]]
  110. # The position of each label relative to it view box。op" | "left" | "right" | "bottom" | "inside" | "outside" | "insideLeft" | "insideRight" | "insideTop" | "insideBottom" | "insideTopLeft" | "insideBottomLeft" | "insideTopRight" | "insideBottomRight" | "insideStart" | "insideEnd" | "end" | "center"
  111. position: Var[str]
  112. # The offset to the specified "position"
  113. offset: Var[int]
  114. # Color of the fill
  115. fill: Var[str]
  116. # Color of the stroke
  117. stroke: Var[str]