diff --git a/lib/components/scrollRankingBoard/src/main.vue b/lib/components/scrollRankingBoard/src/main.vue index 7814f4a..44cd179 100644 --- a/lib/components/scrollRankingBoard/src/main.vue +++ b/lib/components/scrollRankingBoard/src/main.vue @@ -152,10 +152,21 @@ export default { }) const value = data.map(({ value }) => value) + + const min = Math.min(...value) || 0 + + //最小值的绝对值 + const minAbs = Math.abs(min) const max = Math.max(...value) || 0 - data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: row.value / max * 100 })) + //最小值的绝对值 + const maxAbs = Math.abs(max) + + //总数为最大值与最小值的绝对值相加 + const total = max + minAbs + + data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: (row.value + minAbs) / total * 100 })) const rowLength = data.length diff --git a/src/components/scrollRankingBoard/src/main.vue b/src/components/scrollRankingBoard/src/main.vue index f349096..e822906 100644 --- a/src/components/scrollRankingBoard/src/main.vue +++ b/src/components/scrollRankingBoard/src/main.vue @@ -152,10 +152,21 @@ export default { }) const value = data.map(({ value }) => value) + + const min = Math.min(...value) || 0 + + //最小值的绝对值 + const minAbs = Math.abs(min) const max = Math.max(...value) || 0 - data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: row.value / max * 100 })) + //最小值的绝对值 + const maxAbs = Math.abs(max) + + //总数为最大值与最小值的绝对值相加 + const total = max + minAbs + + data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: (row.value + minAbs) / total * 100 })) const rowLength = data.length