Skip to content

Commit 56d3da8

Browse files
authored
numeric interval & documentation (#552)
1 parent 216eac0 commit 56d3da8

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Observable Plot - Changelog
22

3+
## 0.3.0
4+
5+
*Not yet released.* These notes are a work in progress.
6+
7+
### Marks
8+
9+
The rect marks now accept an *interval* option that allows to derive *x1* and *x2* from *x*. A typical use case is an interval: d3.utcDay which creates a rect spanning the whole day that contains a certain date-time. The interval can be specified as an object with *floor** method that returns *x1* from *x* and an **offset** method that returns *x2* from *x1*. If the interval is specified as a (non-null) number, *x1* and *x2* are taken as the two consecutive multiples of *n* that bracket *x*.
10+
311
## 0.2.1
412

513
Released September 19, 2021.

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,9 @@ The following channels are optional:
801801
* **x2** - the ending horizontal position; bound to the *x* scale
802802
* **y2** - the ending vertical position; bound to the *y* scale
803803

804-
Typically either **x1** and **x2** are specified, or **y1** and **y2**, or both. The rect mark supports the [standard mark options](#marks), including insets and rounded corners. The **stroke** defaults to none. The **fill** defaults to currentColor if the stroke is none, and to none otherwise.
804+
Typically either **x1** and **x2** are specified, or **y1** and **y2**, or both. **x1** and **x2** can be derived from **x** and an **interval** object (such as d3.utcDay) with a **floor** method that returns *x1* from *x* and an **offset** method that returns *x2* from *x1*. If the interval is specified as a number *n*, *x1* and *x2* are taken as the two consecutive multiples of *n* that bracket *x*. The interval may be specified either as as {x, interval} or x: {value, interval}—typically to apply different intervals to x and y.
805+
806+
The rect mark supports the [standard mark options](#marks), including insets and rounded corners. The **stroke** defaults to none. The **fill** defaults to currentColor if the stroke is none, and to none otherwise.
805807

806808
#### Plot.rect(*data*, *options*)
807809

src/transforms/interval.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import {maybeInsetX, maybeInsetY} from "./inset.js";
66
// chose between UTC and local time (or better, an explicit timeZone option).
77
function maybeInterval(interval) {
88
if (interval == null) return;
9+
if (typeof interval === "number") {
10+
const n = interval;
11+
// Note: this offset doesn’t support the optional step argument for simplicity.
12+
interval = {floor: d => n * Math.floor(d / n), offset: d => d + n};
13+
}
914
if (typeof interval.floor !== "function" || typeof interval.offset !== "function") throw new Error("invalid interval");
1015
return interval;
1116
}

0 commit comments

Comments
 (0)