Skip to content

Commit 140debb

Browse files
fix: color mapping provide default colors when none exist (#4008)
1 parent e16e8d8 commit 140debb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/visualization/types/Graph/view.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
lineTransform,
1313
LineLayerConfig,
1414
} from '@influxdata/giraffe'
15+
import memoizeOne from 'memoize-one'
1516

1617
// Components
1718
import EmptyGraphMessage from 'src/shared/components/EmptyGraphMessage'
@@ -196,12 +197,13 @@ const XYPlot: FC<Props> = ({
196197
let colorMapping = null
197198

198199
if (isFlagEnabled('graphColorMapping')) {
200+
const memoizedGetColorMappingObjects = memoizeOne(getColorMappingObjects)
199201
const [, fillColumnMap] = createGroupIDColumn(result.table, groupKey)
200202
const {
201203
colorMappingForGiraffe,
202204
colorMappingForIDPE,
203205
needsToSaveToIDPE,
204-
} = getColorMappingObjects(fillColumnMap, properties)
206+
} = memoizedGetColorMappingObjects(fillColumnMap, properties)
205207
colorMapping = colorMappingForGiraffe
206208

207209
// when the view is in a dashboard cell, and there is a need to save to IDPE, save it.

src/visualization/utils/colorMappingUtils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {XYViewProperties} from 'src/types'
22
import {addedDiff, deletedDiff} from 'deep-object-diff'
33
import {getNominalColorScale} from '@influxdata/giraffe'
4+
import {DEFAULT_LINE_COLORS} from 'src/shared/constants/graphColorPalettes'
45

56
/**
67
* Evaluates whether mappings need to be updated
@@ -158,8 +159,9 @@ export const generateSeriesToColorHex = (
158159
const cgMap = {...columnGroupMap}
159160
cgMap.mappings.forEach((graphLine, colorIndex) => {
160161
const id = getSeriesId(graphLine, columnGroupMap.columnKeys)
161-
const colors = properties.colors.map(value => value.hex)
162-
const fillScale = getNominalColorScale(columnGroupMap, colors)
162+
const colors = properties.colors ?? DEFAULT_LINE_COLORS
163+
const colorsHexArray = colors.map(value => value.hex)
164+
const fillScale = getNominalColorScale(columnGroupMap, colorsHexArray)
163165
seriesToColorHex[id] = fillScale(colorIndex)
164166
})
165167

0 commit comments

Comments
 (0)