@quartic/bokehjs
Version:
Interactive, novel data visualization
106 lines (88 loc) • 3.25 kB
text/coffeescript
import {TextAnnotation, TextAnnotationView} from "./text_annotation"
import {hide} from "core/dom"
import * as p from "core/properties"
import * as Visuals from "core/visuals"
export class TitleView extends TextAnnotationView
initialize: (options) ->
super(options)
.text = new Visuals.Text()
# Use side_panel heuristics to determine unset text props
ctx = .canvas_view.ctx
ctx.save()
.panel.apply_label_text_heuristics(ctx, 'justified')
.text_baseline = ctx.textBaseline
.text_align = .align
ctx.restore()
_get_computed_location: () ->
[width, height] =
switch .panel.side
when 'left'
vx = 0
vy = + .offset
when 'right'
vx = .right - 1 #fudge factor due to error in text height measurement
vy = .height - - .offset
when 'above'
vx = + .offset
vy = .top - 10 # Corresponds to the +10 added in get_size
when 'below'
vx = + .offset
vy = 0
sx = .vx_to_sx(vx)
sy = .vy_to_sy(vy)
return [sx, sy]
_get_text_location: (alignment, range) ->
switch alignment
when 'left'
text_location = range.start
when 'center'
text_location = (range.end + range.start)/2
when 'right'
text_location = range.end
return text_location
render: () ->
if not .visible and .render_mode == 'css'
hide()
if not .visible
return
angle = .panel.get_label_angle_heuristic('parallel')
[sx, sy] =
ctx = .canvas_view.ctx
if .text == "" or .text == null
return
if .render_mode == 'canvas'
else
_get_size: () ->
text = .text
if text == "" or text == null
return 0
else
ctx = .canvas_view.ctx
.text.set_value(ctx)
return ctx.measureText(text).ascent + 10
export class Title extends TextAnnotation
default_view: TitleView
type: 'Title'
['line:border_', 'fill:background_']
{
text: [ p.String, ]
text_font: [ p.Font, 'helvetica' ]
text_font_size: [ p.FontSizeSpec, '10pt' ]
text_font_style: [ p.FontStyle, 'bold' ]
text_color: [ p.ColorSpec, '#444444' ]
text_alpha: [ p.NumberSpec, 1.0 ]
align: [ p.TextAlign, 'left' ]
offset: [ p.Number, 0 ]
render_mode: [ p.RenderMode, 'canvas' ]
}
{
background_fill_color: null
border_line_color: null
}
# these are set by heuristics
{
text_align: [ p.TextAlign, 'left' ]
text_baseline: [ p.TextBaseline, 'bottom' ]
}