-
Notifications
You must be signed in to change notification settings - Fork 5
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
ui-chart: spacetimechart: bordered path layer #962
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ type PathStyle = { | |
opacity?: number; | ||
lineCap?: CanvasLineCap; | ||
}; | ||
|
||
export type PathLevel = 1 | 2 | 3 | 4; | ||
const STYLES: Record<PathLevel, PathStyle> = { | ||
1: { | ||
|
@@ -66,6 +67,13 @@ export type PathLayerProps = { | |
color: string; | ||
pickingTolerance?: number; | ||
level?: PathLevel; | ||
border?: { | ||
offset: number; | ||
level: PathLevel; | ||
color: string; | ||
width?: number; | ||
backgroundColor?: string; | ||
}; | ||
}; | ||
|
||
/** | ||
|
@@ -79,6 +87,7 @@ export const PathLayer = ({ | |
color, | ||
level = DEFAULT_LEVEL, | ||
pickingTolerance = DEFAULT_PICKING_TOLERANCE, | ||
border, | ||
}: PathLayerProps) => { | ||
/** | ||
* This function returns the list of points to join to draw the path. It will be both used to | ||
|
@@ -336,8 +345,48 @@ export const PathLayer = ({ | |
[path] | ||
); | ||
|
||
const drawBorder = useCallback<DrawingFunction>( | ||
(ctx, stcContext) => { | ||
if (!border) return; | ||
Yohh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const borderWidth = border.width || 1; | ||
const mainPathStyle = STYLES[level]; | ||
const totalPathWidth = border.offset * 2 + mainPathStyle.width; | ||
|
||
const segments = getPathSegments(stcContext); | ||
ctx.save(); | ||
const drawSegments = (lineWidth: number, borderColor = border.color) => { | ||
ctx.strokeStyle = borderColor; | ||
ctx.lineWidth = lineWidth; | ||
ctx.beginPath(); | ||
segments.forEach(({ x, y }, i) => { | ||
if (x === segments[i - 1]?.x && y === segments[i - 1]?.y) return; | ||
if (i === 0) { | ||
ctx.moveTo(x, y); | ||
} else if (i === segments.length - 1) { | ||
ctx.lineTo(x - border.offset / 2, y); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
} else { | ||
ctx.lineTo(x, y); | ||
} | ||
}); | ||
ctx.stroke(); | ||
}; | ||
|
||
drawSegments(totalPathWidth + borderWidth * 2); | ||
|
||
if (border.backgroundColor) { | ||
drawSegments(totalPathWidth, border.backgroundColor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
ctx.restore(); | ||
}, | ||
[border, getPathSegments, level] | ||
); | ||
|
||
const drawAll = useCallback<DrawingFunction>( | ||
(ctx, stcContext) => { | ||
if (border !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: no need for an |
||
drawBorder(ctx, stcContext); | ||
} | ||
// Draw stops: | ||
ctx.strokeStyle = color; | ||
ctx.lineWidth = PAUSE_THICKNESS; | ||
|
@@ -383,6 +432,8 @@ export const PathLayer = ({ | |
drawExtremities, | ||
computePathLength, | ||
drawLabel, | ||
drawBorder, | ||
border, | ||
path.label, | ||
] | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is unused