vaadin-component-factory / svg

Java API for vcf-svg
Other
2 stars 4 forks source link

Svg elements order should be preserved #20

Open dario-zamuner-trenolab opened 4 months ago

dario-zamuner-trenolab commented 4 months ago

In the case of multiple SVG elements layered on top of each other, the order is important. Currently, the elements are stored inside the Svg class as a HashSet. It should be a LinkedHashSet instead.

`public class Svg extends Component implements HasSize, HasStyle {

private static final long serialVersionUID = 4669224429512601365L;
private static final Logger log = Logger.getLogger(Svg.class.getName());

private Set<SvgElement> svgElements = new HashSet<>(); // this should be a LinkedHashSet
... 

}`

netsrotr commented 2 months ago

As I look at the code the SvgElement is immediatly added to the SVG DOM if you call Svg.add(element). The privately hold Hashset is only hold/used as lookup. So order should be preserved on client side.

dario-zamuner-trenolab commented 2 months ago

I used this set to regenerate the svg server-side because I needed to manipulate and export the svg in multiple formats (png, pdf, jpg). I know the original scope of the HashSet was limited, but this is a case where the order is important. I solved my problem by extending the svg class, but it would have been nice not to have to.