Source: EdgeSampling.js

  1. /**
  2. The function uses the given links ans samples it in defined steps. It returns an Array with the coordinates and the value of the link.
  3. @param {Array} selectedLinks The links which should be sampled
  4. @param {number} steps Steps (amount) in which the lines should be sampled
  5. @param {Array} linkValues Array of Values which the respective line should get
  6. (in Example the result of a Metric which can be used by the Heatmap)
  7. @return {Array} structure Array of objects with coordinates on the a svg and the corresponding value (comDistr) {x, y, comDistr}
  8. */
  9. function EdgeSampling(selectedLinks, steps, linkValues){
  10. var structure = [{x: 0, y: 0, comDistr: 0}];
  11. // Loop through all links
  12. for(var i = 0; i < selectedLinks.length; i++){
  13. var travelRatio_link = 100/(steps-1);// -1 because we start at the startpoint
  14. var link_x1 = parseFloat(d3.select(selectedLinks[i]).attr("x1"));
  15. var link_x2 = parseFloat(d3.select(selectedLinks[i]).attr("x2"));
  16. var link_y1 = parseFloat(d3.select(selectedLinks[i]).attr("y1"));
  17. var link_y2 = parseFloat(d3.select(selectedLinks[i]).attr("y2"));
  18. var link_currentX = link_x1; // Startvalues
  19. var link_currentY = link_y1; // Startvalues
  20. for(var j= 1; j <=steps; j++) {
  21. // Take Startpoint
  22. if (j != 1){
  23. link_currentX = link_x1 + (link_x2 - link_x1) * ( travelRatio_link/100);
  24. link_currentY = link_y1 + (link_y2 - link_y1) * (travelRatio_link/100);
  25. // Adds up to 100% of the range
  26. travelRatio_link += 100/(steps-1);
  27. }
  28. structure.push({x: link_currentX, y: link_currentY, comDistr: linkValues[i]});
  29. }
  30. }
  31. return structure;
  32. }