sigma.canvas.edgehovers.dashed.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.dashed =
  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. if (!color)
  24. switch (edgeColor) {
  25. case 'source':
  26. color = source.color || defaultNodeColor;
  27. break;
  28. case 'target':
  29. color = target.color || defaultNodeColor;
  30. break;
  31. default:
  32. color = defaultEdgeColor;
  33. break;
  34. }
  35. if (settings('edgeHoverColor') === 'edge') {
  36. color = edge.hover_color || color;
  37. } else {
  38. color = edge.hover_color || settings('defaultEdgeHoverColor') || color;
  39. }
  40. size *= settings('edgeHoverSizeRatio');
  41. context.save();
  42. context.setLineDash([8,3]);
  43. context.strokeStyle = color;
  44. context.lineWidth = size;
  45. context.beginPath();
  46. context.moveTo(
  47. source[prefix + 'x'],
  48. source[prefix + 'y']
  49. );
  50. context.lineTo(
  51. target[prefix + 'x'],
  52. target[prefix + 'y']
  53. );
  54. context.stroke();
  55. context.restore();
  56. };
  57. })();