Heatmap: Add independent rendering cell flags (#4950)#5035
Heatmap: Add independent rendering cell flags (#4950)#5035swharden merged 7 commits intoScottPlot:mainfrom
Conversation
There was a problem hiding this comment.
I'm of two minds about this, on one hand this render method may well be a good feature, it likely is more efficient (if we avoid building the cached bitmap) for small heatmaps, especially if they're updated more often then they're panned/zoomed.
But also I'd really rather just find a way to set image-rendering: pixelated on the generated SVGs and let this be handled by the user's image viewer. It will be drastically better on file size and it should look pixel-identical between renderers.
Unfortunately I don't believe this is supported in Skia for whatever reason, though it would be a relatively easy add. So our only option would be to manually edit the generated XML, which is not an idea that sparks joy for me.
Edit: I went all the way to drafting a patch for Skia upstream (see bclehmann/skia@717b241) before I realized that while image-rendering: pixelated is part of the CSS draft, and is thus supported on all SVGs rendered by browsers, it is not in the mainline SVG draft and so we would be relying on behaviour not required by the spec. It appears that W3 is considering it, but it's not yet there.
In the SVG spec we can rely on image-rendering: optimizeSpeed existing (though it's not in the CSS spec) but it is merely a hint and the spec states that implementers who can achieve their performance goals with methods other than nearest neighbour should do so. i.e. a conforming implementation is free to completely ignore this property and use bilinear or bicubic across the board.
|
Hey @CoderPM2011, thanks for this PR! ... and @bclehmann you're my hero for starting with a scottplot feature and trying to fix it by considering submitting a C++ patch to fix Skia 🤣
I'll implement this quickly and merge now, but I we can refine it in subsequent PRs as needed. I'm curious if new strategies will get added in the future. It seems like a new way to get custom rendering functionality! ... although it's not that different than inheriting overriding the virtual Render method, though I guess Update isn't virtual so I'll change that while I'm in there |
|
Hey @CoderPM2011 and @bclehmann, thanks for this PR! I think my implementation of strategy pattern was effective here, but I'll merge now and continue to welcome input on how to improve it. Thanks again! 🚀 |
The issue described in #4950 is similar to that in #5020.
SVG does not fully support pixel-based images, but the
Heatmaprendering currently relies onDrawing.BitmapFromArgbs().To address this, a new optional flag
IndependentCellRenderinghas been added.When set to
true, each cell is rendered independently usingDrawing.FillRectangle().However, when the number of cells is large, the difference is hardly noticeable in the SVG output, so it is generally unnecessary to use
IndependentCellRenderingin such cases. 🤔For this reason, the feature is disabled by default.
🧐 Users should carefully evaluate their needs before enabling it.
demo result (SVG)
demo code