import { XAxis } from 'recharts';
import { useTheme } from 'styled-components';
import { fontSize } from '../../../style/theme';
import {
getTicks,
calculateLabelVisibility,
TIME_CONSTANTS,
getEdgeMargin,
} from './GlobalHealthBar.utils';
import { FormattedDateTime } from '../../date/FormattedDateTime';
interface HealthBarXAxisProps {
startTimestamp: number;
endTimestamp: number;
}
const CustomTick = ({
tickProps,
startTimestamp,
endTimestamp,
}: {
tickProps: any;
startTimestamp: number;
endTimestamp: number;
}) => {
const theme = useTheme();
const { y, payload, width, index, visibleTicksCount } = tickProps;
const span = endTimestamp - startTimestamp;
const is7DaySpan = span === 7 * TIME_CONSTANTS.ONE_DAY;
const isDaySpan = span === TIME_CONSTANTS.ONE_DAY;
const shouldShowLabel = calculateLabelVisibility(
width,
visibleTicksCount,
span,
index,
endTimestamp,
);
const edgeMargin = getEdgeMargin(index, visibleTicksCount, isDaySpan);
return (
// use coordinate to center the text
shouldShowLabel && (
{is7DaySpan ? (
) : (
)}
)
);
};
export const HealthBarXAxis = ({
startTimestamp,
endTimestamp,
}: HealthBarXAxisProps) => {
const theme = useTheme();
const ticks = getTicks(startTimestamp, endTimestamp);
return (
{
return (
);
}}
ticks={ticks}
tickLine={{ stroke: theme.textSecondary }}
axisLine={false}
/>
);
};