Several classes in SVG

I am very new to SVG (using D3.js to invoke everything). Recently, I just came across a huge limitation with the project I'm working on. I want to be able to create classes "g" for each category of data that I work with. Unfortunately, I get my data from an XML file that only connects the data in one way (for example: person1 ---> person2, but not person2 ---> person1). What I would like to do is put each figure from my data into the root class AND the class with which it connects. If I could add this form to two or more classes (for example, g class = person1 and person2), this would be the fastest solution that I consider ... But is something like this possible? Can I set an SVG form for two or more classes? Or he will overwrite it when I define new ones.

I really hope someone can understand what I'm asking for. It’s hard to formulate my problem without tearing off every detail of my final project.

+6
source share
2 answers

Yes, you can install several classes. For instance,

<g class="person1 person2"> 

Or, in D3:

 g.attr("class", "person1 person2"); 
+11
source

One more note: if you call a function from a file:

 .attr("class",function(d) { return d.person1+" "+ d.person2;} ) 
0
source

Source: https://habr.com/ru/post/918687/


All Articles