Skip to content

Commit 97a5302

Browse files
committed
Scale Y to data min/max
1 parent 39cfac7 commit 97a5302

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/Sparkline.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ const buildSparklinePaths = (
147147
xMax += 1
148148
}
149149
150-
let yMin = Math.min(yMinData, 0)
151-
let yMax = Math.max(yMaxData, 0)
150+
let yMin = yMinData
151+
let yMax = yMaxData
152152
if (yMin === yMax) {
153153
yMin -= 1
154154
yMax += 1
@@ -158,7 +158,9 @@ const buildSparklinePaths = (
158158
((value - xMin) / (xMax - xMin)) * SPARKLINE_WIDTH
159159
const scaleY = (value: number) =>
160160
SPARKLINE_HEIGHT - ((value - yMin) / (yMax - yMin)) * SPARKLINE_HEIGHT
161-
const zeroY = scaleY(0)
161+
const clamp = (value: number, min: number, max: number) =>
162+
Math.min(Math.max(value, min), max)
163+
const zeroY = scaleY(clamp(0, yMin, yMax))
162164
163165
const linePaths: string[] = []
164166
const areaPaths: string[] = []

0 commit comments

Comments
 (0)