MockEvents.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { assign } from 'min-dash';
  2. import {
  3. getDiagramJS
  4. } from 'test/TestHelper';
  5. /**
  6. * Create an event with global coordinates
  7. * computed based on the loaded diagrams canvas position and the
  8. * specified canvas local coordinates.
  9. *
  10. * @param {Point} point of the event local the canvas (closure)
  11. * @param {Object} data
  12. *
  13. * @return {Event} event, scoped to the given canvas
  14. */
  15. export function createCanvasEvent(position, data) {
  16. return getDiagramJS().invoke(function(canvas) {
  17. var target = canvas._svg;
  18. var clientRect = canvas._container.getBoundingClientRect();
  19. var absolutePosition = {
  20. x: position.x + clientRect.left,
  21. y: position.y + clientRect.top
  22. };
  23. return createEvent(target, absolutePosition, data);
  24. });
  25. }
  26. export function createEvent(target, position, data) {
  27. return getDiagramJS().invoke(function(eventBus) {
  28. data = assign({
  29. target: target,
  30. clientX: position.x,
  31. clientY: position.y,
  32. offsetX: position.x,
  33. offsetY: position.y
  34. }, data || {});
  35. return eventBus.createEvent(data);
  36. });
  37. }