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

Updates to bindings for XYZ axes, Treemap, Pie, and Cell components #59

Merged
merged 9 commits into from
Dec 2, 2024

Conversation

johnhaley81
Copy link
Contributor

This does include 2 breaking changes:

  • XYZ Axes' tickSize is now a float instead of an int since ticks do not have to be whole numbers
  • In Pie the first arg which is the data that is coming into the event is nullable

I thought I'd group these breaking changes together so that a single release could be cut but I can split things apart if needed.

Summary of changes:

  • fix curried functions in event handlers for XAxis, YAxis, and ZAxis
  • change dataKey type from string to 'dataKey in XAxis, YAxis, and ZAxis
  • change tickSize type from int to float in XAxis, YAxis, and ZAxis
  • add transform and stroke props to XAxis, YAxis, and ZAxis
  • add style prop to ZAxis
  • add fillOpacity prop to Cell
  • add optional flags to Treemap props stroke, fill, isAnimationActive, animationDuration
  • wrap Pie event handlers data prop in Js.Nullable.t

@johnhaley81 johnhaley81 marked this pull request as draft November 26, 2024 00:44
@johnhaley81
Copy link
Contributor Author

Before I intro some breaking changes, I want to ensure that they are the best possible changes I can so I'm making this a draft as I iterate some more on these.

Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me.

) =>
makeProps(
~interval=?interval |> AxisInterval.encodeOpt,
~onClick=?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds some extra runtime (example). But I guess we're fine with it? cc @davesnx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already had the runtime on it with interval |> AxisInterval.encodeOpt here so I figured it was ok but I can rip these out.

I included them mostly to help upgrading since you'd have to rewrite all of the functions to be uncurried otherwise but since these have breaking changes in them anyways maybe that's ok?

src/ZAxis.re Outdated
@@ -10,7 +10,7 @@ external make:
~allowDuplicatedCategory: bool=?,
~axisLine: 'axisLine=?,
~className: string=?,
~dataKey: string=?,
~dataKey: 'dataKey=?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other types can be dataKey? Is it really anything? Is it worth documenting + including a link to official docs if they exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I put this back into draft actually.

I've been hitting a lot of bindings here that are marked as anything but they really aren't so I've been replacing them with [@mel.unwrap] versions in my local copy and I'll update this PR when I have that in a good spot and confirmed they are all indeed working as intended.

@johnhaley81 johnhaley81 marked this pull request as ready for review November 27, 2024 23:42
@johnhaley81
Copy link
Contributor Author

@jchavarri I updated the PR with more correct bindings for the XYZ axes.

Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tried to check some bindings against the official docs but they just say Function so 🤷

CHANGES.md Outdated
Comment on lines 3 to 17
- change `axisLine` type from `any` to `[ | `Bool(bool) | `Obj(Js.t({..}))]` in `XAxis`, `YAxis`, and `ZAxis`
- change `dataKey` type from `string` to `[ | `Str(string) | `Int(int) | `Fn('dataObj => 'dataKey)]` in `XAxis`, `YAxis`, and `ZAxis`
- change `label` type from `any` to `[ | `Str(string) | `Int(int) | `Float(float) | `Component(React.element) | `Obj(Js.t({..}))]` in `XAxis`, `YAxis`, and `ZAxis`
- change `name` type from `string` to `[ | `Str(string) | `Int(int) | `Float(float)]` in `XAxis`, `YAxis`, and `ZAxis`
- add `range` prop to `XAxis` and `YAxis`
- change `tick` type from `any` to `[ | `Obj(Js.t({..})) | `Component(React.element) | `Bool(bool) | `Fn('tick => React.element)]` in `XAxis`, `YAxis`, and `ZAxis`
- change `tickFormatter` type from `any` to `(. 'tick, int) => string` in `XAxis`, `YAxis`, and `ZAxis` and wrap it with a curried function
- change `tickLine` type from `any` to `[ | `Bool(bool) | `Obj(Js.t({..}))]` in `XAxis`, `YAxis`, and `ZAxis`
- change `tickSize` type from `float` to `[ | `Float(float) | `Int(int)]` in `XAxis`, `YAxis`, and `ZAxis`
- fix curried functions in event handlers for `XAxis`, `YAxis`, and `ZAxis`
- add `transform` and `stroke` props to `XAxis`, `YAxis`, and `ZAxis`
- add `style` prop to `ZAxis`
- add `fillOpacity` prop to `Cell`
- add optional flags to `Treemap` props `stroke`, `fill`, `isAnimationActive`, `animationDuration`
- wrap `Pie` event handlers data prop in `Js.Nullable.t`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add something along the lines of the PR description in one line ("Improve bindings for XYZ axes, Treemap, Pie and Cell components"), with a link to the PR for those interested on details.

I would also add "Breaking" before it.

example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +12 to +14
[@mel.unwrap] [
| `Bool(bool)
| `Obj(Js.t({..}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

~unit: string=?,
~width: int=?,
~yAxisId: string=?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://recharts.org/en-US/api/ZAxis#zAxisId

It might have been a typo before but should be correct now

src/YAxis.re Outdated
| `Str(string)
| `Int(int)
| `Float(float)
| `Component(React.element)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this Element. (A component is what creates elements, aka the make function). Same for other usages in other modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... I remember now that I named it that to be consistent with this. I feel like I should also update this as well.

~domain: array('domain)=?,
~height: int=?,
~hide: bool=?,
~interval: AxisInterval.t=?,
~label: 'label=?,
~label:
[@mel.unwrap] [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe replace some of those types in Utils with mel.unwrap too?

https://github.com/ahrefs/melange-recharts/blob/master/src/Utils.re#L135

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to tackle this in another PR but I think this is a great suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR open: #60

@johnhaley81
Copy link
Contributor Author

Nice! I tried to check some bindings against the official docs but they just say Function so 🤷

Yeah I had to do a lot of diving into the repo and runtime testing to figure these out 🫠

@johnhaley81
Copy link
Contributor Author

@jchavarri I left this marked as Unpublished in the CHANGES file since @liubko also raised a good point about making the types in Utils use [@mel.unwrap] as well and I think that having back-to-back breaking releases is not ideal.

@johnhaley81 johnhaley81 merged commit 46db576 into ahrefs:master Dec 2, 2024
2 checks passed
@johnhaley81 johnhaley81 deleted the update-bindings-2 branch December 2, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants