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 ( -... truncated list ...
+ ) : null} +