@elliemae/ds-dataviz 3.26.1-rc.0 → 3.27.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/graphs/Chart/ChartContext.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types.js';\nimport { defaultProps } from './react-desc-prop-types.js';\nimport type { ScaleT } from './scales/index.js';\ninterface ContextT {\n props: DSChartT.Props;\n originalSeries: DSChartT.SeriesT;\n currentData: DSChartT.InternalData;\n xScale: ScaleT;\n yScale: ScaleT;\n y2Scale: ScaleT;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: HTMLDivElement | null;\n setContainerRef: React.Dispatch<React.SetStateAction<SVGElement | null>>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastScrollbarPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n toolbarHeight: number;\n leftLegendHeight: number;\n rightLegendHeight: number;\n leftLabelHeight: number;\n leftLegendWidth: number;\n leftLabelWidth: number;\n leftLegend: SVGGElement;\n bottomLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n width: number;\n height: number;\n isZooming: boolean;\n zoomStartingPosition: number;\n movingPosition: number;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getXValueFormatted: (datum: DSChartT.InternalDatum) => string;\n getYValueFormatted: (datum: DSChartT.InternalDatum) => string;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n setContainerRatio: React.Dispatch<React.SetStateAction<number>>;\n setToolbarRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setMovingPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsZooming: React.Dispatch<React.SetStateAction<boolean>>;\n setZoomStartingPosition: React.Dispatch<React.SetStateAction<number>>;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAyC;AAEzC,gBAAqD;AAErD,mCAA6B;AAuF7B,MAAM,iBAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,YAAQ,qBAAU;AAAA,EAClB,YAAQ,uBAAY;AAAA,EACpB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,kBAAc,wBAA0B;AAAA,EACxC,QAAQ,CAAC;AAAA,EACT,gBAAY,wBAAa;AAAA,EACzB,gBAAgB,MAAM;AAAA,EAAC;AACzB;AACO,MAAM,mBAAe,4BAAc,cAAc;",
4
+ "sourcesContent": ["import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types.js';\nimport { defaultProps } from './react-desc-prop-types.js';\nimport type { ScaleT } from './scales/index.js';\ninterface ContextT {\n props: DSChartT.Props;\n originalSeries: DSChartT.SeriesT;\n currentData: DSChartT.InternalData;\n currentDataWithNullValues: DSChartT.InternalData;\n xScale: ScaleT;\n yScale: ScaleT;\n y2Scale: ScaleT;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: HTMLDivElement | null;\n setContainerRef: React.Dispatch<React.SetStateAction<SVGElement | null>>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastScrollbarPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n toolbarHeight: number;\n leftLegendHeight: number;\n rightLegendHeight: number;\n leftLabelHeight: number;\n leftLegendWidth: number;\n leftLabelWidth: number;\n leftLegend: SVGGElement;\n bottomLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n width: number;\n height: number;\n isZooming: boolean;\n zoomStartingPosition: number;\n movingPosition: number;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getXValueFormatted: (datum: DSChartT.InternalDatum) => string;\n getYValueFormatted: (datum: DSChartT.InternalDatum) => string;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n setContainerRatio: React.Dispatch<React.SetStateAction<number>>;\n setToolbarRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setMovingPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsZooming: React.Dispatch<React.SetStateAction<boolean>>;\n setZoomStartingPosition: React.Dispatch<React.SetStateAction<number>>;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAyC;AAEzC,gBAAqD;AAErD,mCAA6B;AAwF7B,MAAM,iBAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,YAAQ,qBAAU;AAAA,EAClB,YAAQ,uBAAY;AAAA,EACpB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,kBAAc,wBAA0B;AAAA,EACxC,QAAQ,CAAC;AAAA,EACT,gBAAY,wBAAa;AAAA,EACzB,gBAAgB,MAAM;AAAA,EAAC;AACzB;AACO,MAAM,mBAAe,4BAAc,cAAc;",
6
6
  "names": []
7
7
  }
@@ -154,8 +154,8 @@ const useChart = (props) => {
154
154
  }
155
155
  return "y";
156
156
  }, [xAxis.type, yAxis.type]);
157
- const currentData = (0, import_react.useMemo)(
158
- () => originalSeries.filter((serie) => !hiddenSeries.includes(serie.name)).map((d, i) => ({
157
+ const [currentDataWithNullValues, currentData] = (0, import_react.useMemo)(() => {
158
+ const baseData = originalSeries.filter((serie) => !hiddenSeries.includes(serie.name)).map((d, i) => ({
159
159
  ...d,
160
160
  // we set a default on the scale if the user do not pass it
161
161
  scale: d.scale || defaultScale,
@@ -166,11 +166,14 @@ const useChart = (props) => {
166
166
  position: index,
167
167
  serie: d.name,
168
168
  scale: d.scale
169
- })).filter((datum) => datum.value !== null && datum.value !== void 0)
170
- // basically converting from DSChartT.SeriesT to DSChartT.InternalData...
171
- })),
172
- [defaultScale, hiddenSeries, originalSeries]
173
- );
169
+ }))
170
+ }));
171
+ const currentDataWithoutNulls = baseData.map((data) => ({
172
+ ...data,
173
+ data: data.data.filter((datum) => datum.value !== null && datum.value !== void 0)
174
+ }));
175
+ return [baseData, currentDataWithoutNulls];
176
+ }, [defaultScale, hiddenSeries, originalSeries]);
174
177
  const isHorizontal = (0, import_react.useMemo)(() => yAxis?.type === "band", [yAxis]);
175
178
  const stackedData = (0, import_react.useMemo)(
176
179
  () => (0, import_helpers.stackData)(groupsStacked, originalSeries, hiddenSeries, isHorizontal),
@@ -280,7 +283,8 @@ const useChart = (props) => {
280
283
  leftLabelWidth,
281
284
  axisLeftWidth,
282
285
  topLegendHeight,
283
- leftLegendHeight
286
+ leftLegendHeight,
287
+ currentDataWithNullValues
284
288
  }),
285
289
  [
286
290
  props,
@@ -338,7 +342,8 @@ const useChart = (props) => {
338
342
  leftLabelWidth,
339
343
  axisLeftWidth,
340
344
  topLegendHeight,
341
- leftLegendHeight
345
+ leftLegendHeight,
346
+ currentDataWithNullValues
342
347
  ]
343
348
  );
344
349
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/graphs/Chart/config/useChart.tsx", "../../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport { uid } from 'uid';\nimport { debounce } from 'lodash';\nimport type { DSChartT } from '../react-desc-prop-types.js';\nimport { defaultProps, propTypes } from '../react-desc-prop-types.js';\nimport { useScales } from './useScales.js';\nimport { stackData } from '../helpers/index.js';\nimport { useInternalMargins } from './useInternalMargins.js';\nimport { useGetters } from './useGetters.js';\nimport ResizeObserver from 'resize-observer-polyfill';\nimport { useValidateProps } from './useValidateProps.js';\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (ref: HTMLElement | null | undefined) => {\n const [dimensions, setDimensions] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver(\n debounce((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.width));\n });\n }, 200),\n );\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [ref]);\n return dimensions;\n};\n\nexport const useChart = (props: DSChartT.Props) => {\n useValidateProps(props, propTypes);\n\n // const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;\n const userRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n const originalSeries = useMemo(() => {\n if (series.length === 0) {\n return defaultProps.series;\n }\n return series;\n }, [series]);\n const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);\n const svgRef = useRef(null);\n\n const dimensionWidth = useResizeObserver(containerRef);\n\n const width = useMemo(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);\n\n const height = useMemo(() => userHeight ?? 500, [userHeight]);\n\n const [isGrabbed, setIsGrabbed] = useState(false);\n const [startPosition, setStartPosition] = useState(0);\n\n // zoom\n\n const [isZooming, setIsZooming] = useState(false);\n const [zoomStartingPosition, setZoomStartingPosition] = useState(0);\n const [movingPosition, setMovingPosition] = useState(0);\n\n //\n\n const [activePoint, setActivePoint] = useState(null);\n const [activeSerie, setActiveSerie] = useState('');\n const [scrapperPosY, setScrapperPosY] = useState('');\n const [scrapperPosX, setScrapperPosX] = useState('');\n const [xScrollbarPosition, setXScrollbarPosition] = useState(0);\n const [isScrollbarVisible, setIsScrollbarVisible] = useState(false);\n const [containerRatio, setContainerRatio] = useState(userRatio);\n\n const lastScrollbarPosition = useRef(0);\n\n const [axisLeftRef, setAxisLeftRef] = useState<SVGGElement | null>(null);\n const [axisBottomRef, setAxisBottomRef] = useState<SVGGElement | null>(null);\n const [axisRightRef, setAxisRightRef] = useState<SVGGElement | null>(null);\n\n const [leftLegend, setLeftLegend] = useState<SVGGElement | null>(null);\n const [rightLegend, setRightLegend] = useState<SVGGElement | null>(null);\n const [topLegend, setTopLegend] = useState<SVGGElement | null>(null);\n const [bottomLegend, setBottomLegend] = useState<SVGGElement | null>(null);\n\n const [rightLabel, setRightLabel] = useState<SVGGElement | null>(null);\n const [leftLabel, setLeftLabel] = useState<SVGGElement | null>(null);\n const [bottomLabel, setBottomLabel] = useState<SVGGElement | null>(null);\n\n const [toolbarRef, setToolbarRef] = useState<SVGGElement | null>(null);\n\n // we reset the scrollbar position when the chart resize\n useEffect(() => {\n lastScrollbarPosition.current = 0;\n setXScrollbarPosition(0);\n }, [dimensionWidth]);\n\n useEffect(() => {\n setContainerRatio(userRatio);\n }, [userRatio]);\n\n const {\n toolbarHeight,\n axisBottomHeight,\n axisRightWidth,\n bottomLabelHeight,\n internalMargin,\n leftLegendWidth,\n rightLabelWidth,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n } = useInternalMargins({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n });\n\n const innerWidth = useMemo(\n () => width - internalMargin.left - internalMargin.right,\n [internalMargin.left, internalMargin.right, width],\n );\n const innerHeight = useMemo(\n () => height - internalMargin.top - internalMargin.bottom,\n [internalMargin.top, internalMargin.bottom, height],\n );\n\n const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);\n\n const defaultScale = useMemo(() => {\n if (yAxis.type === 'band') {\n return 'x';\n }\n\n if ([undefined, 'band'].includes(xAxis.type)) {\n return 'y';\n }\n\n return 'y';\n }, [xAxis.type, yAxis.type]);\n const currentData = useMemo(\n () =>\n originalSeries\n .filter((serie) => !hiddenSeries.includes(serie.name))\n .map((d, i) => ({\n ...d,\n // we set a default on the scale if the user do not pass it\n scale: d.scale || defaultScale,\n key: `${d.name}-${i}`,\n data: d.data\n .map((value, index) => ({\n key: `${d.name}-${i}-${index}`,\n value,\n position: index,\n serie: d.name,\n scale: d.scale,\n }))\n .filter((datum) => datum.value !== null && datum.value !== undefined), // basically converting from DSChartT.SeriesT to DSChartT.InternalData...\n })) as DSChartT.InternalData,\n [defaultScale, hiddenSeries, originalSeries],\n );\n\n const isHorizontal = useMemo(() => yAxis?.type === 'band', [yAxis]);\n\n const stackedData = useMemo(\n () => stackData(groupsStacked, originalSeries, hiddenSeries, isHorizontal),\n [groupsStacked, originalSeries, hiddenSeries, isHorizontal],\n );\n\n // @TODO we need to create a logic to get this from both axis\n // const containerRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n\n const groups = useMemo(() => currentData.map((serie) => serie.name), [currentData]);\n\n const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = useScales({\n props,\n originalSeries,\n innerHeight,\n innerWidth,\n groups,\n stackedData,\n currentData,\n containerRatio,\n });\n\n const { getXValue, getYValue, getXScaleValue, getYScaleValue, getYValueFormatted, getXValueFormatted } = useGetters({\n xAxis,\n yAxis,\n isHorizontal,\n xScale,\n yScale,\n y2Scale,\n });\n const chartId = useMemo(() => uid(6), []);\n\n return useMemo(\n () => ({\n props,\n originalSeries,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n svgRef,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n setScrapperPosY,\n scrapperPosX,\n setScrapperPosX,\n activePoint,\n setActivePoint,\n activeSerie,\n setActiveSerie,\n xScrollbarPosition,\n setXScrollbarPosition,\n isGrabbed,\n setIsGrabbed,\n setContainerRef,\n startPosition,\n setStartPosition,\n isScrollbarVisible,\n setIsScrollbarVisible,\n lastScrollbarPosition,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n setAxisLeftRef,\n setLeftLegend,\n setRightLegend,\n rightLegend,\n setTopLegend,\n setBottomLegend,\n setAxisBottomRef,\n axisBottomHeight,\n setAxisRightRef,\n setRightLabel,\n setBottomLabel,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n setLeftLabel,\n leftLabel,\n chartId,\n hiddenSeries,\n setHiddenSeries,\n height,\n width,\n setContainerRatio,\n toolbarHeight,\n setToolbarRef,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n }),\n [\n props,\n originalSeries,\n isZooming,\n zoomStartingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n scrapperPosX,\n activePoint,\n activeSerie,\n xScrollbarPosition,\n isGrabbed,\n startPosition,\n isScrollbarVisible,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n rightLegend,\n axisBottomHeight,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n leftLabel,\n chartId,\n hiddenSeries,\n height,\n width,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqD;AACrD,iBAAoB;AACpB,oBAAyB;AAEzB,mCAAwC;AACxC,uBAA0B;AAC1B,qBAA0B;AAC1B,gCAAmC;AACnC,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AA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport { uid } from 'uid';\nimport { debounce } from 'lodash';\nimport type { DSChartT } from '../react-desc-prop-types.js';\nimport { defaultProps, propTypes } from '../react-desc-prop-types.js';\nimport { useScales } from './useScales.js';\nimport { stackData } from '../helpers/index.js';\nimport { useInternalMargins } from './useInternalMargins.js';\nimport { useGetters } from './useGetters.js';\nimport ResizeObserver from 'resize-observer-polyfill';\nimport { useValidateProps } from './useValidateProps.js';\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (ref: HTMLElement | null | undefined) => {\n const [dimensions, setDimensions] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver(\n debounce((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.width));\n });\n }, 200),\n );\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [ref]);\n return dimensions;\n};\n\nexport const useChart = (props: DSChartT.Props) => {\n useValidateProps(props, propTypes);\n\n // const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;\n const userRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n const originalSeries = useMemo(() => {\n if (series.length === 0) {\n return defaultProps.series;\n }\n return series;\n }, [series]);\n const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);\n const svgRef = useRef(null);\n\n const dimensionWidth = useResizeObserver(containerRef);\n\n const width = useMemo(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);\n\n const height = useMemo(() => userHeight ?? 500, [userHeight]);\n\n const [isGrabbed, setIsGrabbed] = useState(false);\n const [startPosition, setStartPosition] = useState(0);\n\n // zoom\n\n const [isZooming, setIsZooming] = useState(false);\n const [zoomStartingPosition, setZoomStartingPosition] = useState(0);\n const [movingPosition, setMovingPosition] = useState(0);\n\n //\n\n const [activePoint, setActivePoint] = useState(null);\n const [activeSerie, setActiveSerie] = useState('');\n const [scrapperPosY, setScrapperPosY] = useState('');\n const [scrapperPosX, setScrapperPosX] = useState('');\n const [xScrollbarPosition, setXScrollbarPosition] = useState(0);\n const [isScrollbarVisible, setIsScrollbarVisible] = useState(false);\n const [containerRatio, setContainerRatio] = useState(userRatio);\n\n const lastScrollbarPosition = useRef(0);\n\n const [axisLeftRef, setAxisLeftRef] = useState<SVGGElement | null>(null);\n const [axisBottomRef, setAxisBottomRef] = useState<SVGGElement | null>(null);\n const [axisRightRef, setAxisRightRef] = useState<SVGGElement | null>(null);\n\n const [leftLegend, setLeftLegend] = useState<SVGGElement | null>(null);\n const [rightLegend, setRightLegend] = useState<SVGGElement | null>(null);\n const [topLegend, setTopLegend] = useState<SVGGElement | null>(null);\n const [bottomLegend, setBottomLegend] = useState<SVGGElement | null>(null);\n\n const [rightLabel, setRightLabel] = useState<SVGGElement | null>(null);\n const [leftLabel, setLeftLabel] = useState<SVGGElement | null>(null);\n const [bottomLabel, setBottomLabel] = useState<SVGGElement | null>(null);\n\n const [toolbarRef, setToolbarRef] = useState<SVGGElement | null>(null);\n\n // we reset the scrollbar position when the chart resize\n useEffect(() => {\n lastScrollbarPosition.current = 0;\n setXScrollbarPosition(0);\n }, [dimensionWidth]);\n\n useEffect(() => {\n setContainerRatio(userRatio);\n }, [userRatio]);\n\n const {\n toolbarHeight,\n axisBottomHeight,\n axisRightWidth,\n bottomLabelHeight,\n internalMargin,\n leftLegendWidth,\n rightLabelWidth,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n } = useInternalMargins({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n });\n\n const innerWidth = useMemo(\n () => width - internalMargin.left - internalMargin.right,\n [internalMargin.left, internalMargin.right, width],\n );\n const innerHeight = useMemo(\n () => height - internalMargin.top - internalMargin.bottom,\n [internalMargin.top, internalMargin.bottom, height],\n );\n\n const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);\n\n const defaultScale = useMemo(() => {\n if (yAxis.type === 'band') {\n return 'x';\n }\n\n if ([undefined, 'band'].includes(xAxis.type)) {\n return 'y';\n }\n\n return 'y';\n }, [xAxis.type, yAxis.type]);\n\n const [currentDataWithNullValues, currentData] = useMemo(() => {\n const baseData = originalSeries\n .filter((serie) => !hiddenSeries.includes(serie.name))\n .map((d, i) => ({\n ...d,\n // we set a default on the scale if the user do not pass it\n scale: d.scale || defaultScale,\n key: `${d.name}-${i}`,\n data: d.data.map((value, index) => ({\n key: `${d.name}-${i}-${index}`,\n value,\n position: index,\n serie: d.name,\n scale: d.scale,\n })),\n })) as DSChartT.InternalData;\n\n const currentDataWithoutNulls = baseData.map((data) => ({\n ...data,\n data: data.data.filter((datum) => datum.value !== null && datum.value !== undefined),\n }));\n\n return [baseData, currentDataWithoutNulls];\n }, [defaultScale, hiddenSeries, originalSeries]);\n\n const isHorizontal = useMemo(() => yAxis?.type === 'band', [yAxis]);\n\n const stackedData = useMemo(\n () => stackData(groupsStacked, originalSeries, hiddenSeries, isHorizontal),\n [groupsStacked, originalSeries, hiddenSeries, isHorizontal],\n );\n\n // @TODO we need to create a logic to get this from both axis\n // const containerRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n\n const groups = useMemo(() => currentData.map((serie) => serie.name), [currentData]);\n\n const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = useScales({\n props,\n originalSeries,\n innerHeight,\n innerWidth,\n groups,\n stackedData,\n currentData,\n containerRatio,\n });\n\n const { getXValue, getYValue, getXScaleValue, getYScaleValue, getYValueFormatted, getXValueFormatted } = useGetters({\n xAxis,\n yAxis,\n isHorizontal,\n xScale,\n yScale,\n y2Scale,\n });\n const chartId = useMemo(() => uid(6), []);\n\n return useMemo(\n () => ({\n props,\n originalSeries,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n svgRef,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n setScrapperPosY,\n scrapperPosX,\n setScrapperPosX,\n activePoint,\n setActivePoint,\n activeSerie,\n setActiveSerie,\n xScrollbarPosition,\n setXScrollbarPosition,\n isGrabbed,\n setIsGrabbed,\n setContainerRef,\n startPosition,\n setStartPosition,\n isScrollbarVisible,\n setIsScrollbarVisible,\n lastScrollbarPosition,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n setAxisLeftRef,\n setLeftLegend,\n setRightLegend,\n rightLegend,\n setTopLegend,\n setBottomLegend,\n setAxisBottomRef,\n axisBottomHeight,\n setAxisRightRef,\n setRightLabel,\n setBottomLabel,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n setLeftLabel,\n leftLabel,\n chartId,\n hiddenSeries,\n setHiddenSeries,\n height,\n width,\n setContainerRatio,\n toolbarHeight,\n setToolbarRef,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n currentDataWithNullValues,\n }),\n [\n props,\n originalSeries,\n isZooming,\n zoomStartingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n scrapperPosX,\n activePoint,\n activeSerie,\n xScrollbarPosition,\n isGrabbed,\n startPosition,\n isScrollbarVisible,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n rightLegend,\n axisBottomHeight,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n leftLabel,\n chartId,\n hiddenSeries,\n height,\n width,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n currentDataWithNullValues,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqD;AACrD,iBAAoB;AACpB,oBAAyB;AAEzB,mCAAwC;AACxC,uBAA0B;AAC1B,qBAA0B;AAC1B,gCAAmC;AACnC,wBAA2B;AAC3B,sCAA2B;AAC3B,8BAAiC;AAGjC,MAAM,oBAAoB,CAAC,QAAwC;AACjE,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAiB,CAAC;AAEtD,8BAAU,MAAM;AACd,QAAI,KAAK;AACP,YAAM,gBAAgB;AACtB,YAAM,iBAAiB,IAAI,gCAAAA;AAAA,YACzB,wBAAS,CAAC,YAA8C;AACtD,kBAAQ,QAAQ,CAAC,UAAU;AACzB,0BAAc,KAAK,KAAK,MAAM,YAAY,KAAK,CAAC;AAAA,UAClD,CAAC;AAAA,QACH,GAAG,GAAG;AAAA,MACR;AACA,qB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,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["ResizeObserver"]
7
7
  }
@@ -35,10 +35,11 @@ module.exports = __toCommonJS(useKeyboardNavigation_exports);
35
35
  var React = __toESM(require("react"));
36
36
  var import_react = require("react");
37
37
  var import_ChartContext = require("../ChartContext.js");
38
- const findInCircularList = (list, from, step = 1) => {
38
+ const findInCircularList = (list, from, step = 1, criteria = (item) => item !== void 0) => {
39
39
  for (let i = (from + step + list.length) % list.length; i !== from && from > -1; i = (i + step + list.length) % list.length) {
40
- if (list[i])
40
+ if (list[i] && criteria(i)) {
41
41
  return i;
42
+ }
42
43
  }
43
44
  return from;
44
45
  };
@@ -64,14 +65,14 @@ const useKeyboardNavigation = () => {
64
65
  setZoomStartingPosition,
65
66
  setMovingPosition,
66
67
  setContainerRatio,
67
- currentData: data,
68
+ currentDataWithNullValues,
68
69
  props: { xAxis, yAxis, xScroll, yScroll }
69
70
  } = (0, import_react.useContext)(import_ChartContext.ChartContext);
70
71
  const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;
71
72
  const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;
72
73
  const currentSerie = (0, import_react.useMemo)(
73
- () => data.find((d) => d.name === activePoint?.serie) ?? data[0],
74
- [activePoint?.serie, data]
74
+ () => currentDataWithNullValues.find((d) => d.name === activePoint?.serie) ?? currentDataWithNullValues[0],
75
+ [activePoint?.serie, currentDataWithNullValues]
75
76
  );
76
77
  const currentActiveItemIndex = (0, import_react.useMemo)(
77
78
  () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),
@@ -96,7 +97,7 @@ const useKeyboardNavigation = () => {
96
97
  const navigateSerie = (0, import_react.useCallback)(
97
98
  (step) => {
98
99
  const newValue = findInCircularList(
99
- currentSerie?.data.map((d) => d.value.toString()),
100
+ currentSerie?.data.map((d) => d.value?.toString()),
100
101
  currentActiveItemIndex,
101
102
  step
102
103
  );
@@ -155,17 +156,15 @@ const useKeyboardNavigation = () => {
155
156
  );
156
157
  const changeSerie = (0, import_react.useCallback)(
157
158
  (step) => {
158
- const nextSerie = data.find((d) => {
159
- const nextSerieIndex = findInCircularList(
160
- groups,
161
- groups.findIndex((item) => item === currentSerie.name),
162
- step
163
- );
164
- return d.name === groups[nextSerieIndex];
165
- });
166
- setActivePoint(nextSerie?.data[currentActiveItemIndex] || nextSerie?.data?.[0] || null);
159
+ const nextSerieIndex = findInCircularList(
160
+ groups,
161
+ groups.findIndex((item) => item === currentSerie.name),
162
+ step,
163
+ (idx) => currentDataWithNullValues[idx].data[currentActiveItemIndex].value !== null
164
+ );
165
+ setActivePoint(currentDataWithNullValues[nextSerieIndex].data[currentActiveItemIndex]);
167
166
  },
168
- [data, setActivePoint, currentActiveItemIndex, groups, currentSerie.name]
167
+ [groups, setActivePoint, currentActiveItemIndex, currentSerie.name, currentDataWithNullValues]
169
168
  );
170
169
  const onInputKeyDown = (0, import_react.useCallback)(
171
170
  (e) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/graphs/Chart/config/useKeyboardNavigation.tsx", "../../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../ChartContext.js';\n\nexport const findInCircularList = (\n list: string[],\n from: number,\n step = 1,\n // eslint-disable-next-line max-params\n): number => {\n for (\n let i = (from + step + list.length) % list.length;\n i !== from && from > -1;\n i = (i + step + list.length) % list.length\n ) {\n if (list[i]) return i;\n }\n return from; // return same item\n};\n\nexport const useKeyboardNavigation = () => {\n const {\n activePoint,\n setActivePoint,\n containerRef,\n xScale,\n yScale,\n lastScrollbarPosition,\n setXScrollbarPosition,\n containerRatio,\n xScrollbarPosition,\n innerWidth,\n innerHeight,\n getXScaleValue,\n getYScaleValue,\n groups,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n setContainerRatio,\n currentData: data,\n props: { xAxis, yAxis, xScroll, yScroll },\n } = useContext(ChartContext);\n\n const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;\n const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;\n\n const currentSerie = useMemo(\n () => data.find((d) => d.name === activePoint?.serie) ?? data[0],\n [activePoint?.serie, data],\n );\n\n const currentActiveItemIndex = useMemo(\n () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),\n [activePoint, currentSerie],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef === e.target && activePoint === null) {\n setActivePoint(currentSerie?.data[0]);\n setXScrollbarPosition(0);\n }\n },\n [activePoint, containerRef, currentSerie?.data, setActivePoint, setXScrollbarPosition],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n if (!containerRef?.contains(document.activeElement)) {\n setActivePoint(null);\n }\n });\n }, [setActivePoint, containerRef]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n step,\n );\n setActivePoint(currentSerie?.data[newValue]);\n\n if (xScrollable) {\n const xValue = getXScaleValue(currentSerie?.data[newValue]);\n if (xValue === undefined) return;\n const barWidth = innerWidth / containerRatio;\n const total = innerWidth * containerRatio;\n if (total <= xValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerWidth) / containerRatio);\n } else if (xValue > xScrollbarPosition * containerRatio + innerWidth)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (xValue / containerRatio - prev);\n if (nextPosition + barWidth > innerWidth) return innerWidth - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (xValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(xValue / containerRatio);\n }\n if (yScrollable) {\n const yValue = getYScaleValue(currentSerie?.data[newValue]);\n if (yValue === undefined) return;\n const barWidth = innerHeight / containerRatio;\n const total = innerHeight * containerRatio;\n if (total <= yValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerHeight) / containerRatio);\n } else if (yValue > xScrollbarPosition * containerRatio + innerHeight)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (yValue / containerRatio - prev);\n if (nextPosition + barWidth > innerHeight) return innerHeight - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (yValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(yValue / containerRatio);\n }\n },\n [\n currentSerie?.data,\n currentActiveItemIndex,\n setActivePoint,\n xScrollable,\n yScrollable,\n getXScaleValue,\n innerWidth,\n containerRatio,\n xScrollbarPosition,\n setXScrollbarPosition,\n getYScaleValue,\n innerHeight,\n ],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n const nextSerie = data.find((d) => {\n const nextSerieIndex = findInCircularList(\n groups,\n groups.findIndex((item) => item === currentSerie.name),\n step,\n );\n\n return d.name === groups[nextSerieIndex];\n });\n setActivePoint(nextSerie?.data[currentActiveItemIndex] || nextSerie?.data?.[0] || null);\n },\n [data, setActivePoint, currentActiveItemIndex, groups, currentSerie.name],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!activePoint) return;\n if (e.code !== 'Tab') {\n e.preventDefault();\n }\n if (['ArrowLeft', 'ArrowRight'].includes(e.code)) {\n if (yScale.type === 'BAND') changeSerie(e.code === 'ArrowLeft' ? -1 : 1);\n else navigateSerie(e.code === 'ArrowLeft' ? -1 : 1);\n }\n\n if (['ArrowDown', 'ArrowUp'].includes(e.code)) {\n if (yScale.type === 'BAND') navigateSerie(e.code === 'ArrowDown' ? 1 : -1);\n else changeSerie(e.code === 'ArrowDown' ? -1 : 1);\n }\n\n const { code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (isShiftKey && !isZooming && !xScale.type === 'BAND') {\n setIsZooming(true);\n setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n },\n [\n activePoint,\n changeSerie,\n containerRatio,\n getXScaleValue,\n isZooming,\n navigateSerie,\n setIsZooming,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n yScale.type,\n ],\n );\n\n const handleOnKeyUp: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!isZooming && xScale.type === 'BAND') return false;\n const { shiftKey, code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (shiftKey && ['ArrowRight', 'ArrowLeft'].includes(code)) {\n setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n if (isShiftKey) {\n setIsZooming(false);\n setZoomStartingPosition(0);\n setMovingPosition(0);\n const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;\n // isRightDirection is used to know if we are zooming right or left direction\n const isRightDirection = zoomStartingPosition < endingPosition;\n const offsetActivePoint = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n isRightDirection ? 1 : -1,\n );\n // we do this so the activePoint does not fall into the blur gradient\n const correctEndingPosition =\n getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;\n const diff = Math.abs(zoomStartingPosition - correctEndingPosition);\n if (diff <= 0) return;\n const newRatio =\n innerWidth / ((innerWidth * containerRatio) / diff) < 40\n ? innerWidth / 40\n : (innerWidth * containerRatio) / diff;\n const newPosition =\n lastScrollbarPosition?.current +\n (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;\n\n // if is bigger thant innerwidth possible we force the end\n if (newPosition > innerWidth - innerWidth / newRatio) setXScrollbarPosition(innerWidth - innerWidth / newRatio);\n else setXScrollbarPosition(newPosition);\n setActivePoint(null);\n setTimeout(() => setActivePoint(activePoint));\n setContainerRatio(newRatio);\n lastScrollbarPosition.current = newPosition;\n }\n },\n [\n activePoint,\n containerRatio,\n currentActiveItemIndex,\n currentSerie?.data,\n getXScaleValue,\n innerWidth,\n isZooming,\n lastScrollbarPosition,\n setActivePoint,\n setContainerRatio,\n setIsZooming,\n setMovingPosition,\n setXScrollbarPosition,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n zoomStartingPosition,\n ],\n );\n return useMemo(\n () => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),\n [handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAiD;AACjD,0BAA6B;AAEtB,MAAM,qBAAqB,CAChC,MACA,MACA,OAAO,MAEI;AACX,WACM,KAAK,OAAO,OAAO,KAAK,UAAU,KAAK,QAC3C,MAAM,QAAQ,OAAO,IACrB,KAAK,IAAI,OAAO,KAAK,UAAU,KAAK,QACpC;AACA,QAAI,KAAK,CAAC;AAAG,aAAO;AAAA,EACtB;AACA,SAAO;AACT;AAEO,MAAM,wBAAwB,MAAM;AACzC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,OAAO,EAAE,OAAO,OAAO,SAAS,QAAQ;AAAA,EAC1C,QAAI,yBAAW,gCAAY;AAE3B,QAAM,cAAc,MAAM,UAAU,cAAc,QAAQ,KAAK;AAC/D,QAAM,cAAc,MAAM,UAAU,cAAc,QAAQ,KAAK;AAE/D,QAAM,mBAAe;AAAA,IACnB,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,SAAS,aAAa,KAAK,KAAK,KAAK,CAAC;AAAA,IAC/D,CAAC,aAAa,OAAO,IAAI;AAAA,EAC3B;AAEA,QA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SAAS,CAAC;AAAA,UAChD;AAAA,UACA,mBAAmB,IAAI;AAAA,QACzB;AAEA,cAAM,wBACJ,eAAe,cAAc,KAAK,iBAAiB,CAAC,IAAI,qBAAqB;AAC/E,cAAM,OAAO,KAAK,IAAI,uBAAuB,qBAAqB;AAClE,YAAI,QAAQ;AAAG;AACf,cAAM,WACJ,cAAe,aAAa,iBAAkB,QAAQ,KAClD,aAAa,KACZ,aAAa,iBAAkB;AACtC,cAAM,cACJ,uBAAuB,WACtB,CAAC,mBAAmB,wBAAwB,wBAAwB;AAGvE,YAAI,cAAc,aAAa,aAAa;AAAU,gCAAsB,aAAa,aAAa,QAAQ;AAAA;AACzG,gCAAsB,WAAW;AACtC,uBAAe,IAAI;AACnB,mBAAW,MAAM,eAAe,WAAW,CAAC;AAC5C,0BAAkB,QAAQ;AAC1B,8BAAsB,UAAU;AAAA,MAClC;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,aAAO;AAAA,IACL,OAAO,EAAE,eAAe,gBAAgB,cAAc,cAAc;AAAA,IACpE,CAAC,cAAc,eAAe,eAAe,cAAc;AAAA,EAC7D;AACF;",
4
+ "sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../ChartContext.js';\n\nexport const findInCircularList = (\n list: string[],\n from: number,\n step = 1,\n criteria = (item: number) => item !== undefined,\n // eslint-disable-next-line max-params\n): number => {\n for (\n let i = (from + step + list.length) % list.length;\n i !== from && from > -1;\n i = (i + step + list.length) % list.length\n ) {\n if (list[i] && criteria(i)) {\n return i;\n }\n }\n return from; // return same item\n};\n\nexport const useKeyboardNavigation = () => {\n const {\n activePoint,\n setActivePoint,\n containerRef,\n xScale,\n yScale,\n lastScrollbarPosition,\n setXScrollbarPosition,\n containerRatio,\n xScrollbarPosition,\n innerWidth,\n innerHeight,\n getXScaleValue,\n getYScaleValue,\n groups,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n setContainerRatio,\n currentDataWithNullValues,\n props: { xAxis, yAxis, xScroll, yScroll },\n } = useContext(ChartContext);\n\n const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;\n const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;\n\n const currentSerie = useMemo(\n () => currentDataWithNullValues.find((d) => d.name === activePoint?.serie) ?? currentDataWithNullValues[0],\n [activePoint?.serie, currentDataWithNullValues],\n );\n\n const currentActiveItemIndex = useMemo(\n () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),\n [activePoint, currentSerie],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef === e.target && activePoint === null) {\n setActivePoint(currentSerie?.data[0]);\n setXScrollbarPosition(0);\n }\n },\n [activePoint, containerRef, currentSerie?.data, setActivePoint, setXScrollbarPosition],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n if (!containerRef?.contains(document.activeElement)) {\n setActivePoint(null);\n }\n });\n }, [setActivePoint, containerRef]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentSerie?.data.map((d) => d.value?.toString()),\n currentActiveItemIndex,\n step,\n );\n setActivePoint(currentSerie?.data[newValue]);\n\n if (xScrollable) {\n const xValue = getXScaleValue(currentSerie?.data[newValue]);\n if (xValue === undefined) return;\n const barWidth = innerWidth / containerRatio;\n const total = innerWidth * containerRatio;\n if (total <= xValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerWidth) / containerRatio);\n } else if (xValue > xScrollbarPosition * containerRatio + innerWidth)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (xValue / containerRatio - prev);\n if (nextPosition + barWidth > innerWidth) return innerWidth - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (xValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(xValue / containerRatio);\n }\n if (yScrollable) {\n const yValue = getYScaleValue(currentSerie?.data[newValue]);\n if (yValue === undefined) return;\n const barWidth = innerHeight / containerRatio;\n const total = innerHeight * containerRatio;\n if (total <= yValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerHeight) / containerRatio);\n } else if (yValue > xScrollbarPosition * containerRatio + innerHeight)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (yValue / containerRatio - prev);\n if (nextPosition + barWidth > innerHeight) return innerHeight - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (yValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(yValue / containerRatio);\n }\n },\n [\n currentSerie?.data,\n currentActiveItemIndex,\n setActivePoint,\n xScrollable,\n yScrollable,\n getXScaleValue,\n innerWidth,\n containerRatio,\n xScrollbarPosition,\n setXScrollbarPosition,\n getYScaleValue,\n innerHeight,\n ],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n const nextSerieIndex = findInCircularList(\n groups,\n groups.findIndex((item) => item === currentSerie.name),\n step,\n (idx: number) => currentDataWithNullValues[idx].data[currentActiveItemIndex].value !== null,\n );\n setActivePoint(currentDataWithNullValues[nextSerieIndex].data[currentActiveItemIndex]);\n },\n [groups, setActivePoint, currentActiveItemIndex, currentSerie.name, currentDataWithNullValues],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!activePoint) return;\n if (e.code !== 'Tab') {\n e.preventDefault();\n }\n if (['ArrowLeft', 'ArrowRight'].includes(e.code)) {\n if (yScale.type === 'BAND') changeSerie(e.code === 'ArrowLeft' ? -1 : 1);\n else navigateSerie(e.code === 'ArrowLeft' ? -1 : 1);\n }\n\n if (['ArrowDown', 'ArrowUp'].includes(e.code)) {\n if (yScale.type === 'BAND') navigateSerie(e.code === 'ArrowDown' ? 1 : -1);\n else changeSerie(e.code === 'ArrowDown' ? -1 : 1);\n }\n\n const { code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (isShiftKey && !isZooming && !xScale.type === 'BAND') {\n setIsZooming(true);\n setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n },\n [\n activePoint,\n changeSerie,\n containerRatio,\n getXScaleValue,\n isZooming,\n navigateSerie,\n setIsZooming,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n yScale.type,\n ],\n );\n\n const handleOnKeyUp: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!isZooming && xScale.type === 'BAND') return false;\n const { shiftKey, code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (shiftKey && ['ArrowRight', 'ArrowLeft'].includes(code)) {\n setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n if (isShiftKey) {\n setIsZooming(false);\n setZoomStartingPosition(0);\n setMovingPosition(0);\n const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;\n // isRightDirection is used to know if we are zooming right or left direction\n const isRightDirection = zoomStartingPosition < endingPosition;\n const offsetActivePoint = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n isRightDirection ? 1 : -1,\n );\n // we do this so the activePoint does not fall into the blur gradient\n const correctEndingPosition =\n getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;\n const diff = Math.abs(zoomStartingPosition - correctEndingPosition);\n if (diff <= 0) return;\n const newRatio =\n innerWidth / ((innerWidth * containerRatio) / diff) < 40\n ? innerWidth / 40\n : (innerWidth * containerRatio) / diff;\n const newPosition =\n lastScrollbarPosition?.current +\n (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;\n\n // if is bigger thant innerwidth possible we force the end\n if (newPosition > innerWidth - innerWidth / newRatio) setXScrollbarPosition(innerWidth - innerWidth / newRatio);\n else setXScrollbarPosition(newPosition);\n setActivePoint(null);\n setTimeout(() => setActivePoint(activePoint));\n setContainerRatio(newRatio);\n lastScrollbarPosition.current = newPosition;\n }\n },\n [\n activePoint,\n containerRatio,\n currentActiveItemIndex,\n currentSerie?.data,\n getXScaleValue,\n innerWidth,\n isZooming,\n lastScrollbarPosition,\n setActivePoint,\n setContainerRatio,\n setIsZooming,\n setMovingPosition,\n setXScrollbarPosition,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n zoomStartingPosition,\n ],\n );\n return useMemo(\n () => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),\n [handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAiD;AACjD,0BAA6B;AAEtB,MAAM,qBAAqB,CAChC,MACA,MACA,OAAO,GACP,WAAW,CAAC,SAAiB,SAAS,WAE3B;AACX,WACM,KAAK,OAAO,OAAO,KAAK,UAAU,KAAK,QAC3C,MAAM,QAAQ,OAAO,IACrB,KAAK,IAAI,OAAO,KAAK,UAAU,KAAK,QACpC;AACA,QAAI,KAAK,CAAC,KAAK,SAAS,CAAC,GAAG;AAC1B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,wBAAwB,MAAM;AACzC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,I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;AAAA,IACF;AAAA,EACF;AACA,aAAO;AAAA,IACL,OAAO,EAAE,eAAe,gBAAgB,cAAc,cAAc;AAAA,IACpE,CAAC,cAAc,eAAe,eAAe,cAAc;AAAA,EAC7D;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/graphs/Chart/ChartContext.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types.js';\nimport { defaultProps } from './react-desc-prop-types.js';\nimport type { ScaleT } from './scales/index.js';\ninterface ContextT {\n props: DSChartT.Props;\n originalSeries: DSChartT.SeriesT;\n currentData: DSChartT.InternalData;\n xScale: ScaleT;\n yScale: ScaleT;\n y2Scale: ScaleT;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: HTMLDivElement | null;\n setContainerRef: React.Dispatch<React.SetStateAction<SVGElement | null>>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastScrollbarPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n toolbarHeight: number;\n leftLegendHeight: number;\n rightLegendHeight: number;\n leftLabelHeight: number;\n leftLegendWidth: number;\n leftLabelWidth: number;\n leftLegend: SVGGElement;\n bottomLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n width: number;\n height: number;\n isZooming: boolean;\n zoomStartingPosition: number;\n movingPosition: number;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getXValueFormatted: (datum: DSChartT.InternalDatum) => string;\n getYValueFormatted: (datum: DSChartT.InternalDatum) => string;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n setContainerRatio: React.Dispatch<React.SetStateAction<number>>;\n setToolbarRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setMovingPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsZooming: React.Dispatch<React.SetStateAction<boolean>>;\n setZoomStartingPosition: React.Dispatch<React.SetStateAction<number>>;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,eAAe,iBAAiB;AAEzC,SAAS,aAAa,WAAW,oBAAoB;AAErD,SAAS,oBAAoB;AAuF7B,MAAM,iBAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ,UAAU;AAAA,EAClB,QAAQ,YAAY;AAAA,EACpB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,cAAc,UAA0B;AAAA,EACxC,QAAQ,CAAC;AAAA,EACT,YAAY,aAAa;AAAA,EACzB,gBAAgB,MAAM;AAAA,EAAC;AACzB;AACO,MAAM,eAAe,cAAc,cAAc;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types.js';\nimport { defaultProps } from './react-desc-prop-types.js';\nimport type { ScaleT } from './scales/index.js';\ninterface ContextT {\n props: DSChartT.Props;\n originalSeries: DSChartT.SeriesT;\n currentData: DSChartT.InternalData;\n currentDataWithNullValues: DSChartT.InternalData;\n xScale: ScaleT;\n yScale: ScaleT;\n y2Scale: ScaleT;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: HTMLDivElement | null;\n setContainerRef: React.Dispatch<React.SetStateAction<SVGElement | null>>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastScrollbarPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n toolbarHeight: number;\n leftLegendHeight: number;\n rightLegendHeight: number;\n leftLabelHeight: number;\n leftLegendWidth: number;\n leftLabelWidth: number;\n leftLegend: SVGGElement;\n bottomLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n width: number;\n height: number;\n isZooming: boolean;\n zoomStartingPosition: number;\n movingPosition: number;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getXValueFormatted: (datum: DSChartT.InternalDatum) => string;\n getYValueFormatted: (datum: DSChartT.InternalDatum) => string;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n setContainerRatio: React.Dispatch<React.SetStateAction<number>>;\n setToolbarRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setMovingPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsZooming: React.Dispatch<React.SetStateAction<boolean>>;\n setZoomStartingPosition: React.Dispatch<React.SetStateAction<number>>;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,eAAe,iBAAiB;AAEzC,SAAS,aAAa,WAAW,oBAAoB;AAErD,SAAS,oBAAoB;AAwF7B,MAAM,iBAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ,UAAU;AAAA,EAClB,QAAQ,YAAY;AAAA,EACpB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,cAAc,UAA0B;AAAA,EACxC,QAAQ,CAAC;AAAA,EACT,YAAY,aAAa;AAAA,EACzB,gBAAgB,MAAM;AAAA,EAAC;AACzB;AACO,MAAM,eAAe,cAAc,cAAc;",
6
6
  "names": []
7
7
  }
@@ -121,8 +121,8 @@ const useChart = (props) => {
121
121
  }
122
122
  return "y";
123
123
  }, [xAxis.type, yAxis.type]);
124
- const currentData = useMemo(
125
- () => originalSeries.filter((serie) => !hiddenSeries.includes(serie.name)).map((d, i) => ({
124
+ const [currentDataWithNullValues, currentData] = useMemo(() => {
125
+ const baseData = originalSeries.filter((serie) => !hiddenSeries.includes(serie.name)).map((d, i) => ({
126
126
  ...d,
127
127
  // we set a default on the scale if the user do not pass it
128
128
  scale: d.scale || defaultScale,
@@ -133,11 +133,14 @@ const useChart = (props) => {
133
133
  position: index,
134
134
  serie: d.name,
135
135
  scale: d.scale
136
- })).filter((datum) => datum.value !== null && datum.value !== void 0)
137
- // basically converting from DSChartT.SeriesT to DSChartT.InternalData...
138
- })),
139
- [defaultScale, hiddenSeries, originalSeries]
140
- );
136
+ }))
137
+ }));
138
+ const currentDataWithoutNulls = baseData.map((data) => ({
139
+ ...data,
140
+ data: data.data.filter((datum) => datum.value !== null && datum.value !== void 0)
141
+ }));
142
+ return [baseData, currentDataWithoutNulls];
143
+ }, [defaultScale, hiddenSeries, originalSeries]);
141
144
  const isHorizontal = useMemo(() => yAxis?.type === "band", [yAxis]);
142
145
  const stackedData = useMemo(
143
146
  () => stackData(groupsStacked, originalSeries, hiddenSeries, isHorizontal),
@@ -247,7 +250,8 @@ const useChart = (props) => {
247
250
  leftLabelWidth,
248
251
  axisLeftWidth,
249
252
  topLegendHeight,
250
- leftLegendHeight
253
+ leftLegendHeight,
254
+ currentDataWithNullValues
251
255
  }),
252
256
  [
253
257
  props,
@@ -305,7 +309,8 @@ const useChart = (props) => {
305
309
  leftLabelWidth,
306
310
  axisLeftWidth,
307
311
  topLegendHeight,
308
- leftLegendHeight
312
+ leftLegendHeight,
313
+ currentDataWithNullValues
309
314
  ]
310
315
  );
311
316
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useChart.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport { uid } from 'uid';\nimport { debounce } from 'lodash';\nimport type { DSChartT } from '../react-desc-prop-types.js';\nimport { defaultProps, propTypes } from '../react-desc-prop-types.js';\nimport { useScales } from './useScales.js';\nimport { stackData } from '../helpers/index.js';\nimport { useInternalMargins } from './useInternalMargins.js';\nimport { useGetters } from './useGetters.js';\nimport ResizeObserver from 'resize-observer-polyfill';\nimport { useValidateProps } from './useValidateProps.js';\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (ref: HTMLElement | null | undefined) => {\n const [dimensions, setDimensions] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver(\n debounce((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.width));\n });\n }, 200),\n );\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [ref]);\n return dimensions;\n};\n\nexport const useChart = (props: DSChartT.Props) => {\n useValidateProps(props, propTypes);\n\n // const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;\n const userRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n const originalSeries = useMemo(() => {\n if (series.length === 0) {\n return defaultProps.series;\n }\n return series;\n }, [series]);\n const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);\n const svgRef = useRef(null);\n\n const dimensionWidth = useResizeObserver(containerRef);\n\n const width = useMemo(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);\n\n const height = useMemo(() => userHeight ?? 500, [userHeight]);\n\n const [isGrabbed, setIsGrabbed] = useState(false);\n const [startPosition, setStartPosition] = useState(0);\n\n // zoom\n\n const [isZooming, setIsZooming] = useState(false);\n const [zoomStartingPosition, setZoomStartingPosition] = useState(0);\n const [movingPosition, setMovingPosition] = useState(0);\n\n //\n\n const [activePoint, setActivePoint] = useState(null);\n const [activeSerie, setActiveSerie] = useState('');\n const [scrapperPosY, setScrapperPosY] = useState('');\n const [scrapperPosX, setScrapperPosX] = useState('');\n const [xScrollbarPosition, setXScrollbarPosition] = useState(0);\n const [isScrollbarVisible, setIsScrollbarVisible] = useState(false);\n const [containerRatio, setContainerRatio] = useState(userRatio);\n\n const lastScrollbarPosition = useRef(0);\n\n const [axisLeftRef, setAxisLeftRef] = useState<SVGGElement | null>(null);\n const [axisBottomRef, setAxisBottomRef] = useState<SVGGElement | null>(null);\n const [axisRightRef, setAxisRightRef] = useState<SVGGElement | null>(null);\n\n const [leftLegend, setLeftLegend] = useState<SVGGElement | null>(null);\n const [rightLegend, setRightLegend] = useState<SVGGElement | null>(null);\n const [topLegend, setTopLegend] = useState<SVGGElement | null>(null);\n const [bottomLegend, setBottomLegend] = useState<SVGGElement | null>(null);\n\n const [rightLabel, setRightLabel] = useState<SVGGElement | null>(null);\n const [leftLabel, setLeftLabel] = useState<SVGGElement | null>(null);\n const [bottomLabel, setBottomLabel] = useState<SVGGElement | null>(null);\n\n const [toolbarRef, setToolbarRef] = useState<SVGGElement | null>(null);\n\n // we reset the scrollbar position when the chart resize\n useEffect(() => {\n lastScrollbarPosition.current = 0;\n setXScrollbarPosition(0);\n }, [dimensionWidth]);\n\n useEffect(() => {\n setContainerRatio(userRatio);\n }, [userRatio]);\n\n const {\n toolbarHeight,\n axisBottomHeight,\n axisRightWidth,\n bottomLabelHeight,\n internalMargin,\n leftLegendWidth,\n rightLabelWidth,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n } = useInternalMargins({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n });\n\n const innerWidth = useMemo(\n () => width - internalMargin.left - internalMargin.right,\n [internalMargin.left, internalMargin.right, width],\n );\n const innerHeight = useMemo(\n () => height - internalMargin.top - internalMargin.bottom,\n [internalMargin.top, internalMargin.bottom, height],\n );\n\n const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);\n\n const defaultScale = useMemo(() => {\n if (yAxis.type === 'band') {\n return 'x';\n }\n\n if ([undefined, 'band'].includes(xAxis.type)) {\n return 'y';\n }\n\n return 'y';\n }, [xAxis.type, yAxis.type]);\n const currentData = useMemo(\n () =>\n originalSeries\n .filter((serie) => !hiddenSeries.includes(serie.name))\n .map((d, i) => ({\n ...d,\n // we set a default on the scale if the user do not pass it\n scale: d.scale || defaultScale,\n key: `${d.name}-${i}`,\n data: d.data\n .map((value, index) => ({\n key: `${d.name}-${i}-${index}`,\n value,\n position: index,\n serie: d.name,\n scale: d.scale,\n }))\n .filter((datum) => datum.value !== null && datum.value !== undefined), // basically converting from DSChartT.SeriesT to DSChartT.InternalData...\n })) as DSChartT.InternalData,\n [defaultScale, hiddenSeries, originalSeries],\n );\n\n const isHorizontal = useMemo(() => yAxis?.type === 'band', [yAxis]);\n\n const stackedData = useMemo(\n () => stackData(groupsStacked, originalSeries, hiddenSeries, isHorizontal),\n [groupsStacked, originalSeries, hiddenSeries, isHorizontal],\n );\n\n // @TODO we need to create a logic to get this from both axis\n // const containerRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n\n const groups = useMemo(() => currentData.map((serie) => serie.name), [currentData]);\n\n const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = useScales({\n props,\n originalSeries,\n innerHeight,\n innerWidth,\n groups,\n stackedData,\n currentData,\n containerRatio,\n });\n\n const { getXValue, getYValue, getXScaleValue, getYScaleValue, getYValueFormatted, getXValueFormatted } = useGetters({\n xAxis,\n yAxis,\n isHorizontal,\n xScale,\n yScale,\n y2Scale,\n });\n const chartId = useMemo(() => uid(6), []);\n\n return useMemo(\n () => ({\n props,\n originalSeries,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n svgRef,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n setScrapperPosY,\n scrapperPosX,\n setScrapperPosX,\n activePoint,\n setActivePoint,\n activeSerie,\n setActiveSerie,\n xScrollbarPosition,\n setXScrollbarPosition,\n isGrabbed,\n setIsGrabbed,\n setContainerRef,\n startPosition,\n setStartPosition,\n isScrollbarVisible,\n setIsScrollbarVisible,\n lastScrollbarPosition,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n setAxisLeftRef,\n setLeftLegend,\n setRightLegend,\n rightLegend,\n setTopLegend,\n setBottomLegend,\n setAxisBottomRef,\n axisBottomHeight,\n setAxisRightRef,\n setRightLabel,\n setBottomLabel,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n setLeftLabel,\n leftLabel,\n chartId,\n hiddenSeries,\n setHiddenSeries,\n height,\n width,\n setContainerRatio,\n toolbarHeight,\n setToolbarRef,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n }),\n [\n props,\n originalSeries,\n isZooming,\n zoomStartingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n scrapperPosX,\n activePoint,\n activeSerie,\n xScrollbarPosition,\n isGrabbed,\n startPosition,\n isScrollbarVisible,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n rightLegend,\n axisBottomHeight,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n leftLabel,\n chartId,\n hiddenSeries,\n height,\n width,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n ],\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,UAAU,WAAW,cAAc;AACrD,SAAS,WAAW;AACpB,SAAS,gBAAgB;AAEzB,SAAS,cAAc,iBAAiB;AACxC,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,OAAO,oBAAoB;AAC3B,SAAS,wBAAwB;AAGjC,MAAM,oBA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;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport { uid } from 'uid';\nimport { debounce } from 'lodash';\nimport type { DSChartT } from '../react-desc-prop-types.js';\nimport { defaultProps, propTypes } from '../react-desc-prop-types.js';\nimport { useScales } from './useScales.js';\nimport { stackData } from '../helpers/index.js';\nimport { useInternalMargins } from './useInternalMargins.js';\nimport { useGetters } from './useGetters.js';\nimport ResizeObserver from 'resize-observer-polyfill';\nimport { useValidateProps } from './useValidateProps.js';\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (ref: HTMLElement | null | undefined) => {\n const [dimensions, setDimensions] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver(\n debounce((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.width));\n });\n }, 200),\n );\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [ref]);\n return dimensions;\n};\n\nexport const useChart = (props: DSChartT.Props) => {\n useValidateProps(props, propTypes);\n\n // const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;\n const userRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n const originalSeries = useMemo(() => {\n if (series.length === 0) {\n return defaultProps.series;\n }\n return series;\n }, [series]);\n const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);\n const svgRef = useRef(null);\n\n const dimensionWidth = useResizeObserver(containerRef);\n\n const width = useMemo(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);\n\n const height = useMemo(() => userHeight ?? 500, [userHeight]);\n\n const [isGrabbed, setIsGrabbed] = useState(false);\n const [startPosition, setStartPosition] = useState(0);\n\n // zoom\n\n const [isZooming, setIsZooming] = useState(false);\n const [zoomStartingPosition, setZoomStartingPosition] = useState(0);\n const [movingPosition, setMovingPosition] = useState(0);\n\n //\n\n const [activePoint, setActivePoint] = useState(null);\n const [activeSerie, setActiveSerie] = useState('');\n const [scrapperPosY, setScrapperPosY] = useState('');\n const [scrapperPosX, setScrapperPosX] = useState('');\n const [xScrollbarPosition, setXScrollbarPosition] = useState(0);\n const [isScrollbarVisible, setIsScrollbarVisible] = useState(false);\n const [containerRatio, setContainerRatio] = useState(userRatio);\n\n const lastScrollbarPosition = useRef(0);\n\n const [axisLeftRef, setAxisLeftRef] = useState<SVGGElement | null>(null);\n const [axisBottomRef, setAxisBottomRef] = useState<SVGGElement | null>(null);\n const [axisRightRef, setAxisRightRef] = useState<SVGGElement | null>(null);\n\n const [leftLegend, setLeftLegend] = useState<SVGGElement | null>(null);\n const [rightLegend, setRightLegend] = useState<SVGGElement | null>(null);\n const [topLegend, setTopLegend] = useState<SVGGElement | null>(null);\n const [bottomLegend, setBottomLegend] = useState<SVGGElement | null>(null);\n\n const [rightLabel, setRightLabel] = useState<SVGGElement | null>(null);\n const [leftLabel, setLeftLabel] = useState<SVGGElement | null>(null);\n const [bottomLabel, setBottomLabel] = useState<SVGGElement | null>(null);\n\n const [toolbarRef, setToolbarRef] = useState<SVGGElement | null>(null);\n\n // we reset the scrollbar position when the chart resize\n useEffect(() => {\n lastScrollbarPosition.current = 0;\n setXScrollbarPosition(0);\n }, [dimensionWidth]);\n\n useEffect(() => {\n setContainerRatio(userRatio);\n }, [userRatio]);\n\n const {\n toolbarHeight,\n axisBottomHeight,\n axisRightWidth,\n bottomLabelHeight,\n internalMargin,\n leftLegendWidth,\n rightLabelWidth,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n } = useInternalMargins({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n });\n\n const innerWidth = useMemo(\n () => width - internalMargin.left - internalMargin.right,\n [internalMargin.left, internalMargin.right, width],\n );\n const innerHeight = useMemo(\n () => height - internalMargin.top - internalMargin.bottom,\n [internalMargin.top, internalMargin.bottom, height],\n );\n\n const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);\n\n const defaultScale = useMemo(() => {\n if (yAxis.type === 'band') {\n return 'x';\n }\n\n if ([undefined, 'band'].includes(xAxis.type)) {\n return 'y';\n }\n\n return 'y';\n }, [xAxis.type, yAxis.type]);\n\n const [currentDataWithNullValues, currentData] = useMemo(() => {\n const baseData = originalSeries\n .filter((serie) => !hiddenSeries.includes(serie.name))\n .map((d, i) => ({\n ...d,\n // we set a default on the scale if the user do not pass it\n scale: d.scale || defaultScale,\n key: `${d.name}-${i}`,\n data: d.data.map((value, index) => ({\n key: `${d.name}-${i}-${index}`,\n value,\n position: index,\n serie: d.name,\n scale: d.scale,\n })),\n })) as DSChartT.InternalData;\n\n const currentDataWithoutNulls = baseData.map((data) => ({\n ...data,\n data: data.data.filter((datum) => datum.value !== null && datum.value !== undefined),\n }));\n\n return [baseData, currentDataWithoutNulls];\n }, [defaultScale, hiddenSeries, originalSeries]);\n\n const isHorizontal = useMemo(() => yAxis?.type === 'band', [yAxis]);\n\n const stackedData = useMemo(\n () => stackData(groupsStacked, originalSeries, hiddenSeries, isHorizontal),\n [groupsStacked, originalSeries, hiddenSeries, isHorizontal],\n );\n\n // @TODO we need to create a logic to get this from both axis\n // const containerRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n\n const groups = useMemo(() => currentData.map((serie) => serie.name), [currentData]);\n\n const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = useScales({\n props,\n originalSeries,\n innerHeight,\n innerWidth,\n groups,\n stackedData,\n currentData,\n containerRatio,\n });\n\n const { getXValue, getYValue, getXScaleValue, getYScaleValue, getYValueFormatted, getXValueFormatted } = useGetters({\n xAxis,\n yAxis,\n isHorizontal,\n xScale,\n yScale,\n y2Scale,\n });\n const chartId = useMemo(() => uid(6), []);\n\n return useMemo(\n () => ({\n props,\n originalSeries,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n svgRef,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n setScrapperPosY,\n scrapperPosX,\n setScrapperPosX,\n activePoint,\n setActivePoint,\n activeSerie,\n setActiveSerie,\n xScrollbarPosition,\n setXScrollbarPosition,\n isGrabbed,\n setIsGrabbed,\n setContainerRef,\n startPosition,\n setStartPosition,\n isScrollbarVisible,\n setIsScrollbarVisible,\n lastScrollbarPosition,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n setAxisLeftRef,\n setLeftLegend,\n setRightLegend,\n rightLegend,\n setTopLegend,\n setBottomLegend,\n setAxisBottomRef,\n axisBottomHeight,\n setAxisRightRef,\n setRightLabel,\n setBottomLabel,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n setLeftLabel,\n leftLabel,\n chartId,\n hiddenSeries,\n setHiddenSeries,\n height,\n width,\n setContainerRatio,\n toolbarHeight,\n setToolbarRef,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n currentDataWithNullValues,\n }),\n [\n props,\n originalSeries,\n isZooming,\n zoomStartingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n scrapperPosX,\n activePoint,\n activeSerie,\n xScrollbarPosition,\n isGrabbed,\n startPosition,\n isScrollbarVisible,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n rightLegend,\n axisBottomHeight,\n getXScaleValue,\n getYScaleValue,\n getYValueFormatted,\n getXValueFormatted,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n leftLabel,\n chartId,\n hiddenSeries,\n height,\n width,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n currentDataWithNullValues,\n ],\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,UAAU,WAAW,cAAc;AACrD,SAAS,WAAW;AACpB,SAAS,gBAAgB;AAEzB,SAAS,cAAc,iBAAiB;AACxC,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,OAAO,oBAAoB;AAC3B,SAAS,wBAAwB;AAGjC,MAAM,oBAAoB,CAAC,QAAwC;AACjE,QAAM,CAAC,YAAY,aAAa,IAAI,SAAiB,CAAC;AAEtD,YAAU,MAAM;AACd,QAAI,KAAK;AACP,YAAM,gBAAgB;AACtB,YAAM,iBAAiB,IAAI;AAAA,QACzB,SAAS,CAAC,YAA8C;AACtD,kBAAQ,QAAQ,CAAC,UAAU;AACzB,0BAAc,KAAK,KAAK,MAAM,YAAY,KAAK,CAAC;AAAA,UAClD,CAAC;AAAA,QACH,GAAG,GAAG;AAAA,MACR;AACA,qBAAe,QAAQ,aAAa;AAEpC,aAAO,MAAM;AACX,uBAAe,UAAU,aAAa;AAAA,MACxC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,GAAG,CAAC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ACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,10 +1,11 @@
1
1
  import * as React from "react";
2
2
  import { useCallback, useContext, useMemo } from "react";
3
3
  import { ChartContext } from "../ChartContext.js";
4
- const findInCircularList = (list, from, step = 1) => {
4
+ const findInCircularList = (list, from, step = 1, criteria = (item) => item !== void 0) => {
5
5
  for (let i = (from + step + list.length) % list.length; i !== from && from > -1; i = (i + step + list.length) % list.length) {
6
- if (list[i])
6
+ if (list[i] && criteria(i)) {
7
7
  return i;
8
+ }
8
9
  }
9
10
  return from;
10
11
  };
@@ -30,14 +31,14 @@ const useKeyboardNavigation = () => {
30
31
  setZoomStartingPosition,
31
32
  setMovingPosition,
32
33
  setContainerRatio,
33
- currentData: data,
34
+ currentDataWithNullValues,
34
35
  props: { xAxis, yAxis, xScroll, yScroll }
35
36
  } = useContext(ChartContext);
36
37
  const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;
37
38
  const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;
38
39
  const currentSerie = useMemo(
39
- () => data.find((d) => d.name === activePoint?.serie) ?? data[0],
40
- [activePoint?.serie, data]
40
+ () => currentDataWithNullValues.find((d) => d.name === activePoint?.serie) ?? currentDataWithNullValues[0],
41
+ [activePoint?.serie, currentDataWithNullValues]
41
42
  );
42
43
  const currentActiveItemIndex = useMemo(
43
44
  () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),
@@ -62,7 +63,7 @@ const useKeyboardNavigation = () => {
62
63
  const navigateSerie = useCallback(
63
64
  (step) => {
64
65
  const newValue = findInCircularList(
65
- currentSerie?.data.map((d) => d.value.toString()),
66
+ currentSerie?.data.map((d) => d.value?.toString()),
66
67
  currentActiveItemIndex,
67
68
  step
68
69
  );
@@ -121,17 +122,15 @@ const useKeyboardNavigation = () => {
121
122
  );
122
123
  const changeSerie = useCallback(
123
124
  (step) => {
124
- const nextSerie = data.find((d) => {
125
- const nextSerieIndex = findInCircularList(
126
- groups,
127
- groups.findIndex((item) => item === currentSerie.name),
128
- step
129
- );
130
- return d.name === groups[nextSerieIndex];
131
- });
132
- setActivePoint(nextSerie?.data[currentActiveItemIndex] || nextSerie?.data?.[0] || null);
125
+ const nextSerieIndex = findInCircularList(
126
+ groups,
127
+ groups.findIndex((item) => item === currentSerie.name),
128
+ step,
129
+ (idx) => currentDataWithNullValues[idx].data[currentActiveItemIndex].value !== null
130
+ );
131
+ setActivePoint(currentDataWithNullValues[nextSerieIndex].data[currentActiveItemIndex]);
133
132
  },
134
- [data, setActivePoint, currentActiveItemIndex, groups, currentSerie.name]
133
+ [groups, setActivePoint, currentActiveItemIndex, currentSerie.name, currentDataWithNullValues]
135
134
  );
136
135
  const onInputKeyDown = useCallback(
137
136
  (e) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useKeyboardNavigation.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../ChartContext.js';\n\nexport const findInCircularList = (\n list: string[],\n from: number,\n step = 1,\n // eslint-disable-next-line max-params\n): number => {\n for (\n let i = (from + step + list.length) % list.length;\n i !== from && from > -1;\n i = (i + step + list.length) % list.length\n ) {\n if (list[i]) return i;\n }\n return from; // return same item\n};\n\nexport const useKeyboardNavigation = () => {\n const {\n activePoint,\n setActivePoint,\n containerRef,\n xScale,\n yScale,\n lastScrollbarPosition,\n setXScrollbarPosition,\n containerRatio,\n xScrollbarPosition,\n innerWidth,\n innerHeight,\n getXScaleValue,\n getYScaleValue,\n groups,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n setContainerRatio,\n currentData: data,\n props: { xAxis, yAxis, xScroll, yScroll },\n } = useContext(ChartContext);\n\n const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;\n const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;\n\n const currentSerie = useMemo(\n () => data.find((d) => d.name === activePoint?.serie) ?? data[0],\n [activePoint?.serie, data],\n );\n\n const currentActiveItemIndex = useMemo(\n () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),\n [activePoint, currentSerie],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef === e.target && activePoint === null) {\n setActivePoint(currentSerie?.data[0]);\n setXScrollbarPosition(0);\n }\n },\n [activePoint, containerRef, currentSerie?.data, setActivePoint, setXScrollbarPosition],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n if (!containerRef?.contains(document.activeElement)) {\n setActivePoint(null);\n }\n });\n }, [setActivePoint, containerRef]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n step,\n );\n setActivePoint(currentSerie?.data[newValue]);\n\n if (xScrollable) {\n const xValue = getXScaleValue(currentSerie?.data[newValue]);\n if (xValue === undefined) return;\n const barWidth = innerWidth / containerRatio;\n const total = innerWidth * containerRatio;\n if (total <= xValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerWidth) / containerRatio);\n } else if (xValue > xScrollbarPosition * containerRatio + innerWidth)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (xValue / containerRatio - prev);\n if (nextPosition + barWidth > innerWidth) return innerWidth - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (xValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(xValue / containerRatio);\n }\n if (yScrollable) {\n const yValue = getYScaleValue(currentSerie?.data[newValue]);\n if (yValue === undefined) return;\n const barWidth = innerHeight / containerRatio;\n const total = innerHeight * containerRatio;\n if (total <= yValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerHeight) / containerRatio);\n } else if (yValue > xScrollbarPosition * containerRatio + innerHeight)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (yValue / containerRatio - prev);\n if (nextPosition + barWidth > innerHeight) return innerHeight - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (yValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(yValue / containerRatio);\n }\n },\n [\n currentSerie?.data,\n currentActiveItemIndex,\n setActivePoint,\n xScrollable,\n yScrollable,\n getXScaleValue,\n innerWidth,\n containerRatio,\n xScrollbarPosition,\n setXScrollbarPosition,\n getYScaleValue,\n innerHeight,\n ],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n const nextSerie = data.find((d) => {\n const nextSerieIndex = findInCircularList(\n groups,\n groups.findIndex((item) => item === currentSerie.name),\n step,\n );\n\n return d.name === groups[nextSerieIndex];\n });\n setActivePoint(nextSerie?.data[currentActiveItemIndex] || nextSerie?.data?.[0] || null);\n },\n [data, setActivePoint, currentActiveItemIndex, groups, currentSerie.name],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!activePoint) return;\n if (e.code !== 'Tab') {\n e.preventDefault();\n }\n if (['ArrowLeft', 'ArrowRight'].includes(e.code)) {\n if (yScale.type === 'BAND') changeSerie(e.code === 'ArrowLeft' ? -1 : 1);\n else navigateSerie(e.code === 'ArrowLeft' ? -1 : 1);\n }\n\n if (['ArrowDown', 'ArrowUp'].includes(e.code)) {\n if (yScale.type === 'BAND') navigateSerie(e.code === 'ArrowDown' ? 1 : -1);\n else changeSerie(e.code === 'ArrowDown' ? -1 : 1);\n }\n\n const { code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (isShiftKey && !isZooming && !xScale.type === 'BAND') {\n setIsZooming(true);\n setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n },\n [\n activePoint,\n changeSerie,\n containerRatio,\n getXScaleValue,\n isZooming,\n navigateSerie,\n setIsZooming,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n yScale.type,\n ],\n );\n\n const handleOnKeyUp: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!isZooming && xScale.type === 'BAND') return false;\n const { shiftKey, code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (shiftKey && ['ArrowRight', 'ArrowLeft'].includes(code)) {\n setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n if (isShiftKey) {\n setIsZooming(false);\n setZoomStartingPosition(0);\n setMovingPosition(0);\n const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;\n // isRightDirection is used to know if we are zooming right or left direction\n const isRightDirection = zoomStartingPosition < endingPosition;\n const offsetActivePoint = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n isRightDirection ? 1 : -1,\n );\n // we do this so the activePoint does not fall into the blur gradient\n const correctEndingPosition =\n getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;\n const diff = Math.abs(zoomStartingPosition - correctEndingPosition);\n if (diff <= 0) return;\n const newRatio =\n innerWidth / ((innerWidth * containerRatio) / diff) < 40\n ? innerWidth / 40\n : (innerWidth * containerRatio) / diff;\n const newPosition =\n lastScrollbarPosition?.current +\n (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;\n\n // if is bigger thant innerwidth possible we force the end\n if (newPosition > innerWidth - innerWidth / newRatio) setXScrollbarPosition(innerWidth - innerWidth / newRatio);\n else setXScrollbarPosition(newPosition);\n setActivePoint(null);\n setTimeout(() => setActivePoint(activePoint));\n setContainerRatio(newRatio);\n lastScrollbarPosition.current = newPosition;\n }\n },\n [\n activePoint,\n containerRatio,\n currentActiveItemIndex,\n currentSerie?.data,\n getXScaleValue,\n innerWidth,\n isZooming,\n lastScrollbarPosition,\n setActivePoint,\n setContainerRatio,\n setIsZooming,\n setMovingPosition,\n setXScrollbarPosition,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n zoomStartingPosition,\n ],\n );\n return useMemo(\n () => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),\n [handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown],\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAA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wBAAwB;AAGvE,YAAI,cAAc,aAAa,aAAa;AAAU,gCAAsB,aAAa,aAAa,QAAQ;AAAA;AACzG,gCAAsB,WAAW;AACtC,uBAAe,IAAI;AACnB,mBAAW,MAAM,eAAe,WAAW,CAAC;AAC5C,0BAAkB,QAAQ;AAC1B,8BAAsB,UAAU;AAAA,MAClC;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,OAAO,EAAE,eAAe,gBAAgB,cAAc,cAAc;AAAA,IACpE,CAAC,cAAc,eAAe,eAAe,cAAc;AAAA,EAC7D;AACF;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../ChartContext.js';\n\nexport const findInCircularList = (\n list: string[],\n from: number,\n step = 1,\n criteria = (item: number) => item !== undefined,\n // eslint-disable-next-line max-params\n): number => {\n for (\n let i = (from + step + list.length) % list.length;\n i !== from && from > -1;\n i = (i + step + list.length) % list.length\n ) {\n if (list[i] && criteria(i)) {\n return i;\n }\n }\n return from; // return same item\n};\n\nexport const useKeyboardNavigation = () => {\n const {\n activePoint,\n setActivePoint,\n containerRef,\n xScale,\n yScale,\n lastScrollbarPosition,\n setXScrollbarPosition,\n containerRatio,\n xScrollbarPosition,\n innerWidth,\n innerHeight,\n getXScaleValue,\n getYScaleValue,\n groups,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n setContainerRatio,\n currentDataWithNullValues,\n props: { xAxis, yAxis, xScroll, yScroll },\n } = useContext(ChartContext);\n\n const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;\n const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;\n\n const currentSerie = useMemo(\n () => currentDataWithNullValues.find((d) => d.name === activePoint?.serie) ?? currentDataWithNullValues[0],\n [activePoint?.serie, currentDataWithNullValues],\n );\n\n const currentActiveItemIndex = useMemo(\n () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),\n [activePoint, currentSerie],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef === e.target && activePoint === null) {\n setActivePoint(currentSerie?.data[0]);\n setXScrollbarPosition(0);\n }\n },\n [activePoint, containerRef, currentSerie?.data, setActivePoint, setXScrollbarPosition],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n if (!containerRef?.contains(document.activeElement)) {\n setActivePoint(null);\n }\n });\n }, [setActivePoint, containerRef]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentSerie?.data.map((d) => d.value?.toString()),\n currentActiveItemIndex,\n step,\n );\n setActivePoint(currentSerie?.data[newValue]);\n\n if (xScrollable) {\n const xValue = getXScaleValue(currentSerie?.data[newValue]);\n if (xValue === undefined) return;\n const barWidth = innerWidth / containerRatio;\n const total = innerWidth * containerRatio;\n if (total <= xValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerWidth) / containerRatio);\n } else if (xValue > xScrollbarPosition * containerRatio + innerWidth)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (xValue / containerRatio - prev);\n if (nextPosition + barWidth > innerWidth) return innerWidth - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (xValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(xValue / containerRatio);\n }\n if (yScrollable) {\n const yValue = getYScaleValue(currentSerie?.data[newValue]);\n if (yValue === undefined) return;\n const barWidth = innerHeight / containerRatio;\n const total = innerHeight * containerRatio;\n if (total <= yValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerHeight) / containerRatio);\n } else if (yValue > xScrollbarPosition * containerRatio + innerHeight)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (yValue / containerRatio - prev);\n if (nextPosition + barWidth > innerHeight) return innerHeight - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (yValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(yValue / containerRatio);\n }\n },\n [\n currentSerie?.data,\n currentActiveItemIndex,\n setActivePoint,\n xScrollable,\n yScrollable,\n getXScaleValue,\n innerWidth,\n containerRatio,\n xScrollbarPosition,\n setXScrollbarPosition,\n getYScaleValue,\n innerHeight,\n ],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n const nextSerieIndex = findInCircularList(\n groups,\n groups.findIndex((item) => item === currentSerie.name),\n step,\n (idx: number) => currentDataWithNullValues[idx].data[currentActiveItemIndex].value !== null,\n );\n setActivePoint(currentDataWithNullValues[nextSerieIndex].data[currentActiveItemIndex]);\n },\n [groups, setActivePoint, currentActiveItemIndex, currentSerie.name, currentDataWithNullValues],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!activePoint) return;\n if (e.code !== 'Tab') {\n e.preventDefault();\n }\n if (['ArrowLeft', 'ArrowRight'].includes(e.code)) {\n if (yScale.type === 'BAND') changeSerie(e.code === 'ArrowLeft' ? -1 : 1);\n else navigateSerie(e.code === 'ArrowLeft' ? -1 : 1);\n }\n\n if (['ArrowDown', 'ArrowUp'].includes(e.code)) {\n if (yScale.type === 'BAND') navigateSerie(e.code === 'ArrowDown' ? 1 : -1);\n else changeSerie(e.code === 'ArrowDown' ? -1 : 1);\n }\n\n const { code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (isShiftKey && !isZooming && !xScale.type === 'BAND') {\n setIsZooming(true);\n setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n },\n [\n activePoint,\n changeSerie,\n containerRatio,\n getXScaleValue,\n isZooming,\n navigateSerie,\n setIsZooming,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n yScale.type,\n ],\n );\n\n const handleOnKeyUp: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!isZooming && xScale.type === 'BAND') return false;\n const { shiftKey, code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (shiftKey && ['ArrowRight', 'ArrowLeft'].includes(code)) {\n setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n if (isShiftKey) {\n setIsZooming(false);\n setZoomStartingPosition(0);\n setMovingPosition(0);\n const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;\n // isRightDirection is used to know if we are zooming right or left direction\n const isRightDirection = zoomStartingPosition < endingPosition;\n const offsetActivePoint = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n isRightDirection ? 1 : -1,\n );\n // we do this so the activePoint does not fall into the blur gradient\n const correctEndingPosition =\n getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;\n const diff = Math.abs(zoomStartingPosition - correctEndingPosition);\n if (diff <= 0) return;\n const newRatio =\n innerWidth / ((innerWidth * containerRatio) / diff) < 40\n ? innerWidth / 40\n : (innerWidth * containerRatio) / diff;\n const newPosition =\n lastScrollbarPosition?.current +\n (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;\n\n // if is bigger thant innerwidth possible we force the end\n if (newPosition > innerWidth - innerWidth / newRatio) setXScrollbarPosition(innerWidth - innerWidth / newRatio);\n else setXScrollbarPosition(newPosition);\n setActivePoint(null);\n setTimeout(() => setActivePoint(activePoint));\n setContainerRatio(newRatio);\n lastScrollbarPosition.current = newPosition;\n }\n },\n [\n activePoint,\n containerRatio,\n currentActiveItemIndex,\n currentSerie?.data,\n getXScaleValue,\n innerWidth,\n isZooming,\n lastScrollbarPosition,\n setActivePoint,\n setContainerRatio,\n setIsZooming,\n setMovingPosition,\n setXScrollbarPosition,\n setZoomStartingPosition,\n xScale.type,\n xScrollbarPosition,\n zoomStartingPosition,\n ],\n );\n return useMemo(\n () => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),\n [handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown],\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,YAAY,eAAe;AACjD,SAAS,oBAAoB;AAEtB,MAAM,qBAAqB,CAChC,MACA,MACA,OAAO,GACP,WAAW,CAAC,SAAiB,SAAS,WAE3B;AACX,WACM,KAAK,OAAO,OAAO,KAAK,UAAU,KAAK,QAC3C,MAAM,QAAQ,OAAO,IACrB,KAAK,IAAI,OAAO,KAAK,UAAU,KAAK,QACpC;AACA,QAAI,KAAK,CAAC,KAAK,SAAS,CAAC,GAAG;AAC1B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,wBAAwB,MAAM;AACzC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,EAAE,OAAO,OAAO,SAAS,QAAQ;AAAA,EAC1C,IAAI,WAAW,YAAY;AAE3B,QAAM,cAAc,MAAM,UAAU,cAAc,QAAQ,KAAK;AAC/D,QAAM,cAAc,MAAM,UAAU,cAAc,QAAQ,KAAK;AAE/D,QAAM,eAAe;AAAA,IACnB,MAAM,0BA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B,uBAAuB;AAChD,cAAM,oBAAoB;AAAA,UACxB,cAAc,KAAK,IAAI,CAAC,MAAM,EAAE,MAAM,SAAS,CAAC;AAAA,UAChD;AAAA,UACA,mBAAmB,IAAI;AAAA,QACzB;AAEA,cAAM,wBACJ,eAAe,cAAc,KAAK,iBAAiB,CAAC,IAAI,qBAAqB;AAC/E,cAAM,OAAO,KAAK,IAAI,uBAAuB,qBAAqB;AAClE,YAAI,QAAQ;AAAG;AACf,cAAM,WACJ,cAAe,aAAa,iBAAkB,QAAQ,KAClD,aAAa,KACZ,aAAa,iBAAkB;AACtC,cAAM,cACJ,uBAAuB,WACtB,CAAC,mBAAmB,wBAAwB,wBAAwB;AAGvE,YAAI,cAAc,aAAa,aAAa;AAAU,gCAAsB,aAAa,aAAa,QAAQ;AAAA;AACzG,gCAAsB,WAAW;AACtC,uBAAe,IAAI;AACnB,mBAAW,MAAM,eAAe,WAAW,CAAC;AAC5C,0BAAkB,QAAQ;AAC1B,8BAAsB,UAAU;AAAA,MAClC;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,OAAO,EAAE,eAAe,gBAAgB,cAAc,cAAc;AAAA,IACpE,CAAC,cAAc,eAAe,eAAe,cAAc;AAAA,EAC7D;AACF;",
6
6
  "names": []
7
7
  }
@@ -6,6 +6,7 @@ interface ContextT {
6
6
  props: DSChartT.Props;
7
7
  originalSeries: DSChartT.SeriesT;
8
8
  currentData: DSChartT.InternalData;
9
+ currentDataWithNullValues: DSChartT.InternalData;
9
10
  xScale: ScaleT;
10
11
  yScale: ScaleT;
11
12
  y2Scale: ScaleT;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { GlobalAttributesT, XstyledProps, DSPropTypesSchema } from '@elliemae/ds-utilities';
2
3
  import { type BackgroundProps, type BorderProps } from '@elliemae/ds-system';
3
4
  import { type COLOR_PALLET } from '../../../index.js';
@@ -12,7 +12,16 @@ export declare const useChart: (props: DSChartT.Props) => {
12
12
  innerHeight: number;
13
13
  innerWidth: number;
14
14
  groups: string[];
15
- currentData: DSChartT.InternalData;
15
+ currentData: {
16
+ data: DSChartT.InternalDatum[];
17
+ key: string;
18
+ name: string;
19
+ type: DSChartT.SerieTypeT;
20
+ scale?: string | undefined;
21
+ color?: string | undefined;
22
+ dashStyle?: string | undefined;
23
+ pointRadius?: number | undefined;
24
+ }[];
16
25
  colorScale: import("d3-scale").ScaleOrdinal<string, unknown, string>;
17
26
  stackedData: DSChartT.StackedSeriesByGroupT;
18
27
  subGroupScale: ([number, number] & import("d3-scale").ScaleBand<string>) | null;
@@ -89,4 +98,5 @@ export declare const useChart: (props: DSChartT.Props) => {
89
98
  axisLeftWidth: number;
90
99
  topLegendHeight: number;
91
100
  leftLegendHeight: number;
101
+ currentDataWithNullValues: DSChartT.InternalData;
92
102
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const findInCircularList: (list: string[], from: number, step?: number) => number;
2
+ export declare const findInCircularList: (list: string[], from: number, step?: number, criteria?: (item: number) => boolean) => number;
3
3
  export declare const useKeyboardNavigation: () => {
4
4
  handleOnKeyUp: import("react").KeyboardEventHandler<HTMLDivElement>;
5
5
  onInputKeyDown: import("react").KeyboardEventHandler<HTMLDivElement>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { Series, ScaleLinear, ScaleBand } from 'd3';
2
3
  export declare namespace DSChartT {
3
4
  type SerieTypeT = 'line' | 'bar' | 'area' | 'point';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-dataviz",
3
- "version": "3.26.1-rc.0",
3
+ "version": "3.27.0-next.1",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - DataViz",
6
6
  "files": [
@@ -41,18 +41,18 @@
41
41
  "d3-time": "~3.1.0",
42
42
  "resize-observer-polyfill": "~1.5.1",
43
43
  "uid": "~2.0.2",
44
- "@elliemae/ds-grid": "3.26.1-rc.0",
45
- "@elliemae/ds-popperjs": "3.26.1-rc.0",
46
- "@elliemae/ds-props-helpers": "3.26.1-rc.0",
47
- "@elliemae/ds-system": "3.26.1-rc.0",
48
- "@elliemae/ds-utilities": "3.26.1-rc.0"
44
+ "@elliemae/ds-grid": "3.27.0-next.1",
45
+ "@elliemae/ds-system": "3.27.0-next.1",
46
+ "@elliemae/ds-props-helpers": "3.27.0-next.1",
47
+ "@elliemae/ds-utilities": "3.27.0-next.1",
48
+ "@elliemae/ds-popperjs": "3.27.0-next.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@elliemae/pui-cli": "~9.0.0-next.31",
52
52
  "@elliemae/pui-theme": "~2.7.0",
53
53
  "@types/d3": "~7.4.0",
54
54
  "styled-components": "~5.3.9",
55
- "@elliemae/ds-monorepo-devops": "3.26.1-rc.0"
55
+ "@elliemae/ds-monorepo-devops": "3.27.0-next.1"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@elliemae/pui-theme": "~2.7.0",