@quartic/bokehjs
Version:
Interactive, novel data visualization
77 lines (63 loc) • 2.04 kB
text/coffeescript
import {InspectTool, InspectToolView} from "./inspect_tool"
import {Span} from "../../annotations/span"
import * as p from "core/properties"
import {values} from "core/util/object"
export class CrosshairToolView extends InspectToolView
_move: (e) ->
if not .active
return
frame = .frame
canvas = .canvas
vx = canvas.sx_to_vx(e.bokeh.sx)
vy = canvas.sy_to_vy(e.bokeh.sy)
if not frame.contains(vx, vy)
vx = vy = null
(vx, vy)
_move_exit: (e) ->
(null, null)
_update_spans: (x, y) ->
dims = .dimensions
if dims in ['width', 'both'] then .spans.width.computed_location = y
if dims in ['height', 'both'] then .spans.height.computed_location = x
export class CrosshairTool extends InspectTool
default_view: CrosshairToolView
type: "CrosshairTool"
tool_name: "Crosshair"
icon: "bk-tool-icon-crosshair"
{
dimensions: [ p.Dimensions, "both" ]
line_color: [ p.Color, 'black' ]
line_width: [ p.Number, 1 ]
line_alpha: [ p.Number, 1.0 ]
}
{
location_units: [ p.SpatialUnits, "screen" ]
render_mode: [ p.RenderMode, "css" ]
spans: [ p.Any ]
}
{
tooltip: () -> ("Crosshair", )
synthetic_renderers: () -> values()
}
initialize: (attrs, options) ->
super(attrs, options)
= {
width: new Span({
for_hover: true
dimension: "width",
render_mode:
location_units:
line_color:
line_width:
line_alpha:
}),
height: new Span({
for_hover: true
dimension: "height"
render_mode:
location_units:
line_color:
line_width:
line_alpha:
})
}