@quartic/bokehjs
Version:
Interactive, novel data visualization
77 lines (59 loc) • 1.84 kB
text/coffeescript
import {Annotation, AnnotationView} from "./annotation"
import * as p from "core/properties"
export class PolyAnnotationView extends AnnotationView
bind_bokeh_events: () ->
# need to respond to either normal BB change events or silent
# "data only updates" that tools might want to use
render: (ctx) ->
if not .visible
return
xs = .xs
ys = .ys
if xs.length != ys.length
return null
if xs.length < 3 or ys.length < 3
return null
canvas = .canvas
ctx = .canvas_view.ctx
for i in [0...xs.length]
if .xs_units == 'screen'
vx = xs[i]
if .ys_units == 'screen'
vy = ys[i]
sx = canvas.vx_to_sx(vx)
sy = canvas.vy_to_sy(vy)
if i == 0
ctx.beginPath()
ctx.moveTo(sx, sy)
else
ctx.lineTo(sx, sy)
ctx.closePath()
if .line.doit
.line.set_value(ctx)
ctx.stroke()
if .fill.doit
.fill.set_value(ctx)
ctx.fill()
export class PolyAnnotation extends Annotation
default_view: PolyAnnotationView
type: "PolyAnnotation"
['line', 'fill']
{
xs: [ p.Array, [] ]
xs_units: [ p.SpatialUnits, 'data' ]
ys: [ p.Array, [] ]
ys_units: [ p.SpatialUnits, 'data' ]
x_range_name: [ p.String, 'default' ]
y_range_name: [ p.String, 'default' ]
}
{
fill_color: "#fff9ba"
fill_alpha: 0.4
line_color: "#cccccc"
line_alpha: 0.3
}
update:({xs, ys}) ->