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
Fix charting lodash shenanigans #64
Conversation
That is what it is.
It breaks lodash. We were not quite able to figure out what's going on, but apparently this plugin, while it does improve our bundle size slightly, also makes a total mess of (some?) lodash methods, which led to very strange behavior when RHKC was used in DHC (and probably elsewhere). Remove the plugin, and rely on the built-in Array.flatMap since that's simpler (we should only rely on lodash where necessary). Also some minor refactoring in related code, and moves lodash from devDependencies where we mistakenly had it to a proper dependency.
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.
🍓
@@ -74,7 +73,8 @@ export default class HKLineChartData extends React.PureComponent< | |||
] | |||
|
|||
// Domain of y coordinates (value) | |||
const valueExtent = d3array.extent(values) | |||
const values = data.flatMap(d => d[1]) | |||
const [minVal, maxVal] = d3array.extent(values) |
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.
destructuring borat_very_nice.gif
Array.prototype.flatMap is not defined in node, where our tests run, so relying on the native flatMap works except in our tests. JavaScript is a good language.
@@ -95,7 +95,7 @@ export default class HKLineChartData extends React.PureComponent< | |||
const area = d3shape | |||
.area() | |||
.x(d => xScale(d.x)) | |||
.y0(yScale(valueExtent[0] < 0 ? yScale(valueExtent) : 0)) | |||
.y0(yScale(Math.min(minVal, 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.
Pretty sure this was bogus--if the min was less than zero, this would call yScale
twice 😮
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.
Good catch
children={`${timeStamp}`} | ||
/> | ||
<HKTooltip xPos={hoverPos} yPos={height / 3}> | ||
{timeStamp} |
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.
Let's pass children as children rather than a prop
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.
🥕
@@ -95,7 +95,7 @@ export default class HKLineChartData extends React.PureComponent< | |||
const area = d3shape | |||
.area() | |||
.x(d => xScale(d.x)) | |||
.y0(yScale(valueExtent[0] < 0 ? yScale(valueExtent) : 0)) | |||
.y0(yScale(Math.min(minVal, 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.
Good catch
Fixes https://trello.com/c/C48rWPXz/183-charts-calculate-boundaries-incorrectly-in-staging