-
Notifications
You must be signed in to change notification settings - Fork 51
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
base: master
Are you sure you want to change the base?
Conversation
d[key] = Number(d[key]); | ||
|
||
// Annotations | ||
var hasAnnotation = d["annotate"] != null && d["annotate"].length > 0; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"]); |
There was a problem hiding this comment.
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;
Sample annotated line chart, see this issue