Skip to content

Commit cf95637

Browse files
author
J. Ian Johnson
committed
Separate legend font from plot font for more control. Unset parameters default to plot parameters.
1 parent 75d6904 commit cf95637

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

plot-doc/plot/scribblings/params.scrbl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ The opacity of the background and foreground colors.
9595
The font size (in drawing units), face, and family of the title, axis labels, tick labels, and other labels.
9696
}
9797

98+
@deftogether[((defparam plot-legend-font-size size (or/c (>=/c 0) #f) #:value #f)
99+
(defparam plot-legend-font-face face (or/c string? #f) #:value #f)
100+
(defparam plot-legend-font-family family (or/c font-family/c #f) #:value #f))]{
101+
The font size (in drawing units), face, and family to prefer for the legend text. If set to @racket[#f], then the corresponding @racket[plot-font-X] parameter is used.
102+
}
103+
98104
@deftogether[((defparam plot-legend-anchor anchor anchor/c #:value 'top-left)
99105
(defparam plot-legend-box-alpha alpha (real-in 0 1) #:value 2/3))]{
100106
The placement of the legend and the opacity of its background.

plot-lib/plot/private/common/parameter-groups.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
plot-background plot-background-alpha
2929
plot-line-width plot-tick-size
3030
plot-font-size plot-font-face plot-font-family
31+
plot-legend-font-size plot-legend-font-face plot-legend-font-family
3132
plot-legend-anchor plot-legend-box-alpha
3233
plot-axes? plot-tick-labels
3334
plot-decorations?
@@ -86,6 +87,9 @@
8687
Nonnegative-Real
8788
(U False String)
8889
Font-Family
90+
(U False Nonnegative-Real)
91+
(U False String)
92+
(U False Font-Family)
8993
Anchor
9094
Nonnegative-Real
9195
(List Boolean Boolean Boolean Boolean Boolean Boolean)

plot-lib/plot/private/common/parameters.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
(defparam2 plot-font-size size Real Nonnegative-Real 11 (nonnegative-rational 'plot-font-size))
7272
(defparam plot-font-face face (U String #f) #f)
7373
(defparam plot-font-family family Font-Family 'roman)
74+
(defparam plot-legend-font-size size (U Nonnegative-Real #f) #f)
75+
(defparam plot-legend-font-face face (U String #f) #f)
76+
(defparam plot-legend-font-family family (U Font-Family #f) #f)
7477
(defparam plot-legend-anchor anchor Anchor 'top-left)
7578
(defparam2 plot-legend-box-alpha alpha Real Nonnegative-Real 2/3 (unit-ivl 'plot-legend-box-alpha))
7679
(defparam plot-animating? Boolean #f)

plot-lib/plot/private/common/plot-device.rkt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@
587587

588588
(match-define (vector (ivl x-min x-max) (ivl y-min y-max)) rect)
589589

590+
(define old-size (send (send dc get-font) get-point-size))
591+
(define old-face (send (send dc get-font) get-face))
592+
(define old-family (send (send dc get-font) get-family))
593+
(set-font-attribs
594+
(or (plot-legend-font-size) old-size)
595+
(or (plot-legend-font-face) old-face)
596+
(or (plot-legend-font-family) old-family))
597+
590598
(define-values (_1 label-y-size baseline _2) (get-text-extent (first labels)))
591599
(define horiz-gap (get-text-width " "))
592600
(define top-gap baseline)
@@ -656,6 +664,9 @@
656664
(send entry-pd reset-drawing-params #f)
657665
(draw-proc this draw-x-size draw-y-size)
658666
(send entry-pd restore-drawing-params))
667+
668+
;; reset plot font attributes
669+
(set-font-attribs old-size old-face old-family)
659670

660671
(clear-clipping-rect))
661672
)) ; end class

plot-lib/plot/private/utils-and-no-gui.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
plot-font-size
7777
plot-font-face
7878
plot-font-family
79+
plot-legend-font-size
80+
plot-legend-font-face
81+
plot-legend-font-family
7982
plot-legend-anchor
8083
plot-legend-box-alpha
8184
plot-decorations?

0 commit comments

Comments
 (0)