[Feature] Gradients: tween stops under `motion()`, and support `gradientUnits`
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- d3, typescript
- Ambito
- data-visualization, frontend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 870
- Fork
- 57
- Merge medio
- 11h 58m
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/charts
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Focus guides: `url(#id)` paints ignore `idPrefix`Forse già presa @getdownandcode l’ha presa 37 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
TanStack/charts#211 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add reverse options to waffleY and waffleXForse già presa @tannerlinsley l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/charts
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
fb55/htmlparser2#2579 ·
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue needs-review
Difficoltà 1/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Add Module DB RulesApertadocumentation public
Difficoltà 1/5 1-3 ore Idoneità per principianti 68/100
midnightntwrk/umbradb#65 ·
I maintainer di solito rispondono entro 2 giorni
-
area/channels kind/bug priority/medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nanocoai/nanoclaw#4501 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
needs verification
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 13 giorni