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

Annotated line chart template #305

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

kokonakajima
Copy link
Contributor

Sample annotated line chart, see this issue

d[key] = Number(d[key]);

// Annotations
var hasAnnotation = d["annotate"] != null && d["annotate"].length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be a truthy check: var hasAnnotation = !!d["annotate"];

var hasAnnotation = d["annotate"] != null && d["annotate"].length > 0;
if (hasAnnotation) {

var hasCustomLabel = d["annotate"] != "True";
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to call toLowerCase() and check against "true", just be safe.

var hasCustomYOffset = d["y_offset"] != null && d["y_offset"].length > 0;

var label = hasCustomLabel ? d["annotate"] : null;
var xOffset = hasCustomXOffset ? 0 : Number(d["x_offset"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than testing for the presence of the offsets and then giving them a default value in two steps, just do var xOffset = Number(d["x_offset"]) || 0;

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.

2 participants