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

ui-speedspacechart: highlight the 4 steps before and after the cursor #881

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
30 changes: 28 additions & 2 deletions ui-speedspacechart/src/components/helpers/drawElements/steps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DrawFunctionParams } from '../../../types/chartTypes';
import { GREY_50, GREY_80, LIGHT_BLUE, MARGINS } from '../../const';
import { BLACK, GREY_50, GREY_80, LIGHT_BLUE, MARGINS } from '../../const';
import {
clearCanvas,
positionToPosX,
Expand Down Expand Up @@ -73,6 +73,23 @@ export const drawSteps = ({ ctx, width, height, store }: DrawFunctionParams) =>

// Text
const filteredTextStops = getDisplayedStops(filteredStops, ratioX, width, maxPosition, 25);
const prevSteps: (typeof filteredTextStops)[0][] = [];
const nextSteps: (typeof filteredTextStops)[0][] = [];

filteredTextStops.forEach((stop) => {
const posX = positionToPosX(stop.position.start, maxPosition, width, ratioX);
if (cursor.x && posX < cursor.x + MARGIN_LEFT - leftOffset) {
prevSteps.push(stop);
if (prevSteps.length > 4) prevSteps.shift();
}

if (cursor.x && posX > cursor.x + MARGIN_LEFT - leftOffset) {
if (nextSteps.length < 4) {
nextSteps.push(stop);
}
}
});

filteredTextStops.forEach(({ position, value }) => {
if (snappedStop && position.start === snappedStop.position.start) {
return;
Expand All @@ -87,7 +104,16 @@ export const drawSteps = ({ ctx, width, height, store }: DrawFunctionParams) =>
ctx.translate(posX, posY);
ctx.rotate((-40 * Math.PI) / 180); // -40 degrees in radians

ctx.fillStyle = GREY_80.alpha(0.2).hex();
// Check if the current step is within the 4 previous or 4 next steps
if (
prevSteps.some((step) => step.position.start === position.start) ||
nextSteps.some((step) => step.position.start === position.start)
) {
ctx.fillStyle = BLACK.hex();
} else {
ctx.fillStyle = GREY_80.alpha(0.2).hex();
}

ctx.font = 'normal 12px IBM Plex Sans';
ctx.textAlign = 'left';

Expand Down