Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 17th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var width = $('svg').width();
  2. var height = $('svg').height();
  3. var svg = d3.select('svg');
  4. var g = svg.append('g');
  5. var branches = [];
  6. var line;
  7. var trunk;
  8. var createLeftBranch;
  9.  
  10. svg
  11.   .attr('width', width)
  12.   .attr('height', height);
  13.  
  14. line = d3.svg.line()
  15.   .x(function(d) { return d.x; })
  16.   .y(function(d) { return d.y; })
  17.   .interpolate('basis');
  18.  
  19. trunk = [
  20.   { 'x': width/2, 'y': height },
  21.   { 'x': width/2, 'y': height - 100 }
  22. ];
  23.  
  24. branches.push(trunk);
  25.  
  26. createLeftBranch = function(parent) {
  27.  
  28.   var branch = [
  29.     { 'x': 0, 'y': 1 },
  30.     { 'x': 0, 'y': 10 }
  31.   ];
  32.  
  33.   return branch;
  34.  
  35. };
  36.  
  37. branches.push(createLeftBranch(trunk));
  38.  
  39. g.selectAll('path')
  40.   .data(branches)
  41.   .enter().append('path')
  42.   .attr('d', line)
  43.   .style('stroke-width', 10);