diff --git a/pynecone/.templates/web/bun.lockb b/pynecone/.templates/web/bun.lockb index 2deee3fa1..e2ee60e5e 100755 Binary files a/pynecone/.templates/web/bun.lockb and b/pynecone/.templates/web/bun.lockb differ diff --git a/pynecone/.templates/web/package.json b/pynecone/.templates/web/package.json index 6052c5774..82e38a378 100644 --- a/pynecone/.templates/web/package.json +++ b/pynecone/.templates/web/package.json @@ -6,9 +6,9 @@ "prod": "next start" }, "dependencies": { - "@chakra-ui/system": "1.12.1", "@chakra-ui/icons": "1.1.7", "@chakra-ui/react": "1.8.8", + "@chakra-ui/system": "1.12.1", "@emotion/react": "^11.9.0", "@emotion/styled": "^11.8.1", "axios": "^0.27.2", @@ -27,6 +27,7 @@ "rehype-katex": "^6.0.2", "rehype-raw": "^6.1.1", "remark-gfm": "^3.0.1", - "remark-math": "^5.1.1" + "remark-math": "^5.1.1", + "victory": "^36.6.8" } } diff --git a/pynecone/__init__.py b/pynecone/__init__.py index 23486b6f0..a96abf7cf 100644 --- a/pynecone/__init__.py +++ b/pynecone/__init__.py @@ -7,6 +7,7 @@ from .app import App from .base import Base from .components import * from .components.component import custom_component as component +from .components.graphing.victory import data from .config import Config from .constants import Env from .event import EventChain, console_log, redirect, window_alert @@ -14,4 +15,3 @@ from .middleware import Middleware from .model import Model, session from .state import ComputedVar as var from .state import State -from .components.graphing.victory import data diff --git a/pynecone/components/component.py b/pynecone/components/component.py index e2e6863b8..71f8ef11b 100644 --- a/pynecone/components/component.py +++ b/pynecone/components/component.py @@ -387,15 +387,24 @@ class Component(Base, ABC): self._get_imports(), *[child.get_imports() for child in self.children] ) - def get_custom_components(self) -> Set[CustomComponent]: + def get_custom_components( + self, seen: Optional[Set[str]] = None + ) -> Set[CustomComponent]: """Get all the custom components used by the component. + Args: + seen: The tags of the components that have already been seen. + Returns: The set of custom components. """ custom_components = set() + + # Store the seen components in a set to avoid infinite recursion. + if seen is None: + seen = set() for child in self.children: - custom_components |= child.get_custom_components() + custom_components |= child.get_custom_components(seen=seen) return custom_components @@ -479,17 +488,29 @@ class CustomComponent(Component): """ return set() - def get_custom_components(self) -> Set[CustomComponent]: + def get_custom_components( + self, seen: Optional[Set[str]] = None + ) -> Set[CustomComponent]: """Get all the custom components used by the component. + Args: + seen: The tags of the components that have already been seen. + Returns: The set of custom components. """ - return ( - {self} - | super().get_custom_components() - # | self.get_component().get_custom_components() - ) + assert self.tag is not None, "The tag must be set." + + # Store the seen components in a set to avoid infinite recursion. + if seen is None: + seen = set() + custom_components = {self} | super().get_custom_components(seen=seen) + + # Avoid adding the same component twice. + if self.tag not in seen: + seen.add(self.tag) + custom_components |= self.get_component().get_custom_components(seen=seen) + return custom_components def _render(self) -> Tag: """Define how to render the component in React. diff --git a/pynecone/components/graphing/__init__.py b/pynecone/components/graphing/__init__.py index fe2aa5bca..dd48762e7 100644 --- a/pynecone/components/graphing/__init__.py +++ b/pynecone/components/graphing/__init__.py @@ -2,19 +2,19 @@ from .plotly import Plotly from .victory import ( - Chart, - Line, - Scatter, Area, Bar, - Pie, - Polar, - Candlestick, BoxPlot, - Histogram, - ErrorBar, + Candlestick, + Chart, ChartGroup, ChartStack, + ErrorBar, + Histogram, + Line, + Pie, + Polar, + Scatter, Voronoi, ) diff --git a/pynecone/components/graphing/victory.py b/pynecone/components/graphing/victory.py index 4d0691ac3..2db2b48f7 100644 --- a/pynecone/components/graphing/victory.py +++ b/pynecone/components/graphing/victory.py @@ -1,6 +1,6 @@ """Victory graphing components.""" -from typing import Any, Dict, Union, List, Optional +from typing import Any, Dict, List, Optional, Union from pynecone.components.component import Component from pynecone.components.tags import Tag diff --git a/pynecone/var.py b/pynecone/var.py index d9c83f31f..00ceca54c 100644 --- a/pynecone/var.py +++ b/pynecone/var.py @@ -286,10 +286,10 @@ class Var(ABC): A var with the absolute value. Raises: - ValueError: If the var is not a list. + TypeError: If the var is not a list. """ if not utils._issubclass(self.type_, List): - raise ValueError(f"Cannot get length of non-list var {self}.") + raise TypeError(f"Cannot get length of non-list var {self}.") return BaseVar( name=f"{self.full_name}.length", type_=int, diff --git a/tests/components/graphing/test_victory_data.py b/tests/components/graphing/test_victory_data.py index 84d1390f2..f966347e3 100644 --- a/tests/components/graphing/test_victory_data.py +++ b/tests/components/graphing/test_victory_data.py @@ -2,13 +2,13 @@ from typing import List, Set, Type import pytest +from pynecone import data from pynecone.components.component import Component, CustomComponent, ImportDict from pynecone.components.layout.box import Box from pynecone.event import EVENT_TRIGGERS, EventHandler from pynecone.state import State from pynecone.style import Style from pynecone.var import Var -from pynecone import data x_num = [1, 2, 3, 4, 5] x_str = ["Cats", "Dogs", "Birds", "Fish", "Reptiles"]