Skip to content

Commit 5c46fc8

Browse files
authored
Merge pull request #85 from celenium-io/CLS-210-network-stats
Fix square size card
2 parents 58c571f + 4d20c5d commit 5c46fc8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

components/modules/stats/SquareSizeCard.vue

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ const getSquareSizes = async () => {
4343
const color = d3.scaleSequential(d3.piecewise(d3.interpolateRgb, ["#65efcc", "#142f28"]))
4444
.domain([0, squareSize.value.length])
4545
46-
let totalShare = 0
46+
let totalSquares = 0
4747
squareSize.value.forEach((item, index) => {
4848
item.color = color(index)
4949
50-
if (index !== squareSize.value.length - 1) {
51-
let share = Math.min(Math.round((item.value / total.value * 100)), 1)
52-
totalShare += share
53-
item.share = share
54-
} else {
55-
item.share = 100 - totalShare
56-
}
50+
let share = Math.floor((item.value / total.value * 100))
51+
totalSquares += Math.max(share, 1)
52+
item.share = share
53+
item.squares = Math.max(share, 1)
5754
})
5855
56+
if (totalSquares > 100) {
57+
let maxSquaresIndex = squareSize.value.reduce((maxIndex, current, index, array) => {
58+
return (current.squares > array[maxIndex].squares) ? index : maxIndex
59+
}, 0)
60+
61+
squareSize.value[maxSquaresIndex].squares = squareSize.value[maxSquaresIndex].squares - (totalSquares - 100)
62+
}
63+
5964
squareSize.value.forEach(item => {
60-
for (let i = 0; i < item.share; i++) {
65+
for (let i = 0; i < item.squares; i++) {
6166
squareSizeGraph.value.push({
6267
size: item.size,
6368
color: item.color,

0 commit comments

Comments
 (0)