mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-04 12:18:12 +08:00
If min / max are the same, hide histo + legend, show value (#1554)
* hide legend, histo single value * display block * extra check for domain * Update client/src/components/continuousLegend/index.js Co-authored-by: Severiano Badajoz <sbadajoz@chanzuckerberg.com> * readability on variables, use clipped ranges Co-authored-by: Severiano Badajoz <sbadajoz@chanzuckerberg.com>
This commit is contained in:
co-authored by
Severiano Badajoz
parent
d6c606b72e
commit
77ffa0712e
@@ -465,6 +465,7 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
isScatterplotXXaccessor,
|
isScatterplotXXaccessor,
|
||||||
isScatterplotYYaccessor,
|
isScatterplotYYaccessor,
|
||||||
zebra,
|
zebra,
|
||||||
|
ranges,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const fieldForId = field.replace(/\s/g, "_");
|
const fieldForId = field.replace(/\s/g, "_");
|
||||||
const {
|
const {
|
||||||
@@ -476,6 +477,8 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
const unclippedRangeMaxColor =
|
const unclippedRangeMaxColor =
|
||||||
world.clipQuantiles.max === 1 ? "#bbb" : globals.blue;
|
world.clipQuantiles.max === 1 ? "#bbb" : globals.blue;
|
||||||
|
|
||||||
|
const isSingleValue = ranges?.min === ranges?.max;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id={`histogram_${fieldForId}`}
|
id={`histogram_${fieldForId}`}
|
||||||
@@ -554,6 +557,7 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
<svg
|
<svg
|
||||||
|
style={{ display: isSingleValue ? "none" : "block" }}
|
||||||
width={this.width}
|
width={this.width}
|
||||||
height={this.height}
|
height={this.height}
|
||||||
id={`histogram_${fieldForId}_svg`}
|
id={`histogram_${fieldForId}_svg`}
|
||||||
@@ -564,10 +568,15 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "space-between",
|
justifyContent: isSingleValue ? "center" : "space-between",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span style={{ color: unclippedRangeMinColor }}>
|
<span
|
||||||
|
style={{
|
||||||
|
color: unclippedRangeMinColor,
|
||||||
|
display: isSingleValue ? "none" : "block",
|
||||||
|
}}
|
||||||
|
>
|
||||||
min {unclippedRangeMin.toPrecision(4)}
|
min {unclippedRangeMin.toPrecision(4)}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
@@ -576,7 +585,15 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
>
|
>
|
||||||
{field}
|
{field}
|
||||||
</span>
|
</span>
|
||||||
<span style={{ color: unclippedRangeMaxColor }}>
|
<div style={{ display: isSingleValue ? "block" : "none" }}>
|
||||||
|
: {unclippedRangeMin}
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: unclippedRangeMaxColor,
|
||||||
|
display: isSingleValue ? "none" : "block",
|
||||||
|
}}
|
||||||
|
>
|
||||||
max {unclippedRangeMax.toPrecision(4)}
|
max {unclippedRangeMax.toPrecision(4)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ const continuous = (selectorId, colorscale, colorAccessor) => {
|
|||||||
class ContinuousLegend extends React.Component {
|
class ContinuousLegend extends React.Component {
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const { colorAccessor, colorScale } = this.props;
|
const { colorAccessor, colorScale } = this.props;
|
||||||
|
const range = colorScale?.range;
|
||||||
|
const [domainMin, domainMax] = colorScale?.domain?.() ?? [0, 0];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
prevProps.colorAccessor !== colorAccessor ||
|
prevProps.colorAccessor !== colorAccessor ||
|
||||||
prevProps.colorScale !== colorScale
|
prevProps.colorScale !== colorScale
|
||||||
@@ -115,9 +118,9 @@ class ContinuousLegend extends React.Component {
|
|||||||
d3.select("#continuous_legend").selectAll("*").remove();
|
d3.select("#continuous_legend").selectAll("*").remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorAccessor && colorScale && colorScale.range) {
|
if (colorAccessor && colorScale && range && domainMin < domainMax) {
|
||||||
/* fragile! continuous range is 0 to 1, not [#fa4b2c, ...], make this a flag? */
|
/* fragile! continuous range is 0 to 1, not [#fa4b2c, ...], make this a flag? */
|
||||||
if (colorScale.range()[0][0] !== "#") {
|
if (range()[0][0] !== "#") {
|
||||||
continuous(
|
continuous(
|
||||||
"#continuous_legend",
|
"#continuous_legend",
|
||||||
d3.scaleSequential(interpolateCool).domain(colorScale.domain()),
|
d3.scaleSequential(interpolateCool).domain(colorScale.domain()),
|
||||||
@@ -128,7 +131,15 @@ class ContinuousLegend extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { colorAccessor } = this.props;
|
const { colorAccessor, colorScale } = this.props;
|
||||||
|
|
||||||
|
if (
|
||||||
|
colorScale?.domain &&
|
||||||
|
colorScale.domain()[1] === colorScale.domain()[0]
|
||||||
|
) {
|
||||||
|
/* it's a single value, not a distribution, min max are the same */
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id="continuous_legend"
|
id="continuous_legend"
|
||||||
|
|||||||
Reference in New Issue
Block a user