show dates instead of months in xaxis

This commit is contained in:
Christopher Lam 2024-09-02 22:33:14 +08:00
parent 0d6303e57a
commit 5914b348ff

View File

@ -55,9 +55,6 @@
options gnc:pagename-general options gnc:pagename-general
optname-from-date optname-to-date "a") optname-from-date optname-to-date "a")
(gnc:options-add-interval-choice!
options gnc:pagename-general optname-stepsize "b" 'MonthDelta)
(gnc:options-add-currency! (gnc:options-add-currency!
options pagename-price optname-report-currency "d") options pagename-price optname-report-currency "d")
@ -108,15 +105,6 @@
(define (get-option section name) (define (get-option section name)
(gnc-optiondb-lookup-value (gnc:report-options report-obj) section name)) (gnc-optiondb-lookup-value (gnc:report-options report-obj) section name))
(define intervals
(list (list 'DayDelta (G_ "Days") 86400)
(list 'WeekDelta (G_ "Weeks") 604800)
(list 'TwoWeekDelta (G_ "Double-Weeks") 1209600)
(list 'MonthDelta (G_ "Months") 2628000)
(list 'QuarterDelta (G_ "Quarters") (/ 31536000 4))
(list 'HalfYearDelta (G_ "Half Years") (/ 31536000 2))
(list 'YearDelta (G_ "Years") 31536000)))
(let* ((to-date (gnc:time64-end-day-time (let* ((to-date (gnc:time64-end-day-time
(gnc:date-option-absolute-time (gnc:date-option-absolute-time
(get-option gnc:pagename-general (get-option gnc:pagename-general
@ -125,7 +113,6 @@
(gnc:date-option-absolute-time (gnc:date-option-absolute-time
(get-option gnc:pagename-general (get-option gnc:pagename-general
optname-from-date)))) optname-from-date))))
(interval (get-option gnc:pagename-general optname-stepsize))
(report-title (get-option gnc:pagename-general (report-title (get-option gnc:pagename-general
gnc:optname-reportname)) gnc:optname-reportname))
@ -143,12 +130,6 @@
optname-price-commodity)) optname-price-commodity))
(price-source (get-option pagename-price (price-source (get-option pagename-price
optname-price-source)) optname-price-source))
(dates-list (gnc:make-date-list
(gnc:time64-end-day-time from-date)
(gnc:time64-end-day-time to-date)
(gnc:deltasym-to-delta interval)))
(document (gnc:make-html-document)) (document (gnc:make-html-document))
(chart (gnc:make-html-chart)) (chart (gnc:make-html-chart))
(currency-accounts (currency-accounts
@ -157,8 +138,7 @@
(invert (get-option pagename-price optname-invert)) (invert (get-option pagename-price optname-invert))
(amount-commodity (if invert price-commodity report-currency)) (amount-commodity (if invert price-commodity report-currency))
(base-commodity (if invert report-currency price-commodity)) (base-commodity (if invert report-currency price-commodity))
(int-label (car (assq-ref intervals interval))) (iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO))
(int-secs (cadr (assq-ref intervals interval)))
(data '())) (data '()))
;; Short helper for all the warnings below ;; Short helper for all the warnings below
@ -201,7 +181,7 @@
(gnc:html-chart-set-y-axis-label! (gnc:html-chart-set-y-axis-label!
chart (gnc-commodity-get-mnemonic amount-commodity)) chart (gnc-commodity-get-mnemonic amount-commodity))
(gnc:html-chart-set-x-axis-label! chart int-label) (gnc:html-chart-set-x-axis-label! chart (G_ "Date"))
(gnc:html-chart-set! chart '(options scales xAxes (0) type) 'linear) (gnc:html-chart-set! chart '(options scales xAxes (0) type) 'linear)
(gnc:html-chart-set-custom-x-axis-ticks?! chart #f) (gnc:html-chart-set-custom-x-axis-ticks?! chart #f)
@ -240,7 +220,7 @@ commodities.")))
(match-lambda (match-lambda
((date amt) ((date amt)
(and (<= from-date date to-date) (and (<= from-date date to-date)
(list (/ (- date from-date) int-secs) (list date
(if invert (/ 1 amt) amt))))) (if invert (/ 1 amt) amt)))))
data)) data))
@ -277,19 +257,25 @@ Unfortunately, the plotting tool can't handle that.")))
chart (map chart (map
(match-lambda (match-lambda
((x y) ((x y)
(format #f "~2,2f ~a = ~a" (format #f "~a = ~a"
x int-label (gnc:monetary->string (qof-print-date x)
(gnc:make-gnc-monetary amount-commodity y))))) (gnc:monetary->string (gnc:make-gnc-monetary amount-commodity y)))))
data)) data))
(gnc:html-chart-add-data-series! (gnc:html-chart-add-data-series!
chart (G_ "Price") chart (G_ "Price")
(map (match-lambda ((x y) (list (cons 'x x) (cons 'y y)))) data) (map (match-lambda ((x y) (list (cons 'x (gnc-print-time64 x iso-date)) (cons 'y y)))) data)
mcolor mcolor
'pointBorderColor mcolor 'fill #f 'borderColor "#4bb2c5" 'pointBorderColor mcolor 'fill #f 'borderColor "#4bb2c5"
'pointBackgroundColor 'pointBackgroundColor
(if (memq marker '(filledcircle filledsquare filleddiamond)) mcolor "white")) (if (memq marker '(filledcircle filledsquare filleddiamond)) mcolor "white"))
(gnc:html-chart-set! chart '(options scales xAxes (0) type) 'time)
(gnc:html-chart-set! chart '(options scales xAxes (0) time)
(list (cons 'unit 'day)
(list 'displayFormats (cons 'day "DD-MM-YYYY"))
(cons 'tooltipFormat "DD-MM-YYYY")))
(gnc:html-document-add-object! document chart))))) (gnc:html-document-add-object! document chart)))))
document)) document))