mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-11 02:30:56 +08:00
fix label selection on trunctated category lists (#1646)
This commit is contained in:
@@ -174,7 +174,7 @@ class Category extends React.PureComponent {
|
|||||||
actions.selectCategoricalAllMetadataAction(
|
actions.selectCategoricalAllMetadataAction(
|
||||||
"categorical metadata filter none of these",
|
"categorical metadata filter none of these",
|
||||||
metadataField,
|
metadataField,
|
||||||
categorySummary.categoryValues,
|
categorySummary.allCategoryValues,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -186,7 +186,7 @@ class Category extends React.PureComponent {
|
|||||||
actions.selectCategoricalAllMetadataAction(
|
actions.selectCategoricalAllMetadataAction(
|
||||||
"categorical metadata filter all of these",
|
"categorical metadata filter all of these",
|
||||||
metadataField,
|
metadataField,
|
||||||
categorySummary.categoryValues,
|
categorySummary.allCategoryValues,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -168,13 +168,12 @@ class CategoryValue extends React.Component {
|
|||||||
categoryIndex,
|
categoryIndex,
|
||||||
categorySummary,
|
categorySummary,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const labels = categorySummary.categoryValues;
|
const label = categorySummary.categoryValues[categoryIndex];
|
||||||
const label = labels[categoryIndex];
|
|
||||||
dispatch(
|
dispatch(
|
||||||
actions.selectCategoricalMetadataAction(
|
actions.selectCategoricalMetadataAction(
|
||||||
"categorical metadata filter deselect",
|
"categorical metadata filter deselect",
|
||||||
metadataField,
|
metadataField,
|
||||||
labels,
|
categorySummary.allCategoryValues,
|
||||||
label,
|
label,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
@@ -238,13 +237,12 @@ class CategoryValue extends React.Component {
|
|||||||
categoryIndex,
|
categoryIndex,
|
||||||
categorySummary,
|
categorySummary,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const labels = categorySummary.categoryValues;
|
const label = categorySummary.categoryValues[categoryIndex];
|
||||||
const label = labels[categoryIndex];
|
|
||||||
dispatch(
|
dispatch(
|
||||||
actions.selectCategoricalMetadataAction(
|
actions.selectCategoricalMetadataAction(
|
||||||
"categorical metadata filter select",
|
"categorical metadata filter select",
|
||||||
metadataField,
|
metadataField,
|
||||||
labels,
|
categorySummary.allCategoryValues,
|
||||||
label,
|
label,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -36,28 +36,30 @@ Remember that option values can be ANY js type, except undefined/null.
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
function topNCategories(colSchema, summary, N) {
|
function topNCategories(colSchema, summary, N) {
|
||||||
/* return top N by occurrences in the data */
|
/* return top N categories by occurrences in the data */
|
||||||
const { categories } = colSchema;
|
const { categories: allCategories } = colSchema;
|
||||||
const counts = categories.map((cat) => summary.categoryCounts.get(cat) ?? 0);
|
const counts = allCategories.map(
|
||||||
|
(cat) => summary.categoryCounts.get(cat) ?? 0
|
||||||
|
);
|
||||||
|
|
||||||
if (categories.length <= N) {
|
if (allCategories.length <= N) {
|
||||||
return [categories, counts];
|
return [allCategories, allCategories, counts];
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortIndex = fillRange(new Array(categories.length)).sort(
|
const sortIndex = fillRange(new Array(allCategories.length)).sort(
|
||||||
(a, b) => counts[b] - counts[a]
|
(a, b) => counts[b] - counts[a]
|
||||||
);
|
);
|
||||||
const topNindices = new Set(sortIndex.slice(0, N));
|
const topNindices = new Set(sortIndex.slice(0, N));
|
||||||
|
|
||||||
const _topNCategories = [];
|
const _topNCategories = [];
|
||||||
const topNCounts = [];
|
const topNCounts = [];
|
||||||
for (let i = 0; i < categories.length; i += 1) {
|
for (let i = 0; i < allCategories.length; i += 1) {
|
||||||
if (topNindices.has(i)) {
|
if (topNindices.has(i)) {
|
||||||
_topNCategories.push(categories[i]);
|
_topNCategories.push(allCategories[i]);
|
||||||
topNCounts.push(counts[i]);
|
topNCounts.push(counts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [_topNCategories, topNCounts];
|
return [allCategories, _topNCategories, topNCounts];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isSelectableCategoryName(schema, name) {
|
export function isSelectableCategoryName(schema, name) {
|
||||||
@@ -87,21 +89,22 @@ export function createCategorySummaryFromDfCol(dfCol, colSchema) {
|
|||||||
if they are not actively used in the current annoMatrix view.
|
if they are not actively used in the current annoMatrix view.
|
||||||
*/
|
*/
|
||||||
const summary = dfCol.summarizeCategorical();
|
const summary = dfCol.summarizeCategorical();
|
||||||
const [categoryValues, categoryValueCounts] = topNCategories(
|
const [
|
||||||
colSchema,
|
allCategoryValues,
|
||||||
summary,
|
categoryValues,
|
||||||
N
|
categoryValueCounts,
|
||||||
);
|
] = topNCategories(colSchema, summary, N);
|
||||||
const categoryValueIndices = new Map(categoryValues.map((v, i) => [v, i]));
|
const categoryValueIndices = new Map(categoryValues.map((v, i) => [v, i]));
|
||||||
const numCategoryValues = categoryValueIndices.size;
|
const numCategoryValues = categoryValueIndices.size;
|
||||||
const isTruncated = categoryValues.length < summary.numCategories;
|
const isTruncated = categoryValues.length < summary.numCategories;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
categoryValues, // array: of natively typed category values
|
allCategoryValues, // array: of natively typed category values (all of them)
|
||||||
categoryValueIndices, // map: category value (native type) -> category index
|
categoryValues, // array: of natively typed category values (top N only)
|
||||||
numCategoryValues, // number: of values in the category
|
categoryValueIndices, // map: category value (native type) -> category index (top N only)
|
||||||
isTruncated, // bool: true if list was truncated
|
numCategoryValues, // number: of values in the category (top N)
|
||||||
categoryValueCounts, // array: cardinality of each category,
|
isTruncated, // bool: true if list was truncated (ie, if topN != all)
|
||||||
|
categoryValueCounts, // array: cardinality of each category, (top N)
|
||||||
isUserAnno, // bool
|
isUserAnno, // bool
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user