Skip to content

Commit d73d2a3

Browse files
committed
prevent safe area from overflowing
1 parent d67e762 commit d73d2a3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/components/SChartBar.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function renderChart({
9797
9898
// Compute a constant offset to center the colored bar inside its full band.
9999
const groupOffset = (paddedScale.step() - paddedScale.bandwidth()) / 2
100+
const heightPadding = 24
100101
101102
// For the axes, use the paddedScale so ticks remain centered on the bars.
102103
svg
@@ -202,9 +203,9 @@ function renderChart({
202203
if (vertical) {
203204
outerBars
204205
.attr('x', 0)
205-
.attr('y', (d) => y(d.value) - groupOffset)
206+
.attr('y', (d) => Math.max(0, y(d.value) - heightPadding))
206207
.attr('width', paddedScale.step())
207-
.attr('height', (d) => height - y(d.value) + groupOffset)
208+
.attr('height', (d) => height - Math.max(0, y(d.value) - heightPadding))
208209
bars
209210
.attr('x', groupOffset)
210211
.attr('y', (d) => y(d.value))
@@ -214,7 +215,7 @@ function renderChart({
214215
outerBars
215216
.attr('x', 0)
216217
.attr('y', 0)
217-
.attr('width', (d) => y(d.value) + groupOffset)
218+
.attr('width', (d) => Math.min(width, y(d.value) + heightPadding))
218219
.attr('height', paddedScale.step())
219220
bars
220221
.attr('x', 0)
@@ -233,8 +234,8 @@ function renderChart({
233234
.transition()
234235
.duration(800)
235236
.delay((_, i) => i * 100)
236-
.attr('y', (d) => y(d.value) - groupOffset)
237-
.attr('height', (d) => height - y(d.value) + groupOffset)
237+
.attr('y', (d) => Math.max(0, y(d.value) - heightPadding))
238+
.attr('height', (d) => height - Math.max(0, y(d.value) - heightPadding))
238239
bars
239240
.attr('x', groupOffset)
240241
.attr('y', height)
@@ -254,7 +255,7 @@ function renderChart({
254255
.transition()
255256
.duration(800)
256257
.delay((_, i) => i * 100)
257-
.attr('width', (d) => y(d.value) + groupOffset)
258+
.attr('width', (d) => Math.min(width, y(d.value) + heightPadding))
258259
bars
259260
.attr('x', 0)
260261
.attr('y', groupOffset)

0 commit comments

Comments
 (0)