Skip to content

Commit

Permalink
fix tooltip callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed Jun 19, 2024
1 parent d1c4401 commit de8ced3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw BarChart [v0.0.1]
// Tremor Raw BarChart [v0.1.0]

"use client"

Expand Down
6 changes: 6 additions & 0 deletions src/components/BarChart/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Tremor Raw BarChart Changelog

## 0.1.0

### Changes

- Feat: Add tooltipCallback prop

## 0.0.1

### Changes
Expand Down
19 changes: 18 additions & 1 deletion src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,29 @@ interface ChartTooltipProps {
label: string
categoryColors: Map<string, string>
valueFormatter: (value: number) => string
tooltipCallback?: TooltipCallback
}

type TooltipCallbackProps = Pick<
ChartTooltipProps,
"active" | "payload" | "label"
>

type TooltipCallback = (props: TooltipCallbackProps) => void

const ChartTooltip = ({
active,
payload,
label,
categoryColors,
valueFormatter,
tooltipCallback,
}: ChartTooltipProps) => {
React.useEffect(() => {
if (tooltipCallback) {
tooltipCallback({ active, payload, label })
}
}, [tooltipCallback, active, payload, label])
if (active && payload) {
const filteredPayload = payload.filter((item: any) => item.type !== "none")

Expand Down Expand Up @@ -507,6 +521,7 @@ interface LineChartProps extends React.HTMLAttributes<HTMLDivElement> {
xAxisLabel?: string
yAxisLabel?: string
legendPosition?: "left" | "center" | "right"
tooltipCallback?: TooltipCallback
}

const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>(
Expand Down Expand Up @@ -537,6 +552,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>(
xAxisLabel,
yAxisLabel,
legendPosition = "right",
tooltipCallback,
...other
} = props
const paddingValue = !showXAxis && !showYAxis ? 0 : 20
Expand Down Expand Up @@ -708,6 +724,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>(
label={label}
valueFormatter={valueFormatter}
categoryColors={categoryColors}
tooltipCallback={tooltipCallback}
/>
)
) : (
Expand Down Expand Up @@ -875,4 +892,4 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>(

LineChart.displayName = "LineChart"

export { LineChart, type LineChartEventProps }
export { LineChart, type LineChartEventProps, type TooltipCallbackProps }
9 changes: 8 additions & 1 deletion src/components/LineChart/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Tremor Raw LineChart Changelog

## 0.2.0

### Changes

- Feat: Add tooltipCallback prop
- Feat: Add fill prop

## 0.1.0

### Changes

Feat: Added legendPosition prop
- Feat: Added legendPosition prop
6 changes: 6 additions & 0 deletions src/components/LineChart/linechart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ export const WithOnValueChange: Story = {
},
}

export const WithTooltipCallback: Story = {
args: {
tooltipCallback: (props) => console.log(props),
},
}

export const WithLargeTickGap: Story = {
args: {
tickGap: 300,
Expand Down

0 comments on commit de8ced3

Please sign in to comment.