UNPKG

@grafana/ui

Version:
1 lines 1.3 kB
{"version":3,"file":"hooks.mjs","sources":["../../../../src/graveyard/GraphNG/hooks.ts"],"sourcesContent":["import { createContext, useCallback, useContext } from 'react';\n\nimport { DataFrame, DataFrameFieldIndex, Field } from '@grafana/data';\n\nimport { XYFieldMatchers } from './types';\n\n/** @deprecated */\ninterface GraphNGContextType {\n mapSeriesIndexToDataFrameFieldIndex: (index: number) => DataFrameFieldIndex;\n dimFields: XYFieldMatchers;\n data: DataFrame;\n}\n\n/** @deprecated */\nexport const GraphNGContext = createContext<GraphNGContextType>({} as GraphNGContextType);\n\n/** @deprecated */\nexport const useGraphNGContext = () => {\n const { data, dimFields, mapSeriesIndexToDataFrameFieldIndex } = useContext<GraphNGContextType>(GraphNGContext);\n\n const getXAxisField = useCallback(() => {\n const xFieldMatcher = dimFields.x;\n let xField: Field | null = null;\n\n for (let j = 0; j < data.fields.length; j++) {\n if (xFieldMatcher(data.fields[j], data, [data])) {\n xField = data.fields[j];\n break;\n }\n }\n\n return xField;\n }, [data, dimFields]);\n\n return {\n dimFields,\n mapSeriesIndexToDataFrameFieldIndex,\n getXAxisField,\n alignedData: data,\n };\n};\n"],"names":[],"mappings":";;AAc8B,aAAkC,CAAA,EAAwB"}