<commit_before>d3 = require 'd3'
rewind = require 'geojson-rewind'

class Stereonet
  constructor: (el)->
    @width = 500
    @height = @width
    @center = [@width/2, @height/2]

    @projection = d3.geo.azimuthalEquidistant()
      .clipAngle 90-1e-3
      .scale 150
      .translate @center
      .precision .1

    @path = d3.geo.path()
      .projection @projection

    graticule = d3.geo.graticule()

    @svg = d3.select el[0][0]
      .append "svg"
        .attr "viewBox", "0,0,500,500"
        .attr "width", @width
        .attr "height", @height

    @svg.append "path"
      .datum graticule
      .attr class:"graticule", d:@path

    @svg.append "path"
        .datum {type: "Sphere"}
        .attr class:"sphere", d:@path

    @frame = @svg.append 'g'
      .attr class: 'dataFrame'

  addData: (d, main=true)->
    newClass = if main then 'main' else 'component'
    coords = [d.upper, d.lower]
    data =
      type: 'Feature'
      geometry:
        type: 'Polygon'
        coordinates: coords
    @frame.append 'path'
      .datum rewind(data)
      .attr
        class: "errors #{newClass}"

    data =
      type: 'Feature'
      geometry:
        type: 'LineString'
        coordinates: d.nominal
    @frame.append 'path'
      .datum data
      .attr
        class: "nominal #{newClass}"
        #stroke: if main then 'rgb(255,0,0)' else 'rgb(100,100,100)'

  draw: =>
    @frame.selectAll 'path'
      .attr d: @path

module.exports = Stereonet<commit_msg>Dragging of stereonet<commit_after>d3 = require 'd3'
rewind = require 'geojson-rewind'

class Stereonet
  constructor: (el)->
    @width = 500
    @height = @width
    @center = [@width/2, @height/2]

    #d3.geo.azimuthalEquidistant()
    @projection = d3.geo.azimuthalEqualArea()
      .clipAngle 90-1e-3
      .scale 150
      .translate @center
      .precision .1

    @path = d3.geo.path()
      .projection @projection

    dragstarted = (d) ->
      #stopPropagation prevents dragging to "bubble up" which triggers same event for all elements below this object
      d3.event.sourceEvent.stopPropagation()
      d3.select @
        .classed 'dragging', true

    dragged = =>
      @projection.rotate [d3.event.x, -d3.event.y]
      @svg.selectAll('path').attr d: @path

    dragended = (d) ->
      d3.select @
        .classed 'dragging', false

    @drag = d3.behavior.drag()
      .origin =>
        r = @projection.rotate()
        {x: r[0], y: -r[1]}
      .on 'drag', dragged
      .on 'dragstart', dragstarted
      .on 'dragend', dragended

    graticule = d3.geo.graticule()

    @svg = d3.select el[0][0]
      .append "svg"
        .attr "viewBox", "0,0,500,500"
        .attr "width", @width
        .attr "height", @height
        .call @drag

    @svg.append "path"
      .datum graticule
      .attr class:"graticule", d:@path

    @svg.append "path"
        .datum {type: "Sphere"}
        .attr class:"sphere", d:@path

    @frame = @svg.append 'g'
      .attr class: 'dataFrame'

  addData: (d, main=true)->
    newClass = if main then 'main' else 'component'
    coords = [d.upper, d.lower]
    data =
      type: 'Feature'
      geometry:
        type: 'Polygon'
        coordinates: coords
    @frame.append 'path'
      .datum rewind(data)
      .attr
        class: "errors #{newClass}"

    data =
      type: 'Feature'
      geometry:
        type: 'LineString'
        coordinates: d.nominal
    @frame.append 'path'
      .datum data
      .attr
        class: "nominal #{newClass}"

  draw: =>
    @frame.selectAll 'path'
      .attr d: @path

module.exports = Stereonet
{'fraction_non_alphanumeric': 0.14118629908103592, 'fraction_numerical': 0.022556390977443608, 'mean_word_length': 2.091222030981067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1069886', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1240, 'n_words': 307}