Skip to content

Commit

Permalink
document ordinal aspectRatio (#2255)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Nov 25, 2024
1 parent 283d8e1 commit 7d18179
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/features/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ The default **width** is 640. On Observable, the width can be set to the [standa
Plot does not adjust margins automatically to make room for long tick labels. If your *y* axis labels are too long, you can increase the **marginLeft** to make more room. Also consider using a different **tickFormat** for short labels (*e.g.*, `s` for SI prefix notation), or a scale **transform** (say to convert units to millions or billions).
:::

The **aspectRatio** option<a id="aspectRatio" href="#aspectRatio" aria-label="Permalink to &quot;aspectRatio&quot;"></a> <VersionBadge version="0.6.4" />, if not null, computes a default **height** such that a variation of one unit in the *x* dimension is represented by the corresponding number of pixels as a variation in the *y* dimension of one unit.
The **aspectRatio** option<a id="aspectRatio" href="#aspectRatio" aria-label="Permalink to &quot;aspectRatio&quot;"></a> <VersionBadge version="0.6.4" />, if not null, computes a default **height** such that a variation of one unit in the *x* dimension is represented by the corresponding number of pixels as a variation in the *y* dimension of one unit. The **aspectRatio** option is recommended only when *x* and *y* domains share the same units, such as millimeters. When a position scale is [ordinal](./scales.md#discrete-scales) (*point* or *band*), consecutive domain values are treated as one unit length apart; for example, if both *x* and *y* are ordinal, then an aspect ratio of one produces a square grid.

<p>
<label class="label-input">
Expand Down
2 changes: 1 addition & 1 deletion docs/features/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Plot.plot({
```
:::

Positions scales also have a **round** option which forces the scale to snap to integer pixels. This defaults to true for point and band scales, and false for quantitative scales. Use caution with high-cardinality ordinal domains (*i.e.*, a point or band scale used to encode many different values), as rounding can lead to “wasted” space or even zero-width bands.
Position scales also have a **round** option which forces the scale to snap to integer pixels. This defaults to true for point and band scales, and false for quantitative scales. Use caution with high-cardinality ordinal domains (*i.e.*, a point or band scale used to encode many different values), as rounding can lead to “wasted” space or even zero-width bands.

## Color scales

Expand Down
6 changes: 4 additions & 2 deletions src/plot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export interface PlotOptions extends ScaleDefaults {
* height. Given an aspect ratio of *dx* / *dy*, and assuming that the *x* and
* *y* scales represent equivalent units (say, degrees Celsius or meters),
* computes a default height such that *dx* pixels along *x* represents the
* same variation as *dy* pixels along *y*. Note: when faceting, set the *fx*
* and *fy* scales’ **round** option to false for an exact aspect ratio.
* same variation as *dy* pixels along *y*. When *x* or *y* is ordinal,
* consecutive domain values are treated as one unit length apart. Note: when
* faceting, set the *fx* and *fy* scales’ **round** option to false for an
* exact aspect ratio.
*/
aspectRatio?: number | boolean | null;

Expand Down

0 comments on commit 7d18179

Please sign in to comment.