Skip to content

The open alternative to Salesforce, designed for AI.

[Dashboards] - refactor - line chart (#14507)

nitin24b7075f60c0
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetChartContainer.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetChartContainer.tsx
new file mode 100644
index 00000000000..749fa44f251
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetChartContainer.tsx
@@ -0,0 +1,23 @@
+import styled from '@emotion/styled';
+
+type GraphWidgetChartContainerProps = {
+ $isClickable?: boolean;
+ $cursorSelector?: string;
+};
+
+const StyledGraphWidgetChartContainer = styled.div<GraphWidgetChartContainerProps>`
+ flex: 1;
+ position: relative;
+ width: 100%;
+
+ ${({ $isClickable, $cursorSelector }) =>
+ $isClickable &&
+ $cursorSelector &&
+ `
+ ${$cursorSelector} {
+ cursor: pointer;
+ }
+ `}
+`;
+
+export const GraphWidgetChartContainer = StyledGraphWidgetChartContainer;
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetGaugeChart.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetGaugeChart.tsx
index ca70bac2e1c..1c65dabd163 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetGaugeChart.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetGaugeChart.tsx
@@ -15,6 +15,7 @@ import {
formatGraphValue,
type GraphValueFormatOptions,
} from '../utils/graphFormatters';
+import { GraphWidgetChartContainer } from './GraphWidgetChartContainer';
import { GraphWidgetLegend } from './GraphWidgetLegend';
import { GraphWidgetTooltip } from './GraphWidgetTooltip';
@@ -43,20 +44,6 @@ const StyledContainer = styled.div`
width: 100%;
`;
-const StyledChartContainer = styled.div<{ $isClickable?: boolean }>`
- flex: 1;
- position: relative;
- width: 100%;
-
- ${({ $isClickable }) =>
- $isClickable &&
- `
- svg g path[fill^="url(#"] {
- cursor: pointer;
- }
- `}
-`;
-
const StyledH1Title = styled(H1Title)`
left: 50%;
position: absolute;
@@ -177,7 +164,10 @@ export const GraphWidgetGaugeChart = ({
return (
<StyledContainer>
- <StyledChartContainer $isClickable={isDefined(to)}>
+ <GraphWidgetChartContainer
+ $isClickable={isDefined(to)}
+ $cursorSelector='svg g path[fill^="url(#"]'
+ >
<ResponsiveRadialBar
data={chartData}
startAngle={-90}
@@ -209,7 +199,7 @@ export const GraphWidgetGaugeChart = ({
fontColor={H1TitleFontColor.Primary}
/>
)}
- </StyledChartContainer>
+ </GraphWidgetChartContainer>
<GraphWidgetLegend
show={showLegend}
items={[
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetLineChart.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetLineChart.tsx
deleted file mode 100644
index 1852f8f74ce..00000000000
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetLineChart.tsx
+++ /dev/null
@@ -1,380 +0,0 @@
-import styled from '@emotion/styled';
-import {
- ResponsiveLine,
- type LineSeries,
- type Point,
- type SliceTooltipProps,
-} from '@nivo/line';
-import { type ScaleLinearSpec, type ScaleSpec } from '@nivo/scales';
-import { useId, useMemo } from 'react';
-import { isDefined } from 'twenty-shared/utils';
-
-import { useTheme } from '@emotion/react';
-import { type GraphColor } from '../types/GraphColor';
-import { createGradientDef } from '../utils/createGradientDef';
-import { createGraphColorRegistry } from '../utils/createGraphColorRegistry';
-import { getColorScheme } from '../utils/getColorScheme';
-import {
- formatGraphValue,
- type GraphValueFormatOptions,
-} from '../utils/graphFormatters';
-import { GraphWidgetLegend } from './GraphWidgetLegend';
-import { GraphWidgetTooltip } from './GraphWidgetTooltip';
-
-type LineChartDataPoint = {
- x: number | string | Date;
- y: number | null;
- to?: string;
-};
-
-type LineChartSeries = {
- id: string;
- label?: string;
- color?: GraphColor;
- data: LineChartDataPoint[];
- enableArea?: boolean;
-};
-
-type GraphWidgetLineChartProps = {
- data: LineChartSeries[];
- showLegend?: boolean;
- showGrid?: boolean;
- enablePoints?: boolean;
- xAxisLabel?: string;
- yAxisLabel?: string;
- id: string;
- enableArea?: boolean;
- stackedArea?: boolean;
- curve?:
- | 'linear'
- | 'monotoneX'
- | 'step'
- | 'stepBefore'
- | 'stepAfter'
- | 'natural';
- lineWidth?: number;
- enableSlices?: 'x' | 'y' | false;
- xScale?: ScaleSpec;
- yScale?: ScaleSpec;
-} & GraphValueFormatOptions;
-
-const getYScaleWithStacking = (
- yScale: ScaleSpec | undefined,
- stackedArea: boolean | undefined,
-): ScaleSpec => {
- if (!yScale || yScale.type === 'linear') {
- const linearScale: ScaleLinearSpec = {
- min: 0,
- max: 'auto',
- ...yScale,
- type: 'linear',
- stacked: stackedArea,
- };
- return linearScale;
- }
-
- return yScale;
-};
-
-const StyledContainer = styled.div`
- align-items: center;
- display: flex;
- flex-direction: column;
- height: 100%;
- justify-content: center;
- width: 100%;
-`;
-
-const StyledChartContainer = styled.div<{ $isClickable?: boolean }>`
- flex: 1;
- position: relative;
- width: 100%;
-
- ${({ $isClickable }) =>
- $isClickable &&
- `
- svg g circle {
- cursor: pointer;
- }
- `}
-`;
-
-export const GraphWidgetLineChart = ({
- data,
- showLegend = true,
- showGrid = true,
- enablePoints = false,
- xAxisLabel,
- yAxisLabel,
- id,
- enableArea = false,
- stackedArea = false,
- curve = 'monotoneX',
- lineWidth = 2,
- enableSlices = 'x',
- xScale = { type: 'linear' },
- yScale = { type: 'linear', min: 0, max: 'auto' },
- displayType,
- decimals,
- prefix,
- suffix,
- customFormatter,
-}: GraphWidgetLineChartProps) => {
- const theme = useTheme();
- const instanceId = useId();
-
- const colorRegistry = createGraphColorRegistry(theme);
-
- const formatOptions: GraphValueFormatOptions = {
- displayType,
- decimals,
- prefix,
- suffix,
- customFormatter,
- };
-
- const dataMap = useMemo(() => {
- const map: Record<string, LineChartSeries> = {};
- for (const series of data) {
- map[series.id] = series;
- }
- return map;
- }, [data]);
-
- const enrichedSeries = useMemo(() => {
- return data.map((series, index) => {
- const colorScheme = getColorScheme(colorRegistry, series.color, index);
- const shouldEnableArea = series.enableArea ?? enableArea;
- const gradientId = `lineGradient-${id}-${instanceId}-${series.id}-${index}`;
-
- return {
- ...series,
- colorScheme,
- gradientId,
- shouldEnableArea,
- label: series.label || series.id,
- };
- });
- }, [data, colorRegistry, id, instanceId, enableArea]);
-
- const nivoData = data.map((series) => ({
- id: series.id,
- data: series.data.map((point) => ({
- x: point.x,
- y: point.y,
- })),
- }));
-
- const defs = enrichedSeries
- .filter((series) => series.shouldEnableArea)
- .map((series) =>
- createGradientDef(
- series.colorScheme,
- series.gradientId,
- false,
- 90,
- theme.name === 'light',
- ),
- );
-
- const fill = enrichedSeries
- .filter((series) => series.shouldEnableArea)
- .map((series) => ({
- match: { id: series.id },
- id: series.gradientId,
- }));
-
- const colors = enrichedSeries.map((series) => series.colorScheme.solid);
-
- const handlePointClick = (point: Point<LineSeries>) => {
- const series = dataMap[point.seriesId];
- if (isDefined(series)) {
- const dataPoint = series.data[point.indexInSeries];
- if (isDefined(dataPoint?.to) === true) {
- window.location.href = dataPoint.to;
- }
- }
- };
-
- const hasClickableItems = data.some((series) =>
- series.data.some((point) => isDefined(point.to)),
- );
-
- const renderSliceTooltip = ({ slice }: SliceTooltipProps<LineSeries>) => {
- const tooltipItems = slice.points
- .map((point) => {
- const enrichedSeriesItem = enrichedSeries.find(
- (s) => s.id === point.seriesId,
- );
- if (!enrichedSeriesItem) return null;
-
- return {
- label: enrichedSeriesItem.label,
- formattedValue: formatGraphValue(
- Number(point.data.y || 0),
- formatOptions,
- ),
- dotColor: enrichedSeriesItem.colorScheme.solid,
- };
- })
- .filter(isDefined);
-
- const hasClickablePoint = slice.points.some((point) => {
- const series = dataMap[point.seriesId];
- if (isDefined(series)) {
- const dataPoint = series.data[point.indexInSeries];
- return isDefined(dataPoint?.to);
- }
- return false;
- });
-
- return (
- <GraphWidgetTooltip
- items={tooltipItems}
- showClickHint={hasClickablePoint}
- />
- );
- };
-
- const renderPointTooltip = (point: Point<LineSeries>) => {
- const enrichedSeriesItem = enrichedSeries.find(
- (s) => s.id === point.seriesId,
- );
- if (!enrichedSeriesItem) return null;
-
- const series = dataMap[point.seriesId];
- const dataPoint = series?.data[point.indexInSeries];
-
- return (
- <GraphWidgetTooltip
- items={[
- {
- label: enrichedSeriesItem.label,
- formattedValue: formatGraphValue(
- Number(point.data.y || 0),
- formatOptions,
- ),
- dotColor: enrichedSeriesItem.colorScheme.solid,
- },
- ]}
- showClickHint={isDefined(dataPoint?.to)}
- />
- );
- };
-
- const getAxisBottomConfig = () => ({
- tickSize: 0,
- tickPadding: 5,
- tickRotation: 0,
- legend: xAxisLabel,
- legendPosition: 'middle' as const,
- legendOffset: 40,
- });
-
- const getAxisLeftConfig = () => ({
- tickSize: 0,
- tickPadding: 5,
- tickRotation: 0,
- legend: yAxisLabel,
- legendPosition: 'middle' as const,
- legendOffset: -50,
- format: (value: number) => formatGraphValue(value, formatOptions),
- });
-
- const legendItems = enrichedSeries.map((series) => {
- const total = series.data.reduce((sum, point) => sum + (point.y || 0), 0);
- return {
- id: series.id,
- label: series.label,
- formattedValue: formatGraphValue(total, formatOptions),
- color: series.colorScheme.solid,
- };
- });
-
- return (
- <StyledContainer id={id}>
- <StyledChartContainer $isClickable={hasClickableItems}>
- <ResponsiveLine
- data={nivoData}
- margin={{ top: 20, right: 20, bottom: 60, left: 70 }}
- xScale={xScale}
- yScale={getYScaleWithStacking(yScale, stackedArea)}
- curve={curve}
- lineWidth={lineWidth}
- enableArea={enableArea}
- areaBaselineValue={0}
- enablePoints={enablePoints}
- pointSize={6}
- pointBorderWidth={0}
- areaOpacity={theme.name === 'dark' ? 0.8 : 1}
- colors={colors}
- areaBlendMode={theme.name === 'dark' ? 'screen' : 'multiply'}
- defs={defs}
- fill={fill}
- axisTop={null}
- axisRight={null}
- axisBottom={getAxisBottomConfig()}
- axisLeft={getAxisLeftConfig()}
- enableGridX={showGrid}
- enableGridY={showGrid}
- enableSlices={enableSlices}
- sliceTooltip={enableSlices === 'x' ? renderSliceTooltip : undefined}
- tooltip={
- enableSlices === false
- ? ({ point }) => renderPointTooltip(point)
- : undefined
- }
- onClick={(datum) => {
- if ('seriesId' in datum) {
- handlePointClick(datum as Point<LineSeries>);
- }
- }}
- useMesh={true}
- crosshairType="cross"
- theme={{
- axis: {
- domain: {
- line: {
- stroke: theme.border.color.light,
- strokeWidth: 1,
- },
- },
- ticks: {
- line: {
- stroke: theme.border.color.light,
- strokeWidth: 1,
- },
- text: {
- fill: theme.font.color.secondary,
- fontSize: 12,
- },
- },
- legend: {
- text: {
- fill: theme.font.color.secondary,
- fontSize: 12,
- fontWeight: theme.font.weight.regular,
- },
- },
- },
- grid: {
- line: {
- stroke: theme.border.color.light,
- strokeWidth: 1,
- strokeDasharray: '4 4',
- },
- },
- crosshair: {
- line: {
- stroke: theme.font.color.tertiary,
- strokeWidth: 1,
- strokeDasharray: '2 2',
- },
- },
- }}
- />
- </StyledChartContainer>
- <GraphWidgetLegend show={showLegend} items={legendItems} />
- </StyledContainer>
- );
-};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetPieChart.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetPieChart.tsx
index ba50dae262e..b8e8839a711 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetPieChart.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetPieChart.tsx
@@ -17,6 +17,7 @@ import {
formatGraphValue,
type GraphValueFormatOptions,
} from '../utils/graphFormatters';
+import { GraphWidgetChartContainer } from './GraphWidgetChartContainer';
import { GraphWidgetLegend } from './GraphWidgetLegend';
import { GraphWidgetTooltip } from './GraphWidgetTooltip';
@@ -41,20 +42,6 @@ const StyledContainer = styled.div`
width: 100%;
`;
-const StyledChartContainer = styled.div<{ $isClickable?: boolean }>`
- flex: 1;
- position: relative;
- width: 100%;
-
- ${({ $isClickable }) =>
- $isClickable &&
- `
- svg g path[fill^="url(#"] {
- cursor: pointer;
- }
- `}
-`;
-
export const GraphWidgetPieChart = ({
data,
showLegend = true,
@@ -198,7 +185,10 @@ export const GraphWidgetPieChart = ({
return (
<StyledContainer id={id}>
- <StyledChartContainer $isClickable={hasClickableItems}>
+ <GraphWidgetChartContainer
+ $isClickable={hasClickableItems}
+ $cursorSelector='svg g path[fill^="url(#"]'
+ >
<ResponsivePie
data={data}
innerRadius={0.8}
@@ -214,7 +204,7 @@ export const GraphWidgetPieChart = ({
fill={fill}
layers={['arcs', renderSliceEndLines]}
/>
- </StyledChartContainer>
+ </GraphWidgetChartContainer>
<GraphWidgetLegend
show={showLegend}
items={enrichedData.map((item) => ({
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetRenderer.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetRenderer.tsx
index 5189024f8f5..82fcbd0c967 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetRenderer.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/GraphWidgetRenderer.tsx
@@ -14,11 +14,11 @@ const GraphWidgetBarChart = lazy(() =>
);
const GraphWidgetLineChart = lazy(() =>
- import('@/page-layout/widgets/graph/components/GraphWidgetLineChart').then(
- (module) => ({
- default: module.GraphWidgetLineChart,
- }),
- ),
+ import(
+ '@/page-layout/widgets/graph/graphWidgetLineChart/components/GraphWidgetLineChart'
+ ).then((module) => ({
+ default: module.GraphWidgetLineChart,
+ })),
);
const GraphWidgetPieChart = lazy(() =>
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/__stories__/GraphWidgetLineChart.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/__stories__/GraphWidgetLineChart.stories.tsx
index c80523d0415..77d737e1710 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/components/__stories__/GraphWidgetLineChart.stories.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/components/__stories__/GraphWidgetLineChart.stories.tsx
@@ -2,7 +2,7 @@ import { type Meta, type StoryObj } from '@storybook/react';
import { type ComponentProps } from 'react';
import { CatalogDecorator, ComponentDecorator } from 'twenty-ui/testing';
-import { GraphWidgetLineChart } from '../GraphWidgetLineChart';
+import { GraphWidgetLineChart } from '../../graphWidgetLineChart/components/GraphWidgetLineChart';
const meta: Meta<typeof GraphWidgetLineChart> = {
title: 'Modules/PageLayout/Widgets/GraphWidgetLineChart',
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/components/GraphWidgetBarChart.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/components/GraphWidgetBarChart.tsx
index 1c858d2dcd7..aa0af90d0ee 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/components/GraphWidgetBarChart.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/components/GraphWidgetBarChart.tsx
@@ -1,3 +1,4 @@
+import { GraphWidgetChartContainer } from '@/page-layout/widgets/graph/components/GraphWidgetChartContainer';
import { GraphWidgetLegend } from '@/page-layout/widgets/graph/components/GraphWidgetLegend';
import { GraphWidgetTooltip } from '@/page-layout/widgets/graph/components/GraphWidgetTooltip';
import { BarChartEndLines } from '@/page-layout/widgets/graph/graphWidgetBarChart/components/BarChartEndLines';
@@ -46,20 +47,6 @@ const StyledContainer = styled.div`
width: 100%;
`;
-const StyledChartContainer = styled.div<{ $isClickable?: boolean }>`
- flex: 1;
- position: relative;
- width: 100%;
-
- ${({ $isClickable }) =>
- $isClickable &&
- `
- svg g[transform] rect[fill^="url(#gradient-"] {
- cursor: pointer;
- }
- `}
-`;
-
export const GraphWidgetBarChart = ({
data,
indexBy,
@@ -159,7 +146,10 @@ export const GraphWidgetBarChart = ({
return (
<StyledContainer id={id}>
- <StyledChartContainer $isClickable={hasClickableItems}>
+ <GraphWidgetChartContainer
+ $isClickable={hasClickableItems}
+ $cursorSelector='svg g[transform] rect[fill^="url(#gradient-"]'
+ >
<ResponsiveBar
data={data}
keys={keys}
@@ -206,7 +196,7 @@ export const GraphWidgetBarChart = ({
onMouseLeave={() => setHoveredBar(null)}
theme={chartTheme}
/>
- </StyledChartContainer>
+ </GraphWidgetChartContainer>
<GraphWidgetLegend
show={showLegend}
items={enrichedKeys.map((item) => {
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/components/GraphWidgetLineChart.tsx b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/components/GraphWidgetLineChart.tsx
new file mode 100644
index 00000000000..31fdd6b0a5d
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/components/GraphWidgetLineChart.tsx
@@ -0,0 +1,215 @@
+import { GraphWidgetChartContainer } from '@/page-layout/widgets/graph/components/GraphWidgetChartContainer';
+import { GraphWidgetLegend } from '@/page-layout/widgets/graph/components/GraphWidgetLegend';
+import { GraphWidgetTooltip } from '@/page-layout/widgets/graph/components/GraphWidgetTooltip';
+import { useLineChartData } from '@/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartData';
+import { useLineChartTheme } from '@/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTheme';
+import { useLineChartTooltip } from '@/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTooltip';
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import { getLineChartAxisBottomConfig } from '@/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisBottomConfig';
+import { getLineChartAxisLeftConfig } from '@/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisLeftConfig';
+import { handleLineChartPointClick } from '@/page-layout/widgets/graph/graphWidgetLineChart/utils/handleLineChartPointClick';
+import { createGraphColorRegistry } from '@/page-layout/widgets/graph/utils/createGraphColorRegistry';
+import { type GraphValueFormatOptions } from '@/page-layout/widgets/graph/utils/graphFormatters';
+import { useTheme } from '@emotion/react';
+import styled from '@emotion/styled';
+import { ResponsiveLine } from '@nivo/line';
+import { type ScaleLinearSpec, type ScaleSpec } from '@nivo/scales';
+import { useId } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+type GraphWidgetLineChartProps = {
+ data: LineChartSeries[];
+ showLegend?: boolean;
+ showGrid?: boolean;
+ enablePoints?: boolean;
+ xAxisLabel?: string;
+ yAxisLabel?: string;
+ id: string;
+ enableArea?: boolean;
+ stackedArea?: boolean;
+ curve?:
+ | 'linear'
+ | 'monotoneX'
+ | 'step'
+ | 'stepBefore'
+ | 'stepAfter'
+ | 'natural';
+ lineWidth?: number;
+ enableSlices?: 'x' | 'y' | false;
+ xScale?: ScaleSpec;
+ yScale?: ScaleSpec;
+} & GraphValueFormatOptions;
+
+const getYScaleWithStacking = (
+ yScale: ScaleSpec | undefined,
+ stackedArea: boolean | undefined,
+): ScaleSpec => {
+ if (!yScale || yScale.type === 'linear') {
+ const linearScale: ScaleLinearSpec = {
+ min: 0,
+ max: 'auto',
+ ...yScale,
+ type: 'linear',
+ stacked: stackedArea,
+ };
+ return linearScale;
+ }
+
+ return yScale;
+};
+
+const StyledContainer = styled.div`
+ align-items: center;
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ justify-content: center;
+ width: 100%;
+`;
+
+export const GraphWidgetLineChart = ({
+ data,
+ showLegend = true,
+ showGrid = true,
+ enablePoints = false,
+ xAxisLabel,
+ yAxisLabel,
+ id,
+ enableArea = false,
+ stackedArea = false,
+ curve = 'monotoneX',
+ lineWidth = 2,
+ enableSlices = 'x',
+ xScale = { type: 'linear' },
+ yScale = { type: 'linear', min: 0, max: 'auto' },
+ displayType,
+ decimals,
+ prefix,
+ suffix,
+ customFormatter,
+}: GraphWidgetLineChartProps) => {
+ const theme = useTheme();
+ const instanceId = useId();
+ const colorRegistry = createGraphColorRegistry(theme);
+ const chartTheme = useLineChartTheme();
+
+ const formatOptions: GraphValueFormatOptions = {
+ displayType,
+ decimals,
+ prefix,
+ suffix,
+ customFormatter,
+ };
+
+ const {
+ dataMap,
+ enrichedSeries,
+ nivoData,
+ defs,
+ fill,
+ colors,
+ legendItems,
+ hasClickableItems,
+ } = useLineChartData({
+ data,
+ colorRegistry,
+ id,
+ instanceId,
+ enableArea,
+ theme,
+ formatOptions,
+ });
+
+ const { createSliceTooltipData, createPointTooltipData } =
+ useLineChartTooltip({
+ dataMap,
+ enrichedSeries,
+ formatOptions,
+ });
+
+ const axisBottomConfig = getLineChartAxisBottomConfig(xAxisLabel);
+ const axisLeftConfig = getLineChartAxisLeftConfig(yAxisLabel, formatOptions);
+
+ const onPointClick = (
+ point: Parameters<typeof handleLineChartPointClick>[0],
+ ) => {
+ handleLineChartPointClick(point, dataMap);
+ };
+
+ const renderSliceTooltip = (
+ props: Parameters<typeof createSliceTooltipData>[0],
+ ) => {
+ const tooltipData = createSliceTooltipData(props);
+ return (
+ <GraphWidgetTooltip
+ items={tooltipData.items}
+ showClickHint={tooltipData.showClickHint}
+ />
+ );
+ };
+
+ const renderPointTooltip = (
+ point: Parameters<typeof createPointTooltipData>[0],
+ ) => {
+ const tooltipData = createPointTooltipData(point);
+ if (!isDefined(tooltipData)) return null;
+ return (
+ <GraphWidgetTooltip
+ items={tooltipData.items}
+ showClickHint={tooltipData.showClickHint}
+ />
+ );
+ };
+
+ return (
+ <StyledContainer id={id}>
+ <GraphWidgetChartContainer
+ $isClickable={hasClickableItems}
+ $cursorSelector="svg g circle"
+ >
+ <ResponsiveLine
+ data={nivoData}
+ margin={{ top: 20, right: 20, bottom: 60, left: 70 }}
+ xScale={xScale}
+ yScale={getYScaleWithStacking(yScale, stackedArea)}
+ curve={curve}
+ lineWidth={lineWidth}
+ enableArea={enableArea}
+ areaBaselineValue={0}
+ enablePoints={enablePoints}
+ pointSize={6}
+ pointBorderWidth={0}
+ areaOpacity={theme.name === 'dark' ? 0.8 : 1}
+ colors={colors}
+ areaBlendMode={theme.name === 'dark' ? 'screen' : 'multiply'}
+ defs={defs}
+ fill={fill}
+ axisTop={null}
+ axisRight={null}
+ axisBottom={axisBottomConfig}
+ axisLeft={axisLeftConfig}
+ enableGridX={showGrid}
+ enableGridY={showGrid}
+ enableSlices={enableSlices}
+ sliceTooltip={enableSlices === 'x' ? renderSliceTooltip : undefined}
+ tooltip={
+ enableSlices === false
+ ? ({ point }) => renderPointTooltip(point)
+ : undefined
+ }
+ onClick={(datum) => {
+ if ('seriesId' in datum) {
+ onPointClick(
+ datum as Parameters<typeof handleLineChartPointClick>[0],
+ );
+ }
+ }}
+ useMesh={true}
+ crosshairType="cross"
+ theme={chartTheme}
+ />
+ </GraphWidgetChartContainer>
+ <GraphWidgetLegend show={showLegend} items={legendItems} />
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/__tests__/useLineChartData.test.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/__tests__/useLineChartData.test.ts
new file mode 100644
index 00000000000..a4ce4a4fb30
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/__tests__/useLineChartData.test.ts
@@ -0,0 +1,387 @@
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import { type GraphColorRegistry } from '@/page-layout/widgets/graph/types/GraphColorRegistry';
+import { type GraphValueFormatOptions } from '@/page-layout/widgets/graph/utils/graphFormatters';
+import { renderHook } from '@testing-library/react';
+import { type ThemeType } from 'twenty-ui/theme';
+import { useLineChartData } from '../useLineChartData';
+
+describe('useLineChartData', () => {
+ const mockColorRegistry: GraphColorRegistry = {
+ red: {
+ name: 'red',
+ gradient: {
+ normal: ['red1', 'red2'],
+ hover: ['red3', 'red4'],
+ },
+ solid: 'redSolid',
+ },
+ blue: {
+ name: 'blue',
+ gradient: {
+ normal: ['blue1', 'blue2'],
+ hover: ['blue3', 'blue4'],
+ },
+ solid: 'blueSolid',
+ },
+ };
+
+ const mockTheme = { name: 'light' } as ThemeType;
+ const mockFormatOptions: GraphValueFormatOptions = { displayType: 'number' };
+
+ const mockData: LineChartSeries[] = [
+ {
+ id: 'series1',
+ data: [
+ { x: 'Jan', y: 100 },
+ { x: 'Feb', y: 120 },
+ { x: 'Mar', y: 150 },
+ ],
+ label: 'Sales',
+ color: 'red',
+ },
+ {
+ id: 'series2',
+ data: [
+ { x: 'Jan', y: 80 },
+ { x: 'Feb', y: 90 },
+ { x: 'Mar', y: 100 },
+ ],
+ label: 'Costs',
+ },
+ ];
+
+ it('should create data map', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.dataMap.series1).toBe(mockData[0]);
+ expect(result.current.dataMap.series2).toBe(mockData[1]);
+ });
+
+ it('should enrich series with color schemes', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.enrichedSeries[0].colorScheme).toBe(
+ mockColorRegistry.red,
+ );
+ expect(result.current.enrichedSeries[0].gradientId).toBe(
+ 'lineGradient-test-chart-instance-1-series1-0',
+ );
+ expect(result.current.enrichedSeries[0].label).toBe('Sales');
+
+ expect(result.current.enrichedSeries[1].colorScheme).toBe(
+ mockColorRegistry.blue,
+ );
+ expect(result.current.enrichedSeries[1].label).toBe('Costs');
+ });
+
+ it('should handle enableArea per series', () => {
+ const dataWithArea: LineChartSeries[] = [
+ { ...mockData[0], enableArea: true },
+ { ...mockData[1], enableArea: false },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithArea,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: true,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.enrichedSeries[0].shouldEnableArea).toBe(true);
+ expect(result.current.enrichedSeries[1].shouldEnableArea).toBe(false);
+ });
+
+ it('should use global enableArea when series does not specify', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: true,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.enrichedSeries[0].shouldEnableArea).toBe(true);
+ expect(result.current.enrichedSeries[1].shouldEnableArea).toBe(true);
+ });
+
+ it('should format data for Nivo', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.nivoData).toEqual([
+ {
+ id: 'series1',
+ data: [
+ { x: 'Jan', y: 100 },
+ { x: 'Feb', y: 120 },
+ { x: 'Mar', y: 150 },
+ ],
+ },
+ {
+ id: 'series2',
+ data: [
+ { x: 'Jan', y: 80 },
+ { x: 'Feb', y: 90 },
+ { x: 'Mar', y: 100 },
+ ],
+ },
+ ]);
+ });
+
+ it('should generate defs only for series with area enabled', () => {
+ const dataWithArea: LineChartSeries[] = [
+ { ...mockData[0], enableArea: true },
+ { ...mockData[1], enableArea: false },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithArea,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.defs).toHaveLength(1);
+ expect(result.current.defs[0].id).toBe(
+ 'lineGradient-test-chart-instance-1-series1-0',
+ );
+ });
+
+ it('should reverse gradient for light theme', () => {
+ const dataWithArea: LineChartSeries[] = [
+ { ...mockData[0], enableArea: true },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithArea,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.defs[0].colors).toEqual([
+ { offset: 0, color: 'red2' },
+ { offset: 100, color: 'red1' },
+ ]);
+ });
+
+ it('should not reverse gradient for dark theme', () => {
+ const dataWithArea: LineChartSeries[] = [
+ { ...mockData[0], enableArea: true },
+ ];
+
+ const darkTheme = { name: 'dark' } as ThemeType;
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithArea,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: darkTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.defs[0].colors).toEqual([
+ { offset: 0, color: 'red1' },
+ { offset: 100, color: 'red2' },
+ ]);
+ });
+
+ it('should generate fill configuration', () => {
+ const dataWithArea: LineChartSeries[] = [
+ { ...mockData[0], enableArea: true },
+ { ...mockData[1], enableArea: true },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithArea,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.fill).toEqual([
+ {
+ match: { id: 'series1' },
+ id: 'lineGradient-test-chart-instance-1-series1-0',
+ },
+ {
+ match: { id: 'series2' },
+ id: 'lineGradient-test-chart-instance-1-series2-1',
+ },
+ ]);
+ });
+
+ it('should extract colors for series', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.colors).toEqual(['redSolid', 'blueSolid']);
+ });
+
+ it('should calculate legend items with totals', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: mockData,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.legendItems).toEqual([
+ {
+ id: 'series1',
+ label: 'Sales',
+ formattedValue: '370',
+ color: 'redSolid',
+ },
+ {
+ id: 'series2',
+ label: 'Costs',
+ formattedValue: '270',
+ color: 'blueSolid',
+ },
+ ]);
+ });
+
+ it('should detect clickable items', () => {
+ const dataWithLinks: LineChartSeries[] = [
+ {
+ id: 'series1',
+ data: [
+ { x: 'Jan', y: 100, to: '/january' },
+ { x: 'Feb', y: 120 },
+ ],
+ },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithLinks,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.hasClickableItems).toBe(true);
+ });
+
+ it('should handle empty data', () => {
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: [],
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.dataMap).toEqual({});
+ expect(result.current.enrichedSeries).toEqual([]);
+ expect(result.current.nivoData).toEqual([]);
+ expect(result.current.defs).toEqual([]);
+ expect(result.current.fill).toEqual([]);
+ expect(result.current.colors).toEqual([]);
+ expect(result.current.legendItems).toEqual([]);
+ expect(result.current.hasClickableItems).toBe(false);
+ });
+
+ it('should use series id as label when label is not provided', () => {
+ const dataWithoutLabel: LineChartSeries[] = [
+ {
+ id: 'series1',
+ data: [{ x: 'Jan', y: 100 }],
+ },
+ ];
+
+ const { result } = renderHook(() =>
+ useLineChartData({
+ data: dataWithoutLabel,
+ colorRegistry: mockColorRegistry,
+ id: 'test-chart',
+ instanceId: 'instance-1',
+ enableArea: false,
+ theme: mockTheme,
+ formatOptions: mockFormatOptions,
+ }),
+ );
+
+ expect(result.current.enrichedSeries[0].label).toBe('series1');
+ });
+});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartData.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartData.ts
new file mode 100644
index 00000000000..e312bebcb94
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartData.ts
@@ -0,0 +1,104 @@
+import { type LineChartEnrichedSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartEnrichedSeries';
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import { type GraphColorRegistry } from '@/page-layout/widgets/graph/types/GraphColorRegistry';
+import { createGradientDef } from '@/page-layout/widgets/graph/utils/createGradientDef';
+import { getColorScheme } from '@/page-layout/widgets/graph/utils/getColorScheme';
+import {
+ formatGraphValue,
+ type GraphValueFormatOptions,
+} from '@/page-layout/widgets/graph/utils/graphFormatters';
+import { type LineSeries } from '@nivo/line';
+import { useMemo } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { type ThemeType } from 'twenty-ui/theme';
+
+type UseLineChartDataProps = {
+ data: LineChartSeries[];
+ colorRegistry: GraphColorRegistry;
+ id: string;
+ instanceId: string;
+ enableArea: boolean;
+ theme: ThemeType;
+ formatOptions: GraphValueFormatOptions;
+};
+
+export const useLineChartData = ({
+ data,
+ colorRegistry,
+ id,
+ instanceId,
+ enableArea,
+ theme,
+ formatOptions,
+}: UseLineChartDataProps) => {
+ const dataMap = Object.fromEntries(data.map((series) => [series.id, series]));
+ const enrichedSeries = useMemo((): LineChartEnrichedSeries[] => {
+ return data.map((series, index) => {
+ const colorScheme = getColorScheme(colorRegistry, series.color, index);
+ const shouldEnableArea = series.enableArea ?? enableArea;
+ const gradientId = `lineGradient-${id}-${instanceId}-${series.id}-${index}`;
+
+ return {
+ ...series,
+ colorScheme,
+ gradientId,
+ shouldEnableArea,
+ label: series.label || series.id,
+ };
+ });
+ }, [data, colorRegistry, id, instanceId, enableArea]);
+
+ const nivoData: LineSeries[] = data.map((series) => ({
+ id: series.id,
+ data: series.data.map((point) => ({
+ x: point.x,
+ y: point.y,
+ })),
+ }));
+
+ const seriesWithArea = enrichedSeries.filter(
+ (series) => series.shouldEnableArea,
+ );
+
+ const defs = seriesWithArea.map((series) =>
+ createGradientDef(
+ series.colorScheme,
+ series.gradientId,
+ false,
+ 90,
+ theme.name === 'light',
+ ),
+ );
+
+ const fill = seriesWithArea.map((series) => ({
+ match: { id: series.id },
+ id: series.gradientId,
+ }));
+
+ const colors = enrichedSeries.map((series) => series.colorScheme.solid);
+
+ const legendItems = enrichedSeries.map((series) => {
+ const total = series.data.reduce((sum, point) => sum + (point.y || 0), 0);
+ return {
+ id: series.id,
+ label: series.label,
+ formattedValue: formatGraphValue(total, formatOptions),
+ color: series.colorScheme.solid,
+ };
+ });
+
+ const hasClickableItems = data.some((series) =>
+ series.data.some((point) => isDefined(point.to)),
+ );
+
+ return {
+ dataMap,
+ enrichedSeries,
+ nivoData,
+ defs,
+ fill,
+ colors,
+ legendItems,
+ hasClickableItems,
+ };
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTheme.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTheme.ts
new file mode 100644
index 00000000000..631f5083315
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTheme.ts
@@ -0,0 +1,47 @@
+import { useTheme } from '@emotion/react';
+
+export const useLineChartTheme = () => {
+ const theme = useTheme();
+
+ return {
+ axis: {
+ domain: {
+ line: {
+ stroke: theme.border.color.light,
+ strokeWidth: 1,
+ },
+ },
+ ticks: {
+ line: {
+ stroke: theme.border.color.light,
+ strokeWidth: 1,
+ },
+ text: {
+ fill: theme.font.color.secondary,
+ fontSize: 12,
+ },
+ },
+ legend: {
+ text: {
+ fill: theme.font.color.secondary,
+ fontSize: 12,
+ fontWeight: theme.font.weight.regular,
+ },
+ },
+ },
+ grid: {
+ line: {
+ stroke: theme.border.color.light,
+ strokeWidth: 1,
+ strokeDasharray: '4 4',
+ },
+ },
+ crosshair: {
+ line: {
+ stroke: theme.font.color.tertiary,
+ strokeWidth: 1,
+ strokeDasharray: '2 2',
+ },
+ },
+ };
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTooltip.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTooltip.ts
new file mode 100644
index 00000000000..224829a0316
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/hooks/useLineChartTooltip.ts
@@ -0,0 +1,89 @@
+import { type LineChartEnrichedSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartEnrichedSeries';
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import {
+ formatGraphValue,
+ type GraphValueFormatOptions,
+} from '@/page-layout/widgets/graph/utils/graphFormatters';
+import {
+ type LineSeries,
+ type Point,
+ type SliceTooltipProps,
+} from '@nivo/line';
+import { isDefined } from 'twenty-shared/utils';
+
+type UseLineChartTooltipProps = {
+ dataMap: Record<string, LineChartSeries>;
+ enrichedSeries: LineChartEnrichedSeries[];
+ formatOptions: GraphValueFormatOptions;
+};
+
+export const useLineChartTooltip = ({
+ dataMap,
+ enrichedSeries,
+ formatOptions,
+}: UseLineChartTooltipProps) => {
+ const enrichedSeriesMap = new Map(
+ enrichedSeries.map((series) => [series.id, series]),
+ );
+
+ const createSliceTooltipData = ({ slice }: SliceTooltipProps<LineSeries>) => {
+ const tooltipItems = slice.points
+ .map((point) => {
+ const enrichedSeriesItem = enrichedSeriesMap.get(
+ String(point.seriesId),
+ );
+ if (!enrichedSeriesItem) return null;
+
+ return {
+ label: enrichedSeriesItem.label,
+ formattedValue: formatGraphValue(
+ Number(point.data.y || 0),
+ formatOptions,
+ ),
+ dotColor: enrichedSeriesItem.colorScheme.solid,
+ };
+ })
+ .filter(isDefined);
+
+ const hasClickablePoint = slice.points.some((point) => {
+ const series = dataMap[point.seriesId];
+ if (isDefined(series)) {
+ const dataPoint = series.data[point.indexInSeries];
+ return isDefined(dataPoint?.to);
+ }
+ return false;
+ });
+
+ return {
+ items: tooltipItems,
+ showClickHint: hasClickablePoint,
+ };
+ };
+
+ const createPointTooltipData = (point: Point<LineSeries>) => {
+ const enrichedSeriesItem = enrichedSeriesMap.get(String(point.seriesId));
+ if (!enrichedSeriesItem) return null;
+
+ const series = dataMap[point.seriesId];
+ const dataPoint = series?.data[point.indexInSeries];
+
+ return {
+ items: [
+ {
+ label: enrichedSeriesItem.label,
+ formattedValue: formatGraphValue(
+ Number(point.data.y || 0),
+ formatOptions,
+ ),
+ dotColor: enrichedSeriesItem.colorScheme.solid,
+ },
+ ],
+ showClickHint: isDefined(dataPoint?.to),
+ };
+ };
+
+ return {
+ createSliceTooltipData,
+ createPointTooltipData,
+ };
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartDataPoint.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartDataPoint.ts
new file mode 100644
index 00000000000..5edf1584814
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartDataPoint.ts
@@ -0,0 +1,5 @@
+export type LineChartDataPoint = {
+ x: number | string | Date;
+ y: number | null;
+ to?: string;
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartEnrichedSeries.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartEnrichedSeries.ts
new file mode 100644
index 00000000000..52e10fbd6b6
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartEnrichedSeries.ts
@@ -0,0 +1,9 @@
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import { type GraphColorScheme } from '@/page-layout/widgets/graph/types/GraphColorScheme';
+
+export type LineChartEnrichedSeries = LineChartSeries & {
+ colorScheme: GraphColorScheme;
+ gradientId: string;
+ shouldEnableArea: boolean;
+ label: string;
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries.ts
new file mode 100644
index 00000000000..a9a6fcde000
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries.ts
@@ -0,0 +1,10 @@
+import { type LineChartDataPoint } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartDataPoint';
+import { type GraphColor } from '@/page-layout/widgets/graph/types/GraphColor';
+
+export type LineChartSeries = {
+ id: string;
+ label?: string;
+ color?: GraphColor;
+ data: LineChartDataPoint[];
+ enableArea?: boolean;
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisBottomConfig.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisBottomConfig.ts
new file mode 100644
index 00000000000..d63df65584c
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisBottomConfig.ts
@@ -0,0 +1,8 @@
+export const getLineChartAxisBottomConfig = (xAxisLabel?: string) => ({
+ tickSize: 0,
+ tickPadding: 5,
+ tickRotation: 0,
+ legend: xAxisLabel,
+ legendPosition: 'middle' as const,
+ legendOffset: 40,
+});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisLeftConfig.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisLeftConfig.ts
new file mode 100644
index 00000000000..c391eb986a7
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/getLineChartAxisLeftConfig.ts
@@ -0,0 +1,17 @@
+import {
+ formatGraphValue,
+ type GraphValueFormatOptions,
+} from '@/page-layout/widgets/graph/utils/graphFormatters';
+
+export const getLineChartAxisLeftConfig = (
+ yAxisLabel?: string,
+ formatOptions?: GraphValueFormatOptions,
+) => ({
+ tickSize: 0,
+ tickPadding: 5,
+ tickRotation: 0,
+ legend: yAxisLabel,
+ legendPosition: 'middle' as const,
+ legendOffset: -50,
+ format: (value: number) => formatGraphValue(value, formatOptions || {}),
+});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/handleLineChartPointClick.ts b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/handleLineChartPointClick.ts
new file mode 100644
index 00000000000..4d42e8b31b7
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetLineChart/utils/handleLineChartPointClick.ts
@@ -0,0 +1,16 @@
+import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLineChart/types/LineChartSeries';
+import { type LineSeries, type Point } from '@nivo/line';
+import { isDefined } from 'twenty-shared/utils';
+
+export const handleLineChartPointClick = (
+ point: Point<LineSeries>,
+ dataMap: Record<string, LineChartSeries>,
+) => {
+ const series = dataMap[point.seriesId];
+ if (isDefined(series)) {
+ const dataPoint = series.data[point.indexInSeries];
+ if (isDefined(dataPoint?.to)) {
+ window.location.href = dataPoint.to;
+ }
+ }
+};