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

Commit

Permalink
Merge pull request #584 from FormidableLabs/perf/labels
Browse files Browse the repository at this point in the history
check on labels prop before computing base props for labels
  • Loading branch information
boygirl authored Apr 18, 2018
2 parents 3e00da9 + df9a959 commit a58669b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 16 deletions.
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={() => ""}
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)) {
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
8 changes: 6 additions & 2 deletions src/components/victory-boxplot/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const getBaseProps = (props, fallbackProps) => {
const boxScale = horizontal ? scale.x : scale.y;

return data.reduce((acc, datum, index) => {
const eventKey = typeof datum.eventKey !== undefined ? datum.eventKey : index;
const eventKey = typeof datum.eventKey !== "undefined" ? datum.eventKey : index;
const positions = {
x: scale.x(datum._x),
y: scale.y(datum._y),
Expand All @@ -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" ||
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

0 comments on commit a58669b

Please sign in to comment.