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

Support customTooltip on AreaChart,BarChart and LineChart #195

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-rats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kubed/charts': major
donniean marked this conversation as resolved.
Show resolved Hide resolved
---

Support customTooltip on Some charts
2 changes: 2 additions & 0 deletions packages/charts/src/charts/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const AreaChart = ({
minValue,
maxValue,
colors,
customTooltip,
legendVerticalAlign = 'top',
legendAlign = 'right',
legendFormatter,
Expand Down Expand Up @@ -131,6 +132,7 @@ export const AreaChart = ({
<Tooltip
wrapperStyle={{ outline: 'none' }}
content={({ active, payload, label }) => (
customTooltip && customTooltip(payload)) || (
<TooltipContent
active={active}
payload={payload}
Expand Down
4 changes: 3 additions & 1 deletion packages/charts/src/charts/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const BarChart = ({
minValue,
maxValue,
colors,
customTooltip,
legendVerticalAlign = 'top',
legendAlign = 'right',
legendFormatter,
Expand Down Expand Up @@ -174,7 +175,8 @@ export const BarChart = ({
{showTooltip ? (
<Tooltip
wrapperStyle={{ outline: 'none' }}
content={({ active, payload, label }) => (
content={({ active, payload, label }) => (
customTooltip && customTooltip(payload)) || (
<TooltipContent
active={active}
payload={payload}
Expand Down
21 changes: 12 additions & 9 deletions packages/charts/src/charts/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const LineChart = ({
minValue,
maxValue,
colors,
customTooltip,
legendVerticalAlign = 'top',
legendAlign = 'right',
legendFormatter,
Expand Down Expand Up @@ -118,15 +119,17 @@ export const LineChart = ({
{showTooltip ? (
<Tooltip
wrapperStyle={{ outline: 'none' }}
content={({ active, payload, label }) => (
<TooltipContent
active={active}
payload={payload}
label={label}
valueFormatter={valueFormatter}
legendFormatter={legendFormatter}
/>
)}
content={({ active, payload, label }) =>
(customTooltip && customTooltip(payload)) || (
<TooltipContent
active={active}
payload={payload}
label={label}
valueFormatter={valueFormatter}
legendFormatter={legendFormatter}
/>
)
}
/>
) : null}
{categories.map((category) => (
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ChartBaseProps extends CategoricalChartProps {
legendAlign?: 'left' | 'center' | 'right';
legendFormatter?: LegendFormatter;
maxActiveCategories?: number;
customTooltip?: (payload: any[]) => React.ReactNode;
}

export type ValueFormatter = {
Expand Down