@quartic/bokehjs
Version:
Interactive, novel data visualization
113 lines (93 loc) • 3.09 kB
text/coffeescript
import {Annotation, AnnotationView} from "./annotation"
import {show, hide} from "core/dom"
import * as p from "core/properties"
export class SpanView extends AnnotationView
initialize: (options) ->
super(options)
.canvas_overlays.appendChild()
.style.position = "absolute"
hide()
bind_bokeh_events: () ->
if .for_hover
(, 'change:computed_location', )
else
if .render_mode == 'canvas'
(, 'change', .request_render)
(, 'change:location', .request_render)
else
(, 'change', )
(, 'change:location', )
render: () ->
if not .visible and .render_mode == 'css'
hide()
if not .visible
return
()
_draw_span: () ->
if .for_hover
loc = .computed_location
else
loc = .location
if not loc?
hide()
return
frame = .frame
canvas = .canvas
xmapper = .frame.x_mappers[.x_range_name]
ymapper = .frame.y_mappers[.y_range_name]
if .dimension == 'width'
stop = canvas.vy_to_sy((loc, ymapper))
sleft = canvas.vx_to_sx(frame.left)
width = frame.width
height = .properties.line_width.value()
else
stop = canvas.vy_to_sy(frame.top)
sleft = canvas.vx_to_sx((loc, xmapper))
width = .properties.line_width.value()
height = frame.height
if .render_mode == "css"
.style.top = "#{stop}px"
.style.left = "#{sleft}px"
.style.width = "#{width}px"
.style.height = "#{height}px"
.style.zIndex = 1000
.style.backgroundColor = .properties.line_color.value()
.style.opacity = .properties.line_alpha.value()
show()
else if .render_mode == "canvas"
ctx = .canvas_view.ctx
ctx.save()
ctx.beginPath()
.line.set_value(ctx)
ctx.moveTo(sleft, stop)
if .dimension == "width"
ctx.lineTo(sleft + width, stop)
else
ctx.lineTo(sleft, stop + height)
ctx.stroke()
ctx.restore()
_calc_dim: (location, mapper) ->
if .location_units == 'data'
vdim = mapper.map_to_target(location)
else
vdim = location
return vdim
export class Span extends Annotation
default_view: SpanView
type: 'Span'
['line']
{
render_mode: [ p.RenderMode, 'canvas' ]
x_range_name: [ p.String, 'default' ]
y_range_name: [ p.String, 'default' ]
location: [ p.Number, null ]
location_units: [ p.SpatialUnits, 'data' ]
dimension: [ p.Dimension, 'width' ]
}
{
line_color: 'black'
}
{
for_hover: [ p.Boolean, false ]
computed_location: [ p.Number, null ]
}