diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/barSeriesBuilder.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/barSeriesBuilder.ts index 5a42b07e6..0ca7e1493 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/barSeriesBuilder.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/barSeriesBuilder.ts @@ -2,7 +2,7 @@ import { type ColumnLabelFormat, DEFAULT_COLUMN_LABEL_FORMAT } from '@buster/ser import type { BarElement } from 'chart.js'; import type { Context } from 'chartjs-plugin-datalabels'; import type { Options } from 'chartjs-plugin-datalabels/types/options'; -import { JOIN_CHARACTER } from '@/lib/axisFormatter'; +import { JOIN_CHARACTER, JOIN_CHARACTER_DATE } from '@/lib/axisFormatter'; import { formatLabel } from '@/lib/columnFormatter'; import type { BusterChartProps } from '../../../BusterChart.types'; import type { DatasetOption } from '../../../chartHooks'; @@ -351,9 +351,15 @@ const getFormattedValueAndSetBarDataLabels = ( export const barSeriesBuilder_labels = ({ datasetOptions, columnLabelFormats, -}: LabelBuilderProps) => { +}: Pick) => { const ticksKey = datasetOptions.ticksKey; + const containsADateStyle = datasetOptions.ticksKey.some((tick) => { + const selectedColumnLabelFormat = columnLabelFormats[tick.key]; + return selectedColumnLabelFormat?.style === 'date'; + }); + const selectedJoinCharacter = containsADateStyle ? JOIN_CHARACTER_DATE : JOIN_CHARACTER; + const labels = datasetOptions.ticks.flatMap((item) => { return item .map((item, index) => { @@ -361,7 +367,7 @@ export const barSeriesBuilder_labels = ({ const columnLabelFormat = columnLabelFormats[key]; return formatLabel(item, columnLabelFormat); }) - .join(JOIN_CHARACTER); + .join(selectedJoinCharacter); }); return labels; diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/comboSeriesBuilder.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/comboSeriesBuilder.ts index a98572d48..159879277 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/comboSeriesBuilder.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/comboSeriesBuilder.ts @@ -86,6 +86,4 @@ const renderBuilder: Record< dot: dotSeriesBuilder, }; -export const comboSeriesBuilder_labels = (props: LabelBuilderProps): (string | Date)[] => { - return lineSeriesBuilder_labels(props); -}; +export const comboSeriesBuilder_labels = lineSeriesBuilder_labels; diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts index 9a50a3249..d7665f2e9 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts @@ -42,6 +42,7 @@ vi.mock('@/lib/columnFormatter', () => ({ vi.mock('@/lib/axisFormatter', () => ({ JOIN_CHARACTER: ' | ', + JOIN_CHARACTER_DATE: ' ', })); vi.mock('../../helpers', () => ({ @@ -329,9 +330,9 @@ describe('lineSeriesBuilder', () => { const labels = lineSeriesBuilder_labels(props); expect(labels).toHaveLength(3); - expect(labels[0]).toBe('formatted-2023-01-01 | formatted-A'); - expect(labels[1]).toBe('formatted-2023-01-02 | formatted-B'); - expect(labels[2]).toBe('formatted-2023-01-03 | formatted-A'); + expect(labels[0]).toBe('formatted-2023-01-01 formatted-A'); + expect(labels[1]).toBe('formatted-2023-01-02 formatted-B'); + expect(labels[2]).toBe('formatted-2023-01-03 formatted-A'); expect(formatLabel).toHaveBeenCalledWith('2023-01-01', props.columnLabelFormats.date); expect(formatLabel).toHaveBeenCalledWith('A', props.columnLabelFormats.category); expect(formatLabel).toHaveBeenCalledWith('B', props.columnLabelFormats.category); @@ -342,9 +343,9 @@ describe('lineSeriesBuilder', () => { const labels = lineSeriesBuilder_labels(props); expect(labels).toHaveLength(3); - expect(labels[0]).toBe('formatted-2023-01-01 | formatted-A'); - expect(labels[1]).toBe('formatted-2023-01-02 | formatted-B'); - expect(labels[2]).toBe('formatted-2023-01-03 | formatted-A'); + expect(labels[0]).toBe('formatted-2023-01-01 formatted-A'); + expect(labels[1]).toBe('formatted-2023-01-02 formatted-B'); + expect(labels[2]).toBe('formatted-2023-01-03 formatted-A'); expect(formatLabel).toHaveBeenCalledWith('A', props.columnLabelFormats.category); expect(formatLabel).toHaveBeenCalledWith('B', props.columnLabelFormats.category); expect(formatLabel).toHaveBeenCalledWith('2023-01-01', props.columnLabelFormats.date); diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.ts index e10cb9fbb..616721c80 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.ts @@ -13,6 +13,7 @@ import { formatLabelForDataset } from '../../../commonHelpers'; import type { ChartProps } from '../../core'; import { formatBarAndLineDataLabel } from '../../helpers'; import { defaultLabelOptionConfig } from '../useChartSpecificOptions/labelOptionConfig'; +import { barSeriesBuilder_labels } from './barSeriesBuilder'; import { createTrendlineOnSeries } from './createTrendlines'; import type { SeriesBuilderProps } from './interfaces'; import type { LabelBuilderProps } from './useSeriesOptions'; @@ -219,7 +220,6 @@ export const lineSeriesBuilder_labels = ({ datasetOptions.ticks[0]?.length === 1 && xColumnLabelFormat.columnType === 'date' && xColumnLabelFormat.style === 'date'; - const ticksKey = datasetOptions.ticksKey; if (useDateLabels) { return datasetOptions.ticks.flatMap((item) => { @@ -229,13 +229,8 @@ export const lineSeriesBuilder_labels = ({ }); } - return datasetOptions.ticks.flatMap((item) => { - return item - .map((item, index) => { - const key = ticksKey[index]?.key || ''; - const columnLabelFormat = columnLabelFormats[key]; - return formatLabel(item, columnLabelFormat); - }) - .join(JOIN_CHARACTER); + return barSeriesBuilder_labels({ + datasetOptions, + columnLabelFormats, }); }; diff --git a/apps/web/src/lib/axisFormatter.ts b/apps/web/src/lib/axisFormatter.ts index 5b62ed968..758aa54bb 100644 --- a/apps/web/src/lib/axisFormatter.ts +++ b/apps/web/src/lib/axisFormatter.ts @@ -1,2 +1,3 @@ export const JOIN_CHARACTER = ' | '; export const AXIS_TITLE_SEPARATOR = JOIN_CHARACTER; +export const JOIN_CHARACTER_DATE = ' ';