From 05bf2d7a9ccc35856ef17fbc60671fc892de1e32 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 26 Sep 2020 17:31:48 +0800 Subject: [PATCH 1/3] [reports] use h3 instead of h2 for report-title "Title" style applies to h3. Ensure that report titles are h3 to be styled as requested by stylesheets. --- gnucash/report/html-utilities.scm | 24 +++++++------------ .../reports/example/welcome-to-gnucash.scm | 2 +- .../reports/standard/new-owner-report.scm | 2 +- .../report/reports/standard/price-scatter.scm | 2 +- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gnucash/report/html-utilities.scm b/gnucash/report/html-utilities.scm index a801111e10f..d5bda78a315 100644 --- a/gnucash/report/html-utilities.scm +++ b/gnucash/report/html-utilities.scm @@ -228,13 +228,10 @@ (define (gnc:html-make-generic-simple-warning report-title-string message) - (let ((p (gnc:make-html-text))) - (gnc:html-text-append! - p - (gnc:html-markup-h2 (string-append report-title-string ":")) - (gnc:html-markup-h2 "") - (gnc:html-markup-p message)) - p)) + (gnc:make-html-text + (gnc:html-markup-h3 (string-append report-title-string ":")) + (gnc:html-markup-h3 "") + (gnc:html-markup-p message))) (define (gnc:html-make-options-link report-id) @@ -301,14 +298,11 @@ (define (gnc:html-make-generic-warning report-title-string report-id warning-title-string warning-string) - (let ((p (gnc:make-html-text))) - (gnc:html-text-append! - p - (gnc:html-markup-h2 (string-append (G_ report-title-string) ":")) - (gnc:html-markup-h2 warning-title-string) - (gnc:html-markup-p warning-string) - (gnc:html-make-options-link report-id)) - p)) + (gnc:make-html-text + (gnc:html-markup-h3 (string-append (G_ report-title-string) ":")) + (gnc:html-markup-h3 warning-title-string) + (gnc:html-markup-p warning-string) + (gnc:html-make-options-link report-id))) (define (gnc:html-make-generic-options-warning report-title-string report-id) diff --git a/gnucash/report/reports/example/welcome-to-gnucash.scm b/gnucash/report/reports/example/welcome-to-gnucash.scm index 6675312ae58..80a2e076876 100644 --- a/gnucash/report/reports/example/welcome-to-gnucash.scm +++ b/gnucash/report/reports/example/welcome-to-gnucash.scm @@ -37,7 +37,7 @@ (gnc:html-document-add-object! doc (gnc:make-html-text - (gnc:html-markup-h2 + (gnc:html-markup-h3 (format #f (G_ "Welcome to GnuCash ~a !") gnc:version)) (gnc:html-markup-p diff --git a/gnucash/report/reports/standard/new-owner-report.scm b/gnucash/report/reports/standard/new-owner-report.scm index 8e0cbcad339..b64c4b02be8 100644 --- a/gnucash/report/reports/standard/new-owner-report.scm +++ b/gnucash/report/reports/standard/new-owner-report.scm @@ -1079,7 +1079,7 @@ invoices and amounts."))))) (gnc:html-document-add-object! document (gnc:make-html-text - (gnc:html-markup-h2 (G_ "No transactions found.")) + (gnc:html-markup-h3 (G_ "No transactions found.")) (gnc:html-markup-p (G_ "No matching transactions found")) (gnc:html-make-options-link (gnc:report-id report-obj))))) diff --git a/gnucash/report/reports/standard/price-scatter.scm b/gnucash/report/reports/standard/price-scatter.scm index a10e7f13055..787bd1333f3 100644 --- a/gnucash/report/reports/standard/price-scatter.scm +++ b/gnucash/report/reports/standard/price-scatter.scm @@ -192,7 +192,7 @@ (gnc:html-document-add-object! document (gnc:make-html-text - (gnc:html-markup-h2 title) + (gnc:html-markup-h3 title) (gnc:html-markup-p text)))) (gnc:html-chart-set-type! chart 'line) From b72014c7de8e9cb7311b1d60ef3895f7060082d8 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 26 Sep 2020 17:43:17 +0800 Subject: [PATCH 2/3] Bug 797893 - Unable to change font size in charts The bug specifies chart fonts are not customisable. We can copy the (gnucash) stylesheet properties which define

and font styles onto chartjs properties. --- gnucash/report/html-chart.scm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gnucash/report/html-chart.scm b/gnucash/report/html-chart.scm index 70d3d49ea6b..3a0c797063e 100644 --- a/gnucash/report/html-chart.scm +++ b/gnucash/report/html-chart.scm @@ -186,7 +186,6 @@ (cons 'display #t) (cons 'labelString ""))) (cons 'ticks (list - (cons 'fontSize 12) (cons 'maxRotation 30)))) ;; the following another xAxis at the top '((position . top) @@ -205,7 +204,6 @@ (cons 'display 1.5) (cons 'labelString ""))) (cons 'ticks (list - (cons 'fontSize 10) (cons 'beginAtZero #f)))) ;; the following another yAxis on the right '((position . right) @@ -215,7 +213,6 @@ )))) (cons 'title (list (cons 'display #t) - (cons 'fontSize 16) (cons 'fontStyle "") (cons 'text "")))))) "XXX" ;currency-iso @@ -348,6 +345,17 @@ Chart.pluginService.register({ } }) +// copy font info from css into chartjs. +bodyStyle = window.getComputedStyle (document.querySelector ('body')); +Chart.defaults.global.defaultFontSize = parseInt (bodyStyle.fontSize); +Chart.defaults.global.defaultFontFamily = bodyStyle.fontFamily; +Chart.defaults.global.defaultFontStyle = bodyStyle.fontStyle; + +titleStyle = window.getComputedStyle (document.querySelector ('h3')); +chartjsoptions.options.title.fontSize = parseInt (titleStyle.fontSize); +chartjsoptions.options.title.fontFamily = titleStyle.fontFamily; +chartjsoptions.options.title.fontStyle = titleStyle.fontStyle; + document.getElementById(chartid).onclick = function(evt) { var activepoints = myChart.getElementAtEvent(evt); var anchor = document.getElementById(jumpid); @@ -403,6 +411,8 @@ document.getElementById(chartid).onclick = function(evt) { (push (gnc:html-js-include (gnc-path-find-localized-html-file "chartjs/Chart.bundle.min.js"))) + ;; the following hidden h3 is used to query style and copy onto chartjs + (push "

") (push (format #f "
\n" (size->str (gnc:html-chart-width chart)) (size->str (gnc:html-chart-height chart)))) @@ -428,7 +438,6 @@ document.getElementById(chartid).onclick = function(evt) { (push "chartjsoptions.options.tooltips.callbacks.label = tooltipLabel;\n") (push "chartjsoptions.options.tooltips.callbacks.title = tooltipTitle;\n") - (push "Chart.defaults.global.defaultFontFamily = \"'Trebuchet MS', Arial, Helvetica, sans-serif\";\n") (push JS-setup) (push "var myChart = new Chart(chartid, chartjsoptions);\n") From d810e82f982ee6a498fbe54e87a6e7088cb041c5 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 26 Sep 2020 19:55:12 +0800 Subject: [PATCH 3/3] [html-chart] use gensym instead of guid ... because technically guids should be freed when not needed. gensym generates a guaranteed unique string with prefix within program lifecycle. --- gnucash/report/html-chart.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnucash/report/html-chart.scm b/gnucash/report/html-chart.scm index 3a0c797063e..d3da4b47e13 100644 --- a/gnucash/report/html-chart.scm +++ b/gnucash/report/html-chart.scm @@ -406,7 +406,7 @@ document.getElementById(chartid).onclick = function(evt) { (push (lambda (l) (set! retval (cons l retval)))) ;; Use a unique chart-id for each chart. This prevents charts ;; clashing on multi-column reports - (id (guid-new-return))) + (id (symbol->string (gensym "chart")))) (push (gnc:html-js-include (gnc-path-find-localized-html-file "chartjs/Chart.bundle.min.js"))) @@ -417,12 +417,12 @@ document.getElementById(chartid).onclick = function(evt) { (size->str (gnc:html-chart-width chart)) (size->str (gnc:html-chart-height chart)))) (push (format #f "\n" id)) - (push (format #f "\n" id)) + (push (format #f "\n" id)) (push "
\n") (push (format #f "