1- import React , { FC } from 'react'
2-
1+ // Libraries
2+ import React , { FC , useMemo } from 'react'
33import {
44 Input ,
55 Grid ,
@@ -11,9 +11,11 @@ import {
1111 ComponentStatus ,
1212 ButtonShape ,
1313} from '@influxdata/clockface'
14+ import { createGroupIDColumn } from '@influxdata/giraffe'
1415
15- import AutoDomainInput from 'src/shared/components/AutoDomainInput'
1616import { AXES_SCALE_OPTIONS } from 'src/visualization/constants'
17+
18+ // Utils
1719import {
1820 FORMAT_OPTIONS ,
1921 resolveTimeFormat ,
@@ -23,6 +25,11 @@ import {
2325 defaultYColumn ,
2426 parseYBounds ,
2527} from 'src/shared/utils/vis'
28+ import { generateSeriesToColorHex } from 'src/visualization/utils/colorMappingUtils'
29+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
30+
31+ // Components
32+ import AutoDomainInput from 'src/shared/components/AutoDomainInput'
2633import ColorSchemeDropdown from 'src/visualization/components/internal/ColorSchemeDropdown'
2734import HoverLegend from 'src/visualization/components/internal/HoverLegend'
2835import StaticLegend from 'src/visualization/components/internal/StaticLegend'
@@ -48,6 +55,10 @@ const GraphViewOptions: FC<Props> = ({properties, results, update}) => {
4855 return columnType === 'time' || columnType === 'number'
4956 } )
5057
58+ const groupKey = useMemo ( ( ) => [ ...results . fluxGroupKeyUnion , 'result' ] , [
59+ results ,
60+ ] )
61+
5162 const xColumn = defaultXColumn ( results ?. table , properties . xColumn )
5263 const yColumn = defaultYColumn ( results ?. table , properties . yColumn )
5364 const getGeomLabel = ( geom : string ) : string => {
@@ -195,7 +206,20 @@ const GraphViewOptions: FC<Props> = ({properties, results, update}) => {
195206 < ColorSchemeDropdown
196207 value = { properties . colors ?. filter ( c => c . type === 'scale' ) ?? [ ] }
197208 onChange = { colors => {
198- update ( { colors} )
209+ if ( isFlagEnabled ( 'graphColorMapping' ) ) {
210+ const [ , fillColumnMap ] = createGroupIDColumn (
211+ results . table ,
212+ groupKey
213+ )
214+ const colorMapping = generateSeriesToColorHex (
215+ fillColumnMap ,
216+ properties
217+ )
218+
219+ update ( { colors, colorMapping} )
220+ } else {
221+ update ( { colors} )
222+ }
199223 } }
200224 />
201225 </ Form . Element >
0 commit comments