# main.coffee

do ->

  # Create the SVG area.

  svg = d3.select('#chart').append('svg:svg')
    .attr('width',  350)
    .attr('height', 350)

  # Create the axes.

  axes        = {}
  axes.foo    = { angle:  0,  color: '#666',    title: 'foo'   }
  axes.bar    = { angle: 120,  color: '#666',  title: 'bar' }
  axes.baz    = { angle: 240,  color: '#666',   title: 'baz'  }

  axis.r_beg  =  20 for name, axis of axes
  axis.r_len  = 100 for name, axis of axes

  draw_axis(axis, svg) for name, axis of axes

  # Create the splines.

  edges1 = (['foo', Math.random(), 
            'bar', Math.random(), 
            'rgba(0,0,0,0.05)'] for i in [1..300])
  edges2 = (['bar', Math.random(), 
            'baz', Math.sqrt(Math.random()), 
            'rgba(0,0,0,0.05)'] for i in [1..300])
  edges3 = (['baz', Math.sqrt(Math.random()), 
            'foo', Math.pow(Math.random(), 3),
            'rgba(0,0,0,0.05)'] for i in [1..300])

  edges = [].concat edges1, edges2, edges3

  # Figure out edge directions.

  edge.push( edge_dir(axes, edge) ) for edge in edges

  # Create some paths.

  cp_off  = 30  # control point offset, in pixels

  paths   = ( edge_path(edge, axes, cp_off) for edge in edges )

  df = d3.svg.line()
         .x( (d) -> d[0] )
         .y( (d) -> d[1] )
         .interpolate('cardinal')
         .tension(15)

  svg.selectAll('path.edge')
    .data(paths)
    .enter()
    .append('svg:path')
    .attr('d', df )
    .attr('stroke', (d,i) -> edges[i][4] )