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

Added custom events click, hover and focus #221

Merged
merged 6 commits into from May 17, 2015

Conversation

chaosmail
Copy link
Contributor

Hi n3-chart team,

I added 3 custom events to the chart directive. Due to the glass g-element displayed for the scrubber tooltip, I was not able to implement click and hover in scrubber mode.

  • click: the mouse clicks on a dot or column (tooltip modes: axes, none)
  • hover: the mouse hovers over a dot or column (tooltip modes: axes, none)
  • focus: an event that triggers the scrubber focus (tooltip mode: scrubber)

Every event handler is called with the data element d and the position i in the array of values of a series.

I used this syntax for now, let me know if we can find something better:

<linechart data="data" options="options" click="onClick" hover="onHover" focus="onFocus"></linechart>
$scope.onClick = function(d, i){ ... };
$scope.onHover = function(d, i){ ... };
$scope.onFocus = function(d, i){ ... };

Here is an example for click and hover: http://plnkr.co/edit/PTxVo3qKEnooK1PcsXMX

Here is an example for focus: http://plnkr.co/edit/vUOa1v4UFRlbPZINCZ6X

Best,
Christoph


```js
$scope.onClick = function(d, i){
conosole.log(d, i);
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, conosole is not well-supported. Let's use console instead, if you don't mind :-)

@lorem--ipsum
Copy link
Member

Very good PR, thank you for your contribution.

@chaosmail
Copy link
Contributor Author

d3.events are very nice, clean and robust for dispatching (a lot of) events, maybe the initialHandler can be replaced with d3 events at one point.

@chaosmail
Copy link
Contributor Author

The glass layer somehow blocks the click events, so that the dots beneath don't get triggered. There is for sure also an easy way to propagate the click event through this layer - but I haven't looked into this yet.

@chaosmail
Copy link
Contributor Author

Yeah, and the point about the scrubber mode sounds good, let me add a third parameter to the callback of the focus event

@chaosmail
Copy link
Contributor Author

what do you think about for sending an array containing the inverted x and y positions from the mouse cursor?

xInvert = axes.xScale.invert(x)
yInvert = axes.yScale.invert(y)

dispatch.focus(v, series.values.indexOf(v), [xInvert, yInvert])

@chaosmail
Copy link
Contributor Author

I updated the demo, actually this additional value can be very useful too. http://plnkr.co/edit/vUOa1v4UFRlbPZINCZ6X?p=preview

@chaosmail
Copy link
Contributor Author

Fixes #199
Fixes #211

@lorem--ipsum
Copy link
Member

🍗

lorem--ipsum pushed a commit that referenced this pull request May 17, 2015
Added custom events click, hover and focus
@lorem--ipsum lorem--ipsum merged commit 6259b52 into n3-charts:master May 17, 2015
@chaosmail
Copy link
Contributor Author

Seems like the linked issues #199 and #211 are not automatically closed

This was referenced May 17, 2015
@chaosmail chaosmail deleted the feature/events branch May 22, 2015 21:28
@dorlandode
Copy link

Is there a reason the click event an hover events only work on tooltip mode axes and none? I was hoping it work on scrubber as well.

@chaosmail
Copy link
Contributor Author

Hi @dorlandode
the reason for this is how the scrubber tooltip works (it generates a transparent rectangle in front of all elements) which makes it hard to enable these events in scrubber mode.
However, we are actively developing version 2 (a complete rewrite in TypeScript) where this problem will be solved - and all events will be available for all tooltips.
Best,
Christoph

@dorlandode
Copy link

awesome, thanks for the update. What is the ETA on version 2?

lorem--ipsum pushed a commit that referenced this pull request Nov 3, 2015
Added custom events click, hover and focus
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