Skip to content

Commit

Permalink
Support customTooltip on AreaChart,BarChart and LineChart (#195)
Browse files Browse the repository at this point in the history
* fix: Support customTooltip on AreaChart,BarChart and LineChart

Signed-off-by: lannyfu <lannyfu@kubesphere.io>

* add changeset

Signed-off-by: lannyfu <lannyfu@kubesphere.io>

* update changeset

Signed-off-by: lannyfu <lannyfu@kubesphere.io>

---------

Signed-off-by: lannyfu <lannyfu@kubesphere.io>
  • Loading branch information
fuchunlan authored Feb 27, 2024
1 parent e8157b9 commit 041561e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-carrots-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kubed/charts': patch
---

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

0 comments on commit 041561e

Please sign in to comment.