const courtStructure = [
{ class: 'legend-rect', shape: 'rect', x: 0, y: TLP + 38, width: 50, height: 8, fill: headerStyle.backgroundColor }, // rectangle behind legend
{ class: 'backboard', shape: 'line', x1: 22, x2: 28, y1: 3.75, y2: 3.75, stroke: hoopColor, opacity: hoopOpacity, strokeWidth: 0.5 }, // backboard
{ class: 'rim', shape: 'circle', r: 0.95, cx: 25, cy: 5.1, opacity: hoopOpacity, fill: hoopColor }, // the circle part of rim
{ class: 'back-iron', shape: 'rect', x: 24.625, y: 3.95, width: 0.75, height: 0.5, stroke: 0, opacity: hoopOpacity, fill: hoopColor } // back iron on rim
];
<rect
className='legend-rect'
x={0}
y={TLP + 38}
width={50}
height={8}
fill={headerStyle.backgroundColor}
/>
...
We have the courtStructure
array of objects, and we would like to .map()
over the array and create the SVG elements described. Example for the first rect
is shown above. The keys in each object within courtStructure
should be created as a field on the SVG element. The shape
determines the element type.
The hardest part of achieving this seems to be:
- creating the correct element (rect, line, circle, etc.)
- handling the fact that different objects have different keys / parameters for the SVG
Is this possible to do?