You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Create Image mark
* Added snapshot test result
* Adding US President data example
* Removed NBA data example, regenerated snapshots
* Removed imageX and imageY
* Changed size to r
* Updated image and image-test to 0.2.0
* Added preserveAspectRatio and crossorigin to image
* Fix for new attrs
* fix test snapshot
* fold transform into xy; crossOrigin; style
* width, height, src
* implied xMidYMid
* default width to height
* ignore fill and stroke on images
* opacity
* allow constant src
* Update README
* Update README
* Update README
Co-authored-by: Robert Lesser <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -231,7 +231,7 @@ Given a scale definition, Plot can generate a legend.
231
231
232
232
#### *chart*.legend(*name*[, *options*])
233
233
234
-
Returns a suitable legend for the chart’s scale with the given *name*. For now, only *color*legends are supported.
234
+
Returns a suitable legend for the chart’s scale with the given *name*. Currently supports only *color*and *opacity* scales. An opacity scale is treated as a color scale with varying transparency.
235
235
236
236
Categorical and ordinal color legends are rendered as swatches, unless *options*.**legend** is set to *ramp*. The swatches can be configured with the following options:
237
237
@@ -259,7 +259,7 @@ Continuous color legends are rendered as a ramp, and can be configured with the
Returns a legend for the given *scale* definition, passing the options described in the previous section. Currently supports only *color* and *opacity* scales. An opacity scale is treated as a color scale with varying transparency.
262
+
Returns a legend for the given *scale* definition, passing the options described in the previous section.
263
263
264
264
### Position options
265
265
@@ -583,6 +583,7 @@ All marks support the following style options:
583
583
***strokeLinecap** - how to cap lines (*butt*, *round*, or *square*)
584
584
***strokeMiterlimit** - to limit the length of *miter* joins
585
585
***strokeDasharray** - a comma-separated list of dash lengths (in pixels)
586
+
***opacity** - object opacity (a number between 0 and 1)
586
587
***mixBlendMode** - the [blend mode](https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode) (*e.g.*, *multiply*)
587
588
***shapeRendering** - the [shape-rendering mode](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/shape-rendering) (*e.g.*, *crispEdges*)
588
589
***dx** - horizontal offset (in pixels; defaults to 0)
@@ -597,9 +598,10 @@ All marks support the following optional channels:
597
598
***stroke** - a stroke color; bound to the *color* scale
598
599
***strokeOpacity** - a stroke opacity; bound to the *opacity* scale
599
600
***strokeWidth** - a stroke width (in pixels)
601
+
***opacity** - an object opacity; bound to the *opacity* scale
600
602
***title** - a tooltip (a string of text, possibly with newlines)
601
603
602
-
The **fill**, **fillOpacity**, **stroke**, **strokeWidth**, and **strokeOpacity** options can be specified as either channels or constants. When the fill or stroke is specified as a function or array, it is interpreted as a channel; when the fill or stroke is specified as a string, it is interpreted as a constant if a valid CSS color and otherwise it is interpreted as a column name for a channel. Similarly when the fill or stroke opacity or the stroke width is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel. When the radius is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel.
604
+
The **fill**, **fillOpacity**, **stroke**, **strokeWidth**, **strokeOpacity**, and **opacity** options can be specified as either channels or constants. When the fill or stroke is specified as a function or array, it is interpreted as a channel; when the fill or stroke is specified as a string, it is interpreted as a constant if a valid CSS color and otherwise it is interpreted as a column name for a channel. Similarly when the fill opacity, stroke opacity, object opacity, stroke width, or radius is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel.
603
605
604
606
The rectangular marks ([bar](#bar), [cell](#cell), and [rect](#rect)) support insets and rounded corner constant options:
Equivalent to [Plot.dot](#plotdotdata-options) except that if the **y** option is not specified, it defaults to the identity function and assumes that *data* = [*y₀*, *y₁*, *y₂*, …].
796
798
799
+
### Image
800
+
801
+
[<imgsrc="./img/image.png"width="320"height="198"alt="a scatterplot of Presidential portraits">](https://observablehq.com/@observablehq/plot-image)
802
+
803
+
[Source](./src/marks/image.js) · [Examples](https://observablehq.com/@observablehq/plot-image) · Draws images as in a scatterplot. The required **src** option specifies the URL (or relative path) of each image. If **src** is specified as a string that starts with a dot, slash, or URL protocol (*e.g.*, “https:”) it is assumed to be a constant; otherwise it is interpreted as a channel.
804
+
805
+
In addition to the [standard mark options](#marks), the following optional channels are supported:
806
+
807
+
***x** - the horizontal position; bound to the *x* scale
808
+
***y** - the vertical position; bound to the *y* scale
809
+
***width** - the image width (in pixels)
810
+
***height** - the image height (in pixels)
811
+
812
+
If the **x** channel is not specified, images will be horizontally centered in the plot (or facet). Likewise if the **y** channel is not specified, images will vertically centered in the plot (or facet). Typically either *x*, *y*, or both are specified.
813
+
814
+
The **width** and **height** options default to 16 pixels and can be specified as either a channel or constant. When the width or height is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel. Dots with a nonpositive width or height are not drawn. If a **width** is specified but not a **height**, or *vice versa*, the one defaults to the other. Images do not support either a fill or a stroke.
815
+
816
+
The **preserveAspectRatio** and **crossOrigin** options, both constant, allow control over the [aspect ratio](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio) and [cross-origin](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/crossorigin) behavior, respectively. The default aspect ratio behavior is “xMidYMid meet”; consider “xMidYMid slice” to crop the image instead of scaling it to fit.
817
+
818
+
Images are drawn in input order, with the last data drawn on top. If sorting is needed, say to mitigate overplotting, consider a [sort and reverse transform](#transforms).
Returns a new image with the given *data* and *options*. If neither the **x** nor **y** options are specified, *data* is assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*, *y₂*, …].
827
+
797
828
### Line
798
829
799
830
[<imgsrc="./img/line.png"width="320"height="198"alt="a line chart">](https://observablehq.com/@observablehq/plot-line)
0 commit comments