@quartic/bokehjs
Version:
Interactive, novel data visualization
84 lines (67 loc) • 2.06 kB
text/coffeescript
import {XYGlyph, XYGlyphView} from "./xy_glyph"
import * as p from "core/properties"
export class OvalView extends XYGlyphView
_set_data: () ->
= 0
if .properties.width.units == "data"
= /2
= 0
if .properties.height.units == "data"
= /2
_map_data: () ->
if .properties.width.units == "data"
= (.xmapper, , , 'center')
else
=
if .properties.height.units == "data"
= (.ymapper, , , 'center')
else
=
_render: (ctx, indices, {sx, sy, sw, sh}) ->
for i in indices
if isNaN(sx[i]+sy[i]+sw[i]+sh[i]+[i])
continue
ctx.translate(sx[i], sy[i])
ctx.rotate([i])
ctx.beginPath()
ctx.moveTo(0, -sh[i]/2)
ctx.bezierCurveTo( sw[i]/2, -sh[i]/2, sw[i]/2, sh[i]/2, 0, sh[i]/2)
ctx.bezierCurveTo(-sw[i]/2, sh[i]/2, -sw[i]/2, -sh[i]/2, 0, -sh[i]/2)
ctx.closePath()
if .fill.doit
.fill.set_vectorize(ctx, i)
ctx.fill()
if .line.doit
.line.set_vectorize(ctx, i)
ctx.stroke()
ctx.rotate(-[i])
ctx.translate(-sx[i], -sy[i])
draw_legend_for_index: (ctx, x0, x1, y0, y1, index) ->
indices = [index]
sx = { }
sx[index] = (x0+x1)/2
sy = { }
sy[index] = (y0+y1)/2
scale = [index] / [index]
d = Math.min(Math.abs(x1-x0), Math.abs(y1-y0)) * 0.8
sw = { }
sh = { }
if scale > 1
sw[index] = d
sh[index] = d/scale
else
sw[index] = d*scale
sh[index] = d
data = {sx, sy, sw, sh}
(ctx, indices, data)
_bounds: (bds) ->
return (bds)
export class Oval extends XYGlyph
default_view: OvalView
type: 'Oval'
['line', 'fill']
{
angle: [ p.AngleSpec, 0.0 ]
width: [ p.DistanceSpec ]
height: [ p.DistanceSpec ]
}