-
Notifications
You must be signed in to change notification settings - Fork 55
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 limit props to set height and width of XLine and YLine respectively #152
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,15 @@ export default class XLine extends React.Component { | |
*/ | ||
xScale: PropTypes.func, | ||
value: PropTypes.any.isRequired, | ||
/** | ||
* D3 scale for Y axis - provided by XYPlot | ||
*/ | ||
yScale: PropTypes.func, | ||
yLimit: PropTypes.any, | ||
/** | ||
* The Y domain of the data as an array - provided by XYPlot | ||
*/ | ||
yDomain: PropTypes.array, | ||
/** | ||
* Spacing top - provided by XYPlot | ||
*/ | ||
|
@@ -39,6 +48,9 @@ export default class XLine extends React.Component { | |
const { | ||
xScale, | ||
value, | ||
yScale, | ||
yLimit, | ||
yDomain, | ||
height, | ||
style, | ||
spacingTop, | ||
|
@@ -47,13 +59,21 @@ export default class XLine extends React.Component { | |
const className = `rct-chart-line-x ${this.props.className}`; | ||
const lineX = xScale(value); | ||
|
||
let y1 = -spacingTop; | ||
let y2 = height + spacingBottom; | ||
|
||
if (yLimit) { | ||
y1 = yScale(yDomain[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't this stay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha! I think we're missing the spacingBottom as well so we need to account for that if users pass that in. Is it possible, for consistency, for the YLine to always grow from the top or bottom (the latter makes more sense to me). So if there's a yLimit the only thing that would be altered is y2 where y1 should stay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @krissalvador27, sorry for the delay in making these changes. Finally had the chance to get to them. For the XLine to always consistently grow from the bottom (ie. by fixing the value of y1 as As of now, the XAxis component doesn't accept the yDomain as a prop from the XYPlot, and so the XLines that make the grid do not have the prop yDomain available. So should I go ahead and add yDomain and yScale as props for both XAxis and XGrid to make all lines (including the grid lines) grow from the bottom? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @tanayv! Thanks for catching that! XYPlot should hand yDomain and yScale down to all its children, so XAxis should easily accept it. I do worry that the complexity and scope is growing though. I think we can go with your original logic to accomplish the original XLine and YLine height and width limits and consistently have XLines grow from the top/limit point. 👍 |
||
y2 = yScale(yLimit); | ||
} | ||
|
||
return ( | ||
<line | ||
{...{ | ||
x1: lineX, | ||
x2: lineX, | ||
y1: -spacingTop, | ||
y2: height + spacingBottom, | ||
y1: y1, | ||
y2: y2, | ||
className, | ||
style | ||
}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems possible for yLimit to be
0
making this falsey.