Skip to content

Commit d67e762

Browse files
committed
fix animation
1 parent 4e6c005 commit d67e762

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

lib/components/SChartBar.vue

+32-5
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,10 @@ function renderChart({
185185
)
186186
187187
// Each group gets a transparent rect covering the full band (using paddedScale.step())
188-
barGroups
188+
const outerBars = barGroups
189189
.append('rect')
190190
.attr('fill', 'transparent')
191191
.attr('pointer-events', 'all')
192-
.attr('x', 0)
193-
.attr('y', (d) => vertical ? y(d.value) - groupOffset : 0)
194-
.attr('width', (d) => vertical ? paddedScale.step() : y(d.value) + groupOffset)
195-
.attr('height', (d) => vertical ? height - y(d.value) + groupOffset : paddedScale.step())
196192
197193
// Append the colored bar rect inside each group.
198194
// We now offset it by groupOffset so its left edge is at paddedScale(d.key)
@@ -204,12 +200,22 @@ function renderChart({
204200
205201
if (!animate) {
206202
if (vertical) {
203+
outerBars
204+
.attr('x', 0)
205+
.attr('y', (d) => y(d.value) - groupOffset)
206+
.attr('width', paddedScale.step())
207+
.attr('height', (d) => height - y(d.value) + groupOffset)
207208
bars
208209
.attr('x', groupOffset)
209210
.attr('y', (d) => y(d.value))
210211
.attr('width', paddedScale.bandwidth())
211212
.attr('height', (d) => height - y(d.value))
212213
} else {
214+
outerBars
215+
.attr('x', 0)
216+
.attr('y', 0)
217+
.attr('width', (d) => y(d.value) + groupOffset)
218+
.attr('height', paddedScale.step())
213219
bars
214220
.attr('x', 0)
215221
.attr('y', groupOffset)
@@ -219,6 +225,16 @@ function renderChart({
219225
} else {
220226
// Animate the bars
221227
if (vertical) {
228+
outerBars
229+
.attr('x', 0)
230+
.attr('y', height)
231+
.attr('width', paddedScale.step())
232+
.attr('height', 0)
233+
.transition()
234+
.duration(800)
235+
.delay((_, i) => i * 100)
236+
.attr('y', (d) => y(d.value) - groupOffset)
237+
.attr('height', (d) => height - y(d.value) + groupOffset)
222238
bars
223239
.attr('x', groupOffset)
224240
.attr('y', height)
@@ -230,6 +246,15 @@ function renderChart({
230246
.attr('y', (d) => y(d.value))
231247
.attr('height', (d) => height - y(d.value))
232248
} else {
249+
outerBars
250+
.attr('x', 0)
251+
.attr('y', 0)
252+
.attr('width', 0)
253+
.attr('height', paddedScale.step())
254+
.transition()
255+
.duration(800)
256+
.delay((_, i) => i * 100)
257+
.attr('width', (d) => y(d.value) + groupOffset)
233258
bars
234259
.attr('x', 0)
235260
.attr('y', groupOffset)
@@ -285,6 +310,8 @@ function renderChart({
285310
.style('height', `${height}px`)
286311
.style('outline', '1px solid blue')
287312
.style('pointer-events', 'none')
313+
outerBars
314+
.style('outline', '1px solid green')
288315
}
289316
}
290317

0 commit comments

Comments
 (0)