edgeConnection.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Plugin that always creates a small black circle to represent a join
  3. * when a new edge is dropped with the target end in free space
  4. */
  5. Draw.loadPlugin(function(ui) {
  6. mxConnectionHandler.prototype.createTargetVertex = function(evt, source)
  7. {
  8. // Uses the first non-relative source
  9. var geo = this.graph.getCellGeometry(source);
  10. while (geo != null && geo.relative)
  11. {
  12. source = this.graph.getModel().getParent(source);
  13. geo = this.graph.getCellGeometry(source);
  14. }
  15. // OVERRIDE clone to create a big filled black circle instead of cloning the source
  16. var clone = this.graph.createVertex(this.graph.getModel().getParent(source), null, null, 0, 0, 6, 6, 'ellipse;fillColor=#000000;fixedPoints=0');
  17. var geo = this.graph.getModel().getGeometry(clone);
  18. if (geo != null)
  19. {
  20. var point = this.graph.getPointForEvent(evt);
  21. geo.x = this.graph.snap(point.x - geo.width / 2) - this.graph.panDx / this.graph.view.scale;
  22. geo.y = this.graph.snap(point.y - geo.height / 2) - this.graph.panDy / this.graph.view.scale;
  23. // Aligns with source if within certain tolerance
  24. if (this.first != null)
  25. {
  26. var sourceState = this.graph.view.getState(source);
  27. if (sourceState != null)
  28. {
  29. var tol = this.getAlignmentTolerance();
  30. if (Math.abs(this.graph.snap(this.first.x) -
  31. this.graph.snap(point.x)) <= tol)
  32. {
  33. geo.x = sourceState.x;
  34. }
  35. else if (Math.abs(this.graph.snap(this.first.y) -
  36. this.graph.snap(point.y)) <= tol)
  37. {
  38. geo.y = sourceState.y;
  39. }
  40. }
  41. }
  42. }
  43. return clone;
  44. };
  45. });