Graph database Analysis of the Steam Network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. ;(function() {
  2. 'use strict';
  3. sigma.utils.pkg('sigma.canvas.edgehovers');
  4. /**
  5. * This hover renderer will display the edge with a different color or size.
  6. *
  7. * @param {object} edge The edge object.
  8. * @param {object} source node The edge source node.
  9. * @param {object} target node The edge target node.
  10. * @param {CanvasRenderingContext2D} context The canvas context.
  11. * @param {configurable} settings The settings function.
  12. */
  13. sigma.canvas.edgehovers.parallel =
  14. function(edge, source, target, context, settings) {
  15. var color = edge.active ?
  16. edge.active_color || settings('defaultEdgeActiveColor') :
  17. edge.color,
  18. prefix = settings('prefix') || '',
  19. size = edge[prefix + 'size'] || 1,
  20. edgeColor = settings('edgeColor'),
  21. defaultNodeColor = settings('defaultNodeColor'),
  22. defaultEdgeColor = settings('defaultEdgeColor'),
  23. sX = source[prefix + 'x'],
  24. sY = source[prefix + 'y'],
  25. tX = target[prefix + 'x'],
  26. tY = target[prefix + 'y'],
  27. c,
  28. d,
  29. dist = sigma.utils.getDistance(sX, sY, tX, tY);
  30. if (!color)
  31. switch (edgeColor) {
  32. case 'source':
  33. color = source.color || defaultNodeColor;
  34. break;
  35. case 'target':
  36. color = target.color || defaultNodeColor;
  37. break;
  38. default:
  39. color = defaultEdgeColor;
  40. break;
  41. }
  42. if (settings('edgeHoverColor') === 'edge') {
  43. color = edge.hover_color || color;
  44. } else {
  45. color = edge.hover_color || settings('defaultEdgeHoverColor') || color;
  46. }
  47. size *= settings('edgeHoverSizeRatio');
  48. // Intersection points of the source node circle:
  49. c = sigma.utils.getCircleIntersection(sX, sY, size, tX, tY, dist);
  50. // Intersection points of the target node circle:
  51. d = sigma.utils.getCircleIntersection(tX, tY, size, sX, sY, dist);
  52. context.save();
  53. context.strokeStyle = color;
  54. context.lineWidth = size;
  55. context.beginPath();
  56. context.moveTo(c.xi, c.yi);
  57. context.lineTo(d.xi_prime, d.yi_prime);
  58. context.closePath();
  59. context.stroke();
  60. context.beginPath();
  61. context.moveTo(c.xi_prime, c.yi_prime);
  62. context.lineTo(d.xi, d.yi);
  63. context.closePath();
  64. context.stroke();
  65. context.restore();
  66. };
  67. })();