<commit_before>import {ImagePool} from "./image_pool"
import {WMTSTileSource} from "./wmts_tile_source"
import {Renderer, RendererView} from "../renderers/renderer"
import {div} from "core/dom"
import * as p from "core/properties"
import {isString} from "core/util/types"

export class TileRendererView extends RendererView

  initialize: (options) ->
    @attributionEl = null
    @_tiles = []
    super

  connect_signals: () ->
    super()
    @connect(@model.change, () -> @request_render())

  get_extent: () ->
    return [@x_range.start, @y_range.start, @x_range.end, @y_range.end]

  _set_data: () ->
    @pool = new ImagePool()
    @map_plot = @plot_model.plot
    @map_canvas = @plot_view.canvas_view.ctx
    @map_frame = @plot_model.frame
    @x_range = @map_plot.x_range
    @y_range = @map_plot.y_range
    @extent = @get_extent()
    @_last_height = undefined
    @_last_width = undefined

  _add_attribution: () =>
    attribution = @model.tile_source.attribution

    if isString(attribution) and attribution.length > 0
      if not @attributionEl?
        border_width = @map_plot.outline_line_width
        bottom_offset = @map_plot.min_border_bottom + border_width
        right_offset = @map_frame._right.value - @map_frame._width.value
        max_width = @map_frame._width.value - border_width
        @attributionEl = div({
          class: 'bk-tile-attribution'
          style: {
            position: 'absolute'
            bottom: "#{bottom_offset}px"
            right: "#{right_offset}px"
            'max-width': "#{max_width}px"
            'background-color': 'rgba(255,255,255,0.8)'
            'font-size': '9pt'
            'font-family': 'sans-serif'
          }
        })

        overlays = @plot_view.canvas_view.events_el
        overlays.appendChild(@attributionEl)

      @attributionEl.innerHTML = attribution

  _map_data: () ->
    @initial_extent = @get_extent()
    zoom_level = @model.tile_source.get_level_by_extent(@initial_extent, @map_frame._height.value, @map_frame._width.value)
    new_extent = @model.tile_source.snap_to_zoom(@initial_extent, @map_frame._height.value, @map_frame._width.value, zoom_level)
    @x_range.start = new_extent[0]
    @y_range.start = new_extent[1]
    @x_range.end = new_extent[2]
    @y_range.end = new_extent[3]
    @_add_attribution()

  _on_tile_load: (e) =>
    tile_data = e.target.tile_data
    tile_data.img = e.target
    tile_data.current = true
    tile_data.loaded = true
    @request_render()

  _on_tile_cache_load: (e) =><commit_msg>Align attribution to frame's lower right corner (#6868)<commit_after>import {ImagePool} from "./image_pool"
import {WMTSTileSource} from "./wmts_tile_source"
import {Renderer, RendererView} from "../renderers/renderer"
import {div} from "core/dom"
import * as p from "core/properties"
import {isString} from "core/util/types"

export class TileRendererView extends RendererView

  initialize: (options) ->
    @attributionEl = null
    @_tiles = []
    super

  connect_signals: () ->
    super()
    @connect(@model.change, () -> @request_render())

  get_extent: () ->
    return [@x_range.start, @y_range.start, @x_range.end, @y_range.end]

  _set_data: () ->
    @pool = new ImagePool()
    @map_plot = @plot_model.plot
    @map_canvas = @plot_view.canvas_view.ctx
    @map_frame = @plot_model.frame
    @x_range = @map_plot.x_range
    @y_range = @map_plot.y_range
    @extent = @get_extent()
    @_last_height = undefined
    @_last_width = undefined

  _add_attribution: () =>
    attribution = @model.tile_source.attribution

    if isString(attribution) and attribution.length > 0
      if not @attributionEl?
        right = @plot_model.canvas._right.value - @plot_model.frame._right.value
        bottom = @plot_model.frame._bottom.value
        max_width = @map_frame._width.value
        @attributionEl = div({
          class: 'bk-tile-attribution'
          style: {
            position: "absolute"
            bottom: "#{bottom}px"
            right: "#{right}px"
            'max-width': "#{max_width}px"
            padding: "2px"
            'background-color': 'rgba(255,255,255,0.8)'
            'font-size': '9pt'
            'font-family': 'sans-serif'
          }
        })

        overlays = @plot_view.canvas_view.events_el
        overlays.appendChild(@attributionEl)

      @attributionEl.innerHTML = attribution

  _map_data: () ->
    @initial_extent = @get_extent()
    zoom_level = @model.tile_source.get_level_by_extent(@initial_extent, @map_frame._height.value, @map_frame._width.value)
    new_extent = @model.tile_source.snap_to_zoom(@initial_extent, @map_frame._height.value, @map_frame._width.value, zoom_level)
    @x_range.start = new_extent[0]
    @y_range.start = new_extent[1]
    @x_range.end = new_extent[2]
    @y_range.end = new_extent[3]
    @_add_attribution()

  _on_tile_load: (e) =>
    tile_data = e.target.tile_data
    tile_data.img = e.target
    tile_data.current = true
    tile_data.loaded = true
    @request_render()

  _on_tile_cache_load: (e) =>
{'fraction_non_alphanumeric': 0.12926249008723237, 'fraction_numerical': 0.007731958762886598, 'mean_word_length': 3.078415521422797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6535712', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1740, 'n_words': 299}