Skip to content
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

interval for rect #550

Merged
merged 6 commits into from
Sep 24, 2021
Merged

interval for rect #550

merged 6 commits into from
Sep 24, 2021

Conversation

mbostock
Copy link
Member

Adds an interval option for rects which transforms x to x1 and x2 using interval.floor and interval.offset. This provides a suitable replacement for bars when an axis is temporal rather than ordinal. Related #513, and perhaps this could be considered a fix.

I’d further love to be able to specify a named interval such as “day” or “hour”, but this requires knowing the time zone (or for now, whether the associated scale is “utc” or local “time”). That’s not easily accessible when evaluating a transform since this happens before scales are constructed. Although I suspect that with a top-level timeZone option #531 we could find some way of passing this down to the transform. At any rate, convenience shorthand can be added in the future.

@mbostock mbostock requested a review from Fil September 23, 2021 20:35
@mbostock
Copy link
Member Author

I guess this should probably set default insets, too, like e.g. bin does?

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

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

Should we expose this in some way, so that custom marks could have access to this new transform?
I'm sending a few suggestions in another PR

src/transforms/interval.js Outdated Show resolved Hide resolved

function maybeInset(inset, inset1, inset2) {
return inset === undefined && inset1 === undefined && inset2 === undefined
? (offset ? [1, 0] : [0.5, 0.5])
Copy link
Contributor

Choose a reason for hiding this comment

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

(This is not new) The default inset makes the marks vanish if they are too narrow. For example in aapl-volume-rect, if you take the whole dataset instead of just a slice, the resulting chart is blank.

Copy link
Contributor

Choose a reason for hiding this comment

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

refs. #422 and d3/d3-scale#243

Copy link
Member Author

Choose a reason for hiding this comment

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

I’m aware of this problem but not going to fix it here. 👍

@mbostock
Copy link
Member Author

mbostock commented Sep 24, 2021

I don’t think we should expose the interval (or inset) transform yet, out of conservatism, but we can always chose to do so in the future if we think it’s useful.

@mbostock
Copy link
Member Author

I think I want to add the interval transform to bar and rule, too.

@mbostock
Copy link
Member Author

Added. Works nicely!

@mbostock mbostock merged commit 33ab79e into main Sep 24, 2021
@mbostock mbostock deleted the mbostock/rect-interval branch September 24, 2021 17:52
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