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

marker #731

Merged
merged 10 commits into from
Feb 1, 2022
Merged

marker #731

merged 10 commits into from
Feb 1, 2022

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Jan 31, 2022

Fixes #628. Allows a marker to be applied to the line and link marks. The marker can be specified as one of the built-in types, or a custom marker function that takes the line’s stroke color and returns an SVG marker element. Here are some examples of the built-in markers with line:

arrow:
Screen Shot 2022-01-31 at 1 55 13 PM

circle (a.k.a. circle-fill):
Screen Shot 2022-01-31 at 1 55 27 PM

circle-stroke:
Screen Shot 2022-01-31 at 1 55 45 PM

@Fil Fil mentioned this pull request Jan 31, 2022
@mbostock
Copy link
Member Author

mbostock commented Jan 31, 2022

A gotcha with this approach: the markers aren’t necessarily drawn at the xy location given by the data. For example, with the step curve, the markers are drawn where the curve steps between points:

Screen Shot 2022-01-31 at 3 10 43 PM

With the basis curve, the markers are drawn on the endpoints of the Bézier segments, rather than the on control points of the spline:

Screen Shot 2022-01-31 at 3 11 01 PM

On the other hand, using markers is very convenient for getting the markers to orient with the path. And you probably don’t need markers with the step curve, and you probably don’t mind that the dots don’t align with the basis curve. And you can always render dots separately if you want them to be on the data points.

Anyway I think this is convenient enough that we probably want this feature, but we probably want to mention these limitations in the documentation.

@mbostock mbostock changed the title line marker marker Jan 31, 2022
@mbostock mbostock requested a review from Fil January 31, 2022 23:24
@mbostock
Copy link
Member Author

I reverted support for markers on rule. Rules lack orientation, so you can’t control which way the arrow points. We could add an additional option to control rule orientation, but I think the utility is small enough for markers on rules that we don’t need it. It was cute that you could draw a little arrow on the axis, though.

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

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

This is really neat!

I've added some documentation, and a suggestion.

I wonder if we must check what a custom marker returns—either verify that it is a svg:marker, or at least that it is not nullish? I've documented it as a MUST, but if we accepted nullish values it would allow to not return a marker for some colors. Currently one has to return an empty svg:marker—which is probably fine too.

},
marks: [
Plot.ruleY([0]),
Plot.lineY(data, {x: "date", y: "deaths", stroke: "cause", marker: "arrow"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Plot.lineY(data, {x: "date", y: "deaths", stroke: "cause", marker: "arrow"})
Plot.lineY(data, {x: "date", y: "deaths", stroke: "cause", marker: "arrow", curve: "natural"})

Capture d’écran 2022-02-01 à 11 13 37

this version feels more natural :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we must check what a custom marker returns—either verify that it is a svg:marker, or at least that it is not nullish? I've documented it as a MUST, but if we accepted nullish values it would allow to not return a marker for some colors. Currently one has to return an empty svg:marker—which is probably fine too.

We could maybe add this in the future, but I don’t think we need to do it now. I would add it if it’s frequently needed (for convenience), or is a frequent source of errors (for debugging). For now I think implementing a custom marker function is a relative “power user” feature, similar to a custom mark implementation, so it can have sharper edges than the more commonly-used APIs.

Copy link
Member Author

Choose a reason for hiding this comment

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

this version feels more natural

I find the natural curve tends to be a little… loosey-goosey, like where it dips below y = 0; catmull-rom tends to do better, and monotone-x makes a hard guarantee. Think I’ll just keep it simple for now though.

@mbostock mbostock merged commit 551f53a into main Feb 1, 2022
@mbostock mbostock deleted the mbostock/marker branch February 1, 2022 20:55
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.

Line with dot
2 participants