<commit_before>#= require estimation_function

class @Chart
  @name = "unspecified"

  addLine: (line) =>
    @display.addLine(line)

  drawLines: =>
    @display.drawLines()

  drawLine: (line, dur) =>
    @display.drawLine(line, dur)

  getLines: =>
    @display.lines

class @LineChart extends Chart
  constructor: (options={}) ->
    boundaries = new Boundaries
      margin:
        top: 10
        right: 10
        bottom: 30
        left: 50
      total_width: 640
      total_height: 380
    @stepsX = options.stepsX ? data_angles
    @domainX = new Domain
      range: data_angles
      width: boundaries.width
    @domainY = new Domain
      range: measured_points
      height: boundaries.height
    axisX = new Axis(
      domain: @domainX)
    axisY = new Axis({domain: @domainY})
    @display = new Display
      select: "#detailview-1 .main"
      boundaries: boundaries
      xAxis: axisX
      yAxis: axisY
      name: "mainview"
    @lines = []


class @NavChart extends Chart
  constructor: (options) ->
    {@ticks, @boundaries, @domain, @quality, @name} = options
    @set_default_boundaries() if not @boundaries
    @calc_ticks() if not @ticks
    @axisX = new Axis({domain: @domain, ticks: @ticks})
    @axisY = new Axis({domain: @quality})
    @display = new Display
      select: "#navigation"
      boundaries: @boundaries
      xAxis: @axisX
      yAxis: @axisY
      name: @name
    # @domain.rangeband.on("mousemove", ->
    #   console.log(d3.mouse(this))
    # )
    @_current_position = options.startposition ? 10
    @current_x_value = @currX   #alias function
    @_x_values = @get_all_x_values(10)
    svg = d3.select("#navigation").selectAll("." + @name)
    svg.append("text")
      .data([@name])
      .attr("y", @boundaries.height + 50)
      .attr("x", @boundaries.total_width / 2)
      .text( (d) ->
        d
      )

  set_default_boundaries: =>
    @boundaries = new Boundaries
      width: 100
      height: 100
      margin:
        bottom: 10
        left: 60
        top: 10
        right: 20

  calc_ticks: =>
    
    r = @domain.range
    t = "a" + r[0] + r[1] # convert to text and get length of text
    l = t.length - 1
    lt = 11 - l

    @ticks = if lt > 2 then lt else 2
    console.log(t)

  current_position: (position = null) =>
    return @_current_position if position == null
    @_current_position = position

  currX: (pos = null) =>
    position = pos ? @current_position()
    @domain.value_at(position)

  get_all_x_values: =>
    @_x_values ? @domain.width_to_values(10)

  mousedown: (d,i) ->
    _overlay = @display.overlay[0][0]
    @current_position(d3.mouse(_overlay)[0])
    console.log(@current_position())

  mouseover: ->
    _overlay = @display.overlay[0][0]
    return d3.mouse(_overlay)[0]
    #@current_hover_position()


class @Domain
  constructor: (options={}) ->
    {@min, @max, @scaletype, @order} = options
    @name = options.name ? ""
    @range = options.range ? [@min, @max]
    @width = options.width ? 0
    @height = options.height ? 0
    @setup()

  setup: =>
    scaledefault = if @width then "linear" else "log"
    scaletyp = @scaletype ? scaledefault
    scale = d3.scale[scaletyp]().clamp(true)
    scale.base(10) if scaletyp == "log"
    @rangeband = scale.range([@height, @width])
    _range = d3.extent(@range)
    _range = [_range[1], _range[0]] if @order == "desc"
    @domain = @rangeband.domain(_range)
        

  orientation: =>
    if @height then "left" else "bottom"

  value_at: (position) =>
    @rangeband.invert(position)

  width_to_values: (modulo = 1)=>
    _values = []
    for i in [0..@width]
      if i % modulo == 0
        _values.push(@value_at(i))
    return _values


class @Boundaries
  constructor: (options={}) ->
    {@total_width, @total_height, @width, @height} = options
    @margin = options.margin ? {}
    @margin.top ?= 0
    @margin.bottom ?= 0
    @margin.left ?= 0
    @margin.right ?= 0
    @width ?= @total_width - @margin.left - @margin.right
    @height ?= @total_height - @margin.bottom - @margin.top
    @total_width ?= @width + @margin.left + @margin.right
    @total_height ?= @height + @margin.bottom + @margin.top



class @Axis
  constructor: (options={}) ->
    {@domain} = options
    @ticks = options.ticks ? 5
    @orientation = options.orientation ? @domain.orientation()
    @setup()

  setup: =>
    @axis =
      d3.svg.axis()
        .scale(@domain.domain)
        .ticks(@ticks)
        .orient(@orientation);

  value_at: (position) =>
    @domain.value_at(position)



class @Display
  constructor: (options={}) ->
    {@select, @boundaries, @xAxis, @yAxis} = options
    @name = options.name ? "undeclared"
    @lines = {}
    @setup()
    @create()
    
  setup: ->
    b = @boundaries
    @svg = d3.select(@select).append("svg")
    @view =
      @svg.attr("width", b.total_width)
      .attr("height", b.total_height)
      .attr("class", @name)
      .append("g")
      .attr(
        "transform",
        "translate(" +
        b.margin.left + "," +
        b.margin.top + ")");

    @overlay =
      @svg.append("rect")
        .attr("class", "overlay")<commit_msg>small thing<commit_after>#= require estimation_function

class @Chart
  @name = "unspecified"

  addLine: (line) =>
    @display.addLine(line)

  drawLines: =>
    @display.drawLines()

  drawLine: (line, dur) =>
    @display.drawLine(line, dur)

  getLines: =>
    @display.lines

class @LineChart extends Chart
  constructor: (options={}) ->
    boundaries = new Boundaries
      margin:
        top: 10
        right: 10
        bottom: 30
        left: 50
      total_width: 640
      total_height: 380
    @stepsX = options.stepsX ? data_angles
    @domainX = new Domain
      range: data_angles
      width: boundaries.width
    @domainY = new Domain
      range: measured_points
      height: boundaries.height
    axisX = new Axis(
      domain: @domainX)
    axisY = new Axis({domain: @domainY})
    @display = new Display
      select: "#detailview-1 .main"
      boundaries: boundaries
      xAxis: axisX
      yAxis: axisY
      name: "mainview"
    @lines = []


class @NavChart extends Chart
  constructor: (options) ->
    {@ticks, @boundaries, @domain, @quality, @name} = options
    @set_default_boundaries() if not @boundaries
    @calc_ticks() if not @ticks
    @axisX = new Axis({domain: @domain, ticks: @ticks})
    @axisY = new KAxis({domain: @quality})
    @display = new Display
      select: "#navigation"
      boundaries: @boundaries
      xAxis: @axisX
      yAxis: @axisY
      name: @name
    # @domain.rangeband.on("mousemove", ->
    #   console.log(d3.mouse(this))
    # )
    @_current_position = options.startposition ? 10
    @current_x_value = @currX   #alias function
    @_x_values = @get_all_x_values(10)
    svg = d3.select("#navigation").selectAll("." + @name)
    svg.append("text")
      .data([@name])
      .attr("y", @boundaries.height + 50)
      .attr("x", @boundaries.total_width / 2)
      .text( (d) ->
        d
      )

  set_default_boundaries: =>
    @boundaries = new Boundaries
      width: 100
      height: 100
      margin:
        bottom: 10
        left: 60
        top: 10
        right: 20

  calc_ticks: =>
    
    r = @domain.range
    t = "a" + r[0] + r[1] # convert to text and get length of text
    l = t.length - 1
    lt = 11 - l

    @ticks = if lt > 2 then lt else 2
    console.log(t)

  current_position: (position = null) =>
    return @_current_position if position == null
    @_current_position = position

  currX: (pos = null) =>
    position = pos ? @current_position()
    @domain.value_at(position)

  get_all_x_values: =>
    @_x_values ? @domain.width_to_values(10)

  mousedown: (d,i) ->
    _overlay = @display.overlay[0][0]
    @current_position(d3.mouse(_overlay)[0])
    console.log(@current_position())

  mouseover: ->
    _overlay = @display.overlay[0][0]
    return d3.mouse(_overlay)[0]
    #@current_hover_position()


class @Domain
  constructor: (options={}) ->
    {@min, @max, @scaletype, @order} = options
    @name = options.name ? ""
    @range = options.range ? [@min, @max]
    @width = options.width ? 0
    @height = options.height ? 0
    @setup()

  setup: =>
    scaledefault = if @width then "linear" else "log"
    scaletyp = @scaletype ? scaledefault
    scale = d3.scale[scaletyp]().clamp(true)
    scale.base(10) if scaletyp == "log"
    @rangeband = scale.range([@height, @width])
    _range = d3.extent(@range)
    _range = [_range[1], _range[0]] if @order == "desc"
    @domain = @rangeband.domain(_range)
        

  orientation: =>
    if @height then "left" else "bottom"

  value_at: (position) =>
    @rangeband.invert(position)

  width_to_values: (modulo = 1)=>
    _values = []
    for i in [0..@width]
      if i % modulo == 0
        _values.push(@value_at(i))
    return _values


class @Boundaries
  constructor: (options={}) ->
    {@total_width, @total_height, @width, @height} = options
    @margin = options.margin ? {}
    @margin.top ?= 0
    @margin.bottom ?= 0
    @margin.left ?= 0
    @margin.right ?= 0
    @width ?= @total_width - @margin.left - @margin.right
    @height ?= @total_height - @margin.bottom - @margin.top
    @total_width ?= @width + @margin.left + @margin.right
    @total_height ?= @height + @margin.bottom + @margin.top



class @Axis
  constructor: (options={}) ->
    {@domain} = options
    @ticks = options.ticks ? 5
    @orientation = options.orientation ? @domain.orientation()
    @setup()

  setup: =>
    @axis =
      d3.svg.axis()
        .scale(@domain.domain)
        .ticks(@ticks)
        .orient(@orientation)
        .tickFormat(@k_format);

  value_at: (position) =>
    @domain.value_at(position)


class @KAxis extends Axis
  constructor: (options={}) ->
    super(options)
    @k_format = d3.format("s")
    @axis.tickFormat(@k_format)




class @Display
  constructor: (options={}) ->
    {@select, @boundaries, @xAxis, @yAxis} = options
    @name = options.name ? "undeclared"
    @lines = {}
    @setup()
    @create()
    
  setup: ->
    b = @boundaries
    @svg = d3.select(@select).append("svg")
    @view =
      @svg.attr("width", b.total_width)
      .attr("height", b.total_height)
      .attr("class", @name)
      .append("g")
      .attr(
        "transform",
        "translate(" +
        b.margin.left + "," +
        b.margin.top + ")");

    @overlay =
      @svg.append("rect")
        .attr("class", "overlay")
{'fraction_non_alphanumeric': 0.15038240917782028, 'fraction_numerical': 0.014053537284894838, 'mean_word_length': 2.553328804347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 58, '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': '3095662', 'n_tokens_mistral': 3720, 'n_tokens_neox': 3537, 'n_words': 811}