From 2f8712f9357e929c7418814d771cb464ad881d09 Mon Sep 17 00:00:00 2001 From: Sam Rich Date: Mon, 22 Apr 2019 11:43:47 -0400 Subject: [PATCH] [PRTL-2503] Print/download Clinical Analysis plots (#2517) * add button type to stop submit action * add print css and print button * move survival plot css to the right folder * add print icon to icon index * adding print css * don't print empty survival plots * Revert "don't print empty survival plots" This reverts commit e1f1a2ea7a2b4a0888618fcc5dd287fbab829efd. * improve styling * remove background colours * revert TS formatting --- .../components/DownloadVisualizationButton.js | 1 + .../@ncigdc/components/SurvivalPlotWrapper.js | 102 +++++++++--------- .../@ncigdc/components/survivalPlot.css | 25 ----- .../ClinicalAnalysisResult.js | 27 +++-- .../ClinicalAnalysis/ClinicalVariableCard.js | 86 +++++++++------ .../ClinicalAnalysis/print.css | 80 ++++++++++++++ .../ClinicalAnalysis/survivalPlot.css | 33 ++++++ src/packages/@ncigdc/theme/icons/Print.js | 5 + src/packages/@ncigdc/theme/icons/index.js | 2 + 9 files changed, 244 insertions(+), 117 deletions(-) create mode 100644 src/packages/@ncigdc/modern_components/ClinicalAnalysis/print.css create mode 100644 src/packages/@ncigdc/modern_components/ClinicalAnalysis/survivalPlot.css create mode 100644 src/packages/@ncigdc/theme/icons/Print.js diff --git a/src/packages/@ncigdc/components/DownloadVisualizationButton.js b/src/packages/@ncigdc/components/DownloadVisualizationButton.js index ef7bdd6e8..aab8d72c1 100644 --- a/src/packages/@ncigdc/components/DownloadVisualizationButton.js +++ b/src/packages/@ncigdc/components/DownloadVisualizationButton.js @@ -76,6 +76,7 @@ const DownloadVisualizationButton = ({ disabled={disabled} leftIcon={!noText && } style={visualizingButton} + type="button" > {noText ? ( diff --git a/src/packages/@ncigdc/components/SurvivalPlotWrapper.js b/src/packages/@ncigdc/components/SurvivalPlotWrapper.js index 90e1a8c72..870050d03 100644 --- a/src/packages/@ncigdc/components/SurvivalPlotWrapper.js +++ b/src/packages/@ncigdc/components/SurvivalPlotWrapper.js @@ -112,58 +112,54 @@ const SurvivalPlotWrapper = ({ - wrapSvg({ - selector: `.${uniqueClass} .${CLASS_NAME} svg`, - title: TITLE, - className: CLASS_NAME, - embed: { - top: { - elements: [ - document.querySelector( - `.${uniqueClass} .legend-0` - ), - document.querySelector( - `.${uniqueClass} .legend-1` - ), - pValue - ? document.querySelector( - `.${uniqueClass} .p-value` - ) - : null, - ], - }, - }, - })} - data={results.map((set, i) => ({ - ...set, - meta: { - ...set.meta, - label: set.meta.label || `S${i + 1}`, - }, - }))} - stylePrefix={`.${CLASS_NAME}`} - slug="survival-plot" - noText - tooltipHTML="Download SurvivalPlot data or image" - tsvData={results.reduce((data, set, i) => { - const mapData = set.donors.map(d => toMap(d)); - return [ - ...data, - ...(results.length > 1 - ? mapData.map(m => - m.set('label', set.meta.label || `S${i + 1}`) - ) - : mapData), - ]; - }, [])} - />, - ] - : []), + + wrapSvg({ + selector: `.${uniqueClass} .${CLASS_NAME} svg`, + title: TITLE, + className: CLASS_NAME, + embed: { + top: { + elements: legend + .map((l, i) => + document.querySelector( + `.${uniqueClass} .legend-${i}` + ) + ) + .concat( + pValue + ? document.querySelector( + `.${uniqueClass} .p-value` + ) + : null + ), + }, + }, + })} + data={results.map((set, i) => ({ + ...set, + meta: { + ...set.meta, + label: set.meta.label || `S${i + 1}`, + }, + }))} + stylePrefix={`.${CLASS_NAME}`} + slug="survival-plot" + noText + tooltipHTML="Download SurvivalPlot data or image" + tsvData={results.reduce((data, set, i) => { + const mapData = set.donors.map(d => toMap(d)); + return [ + ...data, + ...(results.length > 1 + ? mapData.map(m => + m.set('label', set.meta.label || `S${i + 1}`) + ) + : mapData), + ]; + }, [])} + />, - Download}> + Print}> @@ -343,6 +354,7 @@ const ClinicalAnalysisResult = ({ minWidth: 260, marginBottom: '1rem', }} + className="no-print" > @@ -462,7 +474,7 @@ const ClinicalAnalysisResult = ({ flexDirection: 'column', flex: '0 0 auto', height: 250, - margin: '5px 5px 10px', + margin: '5px 2px 10px', }} > /year_of/.test(str); const getRangeValue = (key, field, nextInterval) => { if (valueIsDays(field)) { - return `${getLowerAgeYears(key)}${ - nextInterval === 0 ? '+' : ' - ' + getUpperAgeYears(nextInterval - 1) - } years`; + return `${getLowerAgeYears(key)}${nextInterval === 0 + ? '+' + : ' - ' + getUpperAgeYears(nextInterval - 1)} years`; } else if (valueIsYear(field)) { - return `${Math.floor(key)}${ - nextInterval === 0 ? ' - present' : ' - ' + (nextInterval - 1) - }`; + return `${Math.floor(key)}${nextInterval === 0 + ? ' - present' + : ' - ' + (nextInterval - 1)}`; } else { return key; } @@ -189,7 +192,7 @@ const getCountLink = ({ doc_count, filters, totalDocs }) => ( > {(doc_count || 0).toLocaleString()} - {` (${(((doc_count || 0) / totalDocs) * 100).toFixed(2)}%)`} + {` (${((doc_count || 0) / totalDocs * 100).toFixed(2)}%)`} ); @@ -203,10 +206,9 @@ const enhance = compose( withProps(({ variable, data, fieldName }) => ({ rawQueryData: variable.plotTypes === 'continuous' - ? ( - (data.explore && - data.explore.cases.aggregations[fieldName.replace('.', '__')] - .histogram) || { + ? ((data.explore && + data.explore.cases.aggregations[fieldName.replace('.', '__')] + .histogram) || { buckets: [], } ).buckets @@ -299,8 +301,9 @@ const enhance = compose( .data.slice(0) .reverse() : rawQueryData - .filter(bucket => - !IS_CDAVE_DEV ? bucket.key !== '_missing' : bucket.key + .filter( + bucket => + !IS_CDAVE_DEV ? bucket.key !== '_missing' : bucket.key ) .map(b => ({ ...b, @@ -428,8 +431,8 @@ const ClinicalVariableCard: React.ComponentType = ({ .data.slice(0) .reverse() : rawData - .filter(bucket => - !IS_CDAVE_DEV ? bucket.key !== '_missing' : bucket.key + .filter( + bucket => (!IS_CDAVE_DEV ? bucket.key !== '_missing' : bucket.key) ) .map(b => ({ ...b, @@ -499,10 +502,10 @@ const ClinicalVariableCard: React.ComponentType = ({ b.key === '_missing' || b.chart_doc_count < MINIMUM_CASES ? 'Not enough data' : selectedSurvivalValues.indexOf(b.key) > -1 - ? `Click icon to remove ${b.key}` - : selectedSurvivalValues.length < MAXIMUM_CURVES - ? `Click icon to plot ${b.key}` - : `Maximum plots (${MAXIMUM_CURVES}) reached` + ? `Click icon to remove ${b.key}` + : selectedSurvivalValues.length < MAXIMUM_CURVES + ? `Click icon to plot ${b.key}` + : `Maximum plots (${MAXIMUM_CURVES}) reached` } >