1
1
import type { ScaleName , ScaleOptions } from "./scales.js" ;
2
2
3
- /** The supported legend types. */
4
- export type LegendType = "ramp" | "swatches" ;
5
-
6
3
/** Options for generating a scale legend. */
7
4
export interface LegendOptions {
8
5
/**
9
- * The desired legend type; currently supported only for a discrete *color*
10
- * scale of type *ordinal*, *quantile*, *quantize*, or *threshold*. One of:
6
+ * The desired legend type; one of:
7
+ *
8
+ * - *ramp* - place labels underneath with a connecting line, and no wrapping
9
+ * - *swatches* - place labels to the right, and allow wrapping
11
10
*
12
- * * *ramp* - place labels underneath with a connecting line, and no wrapping
13
- * * *swatches* - place labels to the right, and allow wrapping
11
+ * The legend type can currently only be configured for a discrete *color*
12
+ * scale of type *ordinal*, *quantile*, *quantize*, or *threshold*; for other
13
+ * *color* scale types, or for *opacity* or *symbol* scales, the legend type
14
+ * cannot be changed.
14
15
*/
15
- legend ?: LegendType ;
16
+ legend ?: "ramp" | "swatches" ;
16
17
17
18
/**
18
19
* How to format tick values sampled from the scale’s domain. This may be a
19
20
* function, which will be passed the tick value *t* and zero-based index *i*
20
21
* and must return the corresponding string. If the domain is numbers, the
21
- * tick format may also be expressed as a [d3-format
22
- * string](https://github.com/d3/d3-format/blob/main/README.md#locale_format);
23
- * or if the domain is dates, the tick format may also be expressed as a
24
- * [d3-time-format
25
- * string](https://github.com/d3/d3-time-format/blob/main/README.md#locale_format).
22
+ * tick format may also be expressed as a [d3-format string][1]; or if the
23
+ * domain is dates, the tick format may also be expressed as a [d3-time-format
24
+ * string][2].
25
+ *
26
+ * [1]: https://github.com/d3/d3-format/blob/main/README.md#locale_format
27
+ * [2]: https://github.com/d3/d3-time-format/blob/main/README.md#locale_format
26
28
*/
27
29
tickFormat ?: ScaleOptions [ "tickFormat" ] ;
28
30
29
31
/**
30
- * The [CSS
31
- * font-variant](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant)
32
- * for tick labels. For non-ordinal scales, or ordinal scales without an
33
- * interval, this defaults to *tabular-nums*.
32
+ * The [CSS font-variant][1] for tick labels. For non-ordinal scales, or
33
+ * ordinal scales without an interval, this defaults to *tabular-nums*.
34
+ *
35
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant
34
36
*/
35
37
fontVariant ?: ScaleOptions [ "fontVariant" ] ;
36
38
@@ -43,35 +45,77 @@ export interface LegendOptions {
43
45
*/
44
46
className ?: string | null ;
45
47
46
- /** The constant color for *opacity* scales. Defaults to black. */
48
+ /** The constant color the ramp; defaults to black. For *ramp* *opacity* legends only . */
47
49
color ?: string ;
48
-
49
- // symbol options
50
+ /** The desired fill color of symbols; use *color* for a redundant encoding. For *symbol* legends only. */
50
51
fill ?: string ;
52
+ /** The desired fill opacity of symbols. For *symbol* legends only. */
51
53
fillOpacity ?: number ;
54
+ /** The desired stroke color of symbols; use *color* for a redundant encoding. For *symbol* legends only. */
52
55
stroke ?: string ;
56
+ /** The desired stroke opacity of symbols. For *symbol* legends only. */
53
57
strokeOpacity ?: number ;
58
+ /** The desired stroke width of symbols. For *symbol* legends only. */
54
59
strokeWidth ?: number ;
60
+ /** The desired radius of symbols in pixels. For *symbol* legends only. */
55
61
r ?: number ;
56
62
57
- // dimensions
63
+ /**
64
+ * The width of the legend in pixels. For *ramp* legends, defaults to 240; for
65
+ * *swatch* legends, defaults to undefined, allowing the swatches to wrap
66
+ * based on content flow.
67
+ */
58
68
width ?: number ;
69
+
70
+ /**
71
+ * The height of the legend in pixels; defaults to 44 plus **tickSize**. For
72
+ * *ramp* legends only.
73
+ */
59
74
height ?: number ;
75
+
76
+ /** The top margin in pixels; defaults to 18. For *ramp* legends only. */
60
77
marginTop ?: number ;
78
+ /** The right margin in pixels; defaults to 0. For *ramp* legends only. */
61
79
marginRight ?: number ;
80
+ /** The bottom margin in pixels; defaults to 16 plus **tickSize**. For *ramp* legends only. */
62
81
marginBottom ?: number ;
82
+ /** The left margin in pixels; defaults to 0. For *ramp* legends only. */
63
83
marginLeft ?: number ;
64
84
65
- // ramp options
85
+ /** A textual label to place above the legend. For * ramp* legends only. */
66
86
label ?: string | null ;
87
+
88
+ /**
89
+ * The desired approximate number of axis ticks, or an explicit array of tick
90
+ * values, or an interval such as *day* or *month*. For *ramp* legends only.
91
+ */
67
92
ticks ?: ScaleOptions [ "ticks" ] ;
93
+
94
+ /**
95
+ * The length of axis tick marks in pixels; negative values extend in the
96
+ * opposite direction. For *ramp* legends only.
97
+ */
68
98
tickSize ?: ScaleOptions [ "tickSize" ] ;
99
+
100
+ /**
101
+ * If true, round the output value to the nearest integer (pixel); useful for
102
+ * crisp edges when rendering. For *ramp* legends only.
103
+ */
69
104
round ?: ScaleOptions [ "round" ] ;
70
105
71
- // swatches options
106
+ /**
107
+ * The [CSS columns property][1], for a multi-column layout. For *swatches*
108
+ * legends only.
109
+ *
110
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/columns
111
+ */
72
112
columns ?: string ;
113
+
114
+ /** The swatch width and height in pixels; defaults to 15; For *swatches* legends only. */
73
115
swatchSize ?: number ;
116
+ /** The swatch width in pixels; defaults to **swatchSize**; For *swatches* legends only. */
74
117
swatchWidth ?: number ;
118
+ /** The swatch height in pixels; defaults to **swatchSize**; For *swatches* legends only. */
75
119
swatchHeight ?: number ;
76
120
}
77
121
0 commit comments