import {Fragment, useCallback, useEffect, useMemo, useRef} from 'react'; import { View, Animated, Easing, Text, Dimensions, ColorValue, I18nManager, ViewStyle, } from 'react-native'; import {isWebApp, screenWidth, usePrevious} from '../utils'; import Svg, { Path, LinearGradient, Stop, Circle, Rect, Text as CanvasText, Line, ClipPath, Use, ForeignObject, Defs, Mask, } from 'react-native-svg'; import { getSegmentedPathObjects, getRegionPathObjects, RANGE_ENTER, RANGE_EXIT, SEGMENT_END, SEGMENT_START, STOP, svgPath, LineChartPropsType, lineDataItem, LineSvgProps, useLineChart, adjustToOffset, LineProperties, LineDefaults, pointsWithPaddedRepititions, lineDataItemNullSafe, Linecap, } from 'gifted-charts-core'; import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper'; import {StripAndLabel} from '../Components/common/StripAndLabel'; import {Pointer} from '../Components/common/Pointer'; const AnimatedPath = Animated.createAnimatedComponent(Path); const AnimatedRect = Animated.createAnimatedComponent(Rect); export const LineChart = (props: LineChartPropsType) => { const scrollRef = props.scrollRef ?? useRef(null); const opacityValue = useMemo(() => new Animated.Value(0), []); // const heightValue = useMemo(() => new Animated.Value(0), []); const widthValue = useMemo(() => new Animated.Value(0), []); const widthValue2 = useMemo(() => new Animated.Value(0), []); const widthValue3 = useMemo(() => new Animated.Value(0), []); const widthValue4 = useMemo(() => new Animated.Value(0), []); const widthValue5 = useMemo(() => new Animated.Value(0), []); const { curveType, scrollX, setScrollX, arrow1Points, arrow2Points, arrow3Points, arrow4Points, arrow5Points, secondaryArrowPoints, pointerIndex, setPointerIndex, pointerX, setPointerX, pointerY, setPointerY, pointerItem, setPointerItem, pointerY2, setPointerY2, pointerItem2, setPointerItem2, pointerY3, setPointerY3, pointerItem3, setPointerItem3, pointerY4, setPointerY4, pointerItem4, setPointerItem4, pointerY5, setPointerY5, pointerYsForDataSet, setPointerYsForDataSet, pointerItem5, setPointerItem5, secondaryPointerY, setSecondaryPointerY, secondaryPointerItem, setSecondaryPointerItem, pointerItemsForSet, setPointerItemsForSet, secondaryPointerItemsForSet, setSecondaryPointerItemsForSet, responderStartTime, setResponderStartTime, setResponderActive, points, points2, points3, points4, points5, secondaryPoints, fillPoints, fillPoints2, fillPoints3, fillPoints4, fillPoints5, secondaryFillPoints, pointsFromSet, fillPointsFromSet, arrowPointsFromSet, selectedIndex, setSelectedIndex, containerHeight, data, data2, data3, data4, data5, secondaryData, dataSet, data0, labelsExtraHeight, animationDuration, onDataChangeAnimationDuration, animateTogether, renderDataPointsAfterAnimationEnds, animateOnDataChange, startIndex1, startIndex2, endIndex1, endIndex2, startIndex3, endIndex3, startIndex4, endIndex4, startIndex5, endIndex5, initialSpacing, thickness, yAxisLabelWidth, spacing, xAxisThickness, dataPointsHeight1, dataPointsWidth1, dataPointsRadius1, dataPointsColor1, dataPointsShape1, dataPointsHeight2, dataPointsWidth2, dataPointsRadius2, dataPointsColor2, dataPointsShape2, dataPointsHeight3, dataPointsWidth3, dataPointsRadius3, dataPointsColor3, dataPointsShape3, dataPointsHeight4, dataPointsWidth4, dataPointsRadius4, dataPointsColor4, dataPointsShape4, dataPointsHeight5, dataPointsWidth5, dataPointsRadius5, dataPointsColor5, dataPointsShape5, getIsNthAreaChart, textFontSize1, textFontSize2, textFontSize3, textFontSize4, textFontSize5, textColor1, textColor2, textColor3, textColor4, textColor5, totalWidth, maxValue, overflowTop, extendedContainerHeight, getX, getY, getSecondaryY, secondaryMaxValue, showValuesAsDataPointsText, thickness1, thickness2, thickness3, thickness4, thickness5, zIndex1, zIndex2, zIndex3, zIndex4, zIndex5, strokeDashArray1, strokeDashArray2, strokeDashArray3, strokeDashArray4, strokeDashArray5, strokeLinecap1, strokeLinecap2, strokeLinecap3, strokeLinecap4, strokeLinecap5, rotateLabel, isAnimated, hideDataPoints1, hideDataPoints2, hideDataPoints3, hideDataPoints4, hideDataPoints5, color1, color2, color3, color4, color5, startFillColor1, endFillColor1, startOpacity1, endOpacity1, startFillColor2, endFillColor2, startOpacity2, endOpacity2, startFillColor3, endFillColor3, startOpacity3, endOpacity3, startFillColor4, endFillColor4, startOpacity4, endOpacity4, startFillColor5, endFillColor5, startOpacity5, endOpacity5, arrowStrokeWidth1, arrowStrokeColor1, arrowFillColor1, arrowStrokeWidth2, arrowStrokeColor2, arrowFillColor2, arrowStrokeWidth3, arrowStrokeColor3, arrowFillColor3, arrowStrokeWidth4, arrowStrokeColor4, arrowFillColor4, arrowStrokeWidth5, arrowStrokeColor5, arrowFillColor5, arrowStrokeWidthsFromSet, arrowStrokeColorsFromSet, arrowFillColorsFromSet, secondaryLineConfig, gradientDirection, stepHeight, noOfSectionsBelowXAxis, xAxisTextNumberOfLines, xAxisLabelsVerticalShift, pointerConfig, pointerHeight, pointerWidth, pointerRadius, pointerColor, pointerComponent, showPointerStrip, pointerStripHeight, pointerStripWidth, pointerStripColor, pointerStripUptoDataPoint, pointerLabelComponent, stripOverPointer, shiftPointerLabelX, shiftPointerLabelY, pointerLabelWidth, pointerLabelHeight, autoAdjustPointerLabelPosition, pointerVanishDelay, activatePointersOnLongPress, activatePointersInstantlyOnTouch, activatePointersDelay, persistPointer, resetPointerIndexOnRelease, hidePointers, hidePointer1, hidePointer2, hidePointer3, hidePointer4, hidePointer5, cumulativeSpacing1, cumulativeSpacing2, cumulativeSpacing3, cumulativeSpacing4, cumulativeSpacing5, cumulativeSpacingSecondary, cumulativeSpacingForSet, hideSecondaryPointer, hidePointerDataPointForMissingValues, pointerEvents, focusEnabled, showDataPointOnFocus, showStripOnFocus, stripOverDataPoints, showTextOnFocus, showDataPointLabelOnFocus, stripHeight, stripWidth, stripColor, stripOpacity, stripStrokeDashArray, containerHeightIncludingBelowXAxis = 0, lineGradient, lineGradientDirection, lineGradientStartColor, lineGradientEndColor, barAndLineChartsWrapperProps, areaChart, mostNegativeValue, strips, lastLineNumber, focusTogether, selectedLineNumber, handleFocus, handleUnFocus, pointerItemLocal, allowFontScaling, colors, disableForeignObject, doAllPointsHaveX, } = useLineChart({ ...props, parentWidth: props.parentWidth ?? screenWidth, }); const {principalCumulativeSpacing} = barAndLineChartsWrapperProps; const svgHeight = containerHeightIncludingBelowXAxis + (props.overflowBottom ?? dataPointsRadius1); const {secondaryXAxis, intersectionAreaConfig} = props; const widthValuesFromSet = useMemo( () => dataSet?.map(set => new Animated.Value(0)), [], ); const animatedPoints = new Animated.Value(0); const animatedFillPoints = new Animated.Value(0); const oldPoints = usePrevious(points); const oldFillPoints = usePrevious(fillPoints); const animatedPath = animateOnDataChange && points && oldPoints && points !== oldPoints ? animatedPoints.interpolate({ inputRange: [0, 1], outputRange: pointsWithPaddedRepititions(oldPoints, points), }) : ''; const animatedFillPath = animateOnDataChange && fillPoints && oldFillPoints && fillPoints !== oldFillPoints ? animatedFillPoints.interpolate({ inputRange: [0, 1], outputRange: pointsWithPaddedRepititions(oldFillPoints, fillPoints), }) : ''; useEffect(() => { if (animateOnDataChange) { Animated.timing(animatedPoints, { toValue: 1, duration: onDataChangeAnimationDuration, useNativeDriver: true, easing: Easing.ease, }).start(); if (props.areaChart || props.areaChart1) { Animated.timing(animatedFillPoints, { toValue: 1, duration: onDataChangeAnimationDuration, useNativeDriver: true, easing: Easing.ease, }).start(); } } }, [animatedPoints]); const labelsAppear = useCallback(() => { opacityValue.setValue(0); Animated.timing(opacityValue, { toValue: 1, duration: 500, easing: Easing.ease, useNativeDriver: false, }).start(); }, [opacityValue]); const appearingOpacity = opacityValue.interpolate({ inputRange: [0, 1], outputRange: [0, 1], }); const decreaseWidth = useCallback(() => { widthValue.setValue(0); Animated.timing(widthValue, { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); }, [animationDuration, widthValue]); const decreaseWidth2 = useCallback(() => { widthValue2.setValue(0); Animated.timing(widthValue2, { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); }, [animationDuration, widthValue2]); const decreaseWidth3 = useCallback(() => { widthValue3.setValue(0); Animated.timing(widthValue3, { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); }, [animationDuration, widthValue3]); const decreaseWidth4 = useCallback(() => { widthValue4.setValue(0); Animated.timing(widthValue4, { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); }, [animationDuration, widthValue4]); const decreaseWidth5 = useCallback(() => { widthValue5.setValue(0); Animated.timing(widthValue5, { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); }, [animationDuration, widthValue5]); const decreaseWidthsFromSet = useCallback(() => { dataSet?.map((set, index) => { widthValuesFromSet?.[index]?.setValue(0); if (widthValuesFromSet?.[index]) { Animated.timing(widthValuesFromSet?.[index], { toValue: totalWidth, duration: animationDuration, easing: Easing.linear, useNativeDriver: false, }).start(); } }); }, [animationDuration, widthValuesFromSet]); useEffect(() => { decreaseWidth(); labelsAppear(); widthValuesFromSet?.forEach((item: any, index: number) => { setTimeout( () => { decreaseWidthsFromSet(); }, animateTogether ? 0 : animationDuration * index, ); }); setTimeout( () => { decreaseWidth2(); }, animateTogether ? 0 : animationDuration, ); setTimeout( () => { decreaseWidth3(); }, animateTogether ? 0 : animationDuration * 2, ); setTimeout( () => { decreaseWidth4(); }, animateTogether ? 0 : animationDuration * 3, ); setTimeout( () => { decreaseWidth5(); }, animateTogether ? 0 : animationDuration * 4, ); }, [ animateTogether, animationDuration, decreaseWidth, decreaseWidth2, decreaseWidth3, decreaseWidth4, decreaseWidth5, labelsAppear, ]); const svgWrapperViewStyle = { position: 'absolute', bottom: 61 + xAxisLabelsVerticalShift + labelsExtraHeight - xAxisThickness, left: 0, zIndex: 1, transform: [{scaleX: I18nManager.isRTL ? -1 : 1}], }; const renderLabel = ( top: boolean, index: number, label: string, labelTextStyle: any, labelComponent: Function | undefined, ) => { return ( {labelComponent ? ( labelComponent() ) : ( {label} )} ); }; const renderAnimatedLabel = ( top: boolean, index: number, label: string, labelTextStyle: any, labelComponent: Function | undefined, ) => { return ( {labelComponent ? ( labelComponent() ) : ( {label} )} ); }; const onStripPress = (item: any, index: number) => { if (props.focusedDataPointIndex === undefined || !props.onFocus) { setSelectedIndex(index); } if (props.onFocus) { props.onFocus(item, index); } }; const renderDataPoints = ( hideDataPoints: any, dataForRender: any, dataPtsShape: any, dataPtsWidth: any, dataPtsHeight: any, dataPtsColor: any, dataPtsRadius: any, textColor: any, textFontSize: any, startIndex: any, endIndex: any, isSecondary: any, showValuesAsDataPointsText: any, spacingArray: number[], key: number, ) => { const getYOrSecondaryY = isSecondary ? getSecondaryY : getY; return dataForRender.map((item: lineDataItemNullSafe, index: number) => { if (index < startIndex || index > endIndex) return null; if (item.hideDataPoint) { return null; } let dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, text, customDataPoint, dataPointLabelComponent; if ( index === selectedIndex && (focusTogether || key === selectedLineNumber) ) { dataPointsShape = item.focusedDataPointShape || props.focusedDataPointShape || item.dataPointShape || dataPtsShape; dataPointsWidth = item.focusedDataPointWidth || props.focusedDataPointWidth || item.dataPointWidth || dataPtsWidth; dataPointsHeight = item.focusedDataPointHeight || props.focusedDataPointHeight || item.dataPointHeight || dataPtsHeight; dataPointsColor = item.focusedDataPointColor || props.focusedDataPointColor || LineDefaults.focusedDataPointColor; dataPointsRadius = item.focusedDataPointRadius ?? props.focusedDataPointRadius ?? item.dataPointRadius ?? dataPtsRadius; if (showTextOnFocus) { text = item.dataPointText; } customDataPoint = item.focusedCustomDataPoint || props.focusedCustomDataPoint || item.customDataPoint || props.customDataPoint; dataPointLabelComponent = item.focusedDataPointLabelComponent || item.dataPointLabelComponent || props.focusedDataPointLabelComponent || props.dataPointLabelComponent; } else { dataPointsShape = item.dataPointShape || dataPtsShape; dataPointsWidth = item.dataPointWidth || dataPtsWidth; dataPointsHeight = item.dataPointHeight || dataPtsHeight; dataPointsColor = item.dataPointColor || dataPtsColor; dataPointsRadius = item.dataPointRadius ?? dataPtsRadius; if (showTextOnFocus) { text = ''; } customDataPoint = item.customDataPoint || props.customDataPoint; dataPointLabelComponent = item.dataPointLabelComponent || props.dataPointLabelComponent; } if (showValuesAsDataPointsText) { text = item.originalValue; } const dataPointLabelWidth = item.dataPointLabelWidth ? item.dataPointLabelWidth : props.dataPointLabelWidth ? props.dataPointLabelWidth : 30; return ( {focusEnabled ? ( <> {key === lastLineNumber - 1 ? ( { const locationY = evt.nativeEvent.locationY; // Note that we have another property named pageY which can be useful handleFocus(index, item, locationY, onStripPress); }} onPressOut={handleUnFocus} /> ) : null} ) : null} {/* {renderStrips(item, index, key)} // handled with strips coming from geifted-charts-core */} {hideDataPoints ? null : ( <> {customDataPoint ? ( isWebApp && !disableForeignObject ? ( {customDataPoint(item, index)} ) : ( {customDataPoint(item, index)} ) ) : null} {dataPointsShape === 'rectangular' ? ( {customDataPoint ? null : ( { item.onPress ? item.onPress(item, index) : props.onPress ? props.onPress(item, index) : focusEnabled ? handleFocus(index, item, 0, onStripPress) : null; }, onPressOut: () => { if ( !item.onPress && !props.onPress && focusEnabled ) { handleUnFocus(); } }, } : {})} /> )} ) : ( {customDataPoint ? null : ( { item.onPress ? item.onPress(item, index) : props.onPress ? props.onPress(item, index) : focusEnabled ? handleFocus(index, item, 0, onStripPress) : null; }, onPressOut: () => { if ( !item.onPress && !props.onPress && focusEnabled ) { handleUnFocus(); } }, } : {})} /> )} )} {dataPointLabelComponent ? ( !showTextOnFocus || index === selectedIndex ? ( isWebApp && !disableForeignObject ? ( {showDataPointLabelOnFocus ? index === selectedIndex && (focusTogether || key == selectedLineNumber) ? dataPointLabelComponent(item, index) // not pushed in latest release : null : dataPointLabelComponent(item, index)} ) : ( {showDataPointLabelOnFocus ? index === selectedIndex && (focusTogether || key == selectedLineNumber) ? dataPointLabelComponent(item, index) // not pushed in latest release : null : dataPointLabelComponent(item, index)} ) ) : null ) : text || item.dataPointText ? ( !showTextOnFocus || index === selectedIndex ? ( {!showTextOnFocus && !showValuesAsDataPointsText ? item.dataPointText : text} ) : null ) : null} {/* Workaround to fix the issue - focusedCustomDataPoint not rendering for focused data, (when both customDataPoint and focusedCustomDataPoint are used together)*/} {index === selectedIndex ? {''} : null} )} ); }); }; const renderSpecificVerticalLines = ( dataForRender: any, spacingArray: number[], ) => { return dataForRender.map((item: lineDataItemNullSafe, index: number) => { if (item.showVerticalLine) { const x = getX(spacingArray, index); return ( ); } return null; }); }; const renderPointer = (lineNumber: number, isDataSet?: boolean) => { if (hidePointers) return; if (isDataSet) { let pointerItemLocal, pointerYLocal, pointerColorLocal; return dataSet?.map((set, index) => { const pIndex = barAndLineChartsWrapperProps.pointerIndex; pointerItemLocal = set.data[pIndex]; if (set.hidePointers || pointerItemLocal?.hidePointer) return null; if ( hidePointerDataPointForMissingValues && typeof pointerItemLocal.value !== 'number' ) return null; pointerYLocal = pointerYsForDataSet[index]; pointerColorLocal = pointerConfig?.pointerColorsForDataSet?.[index] ?? pointerColor; return ( {Pointer({ pointerX, pointerYLocal: pointerYLocal + xAxisThickness, pointerComponent, pointerHeight, pointerRadius, pointerWidth, pointerItemLocal, pointerColorLocal, pointerIndex: pIndex, })} ); }); } if (lineNumber === 1 && hidePointer1) return; if (lineNumber === 2 && hidePointer2) return; if (lineNumber === 3 && hidePointer3) return; if (lineNumber === 4 && hidePointer4) return; if (lineNumber === 5 && hidePointer5) return; // 6666 is for secondaryData if (lineNumber === 6666 && hideSecondaryPointer) return; let pointerItemLocal, pointerYLocal, pointerColorLocal; switch (lineNumber) { case 1: pointerItemLocal = pointerItem; pointerYLocal = pointerY; pointerColorLocal = pointerConfig?.pointer1Color || pointerColor; break; case 2: pointerItemLocal = pointerItem2; pointerYLocal = pointerY2; pointerColorLocal = pointerConfig?.pointer2Color || pointerColor; break; case 3: pointerItemLocal = pointerItem3; pointerYLocal = pointerY3; pointerColorLocal = pointerConfig?.pointer3Color || pointerColor; break; case 4: pointerItemLocal = pointerItem4; pointerYLocal = pointerY4; pointerColorLocal = pointerConfig?.pointer4Color || pointerColor; break; case 5: pointerItemLocal = pointerItem5; pointerYLocal = pointerY5; pointerColorLocal = pointerConfig?.pointer5Color || pointerColor; break; case 6666: pointerItemLocal = secondaryPointerItem; pointerYLocal = secondaryPointerY; pointerColorLocal = pointerConfig?.secondaryPointerColor || pointerColor; break; } if (!pointerYLocal) return; if ( hidePointerDataPointForMissingValues && typeof data?.[pointerIndex]?.originalValue !== 'number' ) return null; return Pointer({ pointerX, pointerYLocal: pointerYLocal + xAxisThickness, pointerComponent, pointerHeight, pointerRadius, pointerWidth, pointerItemLocal, pointerColorLocal, pointerIndex, }); }; const renderStripAndLabel = () => { let pointerYLocal; let arr = [pointerY]; if (pointerY2 !== 0) { arr.push(pointerY2); } if (pointerY3 !== 0) { arr.push(pointerY3); } if (pointerY4 !== 0) { arr.push(pointerY4); } if (pointerY5 !== 0) { arr.push(pointerY5); } pointerYLocal = Math.min(...arr); if ( pointerConfig?.hidePointerForMissingValues && typeof pointerItemLocal[0].value !== 'number' ) return null; return StripAndLabel({ autoAdjustPointerLabelPosition, pointerX, pointerLabelWidth, activatePointersOnLongPress, yAxisLabelWidth, pointerRadius, pointerWidth, shiftPointerLabelX, pointerLabelHeight, pointerYLocal, pointerStripUptoDataPoint, pointerStripHeight, shiftPointerLabelY, pointerItemLocal, secondaryPointerItem, pointerItemsForSet, secondaryPointerItemsForSet, showPointerStrip, pointerStripWidth, containerHeight, containerHeightIncludingBelowXAxis, xAxisThickness, pointerStripColor, pointerConfig, pointerLabelComponent, scrollX, pointerEvents, isBarChart: false, pointerIndex, width: totalWidth, screenWidth: props.width ?? Math.min(totalWidth, props.parentWidth ?? screenWidth) - yAxisLabelWidth, hasDataSet: !!dataSet, containsNegative: mostNegativeValue < 0, horizontalStripConfig: pointerConfig?.horizontalStripConfig, }); }; const getLineGradientComponent = () => { return props.lineGradientComponent ? ( props.lineGradientComponent() ) : ( ); }; const getAreaGradientComponent = ( startFillColor: string, endFillColor: string, startOpacity: number, endOpacity: number, gradientId?: string, ) => { return props.areaGradientComponent ? ( props.areaGradientComponent() ) : ( ); }; const getSpreadAreaPath = ( spreadAreaData: {lower: number; upper: number}[], getX: (spacingArray: number[], index: number) => number, getY: (val: number) => number, spacingArray: number[], curvature?: number, curveType?: any, ) => { if (!spreadAreaData || spreadAreaData.length === 0) return ''; // Generate points arrays for upper and lower bounds const upperPoints = spreadAreaData.map((point, index) => [ getX(spacingArray, index), getY(point.upper), ]); const lowerPoints = spreadAreaData.map((point, index) => [ getX(spacingArray, index), getY(point.lower), ]); // Use curve interpolation if curveType is specified if (curveType !== undefined && curveType !== 0) { const topPath = svgPath(upperPoints, curveType, props.curvature); // Reverse the lower points for the path and create curved path const reversedLowerPoints = lowerPoints.slice().reverse(); const bottomPath = svgPath( reversedLowerPoints, curveType, props.curvature, ); // Remove the initial 'M' from bottomPath and prepend 'L' to connect it const bottomPathConnected = bottomPath.replace(/^M/, 'L'); return `${topPath} ${bottomPathConnected} Z`; } else { // Fallback to straight lines for compatibility const topPath = spreadAreaData .map( (point, index) => `L ${getX(spacingArray, index)} ${getY(point.upper)}`, ) .join(' ') .replace(/^L/, 'M'); const bottomPath = spreadAreaData .slice() .reverse() .map( (point, index) => `L ${getX(spacingArray, spreadAreaData.length - 1 - index)} ${getY( point.lower, )}`, ) .join(' '); return `${topPath} ${bottomPath} Z`; } }; const getClipRange = ( startIndex: number, endIndex: number, clipRangeId: string, ) => { const startX = startIndex * spacing + initialSpacing; const endX = endIndex * spacing + initialSpacing; const clipWidth = endX - startX; return ( ); }; const getColorBackRects = () => { return colors?.map(colorItem => { const key = JSON.stringify(colorItem); const {from, to, color} = colorItem; const y = getY(from); const height = getY(to) - getY(from); const rectProps = { x: 0, y, height, fill: color, mask: 'url(#pathMask)', }; return isAnimated ? ( ) : ( ); }); }; const renderIntersection = () => { return ( {/* Define the pathe path1 & path2 */} {/* Render the clipped Path */} {/* Render the Line1 again as its clipped portion gets hidden */} ); }; const renderDataPointsForEachLine = () => { if (dataSet && pointsFromSet.length) { return ( <> {dataSet.map((set, index) => { const { hideDataPoints, data, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, } = set; return renderDataPoints( hideDataPoints ?? hideDataPoints1, data, // adjustToOffset(data, -(props.yAxisOffset ?? 0)), dataPointsShape ?? dataPointsShape1, dataPointsWidth ?? dataPointsWidth1, dataPointsHeight ?? dataPointsHeight1, dataPointsColor ?? dataPointsColor1, dataPointsRadius ?? dataPointsRadius1, textColor ?? textColor1, textFontSize ?? textFontSize1, startIndex ?? 0, endIndex ?? set.data.length - 1, isSecondary, showValuesAsDataPointsText, cumulativeSpacingForSet[index], index, ); })} ); } return ( <> {renderDataPoints( hideDataPoints1, data, // props.data, dataPointsShape1, dataPointsWidth1, dataPointsHeight1, dataPointsColor1, dataPointsRadius1, textColor1, textFontSize1, startIndex1, endIndex1, false, showValuesAsDataPointsText, cumulativeSpacing1, 0, )} {points2 ? renderDataPoints( hideDataPoints2, data2, // props.data2, dataPointsShape2, dataPointsWidth2, dataPointsHeight2, dataPointsColor2, dataPointsRadius2, textColor2, textFontSize2, startIndex2, endIndex2, false, showValuesAsDataPointsText, cumulativeSpacing2, 1, ) : null} {points3 ? renderDataPoints( hideDataPoints3, data3, // props.data3, dataPointsShape3, dataPointsWidth3, dataPointsHeight3, dataPointsColor3, dataPointsRadius3, textColor3, textFontSize3, startIndex3, endIndex3, false, showValuesAsDataPointsText, cumulativeSpacing3, 2, ) : null} {points4 ? renderDataPoints( hideDataPoints4, data4, // props.data4, dataPointsShape4, dataPointsWidth4, dataPointsHeight4, dataPointsColor4, dataPointsRadius4, textColor4, textFontSize4, startIndex4, endIndex4, false, showValuesAsDataPointsText, cumulativeSpacing4, 3, ) : null} {points5 ? renderDataPoints( hideDataPoints5, data5, // props.data5, dataPointsShape5, dataPointsWidth5, dataPointsHeight5, dataPointsColor5, dataPointsRadius5, textColor5, textFontSize5, startIndex5, endIndex5, false, showValuesAsDataPointsText, cumulativeSpacing5, 4, ) : null} {secondaryPoints ? renderDataPoints( secondaryLineConfig.hideDataPoints, secondaryData, // props.secondaryData, secondaryLineConfig.dataPointsShape, secondaryLineConfig.dataPointsWidth, secondaryLineConfig.dataPointsHeight, secondaryLineConfig.dataPointsColor, secondaryLineConfig.dataPointsRadius, secondaryLineConfig.textColor, secondaryLineConfig.textFontSize, secondaryLineConfig.startIndex, secondaryLineConfig.endIndex, true, secondaryLineConfig.showValuesAsDataPointsText, cumulativeSpacingSecondary, 6666, ) : null} ); }; const areaComponent = ( isNthAreaChart: boolean | undefined, startFillColor: string, endFillColor: string, startOpacity: number, endOpacity: number, uniqueId: string, fillPoints: any, startIndex: number, endIndex: number, data: any, clipRangeId: string, currentLineThickness: number | undefined, spreadAreaData: {lower: number; upper: number}[] | undefined, spacingArray: number[], spreadAreaColor: ColorValue | undefined, spreadAreaOpacity: number | undefined, ) => { // For Area Chart return ( <> {isNthAreaChart && getAreaGradientComponent( startFillColor, endFillColor, startOpacity, endOpacity, uniqueId, )} {isNthAreaChart && (startIndex !== 0 || endIndex !== data.length - 1) && getClipRange(startIndex, endIndex, clipRangeId)} {isNthAreaChart ? ( props.interpolateMissingValues === false && data.some( (item: any) => isNaN(item.originalValue), // if we have a null/undefined value in data & interpolation is disabled, then don't render area ) ? null : animateOnDataChange && animatedFillPath ? ( ) : ( ) ) : null} {spreadAreaData && ( )} ); }; const lineSvgComponent = ( points: any, currentLineThickness: number | undefined, color: ColorValue, fillPoints: any, startFillColor: string, endFillColor: string, startOpacity: number, endOpacity: number, strokeDashArray: Array | undefined | null, strokeLinecap: Linecap, showArrow: boolean, arrowPoints: any, arrowStrokeWidth: any, arrowStrokeColor: any, arrowFillColor: any, key: any, hideDataPoints: any, data: any, dataPointsShape: any, dataPointsWidth: any, dataPointsHeight: any, dataPointsColor: any, dataPointsRadius: any, textColor: any, textFontSize: any, startIndex: any, endIndex: any, isSecondary: any, showValuesAsDataPointsText: any, spacingArray: number[], ) => { if (!points) return null; const isCurved = points.includes('C') || points.includes('Q'); const clipRangeId = `Clip-range-${key}`; const uniqueId = `Gradient-line-${key}`; const isNthAreaChart = !!dataSet ? (dataSet[Number(key)].areaChart ?? areaChart) : getIsNthAreaChart(key ?? 0); // Add support for spread area data from props const spreadAreaData = props.spreadAreaData; const spreadAreaColor = props.spreadAreaColor; const spreadAreaOpacity = props.spreadAreaOpacity; let ar: LineProperties[] = [{d: '', color: '', strokeWidth: 0}]; if (points.includes(RANGE_ENTER)) { ar = getRegionPathObjects( points, color, currentLineThickness ?? 0, thickness, strokeDashArray ?? [], isCurved, RANGE_ENTER, STOP, RANGE_EXIT, curveType, ); } else if (points.includes(SEGMENT_START)) { ar = getSegmentedPathObjects( points, color, currentLineThickness ?? 0, thickness, strokeDashArray ?? [], isCurved, SEGMENT_START, SEGMENT_END, curveType, ); } const lineSvgPropsOuter: LineSvgProps = { d: animateOnDataChange && animatedPath ? animatedPath : points, fill: 'none', stroke: lineGradient ? props.lineGradientId ? `url(#${props.lineGradientId})` : `url(#lineGradient)` : color, strokeWidth: currentLineThickness || thickness, strokeLinecap, }; if ( strokeDashArray && strokeDashArray.length === 2 && typeof strokeDashArray[0] === 'number' && typeof strokeDashArray[1] === 'number' ) { lineSvgPropsOuter.strokeDasharray = strokeDashArray; } return ( {areaComponent( isNthAreaChart, startFillColor, endFillColor, startOpacity, endOpacity, uniqueId, fillPoints, startIndex, endIndex, data, clipRangeId, currentLineThickness, spreadAreaData, spacingArray, spreadAreaColor, spreadAreaOpacity, )} {lineGradient && getLineGradientComponent()} {points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? ( ar.map((item, index) => { const lineSvgProps: LineSvgProps = { d: item.d, fill: 'none', stroke: lineGradient ? props.lineGradientId ? `url(#${props.lineGradientId})` : `url(#lineGradient)` : item.color, strokeWidth: item.strokeWidth, strokeLinecap, }; if ( item.strokeDashArray && item.strokeDashArray.length === 2 && typeof item.strokeDashArray[0] === 'number' && typeof item.strokeDashArray[1] === 'number' ) { lineSvgProps.strokeDasharray = item.strokeDashArray; } return ; }) ) : animateOnDataChange && animatedPath ? ( ) : colors ? ( ) : ( )} {colors && getColorBackRects()} {renderSpecificVerticalLines(data, cumulativeSpacing1)} {renderSpecificVerticalLines(data2, cumulativeSpacing2)} {renderSpecificVerticalLines(data3, cumulativeSpacing3)} {renderSpecificVerticalLines(data4, cumulativeSpacing4)} {renderSpecificVerticalLines(data5, cumulativeSpacing5)} {dataSet?.map((set, index) => renderSpecificVerticalLines( set?.data, cumulativeSpacingForSet[index], ), ) ?? null} {/*** !!! Here it's done 5 times intentionally, so that onPress works for each line !!! ***/} {isAnimated && !renderDataPointsAfterAnimationEnds // in this condition onPress won't work properly in case of multi-line, so it's suggested to use either renderDataPointsAfterAnimationEnds prop if you want to use onPress for data points ? renderDataPoints( hideDataPoints, data, // propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, key, ) : key === lastLineNumber - 1 ? renderDataPointsForEachLine() : null} {showArrow && ( )} ); }; // Responder move events arrive for every touch sample, but the pointer snaps to // data points, so most samples resolve to the same pointer state. Writing that // state again re-rendered the whole chart on every sample (always for dataSet, // whose pointer arrays were rebuilt each time), which can flood the JS thread // during fast swipes over long series. Only write values that changed during the // current gesture. The cache is cleared when a gesture starts or ends, when the // pointer is hidden after release, and when the data changes, since other code // paths write the same state. const lastPointerState = useRef<{ source: unknown; values: Map; }>({ source: null, values: new Map(), }); const resetPointerCache = () => { lastPointerState.current = {source: null, values: new Map()}; }; const isSamePointerValue = (a: unknown, b: unknown) => Object.is(a, b) || (Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => Object.is(v, b[i]))); const setIfChanged = (setter: (value: T) => void, value: T) => { const {values} = lastPointerState.current; if (values.has(setter) && isSamePointerValue(values.get(setter), value)) { return; } values.set(setter, value); setter(value); }; const activatePointers = (x: number) => { const pointerSource = dataSet ?? data0 ?? data; if (lastPointerState.current.source !== pointerSource) { resetPointerCache(); lastPointerState.current.source = pointerSource; } let factor = -1, closestX = 0; if (doAllPointsHaveX) { let minDiff = Infinity, minDiffIndex = -1; principalCumulativeSpacing.forEach((space, index) => { const actualX = space + initialSpacing; // this is derived from getX defined in gifted-charts-core const diff = Math.abs(x - actualX); if (diff < minDiff) { minDiff = diff; minDiffIndex = index; closestX = actualX; } }); factor = minDiffIndex; } else { factor = (x - initialSpacing) / (props.spacing1 ?? spacing); } factor = Math.round(factor); factor = Math.min(factor, (data0 ?? data).length - 1); factor = Math.max(factor, 0); let item, y; item = (data0 ?? data)[factor]; if (item && !item.hidePointer) { let z = (doAllPointsHaveX ? closestX : getX( dataSet?.length ? cumulativeSpacingForSet[0] : cumulativeSpacing1, factor, )) - (pointerRadius || pointerWidth / 2) - 1; setIfChanged(setPointerX, Math.max(0.1, z)); // 0.1 is to avoid pointer going out of the chart, See https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/925 setIfChanged(setPointerIndex, factor); y = containerHeight - (item.value * containerHeight) / maxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setPointerY, y); setIfChanged(setPointerItem, item); } if (data2 && data2.length) { item = data2[factor]; if (item && !item.hidePointer) { y = containerHeight - (item.value * containerHeight) / maxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setPointerY2, y); setIfChanged(setPointerItem2, item); } } if (data3 && data3.length) { item = data3[factor]; if (item && !item.hidePointer) { y = containerHeight - (item.value * containerHeight) / maxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setPointerY3, y); setIfChanged(setPointerItem3, item); } } if (data4 && data4.length) { item = data4[factor]; if (item && !item.hidePointer) { y = containerHeight - (item.value * containerHeight) / maxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setPointerY4, y); setIfChanged(setPointerItem4, item); } } if (data5 && data5.length) { item = data5[factor]; if (item && !item.hidePointer) { y = containerHeight - (item.value * containerHeight) / maxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setPointerY5, y); setIfChanged(setPointerItem5, item); } } if (secondaryData?.length) { item = secondaryData[factor]; if (item) { y = containerHeight - (item.value * containerHeight) / secondaryMaxValue - (pointerRadius || pointerHeight / 2) + 10; setIfChanged(setSecondaryPointerY, y); // @ts-ignore setIfChanged(setSecondaryPointerItem, item); } } if (dataSet?.length) { const pointerItemsForSetLocal: lineDataItem[] = []; const secondaryPointerItemsForSetLocal: lineDataItem[] = []; const ysForDataSet = dataSet.map(set => { const item = set.data[factor]; if (set.isSecondary) { secondaryPointerItemsForSetLocal.push(item); } else { pointerItemsForSetLocal.push(item); } const y = item ? containerHeight - (item.value * containerHeight) / (set.isSecondary ? secondaryMaxValue : maxValue) - (pointerRadius || pointerHeight / 2) + 10 : 0; return y; }); setIfChanged(setPointerItemsForSet, pointerItemsForSetLocal); setIfChanged( setSecondaryPointerItemsForSet, secondaryPointerItemsForSetLocal, ); setIfChanged(setPointerYsForDataSet, ysForDataSet); } }; const renderLine = ( containerHeightIncludingBelowXAxis: number, zIndex: number, points: any, currentLineThickness: number | undefined, color: ColorValue, fillPoints: any, startFillColor: string, endFillColor: string, startOpacity: number, endOpacity: number, strokeDashArray: Array | undefined | null, strokeLinecap: Linecap, showArrow: any, arrowPoints: any, arrowStrokeWidth: any, arrowStrokeColor: any, arrowFillColor: any, hideDataPoints: any, paramData: any, dataPointsShape: any, dataPointsWidth: any, dataPointsHeight: any, dataPointsColor: any, dataPointsRadius: any, textColor: any, textFontSize: any, startIndex: any, endIndex: any, isSecondary: any, showValuesAsDataPointsText: any, spacingArray: number[], key?: number, ) => { if (!points) return null; return ( pointerConfig?.onPointerEnter?.()} onPointerLeave={() => pointerConfig?.onPointerLeave?.()} onTouchStart={() => pointerConfig?.onTouchStart?.()} onTouchEnd={() => pointerConfig?.onTouchEnd?.()} onMoveShouldSetResponder={evt => (pointerConfig ? true : false)} onStartShouldSetResponder={evt => pointerConfig && activatePointersInstantlyOnTouch ? true : false } onResponderGrant={evt => { if (!pointerConfig) return; resetPointerCache(); setResponderStartTime(evt.timeStamp); if (activatePointersOnLongPress) { return; } let x = evt.nativeEvent.locationX; activatePointers(x); pointerConfig.onResponderGrant?.(); }} onResponderMove={evt => { if (!pointerConfig) return; if ( activatePointersOnLongPress && evt.timeStamp - responderStartTime < activatePointersDelay ) { return; } else { setIfChanged(setResponderActive, true); } let x = evt.nativeEvent.locationX; let px = evt.nativeEvent.pageX; if (yAxisLabelWidth != -1 && x == px) return; // if locationX and pageX are equal, it means pointer has gone out of the chart, but this is not the case when yAxisLabelWidth is -1 if ( !activatePointersOnLongPress && x > (props.width || Dimensions.get('window').width) ) return; activatePointers(x); pointerConfig?.onResponderMove?.(); }} // onResponderReject={evt => { // console.log('evt...reject.......',evt); // }} onResponderEnd={evt => { setResponderStartTime(0); if (resetPointerIndexOnRelease) setPointerIndex(-1); setResponderActive(false); resetPointerCache(); if (!persistPointer) setTimeout(() => { setPointerX(0); resetPointerCache(); }, pointerVanishDelay); pointerConfig?.onResponderEnd?.(); }} onResponderTerminationRequest={evt => false} // onResponderTerminate={evt => { // console.log('evt...terminate.......',evt); // }} // onResponderRelease={evt => { // setResponderStartTime(0); // setResponderActive(false); // setTimeout(() => setPointerX(0), pointerVanishDelay); // }} style={[ svgWrapperViewStyle as ViewStyle, { width: totalWidth, height: containerHeightIncludingBelowXAxis, zIndex, }, ]}> {lineSvgComponent( points, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, key, hideDataPoints, paramData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, )} ); }; const renderAnimatedLine = ( containerHeightIncludingBelowXAxis: number, zIndex: number, points: any, animatedWidth: any, currentLineThickness: number | undefined, color: ColorValue, fillPoints: any, startFillColor: string, endFillColor: string, startOpacity: number, endOpacity: number, strokeDashArray: Array | undefined | null, strokeLinecap: Linecap, showArrow: any, arrowPoints: any, arrowStrokeWidth: any, arrowStrokeColor: any, arrowFillColor: any, hideDataPoints: any, paramsData: any, dataPointsShape: any, dataPointsWidth: any, dataPointsHeight: any, dataPointsColor: any, dataPointsRadius: any, textColor: any, textFontSize: any, startIndex: any, endIndex: any, isSecondary: any, showValuesAsDataPointsText: any, spacingArray: number[], key?: number, ) => { if (!points) return null; return ( pointerConfig?.onPointerEnter?.()} onPointerLeave={() => pointerConfig?.onPointerLeave?.()} onMoveShouldSetResponder={evt => (pointerConfig ? true : false)} onStartShouldSetResponder={evt => pointerConfig && activatePointersInstantlyOnTouch ? true : false } onResponderGrant={evt => { if (!pointerConfig) return; resetPointerCache(); setResponderStartTime(evt.timeStamp); if (activatePointersOnLongPress) { return; } let x = evt.nativeEvent.locationX; activatePointers(x); pointerConfig.onResponderGrant?.(); }} onResponderMove={evt => { if (!pointerConfig) return; if ( activatePointersOnLongPress && evt.timeStamp - responderStartTime < activatePointersDelay ) { return; } else { setIfChanged(setResponderActive, true); } let x = evt.nativeEvent.locationX; if ( !activatePointersOnLongPress && x > (props.width || Dimensions.get('window').width) ) return; activatePointers(x); pointerConfig?.onResponderMove?.(); }} // onResponderReject={evt => { // console.log('evt...reject.......',evt); // }} onResponderEnd={evt => { // console.log('evt...end.......',evt); setResponderStartTime(0); if (resetPointerIndexOnRelease) setPointerIndex(-1); setResponderActive(false); resetPointerCache(); if (!persistPointer) setTimeout(() => { setPointerX(0); resetPointerCache(); }, pointerVanishDelay); pointerConfig?.onResponderEnd?.(); }} onResponderTerminationRequest={evt => false} // onResponderTerminate={evt => { // console.log('evt...terminate.......',evt); // }} // onResponderRelease={evt => { // setResponderStartTime(0); // setResponderActive(false); // setTimeout(() => setPointerX(0), pointerVanishDelay); // }} style={[ svgWrapperViewStyle as ViewStyle, { width: animatedWidth, height: containerHeightIncludingBelowXAxis, zIndex, }, ]}> {lineSvgComponent( points, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, key, hideDataPoints, paramsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, )} ); }; const remainingScrollViewProps = { onScroll: (ev: any) => { props.onScroll?.(ev); if ( pointerConfig && pointerConfig.activatePointersOnLongPress && pointerConfig.autoAdjustPointerLabelPosition ) { setScrollX(ev.nativeEvent.contentOffset.x); } }, bounces: props.bounces, overScrollMode: props.overScrollMode ?? 'auto', }; const renderStrips = (item: lineDataItem, index: number, ind: number) => { if (item.showStrip || index === selectedIndex) { const currentStripHeight = item.stripHeight ?? stripHeight; const currentStripWidth = item.stripWidth ?? stripWidth; const currentStripOpacity = item.stripOpacity ?? stripOpacity; const currentStripStrokeDashArray = item.stripStrokeDashArray ?? stripStrokeDashArray ?? ''; const currentStripColor = item.stripColor || stripColor; const y1 = currentStripHeight ? containerHeight - currentStripHeight + 8 : containerHeight - (item.dataPointHeight ?? dataPointsHeight1) / 2 + 14 - ((item.originalValue ?? 0) * containerHeight) / maxValue; const actualStripHeight = currentStripHeight || ((item.originalValue ?? 0) * containerHeight) / maxValue - 2 + overflowTop; return ( ); } return null; }; const renderChartContent = (containerHeightIncludingBelowXAxis: number) => { return ( <> {Object.keys(strips).length > 0 || (focusEnabled && showStripOnFocus && selectedIndex !== -1) ? ( // render focus strips separately (so that it's rendered below the data points unless specified otherwise) {Object.keys(strips).map((stripKey: any) => { return Object.keys(strips[stripKey]).map((ind: any) => { const {item, index, key} = strips[stripKey][ind]; return renderStrips(item, index, key); }); })} {focusEnabled && showStripOnFocus && selectedIndex !== -1 ? ( <> {dataSet && pointsFromSet.length ? dataSet.map((set, ind) => { return set.data.map((item, index) => renderStrips(item, index, ind), ); }) : data?.map((item, index) => renderStrips(item, index, 0))} {data2?.map((item, index) => renderStrips(item, index, 1))} {data3?.map((item, index) => renderStrips(item, index, 2))} {data4?.map((item, index) => renderStrips(item, index, 3))} {data5?.map((item, index) => renderStrips(item, index, 4))} {secondaryData?.map((item, index) => renderStrips(item, index, 5), )} ) : null} ) : null} {dataSet ? pointsFromSet.length ? dataSet.map((set, index) => { if (isAnimated) { return renderAnimatedLine( containerHeightIncludingBelowXAxis, set.zIndex ?? zIndex1, pointsFromSet[index], widthValue, set.thickness ?? thickness1, set.color ?? color1, fillPointsFromSet[index], set.startFillColor ?? startFillColor1, set.endFillColor ?? endFillColor1, set.startOpacity ?? startOpacity1, set.endOpacity ?? endOpacity1, set.strokeDashArray ?? strokeDashArray1, set.strokeLinecap ?? strokeLinecap1, set.showArrow || props.showArrows, arrowPointsFromSet[index], arrowStrokeWidthsFromSet?.[index], arrowStrokeColorsFromSet?.[index], arrowFillColorsFromSet?.[index], set.hideDataPoints ?? hideDataPoints1, set.data, // adjustToOffset(set.data, -(props.yAxisOffset ?? 0)), // need the actual values passed by user set.dataPointsShape ?? dataPointsShape1, set.dataPointsWidth ?? dataPointsWidth1, set.dataPointsHeight ?? dataPointsHeight1, set.dataPointsColor ?? dataPointsColor1, set.dataPointsRadius ?? dataPointsRadius1, set.textColor ?? textColor1, set.textFontSize ?? textFontSize1, set.startIndex ?? 0, set.endIndex ?? set.data.length - 1, set.isSecondary, showValuesAsDataPointsText, cumulativeSpacingForSet[index], index, ); } else { return renderLine( containerHeightIncludingBelowXAxis, set.zIndex ?? zIndex1, pointsFromSet[index], set.thickness ?? thickness1, set.color ?? color1, fillPointsFromSet[index], set.startFillColor ?? startFillColor1, set.endFillColor ?? endFillColor1, set.startOpacity ?? startOpacity1, set.endOpacity ?? endOpacity1, set.strokeDashArray ?? strokeDashArray1, set.strokeLinecap ?? strokeLinecap1, set.showArrow || props.showArrows, arrowPointsFromSet[index], arrowStrokeWidthsFromSet?.[index], arrowStrokeColorsFromSet?.[index], arrowFillColorsFromSet?.[index], set.hideDataPoints ?? hideDataPoints1, set.data, // adjustToOffset(set.data, -(props.yAxisOffset ?? 0)), // need the actual values passed by user set.dataPointsShape ?? dataPointsShape1, set.dataPointsWidth ?? dataPointsWidth1, set.dataPointsHeight ?? dataPointsHeight1, set.dataPointsColor ?? dataPointsColor1, set.dataPointsRadius ?? dataPointsRadius1, set.textColor ?? textColor1, set.textFontSize ?? textFontSize1, set.startIndex ?? 0, set.endIndex ?? set.data.length - 1, set.isSecondary, showValuesAsDataPointsText, cumulativeSpacingForSet[index], index, ); } }) : null : isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, zIndex1, points, widthValue, thickness1, color1, fillPoints, startFillColor1, endFillColor1, startOpacity1, endOpacity1, strokeDashArray1, strokeLinecap1, props.showArrow1 || props.showArrows, arrow1Points, arrowStrokeWidth1, arrowStrokeColor1, arrowFillColor1, hideDataPoints1, data, // props.data, dataPointsShape1, dataPointsWidth1, dataPointsHeight1, dataPointsColor1, dataPointsRadius1, textColor1, textFontSize1, startIndex1, endIndex1, false, showValuesAsDataPointsText, cumulativeSpacing1, 0, ) : renderLine( containerHeightIncludingBelowXAxis, zIndex1, points, thickness1, color1, fillPoints, startFillColor1, endFillColor1, startOpacity1, endOpacity1, strokeDashArray1, strokeLinecap1, props.showArrow1 || props.showArrows, arrow1Points, arrowStrokeWidth1, arrowStrokeColor1, arrowFillColor1, hideDataPoints1, data, // props.data, dataPointsShape1, dataPointsWidth1, dataPointsHeight1, dataPointsColor1, dataPointsRadius1, textColor1, textFontSize1, startIndex1, endIndex1, false, showValuesAsDataPointsText, cumulativeSpacing1, 0, )} {secondaryPoints ? isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, secondaryLineConfig.zIndex, secondaryPoints, widthValue, secondaryLineConfig.thickness, secondaryLineConfig.color, secondaryFillPoints, secondaryLineConfig.startFillColor, secondaryLineConfig.endFillColor, secondaryLineConfig.startOpacity, secondaryLineConfig.endOpacity, secondaryLineConfig.strokeDashArray, secondaryLineConfig.strokeLinecap, secondaryLineConfig.showArrow, secondaryArrowPoints, secondaryLineConfig.arrowConfig?.strokeWidth, secondaryLineConfig.arrowConfig?.strokeColor, secondaryLineConfig.arrowConfig?.fillColor, secondaryLineConfig.hideDataPoints, secondaryData, // props.secondaryData, secondaryLineConfig.dataPointsShape, secondaryLineConfig.dataPointsWidth, secondaryLineConfig.dataPointsHeight, secondaryLineConfig.dataPointsColor, secondaryLineConfig.dataPointsRadius, secondaryLineConfig.textColor, secondaryLineConfig.textFontSize, secondaryLineConfig.startIndex, secondaryLineConfig.endIndex, true, secondaryLineConfig.showValuesAsDataPointsText, cumulativeSpacingSecondary, 6666, ) : renderLine( containerHeightIncludingBelowXAxis, secondaryLineConfig.zIndex, secondaryPoints, secondaryLineConfig.thickness, secondaryLineConfig.color, secondaryFillPoints, secondaryLineConfig.startFillColor, secondaryLineConfig.endFillColor, secondaryLineConfig.startOpacity, secondaryLineConfig.endOpacity, secondaryLineConfig.strokeDashArray, secondaryLineConfig.strokeLinecap, secondaryLineConfig.showArrow, secondaryArrowPoints, secondaryLineConfig.arrowConfig?.strokeWidth, secondaryLineConfig.arrowConfig?.strokeColor, secondaryLineConfig.arrowConfig?.fillColor, secondaryLineConfig.hideDataPoints, secondaryData, // props.secondaryData, secondaryLineConfig.dataPointsShape, secondaryLineConfig.dataPointsWidth, secondaryLineConfig.dataPointsHeight, secondaryLineConfig.dataPointsColor, secondaryLineConfig.dataPointsRadius, secondaryLineConfig.textColor, secondaryLineConfig.textFontSize, secondaryLineConfig.startIndex, secondaryLineConfig.endIndex, true, secondaryLineConfig.showValuesAsDataPointsText, cumulativeSpacingSecondary, 6666, ) : null} {points2 ? isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, zIndex2, points2, widthValue2, thickness2, color2, fillPoints2, startFillColor2, endFillColor2, startOpacity2, endOpacity2, strokeDashArray2, strokeLinecap2, props.showArrow2 || props.showArrows, arrow2Points, arrowStrokeWidth2, arrowStrokeColor2, arrowFillColor2, hideDataPoints2, data2, // props.data2, dataPointsShape2, dataPointsWidth2, dataPointsHeight2, dataPointsColor2, dataPointsRadius2, textColor2, textFontSize2, startIndex2, endIndex2, false, showValuesAsDataPointsText, cumulativeSpacing2, 1, ) : renderLine( containerHeightIncludingBelowXAxis, zIndex2, points2, thickness2, color2, fillPoints2, startFillColor2, endFillColor2, startOpacity2, endOpacity2, strokeDashArray2, strokeLinecap2, props.showArrow2 || props.showArrows, arrow2Points, arrowStrokeWidth2, arrowStrokeColor2, arrowFillColor2, hideDataPoints2, data2, // props.data2, dataPointsShape2, dataPointsWidth2, dataPointsHeight2, dataPointsColor2, dataPointsRadius2, textColor2, textFontSize2, startIndex2, endIndex2, false, showValuesAsDataPointsText, cumulativeSpacing2, 1, ) : null} {points3 ? isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, zIndex3, points3, widthValue3, thickness3, color3, fillPoints3, startFillColor3, endFillColor3, startOpacity3, endOpacity3, strokeDashArray3, strokeLinecap3, props.showArrow3 || props.showArrows, arrow3Points, arrowStrokeWidth3, arrowStrokeColor3, arrowFillColor3, hideDataPoints3, data3, // props.data3, dataPointsShape3, dataPointsWidth3, dataPointsHeight3, dataPointsColor3, dataPointsRadius3, textColor3, textFontSize3, startIndex3, endIndex3, false, showValuesAsDataPointsText, cumulativeSpacing3, 2, ) : renderLine( containerHeightIncludingBelowXAxis, zIndex3, points3, thickness3, color3, fillPoints3, startFillColor3, endFillColor3, startOpacity3, endOpacity3, strokeDashArray3, strokeLinecap3, props.showArrow3 || props.showArrows, arrow3Points, arrowStrokeWidth3, arrowStrokeColor3, arrowFillColor3, hideDataPoints3, data3, // props.data3, dataPointsShape3, dataPointsWidth3, dataPointsHeight3, dataPointsColor3, dataPointsRadius3, textColor3, textFontSize3, startIndex3, endIndex3, false, showValuesAsDataPointsText, cumulativeSpacing3, 2, ) : null} {points4 ? isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, zIndex4, points4, widthValue4, thickness4, color4, fillPoints4, startFillColor4, endFillColor4, startOpacity4, endOpacity4, strokeDashArray4, strokeLinecap4, props.showArrow4 || props.showArrows, arrow4Points, arrowStrokeWidth4, arrowStrokeColor4, arrowFillColor4, hideDataPoints4, data4, // props.data4, dataPointsShape4, dataPointsWidth4, dataPointsHeight4, dataPointsColor4, dataPointsRadius4, textColor4, textFontSize4, startIndex4, endIndex4, false, showValuesAsDataPointsText, cumulativeSpacing4, 3, ) : renderLine( containerHeightIncludingBelowXAxis, zIndex4, points4, thickness4, color4, fillPoints4, startFillColor4, endFillColor4, startOpacity4, endOpacity4, strokeDashArray4, strokeLinecap4, props.showArrow4 || props.showArrows, arrow4Points, arrowStrokeWidth4, arrowStrokeColor4, arrowFillColor4, hideDataPoints4, data4, // props.data4, dataPointsShape4, dataPointsWidth4, dataPointsHeight4, dataPointsColor4, dataPointsRadius4, textColor4, textFontSize4, startIndex4, endIndex4, false, showValuesAsDataPointsText, cumulativeSpacing4, 3, ) : null} {points5 ? isAnimated ? renderAnimatedLine( containerHeightIncludingBelowXAxis, zIndex5, points5, widthValue5, thickness5, color5, fillPoints5, startFillColor5, endFillColor5, startOpacity5, endOpacity5, strokeDashArray5, strokeLinecap5, props.showArrow5 || props.showArrows, arrow5Points, arrowStrokeWidth5, arrowStrokeColor5, arrowFillColor5, hideDataPoints5, data5, // props.data5, dataPointsShape5, dataPointsWidth5, dataPointsHeight5, dataPointsColor5, dataPointsRadius5, textColor5, textFontSize5, startIndex5, endIndex5, false, showValuesAsDataPointsText, cumulativeSpacing5, 4, ) : renderLine( containerHeightIncludingBelowXAxis, zIndex5, points5, thickness5, color5, fillPoints5, startFillColor5, endFillColor5, startOpacity5, endOpacity5, strokeDashArray5, strokeLinecap5, props.showArrow5 || props.showArrows, arrow5Points, arrowStrokeWidth5, arrowStrokeColor5, arrowFillColor5, hideDataPoints5, data5, // props.data5, dataPointsShape5, dataPointsWidth5, dataPointsHeight5, dataPointsColor5, dataPointsRadius5, textColor5, textFontSize5, startIndex5, endIndex5, false, showValuesAsDataPointsText, cumulativeSpacing5, 4, ) : null} {intersectionAreaConfig && (props.areaChart || (props.areaChart1 && props.areaChart2)) ? renderIntersection() : null} {pointerX > 0 ? ( {!stripOverPointer && renderStripAndLabel()} {dataSet ? ( renderPointer(0, true) ) : ( // dataSet.map((set, index) => renderPointer(index)) <> {renderPointer(1)} {points2 ? renderPointer(2) : null} {points3 ? renderPointer(3) : null} {points4 ? renderPointer(4) : null} {points5 ? renderPointer(5) : null} {secondaryPoints ? renderPointer(6666) : null} {stripOverPointer && renderStripAndLabel()} )} ) : null} {(data0 ?? data).map((item: lineDataItem, index: number) => { const secondaryLabel = item.secondaryLabel ?? secondaryXAxis?.labelTexts?.[index] ?? (doAllPointsHaveX ? (item.x ?? '').toString() : ''); const secondaryLabelTextStyle = item.secondaryLabelTextStyle ?? secondaryXAxis?.labelsTextStyle ?? item.labelTextStyle ?? props.xAxisLabelTextStyle; return ( {isAnimated ? renderAnimatedLabel( false, index, item.label || (props.xAxisLabelTexts && props.xAxisLabelTexts[index] ? props.xAxisLabelTexts[index] : doAllPointsHaveX ? (item.x ?? '').toString() : ''), item.labelTextStyle || props.xAxisLabelTextStyle, item.labelComponent, ) : renderLabel( false, index, item.label || (props.xAxisLabelTexts && props.xAxisLabelTexts[index] ? props.xAxisLabelTexts[index] : doAllPointsHaveX ? (item.x ?? '').toString() : ''), item.labelTextStyle || props.xAxisLabelTextStyle, item.labelComponent, )} {secondaryXAxis ? isAnimated ? renderAnimatedLabel( true, index, secondaryLabel, secondaryLabelTextStyle, item.secondaryLabelComponent, ) : renderLabel( true, index, secondaryLabel, secondaryLabelTextStyle, item.secondaryLabelComponent, ) : null} ); })} {pointerConfig?.dynamicLegendComponent && pointerX > 0 ? ( {pointerConfig.dynamicLegendComponent( pointerItemLocal, pointerIndex, )} ) : null} ); }; return ( ); };