From 0e4c7cdb4a17fd2390786f2b74db33ae176558d9 Mon Sep 17 00:00:00 2001 From: Nabilah Adani Date: Mon, 17 May 2021 08:43:43 +0700 Subject: [PATCH 1/2] [CHORES] add param for catching type of data --- src/scenes/Home/utilities/utils.tsx | 47 +++++++++++++++++++---------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index 511c2a9..00fc9b5 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -88,30 +88,35 @@ const renderActiveShape = (props: ActiveShapeProps) => { ); }; -const image2pdf = (imageType: string, type: string, key: string) => { - const imgWidth = 252; - const imgHeight = 156; +const image2pdf = (imageType: string, type: string, key: string, dataType: string) => { + const imgWidth = 232; + const imgHeight = 130; const pageWidth = 297; const pageHeight = 210; const marginX = (pageWidth - imgWidth) / 2; - const marginY = 0; const doc = new jsPDF({orientation: "l", format:[pageWidth, pageHeight]}); const header = (doc: jsPDF) => { - doc.setFontSize(30); + doc.setFontSize(26); doc.setFont("arial", "bold"); - doc.text("DATA KASUS TBC DEPOK", pageWidth/2, 25, {align:"center"}); + doc.text("DATA KASUS TBC DEPOK", pageWidth/2, 18, {align:"center"}); } const writeTextToPDF = (doc: jsPDF) => { doc.setFontSize(20); - doc.setFont("arial", "italic"); - if(key == "") - doc.text("Keseluruhan Kasus TBC di DEPOK", pageWidth/2, 160, {align:"center"}); + doc.setFont("arial", "italic-bold"); + if(key == "Tanggal") + if(dataType == "") + doc.text("Keseluruhan Kasus TBC di DEPOK", pageWidth/2, 160, {align:"center"}); + else + doc.text("Berdasarkan tanggal " + dataType, pageWidth/2, 160, {align:"center"}) else - doc.text(type + " " + key, pageWidth/2, 160, {align:"center"}); + if(dataType == "") + doc.text("Keseluruhan Kasus TBC berdasarkan " + type + " " + key, pageWidth/2, 156, {align:"center"}); + else + doc.text(type + " " + key + " dari tanggal " + dataType, pageWidth/2, 156, {align:"center"}); doc.setFillColor(PIE_COLORS[0]); doc.rect(30, 170, 5, 5, 'F'); @@ -142,7 +147,10 @@ const image2pdf = (imageType: string, type: string, key: string) => { let context = canvas.getContext('2d')!; context.drawImage(img, 0, 0, context.canvas.width, context.canvas.height); let png = canvas.toDataURL('image/png', 1.0); - doc.addImage(png, imageType, marginX, 15, imgWidth, imgHeight, undefined, "SLOW"); + if (key == "Tanggal") + doc.addImage(png, imageType, marginX, 12, 252, 156, undefined, "SLOW"); + else + doc.addImage(png, imageType, marginX, 12, imgWidth, imgHeight, undefined, "SLOW"); } const blobToImage = (blob: Blob) => { @@ -164,15 +172,22 @@ const image2pdf = (imageType: string, type: string, key: string) => { header(doc); addImageToDoc(img, doc); writeTextToPDF(doc); - if (key == "") - doc.save("Keseluruhan Kasus TBC.pdf"); + if(key == "Tanggal") + if (dataType == "") + doc.save("Statistik Keseluruhan Kasus TBC.pdf"); + else + doc.save("Statistik berdasarkan tanggal " + dataType + ".pdf") + else - doc.save("Kasus TBC Depok berdasarkan " + type + " " + key + ".pdf"); + if (dataType == "") + doc.save("Diagram Keseluruhan Kasus TBC berdasarkan " + type + " " + key + ".pdf") + else + doc.save("Diagram berdasarkan "+ type + " " + key + " dari tanggal " + dataType + ".pdf"); }); }; -const downloadAsPDF = (type: string, selectedKey: string) => { - image2pdf("PNG", type, translate(selectedKey)); +const downloadAsPDF = (type: string, selectedKey: string, dataType: string) => { + image2pdf("PNG", type, translate(selectedKey), dataType); } export { translate, renderActiveShape, image2pdf, downloadAsPDF, translateTypetoKey }; \ No newline at end of file -- GitLab From c9b38b1dcc89a479a5afc72d69c348d03078be6e Mon Sep 17 00:00:00 2001 From: Nabilah Adani Date: Mon, 17 May 2021 08:46:38 +0700 Subject: [PATCH 2/2] [CHORES] change writing in pdf document --- src/scenes/Home/components/ExportPDFButton/index.tsx | 9 +++++---- src/scenes/Home/components/Statistic/index.tsx | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx index 2e2a87a..cdbcd9c 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -5,14 +5,15 @@ import { downloadAsPDF } from 'scenes/Home/utilities/utils'; interface ExportPDFButtonProps { type: string, selectedKey: string, + dataType: string, clickable: boolean, } function ExportPDFButton({ - type, selectedKey, clickable + type, selectedKey, dataType, clickable }: ExportPDFButtonProps) { - const handleDownload = React.useCallback(async (type: string, selectedKey: string) => { - downloadAsPDF(type, selectedKey); + const handleDownload = React.useCallback(async (type: string, selectedKey: string, dataType: string) => { + downloadAsPDF(type, selectedKey, dataType); }, []); return (