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
feat: make timeunit for bar/rect behaves more like bin #5096
Conversation
bfda0fd
to
d275131
Compare
…o avoid overflow This is especially important for temporal in a follow up PR (#5096).
4ce82fe
to
84c91a2
Compare
@@ -13,6 +13,16 @@ | |||
"format": {"type": "csv", "parse": {"date": "date"}}, | |||
"transform": [ | |||
{"type": "identifier", "as": "_vgsid_"}, | |||
{ |
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 don't know if we generate the best time format here.
examples/compiled/layer_line_errorband_2d_horizontal_borders_strokedash.vg.json
Outdated
Show resolved
Hide resolved
cfc0497
to
68db08b
Compare
@@ -361,16 +363,50 @@ export interface PositionFieldDef<F extends Field> | |||
impute?: ImputeParams; | |||
|
|||
/** | |||
* For rect-based marks (`rect`, `bar`, and `image`), mark size relative to bandwidth of [band scales](https://vega.github.io/vega-lite/docs/scale.html#band). If set to `1`, the mark size is set to the bandwidth. If set to `0.5`, the mark size is half of the bandwidth. | |||
* For rect-based marks (`rect`, `bar`, and `image`), mark size relative to bandwidth of [band scales](https://vega.github.io/vega-lite/docs/scale.html#band) or time units. If set to `1`, the mark size is set to the bandwidth or the time unit interval. If set to `0.5`, the mark size is half of the bandwidth or the time unit interval. |
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.
rect/bar can be band position too, if size property is explicitly specified.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -55,15 +55,16 @@ export function rectPosition(model: UnitModel, channel: 'x' | 'y', mark: 'bar' | | |||
// x, x2, and width -- we must specify two of these in all conditions | |||
if ( | |||
isFieldDef(fieldDef) && | |||
(isBinning(fieldDef.bin) || isBinned(fieldDef.bin)) && | |||
// FIXME use band to determine condition here |
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.
FYI, this will be fixed later in #5244
This comment has been minimized.
This comment has been minimized.
BREAKING CHANGE: bar/rect with timeUnit would look differently
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.
src/mark.ts
Outdated
/** | ||
* Default band position for a time unit. | ||
*/ | ||
timeUnitBandPosition?: 0 | 0.5; |
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.
Why can this only be two values? Please document.
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.
Technically it doesn't have to be either 0 or 0.5. But in practice, these numbers won't make sense if they are not 0 (beginning of the timeUnit interval or 0.5 (middle of the timeUnit interval).
I can relax it to number.
@@ -17,9 +17,14 @@ | |||
"as": "yearmonth_date", |
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.
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 PR doesn't change anything about the label.
it's really hard to know what the values for axis ticks are
This example is only there for explaining that you can customize the format. (See format.md
.) So if you strongly think this should be change, please submit a separate PR for it.
No. Grid in time actually usually represent year / month boundaries, which are helpful to readers. (Grid in bins do not mean much.) In a follow up PR, I'll even make the default band different between bin and timeUnit. |
New user, trying to follow the discussion here. With a known domain resolution of e.g. yearmonth, wouldn't you want the tick mark of the x-axis to be centered under the bar? |
Fix #4868
In this PR, we only make timeUnit like binning for bar and rect.
We do not center other marks (e.g., point/line/area) in the middle of the timeUnit band by default for a few reasons:
Area will be ugly, leaving empty spaces on the side
Centering all marks so will cause breaking changes to all plots with timeUnit.
By only making timeUnit behave like bin for just bars and rects, we only change the behaviors for plots that currently look terrible.
Doing so will cause the plots with and without timeUnit look quite different.
For example, if there is a date field with only year information. Using no timeUnit and timeUnit=year will produce dramatically different results.
When needed, users can easily set the
band
or mark config'stimeUnitBand
to0.5
to center the data point in the middle of a time unit band. Seeline_month_center_band
for example.FWIW, Tableau also does NOT center the data point in the middle of a time unit band by default.
default alignment-- from an experiment the current one is already gooddistinguish between band's width and position
stack with impute case
document band
revise timeUnit docs
make band work for bar with temporal timeUnitwill do in Band should also work with bar with bin / timeUnit #5243Note that we don't include support for a field that has already been "prebinned" with a time unit transform. Let's handle that later in #5242.