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

Improvements for native #1373

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 15 additions & 3 deletions packages/victory-axis/src/victory-axis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from "prop-types";
import React from "react";
import { assign } from "lodash";
import { assign, isEmpty } from "lodash";
import {
PropTypes as CustomPropTypes,
Helpers,
Expand Down Expand Up @@ -154,13 +154,25 @@ class VictoryAxis extends React.Component {
return React.cloneElement(axisLabelComponent, axisLabelProps);
}



renderGridAndTicks(props) {
const { tickComponent, tickLabelComponent, gridComponent, name } = props;
const shouldRender = (componentProps) => {
const { style = {}, events = {} } = componentProps;
const visible = style.stroke !== "transparent"
&& style.stroke !== "none"
&& style.strokeWidth !== 0;
return visible || !isEmpty(events);
};

return this.dataKeys.map((key, index) => {
const tickProps = this.getComponentProps(tickComponent, "ticks", index);
const TickComponent = React.cloneElement(tickComponent, tickProps);
const BaseTickComponent = React.cloneElement(tickComponent, tickProps);
const TickComponent = shouldRender(BaseTickComponent.props) ? BaseTickComponent : undefined;
const gridProps = this.getComponentProps(gridComponent, "grid", index);
const GridComponent = React.cloneElement(gridComponent, gridProps);
const BaseGridComponent = React.cloneElement(gridComponent, gridProps);
const GridComponent = shouldRender(BaseGridComponent.props) ? BaseGridComponent : undefined;
const tickLabelProps = this.getComponentProps(tickLabelComponent, "tickLabels", index);
const TickLabel = React.cloneElement(tickLabelComponent, tickLabelProps);
return React.cloneElement(
Expand Down
4 changes: 3 additions & 1 deletion packages/victory-chart/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ const getChildComponents = (props, defaultAxes) => {
};

if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
return props.prependDefaultAxes
? [defaultAxes.independent, defaultAxes.dependent].concat(childComponents)
: childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
return childComponents;
};
Expand Down
1 change: 1 addition & 0 deletions packages/victory-chart/src/victory-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class VictoryChart extends React.Component {
}),
endAngle: PropTypes.number,
innerRadius: CustomPropTypes.nonNegative,
prependDefaultAxes: PropTypes.bool,
startAngle: PropTypes.number
};

Expand Down
3 changes: 1 addition & 2 deletions packages/victory-core/src/victory-primitives/circle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import isEqual from "react-fast-compare";

const Circle = (props) => <circle vectorEffect="non-scaling-stroke" {...props} />;

export default React.memo(Circle, isEqual);
export default Circle;
3 changes: 1 addition & 2 deletions packages/victory-core/src/victory-primitives/line.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import isEqual from "react-fast-compare";

const Line = (props) => <line vectorEffect="non-scaling-stroke" {...props} />;

export default React.memo(Line, isEqual);
export default Line;
5 changes: 2 additions & 3 deletions packages/victory-core/src/victory-primitives/path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import isEqual from "react-fast-compare";

const Path = (props) => <path {...props} />;
const Path = (props) => <path vectorEffect="non-scaling-stroke" {...props} />;

export default React.memo(Path, isEqual);
export default Path;
3 changes: 1 addition & 2 deletions packages/victory-core/src/victory-primitives/rect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import isEqual from "react-fast-compare";

const Rect = (props) => <rect vectorEffect="non-scaling-stroke" {...props} />;

export default React.memo(Rect, isEqual);
export default Rect;
3 changes: 1 addition & 2 deletions packages/victory-core/src/victory-primitives/text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import PropTypes from "prop-types";
import isEqual from "react-fast-compare";

const Text = (props) => {
const { children, title, desc, ...rest } = props;
Expand All @@ -19,4 +18,4 @@ Text.propTypes = {
title: PropTypes.string
};

export default React.memo(Text, isEqual);
export default Text;
3 changes: 1 addition & 2 deletions packages/victory-core/src/victory-primitives/tspan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import isEqual from "react-fast-compare";

const TSpan = (props) => <tspan {...props} />;

export default React.memo(TSpan, isEqual);
export default TSpan;
19 changes: 14 additions & 5 deletions packages/victory-polar-axis/src/victory-polar-axis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import { assign } from "lodash";
import { assign, isEmpty } from "lodash";
import {
PropTypes as CustomPropTypes,
Helpers,
Expand Down Expand Up @@ -160,23 +160,32 @@ class VictoryPolarAxis extends React.Component {

renderAxis(props) {
const { tickComponent, tickLabelComponent, name } = props;
const shouldRender = (componentProps) => {
const { style = {}, events = {} } = componentProps;
const visible = style.stroke !== "transparent"
&& style.stroke !== "none"
&& style.strokeWidth !== 0;
return visible || !isEmpty(events);
};
const axisType = props.dependentAxis ? "radial" : "angular";
const gridComponent = axisType === "radial" ? props.circularGridComponent : props.gridComponent;
const tickComponents = this.dataKeys.map((key, index) => {
const tickProps = assign(
{ key: `${name}-tick-${key}` },
this.getComponentProps(tickComponent, "ticks", index)
);
return React.cloneElement(tickComponent, tickProps);
});
const TickComponent = React.cloneElement(tickComponent, tickProps);
return shouldRender(TickComponent.props) ? TickComponent : undefined;
}).filter(Boolean);

const gridComponents = this.dataKeys.map((key, index) => {
const gridProps = assign(
{ key: `${name}-grid-${key}` },
this.getComponentProps(gridComponent, "grid", index)
);
return React.cloneElement(gridComponent, gridProps);
});
const GridComponent = React.cloneElement(gridComponent, gridProps);
return shouldRender(GridComponent.props) ? GridComponent : undefined;
}).filter(Boolean);

const tickLabelComponents = this.dataKeys.map((key, index) => {
const tickLabelProps = assign(
Expand Down