diff --git a/client/src/components/categorical/categorical.js b/client/src/components/categorical/categorical.js index 8e7721b4..bddff2dc 100644 --- a/client/src/components/categorical/categorical.js +++ b/client/src/components/categorical/categorical.js @@ -3,20 +3,29 @@ import React from "react"; import _ from "lodash"; import { connect } from "react-redux"; +import * as globals from "../../globals"; import Category from "./category"; -@connect(state => { - const ranges = _.get(state.controls.world, "summary.obs", null); - return { - ranges - }; -}) -class Categories extends React.Component { - constructor(props) { - super(props); - this.state = {}; +/* Cap the max number of displayed categories */ +const truncateCategories = options => { + const numOptions = _.size(options); + if (numOptions <= globals.maxCategoricalOptionsToDisplay) { + return options; } + 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() { const { ranges } = this.props; if (!ranges) return null; @@ -28,16 +37,20 @@ class Categories extends React.Component { marginRight: 40, paddingRight: 20, flexShrink: 0 - // height: 700, - // overflow: "auto", }} >

Categorical Metadata

{_.map(ranges, (value, key) => { const isColorField = key.includes("color") || key.includes("Color"); if (value.options && !isColorField && key !== "name") { + const categoryOptions = truncateCategories(value.options); return ( - + ); } return undefined; diff --git a/client/src/components/categorical/category.js b/client/src/components/categorical/category.js index da0c5ad2..02bb8d20 100644 --- a/client/src/components/categorical/category.js +++ b/client/src/components/categorical/category.js @@ -91,7 +91,7 @@ class Category extends React.Component { render() { const { isExpanded, isChecked } = this.state; - const { metadataField, colorAccessor } = this.props; + const { metadataField, colorAccessor, isTruncated } = this.props; return (
{isExpanded ? this.renderCategoryItems() : null}
+
+ {isExpanded && isTruncated ? ( +

... truncated list ...

+ ) : null} +
); } diff --git a/client/src/globals.js b/client/src/globals.js index 452a06f1..c997a6cd 100644 --- a/client/src/globals.js +++ b/client/src/globals.js @@ -28,6 +28,8 @@ export const continuous = [ "Unmapped_short" ]; +export const maxCategoricalOptionsToDisplay = 100; + /* colors */ export const blue = "#4a90e2"; export const hcaBlue = "#1c7cc7";