The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[Dashboards] Graph bar chart component (#14052)
nitinab9cabce043f
diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.jsonindex 9a7bb4d1817..15f41373a83 100644--- a/packages/twenty-front/package.json+++ b/packages/twenty-front/package.json@@ -45,6 +45,7 @@"@lingui/core": "^5.1.2","@lingui/detect-locale": "^5.2.0","@lingui/react": "^5.1.2",+ "@nivo/bar": "^0.99.0","@nivo/core": "^0.99.0","@nivo/line": "^0.99.0","@nivo/pie": "^0.99.0",diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetBarChart.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetBarChart.tsxnew file mode 100644index 00000000000..0a0acc46d93--- /dev/null+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetBarChart.tsx@@ -0,0 +1,444 @@+import styled from '@emotion/styled';+import {+ ResponsiveBar,+ type BarCustomLayerProps,+ type BarDatum,+ type ComputedBarDatum,+ type ComputedDatum,+} from '@nivo/bar';+import { useId, useMemo, useState } from 'react';+import { isDefined } from 'twenty-shared/utils';++import { useTheme } from '@emotion/react';+import { type GraphColor } from '../types/GraphColor';+import { type GraphColorScheme } from '../types/GraphColorScheme';+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 BarChartDataItem = BarDatum & {+ to?: string;+};++type BarChartSeries = {+ key: string;+ label?: string;+ color?: GraphColor;+};++type BarConfig = {+ key: string;+ indexValue: string | number;+ gradientId: string;+ colorScheme: GraphColorScheme;+};++type GraphWidgetBarChartProps = {+ data: BarChartDataItem[];+ indexBy: string;+ keys: string[];+ series?: BarChartSeries[];+ showLegend?: boolean;+ showGrid?: boolean;+ showValues?: boolean;+ xAxisLabel?: string;+ yAxisLabel?: string;+ id: string;+ layout?: 'vertical' | 'horizontal';+ groupMode?: 'grouped' | 'stacked';+ seriesLabels?: Record<string, string>;+} & GraphValueFormatOptions;++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[transform] rect[fill^="url(#gradient-"] {+ cursor: pointer;+ }+ `}+`;++const getAxisBottomConfig = (+ layout: 'vertical' | 'horizontal',+ xAxisLabel?: string,+ yAxisLabel?: string,+ formatOptions?: GraphValueFormatOptions,+) => {+ return layout === 'vertical'+ ? {+ tickSize: 0,+ tickPadding: 5,+ tickRotation: 0,+ legend: xAxisLabel,+ legendPosition: 'middle' as const,+ legendOffset: 40,+ }+ : {+ tickSize: 0,+ tickPadding: 5,+ tickRotation: 0,+ legend: yAxisLabel,+ legendPosition: 'middle' as const,+ legendOffset: 40,+ format: (value: number) => formatGraphValue(value, formatOptions || {}),+ };+};++const getAxisLeftConfig = (+ layout: 'vertical' | 'horizontal',+ xAxisLabel?: string,+ yAxisLabel?: string,+ formatOptions?: GraphValueFormatOptions,+) => {+ return layout === 'vertical'+ ? {+ tickSize: 0,+ tickPadding: 5,+ tickRotation: 0,+ legend: yAxisLabel,+ legendPosition: 'middle' as const,+ legendOffset: -50,+ format: (value: number) => formatGraphValue(value, formatOptions || {}),+ }+ : {+ tickSize: 0,+ tickPadding: 5,+ tickRotation: 0,+ legend: xAxisLabel,+ legendPosition: 'middle' as const,+ legendOffset: -50,+ };+};++const calculateBarEndLineCoordinates = (+ bar: ComputedBarDatum<BarChartDataItem>,+ layout: 'vertical' | 'horizontal',+) => {+ if (layout === 'vertical') {+ return {+ x1: bar.x,+ x2: bar.x + bar.width,+ y1: bar.y,+ y2: bar.y,+ };+ } else {+ return {+ x1: bar.x + bar.width,+ x2: bar.x + bar.width,+ y1: bar.y,+ y2: bar.y + bar.height,+ };+ }+};++export const GraphWidgetBarChart = ({+ data,+ indexBy,+ keys,+ series,+ showLegend = true,+ showGrid = true,+ showValues = false,+ xAxisLabel,+ yAxisLabel,+ id,+ layout = 'vertical',+ groupMode = 'grouped',+ seriesLabels,+ displayType,+ decimals,+ prefix,+ suffix,+ customFormatter,+}: GraphWidgetBarChartProps) => {+ const theme = useTheme();+ const instanceId = useId();+ const [hoveredBar, setHoveredBar] = useState<{+ key: string;+ indexValue: string | number;+ } | null>(null);++ const colorRegistry = createGraphColorRegistry(theme);++ const formatOptions: GraphValueFormatOptions = {+ displayType,+ decimals,+ prefix,+ suffix,+ customFormatter,+ };++ const seriesConfigMap = useMemo(() => {+ const map = new Map<string, BarChartSeries>();+ series?.forEach((s) => map.set(s.key, s));+ return map;+ }, [series]);++ const barConfigs = useMemo((): BarConfig[] => {+ return data.flatMap((dataPoint, dataIndex) => {+ const indexValue = dataPoint[indexBy];+ return keys.map((key, keyIndex): BarConfig => {+ const seriesConfig = seriesConfigMap.get(key);+ const colorScheme = getColorScheme(+ colorRegistry,+ seriesConfig?.color,+ keyIndex,+ );+ const gradientId = `gradient-${id}-${instanceId}-${key}-${dataIndex}-${keyIndex}`;++ return {+ key,+ indexValue,+ gradientId,+ colorScheme,+ };+ });+ });+ }, [data, indexBy, keys, colorRegistry, id, instanceId, seriesConfigMap]);++ const enrichedKeys = useMemo(() => {+ return keys.map((key, index) => {+ const seriesConfig = seriesConfigMap.get(key);+ const colorScheme = getColorScheme(+ colorRegistry,+ seriesConfig?.color,+ index,+ );+ return {+ key,+ colorScheme,+ label: seriesConfig?.label || seriesLabels?.[key] || key,+ };+ });+ }, [keys, colorRegistry, seriesConfigMap, seriesLabels]);++ const defs = barConfigs.map((bar) => {+ const isHovered =+ hoveredBar?.key === bar.key && hoveredBar?.indexValue === bar.indexValue;+ return createGradientDef(+ bar.colorScheme,+ bar.gradientId,+ isHovered,+ layout === 'horizontal' ? 0 : 90,+ true,+ );+ });++ const getBarColor = (datum: ComputedDatum<BarDatum>) => {+ const bar = barConfigs.find(+ (b) => b.key === datum.id && b.indexValue === datum.indexValue,+ );+ if (!bar) {+ return theme.border.color.light;+ }+ return `url(#${bar.gradientId})`;+ };++ const handleBarClick = (datum: ComputedDatum<BarDatum>) => {+ const dataItem = data.find((d) => d[indexBy] === datum.indexValue);+ if (isDefined(dataItem?.to)) {+ window.location.href = dataItem.to;+ }+ };++ const renderTooltip = (datum: ComputedDatum<BarDatum>) => {+ const hoveredKey = hoveredBar?.key;+ if (!isDefined(hoveredKey)) return null;++ const enrichedKey = enrichedKeys.find((item) => item.key === hoveredKey);+ if (!enrichedKey) return null;++ const dataItem = data.find((d) => d[indexBy] === datum.indexValue);+ const seriesValue = Number(datum.data[hoveredKey] || 0);+ const tooltipItem = {+ label: enrichedKey.label,+ formattedValue: formatGraphValue(seriesValue, formatOptions),+ dotColor: enrichedKey.colorScheme.solid,+ };++ return (+ <GraphWidgetTooltip+ items={[tooltipItem]}+ showClickHint={isDefined(dataItem?.to)}+ />+ );+ };++ const axisBottomConfig = getAxisBottomConfig(+ layout,+ xAxisLabel,+ yAxisLabel,+ formatOptions,+ );+ const axisLeftConfig = getAxisLeftConfig(+ layout,+ xAxisLabel,+ yAxisLabel,+ formatOptions,+ );++ const hasClickableItems = data.some((item) => isDefined(item.to));++ const renderBarEndLines = (props: BarCustomLayerProps<BarChartDataItem>) => {+ const { bars } = props;++ if (!bars || bars.length === 0) {+ return null;+ }++ return (+ <g>+ {bars.map((bar: ComputedBarDatum<BarChartDataItem>, index: number) => {+ const enrichedKey = enrichedKeys.find((k) => k.key === bar.data.id);+ if (!enrichedKey) {+ return null;+ }+ const lineColor = enrichedKey.colorScheme.solid;+ const { x1, y1, x2, y2 } = calculateBarEndLineCoordinates(+ bar,+ layout,+ );++ return (+ <line+ key={`${bar.data.id}-${bar.data.indexValue}-endline-${index}`}+ x1={x1}+ y1={y1}+ x2={x2}+ y2={y2}+ stroke={lineColor}+ strokeWidth={1}+ />+ );+ })}+ </g>+ );+ };++ return (+ <StyledContainer id={id}>+ <StyledChartContainer $isClickable={hasClickableItems}>+ <ResponsiveBar+ data={data}+ keys={keys}+ indexBy={indexBy}+ margin={{ top: 20, right: 20, bottom: 60, left: 70 }}+ padding={0.3}+ groupMode={groupMode}+ layout={layout}+ valueScale={{ type: 'linear' }}+ indexScale={{ type: 'band', round: true }}+ colors={getBarColor}+ defs={defs}+ layers={[+ 'grid',+ 'axes',+ 'bars',+ renderBarEndLines,+ 'markers',+ 'legends',+ ]}+ axisTop={null}+ axisRight={null}+ axisBottom={axisBottomConfig}+ axisLeft={axisLeftConfig}+ enableGridX={layout === 'horizontal' && showGrid}+ enableGridY={layout === 'vertical' && showGrid}+ gridXValues={layout === 'horizontal' ? 5 : undefined}+ gridYValues={layout === 'vertical' ? 5 : undefined}+ enableLabel={showValues}+ labelSkipWidth={12}+ labelSkipHeight={12}+ labelTextColor={theme.font.color.primary}+ label={(d) => formatGraphValue(Number(d.value), formatOptions)}+ tooltip={(props) => renderTooltip(props)}+ onClick={handleBarClick}+ onMouseEnter={(datum) => {+ if (isDefined(datum.id) && isDefined(datum.indexValue)) {+ setHoveredBar({+ key: String(datum.id),+ indexValue: datum.indexValue,+ });+ }+ }}+ onMouseLeave={() => setHoveredBar(null)}+ 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: 11,+ },+ },+ legend: {+ text: {+ fill: theme.font.color.light,+ fontSize: 12,+ fontWeight: theme.font.weight.medium,+ },+ },+ },+ grid: {+ line: {+ stroke: theme.border.color.light,+ strokeWidth: 1,+ strokeDasharray: '4 4',+ },+ },+ labels: {+ text: {+ fontSize: 11,+ fontWeight: theme.font.weight.medium,+ },+ },+ }}+ />+ </StyledChartContainer>+ <GraphWidgetLegend+ show={showLegend}+ items={enrichedKeys.map((item) => {+ const total = data.reduce(+ (sum, d) => sum + Number(d[item.key] || 0),+ 0,+ );+ return {+ id: item.key,+ label: item.label,+ formattedValue: formatGraphValue(total, formatOptions),+ color: item.colorScheme.solid,+ };+ })}+ />+ </StyledContainer>+ );+};diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetGaugeChart.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetGaugeChart.tsxindex 884b92fbaf5..10270a6dc0a 100644--- a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetGaugeChart.tsx+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetGaugeChart.tsx@@ -4,13 +4,13 @@ import {type RadialBarCustomLayerProps,ResponsiveRadialBar,} from '@nivo/radial-bar';-import { useState } from 'react';+import { useId, useState } from 'react';import { isDefined } from 'twenty-shared/utils';import { H1Title, H1TitleFontColor } from 'twenty-ui/display';-+import { type GraphColor } from '../types/GraphColor';import { createGradientDef } from '../utils/createGradientDef';import { createGraphColorRegistry } from '../utils/createGraphColorRegistry';-import { getColorSchemeByName } from '../utils/getColorSchemeByName';+import { getColorScheme } from '../utils/getColorScheme';import {formatGraphValue,type GraphValueFormatOptions,@@ -18,14 +18,19 @@ import {import { GraphWidgetLegend } from './GraphWidgetLegend';import { GraphWidgetTooltip } from './GraphWidgetTooltip';-type GraphWidgetGaugeChartProps = {+type GaugeChartData = {value: number;min: number;max: number;+ color?: GraphColor;+ to?: string;+ label?: string;+};++type GraphWidgetGaugeChartProps = {+ data: GaugeChartData;showValue?: boolean;showLegend?: boolean;- legendLabel: string;- tooltipHref?: string;id: string;} & GraphValueFormatOptions;@@ -38,10 +43,18 @@ const StyledContainer = styled.div`width: 100%;`;-const StyledChartContainer = styled.div`+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)`@@ -52,13 +65,9 @@ const StyledH1Title = styled(H1Title)``;export const GraphWidgetGaugeChart = ({- value,- min,- max,+ data,showValue = true,showLegend = true,- legendLabel,- tooltipHref,id,displayType,decimals,@@ -66,12 +75,13 @@ export const GraphWidgetGaugeChart = ({suffix,customFormatter,}: GraphWidgetGaugeChartProps) => {+ const { value, min, max, color = 'blue', to, label = 'Value' } = data;const theme = useTheme();+ const instanceId = useId();const [isHovered, setIsHovered] = useState(false);const colorRegistry = createGraphColorRegistry(theme);- const colorScheme =- getColorSchemeByName(colorRegistry, 'blue') || colorRegistry.blue;+ const colorScheme = getColorScheme(colorRegistry, color);const formatOptions: GraphValueFormatOptions = {displayType,@@ -86,7 +96,7 @@ export const GraphWidgetGaugeChart = ({const normalizedValue = max === min ? 0 : ((value - min) / (max - min)) * 100;const clampedNormalizedValue = Math.max(0, Math.min(100, normalizedValue));- const data = [+ const chartData = [{id: 'gauge',data: [@@ -96,7 +106,7 @@ export const GraphWidgetGaugeChart = ({},];- const gradientId = `gaugeGradient-${id}`;+ const gradientId = `gaugeGradient-${id}-${instanceId}`;const gaugeAngle = -90 + (clampedNormalizedValue / 100) * 90;const gradientDef = createGradientDef(colorScheme,@@ -107,8 +117,8 @@ export const GraphWidgetGaugeChart = ({const defs = [gradientDef];const handleClick = () => {- if (isDefined(tooltipHref)) {- window.location.href = tooltipHref;+ if (isDefined(to)) {+ window.location.href = to;}};@@ -119,12 +129,12 @@ export const GraphWidgetGaugeChart = ({<GraphWidgetTooltipitems={[{- label: legendLabel,+ label: label,formattedValue: formattedWithPercentage,dotColor: colorScheme.solid,},]}- showClickHint={isDefined(tooltipHref)}+ showClickHint={isDefined(to)}/>);};@@ -167,9 +177,9 @@ export const GraphWidgetGaugeChart = ({return (<StyledContainer>- <StyledChartContainer>+ <StyledChartContainer $isClickable={isDefined(to)}><ResponsiveRadialBar- data={data}+ data={chartData}startAngle={-90}endAngle={90}innerRadius={0.7}@@ -209,7 +219,7 @@ export const GraphWidgetGaugeChart = ({items={[{id: 'gauge',- label: legendLabel,+ label: label,formattedValue: formattedValue,color: colorScheme.solid,},diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetPieChart.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetPieChart.tsxindex 7dcd791e7dc..f364bb80f05 100644--- a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetPieChart.tsx+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetPieChart.tsx@@ -9,9 +9,10 @@ import {import { useState } from 'react';import { isDefined } from 'twenty-shared/utils';+import { type GraphColor } from '../types/GraphColor';import { createGradientDef } from '../utils/createGradientDef';import { createGraphColorRegistry } from '../utils/createGraphColorRegistry';-import { getColorSchemeByIndex } from '../utils/getColorSchemeByIndex';+import { getColorScheme } from '../utils/getColorScheme';import {formatGraphValue,type GraphValueFormatOptions,@@ -20,9 +21,14 @@ import { GraphWidgetLegend } from './GraphWidgetLegend';import { GraphWidgetTooltip } from './GraphWidgetTooltip';type GraphWidgetPieChartProps = {- data: Array<{ id: string; value: number; label?: string }>;+ data: Array<{+ id: string;+ value: number;+ label?: string;+ color?: GraphColor;+ to?: string;+ }>;showLegend?: boolean;- tooltipHref?: string;id: string;} & GraphValueFormatOptions;@@ -35,16 +41,23 @@ const StyledContainer = styled.div`width: 100%;`;-const StyledChartContainer = styled.div`+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,- tooltipHref,id,displayType,decimals,@@ -69,7 +82,7 @@ export const GraphWidgetPieChart = ({let cumulativeAngle = 0;const enrichedData = data.map((item, index) => {- const colorScheme = getColorSchemeByIndex(colorRegistry, index);+ const colorScheme = getColorScheme(colorRegistry, item.color, index);const isHovered = hoveredSliceId === item.id;const gradientId = `${colorScheme.name}Gradient-${id}-${index}`;const percentage = totalValue > 0 ? (item.value / totalValue) * 100 : 0;@@ -102,9 +115,12 @@ export const GraphWidgetPieChart = ({id: item.gradientId,}));- const handleSliceClick = () => {- if (isDefined(tooltipHref)) {- window.location.href = tooltipHref;+ const handleSliceClick = (+ datum: ComputedDatum<{ id: string; value: number; label?: string }>,+ ) => {+ const clickedItem = data.find((d) => d.id === datum.id);+ if (isDefined(clickedItem?.to)) {+ window.location.href = clickedItem.to;}};@@ -114,6 +130,7 @@ export const GraphWidgetPieChart = ({const item = enrichedData.find((d) => d.id === datum.id);if (!item) return null;+ const dataItem = data.find((d) => d.id === datum.id);const formattedValue = formatGraphValue(item.value, formatOptions);const formattedWithPercentage = `${formattedValue} (${item.percentage.toFixed(1)}%)`;@@ -126,7 +143,7 @@ export const GraphWidgetPieChart = ({dotColor: item.colorScheme.solid,},]}- showClickHint={isDefined(tooltipHref)}+ showClickHint={isDefined(dataItem?.to)}/>);};@@ -174,9 +191,11 @@ export const GraphWidgetPieChart = ({);};+ const hasClickableItems = data.some((item) => isDefined(item.to));+return (<StyledContainer id={id}>- <StyledChartContainer>+ <StyledChartContainer $isClickable={hasClickableItems}><ResponsivePiedata={data}innerRadius={0.8}diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetBarChart.stories.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetBarChart.stories.tsxnew file mode 100644index 00000000000..e9a5dc89604--- /dev/null+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetBarChart.stories.tsx@@ -0,0 +1,546 @@+import { type Meta, type StoryObj } from '@storybook/react';++import { CatalogDecorator, ComponentDecorator } from 'twenty-ui/testing';+import { GraphWidgetBarChart } from '../GraphWidgetBarChart';++const meta: Meta<typeof GraphWidgetBarChart> = {+ title: 'Modules/Dashboards/Graphs/GraphWidgetBarChart',+ component: GraphWidgetBarChart,+ decorators: [ComponentDecorator],+ parameters: {+ layout: 'centered',+ },+ argTypes: {+ data: {+ control: 'object',+ },+ indexBy: {+ control: 'text',+ },+ keys: {+ control: 'object',+ },+ series: {+ control: 'object',+ },+ displayType: {+ control: 'select',+ options: ['percentage', 'number', 'shortNumber', 'currency', 'custom'],+ },+ prefix: {+ control: 'text',+ },+ suffix: {+ control: 'text',+ },+ decimals: {+ control: 'number',+ },+ showLegend: {+ control: 'boolean',+ },+ showGrid: {+ control: 'boolean',+ },+ showValues: {+ control: 'boolean',+ },+ xAxisLabel: {+ control: 'text',+ },+ yAxisLabel: {+ control: 'text',+ },+ id: {+ control: 'text',+ },+ layout: {+ control: 'select',+ options: ['vertical', 'horizontal'],+ },+ groupMode: {+ control: 'select',+ options: ['grouped', 'stacked'],+ },+ seriesLabels: {+ control: 'object',+ },+ },+};++export default meta;+type Story = StoryObj<typeof GraphWidgetBarChart>;++const Container = ({ children }: { children: React.ReactNode }) => (+ <div style={{ width: '500px', height: '300px' }}>{children}</div>+);++export const Default: Story = {+ args: {+ data: [+ {+ month: 'Jan',+ sales: 120,+ leads: 45,+ conversions: 12,+ to: '/metrics/january',+ },+ {+ month: 'Feb',+ sales: 150,+ leads: 52,+ conversions: 15,+ to: '/metrics/february',+ },+ {+ month: 'Mar',+ sales: 180,+ leads: 48,+ conversions: 18,+ to: '/metrics/march',+ },+ {+ month: 'Apr',+ sales: 140,+ leads: 60,+ conversions: 14,+ to: '/metrics/april',+ },+ {+ month: 'May',+ sales: 200,+ leads: 55,+ conversions: 20,+ to: '/metrics/may',+ },+ ],+ indexBy: 'month',+ keys: ['sales', 'leads', 'conversions'],+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Month',+ yAxisLabel: 'Count',+ id: 'bar-chart-default',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const Revenue: Story = {+ args: {+ data: [+ {+ quarter: 'Q1',+ revenue: 420000,+ costs: 280000,+ profit: 140000,+ to: '/financials/q1',+ },+ {+ quarter: 'Q2',+ revenue: 480000,+ costs: 320000,+ profit: 160000,+ to: '/financials/q2',+ },+ {+ quarter: 'Q3',+ revenue: 520000,+ costs: 340000,+ profit: 180000,+ to: '/financials/q3',+ },+ {+ quarter: 'Q4',+ revenue: 580000,+ costs: 360000,+ profit: 220000,+ to: '/financials/q4',+ },+ ],+ indexBy: 'quarter',+ keys: ['revenue', 'costs', 'profit'],+ seriesLabels: {+ revenue: 'Total Revenue',+ costs: 'Operating Costs',+ profit: 'Net Profit',+ },+ displayType: 'shortNumber',+ prefix: '$',+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Quarter',+ yAxisLabel: 'Amount ($)',+ id: 'bar-chart-revenue',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const Stacked: Story = {+ args: {+ data: [+ {+ category: 'Website',+ desktop: 65,+ mobile: 35,+ tablet: 15,+ to: '/analytics/website',+ },+ {+ category: 'App',+ desktop: 25,+ mobile: 85,+ tablet: 30,+ to: '/analytics/app',+ },+ {+ category: 'Email',+ desktop: 45,+ mobile: 40,+ tablet: 20,+ to: '/analytics/email',+ },+ {+ category: 'Social',+ desktop: 30,+ mobile: 75,+ tablet: 25,+ to: '/analytics/social',+ },+ ],+ indexBy: 'category',+ keys: ['desktop', 'mobile', 'tablet'],+ seriesLabels: {+ desktop: 'Desktop',+ mobile: 'Mobile',+ tablet: 'Tablet',+ },+ groupMode: 'stacked',+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Channel',+ yAxisLabel: 'Users',+ id: 'bar-chart-stacked',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const Horizontal: Story = {+ args: {+ data: [+ { product: 'Product A', score: 85, to: '/products/a' },+ { product: 'Product B', score: 72, to: '/products/b' },+ { product: 'Product C', score: 90, to: '/products/c' },+ { product: 'Product D', score: 65, to: '/products/d' },+ { product: 'Product E', score: 78, to: '/products/e' },+ ],+ indexBy: 'product',+ keys: ['score'],+ layout: 'horizontal',+ showLegend: false,+ showGrid: true,+ xAxisLabel: 'Score',+ yAxisLabel: 'Product',+ suffix: '%',+ id: 'bar-chart-horizontal',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ layout={args.layout}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ suffix={args.suffix}+ id={args.id}+ />+ </Container>+ ),+};++export const WithValues: Story = {+ args: {+ data: [+ { team: 'Sales', performance: 92, target: 100, to: '/teams/sales' },+ {+ team: 'Marketing',+ performance: 78,+ target: 85,+ to: '/teams/marketing',+ },+ { team: 'Support', performance: 88, target: 90, to: '/teams/support' },+ {+ team: 'Development',+ performance: 95,+ target: 95,+ to: '/teams/development',+ },+ ],+ indexBy: 'team',+ keys: ['performance', 'target'],+ seriesLabels: {+ performance: 'Actual',+ target: 'Target',+ },+ showValues: true,+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Team',+ yAxisLabel: 'Score',+ suffix: '%',+ id: 'bar-chart-with-values',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const WithCustomColors: Story = {+ args: {+ data: [+ {+ month: 'Jan',+ sales: 120,+ leads: 45,+ conversions: 12,+ to: '/reports/jan',+ },+ {+ month: 'Feb',+ sales: 150,+ leads: 52,+ conversions: 15,+ to: '/reports/feb',+ },+ {+ month: 'Mar',+ sales: 180,+ leads: 48,+ conversions: 18,+ to: '/reports/mar',+ },+ {+ month: 'Apr',+ sales: 140,+ leads: 60,+ conversions: 14,+ to: '/reports/apr',+ },+ {+ month: 'May',+ sales: 200,+ leads: 55,+ conversions: 20,+ to: '/reports/may',+ },+ ],+ indexBy: 'month',+ keys: ['sales', 'leads', 'conversions'],+ series: [+ { key: 'sales', label: 'Total Sales', color: 'orange' },+ { key: 'leads', label: 'New Leads', color: 'turquoise' },+ { key: 'conversions', label: 'Conversions', color: 'pink' },+ ],+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Month',+ yAxisLabel: 'Count',+ id: 'bar-chart-custom-colors',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ series={args.series}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const SingleSeries: Story = {+ args: {+ data: [+ { day: 'Mon', visitors: 1200, to: '/traffic/monday' },+ { day: 'Tue', visitors: 1450, to: '/traffic/tuesday' },+ { day: 'Wed', visitors: 1800, to: '/traffic/wednesday' },+ { day: 'Thu', visitors: 1650, to: '/traffic/thursday' },+ { day: 'Fri', visitors: 2000, to: '/traffic/friday' },+ { day: 'Sat', visitors: 1100 },+ { day: 'Sun', visitors: 900 },+ ],+ indexBy: 'day',+ keys: ['visitors'],+ showLegend: false,+ showGrid: true,+ xAxisLabel: 'Day of Week',+ yAxisLabel: 'Visitors',+ displayType: 'shortNumber',+ id: 'bar-chart-single',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const Currency: Story = {+ args: {+ data: [+ { region: 'North', sales: 45000.5, budget: 50000, to: '/regions/north' },+ { region: 'South', sales: 38000.75, budget: 40000, to: '/regions/south' },+ { region: 'East', sales: 52000.25, budget: 48000, to: '/regions/east' },+ { region: 'West', sales: 41000, budget: 45000, to: '/regions/west' },+ ],+ indexBy: 'region',+ keys: ['sales', 'budget'],+ seriesLabels: {+ sales: 'Actual Sales',+ budget: 'Budget',+ },+ displayType: 'currency',+ decimals: 2,+ prefix: '$',+ showLegend: true,+ showGrid: true,+ xAxisLabel: 'Region',+ yAxisLabel: 'Amount',+ id: 'bar-chart-currency',+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy={args.indexBy}+ keys={args.keys}+ showLegend={args.showLegend}+ showGrid={args.showGrid}+ xAxisLabel={args.xAxisLabel}+ yAxisLabel={args.yAxisLabel}+ id={args.id}+ />+ </Container>+ ),+};++export const Catalog: Story = {+ decorators: [CatalogDecorator],+ parameters: {+ catalog: {+ dimensions: [+ {+ name: 'series',+ values: [1, 2, 3],+ props: (seriesCount: number) => {+ const baseData = [+ { category: 'A', series1: 30, series2: 45, series3: 20 },+ { category: 'B', series1: 40, series2: 35, series3: 25 },+ { category: 'C', series1: 25, series2: 50, series3: 30 },+ ];++ const keys = Array.from(+ { length: seriesCount },+ (_, i) => `series${i + 1}`,+ );++ return {+ data: baseData,+ keys,+ id: `bar-chart-catalog-${seriesCount}`,+ };+ },+ labels: (seriesCount: number) => `${seriesCount} series`,+ },+ {+ name: 'groupMode',+ values: ['grouped', 'stacked'],+ props: (mode: string) => ({+ groupMode: mode as 'grouped' | 'stacked',+ }),+ },+ ],+ },+ },+ render: (args) => (+ <Container>+ <GraphWidgetBarChart+ data={args.data}+ indexBy="category"+ keys={args.keys}+ groupMode={args.groupMode}+ showLegend={true}+ showGrid={true}+ id={args.id}+ />+ </Container>+ ),+};diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetGaugeChart.stories.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetGaugeChart.stories.tsxindex cd89c493020..d5df861278b 100644--- a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetGaugeChart.stories.tsx+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetGaugeChart.stories.tsx@@ -11,14 +11,8 @@ const meta: Meta<typeof GraphWidgetGaugeChart> = {layout: 'centered',},argTypes: {- value: {- control: { type: 'number' },- },- min: {- control: { type: 'number' },- },- max: {- control: { type: 'number' },+ data: {+ control: 'object',},displayType: {control: 'select',@@ -39,12 +33,6 @@ const meta: Meta<typeof GraphWidgetGaugeChart> = {showLegend: {control: 'boolean',},- legendLabel: {- control: 'text',- },- tooltipHref: {- control: 'text',- },id: {control: 'text',},@@ -58,31 +46,60 @@ const Container = ({ children }: { children: React.ReactNode }) => (<div style={{ width: '250px', height: '200px' }}>{children}</div>);+export const WithCustomColors: Story = {+ args: {+ data: {+ value: 75,+ min: 0,+ max: 100,+ color: 'purple',+ to: '/metrics/progress',+ label: 'Progress',+ },+ displayType: 'number',+ suffix: '%',+ showValue: true,+ id: 'gauge-chart-purple',+ },+ render: (args) => (+ <Container>+ <GraphWidgetGaugeChart+ data={args.data}+ displayType={args.displayType}+ decimals={args.decimals}+ prefix={args.prefix}+ suffix={args.suffix}+ showValue={args.showValue}+ showLegend={args.showLegend}+ id={args.id}+ />+ </Container>+ ),+};+export const Default: Story = {args: {- value: 0.5,- min: 0,- max: 1,+ data: {+ value: 0.5,+ min: 0,+ max: 1,+ to: '/metrics/conversion',+ label: 'Conversion rate',+ },displayType: 'percentage',showValue: true,- legendLabel: 'Conversion rate',- tooltipHref: 'https://example.com',id: 'gauge-chart-default',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -98,9 +115,13 @@ export const Catalog: Story = {name: 'value',values: [0, 25, 50, 75, 100],props: (value: number) => ({- value: value / 100,- min: 0,- max: 1,+ data: {+ value: value / 100,+ min: 0,+ max: 1,+ label: 'Percentage',+ to: '/metrics/catalog',+ },displayType: 'percentage' as const,id: `gauge-chart-catalog-${value}`,}),@@ -121,13 +142,9 @@ export const Catalog: Story = {render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}showValue={true}- legendLabel="Percentage"- tooltipHref="https://example.com"id="gauge-chart-catalog"/></Container>@@ -136,29 +153,27 @@ export const Catalog: Story = {export const WithoutValue: Story = {args: {- value: 65,- min: 0,- max: 100,+ data: {+ value: 65,+ min: 0,+ max: 100,+ to: '/metrics/conversion-without-value',+ label: 'Conversion rate',+ },displayType: 'percentage',showValue: false,- legendLabel: 'Conversion rate',- tooltipHref: 'https://example.com',id: 'gauge-chart-without-value',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -167,29 +182,27 @@ export const WithoutValue: Story = {export const Revenue: Story = {args: {- value: 750,- min: 0,- max: 1000,+ data: {+ value: 750,+ min: 0,+ max: 1000,+ to: '/financials/revenue',+ label: 'Revenue',+ },displayType: 'shortNumber',showValue: true,- legendLabel: 'Revenue',- tooltipHref: 'https://example.com',id: 'gauge-chart-revenue',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -198,29 +211,27 @@ export const Revenue: Story = {export const Temperature: Story = {args: {- value: 22,- min: -10,- max: 40,+ data: {+ value: 22,+ min: -10,+ max: 40,+ to: '/sensors/temperature',+ label: 'Temperature',+ },suffix: '°C',showValue: true,- legendLabel: 'Temperature',- tooltipHref: 'https://example.com',id: 'gauge-chart-temperature',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -229,29 +240,27 @@ export const Temperature: Story = {export const Storage: Story = {args: {- value: 384,- min: 0,- max: 512,+ data: {+ value: 384,+ min: 0,+ max: 512,+ to: '/system/storage',+ label: 'Storage Used',+ },suffix: ' GB',showValue: true,- legendLabel: 'Storage Used',- tooltipHref: 'https://example.com',id: 'gauge-chart-storage',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -260,30 +269,28 @@ export const Storage: Story = {export const Rating: Story = {args: {- value: 4.2,- min: 0,- max: 5,+ data: {+ value: 4.2,+ min: 0,+ max: 5,+ to: '/reviews/rating',+ label: 'Average Rating',+ },suffix: ' ⭐',decimals: 1,showValue: true,- legendLabel: 'Average Rating',- tooltipHref: 'https://example.com',id: 'gauge-chart-rating',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={args.showLegend}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -292,29 +299,27 @@ export const Rating: Story = {export const WithoutLegend: Story = {args: {- value: 65,- min: 0,- max: 100,+ data: {+ value: 65,+ min: 0,+ max: 100,+ to: '/metrics/conversion-no-legend',+ label: 'Conversion rate',+ },displayType: 'percentage',showValue: true,- legendLabel: 'Conversion rate',- tooltipHref: 'https://example.com',id: 'gauge-chart-without-legend',},render: (args) => (<Container><GraphWidgetGaugeChart- value={args.value}- min={args.min}- max={args.max}+ data={args.data}displayType={args.displayType}decimals={args.decimals}prefix={args.prefix}suffix={args.suffix}showValue={args.showValue}showLegend={false}- legendLabel={args.legendLabel}- tooltipHref={args.tooltipHref}id={args.id}/></Container>diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetPieChart.stories.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetPieChart.stories.tsxindex 2b476d80f3b..264b3bb470b 100644--- a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetPieChart.stories.tsx+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetPieChart.stories.tsx@@ -30,9 +30,6 @@ const meta: Meta<typeof GraphWidgetPieChart> = {showLegend: {control: 'boolean',},- tooltipHref: {- control: 'text',- },id: {control: 'text',},@@ -46,17 +43,93 @@ const Container = ({ children }: { children: React.ReactNode }) => (<div style={{ width: '300px', height: '300px' }}>{children}</div>);+export const WithCustomColors: Story = {+ args: {+ data: [+ {+ id: 'segment1',+ value: 30,+ label: 'Segment A',+ color: 'blue',+ to: '/segments/a',+ },+ {+ id: 'segment2',+ value: 25,+ label: 'Segment B',+ color: 'purple',+ to: '/segments/b',+ },+ {+ id: 'segment3',+ value: 20,+ label: 'Segment C',+ color: 'turquoise',+ to: '/segments/c',+ },+ {+ id: 'segment4',+ value: 15,+ label: 'Segment D',+ color: 'orange',+ to: '/segments/d',+ },+ {+ id: 'segment5',+ value: 10,+ label: 'Segment E',+ color: 'pink',+ to: '/segments/e',+ },+ ],+ showLegend: true,+ id: 'pie-chart-custom-colors',+ },+ render: (args) => (+ <Container>+ <GraphWidgetPieChart+ data={args.data}+ displayType={args.displayType}+ prefix={args.prefix}+ suffix={args.suffix}+ decimals={args.decimals}+ showLegend={args.showLegend}+ id={args.id}+ />+ </Container>+ ),+};+export const Default: Story = {args: {data: [- { id: 'qualified', value: 35, label: 'Qualified' },- { id: 'contacted', value: 25, label: 'Contacted' },- { id: 'unqualified', value: 20, label: 'Unqualified' },- { id: 'proposal', value: 15, label: 'Proposal' },- { id: 'negotiation', value: 5, label: 'Negotiation' },+ {+ id: 'qualified',+ value: 35,+ label: 'Qualified',+ to: '/leads/qualified',+ },+ {+ id: 'contacted',+ value: 25,+ label: 'Contacted',+ to: '/leads/contacted',+ },+ {+ id: 'unqualified',+ value: 20,+ label: 'Unqualified',+ to: '/leads/unqualified',+ },+ { id: 'proposal', value: 15, label: 'Proposal', to: '/leads/proposal' },+ {+ id: 'negotiation',+ value: 5,+ label: 'Negotiation',+ to: '/leads/negotiation',+ },],showLegend: true,- tooltipHref: 'https://example.com/leads',id: 'pie-chart-default',},render: (args) => (@@ -68,7 +141,6 @@ export const Default: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -78,15 +150,34 @@ export const Default: Story = {export const Revenue: Story = {args: {data: [- { id: 'product-a', value: 420000, label: 'Product A' },- { id: 'product-b', value: 380000, label: 'Product B' },- { id: 'product-c', value: 250000, label: 'Product C' },- { id: 'product-d', value: 180000, label: 'Product D' },+ {+ id: 'product-a',+ value: 420000,+ label: 'Product A',+ to: '/products/a/revenue',+ },+ {+ id: 'product-b',+ value: 380000,+ label: 'Product B',+ to: '/products/b/revenue',+ },+ {+ id: 'product-c',+ value: 250000,+ label: 'Product C',+ to: '/products/c/revenue',+ },+ {+ id: 'product-d',+ value: 180000,+ label: 'Product D',+ to: '/products/d/revenue',+ },],prefix: '$',displayType: 'shortNumber',showLegend: true,- tooltipHref: 'https://example.com/revenue',id: 'pie-chart-revenue',},render: (args) => (@@ -98,7 +189,6 @@ export const Revenue: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -108,13 +198,22 @@ export const Revenue: Story = {export const TaskStatus: Story = {args: {data: [- { id: 'completed', value: 45, label: 'Completed' },- { id: 'in-progress', value: 30, label: 'In Progress' },- { id: 'todo', value: 25, label: 'To Do' },+ {+ id: 'completed',+ value: 45,+ label: 'Completed',+ to: '/tasks/completed',+ },+ {+ id: 'in-progress',+ value: 30,+ label: 'In Progress',+ to: '/tasks/in-progress',+ },+ { id: 'todo', value: 25, label: 'To Do', to: '/tasks/todo' },],displayType: 'percentage',showLegend: true,- tooltipHref: 'https://example.com/tasks',id: 'pie-chart-task-status',},render: (args) => (@@ -126,7 +225,6 @@ export const TaskStatus: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -136,12 +234,11 @@ export const TaskStatus: Story = {export const TwoSlices: Story = {args: {data: [- { id: 'active', value: 75, label: 'Active' },- { id: 'inactive', value: 25, label: 'Inactive' },+ { id: 'active', value: 75, label: 'Active', to: '/users/active' },+ { id: 'inactive', value: 25, label: 'Inactive', to: '/users/inactive' },],displayType: 'percentage',showLegend: true,- tooltipHref: 'https://example.com/status',id: 'pie-chart-two-slices',},render: (args) => (@@ -153,7 +250,6 @@ export const TwoSlices: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -163,17 +259,16 @@ export const TwoSlices: Story = {export const ManySlices: Story = {args: {data: [- { id: 'category-1', value: 20, label: 'Category 1' },- { id: 'category-2', value: 18, label: 'Category 2' },- { id: 'category-3', value: 16, label: 'Category 3' },- { id: 'category-4', value: 14, label: 'Category 4' },- { id: 'category-5', value: 12, label: 'Category 5' },- { id: 'category-6', value: 10, label: 'Category 6' },+ { id: 'category-1', value: 20, label: 'Category 1', to: '/categories/1' },+ { id: 'category-2', value: 18, label: 'Category 2', to: '/categories/2' },+ { id: 'category-3', value: 16, label: 'Category 3', to: '/categories/3' },+ { id: 'category-4', value: 14, label: 'Category 4', to: '/categories/4' },+ { id: 'category-5', value: 12, label: 'Category 5', to: '/categories/5' },+ { id: 'category-6', value: 10, label: 'Category 6', to: '/categories/6' },{ id: 'category-7', value: 6, label: 'Category 7' },{ id: 'category-8', value: 4, label: 'Category 8' },],showLegend: true,- tooltipHref: 'https://example.com/categories',id: 'pie-chart-many-slices',},render: (args) => (@@ -185,7 +280,6 @@ export const ManySlices: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -195,13 +289,12 @@ export const ManySlices: Story = {export const WithoutLegend: Story = {args: {data: [- { id: 'web', value: 45, label: 'Web' },- { id: 'mobile', value: 35, label: 'Mobile' },- { id: 'desktop', value: 20, label: 'Desktop' },+ { id: 'web', value: 45, label: 'Web', to: '/platforms/web' },+ { id: 'mobile', value: 35, label: 'Mobile', to: '/platforms/mobile' },+ { id: 'desktop', value: 20, label: 'Desktop', to: '/platforms/desktop' },],displayType: 'percentage',showLegend: false,- tooltipHref: 'https://example.com/platforms',id: 'pie-chart-without-legend',},render: (args) => (@@ -213,7 +306,6 @@ export const WithoutLegend: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -223,14 +315,13 @@ export const WithoutLegend: Story = {export const MarketShare: Story = {args: {data: [- { id: 'brand-a', value: 35.5, label: 'Brand A' },- { id: 'brand-b', value: 28.2, label: 'Brand B' },- { id: 'brand-c', value: 18.7, label: 'Brand C' },- { id: 'others', value: 17.6, label: 'Others' },+ { id: 'brand-a', value: 35.5, label: 'Brand A', to: '/market/brand-a' },+ { id: 'brand-b', value: 28.2, label: 'Brand B', to: '/market/brand-b' },+ { id: 'brand-c', value: 18.7, label: 'Brand C', to: '/market/brand-c' },+ { id: 'others', value: 17.6, label: 'Others', to: '/market/others' },],displayType: 'percentage',showLegend: true,- tooltipHref: 'https://example.com/market',id: 'pie-chart-market-share',},render: (args) => (@@ -242,7 +333,6 @@ export const MarketShare: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>@@ -252,14 +342,23 @@ export const MarketShare: Story = {export const Storage: Story = {args: {data: [- { id: 'documents', value: 125, label: 'Documents' },- { id: 'media', value: 280, label: 'Media' },- { id: 'applications', value: 95, label: 'Applications' },- { id: 'system', value: 50, label: 'System' },+ {+ id: 'documents',+ value: 125,+ label: 'Documents',+ to: '/storage/documents',+ },+ { id: 'media', value: 280, label: 'Media', to: '/storage/media' },+ {+ id: 'applications',+ value: 95,+ label: 'Applications',+ to: '/storage/applications',+ },+ { id: 'system', value: 50, label: 'System', to: '/storage/system' },],suffix: ' GB',showLegend: true,- tooltipHref: 'https://example.com/storage',id: 'pie-chart-storage',},render: (args) => (@@ -271,7 +370,6 @@ export const Storage: Story = {suffix={args.suffix}decimals={args.decimals}showLegend={args.showLegend}- tooltipHref={args.tooltipHref}id={args.id}/></Container>diff --git a/packages/twenty-front/src/modules/dashboards/graphs/types/GraphColor.ts b/packages/twenty-front/src/modules/dashboards/graphs/types/GraphColor.tsnew file mode 100644index 00000000000..7599fceb6dc--- /dev/null+++ b/packages/twenty-front/src/modules/dashboards/graphs/types/GraphColor.ts@@ -0,0 +1 @@+export type GraphColor = 'blue' | 'purple' | 'turquoise' | 'orange' | 'pink';diff --git a/packages/twenty-front/src/modules/dashboards/graphs/utils/createGradientDef.ts b/packages/twenty-front/src/modules/dashboards/graphs/utils/createGradientDef.tsindex ad323ec0c5d..0be9ddc340b 100644--- a/packages/twenty-front/src/modules/dashboards/graphs/utils/createGradientDef.ts+++ b/packages/twenty-front/src/modules/dashboards/graphs/utils/createGradientDef.ts@@ -6,6 +6,7 @@ export const createGradientDef = (id: string,isHovered: boolean = false,angle?: number,+ reverseGradient: boolean = false,) => {const colors = isHovered? colorScheme.gradient.hover@@ -20,9 +21,14 @@ export const createGradientDef = (id,type: 'linearGradient' as const,...coords,- colors: [- { offset: 0, color: colors[0] },- { offset: 100, color: colors[1] },- ],+ colors: reverseGradient+ ? [+ { offset: 0, color: colors[1] },+ { offset: 100, color: colors[0] },+ ]+ : [+ { offset: 0, color: colors[0] },+ { offset: 100, color: colors[1] },+ ],};};diff --git a/packages/twenty-front/src/modules/dashboards/graphs/utils/getColorScheme.ts b/packages/twenty-front/src/modules/dashboards/graphs/utils/getColorScheme.tsnew file mode 100644index 00000000000..a98d7b47d27--- /dev/null+++ b/packages/twenty-front/src/modules/dashboards/graphs/utils/getColorScheme.ts@@ -0,0 +1,16 @@+import { isDefined } from 'twenty-shared/utils';+import { type GraphColor } from '../types/GraphColor';+import { type GraphColorRegistry } from '../types/GraphColorRegistry';+import { type GraphColorScheme } from '../types/GraphColorScheme';+import { getColorSchemeByIndex } from './getColorSchemeByIndex';++export const getColorScheme = (+ registry: GraphColorRegistry,+ colorName?: GraphColor,+ fallbackIndex?: number,+): GraphColorScheme => {+ if (isDefined(colorName) && isDefined(registry[colorName])) {+ return registry[colorName];+ }+ return getColorSchemeByIndex(registry, fallbackIndex || 0);+};diff --git a/yarn.lock b/yarn.lockindex 9c6ed657c5e..ee3eb558255 100644--- a/yarn.lock+++ b/yarn.lock@@ -9718,6 +9718,32 @@ __metadata:languageName: nodelinkType: hard+"@nivo/bar@npm:^0.99.0":+ version: 0.99.0+ resolution: "@nivo/bar@npm:0.99.0"+ dependencies:+ "@nivo/annotations": "npm:0.99.0"+ "@nivo/axes": "npm:0.99.0"+ "@nivo/canvas": "npm:0.99.0"+ "@nivo/colors": "npm:0.99.0"+ "@nivo/core": "npm:0.99.0"+ "@nivo/legends": "npm:0.99.0"+ "@nivo/scales": "npm:0.99.0"+ "@nivo/text": "npm:0.99.0"+ "@nivo/theming": "npm:0.99.0"+ "@nivo/tooltip": "npm:0.99.0"+ "@react-spring/web": "npm:9.4.5 || ^9.7.2 || ^10.0"+ "@types/d3-scale": "npm:^4.0.8"+ "@types/d3-shape": "npm:^3.1.6"+ d3-scale: "npm:^4.0.2"+ d3-shape: "npm:^3.2.0"+ lodash: "npm:^4.17.21"+ peerDependencies:+ react: ^16.14 || ^17.0 || ^18.0 || ^19.0+ checksum: 10c0/17860f18fed48b5c5d7a76e30b5be73481e810aa8bc417a5afc5c2350b1051ee7148bcd32f4444b6d8486839e9b9ffaa8c614b9a53d89196d4494703b0bd05c5+ languageName: node+ linkType: hard+"@nivo/calendar@npm:^0.99.0":version: 0.99.0resolution: "@nivo/calendar@npm:0.99.0"@@ -9740,6 +9766,13 @@ __metadata:languageName: nodelinkType: hard+"@nivo/canvas@npm:0.99.0":+ version: 0.99.0+ resolution: "@nivo/canvas@npm:0.99.0"+ checksum: 10c0/530f074b3368328b9bbadefaa64f5bdaafd210edb0c1446beed749ff4fa9ac805eae44418c88501ac137724db2c685e293da9d38067ea8e7fe9fd1aa500279d9+ languageName: node+ linkType: hard+"@nivo/colors@npm:0.99.0":version: 0.99.0resolution: "@nivo/colors@npm:0.99.0"@@ -50847,6 +50880,7 @@ __metadata:"@lingui/react": "npm:^5.1.2""@lingui/swc-plugin": "npm:^5.6.0""@lingui/vite-plugin": "npm:^5.1.2"+ "@nivo/bar": "npm:^0.99.0""@nivo/core": "npm:^0.99.0""@nivo/line": "npm:^0.99.0""@nivo/pie": "npm:^0.99.0"