pass in colors

This commit is contained in:
Nate Kelley 2025-05-12 14:11:46 -06:00
parent d6b07d1cf1
commit 51ae682095
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 14 additions and 9 deletions

View File

@ -20,7 +20,9 @@ export interface Trendline {
| 'min'
| 'max'
| 'median'; //default is linear trend
trendLineColor?: string | null; //OPTIONAL: default is #000000
trendLineColor?: string | null | 'inherit'; //OPTIONAL: default is #000000
trendlineLabelPositionOffset?: number; //OPTIONAL: default is 0.85. Goes from 0 to 1.
columnId: string;
aggregateAllCategories?: boolean; //OPTIONAL: default is true. if true, the trendline will be calculated for all categories. if false, the trendline will be calculated for the category specified in the columnId.
id?: string;
}

View File

@ -6,26 +6,30 @@ import { formatLabel } from '@/lib/columnFormatter';
export const createTrendlineOnSeries = ({
trendlines,
yAxisKey,
color,
columnLabelFormats
}: {
trendlines: BusterChartProps['trendlines'];
yAxisKey: string;
color: string;
columnLabelFormats: NonNullable<BusterChartProps['columnLabelFormats']>;
}): TrendlineOptions[] | undefined => {
if (!trendlines || trendlines.length === 0) return undefined;
const relevantTrendlines = trendlines.filter(({ columnId }) => columnId === yAxisKey);
const relevantTrendlines = trendlines.filter(
({ columnId, aggregateAllCategories }) => columnId === yAxisKey && !aggregateAllCategories
);
return relevantTrendlines.map(
({ type, show, trendlineLabel, trendLineColor, showTrendlineLabel, columnId, ...rest }) => {
return {
type,
show,
colorMax: trendLineColor,
colorMin: trendLineColor,
colorMax: trendLineColor === 'inherit' ? color : trendLineColor,
colorMin: trendLineColor === 'inherit' ? color : trendLineColor,
label: showTrendlineLabel
? {
display: true,
text: (v) => {
if (!trendlineLabel) {
let value: number | null = null;
@ -40,7 +44,6 @@ export const createTrendlineOnSeries = ({
value = v.minY;
}
console.log(v);
const formattedValue = value
? formatLabel(value, columnLabelFormats[columnId])
: '';
@ -55,8 +58,7 @@ export const createTrendlineOnSeries = ({
}
return trendlineLabel;
}, //
display: true
}
}
: undefined
} satisfies TrendlineOptions;

View File

@ -82,6 +82,7 @@ export const scatterSeriesBuilder_data = ({
xAxisKeys,
trendline: createTrendlineOnSeries({
trendlines,
color,
yAxisKey: dataset.dataKey,
columnLabelFormats
}),

View File

@ -256,7 +256,7 @@ export const ScatterWithTrendline_NumericalXAxisPolynomialRegression: Story = {
show: true,
showTrendlineLabel: true,
trendlineLabel: null,
trendLineColor: 'red',
trendLineColor: 'inherit',
columnId: 'revenue'
},
{