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-chart: spacetimechart: bordered path layer #962

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Math-R
Copy link
Contributor

@Math-R Math-R commented Mar 6, 2025

This PR allow the user to add a border around a PathLayer.
it closes #11056

@Math-R Math-R requested a review from a team as a code owner March 6, 2025 17:52
@Math-R Math-R force-pushed the mrd/spacetimechart/bordered-layer branch 2 times, most recently from 4da5206 to 1e55ad0 Compare March 6, 2025 17:53
@Math-R Math-R requested review from jacomyal and Yohh March 6, 2025 17:53
@Math-R Math-R force-pushed the mrd/spacetimechart/bordered-layer branch from 1e55ad0 to 720dca2 Compare March 6, 2025 18:03
@Math-R Math-R changed the title ui-chart: spacetimecart: borderer path layer ui-chart: spacetimecart: bordered path layer Mar 6, 2025
@Math-R Math-R changed the title ui-chart: spacetimecart: bordered path layer ui-chart: spacetimechart: bordered path layer Mar 6, 2025
@Math-R Math-R force-pushed the mrd/spacetimechart/bordered-layer branch from 720dca2 to fd1bfd7 Compare March 6, 2025 18:11
@Yohh Yohh self-assigned this Mar 6, 2025
@Uriel-Sautron Uriel-Sautron force-pushed the mrd/spacetimechart/bordered-layer branch from fd1bfd7 to b833579 Compare March 7, 2025 11:03
@Math-R Math-R requested a review from emersion March 7, 2025 11:04
drawSegments(totalPathWidth + borderWidth * 2);

if (border.backgroundColor) {
drawSegments(totalPathWidth, border.backgroundColor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing: when there is no background color, I would've expected a thin width-sized border offset away from the path. However a thick path is painted instead:

out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I suppose the right way to fix this would be to leave the space between the path and the border transparent, which would be tricky to do? Perhaps a workaround would be to use white.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i forgot to answer, but i fix this using globalCompositeOperation

if (i === 0) {
ctx.moveTo(x, y);
} else if (i === segments.length - 1) {
ctx.lineTo(x - border.offset / 2, y);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the - border.offset / 2 here? It seems like the spacing on the right is smaller than offset with this adjustment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unnecessary, i wasn't seeing the end of the line well because of the display device so i tried unusefully to see something at the end i guess... so => removed ! thanks

@Math-R Math-R requested a review from emersion March 10, 2025 13:17
const borderWidth = border.width || 1;
const mainPathStyle = STYLES[level];
const totalPathWidth = border.offset * 2 + mainPathStyle.width;
ctx.globalCompositeOperation = border.backgroundColor ? 'source-over' : 'xor';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works only when the paced train is the first one painted. When I move getPaths() for "Paced" to the end of the list in PATHS, I see this:

out

Probably a simple way to workaround this would be to:

  • Set strokeStyle = 'transparent'
  • Set globalCompositeOperation = 'copy' for the second drawSegments() call

Copy link
Contributor Author

@Math-R Math-R Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried but still a problem with another behaviour. I also tried to drawImage from another context but this was not at all optimized in terms of performance, plus this occure blurry effect or aliasing depending of the device pixel ratio.

As the mockup by @thibautsailly use a background color between the path and the border, the fact that a path with border hide a path behind seems to be the normal behaviour.
So i put a default backgroundColor to white.

After a discussion with @jacomyal about these different behaviors, it seems that the only possibility for the user to have a transparent background (using xor for performance) would be to draw a bordered path in another layer.
But this seems heavy in terms of implementation and harder for everyone to use it in a simple way.

So, what you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, defaulting to solid white sounds completely reasonable to me! I'd be fine with making the field required as well, so that everything is more explicit (e.g. if the user uses a dark theme, white might be confusing).

Math-R and others added 2 commits March 11, 2025 10:08
Co-authored-by: Uriel-Sautron <uriel.sautron@gmail.com>
Signed-off-by: Math_R_ <mathieu.richard747@gmail.com>
@Math-R Math-R force-pushed the mrd/spacetimechart/bordered-layer branch from bfe88a6 to e1d9a37 Compare March 11, 2025 16:39
@Math-R Math-R requested a review from emersion March 11, 2025 16:39
Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

Seems like some ESLint warnings need fixing, but should be good to go apart from that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mathieu - update osrd-ui to support train service space time chart style :
4 participants