-
Notifications
You must be signed in to change notification settings - Fork 185
pixel mark #1185
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
pixel mark #1185
Conversation
We could probably learn a trick or two from @yurivish's unbelievably fast https://observablehq.com/@twitter/zoomable-density-scatterplot Writing the colors directly in the canvas data would probably be faster than using fillRect, since we don't need (nor want) anti-aliasing. |
I often want a discrete quantitative scale, where I could draw a bar for a given unit, and it would have a width of 1 unit (minus insets). For example, when drawing a bar chart for yearly data, I would prefer to write: This option is slightly different from interval: 1, in that the bars would be ordinal-discrete, and centered on the unit, instead of covering [0, 1] we would cover [-0.5, 0.5]. And the scale would have a bandwidth. But (thinking out loud) maybe it is something we can do as an extension of interval: 1) an option to center things, and 2) add a bandwidth on the (continuous) scale. |
pixelRatio: 1 / k, | ||
x: (d, i) => i % m, | ||
y: (d, i) => Math.floor(i / m), | ||
fill: (d, i) => ((i % m & 1) === (Math.floor(i / m) & 1) ? true : i % m & 1 ? null : undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the i % m & 1 ? null :
part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to test that both null and undefined produce the same output (transparent).
I think we also need to support mixBlendMode internally (with context.globalCompositeOperation), for when we have several pixels at the same location? |
Okay, I added mixBlendMode support, but it’s pretty much unusably slow presumably because it’s not hardware optimized. I also added opacity support (as a fallback for fillOpacity, since both map to globalAlpha). |
I've documented the pixel mark. Many of the common options do not work, but that's expected. |
7635b37
to
2508468
Compare
Closing in favor of #1196. |
This…
I still need to write documentation, but I think this is functionally complete. I’m not 100% sure about the implementation, since adding and subtracting the default 0.5 can introduce tiny rounding errors (that go away when rounding during rendering, but still it would be nice to avoid them). I slightly wonder if it would be better to instead implement this as a canvas-based rect mark? Most other marks might want canvas-based rendering too… and in theory we Plot could even stack canvas and SVG elements rather than using svg:image (though that would break downloading).
Related #1122 #984.