Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

WDFN-67 - Create a symlog-like graph, using a "compound scale". #89

Merged
merged 3 commits into from
Feb 14, 2018

Conversation

danielnaab
Copy link
Member

This introduced an issue with tooltips on sites that have 100% masked data. @mbucknell, since you've been working in there, I'll wait for the merge to see if the issue needs resolution.

@danielnaab
Copy link
Member Author

There is a corresponding d3-scale PR here: d3/d3-scale#134

@coveralls
Copy link

coveralls commented Feb 13, 2018

Coverage Status

Coverage increased (+0.1%) to 95.707% when pulling b8467b0 on danielnaab:symlog-scale-WDFN-67 into 3fa268b on usgs:master.

// If all values are above zero, make zero the lower bound
if (domainExtent[0] >= 0 && domainExtent[1] >= 0) {
return [
Math.max(0, domainExtent[0] - padding),
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a preference for using Math.max over d3.max? I have been using d3.max in the tooltip code for basically the same purpose as here where I'm finding the max of two numbers. I used d3.max because I was already using it in the package to find the maximum of an array.

Copy link
Member

Choose a reason for hiding this comment

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

I personally don't have a preference, though I've been using Math methods recently (e.g. Math.abs), but that's because I couldn't find a d3 absolute value method.

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 wasn't aware of d3.max - curious if it does something different than the standard one, which I would assume would be pretty optimized.

Copy link
Member Author

Choose a reason for hiding this comment

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

In d3-scale, only Math.maxis used... From the docs, I assume there's specific cases whered3.max` is useful but I don't think we need it here.

];
}

// If we have values less than zero, keep 20% padding around both sides.
Copy link
Member

Choose a reason for hiding this comment

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

Style thing, but I think having one return statement is cleaner.

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 like that when there's cleanup to do before returning, but otherwise I tend to prefer the "return early" notion of weeding out the edge cases first.

Copy link
Member

Choose a reason for hiding this comment

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

In this case though there really are only have two paths, in which case I think it's clearer to have an else clause.

@@ -0,0 +1,47 @@
export default function compound() {
var scales = [].slice.call(arguments);
Copy link
Member

Choose a reason for hiding this comment

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

I'm just curious about the var vs let here?

Also, it seems that this stylistically a bit different from the rest of the javascript... 🤔

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 is a copy-paste of the code I submitted to d3-scale, so I wrote it in the D3 style.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. Makes sense.

};

scale.scales = function(_) {
return arguments.length ? (scales = _, scale) : scales;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not understanding this syntax. Can you describe what this does?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the function is called without arguments, it returns the scales array. Otherwise, it sets the array to the passed in parameters and then returns the scale object, enabling function chaining. That clause is using the comma operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Really need to read up on ES6 syntax.

Copy link
Member

@mbucknell mbucknell 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 pretty slick! I hope becomes part of the D3 library.

@danielnaab danielnaab merged commit 29dc2eb into usgs:master Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants