-
Notifications
You must be signed in to change notification settings - Fork 795
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
Clarify usage of initial values in selection intervals with dates #3643
Comments
Thanks for raising this @dsmedia
I agree with your assessment that this lacks documentation, I certainly didn't know this was possible! However, I must say I really dislike the solution provided on stackoverflow Given that was written over 4 years ago, I'd be more interested in either:
Confirmed solutionsThese are all the solutions I can confirm work so far: Code block
from datetime import date, datetime
import altair as alt
import pandas as pd
import polars as pl
from vega_datasets import data
source = data.sp500.url
# Define an initial date range as timestamps
window_pd = pd.to_datetime(["2005-01-01", "2009-01-01"]).astype(int) / 1e6
window_pl = pl.Series([date(2005, 1, 1), date(2009, 1, 1)]).dt.timestamp("ms")
window_stdlib = (
datetime(2005, 1, 1).timestamp() * 1e3,
datetime(2009, 1, 1).timestamp() * 1e3,
)
window_alt = alt.DateTime(year=2005), alt.DateTime(year=2009)
# Create a brush (interval) selection with initial range
brush = alt.selection_interval(encodings=["x"], value={"x": window_pd})
brush = alt.selection_interval(encodings=["x"], value={"x": window_pl})
brush = alt.selection_interval(encodings=["x"], value={"x": window_stdlib})
brush = alt.selection_interval(encodings=["x"], value={"x": window_alt})
base = (
alt.Chart(source, width=600, height=200).mark_area().encode(x="date:T", y="price:Q")
)
upper = base.encode(alt.X("date:T").scale(domain=brush))
lower = base.properties(height=60).add_params(brush)
chart = upper & lower
chart Since this is both the shortest, and doesn't introduce a dependency - I would lean towards it personally: window_alt = alt.DateTime(year=2005), alt.DateTime(year=2009)
I think it would make this functionality more discoverable if it were a separate example, with a more specific title like:
Or include some other time-series terminology, if that can provide a more accurate description? Would be similar to this pair of examples:
AFAIK, the description there is copy/pasted from the generated docs - which traces back via these two:
Probably a good idea, also maybe a mention in times_and_dates
I want to say no, simply because we can't do this for every datetime type across all libraries. It seems to me that it wants a POSIX timestamp with |
What is your suggestion?
When setting initial values for a selection interval based on date values, users must manually convert dates to timestamps, as discussed here. This requirement does not appear to be clearly documented or exemplified in this repository. Solutions could be one or more of the following:
Potential Solutions
Questions:
Sample diff for current example gallery item
Have you considered any alternative solutions?
I've proposed three possible solutions above.
The text was updated successfully, but these errors were encountered: