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.

74 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.tapered =
  14. function(edge, source, target, context, settings) {
  15. // The goal is to draw a triangle where the target node is a point of
  16. // the triangle, and the two other points are the intersection of the
  17. // source circle and the circle (target, distance(source, target)).
  18. var color = edge.active ?
  19. edge.active_color || settings('defaultEdgeActiveColor') :
  20. edge.color,
  21. prefix = settings('prefix') || '',
  22. size = edge[prefix + 'size'] || 1,
  23. edgeColor = settings('edgeColor'),
  24. prefix = settings('prefix') || '',
  25. defaultNodeColor = settings('defaultNodeColor'),
  26. defaultEdgeColor = settings('defaultEdgeColor'),
  27. sX = source[prefix + 'x'],
  28. sY = source[prefix + 'y'],
  29. tX = target[prefix + 'x'],
  30. tY = target[prefix + 'y'],
  31. dist = sigma.utils.getDistance(sX, sY, tX, tY);
  32. if (!color)
  33. switch (edgeColor) {
  34. case 'source':
  35. color = source.color || defaultNodeColor;
  36. break;
  37. case 'target':
  38. color = target.color || defaultNodeColor;
  39. break;
  40. default:
  41. color = defaultEdgeColor;
  42. break;
  43. }
  44. if (settings('edgeHoverColor') === 'edge') {
  45. color = edge.hover_color || color;
  46. } else {
  47. color = edge.hover_color || settings('defaultEdgeHoverColor') || color;
  48. }
  49. size *= settings('edgeHoverSizeRatio');
  50. // Intersection points:
  51. var c = sigma.utils.getCircleIntersection(sX, sY, size, tX, tY, dist);
  52. context.save();
  53. // Turn transparency on:
  54. context.globalAlpha = 0.65;
  55. // Draw the triangle:
  56. context.fillStyle = color;
  57. context.beginPath();
  58. context.moveTo(tX, tY);
  59. context.lineTo(c.xi, c.yi);
  60. context.lineTo(c.xi_prime, c.yi_prime);
  61. context.closePath();
  62. context.fill();
  63. context.restore();
  64. };
  65. })();