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

VictoryChart: adds an option for adding background for chart area #1558

Merged
merged 20 commits into from
May 11, 2020

Conversation

maddles
Copy link
Contributor

@maddles maddles commented May 5, 2020

VictoryChart

  • Adds a new Background primitive component
  • Adds the background primitive to VictoryChart to allow an option for adding background for just the chart area
  • Updates typed definitions for VictoryChartProps interface
  • Updates the helper-methods in VictoryChart to accept a background prop
  • Adds additional stories to VictoryChart storybook to visually check that the background color is rendered correctly

Storybook Screenshots

Screen Shot 2020-05-07 at 12 04 09 PM

Screen Shot 2020-05-07 at 12 03 59 PM

Screen Shot 2020-05-07 at 12 03 50 PM

Screen Shot 2020-05-08 at 3 36 40 PM

Screen Shot 2020-05-08 at 3 36 50 PM

Screen Shot 2020-05-08 at 3 53 12 PM

@maddles maddles requested a review from wsparsons May 5, 2020 23:45
@wsparsons wsparsons changed the title Added new Background primitive, set up methods in VictoryChart to ren… VictoryChart: adds an option for adding backing for chart area May 7, 2020
@wsparsons wsparsons changed the title VictoryChart: adds an option for adding backing for chart area VictoryChart: adds an option for adding background for chart area May 7, 2020
@wsparsons wsparsons marked this pull request as ready for review May 7, 2020 19:05
@wsparsons wsparsons force-pushed the task/add-chart-background-primitive branch from dbbb9c6 to ce270ae Compare May 7, 2020 19:08
@wsparsons wsparsons requested a review from boygirl May 7, 2020 19:22
Copy link
Contributor

@boygirl boygirl left a comment

Choose a reason for hiding this comment

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

This is working well, but I'd like to see the props on Background cleaned up a bit, and put more responsibility on VictoryChart for calculating the positioning props.

polar: props.polar,
scale: calculatedProps.scale,
style: props.style.background,
width: width
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's calculate x / cx and y/ cy here, too

@@ -87,10 +87,18 @@ export default class VictoryChart extends React.Component {
getNewChildren(props, childComponents, calculatedProps) {
const children = getChildren(props, childComponents, calculatedProps);
const getAnimationProps = Wrapper.getAnimationProps.bind(this);
return children.map((child, index) => {
const backgroundComponent = getBackgroundWithProps(props, calculatedProps);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this calculation into the props.style.background conditional so we can skip it if we don't need it.

wsparsons and others added 2 commits May 8, 2020 14:44
…zontal), adds extra proptypes, exports Background from VictoryCore DefinitelyTyped types
style: props.style.background,
x: xCoordinate,
y: yCoordinate,
width
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add scale to the list of backgroundProps.

Background.propTypes = {
...CommonProps.primitiveProps,
circleComponent: PropTypes.element,
cx: PropTypes.number,
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like cx and cy are never passed in.

…d prop getter is only invoked when it's going to be used
@@ -7,6 +7,7 @@ export { default as VictoryTheme } from "./victory-theme/victory-theme";
export { default as VictoryPortal } from "./victory-portal/victory-portal";
export { default as Portal } from "./victory-portal/portal";
export { default as Arc } from "./victory-primitives/arc";
export { default as Background } from "./victory-primitives/background";
Copy link
Contributor

@boygirl boygirl May 11, 2020

Choose a reason for hiding this comment

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

The main victory package should also reexport the new Background primitive

width
};

return React.cloneElement(backgroundElement, backgroundProps);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use lodash defaults so that props set directly on the backgroundComponent are not nuked by props from the parent.

Like imagine the following scenario where a user wants the background to span the whole height of the svg but be confined to the chart width:

<VictoryChart
  height={300}
  width={300}
  style={{ background: { fill: "pink" } }}
  backgroundComponent={<Background y={0} height={300} />
 ...

The y value and height directly on Background should take prececence over what VictoryChart is trying to set.

I think the props should be defaults({}, backgroundElement.props, backgroundProps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh great point

@boygirl boygirl merged commit c439d67 into master May 11, 2020
@boygirl boygirl deleted the task/add-chart-background-primitive branch May 11, 2020 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants