general.py 5.1 KB

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