I'm currently developing a booking tool that requires users to choose a desk on the map by clicking on it.
Each desk is enclosed in its own group (<g>
) with specific elements like <title>
, <path>
, and <text>
. The issue I've encountered is that every <text>
aligns to the SVG itself rather than their parent <g>
. With around 200 desks, manually positioning each desk number is tedious work, especially considering that the floor plan may change periodically. Am I overlooking something?
Below is a simplified example:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 453.16 313.93">
<defs>
<style>
.cls-1 {
fill: none;
stroke: #231f20;
stroke-miterlimit: 10;
}
.cls-2 {
font-size: 30px;
text-anchor: middle;
}
</style>
</defs>
<g>
<path class="cls-1" d="M122.05,61.28H.5V.5H122.05V61.28Z"/>
<text class="cls-2" x="63" y="34">001</text>
</g>
<g>
<path class="cls-1" d="M122.05,145.33H.5v-60.78H122.05v60.78Z"/>
<text class="cls-2" x="63" y="116">002</text>
</g>
<g>
<path class="cls-1" d="M122.05,229.38H.5v-60.78H122.05v60.78Z"/>
<text class="cls-2" x="63" y="200">003</text>
</g>
</svg>