handle case of excessively large number of options in categorical met… (#350)

* handle case of excessively large number of options in categorical metadata
* move max category options count into globals
This commit is contained in:
Bruce Martin
2018-10-18 18:07:39 -07:00
committed by GitHub
parent 06f402ab0a
commit 5dea303bcd
3 changed files with 34 additions and 14 deletions
@@ -3,20 +3,29 @@ import React from "react";
import _ from "lodash"; import _ from "lodash";
import { connect } from "react-redux"; import { connect } from "react-redux";
import * as globals from "../../globals";
import Category from "./category"; import Category from "./category";
@connect(state => { /* Cap the max number of displayed categories */
const ranges = _.get(state.controls.world, "summary.obs", null); const truncateCategories = options => {
return { const numOptions = _.size(options);
ranges if (numOptions <= globals.maxCategoricalOptionsToDisplay) {
}; return options;
})
class Categories extends React.Component {
constructor(props) {
super(props);
this.state = {};
} }
return _(options)
.map((v, k) => ({ name: k, val: v }))
.sortBy("val")
.slice(numOptions - globals.maxCategoricalOptionsToDisplay)
.transform((r, v) => {
r[v.name] = v.val;
}, {})
.value();
};
@connect(state => ({
ranges: _.get(state.controls.world, "summary.obs", null)
}))
class Categories extends React.Component {
render() { render() {
const { ranges } = this.props; const { ranges } = this.props;
if (!ranges) return null; if (!ranges) return null;
@@ -28,16 +37,20 @@ class Categories extends React.Component {
marginRight: 40, marginRight: 40,
paddingRight: 20, paddingRight: 20,
flexShrink: 0 flexShrink: 0
// height: 700,
// overflow: "auto",
}} }}
> >
<p> Categorical Metadata </p> <p> Categorical Metadata </p>
{_.map(ranges, (value, key) => { {_.map(ranges, (value, key) => {
const isColorField = key.includes("color") || key.includes("Color"); const isColorField = key.includes("color") || key.includes("Color");
if (value.options && !isColorField && key !== "name") { if (value.options && !isColorField && key !== "name") {
const categoryOptions = truncateCategories(value.options);
return ( return (
<Category key={key} metadataField={key} values={value.options} /> <Category
key={key}
metadataField={key}
values={categoryOptions}
isTruncated={categoryOptions !== value.options}
/>
); );
} }
return undefined; return undefined;
@@ -91,7 +91,7 @@ class Category extends React.Component {
render() { render() {
const { isExpanded, isChecked } = this.state; const { isExpanded, isChecked } = this.state;
const { metadataField, colorAccessor } = this.props; const { metadataField, colorAccessor, isTruncated } = this.props;
return ( return (
<div <div
style={{ style={{
@@ -163,6 +163,11 @@ class Category extends React.Component {
</p> </p>
</div> </div>
<div>{isExpanded ? this.renderCategoryItems() : null}</div> <div>{isExpanded ? this.renderCategoryItems() : null}</div>
<div>
{isExpanded && isTruncated ? (
<p style={{ paddingLeft: 15 }}>... truncated list ...</p>
) : null}
</div>
</div> </div>
); );
} }
+2
View File
@@ -28,6 +28,8 @@ export const continuous = [
"Unmapped_short" "Unmapped_short"
]; ];
export const maxCategoricalOptionsToDisplay = 100;
/* colors */ /* colors */
export const blue = "#4a90e2"; export const blue = "#4a90e2";
export const hcaBlue = "#1c7cc7"; export const hcaBlue = "#1c7cc7";