<commit_before>TextAnnotation = require "./text_annotation"
p = require "../../core/properties"

class TitleView extends TextAnnotation.View
  initialize: (options) ->
    super(options)

    # Use side_panel heuristics to determine unset text props
    ctx = @plot_view.canvas_view.ctx
    @model.panel.apply_label_text_heuristics(ctx, 'justified')
    @mset('text_baseline', ctx.textBaseline)
    @mset('text_align', @mget('title_alignment'))

  _get_computed_location: () ->
    switch @model.panel.side
      when 'left'
        vx = 0
        vy = @_get_text_location(@mget('title_alignment'), 'height') + @mget('title_padding')
      when 'right'
        vx = @canvas.get('right')
        vy = @canvas.get('height') - @_get_text_location(@mget('title_alignment'), 'height') + @mget('title_padding')
      when 'above'
        vx = @_get_text_location(@mget('title_alignment'), 'width') + @mget('title_padding')
        vy = @canvas.get('top')
      when 'below'
        vx = @_get_text_location(@mget('title_alignment'), 'width') + @mget('title_padding')
        vy = 0

    sx = @canvas.vx_to_sx(vx)
    sy = @canvas.vy_to_sy(vy)
    return [sx, sy]

  _get_text_location: (alignment, canvas_dimension) ->
    switch alignment
      when 'left'
        text_location = 0
      when 'center'
        text_location = @canvas.get(canvas_dimension)/2
      when 'right'<commit_msg>Add padding to handle text height measurement error<commit_after>TextAnnotation = require "./text_annotation"
p = require "../../core/properties"

class TitleView extends TextAnnotation.View
  initialize: (options) ->
    super(options)

    # Use side_panel heuristics to determine unset text props
    ctx = @plot_view.canvas_view.ctx
    @model.panel.apply_label_text_heuristics(ctx, 'justified')
    @mset('text_baseline', ctx.textBaseline)
    @mset('text_align', @mget('title_alignment'))

  _get_computed_location: () ->
    switch @model.panel.side
      when 'left'
        vx = 0
        vy = @_get_text_location(@mget('title_alignment'), 'height') + @mget('title_padding')
      when 'right'
        vx = @canvas.get('right') - 1 #fudge factor due to error in text height measurement
        vy = @canvas.get('height') - @_get_text_location(@mget('title_alignment'), 'height') + @mget('title_padding')
      when 'above'
        vx = @_get_text_location(@mget('title_alignment'), 'width') + @mget('title_padding')
        vy = @canvas.get('top') - 1 #fudge factor due to error in text height measurement
      when 'below'
        vx = @_get_text_location(@mget('title_alignment'), 'width') + @mget('title_padding')
        vy = 0

    sx = @canvas.vx_to_sx(vx)
    sy = @canvas.vy_to_sy(vy)
    return [sx, sy]

  _get_text_location: (alignment, canvas_dimension) ->
    switch alignment
      when 'left'
        text_location = 0
      when 'center'
        text_location = @canvas.get(canvas_dimension)/2
      when 'right'
{'fraction_non_alphanumeric': 0.13826146475017112, 'fraction_numerical': 0.0034223134839151265, 'mean_word_length': 3.4021084337349397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4326583', 'n_tokens_mistral': 980, 'n_tokens_neox': 925, 'n_words': 200}