coinjar / react-native-wagmi-charts

A sweet & simple chart library for React Native that will make us feel like We're All Gonna Make It.
MIT License
589 stars 116 forks source link

x scale proportional to time. #140

Closed renatomserra closed 1 year ago

renatomserra commented 1 year ago

Hellow,

Is there any way to make the distance between two points respect the scale of time between them? Right now points are evenly split across the x axis in the graph

cam-shaw commented 1 year ago

@RenatoSerra22 On line chart yes this is possible by setting the xDomain prop on the LineChart.Provider. For the xDomain value, provide an array with 2 numbers, the lowest timestamp and highest timestamp in your data.

Let's say I had this data

const dataToShow = [
  { timestamp: 1661904060, value: 1 },
  { timestamp: 1661925060, value: 1.3 },
  { timestamp: 1661926260, value: 2 },
];

and we put it into our provider...

<LineChart.Provider
// other props
data={dataToShow}
 xDomain={[dataToShow[0], dataToShow[dataToShow.length -1]}>
// rest of code
</LineChart.Provider>

It will give you the desired result.

Here is an example (not with the above data) of the difference supplying an xDomain makes.

No xDomain IMG_0446 Has xDomain IMG_0447

renatomserra commented 1 year ago

beautifuuuuuuul thanks so much @cam-shaw !

rodrigof1307 commented 1 year ago

I was about to post this exact same question. This prop of the provider should be on the Component APIs section of the docs

cam-shaw commented 1 year ago

I was about to post this exact same question. This prop of the provider should be on the Component APIs section of the docs

You're 100% correct, and this is my bad. When I added the feature in a PR I forgot to update the docs with it. I'll take a look during the week at adding some documentation.

renatomserra commented 1 year ago

@cam-shaw the gradient doesnt seem to respect the domain tho :)

Screenshot 2023-07-04 at 13 18 56
cam-shaw commented 1 year ago

Iiinteresting... Had a look and I think I know how to solve the gradient issue.. Looks fairly simple to resolve, the gradient just needs to also respect the xDomain if provided. No promises yet but give me some time and I'll try this week to have a play and I'll get something up for the maintainers to review.

ChaseK30 commented 1 year ago

@cam-shaw For some reason I am getting a malformed path data error when putting the xDomain the same as the example that you gave, not sure what I am doing wrong

ChaseK30 commented 1 year ago

Nevermind I figured it out, the timestamps were formatted differently then the data that was being shown, I did find a weird reaction when putting the xdomain, the dot seems to be hanging off the screen Simulator Screen Shot - Iphone 14 pro 16 2 - 2023-07-05 at 15 18 54

cam-shaw commented 1 year ago

@ChaseK30 If you're able to, would be great if you can give this PR a test. I have fixed up the x position for the dot - would be great to know if it resolves your issues.

https://github.com/coinjar/react-native-wagmi-charts/pull/144

Let me know if you have any issues integrating it into your project.

  1. Clone the PR
  2. Change package.json of PR version to 2.3.0-local.0 to avoid any package conflicts
  3. yarn prepare && yarn pack - This will output a path to the terminal similar to success Wrote tarball to "/Users/.../react-native-wagmi-charts-v2.3.0-local.0.tgz
  4. In your personal project, run yarn install pathToTarball
ChaseK30 commented 1 year ago

checking now!

ChaseK30 commented 1 year ago

@cam-shaw there are no build commands

cam-shaw commented 1 year ago

@ChaseK30 sorry, yarn prepare instead of yarn build. Have updated my comment above.

ChaseK30 commented 1 year ago

Sorry for the delay running into a ton of dependency issues

cam-shaw commented 1 year ago

@ChaseK30 no worries at all. Could be good to document on the PR if the dependency issues are specific to the PR. I'd imagine the maintainers could throw that into the release notes.

Perhaps we can move this conversation there.

ChaseK30 commented 1 year ago

Screenshot 2023-07-05 at 6 22 17 PM

Gettin a ton of these errors trying to run it at all

cam-shaw commented 1 year ago

@ChaseK30 those are unfortunately/fortunately (depending on how you look at it 😅 ) unrelated to the PR. Double check your @react/types and react native types are correct for the React version you're using.

Perhaps even go as far as deleting the node_modules directory and installing dependencies again. Bit hard to debug from here unfortunately.

Were you already on react-native-wagmi-charts 2.3.0?

ChaseK30 commented 1 year ago

in my personal project yes, but i am getting all these errors running a yarn install && yarn prepare && yarn pack before getting it into my personal project @cam-shaw

renatomserra commented 1 year ago

just saw the PR thank you @cam-shaw for being so quick with it!

renatomserra commented 1 year ago

Found another issue :D when dragging over the line, the labels dont show the correct timestamp/value

cam-shaw commented 1 year ago

@RenatoSerra22 are you able to provide some sample data for me to test with? I believe I have fixed this in the PR as well.