Skip to content

numeric interval & documentation - #552

Merged
Fil merged 4 commits into
mbostock/rect-intervalfrom
fil/interval
Sep 24, 2021
Merged

Fil merged 4 commits into
mbostock/rect-intervalfrom
fil/interval

Conversation

@Fil

@Fil Fil commented Sep 24, 2021

Copy link
Copy Markdown
Contributor

No description provided.

@Fil
Fil requested a review from mbostock September 24, 2021 08:47

@mbostock mbostock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice generalization! 👍

Comment thread src/transforms/interval.js Outdated
// chose between UTC and local time (or better, an explicit timeZone option).
function maybeInterval(interval) {
if (interval == null) return;
if (typeof interval === "number" && interval) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the truthy interval test for? Testing for nonzero, non-NaN? I think I’d prefer to drop this because it’s not sufficient to ensure good behavior (for example, Infinity or -Infinity will produce NaN below), and it’s just simpler to avoid trying.

Suggested change
if (typeof interval === "number" && interval) {
if (typeof interval === "number") {

Alternatively, we could ignore NaN specifically:

Suggested change
if (typeof interval === "number" && interval) {
if (typeof interval === "number" && !isNaN(interval)) {

This will still break for zero and infinities, but those are at least considered defined values, so it’s probably reasonable that it breaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with not trying :)

Comment thread src/transforms/interval.js Outdated
if (interval == null) return;
if (typeof interval === "number" && interval) {
const n = interval;
interval = { floor: d => n * Math.floor(d / n), offset: d => d + n };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interval = { floor: d => n * Math.floor(d / n), offset: d => d + n };
// Note: this offset doesn’t support the optional step argument for simplicity.
interval = {floor: d => n * Math.floor(d / n), offset: d => d + n};

Comment thread README.md Outdated
* **y2** - the ending vertical position; bound to the *y* scale

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.
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 (non-null) number, *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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 (non-null) number, *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.
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 (and not NaN), *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.

@Fil
Fil merged commit 56d3da8 into mbostock/rect-interval Sep 24, 2021
@Fil
Fil deleted the fil/interval branch September 24, 2021 13:57
mbostock pushed a commit that referenced this pull request Sep 24, 2021
mbostock added a commit that referenced this pull request Sep 24, 2021
* interval for rect

* default insets for intervals

* Update src/transforms/interval.js

* numeric interval & documentation (#552)

* interval for rule and bar

* Update CHANGELOG

Co-authored-by: Philippe Rivière <fil@rezo.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants