[Bug] Arc motion: rounded arcs snap and lose their round caps, and enter `delay` runs once per arc group

Đang mở
#194 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
data-visualization

Hướng nghiên cứu

Start with createArcTracks in packages/charts-core/src/motion.ts (around line 1638), which builds one enter track per g.ts-chart__arc group, and compare it with createBarTracks (around line 1238), which makes one call per datum. Run the reproduction test in part A to see that delay fires once. Done for part A means one enter track and one delay call per sector, with datumIndex, datumCount and datum set. Parts B and C also need public API decisions on SceneArea and the enter/exit seeds, so check with maintainers before writing those.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version: @tanstack/charts 1.1.0 (57774e1).

Built-in polar arcs (radialArc, ring progress arcs, pie wedges, sunburst sectors) animate worse than bars: a sunburst cannot stagger its sectors on enter (A), a rounded arc snaps when its sweep changes (F, moved here from #193), and the enter sweep cuts round caps flat (E). B asks for the arc geometry that would fix F and E to be public, so custom marks get the arc tween too.

A. Enter delay is called once per arc group, not per sector

Repro: save as packages/charts-core/src/repro.test.ts, run pnpm vitest run packages/charts-core/src/repro.test.ts (fails on main).

import { expect, it } from 'vitest'
import { motion } from './motion'
import { polar } from './polar'
import { sunburst } from './hierarchy-sunburst'
import { createChartScene, defineChart } from './scene'
import type { ChartMotionContext } from './types'

const rows = [
  { name: 'a', size: 0 }, { name: 'a.x', size: 3 }, { name: 'a.y', size: 2 },
  { name: 'b', size: 0 }, { name: 'b.x', size: 4 }, { name: 'b.y', size: 1 },
]

it('A: enter delay is called once per sector', () => {
  const calls: ChartMotionContext[] = []
  const scene = createChartScene(
    defineChart({
      marks: [polar({
        marks: [sunburst(rows, {
          path: 'name', delimiter: '.', value: 'size',
          motion: { delay: (ctx) => (calls.push(ctx), ctx.datumIndex * 80) },
        })],
        scales: { angle: null, radius: null },
      })],
      scales: { x: null, y: null },
    }),
    { width: 200, height: 200 },
  )
  const container = document.createElement('div')
  motion({ transition: { type: 'tween', duration: 100, easing: 'linear' } })
    .mount(container, () => {})
    .render(scene, { ariaLabel: 'Sunburst' })
  const enter = calls.filter((c) => c.phase === 'enter')
  console.log(enter.map((c) => [c.role, c.datumIndex, c.datumCount]))
  expect(container.querySelectorAll('g.ts-chart__arc path').length).toBe(6)
  expect(enter.length).toBe(6) // one call per sector
})

Actual output:

[ [ 'arc', 0, 1 ] ]
AssertionError: expected 1 to be 6

Expected: delay is called per sector on enter, with datumIndex, datumCount and datum set, as for bars. Proposed: one enter track per sector, as createBarTracks does (motion.ts:1238).

F. Rounded polar arcs snap (moved here from #193 C)
  • radialArc builds a plain d3 arc() with .cornerRadius(...) (polar.ts:445-453) and attaches no path geometry, so addSemanticPathUpdateTrack returns false (motion.ts:2386-2399).
  • The generic path needs identical command skeletons (motion.ts:3650-3658); otherwise d is set directly.
  • Measured skeletons with cornerRadius(6), radii 60/80: sweep 0 rad MLZ, 0.012 MALAZ, 1 to 5 MAAALAAAZ, full circle MAAMAAZ. Crossing a threshold, including 0 to N, snaps.

Expected: a keyed arc whose angle changes animates. At minimum, document that a skeleton mismatch snaps.

Fix: radialArc, radialBarRadius and radialBarAngle attach arc geometry including corner radius so they use addSemanticPathUpdateTrack.

Repro: same file and command as A. With cornerRadius: 6 it fails; the cornerRadius: 0 control passes.

import { expect, it, vi } from 'vitest'
import { motion } from './motion'
import { polar, radialArc } from './polar'
import { createChartScene, defineChart } from './scene'

it.each([6, 0])('F: arc sweep tweens with cornerRadius %i', (cornerRadius) => {
  const queue: FrameRequestCallback[] = []
  const tick = (t: number) => queue.splice(0).forEach((f) => f(t))
  vi.spyOn(window, 'requestAnimationFrame').mockImplementation((f) => queue.push(f))
  vi.spyOn(window, 'cancelAnimationFrame').mockImplementation(() => {})
  const el = document.createElement('div')
  const s = motion({ transition: { type: 'tween', duration: 1000, easing: 'linear' } }).mount(el, () => {})
  const render = (e: number) => s.render(createChartScene(defineChart({
    scales: { x: null, y: null }, guides: false,
    marks: [polar({ scales: { angle: null, radius: null }, marks: [radialArc([{ id: 'a', s: 0, e }],
      { key: 'id', startAngle: 's', endAngle: 'e', innerRadius: 60, outerRadius: 80, cornerRadius })] })],
  }), { width: 300, height: 200 }), { ariaLabel: 'x' })
  render(0.012); tick(0); tick(2000)
  render(5); tick(0)
  const seen = new Set<string>()
  for (const t of [250, 500, 750]) { tick(t); seen.add(el.querySelector('path')!.getAttribute('d')!) }
  expect(seen.size).toBeGreaterThan(1)
})

Output on 57774e14: F: distinct d values at 250/500/750 ms with cornerRadius 6 = 1 (expected > 1); with cornerRadius: 0, 3 distinct values.

E. The arc enter sweep is a straight wedge clip, so rounded caps are cut flat (from this comment)

For built-in polar arcs (radialArc with cornerRadius, ring progress arcs, pie wedges), the enter animation does not draw an arc of growing sweep. createArcTracks clips the whole g.ts-chart__arc group with a <clipPath> whose path is a centre-anchored wedge, rebuilt per frame by radialSweepClipPath (motion.ts:1618-1700, motion.ts:1803-1820). The final shape is therefore revealed by a straight radial edge, and the leading end of a rounded arc shows a flat cut instead of a round cap until the sweep completes.

Read from source, not run (jsdom has no paint): render a radialArc with cornerRadius: 6 and a large sweep under motion() and inspect the group's clip-path mid-enter.

Expected: the same arc geometry that F needs (and B proposes exposing) would let the enter animate the arc's own end angle, so the cap stays round, instead of clipping. At minimum, document that the enter is a wedge clip.

B. The arc tween metadata is private

Expected: a documented optional field on SceneArea (arc values and projector) so custom marks get the arc tween.

C. Sunburst enter/exit seeds cannot be supplied

Moved to #214, together with the scale enter from #193 D.

D. Arc state styles have no angle or radius keys

Moved to #213, together with the geometry keys from #186 E.

A and F were run; B and E are read from source.

Related: polar states are in released code as commit 265b20e (see this comment); #126 and PR #158 do not yet reflect that.

Ngôn ngữ chính
TypeScript
Star
870
Fork
57
Merge trung bình
11 giờ 58 phút
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/charts

Tất cả issue của TanStack/charts

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.