Swift-Charts-Examples icon indicating copy to clipboard operation
Swift-Charts-Examples copied to clipboard

Add a scrolling graph

Open scsinke opened this issue 2 years ago • 10 comments

The Apple Health app contains a graph that you can scroll. I think this would also be a good use case to implement.

I have no clue where to start yet, but maybe we can figure something out.

https://user-images.githubusercontent.com/11280647/177356069-a2ed2eb7-3a82-41a9-a3af-7e3d4b172faa.MP4

scsinke avatar Jul 05 '22 14:07 scsinke

https://wwdclounges.com/wwdc22/swiftui-lounge.html#can-the-new-charts-api-allow-for-scrolling-similar-to-the-health-apps-charts

Seems like we need to file some feedback first! From the digital lounges:

Can the new Charts API allow for scrolling? similar to the health app's charts

|U03HL00QL68|: Sorry, late answer forgot to hit send: Yes, charts should behave just like any other view in this regard. though you may have to set explicit frames on the chart to specify how big (wide? tall?) you want it to be

|U03J7BQ7P9N|: We just couldn’t wait till the next Q&A, Ok I promise we are done now!!! :nerd_face:

|U03HL00QL68|: Hey <@U03J21CNQ1G> I just realized the health app chart does scrolling that keeps the y-axis stationary, that specifically isn't supported, but we've received a few requests about this, but few feedbacks. So if you file a feedback for the Charts team, we'd appreciate it

jordibruin avatar Jul 08 '22 06:07 jordibruin

@scsinke check out the latest PR by Stewart Lynch 🙂

jordibruin avatar Jul 13 '22 12:07 jordibruin

Sort of meets it but the headers get scrolled off, hopefully someone finds a way to allow the axis labels to be sticky when scrolling.

atrinh0 avatar Jul 15 '22 09:07 atrinh0

@jordibruin yeah it's a scrolling graph, but still not the same feel as the version used in the apple health app. Maybe we can make some improvement to this one to make is more resembling to the apple version.

scsinke avatar Jul 15 '22 21:07 scsinke

As I mentioned in my comment above, stationary axis labels aren't supported right now so I don't think we'll get much more than this. 😞

jordibruin avatar Jul 16 '22 19:07 jordibruin

As I mentioned in my comment above, stationary axis labels aren't supported right now so I don't think we'll get much more than this. 😞

Was curious about a smoke a mirrors type of workaround, e.g. HStack with around 30 pixels showing the axis (and clipping the rest of the chart) and a scroll view next to it containing a duplicate chart with axis labels disabled.

Horrible solution but it might give the illusion/effect we are trying to achieve.

Side effects:

  • Dynamic text support
  • Dynamic calculation of the width based on content/text, etc
  • Performance impact with a large dataset

atrinh0 avatar Jul 16 '22 19:07 atrinh0

As I mentioned in my comment above, stationary axis labels aren't supported right now so I don't think we'll get much more than this. 😞

Was curious about a smoke a mirrors type of workaround, e.g. HStack with around 30 pixels showing the axis (and clipping the rest of the chart) and a scroll view next to it containing a duplicate chart with axis labels disabled.

Horrible solution but it might give the illusion/effect we are trying to achieve.

Side effects:

  • Dynamic text support
  • Dynamic calculation of the width based on content/text, etc
  • Performance impact with a large dataset

Cool! let me try it out

jordibruin avatar Jul 21 '22 13:07 jordibruin

Very hacky but it's an approach we could explore more! @atrinh0

https://user-images.githubusercontent.com/170948/180226590-9d938a61-ce20-40ae-8813-311f5d2848de.mp4

jordibruin avatar Jul 21 '22 13:07 jordibruin

Here's a gist that looks pretty promising for emulating the Health apps scrollable charts: https://gist.github.com/beader/8779526f466e373a9085338742919d9b

MichaelBechHansen avatar Dec 06 '22 22:12 MichaelBechHansen

https://developer.apple.com/videos/play/wwdc2023/10037/?time=469

This is now possible with iOS 17

Screenshot 2023-07-15 at 10 38 46

atrinh0 avatar Jul 15 '23 09:07 atrinh0