Skip to content

Commit 6fa6b63

Browse files
authored
Merge pull request #109 from typhoidgenomics/dev2
Dev2
2 parents 8e7ba6e + 6bece22 commit 6fa6b63

3 files changed

Lines changed: 29 additions & 36 deletions

File tree

client/src/components/Elements/DownloadData/DownloadData.js

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export const DownloadData = () => {
157157
}
158158

159159
function drawFooter({ document, pageHeight, pageWidth, date, page1=false }) {
160-
const ab = abbrivations();
161160
document.setFontSize(10);
162161

163162
document.line(0, pageHeight - 26, pageWidth, pageHeight - 26);
@@ -201,7 +200,7 @@ export const DownloadData = () => {
201200
const logo = new Image();
202201
logo.src = LogoImg;
203202
const logoWidth = 80;
204-
doc.addImage(logo, 'PNG', 16, 16, logoWidth, 34);
203+
doc.addImage(logo, 'PNG', 16, 16, logoWidth, 34, undefined,'FAST');
205204

206205
// Title and Date
207206
doc.setFontSize(16).setFont(undefined, 'bold');
@@ -215,30 +214,23 @@ export const DownloadData = () => {
215214
doc.text(date, pageWidth / 2, 48, { align: 'center' });
216215

217216
let list = PIMD.filter((value)=> value !== "-")
218-
let pmidSpace;
217+
let pmidSpace, dynamicText;
219218
if (actualCountry === 'All'){
220219
pmidSpace = 0;
221-
doc.text(
222-
`TyphiNET presents data aggregated from >100 studies. Data are drawn from studies with the following PubMed IDs (PMIDs) or Digital Object Identifier (DOI): ${list.join(
223-
', '
224-
)}.`,
225-
16,
226-
185,
227-
{ align: 'left', maxWidth: pageWidth - 36 }
228-
);
220+
dynamicText = `TyphiNET presents data aggregated from >100 studies. Data are drawn from studies with the following PubMed IDs (PMIDs) or Digital Object Identifier (DOI): ${list.join(', ')}.`
229221
}else{
230222
list = listPIMD.filter((value)=> value !== "-")
231-
pmidSpace = -30;
232-
doc.text(
233-
`TyphiNET presents data aggregated from >100 studies. Data for country ${actualCountry} are drawn from studies with the following PubMed IDs (PMIDs) or Digital Object Identifier (DOI): ${list.join(
234-
', '
235-
)}.`,
236-
16,
237-
185,
238-
{ align: 'left', maxWidth: pageWidth - 36 }
239-
);
240-
}
223+
dynamicText = `TyphiNET presents data aggregated from >100 studies. Data for country ${actualCountry} are drawn from studies with the following PubMed IDs (PMIDs) or Digital Object Identifier (DOI): ${list.join(', ')}.`
224+
const textWidth = doc.getTextWidth(dynamicText);
225+
226+
const widthRanges = [815, 1200, 1600, 2000, 2400];
227+
const pmidSpaces = [-50, -40, -30, -20, -10, 0];
241228

229+
// Find the appropriate pmidSpace based on textWidth
230+
pmidSpace = pmidSpaces.find((space, index) => textWidth <= widthRanges[index]) || pmidSpaces[pmidSpaces.length - 1];
231+
}
232+
doc.text(dynamicText,16, 185,{ align: 'left', maxWidth: pageWidth - 36 });
233+
242234
const texts = getSalmonellaTexts(date);
243235

244236
// Info
@@ -269,15 +261,15 @@ export const DownloadData = () => {
269261
doc.setFont(undefined, 'normal');
270262
doc.text(texts[13], 185, 495+pmidSpace, { align: 'left', maxWidth: pageWidth - 36 });
271263
doc.text(texts[14], 16, 515+pmidSpace, { align: 'left', maxWidth: pageWidth - 36 });
272-
doc.setFont(undefined, 'bold');
273-
doc.text(texts[15], 16, 545+pmidSpace, { align: 'left', maxWidth: pageWidth - 36 });
264+
doc.setFontSize(10).setFont(undefined, 'bold');
265+
doc.text(texts[15], 16, pageHeight-60, { align: 'left', maxWidth: pageWidth - 36 });
274266
doc.setFont(undefined, 'normal');
275-
doc.text(texts[16], 16, 565+pmidSpace, { align: 'left', maxWidth: pageWidth - 36 });
267+
doc.text(texts[16], 16, pageHeight-50, { align: 'left', maxWidth: pageWidth - 36 });
276268

277269

278270
const euFlag = new Image();
279271
euFlag.src = EUFlagImg;
280-
doc.addImage(euFlag, 'JPG',320,579+pmidSpace, 12, 7);
272+
doc.addImage(euFlag, 'JPG',173,pageHeight-38, 12, 7, undefined,'FAST');
281273

282274
drawFooter({ document: doc, pageHeight, pageWidth, date, page1: true });
283275

@@ -333,7 +325,7 @@ export const DownloadData = () => {
333325
ctx.drawImage(mapImg, 0, 0, canvas.width, canvas.height);
334326

335327
const img = canvas.toDataURL('image/png');
336-
doc.addImage(img, 'PNG', 0, 160, pageWidth, 223);
328+
doc.addImage(img, 'PNG', 0, 160, pageWidth, 223, undefined,'FAST');
337329
// doc.addImage(img, 'PNG', 0, mapY, pageWidth, 223);
338330
});
339331

@@ -360,9 +352,9 @@ export const DownloadData = () => {
360352
break;
361353
}
362354
if (mapView === 'Dominant Genotype') {
363-
doc.addImage(mapLegend, 'PNG', pageWidth / 2 - legendWidth / 2, 351, legendWidth, 47);
355+
doc.addImage(mapLegend, 'PNG', pageWidth / 2 - legendWidth / 2, 351, legendWidth, 47, undefined,'FAST');
364356
} else {
365-
doc.addImage(mapLegend, 'PNG', pageWidth - pageWidth / 5 , 85, legendWidth, 47);
357+
doc.addImage(mapLegend, 'PNG', pageWidth - pageWidth / 5 , 85, legendWidth, 47, undefined,'FAST');
366358
}
367359

368360
// Graphs
@@ -395,9 +387,9 @@ export const DownloadData = () => {
395387
graphImg.src = await domtoimage.toPng(document.getElementById(graphCards[index].id), { bgcolor: 'white' });
396388
await graphImgPromise;
397389
if (graphImg.width <= 741) {
398-
doc.addImage(graphImg, 'PNG', 16, 110);
390+
doc.addImage(graphImg, 'PNG', 16, 110, undefined,'FAST');
399391
} else {
400-
doc.addImage(graphImg, 'PNG', 16, 110, pageWidth - 80, 271);
392+
doc.addImage(graphImg, 'PNG', 16, 110, pageWidth - 80, 271, undefined,'FAST');
401393
}
402394

403395
doc.setFillColor(255, 255, 255);
@@ -444,6 +436,7 @@ export const DownloadData = () => {
444436
}
445437

446438
doc.save('TyphiNET-report.pdf');
439+
447440
} catch (error) {
448441
setShowAlert(true);
449442
} finally {
@@ -475,7 +468,7 @@ export const DownloadData = () => {
475468
startIcon={<PictureAsPdf />}
476469
loadingPosition="start"
477470
>
478-
Download report from current view
471+
Download report from current view (PDF, 1MB)
479472
</LoadingButton>
480473
<Snackbar open={showAlert} autoHideDuration={5000} onClose={handleCloseAlert}>
481474
<Alert onClose={handleCloseAlert} severity="error" sx={{ width: '100%' }}>

client/src/components/Elements/Graphs/DrugResistanceGraph/DrugResistanceGraph.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export const DrugResistanceGraph = () => {
6767
const tooltipData = [];
6868

6969
payload.forEach((item) => {
70-
if (item.value === 0) {
71-
return;
72-
}
70+
// if (item.value === 0) {
71+
// return;
72+
// }
7373

7474
const count = data[item.name];
7575
tooltipData.push({
@@ -253,7 +253,7 @@ export const DrugResistanceGraph = () => {
253253
<div className={classes.labelWrapper}>
254254
<Typography variant="caption">Select drugs/classes to display</Typography>
255255
<Tooltip
256-
title="The resistance frequencies are only shown for years with N≥10 genomes. When the data is insufficent per year to calculate annual frequencies, there are no data points to show."
256+
title="The resistance frequencies are only shown for years with N≥10 genomes. When the data is insufficient per year to calculate annual frequencies, there are no data points to show."
257257
placement="top"
258258
>
259259
<InfoOutlined color="action" fontSize="small" className={classes.labelTooltipIcon} />

client/src/util/mapLegends.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export const mapLegends = [
33
{ value: 'MDR', label: 'Multidrug resistant (MDR)' },
44
{ value: 'XDR', label: 'Extensively drug resistant (XDR)' },
5-
{ value: 'ESBL_category', label: 'Ceftriaxone resistance' },
5+
{ value: 'ESBL_category', label: 'Ceftriaxone resistant' },
66
{ value: 'AzithR', label: 'Azithromycin resistant' },
77
{ value: 'CipNS', label: 'Ciprofloxacin non-susceptible (CipNS)' },
88
{ value: 'CipR', label: 'Ciprofloxacin resistant (CipR)' },

0 commit comments

Comments
 (0)