Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paint #1731

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

paint #1731

wants to merge 4 commits into from

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Jun 29, 2023

This introduces a paint method for specifying SVG paint servers, namely patterns and gradients.

In contrast to the render function approach and function uris, this approach eliminates manual management of unique identifiers, and lets you specify the desired paint inline, in one place — either as a constant fill or stroke option, or the range of an ordinal color scale (and perhaps even a quantitative scale?).

This also lets us offer convenience constructors for common paint servers such as linearGradient. We have to decide how much of the CSS specification to implement… but you could always go beyond that with a custom paint method. We should also decide whether e.g. color stops are expressed relative to the object bounding box, or if the stops should be positioned in data space. The former is the SVG default, but the latter allows more meaningful encodings in visualization.

TODO

  • Types
  • Documentation
  • Tests
  • Allow fill to be specified as a constant paint
  • Allow fill to be specified as a paint channel
  • Allow stroke to be specified a constant paint
  • Allow stroke to be specified as a paint channel
  • Allow ordinal color range to be specified as an array of paints
  • Assign unique identifiers when rendering paints
  • Design a linearGradient API… userSpaceOnUse or objectBoundingBox?

Fixes #185 #903 (with additional work).

@mbostock mbostock requested a review from Fil June 29, 2023 12:27
@Fil
Copy link
Contributor

Fil commented Jun 29, 2023

Sounds promising! (Also, somehow related to #1132 / #1109, for the attribution of a unique id.)

I'm trying to think about how we would express these gradients in the API.

A few use cases for data encoding:

These cases are arguably (more or less) covered by the variable stroke feature. They have a color that depends on the datum (x or y), and an orientation that can be horizontal or vertical. The corresponding stops would have to be sorted and normalized into 0%—100%, or, alternatively, generated with ticks?

(Assuming we had sankey paths as a mark, but we can think of it as a link mark.) In this case the orientation would be given by the direction of the mark (source to target). Each individual mark would need two colors, either constant or a channel: one for the source and the other for the target.

There might be more use cases that we'd want to support.

Then there are "aesthetic" use cases, for example to paint each country with a gradient to give some visual dynamism to a map. In that case we need the orientation and n colors.

A secondary question is how do we make the ids predictable? Would they be some sort of a hash of the parameters+a counter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color gradients?
2 participants