|
| 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 | +}; |
0 commit comments