UNPKG

@grafana/ui

Version:
1 lines 1.93 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":";;AAca,MAAA,cAAA,GAAiB,aAAkC,CAAA,EAAwB;AAGjF,MAAM,oBAAoB,MAAM;AACrC,EAAA,MAAM,EAAE,IAAM,EAAA,SAAA,EAAW,mCAAoC,EAAA,GAAI,WAA+B,cAAc,CAAA;AAE9G,EAAM,MAAA,aAAA,GAAgB,YAAY,MAAM;AACtC,IAAA,MAAM,gBAAgB,SAAU,CAAA,CAAA;AAChC,IAAA,IAAI,MAAuB,GAAA,IAAA;AAE3B,IAAA,KAAA,IAAS,IAAI,CAAG,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AAC3C,MAAI,IAAA,aAAA,CAAc,KAAK,MAAO,CAAA,CAAC,GAAG,IAAM,EAAA,CAAC,IAAI,CAAC,CAAG,EAAA;AAC/C,QAAS,MAAA,GAAA,IAAA,CAAK,OAAO,CAAC,CAAA;AACtB,QAAA;AAAA;AACF;AAGF,IAAO,OAAA,MAAA;AAAA,GACN,EAAA,CAAC,IAAM,EAAA,SAAS,CAAC,CAAA;AAEpB,EAAO,OAAA;AAAA,IACL,SAAA;AAAA,IACA,mCAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAa,EAAA;AAAA,GACf;AACF;;;;"}