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

Map - add forward backward step buttons to easy timeslider - add date pickers too (animation on the cheap) #775

Closed
bobular opened this issue Jan 17, 2024 · 14 comments · Fixed by #1095
Assignees
Labels
enhancement New feature or request map

Comments

@bobular
Copy link
Member

bobular commented Jan 17, 2024

As per title.

It's not trivial, however, because of the issue below. The Brush component will need to be controlled/controllable. If/when it's controllable, we can add date pickers (date inputs) in the expanded version of the component to allowed precise settting of the window.

After a lot of back and forth between controlled and uncontrolled behaviour of the visx Brush sub-component of the time-slider, we decided to leave it uncontroled. The main problem was with a drift/offset being introduced in the "round trip" between appState and component state as described in this comment:

// If we reenable the fake controlled behaviour of the <Brush> component using the key prop
// then we'll need to figure out why both brush handles drift every time you adjust one of them.
// The issue is something to do with the round-trip conversion of pixel/date/millisecond positions.
// A good place to start looking is here.

@bobular bobular added enhancement New feature or request map labels Jan 17, 2024
@bobular
Copy link
Member Author

bobular commented Feb 28, 2024

UPDATE: we can hopefully control the brush directly using the innerRef tricks mentioned here airbnb/visx#934 and in this sandbox: https://codesandbox.io/s/github/airbnb/visx/tree/master/packages/visx-demo/src/sandboxes/visx-brush?file=/Example.tsx:4287-4295

It's still a medium cost ticket but at least this part should be straightforward.

@bobular bobular changed the title Map - add forward backward step buttons to easy timeslider - add date pickers too. Map - add forward backward step buttons to easy timeslider - add date pickers too (animation on the cheap) Mar 20, 2024
@dmfalke
Copy link
Member

dmfalke commented Apr 10, 2024

Has this been discussed in a ux meeting? Just wondering what sort of consensus we have.

@moontrip
Copy link
Contributor

moontrip commented May 1, 2024

@bobular As a part of this ticket, I have extensively investigated the drift/offset issue. In summary, I found that somehow there exist additional 2 pixels in the first and last bounds: for whatever reason Brush results in adding (-2) pixel in the first bound and (+2) pixel in the last bound. This can be checked via x0 and x1 at onBrushChange function (

) when selecting full range: technically it should be [0, 700] pixels in the current timeSlider configuration (for full range) but it actually has the range of [-2, 702] pixels (more exactly [-1.999999999, 701.99999999]).

Thus, I think that we need to consider this inherent drift when changing range at onBrushChange. For example,
a) compute inherent domain value (drift) from range (pixel) using d3.invert() function, e.g., const drift = xBrushScale.invert(2)
b) in the onBrushChange(), compensate x0 and x1 (current domain values) with the above drift before calculating startDate/endDate, e.g., [x0+drift, x1-drift]

@bobular
Copy link
Member Author

bobular commented May 1, 2024

Hi @moontrip - did you see my comment above #775 (comment) ?

I think we can control the brush without fudge factors? It's a while since I looked at this though.

@moontrip
Copy link
Contributor

moontrip commented May 1, 2024

@bobular I didn't see that carefully now (but saw that before) as I just focused on the drift issue. I am not quite sure if that updateBrush works better than the current approach: I saw a developer's comment that it is not for fully controlled brush and it is not done yet. The updateBrush approach existed before when I used Reset button: Brush example code used it that way to reset range. Anyway I feel that we would still need to offset the drift either way because the Brush itself seems to have such an inherent drift.

@bobular
Copy link
Member Author

bobular commented May 1, 2024

Ah, I see.

I thought the drift arose from the round-trip of setting the brush position from our props, and then reading the brush position back from the visx component, or something. This would be avoided if the component was fully controlled. I'll have to look at it in more detail.

@moontrip
Copy link
Contributor

moontrip commented May 1, 2024

@bobular From my observation, it is not a kind of numerical error as I can see drift at initial condition: well the term drift may not be appropriate as it looks like Brush just adds additional 2 pixels at start and end (for Brush handle or bound edges? IDK).

@dmfalke
Copy link
Member

dmfalke commented May 1, 2024

Not sure if either of you have looked at this, but it could account for the offset: https://airbnb.io/visx/docs/brush#Brush_brushRegion. I'm not sure what value we're using, but might be worth playing with it.

@moontrip
Copy link
Contributor

moontrip commented May 1, 2024

Not sure if either of you have looked at this, but it could account for the offset: https://airbnb.io/visx/docs/brush#Brush_brushRegion. I'm not sure what value we're using, but might be worth playing with it.

It looks like the option is just to choose what will be filtered via Brush, e.g., chart, xAxis, or yAxis, not range: default value is chart. The Brush is originally intended to use Visx Chart together but we use it as a UI only.

@dmfalke
Copy link
Member

dmfalke commented May 1, 2024

This part of the description caught my eye:

[...] used for margin subtraction

@moontrip
Copy link
Contributor

moontrip commented May 1, 2024

This part of the description caught my eye:

[...] used for margin subtraction

@dmfalke Yeah it's indeed confusing 😅

@moontrip
Copy link
Contributor

moontrip commented May 7, 2024

@bobular I have tested to consider the inherent(?) offset of 2 pixels as I mentioned earlier. For the example of the Geolocation visualizations of field-based studies and time slider's variable of 'species collection start date', such a 2 pixel results in about 4 months, because the data ranges widely (from 1907 to 2024). I made a draft PR just in case: #1076

@bobular
Copy link
Member Author

bobular commented May 7, 2024

Hi @moontrip
I was reading through the Brush code today for #1075 and it's definitely inherent in the code...

https://github.com/airbnb/visx/blob/86a851cb3bf622b013b186f02f955bcd6548a87f/packages/visx-brush/src/Brush.tsx#L14

I've tested your PR but will comment over there. Thanks!

@bobular
Copy link
Member Author

bobular commented May 7, 2024

So - after #1076 there is probably no need to use the updateBrush approach via the innerRef. Yay 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request map
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants