2024-01-09 16:25:36 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { G, Line } from 'react-native-svg';
|
2024-01-11 23:59:15 -07:00
|
|
|
import { colors } from '../../styles';
|
2024-01-15 18:40:24 -07:00
|
|
|
import { ScaleLinearType } from './graph-types';
|
2024-01-09 16:25:36 -07:00
|
|
|
|
|
|
|
interface CustomGridProps {
|
2024-01-15 18:40:24 -07:00
|
|
|
y: ScaleLinearType;
|
2024-01-09 16:42:38 -07:00
|
|
|
ticks: Array<number>;
|
2024-01-09 16:25:36 -07:00
|
|
|
}
|
|
|
|
|
2024-01-15 18:40:24 -07:00
|
|
|
export const CustomGrid: React.FC<Partial<CustomGridProps>> = ({ y, ticks }) => {
|
2024-01-09 16:25:36 -07:00
|
|
|
const [firstTick, ...remainingTicks] = ticks;
|
|
|
|
const dashArray = [1, 3];
|
|
|
|
const strokeSolidWidth = 0.2;
|
|
|
|
const strokeSolidColor = colors.bgBlack;
|
|
|
|
const strokeDashWidth = 1;
|
|
|
|
const strokeDashColor = colors.lightGrey;
|
|
|
|
|
|
|
|
const renderLine = (tick: number, stroke: string, strokeWidth: number, dashArray?: number[]) => (
|
|
|
|
<Line
|
|
|
|
key={`line-${tick}`}
|
|
|
|
x1="0%"
|
|
|
|
x2="100%"
|
|
|
|
y1={y(tick)}
|
|
|
|
y2={y(tick)}
|
|
|
|
stroke={stroke}
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
strokeDasharray={dashArray}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<G>
|
|
|
|
{renderLine(firstTick, strokeSolidColor, strokeSolidWidth)}
|
|
|
|
{remainingTicks.map((tick) => renderLine(tick, strokeDashColor, strokeDashWidth, dashArray))}
|
|
|
|
</G>
|
|
|
|
);
|
|
|
|
};
|