general.py 5.4 KB

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