svg.draggable.js icon indicating copy to clipboard operation
svg.draggable.js copied to clipboard

Flickering when dragging a group with an SVG in it

Open lucafaggianelli opened this issue 3 years ago • 5 comments

I have a group element <g> containing several elements, there's always an <svg> and optionally other stuff. The drag and drop works but it flickers a lot and the drop position is not correct.

https://codepen.io/lucafaggianelli/pen/eYzVmxx?editors=0010

const draw = SVG().size(500, 500).addTo('body')
const table = draw.group()
  .svg(TABLE)
  .draggable()

Moreover I need to resize the loaded image inside the group and if I do that, the situation is worse as the element jump out of the window (literally :))

const table = draw.group()
  .svg(TABLE)
  .draggable()
  .last().size(100)

lucafaggianelli avatar Oct 28 '20 15:10 lucafaggianelli

And I thought this plug-in was finally stable... I'll look into it but it might take some time.

Fuzzyma avatar Oct 28 '20 22:10 Fuzzyma

Yes it seems a pretty delicate matter, when I drag the group only the inner svg is moved via x and y attrs, so I tried to make a custom drag logic applying a translation to the g element and situation is better but still buggy

lucafaggianelli avatar Oct 28 '20 23:10 lucafaggianelli

This is actually the correct behavior because groups just inherit the position if it's content. So if you love the content the group moves. But obviously something is not working out here

Fuzzyma avatar Oct 29 '20 10:10 Fuzzyma

A possible work-around - move each element of the group manually:

let lastPoint;
group.draggable().on('dragstart', (e) => {
  lastPoint = e.detail.p;
}).on('dragmove', (e) => {
  e.preventDefault();
  const currentPoint = e.detail.p;
  const dx = currentPoint.x - lastPoint.x;
  const dy = currentPoint.y - lastPoint.y;
  // move each element of the group
  lastPoint = currentPoint;
})

alexanderGerbik avatar Dec 08 '20 16:12 alexanderGerbik

is there any news about this?

antonioaltamura avatar Oct 18 '21 21:10 antonioaltamura