Exemple #1
0
    def modify_doc(doc):
        plot = Plot(height=400,
                    width=400,
                    x_range=Range1d(0, 3),
                    y_range=Range1d(0, 3),
                    min_border=0)
        renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys'))
        tool = PolyEditTool(renderers=[renderer])
        psource = ColumnDataSource(dict(x=[], y=[]))
        prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10))
        tool.vertex_renderer = prenderer
        plot.add_tools(tool)
        plot.toolbar.active_multi = tool
        plot.toolbar_sticky = False
        div = Div(text='False')

        def cb(attr, old, new):
            try:
                if cds_data_almost_equal(new, expected):
                    div.text = 'True'
            except ValueError:
                return

        source.on_change('data', cb)
        code = RECORD("matches", "div.text")
        plot.add_tools(
            CustomAction(callback=CustomJS(args=dict(div=div), code=code)))
        doc.add_root(column(plot, div))
Exemple #2
0
def _make_plot():
    data = {"xs": [[1, 2], [1.6, 2.45]],
            "ys": [[1, 1], [1.5, 0.75]]}
    source = ColumnDataSource(data)
    plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
    renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys', line_width=10))
    tool = PolyEditTool(renderers=[renderer])
    psource = ColumnDataSource(dict(x=[], y=[]))
    prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10))
    tool.vertex_renderer = prenderer
    plot.add_tools(tool)
    plot.toolbar.active_multi = tool
    code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys")
    plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code)))
    plot.toolbar_sticky = False
    return plot