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: display electrical profile names on short ranges #884

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,36 @@ export const drawElectricalProfile = ({ ctx, width, height, store }: DrawFunctio
);
ctx.globalAlpha = 1;

const profilNameWidth = Math.floor(ctx.measureText(electricalProfile).width);
const marginProfilName = 20;
const profileNameWidth = Math.floor(ctx.measureText(electricalProfile).width);
const marginProfileName = 20;

const profileNameOverflow = Math.max(
profileNameWidth + marginProfileName - profileWidth,
0
);

// Draw profile name
if (profileWidth > profilNameWidth + marginProfilName) {
ctx.fillStyle = '#000';
ctx.font = '600 14px IBM Plex Sans';
ctx.textAlign = 'center';
ctx.fillText(`${electricalProfile}`, xStart + profileWidth / 2, topLayer / 2);
}

ctx.fillStyle = '#000';
ctx.font = '600 14px IBM Plex Sans';
ctx.textAlign = 'center';
ctx.fillText(`${electricalProfile}`, xStart + profileWidth / 2, topLayer / 2);

// Draw begin and end position
ctx.fillStyle = 'rgb(49, 46, 43)';
ctx.font = '400 14px IBM Plex Sans';

ctx.textAlign = 'right';
ctx.fillText(`${(start || 0).toFixed(1)}`, xStart - MARGIN_POSITION_TEXT, topLayer / 2);
ctx.fillText(
`${(start || 0).toFixed(1)}`,
xStart - (MARGIN_POSITION_TEXT + profileNameOverflow / 2),
topLayer / 2
);

ctx.textAlign = 'left';
ctx.fillText(
`${end!.toFixed(1)}`,
xStart + profileWidth + MARGIN_POSITION_TEXT,
xStart + profileWidth + (MARGIN_POSITION_TEXT + profileNameOverflow / 2),
topLayer / 2
);
}
Expand Down