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

Add specific class names to x and y axes #191

Merged
merged 8 commits into from
Nov 29, 2016

Conversation

mcnuttandrew
Copy link
Contributor

Also allow users to specify custom classnames! Addresses #180

@@ -31,14 +32,21 @@ const propTypes = {
])
};

delete propTypes.axisType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using delete prevents optimizations and it's a mutating operation. How about alternatives such as the rest operator or using lodash's omit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand what you are suggesting with rest parameters? I also haven't heard of delete preventing optimizations? (Though I would be excited to see source saying otherwise)

Copy link
Contributor

@chrisirhc chrisirhc Nov 29, 2016

Choose a reason for hiding this comment

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

Meant to attach references but forgot, here goes. delete causes v8 to deoptimize, the hidden classes optimization.

Here's a related discussion: https://groups.google.com/forum/#!topic/v8-users/zE4cOHBkAnY
and googleapis/google-api-nodejs-client#375 (comment) .

For example with rest: const {axisType, ...propsWithoutAxisType} = Axis.propTypes;

return (
<Axis {...props} />
<Axis {...axisProps} />
Copy link
Contributor

Choose a reason for hiding this comment

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

You can supply additional props here by: <Axis {...props} axisType={DIRECTION.VERTICAL} />.
This might be cleaner as it doesn't require the introduction of a new variable (axisProps vs props).

const propTypes = {
...Axis.propTypes,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do custom validators, an even better option here might be to return an Error if axisType is specified when using x-axis:

https://facebook.github.io/react/docs/typechecking-with-proptypes.html

@@ -39,13 +43,17 @@ const propTypes = {
orientation: React.PropTypes.oneOf([
LEFT, RIGHT, TOP, BOTTOM
]),
axisType: React.PropTypes.oneOf([
DIRECTION.VERTICAL, DIRECTION.HORIZONTAL
]).isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this PR in detail, could the axisType a derived from the orientation? For example, would there be a case where a LEFT or RIGHT orientation axis, would have a axisType of HORIZONTAL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess because they are required that's true

Copy link
Contributor

@chrisirhc chrisirhc left a comment

Choose a reason for hiding this comment

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

minor comments

left,
top,
width,
height,
orientation,
title
} = props;

const isY = [LEFT, RIGHT].indexOf(orientation) > -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I typically recommend .includes for bit of added readability, if there are existing usages of .includes, we should use that instead since that would mean existing users have it already set up.

@@ -19,6 +19,7 @@
// THE SOFTWARE.

import React from 'react';

Copy link
Contributor

Choose a reason for hiding this comment

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

whitespace change unnecessary

@@ -38,7 +39,7 @@ const defaultProps = {

function XAxis(props) {
return (
<Axis {...props} />
<Axis {...props}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

} = props;

const isY = [LEFT, RIGHT].indexOf(orientation) > -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I typically recommend .includes for bit of added readability, if there are existing usages of .includes, we should use that instead since that would mean existing users have it already set up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm totally with you, but there aren't any examples of includes in react-vis, while there are a number of instances of indexOf

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, no change here then, 👍 .

@@ -71,6 +72,10 @@ const defaultProps = {
orientation: BOTTOM
};

const predefinedClassName = 'rv-xy-plot__axis';
const VERTICAL_CLASS_NAME = 'rv-xy-plot__axis-vertical';
Copy link
Contributor

Choose a reason for hiding this comment

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

--vertical is the correct BEM convention. Do you think we'll get requests for separate classNames for left vs right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i doubt it, i've also subverted that potential issue by allowing users to supply their own

} = props;

const isY = [LEFT, RIGHT].indexOf(orientation) > -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

isY as a variable name might be a little confusing since there's an attribute and it may not be y

@mcnuttandrew mcnuttandrew merged commit b3bd715 into uber:master Nov 29, 2016
@mcnuttandrew mcnuttandrew deleted the better-axis-names branch March 23, 2017 20:20
ayarcohaila pushed a commit to ayarcohaila/react-vis that referenced this pull request Jun 30, 2021
* Add specific class names to x and y axes

* remove prop without delete

* add examples of using custom classing for axes

* respond to comment

* respond to moar comment

* lint ad clean up

* use benv

* change variable name
ayarcohaila added a commit to ayarcohaila/react-vis that referenced this pull request May 30, 2023
* Add specific class names to x and y axes

* remove prop without delete

* add examples of using custom classing for axes

* respond to comment

* respond to moar comment

* lint ad clean up

* use benv

* change variable name
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.

2 participants