svgdotjs / svg.js

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

flatten () gets error: "parent is undefined" #1127

Closed sittingelk closed 1 year ago

sittingelk commented 4 years ago

Hi, the flatten method (https://svgjs.com/docs/3.0/manipulating/#flatten) on svg or group seems to be not working in SVG.js v3.0.

The reported error is: "TypeError: parent is undefined", "transform.js:41:13"

I use Firefox 77.0.1

Here is my minimal example:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
    </head>
    <body>
    </body>
    <script>
        let svg = SVG ().addTo ("body").size (300, 300)
        let group = svg.group ()
        group.rect (100, 100)

        group.flatten ()
        //svg.flatten () // error also occurs here
    </script>
</html>

Am I doing this wrong? Is this a bug?

sittingelk commented 4 years ago

ok, I think I just have to give the new container (may be the root/drawing) as parameter: group.flatten (svg) or svg.flatten (svg)

But documentation says "(default: parent container of the calling element)" so this nevertheless may be a bug (or a documentation incorrectness)?

Fuzzyma commented 4 years ago

flatten is buggy in v3.0 and was fixed in the current master which isnt released yet. Can you try master and report if it solved your problem?

Quick guide how to use master:

git clone https://github.com/svgdotjs/svg.js
cd svg.js
npm install
npm run build
# files are in the ./dist folder now
sittingelk commented 4 years ago

thank you very much for quick answer!

I am sorry for my late one and more sorry, that I cannot report anything now, because I didnt had/have time to do so now, but will report as soon as possible.