1
1
import type { ScaleName , ScaleOptions } from "./scales.js" ;
2
2
3
+ export interface SwatchesLegendOptions {
4
+ /**
5
+ * The width of the legend in pixels. Defaults to undefined, allowing swatches
6
+ * to wrap based on content flow.
7
+ */
8
+ width ?: number ;
9
+
10
+ /**
11
+ * The [CSS columns property][1], for a multi-column layout.
12
+ *
13
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/columns
14
+ */
15
+ columns ?: string ;
16
+
17
+ /** The swatch width and height in pixels; defaults to 15. */
18
+ swatchSize ?: number ;
19
+
20
+ /** The swatch width in pixels; defaults to **swatchSize**. */
21
+ swatchWidth ?: number ;
22
+
23
+ /** The swatch height in pixels; defaults to **swatchSize**. */
24
+ swatchHeight ?: number ;
25
+ }
26
+
27
+ export interface RampLegendOptions {
28
+ /** The width of the legend in pixels; defaults to 240. */
29
+ width ?: number ;
30
+ /** The height of the legend in pixels; defaults to 44 plus **tickSize**. */
31
+ height ?: number ;
32
+ /** The top margin in pixels; defaults to 18. */
33
+ marginTop ?: number ;
34
+ /** The right margin in pixels; defaults to 0. */
35
+ marginRight ?: number ;
36
+ /** The bottom margin in pixels; defaults to 16 plus **tickSize**. */
37
+ marginBottom ?: number ;
38
+ /** The left margin in pixels; defaults to 0. */
39
+ marginLeft ?: number ;
40
+
41
+ /**
42
+ * The desired approximate number of axis ticks, or an explicit array of tick
43
+ * values, or an interval such as *day* or *month*.
44
+ */
45
+ ticks ?: ScaleOptions [ "ticks" ] ;
46
+
47
+ /**
48
+ * The length of axis tick marks in pixels; negative values extend in the
49
+ * opposite direction.
50
+ */
51
+ tickSize ?: ScaleOptions [ "tickSize" ] ;
52
+
53
+ /**
54
+ * If true, round the output value to the nearest integer (pixel); useful for
55
+ * crisp edges when rendering.
56
+ */
57
+ round ?: ScaleOptions [ "round" ] ;
58
+ }
59
+
60
+ export interface OpacityLegendOptions extends RampLegendOptions {
61
+ /** The constant color the ramp; defaults to black. */
62
+ color ?: string ;
63
+ }
64
+
65
+ export interface ColorLegendOptions extends SwatchesLegendOptions , RampLegendOptions {
66
+ /** The desired opacity of the color swatches or ramp; defaults to 1. */
67
+ opacity ?: number ;
68
+ }
69
+
70
+ export interface SymbolLegendOptions extends SwatchesLegendOptions {
71
+ /** The desired fill color of symbols; use *color* for a redundant encoding. */
72
+ fill ?: string ;
73
+ /** The desired fill opacity of symbols; defaults to 1. */
74
+ fillOpacity ?: number ;
75
+ /** The desired stroke color of symbols; use *color* for a redundant encoding. */
76
+ stroke ?: string ;
77
+ /** The desired stroke opacity of symbols; defaults to 1. */
78
+ strokeOpacity ?: number ;
79
+ /** The desired stroke width of symbols; defaults to 1.5. */
80
+ strokeWidth ?: number ;
81
+ /** The desired radius of symbols in pixels; defaults to 4.5. */
82
+ r ?: number ;
83
+ }
84
+
3
85
/** Options for generating a scale legend. */
4
- export interface LegendOptions {
86
+ export interface LegendOptions extends ColorLegendOptions , SymbolLegendOptions , OpacityLegendOptions {
5
87
/**
6
88
* The desired legend type; one of:
7
89
*
@@ -15,6 +97,9 @@ export interface LegendOptions {
15
97
*/
16
98
legend ?: "ramp" | "swatches" ;
17
99
100
+ /** A textual label to place above the legend. */
101
+ label ?: string | null ;
102
+
18
103
/**
19
104
* How to format tick values sampled from the scale’s domain. This may be a
20
105
* function, which will be passed the tick value *t* and zero-based index *i*
@@ -44,81 +129,6 @@ export interface LegendOptions {
44
129
* default, a random string prefixed with “plot-”.
45
130
*/
46
131
className ?: string | null ;
47
-
48
- /** The constant color the ramp; defaults to black. For *ramp* *opacity* legends only. */
49
- color ?: string ;
50
- /** The desired fill color of symbols; use *color* for a redundant encoding. For *symbol* legends only. */
51
- fill ?: string ;
52
- /** The desired fill opacity of symbols. For *symbol* legends only. */
53
- fillOpacity ?: number ;
54
- /** The desired opacity of the color swatches or ramp. For *color* legends only. */
55
- opacity ?: number ;
56
- /** The desired stroke color of symbols; use *color* for a redundant encoding. For *symbol* legends only. */
57
- stroke ?: string ;
58
- /** The desired stroke opacity of symbols. For *symbol* legends only. */
59
- strokeOpacity ?: number ;
60
- /** The desired stroke width of symbols. For *symbol* legends only. */
61
- strokeWidth ?: number ;
62
- /** The desired radius of symbols in pixels. For *symbol* legends only. */
63
- r ?: number ;
64
-
65
- /**
66
- * The width of the legend in pixels. For *ramp* legends, defaults to 240; for
67
- * *swatch* legends, defaults to undefined, allowing the swatches to wrap
68
- * based on content flow.
69
- */
70
- width ?: number ;
71
-
72
- /**
73
- * The height of the legend in pixels; defaults to 44 plus **tickSize**. For
74
- * *ramp* legends only.
75
- */
76
- height ?: number ;
77
-
78
- /** The top margin in pixels; defaults to 18. For *ramp* legends only. */
79
- marginTop ?: number ;
80
- /** The right margin in pixels; defaults to 0. For *ramp* legends only. */
81
- marginRight ?: number ;
82
- /** The bottom margin in pixels; defaults to 16 plus **tickSize**. For *ramp* legends only. */
83
- marginBottom ?: number ;
84
- /** The left margin in pixels; defaults to 0. For *ramp* legends only. */
85
- marginLeft ?: number ;
86
-
87
- /** A textual label to place above the legend. For *ramp* legends only. */
88
- label ?: string | null ;
89
-
90
- /**
91
- * The desired approximate number of axis ticks, or an explicit array of tick
92
- * values, or an interval such as *day* or *month*. For *ramp* legends only.
93
- */
94
- ticks ?: ScaleOptions [ "ticks" ] ;
95
-
96
- /**
97
- * The length of axis tick marks in pixels; negative values extend in the
98
- * opposite direction. For *ramp* legends only.
99
- */
100
- tickSize ?: ScaleOptions [ "tickSize" ] ;
101
-
102
- /**
103
- * If true, round the output value to the nearest integer (pixel); useful for
104
- * crisp edges when rendering. For *ramp* legends only.
105
- */
106
- round ?: ScaleOptions [ "round" ] ;
107
-
108
- /**
109
- * The [CSS columns property][1], for a multi-column layout. For *swatches*
110
- * legends only.
111
- *
112
- * [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/columns
113
- */
114
- columns ?: string ;
115
-
116
- /** The swatch width and height in pixels; defaults to 15; For *swatches* legends only. */
117
- swatchSize ?: number ;
118
- /** The swatch width in pixels; defaults to **swatchSize**; For *swatches* legends only. */
119
- swatchWidth ?: number ;
120
- /** The swatch height in pixels; defaults to **swatchSize**; For *swatches* legends only. */
121
- swatchHeight ?: number ;
122
132
}
123
133
124
134
/** Scale definitions and options for a standalone legend. */
0 commit comments