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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/components/victory-boxplot-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

whiskerWidth={50}
data={[{ y: 1, x: [5, 10, 9, 2] }, { y: 2, x: [1, 15, 6, 8] }]}
boxWidth={20}
Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-area/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getBaseProps = (props, fallbackProps) => {
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
scale, sharedEvents, standalone, style, theme, width, labels
} = props;
const initialChildProps = {
parent: {
Expand All @@ -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

const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-bar/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getBaseProps = (props, fallbackProps) => {
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
alignment, barRatio, cornerRadius, data, domain, events, height, horizontal, origin, padding,
polar, scale, sharedEvents, standalone, style, theme, width
polar, scale, sharedEvents, standalone, style, theme, width, labels
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone,
Expand All @@ -65,7 +65,7 @@ const getBaseProps = (props, fallbackProps) => {
};

const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
Expand Down
6 changes: 5 additions & 1 deletion src/components/victory-boxplot/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ const getBaseProps = (props, fallbackProps) => {

TYPES.forEach((type) => {
const labelText = getText(dataProps, type);
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).

labelProp && (events || sharedEvents)
) {
const target = `${type}Labels`;
acc[eventKey][target] = getLabelProps(dataProps, labelText, type);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-candlestick/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const getBaseProps = (props, fallbackProps) => { // eslint-disable-line max-stat
const { data, style, scale, domain, origin } = calculatedValues;
const {
groupComponent, width, height, padding, standalone,
theme, polar, wickStrokeWidth
theme, polar, wickStrokeWidth, labels, events, sharedEvents
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone, theme, polar, origin,
Expand All @@ -175,7 +175,7 @@ const getBaseProps = (props, fallbackProps) => { // eslint-disable-line max-stat
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}

Expand Down
7 changes: 5 additions & 2 deletions src/components/victory-errorbar/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ const getDataStyles = (datum, style) => {
const getBaseProps = (props, fallbackProps) => {
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
const { data, style, scale, domain, origin } = getCalculatedValues(props, fallbackProps);
const { groupComponent, height, width, borderWidth, standalone, theme, polar, padding } = props;
const {
groupComponent, height, width, borderWidth, standalone, theme, polar, padding,
labels, events, sharedEvents
} = props;
const initialChildProps = { parent: {
domain, scale, data, height, width, standalone, theme, polar, origin,
padding, style: style.parent
Expand All @@ -225,7 +228,7 @@ const getBaseProps = (props, fallbackProps) => {
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-line/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getBaseProps = (props, fallbackProps) => {
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
scale, sharedEvents, standalone, style, theme, width, labels
} = props;
const initialChildProps = {
parent: {
Expand All @@ -45,7 +45,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)) {
const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-scatter/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
props = assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
const {
data, domain, events, height, origin, padding, polar, scale,
sharedEvents, standalone, style, theme, width
sharedEvents, standalone, style, theme, width, labels
} = props;
const initialChildProps = { parent: {
style: style.parent, scale, domain, data, height, width, standalone, theme,
Expand All @@ -26,7 +26,7 @@ export default {

childProps[eventKey] = { data: dataProps };
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/victory-voronoi/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const getBaseProps = (props, fallbackProps) => {
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, height, origin, padding, polar, polygons,
scale, sharedEvents, standalone, style, theme, width
scale, sharedEvents, standalone, style, theme, width, labels
} = props;
const initialChildProps = { parent: {
style: style.parent, scale, domain, data, standalone, height, width, theme,
Expand All @@ -68,7 +68,7 @@ const getBaseProps = (props, fallbackProps) => {

childProps[eventKey] = { data: dataProps };
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
if (text !== undefined && text !== null || (labels && events || sharedEvents)) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}

Expand Down