[Feature] `motion()`: ticks that enter or leave on a change of scale do not travel with it

Đang mở
#269 0 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
57/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
d3, typescript

Hướng nghiên cứu

Start in packages/charts-core/src/motion.ts at the enter and exit opacity tweens, then read packages/charts-core/src/scene.ts where ticks are keyed by value. Compare the renderer’s previous and next scenes and scale positions; the issue’s Vitest repro gives a concrete check. Done means entering ticks start at their previous-scale positions and leaving ticks end at their new-scale positions while still fading.

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.5.0 (b236dae).

When a continuous scale's domain changes, a kept tick moves with the marks, but an entering tick fades in at its final place and a leaving one fades out where it stood. With a y domain going from 0–100 to 0–200, the 100 label slides down from the top while the new 200 label already sits there. Grid lines do the same.

Ticks are keyed by value (scene.ts:1883), and enter and exit are opacity tweens only (motion.ts:2642-2659, motion.ts:2749-2762). d3-axis starts an entering tick at its value's place on the previous scale and ends a leaving one at its place on the new scale (axis.js, __axis).

Repro

npm i @tanstack/[email protected] vitest jsdom, then npx vitest run ticks.test.ts.

// @vitest-environment jsdom
import { defineChart, lineY } from '@tanstack/charts'
import { motion } from '@tanstack/charts/motion'
import { mountChartRenderer } from '@tanstack/charts/renderer'
import { scaleLinear } from '@tanstack/charts/scales/linear'
import { expect, it, vi } from 'vitest'

it('entering and leaving ticks travel with a change of scale', () => {
  let now = 0
  const frames: FrameRequestCallback[] = []
  vi.spyOn(performance, 'now').mockImplementation(() => now)
  vi.spyOn(window, 'requestAnimationFrame').mockImplementation((f) => frames.push(f))
  const renderer = motion({ initial: false, transition: { type: 'tween', duration: 400, easing: 'linear' } })
  // Ticks at 0, top / 2 and top. In the plot, y=170 is 0 and y=10 is `top`.
  const options = (top: number) => ({
    definition: defineChart({
      marks: [lineY([{ x: 0, y: 10 }, { x: 1, y: 90 }], { x: 'x', y: 'y' })],
      scales: {
        x: { scale: scaleLinear().domain([0, 1]) },
        y: { scale: scaleLinear().domain([0, top]), axis: { ticks: { values: [0, top / 2, top] } } },
      },
      margin: { top: 10, right: 10, bottom: 30, left: 40 },
    }),
    renderer,
    width: 300,
    height: 200,
    ariaLabel: 'ticks',
  })
  const el = document.createElement('div')
  const host = mountChartRenderer(el, options(100))
  const y = (tick: number) =>
    Number(el.querySelector(`[data-ts-key="y-tick-label:number:${tick}"]`)?.getAttribute('y'))

  host.update(options(200)) // 100 moves from y=10 to y=90, 200 enters, 50 leaves
  now = 200 // half way
  frames.splice(0).forEach((frame) => frame(now))
  // On the scale the kept tick is moving with, 200 is at y=-70 and 50 at y=110.
  expect({ kept100: y(100), entering200: y(200), leaving50: y(50) }).toEqual({ kept100: 50, entering200: -70, leaving50: 110 })
})
-   "entering200": -70,
+   "entering200": 10,
    "kept100": 50,
-   "leaving50": 110,
+   "leaving50": 90,
Ask

Under motion(), when a continuous scale's domain changes, an entering tick rule, label and grid line start where their value sits on the previous scale, and a leaving one ends where its value sits on the new scale, each still fading. The renderer holds both scenes, so this needs no option.

The workaround is two renders in one frame (the new tick values on the old domain with enter motion off, then the real update), which needs fixed margins and thin: false, and still leaves exiting ticks in place.

Related: #195, #214.

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.