kinegratii / django-echarts

基于pyecharts和django的可视化网站脚手架。
https://django-echarts.readthedocs.io/
MIT License
282 stars 75 forks source link

渲染图表时加载DJANGO_ECHARTS存在问题 #21

Closed myTeemo closed 6 years ago

myTeemo commented 6 years ago

1.在渲染多图表的时候,若添加词云,渲染对应的依赖js的时候,对应的百度资源无法使用,'http://echarts.baidu.com/asset/map/js/wordcloud.js ' 访问报404,也找不到wordcloud.js应该是echarts-wordcloud.mini.js,还望修正公共cdndependencies = merge_js_dependencies(*args) dependencies 为echarts和wordcloud

  1. 在获取echarts默认设置时存在无论怎么设置只加载默认DEFAULT_SETTINGS 具体方法为:
    
    def get_django_echarts_settings():
    project_echarts_settings = {k: v for k, v in DEFAULT_SETTINGS.items()}
    project_echarts_settings.update(getattr(settings, 'DJANGO_ECHARTS', {}))
    extra_settings = {
        'STATIC_URL': settings.STATIC_URL
    }
    settings_store = SettingsStore(
        echarts_settings=project_echarts_settings,
        extra_settings=extra_settings
    )
    return settings_store

```python 
class SettingsStore(object):
    def __init__(self, *, echarts_settings=None, extra_settings=None, **kwargs):
        # Pre check settings

        self._extra_settings = extra_settings or {}
        if  self._extra_settings.get('lib_js_host') == 'local_host':
            self._extra_settings['lib_js_host'] = echarts_settings['local_host']
        if  self._extra_settings.get('map_js_host') == 'local_host':
            self._extra_settings['map_js_host'] = echarts_settings['local_host']

        # Merge echarts settings
        self._settings = {**DEFAULT_SETTINGS, **self._extra_settings}

上述self._extra_settings的值一直是

extra_settings = {
        'STATIC_URL': settings.STATIC_URL
    }

我觉着如果本地有仓库的话应该为:

        if  echarts_settings.get('lib_js_host') == 'local_host':
            self._extra_settings['lib_js_host'] = echarts_settings['local_host']
        if  echarts_settings.get('map_js_host') == 'local_host':
            self._extra_settings['map_js_host'] = echarts_settings['local_host']

DJANGO_ECHARTS = {
    'echarts_version': '4.0.4',
    'renderer': 'svg',
    'lib_js_host': 'local_host',
    'map_js_host': 'local_host',
    'local_host': '/static/js' 本地设置
}

烦请您查看一下,如有误解,还望解答。谢谢

kinegratii commented 6 years ago
  1. 确实目前是一个 缺陷,预计下个系列版本修复。

通过设置 DJANGO_ECHARTS.js_names 解决。

比如

DJANGO_ECHARTS = {
    'echarts_version': '4.0.4',
    'renderer': 'svg',
    'lib_js_host': 'local_host',
    'map_js_host': 'local_host',
    'local_host': '/static/js',
    'js_urls': {
        'wordcloud': 'echarts-wordcloud.mini'
    } 
}