marker.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { append as svgAppend, attr as svgAttr, create as svgCreate } from 'tiny-svg';
  2. import { assign } from 'min-dash';
  3. import { query as domQuery } from 'min-dom';
  4. export default function createAddMarkerSelect(element: any, ymCanvas: any) {
  5. var activeElement = document.getElementById('bpmnSequenceFlowActiveId');
  6. if (!activeElement) {
  7. if (element.type === 'bpmn:SequenceFlow') {
  8. var sequenceFlowEnd = svgCreate('path');
  9. svgAttr(sequenceFlowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
  10. addMarker(
  11. 'bpmnSequenceFlowActiveId',
  12. {
  13. element: sequenceFlowEnd,
  14. ref: { x: 11, y: 10 },
  15. scale: 0.5,
  16. attrs: {
  17. fill: 'rgb(24, 131, 255)',
  18. stroke: 'rgb(24, 131, 255)',
  19. },
  20. },
  21. ymCanvas,
  22. );
  23. }
  24. }
  25. }
  26. function addMarker(id: any, options: any, ymCanvas: any) {
  27. let attrs = assign(
  28. {
  29. fill: 'hsl(225, 10%, 15%)',
  30. strokeWidth: 1,
  31. strokeLinecap: 'round',
  32. strokeDasharray: 'none',
  33. },
  34. options.attrs,
  35. );
  36. let ref = options.ref || { x: 0, y: 0 };
  37. let scale = options.scale || 1;
  38. if (attrs.strokeDasharray === 'none') {
  39. attrs.strokeDasharray = [10000, 1];
  40. }
  41. let marker = svgCreate('marker');
  42. svgAttr(options.element, attrs);
  43. svgAppend(marker, options.element);
  44. svgAttr(marker, {
  45. id: id,
  46. viewBox: '0 0 20 20',
  47. refX: ref.x,
  48. refY: ref.y,
  49. markerWidth: 20 * scale,
  50. markerHeight: 20 * scale,
  51. orient: 'auto',
  52. });
  53. let defs = domQuery('defs', ymCanvas._svg);
  54. if (!defs) {
  55. defs = svgCreate('defs');
  56. svgAppend(ymCanvas._svg, defs);
  57. }
  58. svgAppend(defs, marker);
  59. // markers[id] = marker;
  60. }