@quartic/bokehjs
Version:
Interactive, novel data visualization
81 lines (63 loc) • 1.92 kB
text/coffeescript
import {SelectTool, SelectToolView} from "./select_tool"
import {PolyAnnotation} from "../../annotations/poly_annotation"
import * as p from "core/properties"
import {copy} from "core/util/array"
export class PolySelectToolView extends SelectToolView
initialize: (options) ->
super(options)
= {vx: [], vy: []}
_active_change: () ->
if not .active
_keyup: (e) ->
if e.keyCode == 13
_doubletap: (e)->
append = e.srcEvent.shiftKey ? false
_clear_data: () ->
= {vx: [], vy: []}
.overlay.update({xs:[], ys:[]})
_tap: (e) ->
canvas = .canvas
vx = canvas.sx_to_vx(e.bokeh.sx)
vy = canvas.sy_to_vy(e.bokeh.sy)
.vx.push(vx)
.vy.push(vy)
.overlay.update({xs: copy(.vx), ys: copy(.vy)})
_select: (vx, vy, final, append) ->
geometry = {
type: 'poly'
vx: vx
vy: vy
}
for r in .computed_renderers
ds = r.data_source
sm = ds.selection_manager
sm.select(@, .renderer_views[r.id], geometry, final, append)
.push_state('poly_select', {selection: .get_selection()})
return null
DEFAULT_POLY_OVERLAY = () -> new PolyAnnotation({
level: "overlay"
xs_units: "screen"
ys_units: "screen"
fill_color: "lightgrey"
fill_alpha: 0.5
line_color: "black"
line_alpha: 1.0
line_width: 2
line_dash: [4, 4]
})
export class PolySelectTool extends SelectTool
default_view: PolySelectToolView
type: "PolySelectTool"
tool_name: "Poly Select"
icon: "bk-tool-icon-polygon-select"
event_type: "tap"
default_order: 11
{
overlay: [ p.Instance, DEFAULT_POLY_OVERLAY ]
}