From 6014a6770fcd966fa58f6b9e96c306f5a1f477ee Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 31 Dec 2020 23:43:42 +0530 Subject: Use tikz to draw biometry. * ksh-report.el (draw-biometry, make-temp-script, combine-pdfs, crop-pdf): Delete functions. (biometry-subfloat, latex-macro): New functions. (insert-biometry): Use tikz to draw biometry. (make-report-header): Use subfig and tikz packages. Use calc tikz library. Define tickheight, parameterheight and parameterageheight macros. * biometry.asy: Delete file. --- ksh-report.el | 76 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'ksh-report.el') diff --git a/ksh-report.el b/ksh-report.el index 722e4f6..ac31a62 100644 --- a/ksh-report.el +++ b/ksh-report.el @@ -1,53 +1,45 @@ (require 'seq) -(defun draw-biometry (param-name param param-age percentile) - (let ((temp-script-file (make-temp-script - (format "%s %s" param-name param) - param-age (string-to-number percentile)))) - (message "Drawing %s..." temp-script-file) - (shell-command - (format "asy -f pdf -o %s %s" (file-name-directory temp-script-file) temp-script-file)) - (delete-file temp-script-file) - (format "%s.pdf" temp-script-file))) -(defun make-temp-script (param param-age percentile) - (let ((temp-script-file (make-temp-file "biometry"))) - (with-temp-file temp-script-file - (insert "include \"biometry\";\n") - (insert (format - "draw_biometry(\"%s\", \"%s\", %d);" - param param-age percentile))) - temp-script-file)) +(defun biometry-subfloat (param-name param param-age percentile) + (format + "\\subfloat { + \\begin{tikzpicture} + \\coordinate (O) at (0,0); + \\coordinate (A) at (2,0); + \\coordinate (B) at ($0.5*(A)$); + \\draw (O) -- (A); + \\draw ($(O) + 0.05*(A)$) -- +(0,-\\tickheight) node [below] {5\\%%}; + \\draw ($(O) + 0.25*(A)$) -- +($0.5*(0,-\\tickheight)$); + \\draw ($(O) + 0.5*(A)$) -- +(0,-\\tickheight) node [below] {50\\%%}; + \\draw ($(O) + 0.75*(A)$) -- +($0.5*(0,-\\tickheight)$); + \\draw ($(O) + 0.95*(A)$) -- +(0,-\\tickheight) node [below] {95\\%%}; + \\node [above] at ($(O) + %s*0.01*(A)$) {*}; + \\node at ($0.5*(A) + (0,\\parameterheight)$) {%s %s}; + \\node at ($0.5*(A) + (0,\\parameterageheight)$) {%s}; + \\end{tikzpicture} + } +" percentile param-name param param-age)) (defun insert-biometry (readings) - (princ - (format "[[%s]]\n" - (crop-pdf - (combine-pdfs - (mapcar (lambda (reading) - (apply 'draw-biometry - (mapcar 'get-field reading))) - readings)))))) - -(defun combine-pdfs (pdfs) - (let ((temp-combination (make-temp-file "pdfjam" nil ".pdf"))) - (apply 'call-process "pdfjam" nil nil nil - "--nup" "4x1" - "--outfile" temp-combination pdfs) - (mapc 'delete-file pdfs) - temp-combination)) - -(defun crop-pdf (pdf) - (message "Cropping %s..." pdf) - (let ((output-pdf (format "%s-crop.pdf" (file-name-sans-extension pdf)))) - (shell-command (format "pdfcrop %s %s" pdf output-pdf)) - (delete-file pdf) output-pdf)) + (princ "#+BEGIN_EXPORT latex\n") + (princ "\\begin{figure}\n") + (princ "\\centering\n") + (seq-do (lambda (reading) + (princ (apply 'biometry-subfloat + (seq-map 'get-field reading)))) + readings) + (princ "\\end{figure}\n") + (princ "#+END_EXPORT\n")) (defun latex-use-package (package &optional arguments) (if arguments (format "\\usepackage[%s]{%s}" arguments package) (format "\\usepackage{%s}" package))) +(defun latex-macro (name value) + (format "\\newcommand{\\%s}{%s}" name value)) + (defun make-report-header (title) (seq-do 'ksh-forms-org-keyword '(("TITLE" . "Kuzhanthai Sanjeevi Hospital") @@ -56,7 +48,13 @@ (list (latex-use-package "fullpage") (latex-use-package "nopageno") (latex-use-package "datetime" "ddmmyyyy") + (latex-use-package "subfig") + (latex-use-package "tikz") + "\\usetikzlibrary{calc}" "\\renewcommand{\\dateseparator}{-}" + (latex-macro "tickheight" "0.3") + (latex-macro "parameterheight" "1") + (latex-macro "parameterageheight" "0.6") "\\setlength{\\parindent}{0cm}" (latex-use-package "titlesec" "tiny") (latex-use-package "wasysym") -- cgit v1.2.3