This commit is contained in:
Bruce Martin
2020-04-20 09:56:26 -07:00
committed by GitHub
parent 8b59755157
commit 8742f9094e
2 changed files with 29 additions and 55 deletions
@@ -17,6 +17,7 @@ import AnnoDialog from "../annoDialog";
import LabelInput from "../labelInput"; import LabelInput from "../labelInput";
import { AnnotationsHelpers } from "../../../util/stateManager"; import { AnnotationsHelpers } from "../../../util/stateManager";
import maybeTruncateString from "../../../util/maybeTruncateString";
import { labelPrompt, isLabelErroneous } from "../labelUtil"; import { labelPrompt, isLabelErroneous } from "../labelUtil";
/* this is defined outside of the class so we can use it in connect() */ /* this is defined outside of the class so we can use it in connect() */
@@ -291,6 +292,7 @@ class CategoryValue extends React.Component {
// our lint doesn't like jsx spread, we are version pinned to prevent api change on their part // our lint doesn't like jsx spread, we are version pinned to prevent api change on their part
flippedProps, flippedProps,
isDilated, isDilated,
world,
} = this.props; } = this.props;
const ontologyEnabled = ontology?.enabled ?? false; const ontologyEnabled = ontology?.enabled ?? false;
@@ -312,29 +314,12 @@ class CategoryValue extends React.Component {
categories = schema.annotations.obsByName[colorAccessor]?.categories; categories = schema.annotations.obsByName[colorAccessor]?.categories;
} }
let truncatedString = null; const truncatedString = maybeTruncateString(
displayString,
if ( colorAccessor && !isColorBy
colorAccessor && ? globals.categoryLabelDisplayStringShortLength
!isColorBy && : globals.categoryLabelDisplayStringLongLength
displayString.length > globals.categoryLabelDisplayStringShortLength );
) {
truncatedString = `${displayString.slice(
0,
globals.categoryLabelDisplayStringShortLength / 2
)}…${displayString.slice(
-globals.categoryLabelDisplayStringShortLength / 2
)}`;
} else if (
displayString.length > globals.categoryLabelDisplayStringLongLength
) {
truncatedString = `${displayString.slice(
0,
globals.categoryLabelDisplayStringLongLength / 2
)}…${displayString.slice(
-globals.categoryLabelDisplayStringLongLength / 2
)}`;
}
const editModeActive = const editModeActive =
isUserAnno && isUserAnno &&
@@ -464,8 +449,12 @@ class CategoryValue extends React.Component {
<span style={{ flexShrink: 0 }}> <span style={{ flexShrink: 0 }}>
{colorAccessor && !isColorBy && !annotations.isEditingLabelName ? ( {colorAccessor && !isColorBy && !annotations.isEditingLabelName ? (
<Occupancy <Occupancy
category={category} categoryValue={value}
{...this.props} // eslint-disable-line react/jsx-props-no-spreading colorAccessor={colorAccessor}
metadataField={metadataField}
world={world}
colorScale={colorScale}
colorByIsCategorical={!!categoricalSelection[colorAccessor]}
/> />
) : null} ) : null}
</span> </span>
@@ -6,7 +6,7 @@ import {
Popover, Popover,
PopoverInteractionKind, PopoverInteractionKind,
Position, Position,
Classes Classes,
} from "@blueprintjs/core"; } from "@blueprintjs/core";
@connect() @connect()
@@ -21,13 +21,7 @@ class Occupancy extends React.PureComponent {
createHistogram fetches the continous data in relation to the cells releveant to the catagory value. createHistogram fetches the continous data in relation to the cells releveant to the catagory value.
It then seperates that data into 50 bins for drawing the mini-histogram It then seperates that data into 50 bins for drawing the mini-histogram
*/ */
const { const { world, metadataField, colorAccessor, categoryValue } = this.props;
world,
metadataField,
colorAccessor,
category,
categoryIndex
} = this.props;
if (!this.canvas) return; if (!this.canvas) return;
@@ -45,7 +39,7 @@ class Occupancy extends React.PureComponent {
groupBy groupBy
); /* Because the signature changes we really need different names for histogram to differentiate signatures */ ); /* Because the signature changes we really need different names for histogram to differentiate signatures */
const categoryValue = category.categoryValues[categoryIndex]; // const categoryValue = category.categoryValues[categoryIndex];
const bins = histogramMap.has(categoryValue) const bins = histogramMap.has(categoryValue)
? histogramMap.get(categoryValue) ? histogramMap.get(categoryValue)
: new Array(50).fill(0); : new Array(50).fill(0);
@@ -88,11 +82,10 @@ class Occupancy extends React.PureComponent {
world, world,
metadataField, metadataField,
colorAccessor, colorAccessor,
category, categoryValue,
categoryIndex, colorScale,
schema,
colorScale
} = this.props; } = this.props;
const { schema } = world;
const ctx = this.canvas?.getContext("2d"); const ctx = this.canvas?.getContext("2d");
@@ -103,7 +96,7 @@ class Occupancy extends React.PureComponent {
.col(colorAccessor) .col(colorAccessor)
.histogramCategorical(groupBy); .histogramCategorical(groupBy);
const occupancy = occupancyMap.get(category.categoryValues[categoryIndex]); const occupancy = occupancyMap.get(categoryValue);
if (occupancy && occupancy.size > 0) { if (occupancy && occupancy.size > 0) {
// not all categories have occupancy, so occupancy may be undefined. // not all categories have occupancy, so occupancy may be undefined.
@@ -137,19 +130,11 @@ class Occupancy extends React.PureComponent {
}; };
render() { render() {
const { const { colorAccessor, categoryValue, colorByIsCategorical } = this.props;
colorAccessor,
categoricalSelection,
category,
categoryIndex
} = this.props;
const { canvas } = this; const { canvas } = this;
if (canvas) if (canvas)
canvas.getContext("2d").clearRect(0, 0, this._WIDTH, this._HEIGHT); canvas.getContext("2d").clearRect(0, 0, this._WIDTH, this._HEIGHT);
const colorByIsCatagoricalData = !!categoricalSelection[colorAccessor];
return ( return (
<Popover <Popover
interactionKind={PopoverInteractionKind.HOVER_TARGET_ONLY} interactionKind={PopoverInteractionKind.HOVER_TARGET_ONLY}
@@ -158,11 +143,11 @@ class Occupancy extends React.PureComponent {
position={Position.LEFT} position={Position.LEFT}
modifiers={{ modifiers={{
preventOverflow: { enabled: false }, preventOverflow: { enabled: false },
hide: { enabled: false } hide: { enabled: false },
}} }}
lazy lazy
usePortal usePortal
disabled={colorByIsCatagoricalData} disabled={colorByIsCategorical}
popoverClassName={Classes.POPOVER_CONTENT_SIZING} popoverClassName={Classes.POPOVER_CONTENT_SIZING}
> >
<canvas <canvas
@@ -171,15 +156,15 @@ class Occupancy extends React.PureComponent {
marginRight: 5, marginRight: 5,
width: this._WIDTH, width: this._WIDTH,
height: this._HEIGHT, height: this._HEIGHT,
borderBottom: colorByIsCatagoricalData borderBottom: colorByIsCategorical
? "" ? ""
: "solid rgb(230, 230, 230) 0.25px" : "solid rgb(230, 230, 230) 0.25px",
}} }}
width={this._WIDTH} width={this._WIDTH}
height={this._HEIGHT} height={this._HEIGHT}
ref={ref => { ref={(ref) => {
this.canvas = ref; this.canvas = ref;
if (colorByIsCatagoricalData) this.createOccupancyStack(); if (colorByIsCategorical) this.createOccupancyStack();
else this.createHistogram(); else this.createHistogram();
}} }}
/> />
@@ -187,7 +172,7 @@ class Occupancy extends React.PureComponent {
<p style={{ margin: "0" }}> <p style={{ margin: "0" }}>
This histograms shows the distribution of{" "} This histograms shows the distribution of{" "}
<strong>{colorAccessor}</strong> within{" "} <strong>{colorAccessor}</strong> within{" "}
<strong>{category.categoryValues[categoryIndex]}</strong>. <strong>{categoryValue}</strong>.
<br /> <br />
<br /> <br />
The x axis is the same for each histogram, while the y axis is The x axis is the same for each histogram, while the y axis is