[Feature] Gradients: tween stops under `motion()`, and support `gradientUnits`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- d3, typescript
- Área
- data-visualization, frontend
Línea de trabajo
Start with the repro in the issue: the vitest case for stop offsets uses motion() and createChartScene, and the focus-guide case uses surface.paintFocus. The relevant code is motionAttributes and the update track in packages/charts-core/src/motion.ts, renderGradients in svg.ts, focusGuideRenderHooks in svg-renderer.ts, and svg-surface.ts. Done means the stop offset changes across frames and the guide stroke resolves to url(#a-fade). Gradient units are a separate change, and the issue's own pattern and design notes suggest splitting it up.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version: @tanstack/charts 1.1.0 (57774e1).
Description
Gradients in definition.gradients have two gaps: stops snap instead of easing with motion() (A), and they cannot paint zero-width or zero-height strokes (B).
A. motion() does not tween gradient stops
offset,stop-opacityandstop-colorare not inmotionAttributes(motion.ts:2069-2090), so they are copied withsetAttribute(motion.ts:2243).<stop>is outsideg.ts-chart__marks, soguideOrMarkTimingContextreturnsundefined(motion.ts:3051-3052) and the update applies instantly (motion.ts:2277-2279).
Repro: save as packages/charts-core/src/repro.test.ts, run pnpm vitest run packages/charts-core/src/repro.test.ts.
import { expect, it, vi } from 'vitest'
import { scaleLinear } from 'd3-scale'
import { areaY } from './area'
import { crosshair } from './crosshair'
import { motion } from './motion'
import { createChartScene, defineChart } from './scene'
const make = (end: number, top: number) =>
createChartScene(defineChart({
marks: [
areaY([{ x: 0, y: 1 }, { x: 1, y: top }, { x: 2, y: 2 }], { x: 'x', y: 'y', fill: 'url(#fade)' }),
crosshair({ y: false, stroke: 'url(#fade)' }),
],
scales: { x: { scale: scaleLinear().domain([0, 2]) }, y: { scale: scaleLinear().domain([0, 4]) } },
gradients: [{ id: 'fade', stops: [
{ offset: 0, color: '#2563eb', opacity: 0.6 }, { offset: end, color: '#2563eb', opacity: 0 }] }],
}), { width: 320, height: 200 })
const opts = { ariaLabel: 't', idPrefix: 'a' }
it('A: stop offset eases with the update transition', () => {
const cbs: FrameRequestCallback[] = []
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => cbs.push(cb))
const el = document.createElement('div')
const surface = motion({ initial: false, transition: { type: 'tween', duration: 500 } }).mount(el, () => {})
surface.render(make(0.5, 3), opts)
surface.render(make(1, 2), opts)
const stop = el.querySelector('[data-ts-key="gradient:fade:stop:1"]')!
const offsets = [stop.getAttribute('offset')]
for (let t = 0; t <= 600; t += 100) {
cbs.splice(0).forEach((cb) => cb(t))
offsets.push(stop.getAttribute('offset'))
}
console.log('offsets:', offsets.join(' '))
expect(new Set(offsets).size).toBeGreaterThan(2)
})
Actual output:
offsets: 100% 100% 100% 100% 100% 100% 100% 100%
AssertionError: expected 1 to be greater than 2
Expected: offset and stop-opacity (ideally stop-color) interpolate with the update transition.
Proposal: add them to the update track for stops, with a timing context that reuses the root transition (for example a gradient role in ChartMotionRole).
Downstream measurement (bklit migration, Chrome, data-driven area fade): the gradient end moved about 18 px per update and snapped in one frame while the area eased.
B. No gradientUnits
- Gradients have no units field (types.ts:644-675) and
renderGradientsemits nogradientUnits(svg.ts:30-48), so SVG usesobjectBoundingBox. - A zero-width or zero-height stroke (
ruleX,ruleY, crosshair) has an empty bounding box, so the gradient paints nothing. The docs stateobjectBoundingBox(chart-spec.md:179-180).
Proposal: units?: 'objectBoundingBox' | 'userSpaceOnUse' on ChartGradientBase (default unchanged), emitted as gradientUnits.
C. Focus-guide nodes do not scope url(#id)
Moved to #211 (a bug, separate from these two features). The repro above already sets
idPrefix: 'a'and a gradient crosshair for it.
Path clip (this comment)
Moved to #216, together with the
<mask>ask from #128.
Related upstream
#129 (radial gradients, shipped in #147) and #128 / PR #166 (<pattern> resources) are different gaps.
- Lenguaje dominante
- TypeScript
- Estrellas
- 870
- Forks
- 57
- Merge medio
- 11 h 58 min
- PR fusionados (30 d)
- 18
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/charts
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
[Bug] Focus guides: `url(#id)` paints ignore `idPrefix`Posiblemente ocupada @getdownandcode la tomó hace 37 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TanStack/charts#211 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add reverse options to waffleY and waffleXPosiblemente ocupada @tannerlinsley la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/charts
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
fb55/htmlparser2#2579 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue needs-review
Dificultad 1/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
Add Module DB RulesAbiertodocumentation public
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
midnightntwrk/umbradb#65 ·
Los mantenedores suelen responder en 2 días
-
area/channels kind/bug priority/medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nanocoai/nanoclaw#4501 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildAbiertoneeds verification
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 13 días