recharts.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. """A component that wraps a recharts lib."""
  2. from typing import Literal
  3. from reflex.components.component import Component, NoSSRComponent
  4. from reflex.constants import MemoizationDisposition, MemoizationMode
  5. class Recharts(Component):
  6. """A component that wraps a recharts lib."""
  7. library = "recharts@2.8.0"
  8. class RechartsMemoizationLeafMixin(Component):
  9. """A mixin for Recharts components that must not memoize their children separately.
  10. This includes all chart types and ResponsiveContainer itself.
  11. """
  12. _memoization_mode = MemoizationMode(recursive=False)
  13. @classmethod
  14. def create(cls, *children, **props) -> Component:
  15. """Create a Recharts chart container component (mixin).
  16. Args:
  17. *children: The children components.
  18. **props: The props of the component.
  19. Returns:
  20. A Recharts component.
  21. """
  22. comp = super().create(*children, **props)
  23. if comp.get_hooks():
  24. # If any of the children depend on state, then this instance needs to memoize.
  25. comp._memoization_mode = cls._memoization_mode.copy(
  26. update={"disposition": MemoizationDisposition.ALWAYS},
  27. )
  28. return comp
  29. class RechartsCharts(NoSSRComponent, RechartsMemoizationLeafMixin):
  30. """A component that wraps a recharts lib."""
  31. library = "recharts@2.8.0"
  32. LiteralAnimationEasing = Literal["ease", "ease-in", "ease-out", "ease-in-out", "linear"]
  33. LiteralIfOverflow = Literal["discard", "hidden", "visible", "extendDomain"]
  34. LiteralShape = Literal[
  35. "square", "circle", "cross", "diamond", "star", "triangle", "wye"
  36. ]
  37. LiteralLineType = Literal["joint", "fitting"]
  38. LiteralOrientation = Literal["top", "bottom", "left", "right", "middle"]
  39. LiteralOrientationLeftRightMiddle = Literal["left", "right", "middle"]
  40. LiteralOrientationTopBottom = Literal["top", "bottom"]
  41. LiteralOrientationTopBottomLeftRight = Literal["top", "bottom", "left", "right"]
  42. LiteralScale = Literal[
  43. "auto",
  44. "linear",
  45. "pow",
  46. "sqrt",
  47. "log",
  48. "identity",
  49. "time",
  50. "band",
  51. "point",
  52. "ordinal",
  53. "quantile",
  54. "quantize",
  55. "utc",
  56. "sequential",
  57. "threshold",
  58. ]
  59. LiteralLayout = Literal["horizontal", "vertical"]
  60. LiteralPolarRadiusType = Literal["number", "category"]
  61. LiteralGridType = Literal["polygon", "circle"]
  62. LiteralPosition = Literal[
  63. "top",
  64. "left",
  65. "right",
  66. "bottom",
  67. "inside",
  68. "outside",
  69. "insideLeft",
  70. "insideRight",
  71. "insideTop",
  72. "insideBottom",
  73. "insideTopLeft",
  74. "insideBottomLeft",
  75. "insideTopRight",
  76. "insideBottomRight",
  77. "insideStart",
  78. "insideEnd",
  79. "end",
  80. "center",
  81. ]
  82. LiteralIconType = Literal[
  83. "line",
  84. "plainline",
  85. "square",
  86. "rect",
  87. "circle",
  88. "cross",
  89. "diamond",
  90. "star",
  91. "triangle",
  92. "wye",
  93. ]
  94. LiteralLegendType = [
  95. "line",
  96. "plainline",
  97. "square",
  98. "rect",
  99. "circle",
  100. "cross",
  101. "diamond",
  102. "star",
  103. "triangle",
  104. "wye",
  105. "none",
  106. ]
  107. LiteralLegendAlign = Literal["left", "center", "right"]
  108. LiteralVerticalAlign = Literal["top", "middle", "bottom"]
  109. LiteralStackOffset = Literal["expand", "none", "wiggle", "silhouette"]
  110. LiteralBarChartStackOffset = Literal["expand", "none", "wiggle", "silhouette", "sign"]
  111. LiteralComposedChartBaseValue = Literal["dataMin", "dataMax", "auto"]
  112. LiteralAxisType = Literal["number", "category"]
  113. LiteralAreaType = Literal[
  114. "basis",
  115. "basisClosed",
  116. "basisOpen",
  117. "bumpX",
  118. "bumpY",
  119. "bump",
  120. "linear",
  121. "linearClosed",
  122. "natural",
  123. "monotoneX",
  124. "monotoneY",
  125. "monotone",
  126. "step",
  127. "stepBefore",
  128. "stepAfter",
  129. ]
  130. LiteralDirection = Literal["x", "y", "both"]
  131. LiteralInterval = Literal["preserveStart", "preserveEnd", "preserveStartEnd"]
  132. LiteralSyncMethod = Literal["index", "value"]