general.py 6.1 KB

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