svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.01k stars 1.07k forks source link

ungroup() reorders nodes #1192

Closed samhocevar closed 11 months ago

samhocevar commented 3 years ago

Bug report

Fiddle

https://jsfiddle.net/3rof824w/

var canvas = SVG().addTo('#canvas').size('100%', '100%')
g = canvas.group()
g.add(canvas.rect(100, 100).move(50,50).fill('red'))
canvas.rect(100, 100).move(100, 100).fill('blue')
g.ungroup()

Explanation

Ungrouping g brings the red square to the front, because it is inserted after the blue square. I would expect ungrouped nodes to be inserted at the position of the original group.

samhocevar commented 3 years ago

FYI here is my implementation:

function ungroup_in_place(g) {
    for (let e of g.children())
        g.before(e);
    g.remove();
}
Fuzzyma commented 3 years ago

good catch

Fuzzyma commented 11 months ago

seems like this was fixed long time ago