|
1 | 1 | import type {ChannelValue, ChannelValueSpec} from "../channel.js";
|
2 | 2 | import type {Data, FrameAnchor, MarkOptions, RenderableMark} from "../mark.js";
|
3 | 3 |
|
| 4 | +/** Options for the image mark. */ |
4 | 5 | export interface ImageOptions extends MarkOptions {
|
| 6 | + /** |
| 7 | + * The horizontal position channel specifying the image’s center; typically |
| 8 | + * bound to the *x* scale. |
| 9 | + */ |
5 | 10 | x?: ChannelValueSpec;
|
| 11 | + |
| 12 | + /** |
| 13 | + * The vertical position channel specifying the image’s center; typically |
| 14 | + * bound to the *y* scale. |
| 15 | + */ |
6 | 16 | y?: ChannelValueSpec;
|
| 17 | + |
| 18 | + /** |
| 19 | + * The image width in pixels. When a number, it is interpreted as a constant |
| 20 | + * radius in pixels; otherwise it is interpreted as a channel. Also sets the |
| 21 | + * default **height**; if neither are set, defaults to 16. Images with a |
| 22 | + * nonpositive width are not drawn. |
| 23 | + */ |
7 | 24 | width?: ChannelValue;
|
| 25 | + |
| 26 | + /** |
| 27 | + * The image height in pixels. When a number, it is interpreted as a constant |
| 28 | + * radius in pixels; otherwise it is interpreted as a channel. Also sets the |
| 29 | + * default **height**; if neither are set, defaults to 16. Images with a |
| 30 | + * nonpositive height are not drawn. |
| 31 | + */ |
8 | 32 | height?: ChannelValue;
|
| 33 | + |
| 34 | + /** |
| 35 | + * The required image URL (or relative path). If a string that starts with a |
| 36 | + * dot, slash, or URL protocol (*e.g.*, “https:”) it is assumed to be a |
| 37 | + * constant; otherwise it is interpreted as a channel. |
| 38 | + */ |
9 | 39 | src?: ChannelValue;
|
| 40 | + |
| 41 | + /** |
| 42 | + * The image [aspect ratio][1]; defaults to *xMidYMid meet*. To crop the image |
| 43 | + * instead of scaling it to fit, use *xMidYMid slice*. |
| 44 | + * |
| 45 | + * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio |
| 46 | + */ |
10 | 47 | preserveAspectRatio?: string;
|
| 48 | + |
| 49 | + /** |
| 50 | + * The [cross-origin][1] behavior. See the [Plot.image notebook][2] for details. |
| 51 | + * |
| 52 | + * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/crossorigin |
| 53 | + * [2]: https://observablehq.com/@observablehq/plot-image |
| 54 | + */ |
11 | 55 | crossOrigin?: string;
|
| 56 | + |
| 57 | + /** |
| 58 | + * The frame anchor specifies defaults for **x** and **y** based on the plot’s |
| 59 | + * frame; it may be one of the four sides (*top*, *right*, *bottom*, *left*), |
| 60 | + * one of the four corners (*top-left*, *top-right*, *bottom-right*, |
| 61 | + * *bottom-left*), or the *middle* of the frame. |
| 62 | + */ |
12 | 63 | frameAnchor?: FrameAnchor;
|
| 64 | + |
| 65 | + /** |
| 66 | + * The [image-rendering attribute][1]; defaults to *auto* (bilinear). The |
| 67 | + * option may be set to *pixelated* to disable bilinear interpolation for a |
| 68 | + * sharper image; however, note that this is not supported in WebKit. |
| 69 | + * |
| 70 | + * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/image-rendering |
| 71 | + */ |
13 | 72 | imageRendering?: string;
|
14 | 73 | }
|
15 | 74 |
|
| 75 | +/** |
| 76 | + * Returns a new image mark for the given *data* and *options* that draws images |
| 77 | + * as in a scatterplot. For example, portraits of U.S. presidents by date of |
| 78 | + * inauguration and favorability: |
| 79 | + * |
| 80 | + * ```js |
| 81 | + * Plot.image(presidents, {x: "inauguration", y: "favorability", src: "portrait"}) |
| 82 | + * ``` |
| 83 | + * |
| 84 | + * If either **x** or **y** is not specified, the default is determined by the |
| 85 | + * **frameAnchor** option. If none of **x**, **y**, and **frameAnchor** are |
| 86 | + * specified, *data* is assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*, |
| 87 | + * *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** = |
| 88 | + * [*y₀*, *y₁*, *y₂*, …]. |
| 89 | + */ |
16 | 90 | export function image(data?: Data, options?: ImageOptions): Image;
|
17 | 91 |
|
| 92 | +/** The image mark. */ |
18 | 93 | export class Image extends RenderableMark {}
|
0 commit comments