drawsvg icon indicating copy to clipboard operation
drawsvg copied to clipboard

Any subDrawing instances ?

Open Thibaud-Ardoin opened this issue 3 years ago • 5 comments

Hello,

I like your library, although I can't find any complete doc about it.

I don't manage to create multiple drawing elements and then combine them. Would there be a way to do that properly ? For example :

# A map element
d = draw.subDrawing(2, 2, origin='center', id='map')
d.append(draw.Circle(position_relative_to_map[0],position_relative_to_map[1], 0.03,
                fill=pick_fill_col, stroke_width=0.008, stroke=pick_strok_col))

# An information element
panel = draw.subDrawing(2, 2, origin='center', id='data_panel')
panel.append(draw.Text(data_text, position_in_data[0], position_in_data[1], fill=target_text_color, text_anchor='start'))

# Final combination of booth
final = draw.Drawing(4,2, origin='center')
final.append(d, (3, 1)) #Inserting subDrawing at determinated position
final.append(panel, (1, 1))

A hacky way would be to append everything directly to the final drawing with a offset that depends on the 'subDrawing'. It is unpleasant tho.

Thank you in advance for your help Best, T.

Thibaud-Ardoin avatar Jun 04 '21 12:06 Thibaud-Ardoin

You would use Group for this. It looks like there is no example in the README for Group yet.

d = draw.Drawing(...)

map = draw.Group(id='map_panel', x=3, y=1)
map.append(...)
d.append(map)

panel = draw.Group(id='data_panel', x=1, y=1)
panel.append(...)
d.append(panel)

cduck avatar Jun 04 '21 20:06 cduck

Oh I see, Thank you very much !

Best, T.

Thibaud-Ardoin avatar Jun 05 '21 08:06 Thibaud-Ardoin

Re-opening this until I add an example to the documentation.

cduck avatar Jun 06 '21 04:06 cduck

Actually, I what is working is the following

d = draw.Drawing(...)

map = draw.Group(id='map_panel', transform='translate(3, -1)')
map.append(...)
d.append(map)

panel = draw.Group(id='data_panel', transform='translate(1, -1)')
panel.append(...)
d.append(panel)

Thibaud-Ardoin avatar Jun 07 '21 08:06 Thibaud-Ardoin

Right, x and y work with Use with may also be helpful for you.

d.append(draw.Use(map, 3, -1))

cduck avatar Jun 07 '21 18:06 cduck