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

オープン
#194 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
870
フォーク
57
平均マージ
11時間 58分
マージ済み PR(30日)
18

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/charts のほかの issue

TanStack/charts の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。