categorical fields

This commit is contained in:
Colin Megill
2017-10-10 23:55:20 -07:00
parent 448d177b4f
commit e5b8d473d6
+66 -29
View File
@@ -1,59 +1,96 @@
import React from "react"; 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 * as globals from "../../globals";
import styles from "./categorical.css";
import SectionHeader from "../framework/sectionHeader"
import createCategoryCounts from "./createCategoryCounts";
import { updateCategoricalQueryParams } from "../../util";
import cells from "../../../data/GBM_metadata.js"; import cells from "../../../data/GBM_metadata.js";
import createCategoryCounts from "./createCategoryCounts";
const Button = ({category, c, i}) => ( const Button = ({category, value, count, i}) => (
<button <button
key={i} key={i}
onClick={() => {
updateCategoricalQueryParams(category, value)
}}
style={{ style={{
border: i > -1 ? "none" : `1px solid ${globals.lightgrey}`, border: "none",
background: i > -1 ? globals.hcaBlue : "none", background: "none",
color: i > -1 ? "white" : "black", color: "black",
padding: "7px 10px", padding: "7px 10px",
marginRight: 20, marginRight: 3,
borderRadius: 3,
cursor: "pointer" cursor: "pointer"
}}> }}>
{c} {value}
<span <span
style={{ style={{
fontWeight: i > -1 ? globals.bolder : "auto", fontFamily: globals.accentFont,
background: i > -1 ? "white" : "none", fontStyle: "italic",
color: "black", color: "black",
marginLeft: 10, marginLeft: 4,
padding: "2px 4px",
borderRadius: 3 borderRadius: 3
}}> }}>
{category[c]} {count}
</span> </span>
</button> </button>
) )
const Category = ({category, title}) => ( const alphabeticallySortedValues = (values) => {
<div> return Object.keys(values).sort((a, b) => {
<p>{title}</p> var textA = a.toUpperCase();
{ _.map(Object.keys(category), (c, i) => <Button key={i} category={category} c={c} i={i} />) } var textB = b.toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
})
}
const Category = ({category, values}) => (
<div style={{
display: "flex",
alignItems: "baseline",
maxWidth: globals.maxParagraphWidth,
}}>
<p style={{
flexShrink: 0,
width: 100,
textAlign: "right",
marginRight: 20
}}>{category}:</p>
<div>
{ _.map(alphabeticallySortedValues(values), (v, i) => <Button key={v} category={category} count={values[v]} value={v} i={i} />) }
</div>
</div> </div>
) )
const Categorical = () => { @connect((state) => {
return {
foo123: state
}
})
class Categorical extends React.Component {
constructor(props) {
super(props);
this.state = {
return ( };
<div style={{marginTop: 50}}> }
<h3>Categorical Metadata</h3> render () {
{ return (
_.map(createCategoryCounts(cells), <div style={{marginTop: 50}}>
(value, key) => {
return <Category key={key} title={key} category={value} />
})
}
</div>
)
<SectionHeader text="Categorical Metadata"/> <SectionHeader text="Categorical Metadata"/>
<p> Sort by: Alphabetical / Count || Show counts: true / false || Collapse: all / none</p>
{
_.map(createCategoryCounts(cells),
(value, key) => {
return <Category key={key} category={key} values={value} />
})
}
</div>
)
}
}; };
export default Categorical; export default Categorical;