<commit_before>view = require("backbone-viewj")
mouse = require "mouse-pos"
selection = require "../g/selection/Selection"
jbone = require "jbone"
_ = require "underscore"

module.exports = OverviewBox = view.extend

  className: "biojs_msa_overviewbox"
  tagName: "canvas"

  initialize: (data) ->
    @g = data.g
    @listenTo @g.zoomer,"change:boxRectWidth change:boxRectHeight
    change:overviewboxPaddingTop", @rerender
    @listenTo @g.selcol, "add reset change", @rerender
    @listenTo @g.columns, "change:hidden", @rerender
    @listenTo @g.colorscheme, "change:showLowerCase", @rerender
    @listenTo @model, "change", _.debounce @rerender, 5

    # color
    @color = @g.colorscheme.getSelectedScheme()
    @listenTo @g.colorscheme, "change:scheme", ->
      @color = @g.colorscheme.getSelectedScheme()
      @rerender()
    @dragStart = []

  events:
    click: "_onclick"
    mousedown: "_onmousedown"

  rerender: ->
    unless @g.config.get "manualRendering"
      @render()

  render: ->
    @_createCanvas()
    @el.textContent = "overview"
    @el.style.marginTop = @g.zoomer.get "overviewboxPaddingTop"

    # background bg for non-drawed area
    @ctx.fillStyle = "#999999"
    @ctx.fillRect 0,0,@el.width,@el.height

    rectWidth = @g.zoomer.get "boxRectWidth"
    rectHeight = @g.zoomer.get "boxRectHeight"
    hidden = @g.columns.get "hidden"
    showLowerCase = @g.colorscheme.get "showLowerCase"

    y = -rectHeight
    for i in [0.. @model.length - 1] by 1
      seq = @model.at(i).get "seq"
      x = 0
      y = y + rectHeight


      if @model.at(i).get "hidden"
        # hidden seq
        console.log @model.at(i).get "hidden"
        @ctx.fillStyle = "grey"
        @ctx.fillRect 0,y,seq.length * rectWidth,rectHeight
        continue

      for j in [0.. seq.length - 1] by 1
        c = seq[j]
        # todo: optional uppercasing
        c = c.toUpperCase() if showLowerCase
        color = @color.getColor c, {pos: j}

        if hidden.indexOf(j) >= 0
          color = "grey"

        if color?
          @ctx.fillStyle = color
          @ctx.fillRect x,y,rectWidth,rectHeight

        x = x + rectWidth

    @_drawSelection()

  _drawSelection: ->
    # hide during selection
    return if @dragStart.length > 0 and not @prolongSelection

    rectWidth = @g.zoomer.get "boxRectWidth"
    rectHeight = @g.zoomer.get "boxRectHeight"
    maxHeight = rectHeight * @model.length
    @ctx.fillStyle = "#ffff00"
    @ctx.globalAlpha = 0.9
    for i in [0.. @g.selcol.length - 1] by 1
      sel = @g.selcol.at(i)
      if sel.get('type') is 'column'
        @ctx.fillRect rectWidth * sel.get('xStart'),0,rectWidth *
        (sel.get('xEnd') - sel.get('xStart') + 1),maxHeight
      else if sel.get('type') is 'row'
        seq = (@model.filter (el) -> el.get('id') is sel.get('seqId'))[0]
        pos = @model.indexOf(seq)
        @ctx.fillRect 0,rectHeight * pos, rectWidth * seq.get('seq').length, rectHeight
      else if sel.get('type') is 'pos'
        seq = (@model.filter (el) -> el.get('id') is sel.get('seqId'))[0]
        pos = @model.indexOf(seq)
        @ctx.fillRect rectWidth * sel.get('xStart'),rectHeight * pos, rectWidth * (sel.get('xEnd') - sel.get('xStart') + 1), rectHeight

    @ctx.globalAlpha = 1

  _onclick: (evt) ->
    @g.trigger "meta:click", {seqId: @model.get "id", evt:evt}

  _onmousemove: (e) ->
    # duplicate events
    return if @dragStart.length is 0

    @render()
    @ctx.fillStyle = "#ffff00"
    @ctx.globalAlpha = 0.9

    rect = @_calcSelection( mouse.abs e )<commit_msg>yellow boxes<commit_after>view = require("backbone-viewj")
mouse = require "mouse-pos"
selection = require "../g/selection/Selection"
jbone = require "jbone"
_ = require "underscore"

module.exports = OverviewBox = view.extend

  className: "biojs_msa_overviewbox"
  tagName: "canvas"

  initialize: (data) ->
    @g = data.g
    @listenTo @g.zoomer,"change:boxRectWidth change:boxRectHeight
    change:overviewboxPaddingTop", @rerender
    @listenTo @g.selcol, "add reset change", @rerender
    @listenTo @g.columns, "change:hidden", @rerender
    @listenTo @g.colorscheme, "change:showLowerCase", @rerender
    @listenTo @model, "change", _.debounce @rerender, 5

    # color
    @color = @g.colorscheme.getSelectedScheme()
    @listenTo @g.colorscheme, "change:scheme", ->
      @color = @g.colorscheme.getSelectedScheme()
      @rerender()
    @dragStart = []

  events:
    click: "_onclick"
    mousedown: "_onmousedown"

  rerender: ->
    unless @g.config.get "manualRendering"
      @render()

  render: ->
    @_createCanvas()
    @el.textContent = "overview"
    @el.style.marginTop = @g.zoomer.get "overviewboxPaddingTop"

    # background bg for non-drawed area
    @ctx.fillStyle = "#999999"
    @ctx.fillRect 0,0,@el.width,@el.height

    rectWidth = @g.zoomer.get "boxRectWidth"
    rectHeight = @g.zoomer.get "boxRectHeight"
    hidden = @g.columns.get "hidden"
    showLowerCase = @g.colorscheme.get "showLowerCase"

    y = -rectHeight
    for i in [0.. @model.length - 1] by 1
      seq = @model.at(i).get "seq"
      x = 0
      y = y + rectHeight


      if @model.at(i).get "hidden"
        # hidden seq
        console.log @model.at(i).get "hidden"
        @ctx.fillStyle = "grey"
        @ctx.fillRect 0,y,seq.length * rectWidth,rectHeight
        continue

      for j in [0.. seq.length - 1] by 1
        c = seq[j]
        # todo: optional uppercasing
        c = c.toUpperCase() if showLowerCase
        color = @color.getColor c, {pos: j}

        if hidden.indexOf(j) >= 0
          color = "grey"

        if color?
          @ctx.fillStyle = color
          @ctx.fillRect x,y,rectWidth,rectHeight

        x = x + rectWidth

    @_drawSelection()

  _drawSelection: ->
    # hide during selection
    return if @dragStart.length > 0 and not @prolongSelection

    rectWidth = @g.zoomer.get "boxRectWidth"
    rectHeight = @g.zoomer.get "boxRectHeight"
    maxHeight = rectHeight * @model.length
    @ctx.fillStyle = "#666666"
    @ctx.globalAlpha = 0.9
    for i in [0.. @g.selcol.length - 1] by 1
      sel = @g.selcol.at(i)
      if sel.get('type') is 'column'
        @ctx.fillRect rectWidth * sel.get('xStart'),0,rectWidth *
        (sel.get('xEnd') - sel.get('xStart') + 1),maxHeight
      else if sel.get('type') is 'row'
        seq = (@model.filter (el) -> el.get('id') is sel.get('seqId'))[0]
        pos = @model.indexOf(seq)
        @ctx.fillRect 0,rectHeight * pos, rectWidth * seq.get('seq').length, rectHeight
      else if sel.get('type') is 'pos'
        seq = (@model.filter (el) -> el.get('id') is sel.get('seqId'))[0]
        pos = @model.indexOf(seq)
        @ctx.fillRect rectWidth * sel.get('xStart'),rectHeight * pos, rectWidth * (sel.get('xEnd') - sel.get('xStart') + 1), rectHeight

    @ctx.globalAlpha = 1

  _onclick: (evt) ->
    @g.trigger "meta:click", {seqId: @model.get "id", evt:evt}

  _onmousemove: (e) ->
    # duplicate events
    return if @dragStart.length is 0

    @render()
    @ctx.fillStyle = "#666666"
    @ctx.globalAlpha = 0.9

    rect = @_calcSelection( mouse.abs e )
{'fraction_non_alphanumeric': 0.14927475003520632, 'fraction_numerical': 0.011829319814110688, 'mean_word_length': 2.7105538140020897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2107599', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2447, 'n_words': 559}