svgdotjs / svg.js

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

Feature request: `group(id)` constructor for SVG.G #1288

Closed jango-fx closed 10 months ago

jango-fx commented 1 year ago

Feature request: group(id) constructor for SVG.G

to my mind a <g> tag's main attribute is its id (just like the width and height of a rect) and I would expect it to be set similarly intuitively during construction. Without a cumbersome additional call of .attr('id', 'ID').

so instead of

let theGroup = draw.group()
theGroup.attr('id', 'myGroupID')

simply

let theGroup = draw.group("myGroupID")

to get

<svg>
  <g id="myGroupID">
  </g>
</svg>

(love your lib though ❤️ )

Fuzzyma commented 1 year ago

The constructor always takes the dimensions of the object. Since g don't have dimensions itself they don't take an argument.

But you can always pass an object with attributes: canvas.group({ id })

jango-fx commented 1 year ago

arr, I still don't find that very intuitive, but I might bow to your consistency 😜

Fuzzyma commented 1 year ago

haha, and I thought intuity comes from consistency :D

jango-fx commented 1 year ago

The constructor always takes the dimensions of the object

not true for SVG.text() though 🤨

Fuzzyma commented 1 year ago

@jango-fx text doesnt have a dimension!! At least not until SVG 2 which isnt broadly supported and a whole other beast