We can’t add text to a rectangle or any shape to any other shape in the SVG. In standard HTML we can put almost or any element inside another element, eg we can add table an element inside the div element.
There are some exception element in SVG, eg TSPAN can be added inside the text element. The SVG group element allows us to add anything inside the group include group inside another group. The SVG group element can be used to group another SVG element together and it acts as a container for another SVG element. By nature group, an element is not shown in the web browser, as itself can’t be style. But group element has the tangible effect, the group content can be conceptual move, rotate its content.
The group element allows us to join another element together, turn then in pink or move to new pixel and they allow us to tight organize the elements in the DOM. In the example below, we had used different interpolate available in D3 and we had created 6 group element and each group is having path information and six dots as the circle on the path.
In the above example, we have created 6 charts with 6 dot indicating data points and each chart we have path added to it with different curve setting or interpolation methods.
- Create 1st line path and added 6 dots as the circle.
- Added all element with path and dot are group into 6 group element. As we can easily reposition group rather than reposition each individual element in the group.
We can see DOM structure of our above code.