sigma.canvas.edges.dotted.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;(function() {
  2. 'use strict';
  3. sigma.utils.pkg('sigma.canvas.edges');
  4. /**
  5. * This method renders the edge as a dotted line.
  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.edges.dotted = function(edge, source, target, context, settings) {
  14. var color = edge.active ?
  15. edge.active_color || settings('defaultEdgeActiveColor') :
  16. edge.color,
  17. prefix = settings('prefix') || '',
  18. size = edge[prefix + 'size'] || 1,
  19. edgeColor = settings('edgeColor'),
  20. defaultNodeColor = settings('defaultNodeColor'),
  21. defaultEdgeColor = settings('defaultEdgeColor');
  22. if (!color)
  23. switch (edgeColor) {
  24. case 'source':
  25. color = source.color || defaultNodeColor;
  26. break;
  27. case 'target':
  28. color = target.color || defaultNodeColor;
  29. break;
  30. default:
  31. color = defaultEdgeColor;
  32. break;
  33. }
  34. context.save();
  35. if (edge.active) {
  36. context.strokeStyle = settings('edgeActiveColor') === 'edge' ?
  37. (color || defaultEdgeColor) :
  38. settings('defaultEdgeActiveColor');
  39. }
  40. else {
  41. context.strokeStyle = color;
  42. }
  43. context.setLineDash([2]);
  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. })();