Skip to content

Commit 4b7395f

Browse files
authored
Merge pull request #574 from FluxNotes/ccp-table-legend
Ccp table legend
2 parents 5b21e3e + 2c77030 commit 4b7395f

File tree

5 files changed

+150
-6
lines changed

5 files changed

+150
-6
lines changed

src/mcode-pilot/components/TreatmentOptionsOutcomes/TreatmentOptionsOutcomes.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import _ from 'lodash';
66
import { isSame, getCombinations } from '../../utils/arrayCompare';
77

88
import BarChart from '../../visualizations/BarChart/BarChart';
9+
import TableLegend from '../../visualizations/TableLegend/TableLegend';
910
import TreatmentsPopover from '../TreatmentsPopover/TreatmentsPopover';
1011

1112
import './TreatmentOptionsOutcomes.css';
@@ -299,6 +300,7 @@ export default class TreatmentOptionsOutcomes extends Component {
299300
)}
300301
</div>
301302
</div>
303+
<TableLegend includedRow={includedRow} treatmentNames={TREATMENT_NAMES}/>
302304
</div>
303305
);
304306
}

src/mcode-pilot/visualizations/BarChart/BarChart.jsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ import FontAwesome from 'react-fontawesome';
55
import './BarChart.css';
66

77
export default class BarChart extends Component {
8-
getStyles = (survivedPercent, compareToPercent, percentChange) => {
8+
getStyles = (survivedPercent, compareToPercent, percentChange, roundedPercent) => {
99
let mainStyle, changeStyle, textStyle;
1010
if (percentChange < 0) {
1111
// style for when survival decreases (red)
1212
mainStyle = {"width": `${survivedPercent}%`, "backgroundColor": "#9e9e9e" };
13-
changeStyle = {"width": `${Math.abs(percentChange)}%`, "backgroundColor": "#e13949" };
13+
changeStyle = {"width": `${Math.abs(roundedPercent)}%`, "background": `repeating-linear-gradient(
14+
45deg,
15+
transparent,
16+
transparent 2px,
17+
#EC9696 2px,
18+
#EC9696 4px
19+
),
20+
linear-gradient(
21+
to bottom,
22+
#9e9e9e,
23+
#9e9e9e
24+
)` };
1425
textStyle = { "color": "#d9534f" };
1526
} else {
1627
// styles for when survival increases (green)
@@ -33,7 +44,7 @@ export default class BarChart extends Component {
3344
compareToPercent = compareToNumerator / compareToDenominator * 100;
3445
roundedPercent = Math.floor(survivedPercent - compareToPercent);
3546
percentChange = survivedPercent - compareToPercent;
36-
const styles = this.getStyles(survivedPercent, compareToPercent, percentChange);
47+
const styles = this.getStyles(survivedPercent, compareToPercent, percentChange, roundedPercent);
3748
mainStyle = styles.mainStyle;
3849
changeStyle = styles.changeStyle;
3950
textStyle = styles.textStyle;
@@ -55,6 +66,7 @@ export default class BarChart extends Component {
5566
<div className="progress-bar">
5667
<div className="prog-fill" style={mainStyle}></div>
5768
{hasCompare && <div className="prog-fill" style={changeStyle}></div>}
69+
<div className="prog-fill-empty"></div>
5870
</div>
5971
</div>
6072
</div>

src/mcode-pilot/visualizations/BarChart/BarChart.scss

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,27 @@ $color-background: #9e9e9e;
2020

2121
.progress-bar {
2222
display: flex;
23-
height: 12px;
23+
height: 100%;
2424
position: relative;
25-
border: 1px solid $color-border;
2625
background-color: $color-white;
2726
}
2827

2928
.prog-fill {
29+
background-size:6px !important;
3030
display: inline-block;
3131
padding: 0;
32-
height: 100%;
32+
height: 12px;
3333
width: 0;
3434
background-color: $color-background;
3535
}
3636

37+
.prog-fill-empty {
38+
border-style: solid;
39+
border-color: $color-border;
40+
border-width:1px 1px 1px 0;
41+
flex-grow:100;
42+
43+
}
3744
.tiny-arrow {
3845
opacity: 0.75;
3946
padding-right: 2px;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import './TableLegend.css';
5+
6+
export default class TableLegend extends Component {
7+
8+
render() {
9+
let message;
10+
if(this.props.includedRow instanceof Array) {
11+
// the row is empty
12+
message = "survived with treatment"
13+
}else{
14+
const name = this.props.includedRow.name;
15+
const noTreatment = this.props.treatmentNames.noTreatment===name;
16+
const hasAnd = name.indexOf('&') > -1
17+
message = "survived with " + (noTreatment?'no treatment':name) + (hasAnd||noTreatment?"":" alone")
18+
}
19+
const mainStyle = {"width": `45px`};
20+
const treatmentStyle = {"width":"10px", "backgroundColor":"#91bd7b"};
21+
const redTreatmentStyle = {"width": "14px", "background": `repeating-linear-gradient(
22+
45deg,
23+
transparent,
24+
transparent 2px,
25+
#EC9696 2px,
26+
#EC9696 4px
27+
),
28+
linear-gradient(
29+
to bottom,
30+
#FFFFFF,
31+
#FFFFFF
32+
)`};
33+
const cancerStyle = {"width":"20px"};
34+
return (
35+
<div className="table-legend">
36+
<div className="wrapper">
37+
<div className="legend-entry">
38+
<div className="prog-fill-container">
39+
<div className="prog-fill" style={mainStyle}/>
40+
</div>
41+
<span className="legend-text">{message}</span>
42+
</div>
43+
44+
<div className="legend-entry">
45+
<div className="prog-fill-container">
46+
<div className="prog-fill" style={treatmentStyle}/>
47+
</div>
48+
<span className="legend-text">increase in survival due to treatment</span>
49+
</div>
50+
51+
<div className="legend-entry">
52+
<div className="prog-fill-container">
53+
<div className="prog-fill" style={redTreatmentStyle}/>
54+
</div>
55+
<span className="legend-text">decrease in survival due to treatment</span>
56+
</div>
57+
58+
<div className="legend-entry">
59+
<div className="prog-fill-container">
60+
<div className="progress-bar" style={cancerStyle}/>
61+
</div>
62+
<span className="legend-text">cancer related deaths</span>
63+
</div>
64+
65+
</div>
66+
67+
</div>
68+
);
69+
}
70+
}
71+
72+
TableLegend.propTypes = {
73+
includedRow: PropTypes.oneOfType([
74+
PropTypes.object,
75+
PropTypes.array
76+
]),
77+
treatmentNames: PropTypes.object
78+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
$color-white: #fff;
2+
$color-border: #d1d1d1;
3+
$color-background: #9e9e9e;
4+
5+
.table-legend {
6+
text-align: center;
7+
.wrapper {
8+
display:inline-block;
9+
}
10+
.prog-fill {
11+
background-size:6px !important;
12+
display: inline-block;
13+
padding: 0;
14+
height: 10px;
15+
width: 40px;
16+
background-color: $color-background;
17+
}
18+
19+
.legend-entry {
20+
display:block;
21+
text-align: left;
22+
}
23+
24+
.prog-fill-container {
25+
26+
display:inline-block;
27+
width: 50px;
28+
}
29+
30+
.legend-text {
31+
32+
font-size: 10px;
33+
padding-left:10px;
34+
line-height:10px;
35+
36+
}
37+
38+
.progress-bar {
39+
display: flex;
40+
height: 8px;
41+
// position: relative;
42+
border: 1px solid $color-border;
43+
background-color: $color-white;
44+
}
45+
}

0 commit comments

Comments
 (0)