Skip to content

numeric interval & documentation #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 24, 2021
Merged

numeric interval & documentation #552

merged 4 commits into from
Sep 24, 2021

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Sep 24, 2021

No description provided.

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

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

Nice generalization! 👍

@@ -6,6 +6,10 @@ import {maybeInsetX, maybeInsetY} from "./inset.js";
// 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
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
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 :)

@@ -6,6 +6,10 @@ import {maybeInsetX, maybeInsetY} from "./inset.js";
// chose between UTC and local time (or better, an explicit timeZone option).
function maybeInterval(interval) {
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
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};

README.md Outdated
@@ -801,7 +801,9 @@ The following channels are optional:
* **x2** - the ending horizontal position; bound to the *x* scale
* **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
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 <[email protected]>
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