Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

VictoryCursorContainer #469

Merged
merged 5 commits into from
May 12, 2017
Merged

VictoryCursorContainer #469

merged 5 commits into from
May 12, 2017

Conversation

chrisbolin
Copy link
Contributor

Implements VictoryCursorContainer (FormidableLabs/victory#514)

demo at http://localhost:3000/#/cursor-container

Open issues:

  • Where should the label go for 1-dimensional cursors? (with mouse [current implementation], outside of chart, middle of chart, something else?)
  • createContainer("cursor", "voronoi") works pretty well, but is awkward when labels is used (both containers try to create labels, but they are in different places and for different values)

@chrisbolin
Copy link
Contributor Author

VictoryCursorContainer

may-11-2017 19-59-38

@chrisbolin
Copy link
Contributor Author

createContainer("cursor", "voronoi")

may-11-2017 19-59-06

@chrisbolin chrisbolin requested a review from boygirl May 11, 2017 18:04
static displayName = "VictoryCursorContainer";
static propTypes = {
...VictoryContainer.propTypes,
defaultCursorValue: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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"
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 = {
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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.

Approved pending labelOffset prop or something similar

@boygirl
Copy link
Contributor

boygirl commented May 11, 2017

Oh! actually, I just noticed... do labels and labelComponent conflict when you use createContainer with "voronoi" and "cursor"? How would you define independent values?

@chrisbolin
Copy link
Contributor Author

@boygirl YES, you are correct. When createContainer is used, they will both reference the same labels prop. That's why the example above (top-left under createContainer("cursor", "voronoi")) has two tooltips.

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 voronoiLabels and cursorLabelComponent) does make things more clear.

I'm not sure exactly what another solution would look like. createContainer literally creates a single class that implements the hybrid container.

@boygirl
Copy link
Contributor

boygirl commented May 11, 2017

In that case, let's go with cursorLabels and cursorLabelComponent. We can leave VictoryVoronoiContainer as is to avoid a breaking change

@chrisbolin
Copy link
Contributor Author

chrisbolin commented May 12, 2017

@boygirl addressed those issues. waiting for CI to pass before I merge anything.

also, i went with cursorLabel (singular) instead of cursorLabels, as a cursor can only have one label, and cursorLabelComponent was singular. Totally happy to do plural cursorLabels if you think that would be more consistent with other components.

@boygirl
Copy link
Contributor

boygirl commented May 12, 2017

@chrisbolin looks good to me! Approved!

@boygirl
Copy link
Contributor

boygirl commented May 12, 2017

I'm about to do a quick release, so I'm going to go ahead and merge this :)

@boygirl boygirl merged commit 8c73ecb into master May 12, 2017
@boygirl boygirl deleted the cursor branch May 12, 2017 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants