浏览代码

serve highcharts and aggrid libraries only if chart or table elements have been added to the UI

Falko Schindler 2 年之前
父节点
当前提交
2216e6455b
共有 3 个文件被更改,包括 9 次插入5 次删除
  1. 4 0
      nicegui/elements/chart.py
  2. 4 0
      nicegui/elements/table.py
  3. 1 5
      nicegui/ui.py

+ 4 - 0
nicegui/elements/chart.py

@@ -4,8 +4,11 @@ import justpy as jp
 
 
 from .element import Element
 from .element import Element
 
 
+jp.template_options['highcharts'] = False
+
 
 
 class Chart(Element):
 class Chart(Element):
+
     def __init__(self, options: Dict):
     def __init__(self, options: Dict):
         """Chart
         """Chart
 
 
@@ -15,4 +18,5 @@ class Chart(Element):
         """
         """
         view = jp.HighCharts(temp=False)
         view = jp.HighCharts(temp=False)
         view.options = self.options = jp.Dict(**options)
         view.options = self.options = jp.Dict(**options)
+        jp.template_options['highcharts'] = True
         super().__init__(view)
         super().__init__(view)

+ 4 - 0
nicegui/elements/table.py

@@ -4,8 +4,11 @@ import justpy as jp
 
 
 from .element import Element
 from .element import Element
 
 
+jp.template_options['aggrid'] = False
+
 
 
 class Table(Element):
 class Table(Element):
+
     def __init__(self, options: Dict):
     def __init__(self, options: Dict):
         """Table
         """Table
 
 
@@ -15,4 +18,5 @@ class Table(Element):
         """
         """
         view = jp.AgGrid(temp=False)
         view = jp.AgGrid(temp=False)
         view.options = self.options = jp.Dict(**options)
         view.options = self.options = jp.Dict(**options)
+        jp.template_options['aggrid'] = True
         super().__init__(view)
         super().__init__(view)

+ 1 - 5
nicegui/ui.py

@@ -8,12 +8,11 @@ class Ui:
     # _excludes = [word.strip().lower() for word in globals.config.exclude.split(',')]
     # _excludes = [word.strip().lower() for word in globals.config.exclude.split(',')]
     # _excludes = [e[:-3] if e.endswith('.js') else e for e in _excludes]  # NOTE: for python <3.9 without removesuffix
     # _excludes = [e[:-3] if e.endswith('.js') else e for e in _excludes]  # NOTE: for python <3.9 without removesuffix
     _excludes = []
     _excludes = []
-    os.environ['HIGHCHARTS'] = str('highcharts' not in _excludes)
-    os.environ['AGGRID'] = str('aggrid' not in _excludes)
 
 
     from .elements.button import Button as button
     from .elements.button import Button as button
     from .elements.card import Card as card
     from .elements.card import Card as card
     from .elements.card import CardSection as card_section
     from .elements.card import CardSection as card_section
+    from .elements.chart import Chart as chart
     from .elements.checkbox import Checkbox as checkbox
     from .elements.checkbox import Checkbox as checkbox
     from .elements.color_input import ColorInput as color_input
     from .elements.color_input import ColorInput as color_input
     from .elements.color_picker import ColorPicker as color_picker
     from .elements.color_picker import ColorPicker as color_picker
@@ -54,9 +53,6 @@ class Ui:
     if 'custom_example' not in _excludes:
     if 'custom_example' not in _excludes:
         from .elements.custom_example import CustomExample as custom_example
         from .elements.custom_example import CustomExample as custom_example
 
 
-    if 'highcharts' not in _excludes:
-        from .elements.chart import Chart as chart
-
     if 'interactive_image' not in _excludes:
     if 'interactive_image' not in _excludes:
         from .elements.interactive_image import InteractiveImage as interactive_image
         from .elements.interactive_image import InteractiveImage as interactive_image