-
Notifications
You must be signed in to change notification settings - Fork 88
VictoryCursorContainer #469
Conversation
static displayName = "VictoryCursorContainer"; | ||
static propTypes = { | ||
...VictoryContainer.propTypes, | ||
defaultCursorValue: PropTypes.oneOfType([PropTypes.number, PropTypes.object]), |
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.
Prefer PropTypes.shape(x... y...)
to PropTypes.object
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.
yup!
return newElements; | ||
} | ||
|
||
getTooltip(props) { |
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.
getLabel
y: cursorCoordinates.y - 10, | ||
text: Helpers.evaluateProp(labels, cursorPosition, true), | ||
active: true, | ||
key: "cursor-tooltip" |
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.
"cursor-label"
}; | ||
if (labels) { | ||
newElements.push(React.cloneElement(labelComponent, { | ||
x: cursorCoordinates.x + 5, |
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.
hard coded positioning here seems wrong. Maybe a labelOffset
prop that can take a single value, or values for x and y.
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.
The values you have here can be the defaults
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.
thank you! i felt the same way
const newElements = []; | ||
const domainCoordinates = Selection.getDomainCoordinates(scale, domain); | ||
|
||
const cursorCoordinates = { |
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.
You're already getting the svg coordinates of the mouse position and transforming those into data coordinates in your helpers. You could just add the svg coordinates to the mutation in onMouseMove
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.
totally understand. i think i'll keep it this way though, because it handles getting the position when defaultCursorValue
(which can be both number and object) is used (i.e. there is no onMouseMove
).
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.
👍
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.
Approved pending labelOffset
prop or something similar
Oh! actually, I just noticed... do |
@boygirl YES, you are correct. When We could rename the props. This is definitely the simplest solution, but also is kind of skirting the problem. But hey, being specific (like with I'm not sure exactly what another solution would look like. |
In that case, let's go with |
…fset) to avoid collision using createContainer
@boygirl addressed those issues. waiting for CI to pass before I merge anything. also, i went with |
@chrisbolin looks good to me! Approved! |
I'm about to do a quick release, so I'm going to go ahead and merge this :) |
Implements VictoryCursorContainer (FormidableLabs/victory#514)
demo at http://localhost:3000/#/cursor-container
Open issues:
labels
is used (both containers try to create labels, but they are in different places and for different values)