2022-03-09 10:43:02 +05:30
|
|
|
import { StyledDiv } from 'components/Styled';
|
2022-03-25 12:03:57 +05:30
|
|
|
import { ITraceMetaData } from 'container/GantChart';
|
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-24 12:06:57 +05:30
|
|
|
import React, { useEffect, useRef, 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
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
const TimelineHeight = 22;
|
|
|
|
|
const TimelineHSpacing = 0;
|
2022-03-06 12:02:21 +05:30
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
function Timeline({
|
2022-03-03 19:04:23 +05:30
|
|
|
traceMetaData,
|
|
|
|
|
globalTraceMetadata,
|
|
|
|
|
setIntervalUnit,
|
2022-03-22 12:10:31 +05:30
|
|
|
}: TimelineProps): JSX.Element {
|
2022-03-03 19:04:23 +05:30
|
|
|
const [ref, { width }] = useMeasure<HTMLDivElement>();
|
|
|
|
|
const { isDarkMode } = useThemeMode();
|
|
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
const asd = useRef('');
|
|
|
|
|
|
|
|
|
|
asd.current = '1';
|
|
|
|
|
|
2022-03-03 19:04:23 +05:30
|
|
|
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({
|
2022-03-22 12:10:31 +05:30
|
|
|
globalTraceMetadata,
|
2022-03-03 19:04:23 +05:30
|
|
|
localTraceMetaData: traceMetaData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let intervalUnit = INTERVAL_UNITS[0];
|
2022-03-24 12:06:57 +05:30
|
|
|
for (let idx = 0; idx < INTERVAL_UNITS.length; idx += 1) {
|
|
|
|
|
const standardInterval = INTERVAL_UNITS[idx];
|
|
|
|
|
if (baseSpread * standardInterval.multiplier < 1) {
|
|
|
|
|
const index = idx;
|
2022-03-17 11:56:25 +05:30
|
|
|
if (index > 1) intervalUnit = INTERVAL_UNITS[index - 1];
|
2022-03-03 19:04:23 +05:30
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 16:37:15 +05:30
|
|
|
intervalUnit = intervalUnit || INTERVAL_UNITS[0];
|
2022-03-03 19:04:23 +05:30
|
|
|
setIntervals(
|
|
|
|
|
getIntervals({
|
|
|
|
|
baseInterval,
|
|
|
|
|
baseSpread,
|
|
|
|
|
intervalSpreadNormalized,
|
|
|
|
|
intervalUnit,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-03-11 16:32:11 +05:30
|
|
|
setIntervalUnit(intervalUnit);
|
2022-03-11 16:37:15 +05:30
|
|
|
}, [traceMetaData, globalTraceMetadata, setIntervalUnit]);
|
2022-03-03 19:04:23 +05:30
|
|
|
|
|
|
|
|
return (
|
2022-03-24 12:06:57 +05:30
|
|
|
<StyledDiv ref={ref as never} styledclass={[styles.timelineContainer]}>
|
2022-03-09 10:43:02 +05:30
|
|
|
<Svg
|
2022-03-24 12:06:57 +05:30
|
|
|
viewBox={`0 0 ${width} ${TimelineHeight}`}
|
2022-03-03 19:04:23 +05:30
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
<line
|
2022-03-24 12:06:57 +05:30
|
|
|
x1={TimelineHSpacing}
|
|
|
|
|
y1={TimelineHeight}
|
|
|
|
|
x2={width - TimelineHSpacing}
|
|
|
|
|
y2={TimelineHeight}
|
2022-03-03 19:04:23 +05:30
|
|
|
stroke={isDarkMode ? 'white' : 'black'}
|
|
|
|
|
strokeWidth="1"
|
|
|
|
|
/>
|
|
|
|
|
{intervals &&
|
|
|
|
|
intervals.map((interval, index) => (
|
2022-03-09 10:43:02 +05:30
|
|
|
<TimelineInterval
|
2022-03-25 12:03:57 +05:30
|
|
|
transform={`translate(${TimelineHSpacing +
|
2022-03-24 12:06:57 +05:30
|
|
|
(interval.percentage * (width - 2 * TimelineHSpacing)) / 100
|
2022-03-25 12:03:57 +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
|
2022-03-24 12:06:57 +05:30
|
|
|
y1={TimelineHeight - 5}
|
|
|
|
|
y2={TimelineHeight + 0.5}
|
2022-03-03 19:04:23 +05:30
|
|
|
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-22 12:10:31 +05:30
|
|
|
}
|
2022-03-03 19:04:23 +05:30
|
|
|
|
2022-03-06 12:02:21 +05:30
|
|
|
interface TimelineProps {
|
2022-03-17 11:56:25 +05:30
|
|
|
traceMetaData: {
|
|
|
|
|
globalStart: number;
|
|
|
|
|
globalEnd: number;
|
|
|
|
|
spread: number;
|
|
|
|
|
totalSpans: number;
|
|
|
|
|
levels: number;
|
|
|
|
|
};
|
2022-03-25 12:03:57 +05:30
|
|
|
globalTraceMetadata: ITraceMetaData;
|
2022-03-17 11:56:25 +05:30
|
|
|
setIntervalUnit: React.Dispatch<React.SetStateAction<IIntervalUnit>>;
|
2022-03-06 12:02:21 +05:30
|
|
|
}
|
|
|
|
|
|
2022-03-03 19:04:23 +05:30
|
|
|
export default Timeline;
|