Skip to content

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.

3 participants