general.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 (
  7. LiteralIconType,
  8. LiteralLayout,
  9. LiteralLegendAlign,
  10. LiteralPosition,
  11. LiteralVerticalAlign,
  12. Recharts,
  13. RechartsMemoizationLeafMixin,
  14. )
  15. class ResponsiveContainer(Recharts, RechartsMemoizationLeafMixin):
  16. """A base class for responsive containers in Recharts."""
  17. tag = "ResponsiveContainer"
  18. alias = "RechartsResponsiveContainer"
  19. # The aspect ratio of the container. The final aspect ratio of the SVG element will be (width / height) * aspect. Number
  20. aspect: Var[int]
  21. # The width of chart container. Can be a number or string
  22. width: Var[Union[int, str]]
  23. # The height of chart container. Number
  24. height: Var[Union[int, str]]
  25. # The minimum width of chart container.
  26. min_width: Var[int]
  27. # The minimum height of chart container. Number
  28. min_height: Var[int]
  29. # If specified a positive number, debounced function will be used to handle the resize event.
  30. debounce: Var[int]
  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 = "Legend"
  46. alias = "RechartsLegend"
  47. # The width of legend container. Number
  48. width: Var[int]
  49. # The height of legend container. Number
  50. height: Var[int]
  51. # The layout of legend items. 'horizontal' | 'vertical'
  52. layout: Var[LiteralLayout]
  53. # The alignment of legend items in 'horizontal' direction, which can be 'left', 'center', 'right'.
  54. align: Var[LiteralLegendAlign]
  55. # The alignment of legend items in 'vertical' direction, which can be 'top', 'middle', 'bottom'.
  56. vertical_align: Var[LiteralVerticalAlign]
  57. # The size of icon in each legend item.
  58. icon_size: Var[int]
  59. # The type of icon in each legend item. 'line' | 'plainline' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye'
  60. icon_type: Var[LiteralIconType]
  61. # The width of chart container, usually calculated internally.
  62. chart_width: Var[int]
  63. # The height of chart container, usually calculated internally.
  64. chart_height: Var[int]
  65. # The margin of chart container, usually calculated internally.
  66. margin: Var[Dict[str, Any]]
  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 = "Tooltip"
  83. alias = "RechartsTooltip"
  84. # The separator between name and value.
  85. separator: Var[str]
  86. # The offset size of tooltip. Number
  87. offset: Var[int]
  88. # When an item of the payload has value null or undefined, this item won't be displayed.
  89. filter_null: Var[bool]
  90. # If set false, no cursor will be drawn when tooltip is active.
  91. cursor: Var[bool]
  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. # If set true, the tooltip is displayed. If set false, the tooltip is hidden, usually calculated internally.
  95. active: Var[bool]
  96. # If this field is set, the tooltip position will be fixed and will not move anymore.
  97. position: Var[Dict[str, Any]]
  98. # The coordinate of tooltip which is usually calculated internally.
  99. coordinate: Var[Dict[str, Any]]
  100. class Label(Recharts):
  101. """A Label component in Recharts."""
  102. tag = "Label"
  103. alias = "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: Var[Dict[str, Any]]
  106. # The value of label, which can be specified by this props or the children of <Label />
  107. value: Var[str]
  108. # The offset of label which can be specified by this props or the children of <Label />
  109. offset: Var[int]
  110. # The position of label which can be specified by this props or the children of <Label />
  111. position: Var[LiteralPosition]
  112. class LabelList(Recharts):
  113. """A LabelList component in Recharts."""
  114. tag = "LabelList"
  115. alias = "RechartsLabelList"
  116. # The key of a group of label values in data.
  117. data_key: Var[Union[str, int]]
  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: Var[LiteralPosition]
  120. # The offset to the specified "position"
  121. offset: Var[int]
  122. # Color of the fill
  123. fill: Var[str]
  124. # Color of the stroke
  125. stroke: Var[str]