@@ -47,18 +47,22 @@ const getSquareSizes = async () => {
4747 squareSize .value .forEach ((item , index ) => {
4848 item .color = color (index)
4949
50- let share = Math .floor ((item .value / total .value * 100 ))
50+ let share = Math .round ((item .value / total .value * 100 ))
5151 totalSquares += Math .max (share, 1 )
5252 item .share = share
5353 item .squares = Math .max (share, 1 )
5454 })
5555
56- if (totalSquares > 100 ) {
56+ if (totalSquares !== 100 ) {
5757 let maxSquaresIndex = squareSize .value .reduce ((maxIndex , current , index , array ) => {
5858 return (current .squares > array[maxIndex].squares ) ? index : maxIndex
5959 }, 0 )
6060
61- squareSize .value [maxSquaresIndex].squares = squareSize .value [maxSquaresIndex].squares - (totalSquares - 100 )
61+ if (totalSquares > 100 ) {
62+ squareSize .value [maxSquaresIndex].squares = squareSize .value [maxSquaresIndex].squares - (totalSquares - 100 )
63+ } else {
64+ squareSize .value [maxSquaresIndex].squares = squareSize .value [maxSquaresIndex].squares + (100 - totalSquares)
65+ }
6266 }
6367
6468 squareSize .value .forEach (item => {
@@ -166,7 +170,7 @@ onMounted(async () => {
166170 < Text size= " 12" weight= " 600" color= " primary" > {{ ` ${ s .size } x ${ s .size } ` }} < / Text >
167171 < / Flex>
168172
169- < Text size= " 12" weight= " 600" color= " tertiary" style= " text-align: right; flex: 1" > {{ ` ${ s .share === 0 ? ' <1' : s .share } %` }} < / Text >
173+ < Text size= " 12" weight= " 600" color= " tertiary" style= " text-align: right; flex: 1" > {{ ` ${ s .share <= 1 ? ' <1' : s .share } %` }} < / Text >
170174 < Text size= " 12" weight= " 600" color= " primary" style= " text-align: right; flex: 1" > {{ comma (s .value ) }} < / Text >
171175 < / Flex>
172176 < / Flex>
0 commit comments