Skip to content

Commit

Permalink
Merge pull request #227 from bento-platform/chart-pointer
Browse files Browse the repository at this point in the history
Added onclick pointer to bar chart/histogram
  • Loading branch information
SanjeevLakhwani authored Nov 25, 2024
2 parents ec482e9 + 9d99ac8 commit 68bb886
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/js/components/Overview/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useTranslationFn } from '@/hooks';
import type { ChartData } from '@/types/data';
import type { ChartConfig } from '@/types/chartConfig';
import { CHART_TYPE_BAR, CHART_TYPE_CHOROPLETH, CHART_TYPE_HISTOGRAM, CHART_TYPE_PIE } from '@/types/chartConfig';
import { noop } from '@/utils/chart';

interface BarChartEvent {
activePayload: Array<{ payload: { x: string; id?: string } }>;
Expand Down Expand Up @@ -48,7 +49,12 @@ const Chart = memo(({ chartConfig, data, units, id, isClickable }: ChartProps) =
units={units}
preFilter={removeMissing}
dataMap={translateMap}
{...(isClickable ? { onChartClick: barChartOnChartClickHandler } : {})}
{...(isClickable
? {
onChartClick: barChartOnChartClickHandler,
onClick: noop,
}
: {})} // The noop is to provide the cursor: pointer style as onChartClick doesn't provide the behavior
/>
);
case CHART_TYPE_HISTOGRAM:
Expand All @@ -59,7 +65,12 @@ const Chart = memo(({ chartConfig, data, units, id, isClickable }: ChartProps) =
data={data}
preFilter={removeMissing}
dataMap={translateMap}
{...(isClickable ? { onChartClick: barChartOnChartClickHandler } : {})}
{...(isClickable
? {
onChartClick: barChartOnChartClickHandler,
onClick: noop,
}
: {})} // The noop is to provide the cursor: pointer style as onChartClick doesn't provide the behavior
/>
);
case CHART_TYPE_PIE:
Expand Down
2 changes: 2 additions & 0 deletions src/js/utils/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import type { ChartData } from '@/types/data';
export const serializeChartData = (chartData: Datum[]): ChartData[] => {
return chartData.map(({ label, value }) => ({ x: label, y: value }));
};

export const noop = () => {};

0 comments on commit 68bb886

Please sign in to comment.