While experimenting with the svg attributes, I stumbled upon a solution that may benefit you. The fix is fairly straightforward - just make a simple change to the following line.
[attr.stroke-dasharray]="
item.utilization + ' ' + (100 - item.utilization)
"
[attr.stroke-dasharray]="
item.utilization - 1 + ' ' + (100 - item.utilization + 1)
"
I attempted to fork your stackblitz for a functional version link, but it seems stuck loading
Edit:
Upon further consideration, the initial approach doesn't align well with how dash-array and -offset function.
The issue with the first method is that you subtract a fixed amount from a percentage. This only works if the percentage (item.utilization) is higher than that specific amount. Additionally, this distorts the visual representation of the chart as it no longer accurately reflects the actual percentage.
A more effective approach is to base your chart on 100 + x percent (x representing the elements in your chart), such as 105. This allows for greater spacing within the chart. Utilize the dash-offset to shift the individual items based on their index.
[attr.stroke-dasharray]="(item.utilization) + ' ' + (105 - item.utilization)"
[attr.stroke-dashoffset]="
i === 0 ? 25 : (105 - item?.runningTotal + 25 - i)
"
By using 105, a significant gap becomes apparent. To decrease this gap, consider utilizing 102.5
and i / 2
. Remember to adjust the percentage by the number of elements in your chart since each element accounts for 1% (or 0.5% respectively) of the extra space provided.
Edit2: You can leverage donutData.length
to incorporate additional space.
[attr.stroke-dasharray]="(item.utilization) + ' ' + (100 + donutData?.length / 2 - item.utilization)"
[attr.stroke-dashoffset]="
i === 0 ? 25 : (100 + donutData?.length / 2 - item?.runningTotal + 25 - i/2)
"