-
Notifications
You must be signed in to change notification settings - Fork 185
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
interval for rect #550
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
30f6216
interval for rect
mbostock 827000c
default insets for intervals
mbostock f7c29ad
Update src/transforms/interval.js
Fil cb26d3f
numeric interval & documentation (#552)
Fil e458601
interval for rule and bar
mbostock 17115d5
Update CHANGELOG
mbostock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {offset} from "../style.js"; | ||
|
||
export function maybeInsetX({inset, insetLeft, insetRight, ...options} = {}) { | ||
([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight)); | ||
return {inset, insetLeft, insetRight, ...options}; | ||
} | ||
|
||
export function maybeInsetY({inset, insetTop, insetBottom, ...options} = {}) { | ||
([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom)); | ||
return {inset, insetTop, insetBottom, ...options}; | ||
} | ||
|
||
function maybeInset(inset, inset1, inset2) { | ||
return inset === undefined && inset1 === undefined && inset2 === undefined | ||
? (offset ? [1, 0] : [0.5, 0.5]) | ||
: [inset1, inset2]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {labelof, maybeValue, valueof} from "../mark.js"; | ||
import {maybeInsetX, maybeInsetY} from "./inset.js"; | ||
|
||
// TODO Allow the interval to be specified as a string, e.g. “day” or “hour”? | ||
// This will require the interval knowing the type of the associated scale to | ||
// chose between UTC and local time (or better, an explicit timeZone option). | ||
function maybeInterval(interval) { | ||
if (interval == null) return; | ||
if (typeof interval === "number") { | ||
const n = interval; | ||
// Note: this offset doesn’t support the optional step argument for simplicity. | ||
interval = {floor: d => n * Math.floor(d / n), offset: d => d + n}; | ||
} | ||
if (typeof interval.floor !== "function" || typeof interval.offset !== "function") throw new Error("invalid interval"); | ||
return interval; | ||
} | ||
|
||
// The interval may be specified either as x: {value, interval} or as {x, | ||
// interval}. The former is used, for example, for Plot.rect. | ||
function maybeIntervalValue(value, {interval} = {}) { | ||
value = {...maybeValue(value)}; | ||
value.interval = maybeInterval(value.interval === undefined ? interval : value.interval); | ||
return value; | ||
} | ||
|
||
function maybeIntervalK(k, maybeInsetK, options = {}) { | ||
const {[k]: v, [`${k}1`]: v1, [`${k}2`]: v2} = options; | ||
const {value, interval} = maybeIntervalValue(v, options); | ||
if (interval == null) return options; | ||
let V1; | ||
const tv1 = data => V1 || (V1 = valueof(data, value).map(v => interval.floor(v))); | ||
const label = labelof(v); | ||
return maybeInsetK({ | ||
...options, | ||
[k]: undefined, | ||
[`${k}1`]: v1 === undefined ? {transform: tv1, label} : v1, | ||
[`${k}2`]: v2 === undefined ? {transform: () => tv1().map(v => interval.offset(v)), label} : v2 | ||
}); | ||
} | ||
|
||
export function maybeIntervalX(options) { | ||
return maybeIntervalK("x", maybeInsetX, options); | ||
} | ||
|
||
export function maybeIntervalY(options = {}) { | ||
return maybeIntervalK("y", maybeInsetY, options); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 👍