@quartic/bokehjs
Version:
Interactive, novel data visualization
92 lines (71 loc) • 3.07 kB
text/coffeescript
import {RBush} from "core/util/spatial"
import {Glyph, GlyphView} from "./glyph"
import {CategoricalMapper} from "../mappers/categorical_mapper"
import * as hittest from "core/hittest"
export class QuadView extends GlyphView
_index_data: () ->
map_to_synthetic = (mapper, array) ->
if mapper instanceof CategoricalMapper
mapper.v_map_to_target(array, true)
else
array
left = map_to_synthetic(.xmapper, )
right = map_to_synthetic(.xmapper, )
top = map_to_synthetic(.ymapper, )
bottom = map_to_synthetic(.ymapper, )
points = []
for i in [0...left.length]
l = left[i]
r = right[i]
t = top[i]
b = bottom[i]
if isNaN(l+r+t+b) or not isFinite(l+r+t+b)
continue
points.push({minX: l, minY: b, maxX: r, maxY: t, i: i})
return new RBush(points)
_render: (ctx, indices, {sleft, sright, stop, sbottom}) ->
for i in indices
if isNaN(sleft[i]+stop[i]+sright[i]+sbottom[i])
continue
if .fill.doit
.fill.set_vectorize(ctx, i)
ctx.fillRect(sleft[i], stop[i], sright[i]-sleft[i], sbottom[i]-stop[i])
if .line.doit
ctx.beginPath()
ctx.rect(sleft[i], stop[i], sright[i]-sleft[i], sbottom[i]-stop[i])
.line.set_vectorize(ctx, i)
ctx.stroke()
_hit_point: (geometry) ->
[vx, vy] = [geometry.vx, geometry.vy]
x = .xmapper.map_from_target(vx, true)
y = .ymapper.map_from_target(vy, true)
hits = .indices({minX: x, minY: y, maxX: x, maxY: y})
result = hittest.create_hit_test_result()
result['1d'].indices = hits
return result
get_anchor_point: (anchor, i, spt) ->
left = Math.min([i], [i])
right = Math.max([i], [i])
top = Math.min([i], [i]) # screen coordinates !!!
bottom = Math.max([i], [i]) #
switch anchor
when 'top_left' then {x: left, y: top }
when 'top_center' then {x: (left + right)/2, y: top }
when 'top_right' then {x: right, y: top }
when 'center_right' then {x: right, y: (top + bottom)/2 }
when 'bottom_right' then {x: right, y: bottom }
when 'bottom_center' then {x: (left + right)/2, y: bottom }
when 'bottom_left' then {x: left, y: bottom }
when 'center_left' then {x: left, y: (top + bottom)/2 }
when 'center' then {x: (left + right)/2, y: (top + bottom)/2 }
scx: (i) ->
return ([i] + [i])/2
scy: (i) ->
return ([i] + [i])/2
draw_legend_for_index: (ctx, x0, x1, y0, y1, index) ->
export class Quad extends Glyph
default_view: QuadView
type: 'Quad'
[['right', 'bottom'], ['left', 'top']]
['line', 'fill']