[Feature] `fillOpacity` and `strokeOpacity` as per-datum channels, and `fill` on `rect`

Open
#270 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start with the channel definitions in packages/charts-core/src/rect.ts, bar.ts and dot.ts, then trace how marks pass visual channels into rendering and motion updates. Compare rect with barY and barX to identify the relevant types and tests. Done when per datum fillOpacity and strokeOpacity work on all four marks and rect accepts a per datum fill channel.

Written by the indexing model from the issue text.

Description

Version: @tanstack/charts 1.5.0 (b236dae).

A mark cannot draw its data at different opacities.

  • fillOpacity and strokeOpacity are numbers on rect, barY, barX and dot (rect.ts:48, bar.ts:70, dot.ts:52).
  • fill is a VisualChannel on bars but a constant on rect (bar.ts:69, rect.ts:47).
  • Mark states take a per-datum fillOpacity, but wait while data motion is active (motion.md:77), so they never apply in a chart that updates on every frame.

Use case: dimming the marks outside a range while the range is dragged.

The workaround is one mark for each datum:

marks: rows.map((row) =>
  rect([row], { id: `bar-${row.key}`, x1: 'x1', x2: 'x2', y1: 'y1', y2: 'y2', key: 'key', fillOpacity: row.opacity }),
)

The opacity tweens, but each update costs up to twice as much. Median synchronous host.update under motion(), headless Chromium 153, values changing and nothing else:

Bars One mark One mark for each bar
48 1.8 ms 2.4 ms
192 7.1 ms 13.1 ms
768 57.4 ms 116.4 ms
Ask
  • fillOpacity as VisualChannel<TDatum, number> on rect, barY, barX and dot, and strokeOpacity likewise.
  • fill as VisualChannel<TDatum, string> on rect, as bars have.
Dominant language
TypeScript
Stars
870
Forks
57
Avg merge
11h 58m
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TanStack/charts

All issues in TanStack/charts

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.