mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-24 10:08:13 +08:00
Fix label sorting bugs (#1102)
* move category label sort to utils * refactor cat label sort * fix category label sort and color assignment * convert whitespace from tabs to spaces
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
|
||||
import * as globals from "../../globals";
|
||||
import Value from "./value";
|
||||
import sortedCategoryValues from "./util";
|
||||
import sortedCategoryLabels from "../../util/catLabelSort";
|
||||
import { AnnotationsHelpers } from "../../util/stateManager";
|
||||
|
||||
@connect(state => ({
|
||||
@@ -321,11 +321,8 @@ class Category extends React.Component {
|
||||
annotations
|
||||
} = this.props;
|
||||
const { isTruncated } = categoricalSelection[metadataField];
|
||||
|
||||
const cat = categoricalSelection[metadataField];
|
||||
const optTuples = sortedCategoryValues(isUserAnno, [
|
||||
...cat.categoryValueIndices
|
||||
]);
|
||||
const optTuples = [...cat.categoryValueIndices];
|
||||
const optTuplesAsKey = _.map(optTuples, t => t[0]).join(""); // animation
|
||||
const allCategoryNames = _.keys(categoricalSelection);
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// jshint esversion: 6
|
||||
|
||||
// values is [ [optVal, optIdx], ...]
|
||||
// index is range array
|
||||
// return sorted index
|
||||
|
||||
/*
|
||||
Sort category values (labels) in the order we want for presentation.
|
||||
|
||||
TL;DR: numeric sort for number-like strings, then strings in case-ignoring alpha
|
||||
order. Except, when isUserAnno is true, pin globals.unassignedCategoryLabel
|
||||
to the end.
|
||||
|
||||
*/
|
||||
|
||||
import isNumber from "is-number";
|
||||
import * as globals from "../../globals";
|
||||
|
||||
const sortedCategoryValues = (isUserAnno, values) => {
|
||||
/* this sort could be memoized for perf */
|
||||
|
||||
const strings = [];
|
||||
const ints = [];
|
||||
const unassigned = [];
|
||||
|
||||
values.forEach(v => {
|
||||
if (isUserAnno && v[0] === globals.unassignedCategoryLabel) {
|
||||
unassigned.push(v);
|
||||
} else if (isNumber(v[0])) {
|
||||
ints.push(v);
|
||||
} else {
|
||||
strings.push(v);
|
||||
}
|
||||
});
|
||||
|
||||
strings.sort((a, b) => {
|
||||
const textA = String(a[0]).toUpperCase();
|
||||
const textB = String(b[0]).toUpperCase();
|
||||
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
||||
});
|
||||
|
||||
ints.sort((a, b) => +a[0] - +b[0]);
|
||||
|
||||
return ints.concat(strings, unassigned);
|
||||
};
|
||||
|
||||
export default sortedCategoryValues;
|
||||
Reference in New Issue
Block a user