My current project involves creating an interactive schema that includes complex SVG elements, such as groups containing multiple sub-objects like rect
, path
, and text
.
I am wondering if there is a way to store the description of these elements in a variable and then directly use it with .append()
function?
Here is an example of one object:
<g id="Titre_x5F_A11">
<g>
<g id="Cadre_3_">
<rect x="13.2" y="636" class="st14" width="157.5" height="26.8"/>
<rect x="12.3" y="636" class="st15" width="13.7" height="26.8"/>
</g>
<g id="IN_3_">
<rect x="142.6" y="654.5" class="st16" width="10" height="5.7"/>
<text transform="matrix(0.9497 0 0 1 145.6079 658.4658)" class="st17 st4 st18">IN</text>
</g>
<g id="OUT_3_">
<rect x="155.9" y="654.5" class="st19" width="10" height="5.7"/>
<text transform="matrix(0.9497 0 0 1 156.8984 658.4434)" class="st17 st4 st18">OUT</text>
</g>
<rect x="28.2" y="637.7" class="st20" width="111.1" height="7.4"/>
<text id="TitreAction_18_" transform="matrix(0.9497 0 0 1 28.1768 643.1006)" class="st4 st21">A11 - xxxxxe</text>
<rect x="28.2" y="646.7" class="st20" width="106.5" height="14.8"/>
<text id="DescrAction_3_" transform="matrix(0.9497 0 0 1 28.1768 650.082)" class="st22 st4 st18">To be completed</text>
<g id="IconePeople_3_">
<circle class="st23" cx="155" cy="644.8" r="6.5"/>
<path class="st24" d="M153.4,644.1c0.9,0.9,2.3,0.9,3.1,0c0.9-0.9,0.9-2.4,0-3.4c-0.9-0.9-2.3-0.9-3.1,0l0,0
C152.5,641.6,152.5,643.1,153.4,644.1z M151.2,649c1.1,0,6.6,0,7.7,0c1.1,0,0.5-1.1,0.5-1.1s-2.2-2.7-4.4-2.7
s-4.4,2.7-4.4,2.7l0,0C150.6,648,150.1,649,151.2,649z"/>
</g>
</g>
</g>
and my main objective is:
var complexObject = ... description of complexObject
var circles = svgContainer.selectAll("complexObject")
.data(data)
.enter()
.append("complexObject");