Exemple #1
0
def figure_constructor(tool, loader, node):
    #print('Figureeeee: /n')
    fig = loader.construct_mapping(node, deep=True)
    fmt = tool.formats.get('Figure', {})

    elements = fig.pop('elements', [])
    #print('Figureeeee2: /n', elements)
    cmds = []
    ref = fig.pop("ref", "")
    callback = fig.pop("on_change", [])
    axis = tool.formats.get("Axis", {})

    for key in fig:
        val = fig[key]
        #print('Figureeeee3: /n', val,key)
        if key in ['text', 'add_tools']:
            cmds.append((key, val))
        else:
            fmt[key] = val

    figure = Figure(**fmt)

    for key, cmd in cmds:
        if key == 'add_tools':
            figure.add_tools(*cmd)
        elif key == 'text':
            figure.text(*cmd.pop('loc'), **cmd)

    for element in elements:
        key = element.pop('kind')
        if key == 'line':
            line_fmt = tool.formats.get('Line', {})
            line_fmt.update(element)
            figure.line('x', 'y', **line_fmt)
            #print('PLOT LINE: ', line_fmt, line_fmt.update(element))
        elif key == 'circle':
            circle_fmt = tool.formats.get('Circle', {})
            circle_fmt.update(element)
            figure.circle('x', 'y', **circle_fmt)
        elif key == 'image':
            print('HElooooo!!')
            image_fmt = tool.formats.get('Image', {})
            image_fmt.update(element)
            figure.image('value', 'x', 'y', 'dw', 'dh', **image_fmt)
            #print('PLOT image: ', image_fmt, image_fmt.update(element))

    for attr, val in axis.items():
        #change axis attributes, hopefully
        setattr(figure.axis, attr, val)

    if ref:
        tool.refs[ref] = figure
    if callback:
        figure.on_change(*callback)

    yield figure
def setup_timeline_backend_parts(plot: figure,
                                 desc_label_source: ColumnDataSource) -> None:
    """

    :param plot:
    :param desc_label_source:
    :return:
    """
    start_date, end_date = plot.x_range.start, plot.x_range.end
    arrow_x = start_date + datetime.timedelta(days=180)

    # 補助線を引く
    plot.line([start_date, end_date], [1, 1], line_width=3, line_color='pink')
    plot.line([start_date, end_date], [0.5, 0.5],
              line_width=3,
              line_dash='dotted',
              line_color='pink')
    plot.line([start_date, end_date], [1.5, 1.5],
              line_width=3,
              line_dash='dotted',
              line_color='pink')

    # 矢印を表示する
    plot.add_layout(
        Arrow(end=VeeHead(size=15),
              line_color='black',
              x_start=arrow_x,
              y_start=1.4,
              x_end=arrow_x,
              y_end=1.1))
    plot.add_layout(
        Arrow(end=VeeHead(size=15),
              line_color='black',
              x_start=arrow_x,
              y_start=0.9,
              x_end=arrow_x,
              y_end=0.6))

    plot.text(source=desc_label_source,
              x='x',
              y='y',
              text='text',
              text_font_size='size',
              text_alpha=0.8)