コード例 #1
0
ファイル: test_base.py プロジェクト: yangluheng/datastudio
def test_base_init_funcs():
    c0 = Base({"width": "100px", "height": "200px"})
    eq_(c0.width, "100px")
    eq_(c0.height, "200px")

    c1 = Base(dict(width="110px", height="210px"))
    eq_(c1.width, "110px")
    eq_(c1.height, "210px")
コード例 #2
0
def test_base_init_funcs():
    c0 = Base({"width": "100px", "height": "200px"})
    eq_(c0.width, "100px")
    eq_(c0.height, "200px")

    c1 = Base(dict(width="110px", height="210px"))
    eq_(c1.width, "110px")
    eq_(c1.height, "210px")
    assert_not_in(c1.js_host, ['', None])
コード例 #3
0
def st_pyecharts(
    chart: Base,
    theme: Union[str, Dict] = "",
    events: Dict[str, str] = None,
    height: str = "300px",
    width: str = "100%",
    renderer: str = "canvas",
    key: str = None,
):
    """Display echarts chart from pyecharts instance
    :param chart: pyecharts instance. JS code should have been wrapped beforehand.
    :param theme: prebuilt theme as string, or object
    :param events: dictionary of mouse events to string JS functions. Don't wrap values with JsCode placeholder.
    :param height: height of div wrapper
    :param width: width of div wrapper
    :param renderer: choose canvas or svg
    :param key: assign a key to prevent component remounting
    :return: chart
    """
    options = json.dumps(chart.get_options(), default=default, ignore_nan=True)
    return st_echarts(
        options=json.loads(options),
        theme=theme,
        events=events,
        height=height,
        width=width,
        key=key,
        renderer=renderer,
    )
コード例 #4
0
def st_pyecharts(
    chart: Base,
    theme: Union[str, Dict] = "",
    events: Dict[str, str] = None,
    height: str = "300px",
    width: str = "100%",
    renderer: str = "canvas",
    key: str = None,
):
    """Display a PyECharts instance in Streamlit

    Parameters
    ----------
    chart: Base
        PyEcharts instance. JS code should have been wrapped beforehand.
    theme: str | Dict
        Prebuilt theme, or object defining theme
    events: Dict
        Dictionary of mouse events to string JS functions. 
        Don't wrap values with JsCode placeholder.
    height: str
        Height of ECharts chart
    width: Image
        Width of ECharts chart
    renderer: {'canvas', 'svg'}
        Renderer for displaying chart
    key: str
        An optional string to use as the unique key for the widget. 
        Assign a key so the component is not remount every time the script is rerun.
    """
    options = json.dumps(chart.get_options(), default=default, ignore_nan=True)
    return st_echarts(
        options=json.loads(options),
        theme=theme,
        events=events,
        height=height,
        width=width,
        key=key,
        renderer=renderer,
    )
コード例 #5
0
def test_base_add_functions():
    c = Base()
    c.add_js_funcs("console.log('hello')", "console.log('hello')")
    eq_(1, len(c.js_functions.items))
    eq_(["console.log('hello')"], c.js_functions.items)