mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-22 06:18:11 +08:00
render perf refinements (#1632)
* render performance improvements * improve render perf * remove logging * lint * improve memoziation
This commit is contained in:
@@ -117,6 +117,32 @@ class Scatterplot extends React.PureComponent {
|
||||
}
|
||||
);
|
||||
|
||||
computeHighlightFlags = memoize(
|
||||
(nObs, pointDilationData, pointDilationLabel) => {
|
||||
const flags = new Float32Array(nObs);
|
||||
if (pointDilationData) {
|
||||
for (let i = 0, len = flags.length; i < len; i += 1) {
|
||||
if (pointDilationData[i] === pointDilationLabel) {
|
||||
flags[i] = flagHighlight;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
);
|
||||
|
||||
computeColorByFlags = memoize((nObs, colorByData) => {
|
||||
const flags = new Float32Array(nObs);
|
||||
if (colorByData) {
|
||||
for (let i = 0, len = flags.length; i < len; i += 1) {
|
||||
if (!Number.isFinite(colorByData[i])) {
|
||||
flags[i] = flagNaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
});
|
||||
|
||||
computePointFlags = memoize(
|
||||
(crossfilter, colorByData, pointDilationData, pointDilationLabel) => {
|
||||
/*
|
||||
@@ -132,24 +158,25 @@ class Scatterplot extends React.PureComponent {
|
||||
continuous metadata, as they rely on different tests, and some of the flags
|
||||
(eg, isNaN) are meaningless in the face of categorical metadata.
|
||||
*/
|
||||
const nObs = crossfilter.size();
|
||||
|
||||
const flags = this.computeSelectedFlags(
|
||||
const selectedFlags = this.computeSelectedFlags(
|
||||
crossfilter,
|
||||
flagSelected,
|
||||
0
|
||||
).slice();
|
||||
);
|
||||
const highlightFlags = this.computeHighlightFlags(
|
||||
nObs,
|
||||
pointDilationData,
|
||||
pointDilationLabel
|
||||
);
|
||||
const colorByFlags = this.computeColorByFlags(nObs, colorByData);
|
||||
|
||||
if (colorByData || pointDilationData) {
|
||||
for (let i = 0, len = flags.length; i < len; i += 1) {
|
||||
if (pointDilationData) {
|
||||
flags[i] +=
|
||||
pointDilationData[i] === pointDilationLabel ? flagHighlight : 0;
|
||||
}
|
||||
if (colorByData) {
|
||||
flags[i] += Number.isFinite(colorByData[i]) ? 0 : flagNaN;
|
||||
}
|
||||
}
|
||||
const flags = new Float32Array(nObs);
|
||||
for (let i = 0; i < nObs; i += 1) {
|
||||
flags[i] = selectedFlags[i] + highlightFlags[i] + colorByFlags[i];
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user