<commit_before>colors = require './colors'
d3 = require 'd3'
_ = require 'underscore'
moment = require 'moment'
Bacon = require 'bacon.model'
Q = require 'q'

clearExtent = (v) -> _.extend {}, v, {extent: null}
setBrushing = (v) -> _.extend {}, v, {brushing: true}
setNotBrushing = (v) -> _.extend {}, v, {brushing: false}

expandIsolatedValuesToLineSegments = (values) ->
  result = []
  segmentLength = 0
  previous = null
  _.each values, (v, i) ->
    if v.value?
      segmentLength++
      previous = v
    else
      if segmentLength is 1
        result.push previous
      segmentLength = 0

    result.push v

  if segmentLength is 1
    result.push previous
  result

simplifyPoints = (minDistance, values) ->
  previous = null
  result = []

  _.each values, (v) ->
    if previous?
      if previous.y? != v.y? # discontinuity
        result.push v
        if v.y?
          previous = v
      else if v.y?
        deltaX = Math.abs v.x - previous.x
        deltaY = Math.abs v.y - previous.y
        if Math.sqrt(deltaX * deltaX + deltaY * deltaY) > minDistance
          previous = v
          result.push v
    else
      previous = v
      result.push v

  result

invisibility = (sel, invisible) ->
  if invisible
    sel.attr('visibility', 'hidden')
  else
    sel.attr('visibility', 'visible')

defaultParams =
  width: 800
  height: 400
  type: 'line'
  get_value: (dp) -> dp[1]
  get_timestamp: (dp) -> dp[0]
  d3_colors: colors.d3.category10
  areaAlpha: 1.0
  bgcolor: '#fff'
  areaMode: 'none'
  areaOffset: 'zero'
  drawNullAsZero: false
  simplify: 0.5
  axisLineColor: '#ccc'
  axisTextColor: '#aaa'
  axisTextSize: '10px'
  crosshairLineColor: '#ddd'
  crosshairTextColor: '#aaa'
  crosshairTextSize: '10px'
  crosshairValueTextColor: '#aaa'
  brushColor: '#efefef'
  valueFormat: d3.format(',.4g')
  hideAxes: false
  hideLegend: false
  hideXAxis: false
  hideYAxis: false
  title: null
  titleTextSize: '12px'
  #lineWidth: 1

fgColorParams = ['axisLineColor', 'axisTextColor', 'crosshairLineColor', 'crosshairTextColor']

pathStyles =
  line:
    fill: 'none'
    'stroke-linecap': 'square'

create = (container) ->
  x = d3.time.scale()
  y = d3.scale.linear()
  xAxis = d3.svg.axis().scale(x).orient('bottom')
  yAxis = d3.svg.axis().scale(y).orient('left')

  color = d3.scale.ordinal()

  mouseOver = new Bacon.Bus
  mouseOut = new Bacon.Bus
  clicks = new Bacon.Bus
  mouseMoves = new Bacon.Bus

  area = d3.svg.area()
    .x((d) -> d.x)
    .y0((d) -> y d.y0 ? 0)
    .y1((d) -> y d.value + (d.y0 ? 0))
    .defined((d) -> d.value?)

  line = d3.svg.line()
    .x((d) -> d.x)
    .y((d) -> y d.value)
    .defined((d) -> d.value?)

  stack = d3.layout.stack()
    .values((d) -> d.values)
    .x((d) -> d.time)
    .y((d) -> d.value)
    .out((d, y0, y) ->
      d.y0 = y0
      d.value = y)

  svg = d3.select(container)
    .append('svg')
    .style({'font-family': '"Helvetica Neue"'})
    .on('mousemove', (d, i) -> mouseMoves.push d3.mouse g.node())

  title = svg.append('text')
    .style('text-anchor', 'middle')

  # TODO font
  g = svg
    .append("g")

  xAxisG = g.append('g')
    .attr('class', 'x axis')

  yAxisG = g.append('g')
    .attr('class', 'y axis')

  verticalCrosshair = g.append('line')
    .attr('class', 'crosshair')
    .attr('y1', 0)

  crosshairTime = g.append('text')
    .style('text-anchor', 'middle')
    .attr('y', -6)

  brushG = g.append("g")
    .attr("class", "x brush")

  legend = d3.select(container).append('ul')
    .attr('class', 'legend')

  currentCrosshairTime = null
  allNames = []

  destroyFunctions = []
  destroy = -><commit_msg>crisp edges for crosshair<commit_after>colors = require './colors'
d3 = require 'd3'
_ = require 'underscore'
moment = require 'moment'
Bacon = require 'bacon.model'
Q = require 'q'

clearExtent = (v) -> _.extend {}, v, {extent: null}
setBrushing = (v) -> _.extend {}, v, {brushing: true}
setNotBrushing = (v) -> _.extend {}, v, {brushing: false}

expandIsolatedValuesToLineSegments = (values) ->
  result = []
  segmentLength = 0
  previous = null
  _.each values, (v, i) ->
    if v.value?
      segmentLength++
      previous = v
    else
      if segmentLength is 1
        result.push previous
      segmentLength = 0

    result.push v

  if segmentLength is 1
    result.push previous
  result

simplifyPoints = (minDistance, values) ->
  previous = null
  result = []

  _.each values, (v) ->
    if previous?
      if previous.y? != v.y? # discontinuity
        result.push v
        if v.y?
          previous = v
      else if v.y?
        deltaX = Math.abs v.x - previous.x
        deltaY = Math.abs v.y - previous.y
        if Math.sqrt(deltaX * deltaX + deltaY * deltaY) > minDistance
          previous = v
          result.push v
    else
      previous = v
      result.push v

  result

invisibility = (sel, invisible) ->
  if invisible
    sel.attr('visibility', 'hidden')
  else
    sel.attr('visibility', 'visible')

defaultParams =
  width: 800
  height: 400
  type: 'line'
  get_value: (dp) -> dp[1]
  get_timestamp: (dp) -> dp[0]
  d3_colors: colors.d3.category10
  areaAlpha: 1.0
  bgcolor: '#fff'
  areaMode: 'none'
  areaOffset: 'zero'
  drawNullAsZero: false
  simplify: 0.5
  axisLineColor: '#ccc'
  axisTextColor: '#aaa'
  axisTextSize: '10px'
  crosshairLineColor: '#ddd'
  crosshairTextColor: '#aaa'
  crosshairTextSize: '10px'
  crosshairValueTextColor: '#aaa'
  brushColor: '#efefef'
  valueFormat: d3.format(',.4g')
  hideAxes: false
  hideLegend: false
  hideXAxis: false
  hideYAxis: false
  title: null
  titleTextSize: '12px'
  #lineWidth: 1

fgColorParams = ['axisLineColor', 'axisTextColor', 'crosshairLineColor', 'crosshairTextColor']

pathStyles =
  line:
    fill: 'none'
    'stroke-linecap': 'square'

create = (container) ->
  x = d3.time.scale()
  y = d3.scale.linear()
  xAxis = d3.svg.axis().scale(x).orient('bottom')
  yAxis = d3.svg.axis().scale(y).orient('left')

  color = d3.scale.ordinal()

  mouseOver = new Bacon.Bus
  mouseOut = new Bacon.Bus
  clicks = new Bacon.Bus
  mouseMoves = new Bacon.Bus

  area = d3.svg.area()
    .x((d) -> d.x)
    .y0((d) -> y d.y0 ? 0)
    .y1((d) -> y d.value + (d.y0 ? 0))
    .defined((d) -> d.value?)

  line = d3.svg.line()
    .x((d) -> d.x)
    .y((d) -> y d.value)
    .defined((d) -> d.value?)

  stack = d3.layout.stack()
    .values((d) -> d.values)
    .x((d) -> d.time)
    .y((d) -> d.value)
    .out((d, y0, y) ->
      d.y0 = y0
      d.value = y)

  svg = d3.select(container)
    .append('svg')
    .style({'font-family': '"Helvetica Neue"'})
    .on('mousemove', (d, i) -> mouseMoves.push d3.mouse g.node())

  title = svg.append('text')
    .style('text-anchor', 'middle')

  # TODO font
  g = svg
    .append("g")

  xAxisG = g.append('g')
    .attr('class', 'x axis')

  yAxisG = g.append('g')
    .attr('class', 'y axis')

  verticalCrosshair = g.append('line')
    .attr('class', 'crosshair')
    .style('shape-rendering': 'crispEdges')
    .attr('y1', 0)

  crosshairTime = g.append('text')
    .style('text-anchor', 'middle')
    .attr('y', -6)

  brushG = g.append("g")
    .attr("class", "x brush")

  legend = d3.select(container).append('ul')
    .attr('class', 'legend')

  currentCrosshairTime = null
  allNames = []

  destroyFunctions = []
  destroy = ->
{'fraction_non_alphanumeric': 0.16945205479452055, 'fraction_numerical': 0.014794520547945205, 'mean_word_length': 2.6688442211055277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '2325148', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2709, 'n_words': 639}