Skip to content

Commit

Permalink
refactor: [GSW-2033] Extract this nested ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 4, 2025
1 parent 3e5a889 commit 632104e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/web/src/components/common/line-graph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const LineGraph: React.FC<LineGraphProps> = ({
strokeWidth = 2,
gradientStartColor = `${color}66`,
gradientEndColor = "transparent",
smooth,
smooth = false,
width = VIEWPORT_DEFAULT_WIDTH,
height = VIEWPORT_DEFAULT_HEIGHT,
forcedHeight,
Expand Down Expand Up @@ -537,6 +537,12 @@ const LineGraph: React.FC<LineGraphProps> = ({
onMouseMove(event);
};

const getLineCommand = (point: Point, index: number, points: Point[], smooth: boolean) => {
const smoothCommand = smooth ? bezierCommand(point, index, points) : ` L ${point.x},${point.y}`;

return index === 0 ? ` L ${point.x},${point.y}` : smoothCommand;
};

const areaPath = useMemo(() => {
if (!points || points.length === 0 || points.some(point => point === undefined)) {
return undefined;
Expand All @@ -550,8 +556,8 @@ const LineGraph: React.FC<LineGraphProps> = ({
const point = points[i];
// Plots the actual curve only when the current point is above firstPoint.y
if (point.y <= firstPoint.y) {
path +=
i === 0 ? ` L ${point.x},${point.y}` : smooth ? bezierCommand(point, i, points) : ` L ${point.x},${point.y}`;
const lineCommand = getLineCommand(point, i, points, smooth);
path += lineCommand;
} else {
// Move at the level of firstPoint.y if it is below firstPoint.y
path += ` L ${point.x},${firstPoint.y}`;
Expand Down

0 comments on commit 632104e

Please sign in to comment.