diff --git a/.changeset/orange-charts-glow.md b/.changeset/orange-charts-glow.md new file mode 100644 index 0000000000..e9b31b359e --- /dev/null +++ b/.changeset/orange-charts-glow.md @@ -0,0 +1,5 @@ +--- +"@hyperdx/app": patch +--- + +feat(charts): switch to Observable categorical color palette for better accessibility and theme support diff --git a/packages/app/src/HDXMultiSeriesTimeChart.tsx b/packages/app/src/HDXMultiSeriesTimeChart.tsx index 9dc769782a..f2d1110538 100644 --- a/packages/app/src/HDXMultiSeriesTimeChart.tsx +++ b/packages/app/src/HDXMultiSeriesTimeChart.tsx @@ -453,7 +453,7 @@ export const MemoChart = memo(function MemoChart({ return !hasSelection || selectedSeriesNames.has(seriesName); }); - return limitedGroupKeys.map((key, i) => { + return limitedGroupKeys.map(key => { const lineDataIndex = lineData.findIndex(ld => ld.dataKey === key); const color = lineData[lineDataIndex]?.color; const strokeDasharray = lineData[lineDataIndex]?.isDashed ? '4 3' : '0'; @@ -495,7 +495,7 @@ export const MemoChart = memo(function MemoChart({ {...(isHovered ? { fill: 'none', strokeDasharray } : { - fill: `url(#time-chart-lin-grad-${id}-${color.replace('#', '').toLowerCase()})`, + fill: `url(#time-chart-lin-grad-${id}-${color?.replace('#', '').toLowerCase()})`, strokeDasharray, })} name={seriesName} diff --git a/packages/app/src/__tests__/ChartUtils.test.ts b/packages/app/src/__tests__/ChartUtils.test.ts index 72b263545b..53301f621d 100644 --- a/packages/app/src/__tests__/ChartUtils.test.ts +++ b/packages/app/src/__tests__/ChartUtils.test.ts @@ -10,6 +10,7 @@ import { convertToTimeChartConfig, formatResponseForTimeChart, } from '@/ChartUtils'; +import { CHART_COLOR_ERROR, COLORS } from '@/utils'; describe('ChartUtils', () => { describe('formatResponseForTimeChart', () => { @@ -122,7 +123,7 @@ describe('ChartUtils', () => { }); expect(actual.lineData).toEqual([ { - color: '#20c997', + color: COLORS[0], dataKey: 'AVG(toFloat64OrDefault(toString(Duration)))', currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration)))', previousPeriodKey: @@ -211,7 +212,7 @@ describe('ChartUtils', () => { }); expect(actual.lineData).toEqual([ { - color: '#20c997', + color: COLORS[0], dataKey: 'AVG(toFloat64OrDefault(toString(Duration))) · checkout', currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) · checkout', @@ -221,7 +222,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#8250dc', + color: COLORS[1], dataKey: 'max · checkout', currentPeriodKey: 'max · checkout', previousPeriodKey: 'max · checkout (previous)', @@ -229,7 +230,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#cdad7a', + color: COLORS[2], dataKey: 'AVG(toFloat64OrDefault(toString(Duration))) · shipping', currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) · shipping', @@ -239,7 +240,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#0d6efd', + color: COLORS[3], dataKey: 'max · shipping', currentPeriodKey: 'max · shipping', previousPeriodKey: 'max · shipping (previous)', @@ -299,7 +300,7 @@ describe('ChartUtils', () => { expect(actual.lineData).toEqual([ { - color: '#20c997', + color: COLORS[0], dataKey: 'info', currentPeriodKey: 'info', previousPeriodKey: 'info (previous)', @@ -307,7 +308,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#20c997', + color: COLORS[0], dataKey: 'debug', currentPeriodKey: 'debug', previousPeriodKey: 'debug (previous)', @@ -315,7 +316,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#F81358', + color: CHART_COLOR_ERROR, dataKey: 'error', currentPeriodKey: 'error', previousPeriodKey: 'error (previous)', @@ -403,7 +404,7 @@ describe('ChartUtils', () => { }); expect(actual.lineData).toEqual([ { - color: '#20c997', + color: COLORS[0], dataKey: 'AVG(toFloat64OrDefault(toString(Duration))) · checkout', currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) · checkout', @@ -413,7 +414,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#8250dc', + color: COLORS[1], dataKey: 'max · checkout', currentPeriodKey: 'max · checkout', previousPeriodKey: 'max · checkout (previous)', @@ -421,7 +422,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#cdad7a', + color: COLORS[2], dataKey: 'AVG(toFloat64OrDefault(toString(Duration))) · shipping', currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) · shipping', @@ -431,7 +432,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#0d6efd', + color: COLORS[3], dataKey: 'max · shipping', currentPeriodKey: 'max · shipping', previousPeriodKey: 'max · shipping (previous)', @@ -519,7 +520,7 @@ describe('ChartUtils', () => { }); expect(actual.lineData).toEqual([ { - color: '#20c997', + color: COLORS[0], currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration)))', previousPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) (previous)', @@ -528,7 +529,7 @@ describe('ChartUtils', () => { isDashed: false, }, { - color: '#20c997', + color: COLORS[0], currentPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration)))', previousPeriodKey: 'AVG(toFloat64OrDefault(toString(Duration))) (previous)', diff --git a/packages/app/src/components/DBDeltaChart.tsx b/packages/app/src/components/DBDeltaChart.tsx index 262f970ea3..c4961f91f9 100644 --- a/packages/app/src/components/DBDeltaChart.tsx +++ b/packages/app/src/components/DBDeltaChart.tsx @@ -27,7 +27,11 @@ import { import { isAggregateFunction } from '@/ChartUtils'; import { useQueriedChartConfig } from '@/hooks/useChartConfig'; import { getFirstTimestampValueExpression } from '@/source'; -import { truncateMiddle } from '@/utils'; +import { + CHART_COLOR_ERROR, + CHART_COLOR_SUCCESS, + truncateMiddle, +} from '@/utils'; import { SQLPreview } from './ChartSQLPreview'; @@ -246,13 +250,13 @@ function PropertyComparisonChart({ diff --git a/packages/app/src/components/DBRowTable.tsx b/packages/app/src/components/DBRowTable.tsx index 626d4c95eb..d95073f14c 100644 --- a/packages/app/src/components/DBRowTable.tsx +++ b/packages/app/src/components/DBRowTable.tsx @@ -84,6 +84,7 @@ import { UNDEFINED_WIDTH } from '@/tableUtils'; import { FormatTime } from '@/useFormatTime'; import { useUserPreferences } from '@/useUserPreferences'; import { + COLORS, getLogLevelClass, logLevelColor, useLocalStorage, @@ -232,14 +233,14 @@ export const PatternTrendChart = ({ isAnimationActive={false} dataKey="count" stackId="a" - fill={color || '#20c997'} + fill={color || COLORS[0]} maxBarSize={24} /> {/* */} } /> diff --git a/packages/app/src/components/DBTimeChart.tsx b/packages/app/src/components/DBTimeChart.tsx index e800f18c40..fb9098514f 100644 --- a/packages/app/src/components/DBTimeChart.tsx +++ b/packages/app/src/components/DBTimeChart.tsx @@ -685,8 +685,7 @@ function DBTimeChartComponent({