-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Improve heatmap rendering performance when zsmooth
is false
#6574
Conversation
- add `trace._is_linear` flag to help determine drawing method - use "fast" drawing method whenever possible (ie. flag is true, no gap) - fix heatmap tests, taking account of these changes
Thanks @lvlte! Re: feature detection - I did a little checking and wasn't able to get an svg var _supportsPixelated = null;
function supportsPixelated() {
if(_supportsPixelated === null) { // only run the feature detection once
var img = document.createElement('img');
document.body.appendChild(img);
img.style.imageRendering = 'pixelated';
_supportsPixelated = getComputedStyle(img).imageRendering === 'pixelated';
document.body.removeChild(img);
}
return _supportsPixelated;
} |
Thank you @alexcjohnson, I used your code as a starting point to make the testing work with SVG Also, it's worth noting the exact same trick is used for image traces, the fallbacks were taken from there actually (see my comment on the issue, you probably missed it because I've made an edit). I also tried |
@lvlte Thanks for the PR. |
src/traces/heatmap/plot.js
Outdated
// `-ms-interpolation-mode` works only with <img> not with SVG <image> | ||
_supportsPixelated = false; | ||
} else { | ||
var declarations = Array.from(pixelatedImageCSS).reverse(); |
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.
Could you please elaborate why we need to reverse the list here?
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.
The pixelatedImageCSS
array is ordered so that the actual declaration image-rendering: pixelated
, which targets modern browsers (most users) is the last one, and the oldest fallback comes first. Reversing the array is just for doing the testing on the actual declaration first, and let declarations.some
returns early.
Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com>
Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com>
- move style and support function into `src/lib` - make heatmap and image trace use the same base
- fix circular dependency (introduced in previous commit) - move css constants into `src/constants/pixelated_image` - move support function into `src/lib/supports_pixelated_image`
Make the condition test work regardless of the drawing method
💃 |
@lvlte great work! Not only better performance, I think the results actually look better than before, ie the brick edges are positioned more accurately. Also you taught me about |
This PR fixes #6573, here are the main changes :
trace._is_linear
flag to help determine drawing methodimage-rendering
directive, I should probably have started with this !)Although the vocabulary about the drawing method might not be appropriate or sounds confusing, the proposition here is to render the heatmap according to the determined method instead of the
zsmooth
parameter, for now these methods appears in the code as :zsmooth='best'
(manual interpolation), usesimageData
zsmooth=false|'fast'
, usesimageData
; fastest method but requires all bricks be uniform, with no xgap/ygap, if zsmooth is 'fast' we let the browser do the interpolation, otherwise we prevent it from doing so;zsmooth=false
), usesfillRect