I am trying to draw this SVG path.
I could achieve it using SVG Line and Curve properties for a fixed height and width using fixed coordinates.
But, I need to draw this responsively which means, the width of the path, space between the lines, the distance between each point, and the curves at the sides should be responsive.
It contains levels indicated by numbers as shown in the image, and the length of the path should be determined by the number of levels given.
While trying to draw this responsively, I was stuck at
- Getting the start and end-point of the Lines
- Getting control points for the curves
- Responsive adjustment of the distance between each point and space between the curves
- Determining the length of the path based on the number of levels given
I am trying to do these using percentages based on the parent div
's width by some mathematical calculations. But, it seems it breaks some or other cases due to its complexity.
There are some other things to do along with these, but this is the top-level version of what needs to be done.
Is there any direct method or formula or calculation for achieving this? (or) Is there any other approach to draw this? (or) Are there any tutorials for learning to draw these types of SVG paths?
After creating the path you need to calculate the position of the numbers and circles on the path. For this you need to know the length of the path calculated with the getTotalLength() method. Next you need a loop to calculate the position of the numbers on the path. For this I've used the
getPointAtLength()
method. On each of this pointd you create a new circle (use) element and a new text element.Please read the comments in the code.
Please observe that since the svg element has a viewBox attribute and no with it takes all the available width making it responsive.