diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx
index 2e2a87a60566e476280f27c855093e70cee14164..cdbcd9ca4574e0f87244eaeb57c323e02b01fd18 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 (
@@ -513,7 +515,8 @@ function Statistic({
>
a + (b['total_count'] || 0), 0) !== 0}
/>
@@ -573,6 +576,7 @@ function Statistic({
diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx
index 511c2a9eb7af8c8ed64635552817dbd519f4cd77..00fc9b55d1cd24b365a48d88de2d2ea1a7ed31f8 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