2022-03-09 10:43:02 +05:30
|
|
|
import { StyledDiv } from 'components/Styled';
|
2022-03-16 16:05:21 +05:30
|
|
|
import { IIntervalUnit, INTERVAL_UNITS } from 'container/TraceDetail/utils';
|
2022-03-03 19:04:23 +05:30
|
|
|
import useThemeMode from 'hooks/useThemeMode';
|
2022-03-14 20:15:21 +05:30
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-03-09 10:43:02 +05:30
|
|
|
import { useMeasure } from 'react-use';
|
|
|
|
|
|
|
|
|
|
import { styles, Svg, TimelineInterval } from './styles';
|
2022-03-03 19:04:23 +05:30
|
|
|
import { Interval } from './types';
|
2022-03-09 10:43:02 +05:30
|
|
|
import { getIntervals, getIntervalSpread } from './utils';
|
2022-03-06 12:02:21 +05:30
|
|
|
|
|
|
|
|
const Timeline_Height = 22;
|
|
|
|
|
const Timeline_H_Spacing = 0;
|
|
|
|
|
|
2022-03-03 19:04:23 +05:30
|
|
|
const Timeline = ({
|
|
|
|
|
traceMetaData,
|
|
|
|
|
globalTraceMetadata,
|
|
|
|
|
setIntervalUnit,
|
2022-03-09 10:43:02 +05:30
|
|
|
}: TimelineProps): JSX.Element => {
|
2022-03-03 19:04:23 +05:30
|
|
|
const [ref, { width }] = useMeasure<HTMLDivElement>();
|
|
|
|
|
const { isDarkMode } = useThemeMode();
|
|
|
|
|
|
|
|
|
|
const [intervals, setIntervals] = useState<Interval[] | null>(null);
|
|
|
|
|
|
2022-03-06 12:02:21 +05:30
|
|
|
useEffect(() => {
|
2022-03-03 19:04:23 +05:30
|
|
|
const {
|
|
|
|
|
baseInterval,
|
|
|
|
|
baseSpread,
|
|
|
|
|
intervalSpreadNormalized,
|
|
|
|
|
} = getIntervalSpread({
|
|
|
|
|
globalTraceMetadata: globalTraceMetadata,
|
|
|
|
|
localTraceMetaData: traceMetaData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let intervalUnit = INTERVAL_UNITS[0];
|
|
|
|
|
for (const idx in INTERVAL_UNITS) {
|
|
|
|
|
const standard_interval = INTERVAL_UNITS[idx];
|
|
|
|
|
if (baseSpread * standard_interval.multiplier < 1) {
|
2022-03-07 16:08:37 +05:30
|
|
|
if (idx > 1) intervalUnit = INTERVAL_UNITS[idx - 1];
|
2022-03-03 19:04:23 +05:30
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIntervalUnit(intervalUnit);
|
|
|
|
|
setIntervals(
|
|
|
|
|
getIntervals({
|
|
|
|
|
baseInterval,
|
|
|
|
|
baseSpread,
|
|
|
|
|
intervalSpreadNormalized,
|
|
|
|
|
intervalUnit,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-03-06 12:02:21 +05:30
|
|
|
}, []);
|
2022-03-03 19:04:23 +05:30
|
|
|
|
|
|
|
|
return (
|
2022-03-09 10:43:02 +05:30
|
|
|
<StyledDiv ref={ref} styledclass={[styles.timelineContainer]}>
|
|
|
|
|
<Svg
|
2022-03-03 19:04:23 +05:30
|
|
|
viewBox={`0 0 ${width} ${Timeline_Height}`}
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
<line
|
|
|
|
|
x1={Timeline_H_Spacing}
|
|
|
|
|
y1={Timeline_Height}
|
|
|
|
|
x2={width - Timeline_H_Spacing}
|
|
|
|
|
y2={Timeline_Height}
|
|
|
|
|
stroke={isDarkMode ? 'white' : 'black'}
|
|
|
|
|
strokeWidth="1"
|
|
|
|
|
/>
|
|
|
|
|
{intervals &&
|
|
|
|
|
intervals.map((interval, index) => (
|
2022-03-09 10:43:02 +05:30
|
|
|
<TimelineInterval
|
2022-03-16 16:05:21 +05:30
|
|
|
transform={`translate(${Timeline_H_Spacing +
|
2022-03-03 19:04:23 +05:30
|
|
|
(interval.percentage * (width - 2 * Timeline_H_Spacing)) / 100
|
2022-03-16 16:05:21 +05:30
|
|
|
},0)`}
|
2022-03-09 10:43:02 +05:30
|
|
|
key={`${interval.label + interval.percentage + index}`}
|
2022-03-03 19:04:23 +05:30
|
|
|
>
|
|
|
|
|
<text y={13} fill={isDarkMode ? 'white' : 'black'}>
|
|
|
|
|
{interval.label}
|
|
|
|
|
</text>
|
|
|
|
|
<line
|
|
|
|
|
y1={Timeline_Height - 5}
|
|
|
|
|
y2={Timeline_Height + 0.5}
|
|
|
|
|
stroke={isDarkMode ? 'white' : 'black'}
|
|
|
|
|
strokeWidth="1"
|
|
|
|
|
/>
|
2022-03-09 10:43:02 +05:30
|
|
|
</TimelineInterval>
|
2022-03-03 19:04:23 +05:30
|
|
|
))}
|
2022-03-09 10:43:02 +05:30
|
|
|
</Svg>
|
|
|
|
|
</StyledDiv>
|
2022-03-03 19:04:23 +05:30
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-06 12:02:21 +05:30
|
|
|
interface TimelineProps {
|
|
|
|
|
traceMetaData: object;
|
|
|
|
|
globalTraceMetadata: object;
|
2022-03-16 16:05:21 +05:30
|
|
|
intervalUnit: IIntervalUnit;
|
2022-03-16 16:14:27 +05:30
|
|
|
setIntervalUnit: () => void;
|
2022-03-06 12:02:21 +05:30
|
|
|
}
|
|
|
|
|
|
2022-03-03 19:04:23 +05:30
|
|
|
export default Timeline;
|