diff --git a/CHANGES.md b/CHANGES.md index 5025821..09c2825 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +## Unpublished + +- *[breaking]* improve bindings for XYZ axes, Treemap, Pie and Cell components [#59](https://github.com/ahrefs/melange-recharts/pull/59) + ## 4.0.7 (2024-11-23) - add `payload` to `Pie` and `Bar` event handler diff --git a/src/Cell.re b/src/Cell.re index 44da70d..6b88fb2 100644 --- a/src/Cell.re +++ b/src/Cell.re @@ -2,6 +2,13 @@ [@mel.module "recharts"] [@react.component] external make: - (~background: 'background=?, ~className: string=?, ~fill: string=?, ~stroke: string=?, ~strokeWidth: int=?) => + ( + ~background: 'background=?, + ~className: string=?, + ~fill: string=?, + ~fillOpacity: float=?, + ~stroke: string=?, + ~strokeWidth: int=? + ) => React.element = "Cell"; diff --git a/src/Pie.re b/src/Pie.re index b5d97b2..5dfa0ef 100644 --- a/src/Pie.re +++ b/src/Pie.re @@ -35,39 +35,52 @@ external make: // Pulled from: // https://github.com/recharts/recharts/blob/7fb227dae542c3d3093506e6d80a2c2c366f9a26/src/polar/Pie.tsx#L107-L109 ~onClick: + (Js.Nullable.t({.. "payload": 'dataItem}), int, React.Event.Mouse.t) => + unit + =?, + ~onMouseEnter: + (Js.Nullable.t({.. "payload": 'dataItem}), int, React.Event.Mouse.t) => + unit + =?, + ~onMouseLeave: + (Js.Nullable.t({.. "payload": 'dataItem}), int, React.Event.Mouse.t) => + unit + =?, + ~onMouseDown: ( Js.Nullable.t(Js.t({.. "payload": 'dataItem})), - int, React.Event.Mouse.t ) => unit =?, - ~onMouseDown: - (Js.t({.. "payload": 'dataItem}), React.Event.Mouse.t) => unit=?, - ~onMouseEnter: + ~onMouseMove: ( Js.Nullable.t(Js.t({.. "payload": 'dataItem})), - int, React.Event.Mouse.t ) => unit =?, - ~onMouseLeave: + ~onMouseOut: ( Js.Nullable.t(Js.t({.. "payload": 'dataItem})), - int, React.Event.Mouse.t ) => unit =?, - ~onMouseMove: - (Js.t({.. "payload": 'dataItem}), React.Event.Mouse.t) => unit=?, - ~onMouseOut: - (Js.t({.. "payload": 'dataItem}), React.Event.Mouse.t) => unit=?, ~onMouseOver: - (Js.t({.. "payload": 'dataItem}), React.Event.Mouse.t) => unit=?, + ( + Js.Nullable.t(Js.t({.. "payload": 'dataItem})), + React.Event.Mouse.t + ) => + unit + =?, ~onMouseUp: - (Js.t({.. "payload": 'dataItem}), React.Event.Mouse.t) => unit=?, + ( + Js.Nullable.t(Js.t({.. "payload": 'dataItem})), + React.Event.Mouse.t + ) => + unit + =?, ~outerRadius: PxOrPrc.t=?, ~paddingAngle: int=?, ~startAngle: int=?, diff --git a/src/Treemap.re b/src/Treemap.re index 9b66211..a2e2154 100644 --- a/src/Treemap.re +++ b/src/Treemap.re @@ -6,12 +6,12 @@ external make: ~data: array('dataItem), ~dataKey: string, ~aspectRatio: float=?, - ~stroke: string, - ~fill: string, + ~stroke: string=?, + ~fill: string=?, ~className: string=?, ~height: int=?, - ~isAnimationActive: bool, - ~animationDuration: int, + ~isAnimationActive: bool=?, + ~animationDuration: int=?, ~syncId: string=?, ~width: int=?, ~content: 'contentProps => React.element=?, diff --git a/src/XAxis.re b/src/XAxis.re index 1366af5..884e9ce 100644 --- a/src/XAxis.re +++ b/src/XAxis.re @@ -8,26 +8,55 @@ external make: ~allowDataOverflow: bool=?, ~allowDecimals: bool=?, ~allowDuplicatedCategory: bool=?, - ~axisLine: 'axisLine=?, + ~axisLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~className: string=?, - ~dataKey: string=?, + ~dataKey: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Fn('dataObj => 'data) + ] + =?, ~domain: array('domain)=?, ~height: int=?, ~hide: bool=?, ~interval: AxisInterval.t=?, - ~label: 'label=?, + ~label: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + | `Element(React.element) + | `Obj(Js.t({..})) + ] + =?, ~minTickGap: int=?, ~mirror: bool=?, - ~name: string=?, - ~onClick: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseDown: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~name: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + ] + =?, + ~onClick: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseDown: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~onMouseEnter: - (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseLeave: (Js.t({..}), React.Event.Mouse.t) => unit=?, - ~onMouseMove: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOut: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOver: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseUp: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseLeave: (. Js.t({..}), React.Event.Mouse.t) => unit=?, + ~onMouseMove: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOut: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOver: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseUp: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~orientation: [ | `bottom @@ -35,16 +64,36 @@ external make: ] =?, ~padding: paddingHorizontal=?, + ~range: array(int)=?, ~reversed: bool=?, ~scale: scale=?, + ~stroke: string=?, ~style: ReactDOM.Style.t=?, - ~tick: 'tick=?, + ~tick: + [@mel.unwrap] [ + | `Obj(Js.t({..})) + | `Element(React.element) + | `Bool(bool) + | `Fn('tick => React.element) + ] + =?, ~tickCount: int=?, - ~tickFormatter: 'tickFormatter=?, - ~tickLine: 'tickLine=?, + ~tickFormatter: (. 'tick, int) => string=?, + ~tickLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~tickMargin: int=?, ~ticks: array('ticks)=?, - ~tickSize: int=?, + ~tickSize: + [@mel.unwrap] [ + | `Float(float) + | `Int(int) + ] + =?, + ~transform: string=?, ~unit: string=?, ~width: int=?, ~xAxisId: string=? @@ -52,5 +101,62 @@ external make: React.element = "XAxis"; -let makeProps = (~interval=?) => - makeProps(~interval=?interval->AxisInterval.encodeOpt); +let makeProps = + ( + ~interval=?, + ~onClick=?, + ~onMouseDown=?, + ~onMouseEnter=?, + ~onMouseLeave=?, + ~onMouseMove=?, + ~onMouseOut=?, + ~onMouseOver=?, + ~onMouseUp=?, + ~tickFormatter=?, + ) => + makeProps( + ~interval=?interval |> AxisInterval.encodeOpt, + ~onClick=? + onClick + |> Option.map(onClick => (. payload, event) => onClick(payload, event)), + ~onMouseDown=? + onMouseDown + |> Option.map(onMouseDown => + (. payload, event) => onMouseDown(payload, event) + ), + ~onMouseEnter=? + onMouseEnter + |> Option.map(onMouseEnter => + (. payload, event) => onMouseEnter(payload, event) + ), + ~onMouseLeave=? + onMouseLeave + |> Option.map(onMouseLeave => + (. payload, event) => onMouseLeave(payload, event) + ), + ~onMouseMove=? + onMouseMove + |> Option.map(onMouseMove => + (. payload, event) => onMouseMove(payload, event) + ), + ~onMouseOut=? + onMouseOut + |> Option.map(onMouseOut => + (. payload, event) => onMouseOut(payload, event) + ), + ~onMouseOver=? + onMouseOver + |> Option.map(onMouseOver => + (. payload, event) => onMouseOver(payload, event) + ), + ~onMouseUp=? + onMouseUp + |> Option.map(onMouseUp => + (. payload, event) => onMouseUp(payload, event) + ), + ~tickFormatter=? + tickFormatter + |> Option.map(tickFormatter => + (. tick, index) => tickFormatter(tick, index) + ), + ); diff --git a/src/YAxis.re b/src/YAxis.re index bb158bf..ae0a94f 100644 --- a/src/YAxis.re +++ b/src/YAxis.re @@ -8,26 +8,55 @@ external make: ~allowDataOverflow: bool=?, ~allowDecimals: bool=?, ~allowDuplicatedCategory: bool=?, - ~axisLine: 'axisLine=?, + ~axisLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~className: string=?, - ~dataKey: string=?, + ~dataKey: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Fn('dataObj => 'data) + ] + =?, ~domain: array('domain)=?, ~height: int=?, ~hide: bool=?, ~interval: AxisInterval.t=?, - ~label: 'label=?, + ~label: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + | `Element(React.element) + | `Obj(Js.t({..})) + ] + =?, ~minTickGap: int=?, ~mirror: bool=?, - ~name: string=?, - ~onClick: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseDown: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~name: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + ] + =?, + ~onClick: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseDown: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~onMouseEnter: - (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseLeave: (Js.t({..}), React.Event.Mouse.t) => unit=?, - ~onMouseMove: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOut: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOver: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseUp: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseLeave: (. Js.t({..}), React.Event.Mouse.t) => unit=?, + ~onMouseMove: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOut: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOver: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseUp: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~orientation: [ | `left @@ -35,16 +64,36 @@ external make: ] =?, ~padding: paddingVertical=?, + ~range: array(int)=?, ~reversed: bool=?, ~scale: scale=?, + ~stroke: string=?, ~style: ReactDOM.Style.t=?, - ~tick: 'tick=?, + ~tick: + [@mel.unwrap] [ + | `Obj(Js.t({..})) + | `Element(React.element) + | `Bool(bool) + | `Fn('tick => React.element) + ] + =?, ~tickCount: int=?, - ~tickFormatter: 'tickFormatter=?, - ~tickLine: 'tickLine=?, + ~tickFormatter: (. 'tick, int) => string=?, + ~tickLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~tickMargin: int=?, ~ticks: array('ticks)=?, - ~tickSize: int=?, + ~tickSize: + [@mel.unwrap] [ + | `Float(float) + | `Int(int) + ] + =?, + ~transform: string=?, ~unit: string=?, ~width: int=?, ~yAxisId: string=? @@ -52,5 +101,62 @@ external make: React.element = "YAxis"; -let makeProps = (~interval=?) => - makeProps(~interval=?interval->AxisInterval.encodeOpt); +let makeProps = + ( + ~interval=?, + ~onClick=?, + ~onMouseDown=?, + ~onMouseEnter=?, + ~onMouseLeave=?, + ~onMouseMove=?, + ~onMouseOut=?, + ~onMouseOver=?, + ~onMouseUp=?, + ~tickFormatter=?, + ) => + makeProps( + ~interval=?interval |> AxisInterval.encodeOpt, + ~onClick=? + onClick + |> Option.map(onClick => (. payload, event) => onClick(payload, event)), + ~onMouseDown=? + onMouseDown + |> Option.map(onMouseDown => + (. payload, event) => onMouseDown(payload, event) + ), + ~onMouseEnter=? + onMouseEnter + |> Option.map(onMouseEnter => + (. payload, event) => onMouseEnter(payload, event) + ), + ~onMouseLeave=? + onMouseLeave + |> Option.map(onMouseLeave => + (. payload, event) => onMouseLeave(payload, event) + ), + ~onMouseMove=? + onMouseMove + |> Option.map(onMouseMove => + (. payload, event) => onMouseMove(payload, event) + ), + ~onMouseOut=? + onMouseOut + |> Option.map(onMouseOut => + (. payload, event) => onMouseOut(payload, event) + ), + ~onMouseOver=? + onMouseOver + |> Option.map(onMouseOver => + (. payload, event) => onMouseOver(payload, event) + ), + ~onMouseUp=? + onMouseUp + |> Option.map(onMouseUp => + (. payload, event) => onMouseUp(payload, event) + ), + ~tickFormatter=? + tickFormatter + |> Option.map(tickFormatter => + (. tick, index) => tickFormatter(tick, index) + ), + ); diff --git a/src/ZAxis.re b/src/ZAxis.re index 9c61d5e..cf0b64b 100644 --- a/src/ZAxis.re +++ b/src/ZAxis.re @@ -8,27 +8,55 @@ external make: ~allowDataOverflow: bool=?, ~allowDecimals: bool=?, ~allowDuplicatedCategory: bool=?, - ~axisLine: 'axisLine=?, + ~axisLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~className: string=?, - ~dataKey: string=?, + ~dataKey: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Fn('dataObj => 'tick) + ] + =?, ~domain: array('domain)=?, ~height: int=?, ~hide: bool=?, ~interval: AxisInterval.t=?, - ~label: 'label=?, + ~label: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + | `Element(React.element) + | `Obj(Js.t({..})) + ] + =?, ~minTickGap: int=?, ~mirror: bool=?, - ~name: string=?, - ~range: array(int)=?, - ~onClick: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseDown: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~name: + [@mel.unwrap] [ + | `Str(string) + | `Int(int) + | `Float(float) + ] + =?, + ~onClick: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseDown: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~onMouseEnter: - (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseLeave: (Js.t({..}), React.Event.Mouse.t) => unit=?, - ~onMouseMove: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOut: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseOver: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, - ~onMouseUp: (Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseLeave: (. Js.t({..}), React.Event.Mouse.t) => unit=?, + ~onMouseMove: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOut: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseOver: + (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, + ~onMouseUp: (. Js.Nullable.t(Js.t({..})), React.Event.Mouse.t) => unit=?, ~orientation: [ | `left @@ -36,21 +64,99 @@ external make: ] =?, ~padding: paddingVertical=?, + ~range: array(int)=?, ~reversed: bool=?, ~scale: scale=?, - ~tick: 'tick=?, + ~stroke: string=?, + ~style: ReactDOM.Style.t=?, + ~tick: + [@mel.unwrap] [ + | `Obj(Js.t({..})) + | `Element(React.element) + | `Bool(bool) + | `Fn('tick => React.element) + ] + =?, ~tickCount: int=?, - ~tickFormatter: 'tickFormatter=?, - ~tickLine: 'tickLine=?, + ~tickFormatter: (. 'tick, int) => string=?, + ~tickLine: + [@mel.unwrap] [ + | `Bool(bool) + | `Obj(Js.t({..})) + ] + =?, ~tickMargin: int=?, ~ticks: array('ticks)=?, - ~tickSize: int=?, + ~tickSize: + [@mel.unwrap] [ + | `Float(float) + | `Int(int) + ] + =?, + ~transform: string=?, ~unit: string=?, ~width: int=?, - ~yAxisId: string=? + ~zAxisId: string=? ) => React.element = "ZAxis"; -let makeProps = (~interval=?) => - makeProps(~interval=?interval->AxisInterval.encodeOpt); +let makeProps = + ( + ~interval=?, + ~onClick=?, + ~onMouseDown=?, + ~onMouseEnter=?, + ~onMouseLeave=?, + ~onMouseMove=?, + ~onMouseOut=?, + ~onMouseOver=?, + ~onMouseUp=?, + ~tickFormatter=?, + ) => + makeProps( + ~interval=?interval |> AxisInterval.encodeOpt, + ~onClick=? + onClick + |> Option.map(onClick => (. payload, event) => onClick(payload, event)), + ~onMouseDown=? + onMouseDown + |> Option.map(onMouseDown => + (. payload, event) => onMouseDown(payload, event) + ), + ~onMouseEnter=? + onMouseEnter + |> Option.map(onMouseEnter => + (. payload, event) => onMouseEnter(payload, event) + ), + ~onMouseLeave=? + onMouseLeave + |> Option.map(onMouseLeave => + (. payload, event) => onMouseLeave(payload, event) + ), + ~onMouseMove=? + onMouseMove + |> Option.map(onMouseMove => + (. payload, event) => onMouseMove(payload, event) + ), + ~onMouseOut=? + onMouseOut + |> Option.map(onMouseOut => + (. payload, event) => onMouseOut(payload, event) + ), + ~onMouseOver=? + onMouseOver + |> Option.map(onMouseOver => + (. payload, event) => onMouseOver(payload, event) + ), + ~onMouseUp=? + onMouseUp + |> Option.map(onMouseUp => + (. payload, event) => onMouseUp(payload, event) + ), + ~tickFormatter=? + tickFormatter + |> Option.map(tickFormatter => + (. tick, index) => tickFormatter(tick, index) + ), + );