Skip to content

Commit

Permalink
fix: change inverted line strategy into lead line index
Browse files Browse the repository at this point in the history
  • Loading branch information
WadhahEssam committed Nov 13, 2023
1 parent 9093a91 commit 9ff2f34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const getExtraConfig = (extraConfig: ExtraConfig): ExtraConfig => {
activeOffsetX: extraConfig.activeOffsetX || EXTRA_CONFIG.activeOffsetX,
animationConfig:
extraConfig.animationConfig || EXTRA_CONFIG.animationConfig,
invertLineOrder:
extraConfig.invertLineOrder !== undefined
? extraConfig.invertLineOrder
: EXTRA_CONFIG.invertLineOrder,
leadLineIndex:
extraConfig.leadLineIndex !== undefined
? extraConfig.leadLineIndex
: EXTRA_CONFIG.leadLineIndex,
};
};
function LineChart({
Expand Down
14 changes: 4 additions & 10 deletions src/SvgPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, {
ReactElement,
useCallback,
useEffect,
useMemo,
} from 'react';
import {
interpolate,
Expand Down Expand Up @@ -88,16 +87,9 @@ const SvgPath = ({
return activeIndexLocal;
}, [activeTouchX, lines[0]?.data]);

const checkedLines = useMemo(() => {
if (extraConfig?.invertLineOrder) {
return [...lines].reverse();
}
return lines;
}, [lines, extraConfig?.invertLineOrder]);

return (
<>
{checkedLines.map((line, index) => {
{lines.map((line, index) => {
if (line?.data) {
return (
<MemoizedLineComponent
Expand All @@ -110,7 +102,9 @@ const SvgPath = ({
activeTouch={activeTouch}
identifier={`${index}`}
extraConfig={extraConfig}
onPointChange={index === 0 ? onPointChange : undefined}
onPointChange={
index === extraConfig.leadLineIndex ? onPointChange : undefined
}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/defaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const EXTRA_CONFIG = {
calculateChartYAxisMinMax: undefined,
activeOffsetX: [0, 0],
animationConfig: undefined,
invertLineOrder: false,
leadLineIndex: 0,
};

export const LINE_CHART = {
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ export interface ExtraConfig {
*/
animationConfig?: AnimationConfig;
/**
* Invert the order of the lines (useful when you want to show the last line on top)
* @default false
* The line where the onPointFocus & activePointSharedValue will be called on
* @default 0
*/
invertLineOrder?: boolean;
leadLineIndex?: number;
}

/**
Expand Down

0 comments on commit 9ff2f34

Please sign in to comment.