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

feat: add timeline view connectors #3623

Merged
merged 1 commit into from
Feb 12, 2024
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 @@ -4,8 +4,6 @@
import {useTimeline} from '../Timeline.provider';
import * as S from '../TimelineV2.styled';

const BaseLeftPadding = 16; // TODO: Move to Timeline.constants

function toPercent(value: number) {
return `${(value * 100).toFixed(1)}%`;
}
Expand All @@ -19,14 +17,13 @@
span: Span;
}

const BaseSpanNode = ({header, index, node, span, style}: IProps) => {

Check warning on line 20 in web/src/components/Visualization/components/Timeline/BaseSpanNode/BaseSpanNodeV2.tsx

View workflow job for this annotation

GitHub Actions / WebUI unit tests

'header' is defined but never used
const {collapsedSpans, getScale, matchedSpans, onSpanCollapse, onSpanClick, selectedSpan} = useTimeline();
const {start: viewStart, end: viewEnd} = getScale(span.startTime, span.endTime);
const hintSide = getHintSide(viewStart, viewEnd);
const isSelected = selectedSpan === node.data.id;
const isMatched = matchedSpans.includes(node.data.id);
const isCollapsed = collapsedSpans.includes(node.data.id);
const leftPadding = node.depth * BaseLeftPadding;

return (
<div style={style}>
Expand All @@ -42,7 +39,7 @@
hasParent={!!node.data.parentId}
id={node.data.id}
isCollapsed={isCollapsed}
leftPadding={leftPadding}
nodeDepth={node.depth}
onCollapse={onSpanCollapse}
totalChildren={node.children}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
import {BaseLeftPaddingV2} from 'constants/Timeline.constants';
import * as S from '../TimelineV2.styled';

interface IProps {
hasParent: boolean;
id: string;
isCollapsed: boolean;
leftPadding: number;
nodeDepth: number;
onCollapse(id: string): void;
totalChildren: number;
}

const Connector = ({hasParent, id, isCollapsed, leftPadding, onCollapse, totalChildren}: IProps) => (
<S.Connector height="100%" width={leftPadding + 30}>
{hasParent && (
<>
<S.LineBase x1={leftPadding - 3} x2={leftPadding + 12} y1="16" y2="16" />
<S.LineBase x1={leftPadding - 4} x2={leftPadding - 4} y1="0" y2="16.5" />
</>
)}
const Connector = ({hasParent, id, isCollapsed, nodeDepth, onCollapse, totalChildren}: IProps) => {
const leftPadding = nodeDepth * BaseLeftPaddingV2;

{totalChildren > 0 ? (
<>
{!isCollapsed && <S.LineBase x1={leftPadding + 12} x2={leftPadding + 12} y1="16" y2="32" />}
<S.RectBase x={leftPadding + 2} y="8" width="20" height="16" rx="3px" ry="3px" $isActive={isCollapsed} />
<S.TextConnector x={leftPadding + 12} y="20" textAnchor="middle" $isActive={isCollapsed}>
{totalChildren}
</S.TextConnector>
<S.RectBaseTransparent
x={leftPadding + 2}
y="8"
width="20"
height="16"
rx="3px"
ry="3px"
onClick={event => {
event.stopPropagation();
onCollapse(id);
}}
/>
</>
) : (
<S.CircleDot cx={leftPadding + 12} cy="16" r="3" />
)}
</S.Connector>
);
return (
<S.Connector height="100%" width={leftPadding + 30}>
{hasParent && (
<>
<S.LineBase x1={leftPadding - 3} x2={leftPadding + 12} y1="16" y2="16" />
<S.LineBase x1={leftPadding - 4} x2={leftPadding - 4} y1="0" y2="16.5" />
</>
)}

{totalChildren > 0 ? (
<>
{!isCollapsed && <S.LineBase x1={leftPadding + 12} x2={leftPadding + 12} y1="16" y2="32" />}
<S.RectBase x={leftPadding + 2} y="8" width="20" height="16" rx="3px" ry="3px" $isActive={isCollapsed} />
<S.TextConnector x={leftPadding + 12} y="20" textAnchor="middle" $isActive={isCollapsed}>
{totalChildren}
</S.TextConnector>
<S.RectBaseTransparent
x={leftPadding + 2}
y="8"
width="20"
height="16"
rx="3px"
ry="3px"
onClick={event => {
event.stopPropagation();
onCollapse(id);
}}
/>
</>
) : (
<S.CircleDot cx={leftPadding + 12} cy="16" r="3" />
)}

{new Array(nodeDepth).fill(0).map((_, index) => {
return <S.LineBase x1={index * BaseLeftPaddingV2 + 12} x2={index * BaseLeftPaddingV2 + 12} y1="0" y2="32" />;
})}
</S.Connector>
);
};

export default Connector;
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const CircleDot = styled.circle`
`;

export const LineBase = styled.line`
stroke: ${({theme}) => theme.color.textSecondary};
stroke: ${({theme}) => theme.color.borderLight};
`;

export const RectBase = styled.rect<{$isActive?: boolean}>`
Expand Down
1 change: 1 addition & 0 deletions web/src/constants/Timeline.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const AxisOffset = 100;
export const NodeHeight = 66;
export const NodeOverlayHeight = NodeHeight - 2;
export const BaseLeftPadding = 10;
export const BaseLeftPaddingV2 = 16;
Loading