Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

check on labels prop before computing base props for labels #584

Merged
merged 2 commits into from
Apr 18, 2018

Conversation

boygirl
Copy link
Contributor

@boygirl boygirl commented Apr 17, 2018

cc/ @chrisbolin

This PR checks on the existence of a labels prop (or corresponding prop) rather than calculating base props for labels any time there are events. This will be a breaking change for some small number of users, but the upgrade path is simple. Those impacted will just need to add labels={() => null} or similar.

if (labelText !== null && typeof labelText !== undefined || !events || !sharedEvents) {
const labelProp = props.labels || props[`${type}Labels`];
if (
labelText !== null && typeof labelText !== undefined ||
Copy link
Member

Choose a reason for hiding this comment

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

BIG WARNING!!!

I know this is existing code, but we have a very big problem here:

> typeof labelText
< "undefined"
> typeof labelText !== undefined
< true

Can we create a high-priority ticket to scour all our victory repos for == undefined or something?

What we really want is:

> typeof labelText !== "undefined"
< false

Copy link
Member

Choose a reason for hiding this comment

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

Did a quick grep. I think the only other place it occurs is in this same file in master at: https://github.com/FormidableLabs/victory-chart/blob/master/src/components/victory-boxplot/helper-methods.js#L350

Side note -- we have lots of mixed foo === undefined and typeof foo === "undefined". Might make sense to create a cross-repo ticket to hone all of them to one approach (prefer the latter or _.isUndefined).

@boygirl
Copy link
Contributor Author

boygirl commented Apr 17, 2018

o.O yikes! I'll do that now.

@boygirl
Copy link
Contributor Author

boygirl commented Apr 17, 2018

actually it looks like it was just in this one file (in victory-chart at least)

Copy link
Contributor

@chrisbolin chrisbolin left a comment

Choose a reason for hiding this comment

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

just a quick question and comment. looks good!

@@ -76,6 +76,7 @@ export default class App extends React.Component {
<VictoryChart style={chartStyle} domain={{ x: [0, 20], y: [0, 3] }}>
<VictoryBoxPlot
minLabels maxLabels
q1Labels={() => ""}
Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to commit this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a necessary change if you want labels to show up when you click on them. They need to be defined ahead of time even if just with a throwaway function.

@@ -57,7 +57,7 @@ const getBaseProps = (props, fallbackProps) => {
};
return data.reduce((childProps, datum, index) => {
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is getting a little tough to read. many permutations. we could have separate variables, or group with parents, or comments

@boygirl boygirl merged commit a58669b into master Apr 18, 2018
@boygirl boygirl deleted the perf/labels branch April 18, 2018 17:24
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.

3 participants