Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] TracingGanttChart: align span duration label location based on available space #2348

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ describe('SpanDuration', () => {
viewport: { startTimeUnixMs: trace1_root.startTimeUnixMs, endTimeUnixMs: trace1_root.endTimeUnixMs },
});
expect(screen.getByText('150ms')).toBeInTheDocument();
expect(parseInt(screen.getByText('150ms').style.left)).toEqual(44); // 44%, on the right side of the span bar
expect(screen.getByTestId('span-duration-bar').style.backgroundColor).toEqual('rgba(83, 83, 83, 0.9)');
});

it('render span bar duration on left side', () => {
renderComponent({
options: {},
span: trace1_root_child1_child1,
viewport: {
startTimeUnixMs: trace1_root.startTimeUnixMs + 290,
endTimeUnixMs: trace1_root.startTimeUnixMs + 400,
},
});
expect(screen.getByText('150ms')).toBeInTheDocument();
expect(parseInt(screen.getByText('150ms').style.left)).toEqual(9); // 9%, on the left side of the span bar
});

it('render span bar with colors from eCharts theme', () => {
renderComponent({
options: { visual: { palette: { mode: 'categorical' } } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function SpanDuration(props: SpanDurationProps) {
top: 0,
bottom: 0,
margin: 'auto',
minWidth: '2px',
height: '8px',
borderRadius: muiTheme.shape.borderRadius,
}}
Expand All @@ -61,13 +62,21 @@ export function SpanDuration(props: SpanDurationProps) {
position: 'absolute',
top: '50%',
transform: 'translateY(-50%)',
marginLeft: '8px',
padding: '0 8px',
color: muiTheme.palette.grey[700],
fontSize: '.7rem',
}}
style={{
left: `${(relativeStart + relativeDuration) * 100}%`,
}}
style={
/* print span duration on right side of the span bar, if there is space */
relativeStart + relativeDuration < 0.95
? {
left: `${(relativeStart + relativeDuration) * 100}%`,
}
: {
left: `${relativeStart * 100}%`,
transform: 'translateY(-50%) translateX(-100%)',
}
}
>
{formatDuration(spanDuration)}
</Box>
Expand Down
Loading