Explorar el Código

small improvements and corrections

Falko Schindler hace 1 año
padre
commit
02d50f47e4
Se han modificado 4 ficheros con 16 adiciones y 89 borrados
  1. 1 1
      nicegui/element.py
  2. 9 82
      nicegui/elements/chart.py
  3. 4 4
      nicegui/elements/scene.js
  4. 2 2
      nicegui/nicegui.py

+ 1 - 1
nicegui/element.py

@@ -312,7 +312,7 @@ class Element(Visibility):
         """
 
     def use_component(self, name: str) -> None:
-        """Register a *.js Vue component to be used by this element."""
+        """Register a ``*.js`` Vue component to be used by this element."""
         self.components.append(name)
 
     def use_library(self, name: str) -> None:

+ 9 - 82
nicegui/elements/chart.py

@@ -4,87 +4,14 @@ from typing import Dict, List
 from ..dependencies import register_library, register_vue_component
 from ..element import Element
 
-dependencies = [
-    'lib/highcharts/highcharts.js',
-    'lib/highcharts/highcharts-more.js',
-    'lib/highcharts/highcharts-3d.js',
-]
-optional_dependencies = [
-    'lib/highcharts/modules/sankey.js',
-    'lib/highcharts/modules/accessibility.js',
-    'lib/highcharts/modules/exporting.js',
-    'lib/highcharts/modules/export-data.js',
-    'lib/highcharts/modules/solid-gauge.js',
-    'lib/highcharts/modules/annotations-advanced.js',
-    'lib/highcharts/modules/annotations.js',
-    'lib/highcharts/modules/arc-diagram.js',
-    'lib/highcharts/modules/arrow-symbols.js',
-    'lib/highcharts/modules/boost-canvas.js',
-    'lib/highcharts/modules/boost.js',
-    'lib/highcharts/modules/broken-axis.js',
-    'lib/highcharts/modules/bullet.js',
-    'lib/highcharts/modules/coloraxis.js',
-    'lib/highcharts/modules/current-date-indicator.js',
-    'lib/highcharts/modules/datagrouping.js',
-    'lib/highcharts/modules/data.js',
-    'lib/highcharts/modules/debugger.js',
-    'lib/highcharts/modules/dependency-wheel.js',
-    'lib/highcharts/modules/dotplot.js',
-    'lib/highcharts/modules/draggable-points.js',
-    'lib/highcharts/modules/drag-panes.js',
-    'lib/highcharts/modules/drilldown.js',
-    'lib/highcharts/modules/dumbbell.js',
-    'lib/highcharts/modules/full-screen.js',
-    'lib/highcharts/modules/funnel.js',
-    'lib/highcharts/modules/gantt.js',
-    'lib/highcharts/modules/grid-axis.js',
-    'lib/highcharts/modules/heatmap.js',
-    'lib/highcharts/modules/histogram-bellcurve.js',
-    'lib/highcharts/modules/item-series.js',
-    'lib/highcharts/modules/lollipop.js',
-    'lib/highcharts/modules/marker-clusters.js',
-    'lib/highcharts/modules/networkgraph.js',
-    'lib/highcharts/modules/no-data-to-display.js',
-    'lib/highcharts/modules/offline-exporting.js',
-    'lib/highcharts/modules/oldie.js',
-    'lib/highcharts/modules/oldie-polyfills.js',
-    'lib/highcharts/modules/organization.js',
-    'lib/highcharts/modules/overlapping-datalabels.js',
-    'lib/highcharts/modules/parallel-coordinates.js',
-    'lib/highcharts/modules/pareto.js',
-    'lib/highcharts/modules/pathfinder.js',
-    'lib/highcharts/modules/pattern-fill.js',
-    'lib/highcharts/modules/price-indicator.js',
-    'lib/highcharts/modules/series-label.js',
-    'lib/highcharts/modules/series-on-point.js',
-    'lib/highcharts/modules/sonification.js',
-    'lib/highcharts/modules/static-scale.js',
-    'lib/highcharts/modules/stock.js',
-    'lib/highcharts/modules/stock-tools.js',
-    'lib/highcharts/modules/streamgraph.js',
-    'lib/highcharts/modules/sunburst.js',
-    'lib/highcharts/modules/tilemap.js',
-    'lib/highcharts/modules/timeline.js',
-    'lib/highcharts/modules/treegraph.js',
-    'lib/highcharts/modules/treegrid.js',
-    'lib/highcharts/modules/variable-pie.js',
-    'lib/highcharts/modules/variwide.js',
-    'lib/highcharts/modules/vector.js',
-    'lib/highcharts/modules/venn.js',
-    'lib/highcharts/modules/windbarb.js',
-    'lib/highcharts/modules/wordcloud.js',
-    'lib/highcharts/modules/xrange.js',
-    'lib/highcharts/modules/funnel3d.js',
-    'lib/highcharts/modules/heikinashi.js',
-    'lib/highcharts/modules/hollowcandlestick.js',
-    'lib/highcharts/modules/pyramid3d.js',
-    'lib/highcharts/modules/cylinder.js',
-]
 register_vue_component('chart', Path(__file__).parent / 'chart.js')
-for path in dependencies:
-    register_library(Path(path).stem, Path(__file__).parent / path)
-for path in optional_dependencies:
-    register_library(Path(path).stem, Path(__file__).parent / path)
+
+core_dependencies: List[Path] = []
+for path in sorted((Path(__file__).parent / 'lib' / 'highcharts').glob('*.js'), key=lambda p: p.stem):
+    register_library(path.stem, path)
+    core_dependencies.append(path)
+for path in sorted((Path(__file__).parent / 'lib' / 'highcharts' / 'modules').glob('*.js'), key=lambda p: p.stem):
+    register_library(path.stem, path)
 
 
 class Chart(Element):
@@ -108,8 +35,8 @@ class Chart(Element):
         self._props['options'] = options
         self._props['extras'] = extras
         self.use_component('chart')
-        for dependency in dependencies:
-            self.use_library(Path(dependency).stem)
+        for dependency in core_dependencies:
+            self.use_library(dependency.stem)
         for extra in extras:
             self.use_library(extra)
 

+ 4 - 4
nicegui/elements/scene.js

@@ -1,6 +1,6 @@
 import * as THREE from "three";
-import { CSS2DRenderer } from "CSS2DRenderer";
-import { CSS3DRenderer } from "CSS3DRenderer";
+import { CSS2DRenderer, CSS2DObject } from "CSS2DRenderer";
+import { CSS3DRenderer, CSS3DObject } from "CSS3DRenderer";
 import { OrbitControls } from "OrbitControls";
 import { STLLoader } from "STLLoader";
 
@@ -185,12 +185,12 @@ export default {
         const div = document.createElement("div");
         div.textContent = args[0];
         div.style.cssText = args[1];
-        mesh = new THREE.CSS2DObject(div);
+        mesh = new CSS2DObject(div);
       } else if (type == "text3d") {
         const div = document.createElement("div");
         div.textContent = args[0];
         div.style.cssText = "userSelect:none;" + args[1];
-        mesh = new THREE.CSS3DObject(div);
+        mesh = new CSS3DObject(div);
       } else if (type == "texture") {
         const url = args[0];
         const coords = args[1];

+ 2 - 2
nicegui/nicegui.py

@@ -47,8 +47,8 @@ def index(request: Request) -> Response:
 @app.get(f'/_nicegui/{__version__}' + '/library/{name}/{file}')
 def get_dependencies(name: str, file: str):
     if name in libraries and libraries[name]['path'].exists():
-        file = Path(libraries[name]['path'].parent, file)
-        if file.exists() and not file.is_dir():
+        filepath = Path(libraries[name]['path']).parent / file
+        if filepath.exists() and not filepath.is_dir():
             return FileResponse(file, media_type='text/javascript')
         return FileResponse(libraries[name]['path'], media_type='text/javascript')
     raise HTTPException(status_code=404, detail=f'dependency "{name}" not found')