Skip to content

Commit

Permalink
Added support for 3D graphing for echarts. (#3195)
Browse files Browse the repository at this point in the history
* update script to support import of echarts-gl

* added echarts-gl library

* modify element to import echarts-gl library

* added an example of 3D echarts graphing

* code review

---------

Co-authored-by: Falko Schindler <[email protected]>
  • Loading branch information
natankeddem and falkoschindler committed Jun 16, 2024
1 parent f0706ec commit 7e336b0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- aggrid: 30.2.0 ([MIT](https://opensource.org/licenses/MIT))
- codemirror: 6.0.1 ([MIT](https://opensource.org/licenses/MIT))
- echarts: 5.4.3 ([Apache-2.0](https://opensource.org/licenses/Apache-2.0))
- echarts-gl: 2.0.9 ([BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause))
- leaflet: 1.9.4 ([BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause))
- leaflet-draw: 1.0.4 ([MIT](https://opensource.org/licenses/MIT))
- mermaid: 10.5.1 ([MIT](https://opensource.org/licenses/MIT))
Expand Down
9 changes: 7 additions & 2 deletions nicegui/elements/echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
pass


class EChart(Element, component='echart.js', libraries=['lib/echarts/echarts.min.js']):
class EChart(Element, component='echart.js', libraries=['lib/echarts/echarts.min.js'], extra_libraries=['lib/echarts-gl/echarts-gl.min.js']):

def __init__(self, options: Dict, on_point_click: Optional[Callable] = None) -> None:
def __init__(self, options: Dict, on_point_click: Optional[Callable] = None, *, enable_3d: bool = False) -> None:
"""Apache EChart
An element to create a chart using `ECharts <https://echarts.apache.org/>`_.
Expand All @@ -28,10 +28,15 @@ def __init__(self, options: Dict, on_point_click: Optional[Callable] = None) ->
:param options: dictionary of EChart options
:param on_click_point: callback that is invoked when a point is clicked
:param enable_3d: enforce importing the echarts-gl library
"""
super().__init__()
self._props['options'] = options
self._classes.append('nicegui-echart')
for key in options:
if '3D' in key or enable_3d:
self.libraries.extend(library for library in self.extra_libraries if library.name == 'echarts-gl')
break

if on_point_click:
self.on_point_click(on_point_click)
Expand Down
1 change: 1 addition & 0 deletions nicegui/elements/lib/echarts-gl/echarts-gl.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions nicegui/elements/lib/echarts-gl/echarts-gl.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
"package/dist/": ""
}
},
"echarts-gl": {
"destination": "nicegui/elements/lib",
"keep": ["package/dist/echarts-gl\\.min\\.js", "package/dist/echarts-gl\\.js\\.map"],
"rename": {
"package/dist/": ""
}
},
"leaflet": {
"destination": "nicegui/elements/lib/leaflet",
"keep": [
Expand Down
8 changes: 7 additions & 1 deletion npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def download_buffered(url: str) -> Path:
DEPENDENCIES = (root_path / 'DEPENDENCIES.md').open('w')
DEPENDENCIES.write('# Included Web Dependencies\n\n')
KNOWN_LICENSES = {
'UNKNOWN': 'UNKNOWN',
'MIT': 'https://opensource.org/licenses/MIT',
'ISC': 'https://opensource.org/licenses/ISC',
'Apache-2.0': 'https://opensource.org/licenses/Apache-2.0',
'BSD-2-Clause': 'https://opensource.org/licenses/BSD-2-Clause',
'BSD-3-Clause': 'https://opensource.org/licenses/BSD-3-Clause',
}

# Create a hidden folder to work in.
Expand All @@ -78,7 +80,11 @@ def download_buffered(url: str) -> Path:
npm_data = json.loads(download_buffered(f'https://registry.npmjs.org/{package_name}').read_text())
npm_version = dependency.get('version') or dependency.get('version', npm_data['dist-tags']['latest'])
npm_tarball = npm_data['versions'][npm_version]['dist']['tarball']
license_ = npm_data['versions'][npm_version]['license']
license_ = 'UNKNOWN'
if 'license' in npm_data['versions'][npm_version]:
license_ = npm_data['versions'][npm_version]['license']
elif package_name == 'echarts-gl':
license_ = 'BSD-3-Clause'
print(f'{key}: {npm_version} - {npm_tarball} ({license_})')
DEPENDENCIES.write(f'- {key}: {npm_version} ([{license_}]({KNOWN_LICENSES.get(license_, license_)}))\n')

Expand Down
17 changes: 17 additions & 0 deletions website/documentation/content/echart_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@ def events_demo() -> None:
label = ui.label()


@doc.demo('3D Graphing', '''
Charts will automatically be 3D enabled if the initial options contain the string "3D".
If not, set the `enable_3d` argument to `True`.
''')
def echarts_gl_demo() -> None:
ui.echart({
'xAxis3D': {},
'yAxis3D': {},
'zAxis3D': {},
'grid3D': {},
'series': [{
'type': 'line3D',
'data': [[1, 1, 1], [3, 3, 3]],
}],
})


doc.reference(ui.echart)

0 comments on commit 7e336b0

Please sign in to comment.