// jshint esversion: 6 import { connect } from "react-redux"; import React from "react"; import _ from "lodash"; import Occupancy from "./occupancy"; import { countCategoryValues2D } from "../../util/stateManager/worldUtil"; import * as globals from "../../globals"; @connect(state => ({ categoricalSelectionState: state.controls.categoricalSelectionState, colorScale: state.controls.colorScale, colorAccessor: state.controls.colorAccessor, schema: _.get(state.controls.world, "schema", null), world: state.controls.world })) class CategoryValue extends React.Component { toggleOff() { const { dispatch, metadataField, categoryIndex } = this.props; dispatch({ type: "categorical metadata filter deselect", metadataField, categoryIndex }); } toggleOn() { const { dispatch, metadataField, categoryIndex } = this.props; dispatch({ type: "categorical metadata filter select", metadataField, categoryIndex }); } render() { const { categoricalSelectionState, metadataField, categoryIndex, colorAccessor, colorScale, i, schema, world } = this.props; if (!categoricalSelectionState) return null; const category = categoricalSelectionState[metadataField]; const selected = category.categorySelected[categoryIndex]; const count = category.categoryCounts[categoryIndex]; const value = category.categoryValues[categoryIndex]; const displayString = String( category.categoryValues[categoryIndex] ).valueOf(); /* this is the color scale, so add swatches below */ const isColorBy = metadataField === colorAccessor; let categories = null; let occupancy = null; if (isColorBy && schema) { categories = _.filter(schema.annotations.obs, { name: colorAccessor })[0].categories; } if (colorAccessor && !isColorBy) { occupancy = countCategoryValues2D( metadataField, colorAccessor, world.obsAnnotations ); } return (
{colorAccessor && !isColorBy && categoricalSelectionState[colorAccessor] ? ( ) : null}
{count}
); } } export default CategoryValue;