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

Fix charting lodash shenanigans #64

Merged
merged 4 commits into from Dec 13, 2018
Merged

Conversation

msakrejda
Copy link
Contributor

Maciek Sakrejda added 3 commits December 13, 2018 12:19
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.
@msakrejda msakrejda requested a review from a team December 13, 2018 20:44
@mattrothenberg mattrothenberg temporarily deployed to react-hk-components-pr-64 December 13, 2018 20:44 Inactive
Copy link
Contributor

@idan idan left a 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)
Copy link
Contributor

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)))
Copy link
Contributor Author

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 😮

Copy link
Contributor

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}
Copy link
Contributor Author

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

Copy link
Contributor

@idan idan left a 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)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch

@msakrejda msakrejda merged commit c78c1fd into master Dec 13, 2018
@msakrejda msakrejda deleted the fix-charting-lodash-shenanigans branch December 13, 2018 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants