Comments (17)
It should be possible. Let me tinker with it and see whatI can come up with.
from angularjs-nvd3-directives.
Currently I add "callback" attribute to directive scope:
.directive('nvd3DiscreteBarChart', ['$window', '$timeout', function($window, $timeout){
return {
restrict: 'E',
scope: {
callback: "&",
and call it once chart is created, inside of:
link: function(scope, element, attrs){
scope.$watch('data', function(data){}
}
and it looks ugly.(
from angularjs-nvd3-directives.
it seems like there should be an 'angular' way of approaching this.
Also, nvd3 exposes the d3 dispatch object which handles chart events. I think the trick should be finding the right way to marry the two (angular and dispatch).
from angularjs-nvd3-directives.
There appear to be a number of possibilities for handling this situation.
One method would be like the other event directives ngClick, etc that handle events. This jsfiddle example shows how this would work. http://jsfiddle.net/bYUa3/2/
Another method would be to intercept the specific dispatch events from nvd3/d3 and delegate them to an angular event with scope.$emit, or scope.$broadcast
In the directive, the code that would intercept the d3/nvd3 event would look something like this
chart.discretebar.dispatch.on('elementMouseover.tooltip', function(event) {
scope.$emit('elementMouseover.tooltip', event);
});
Then in the controller, all you would need to do is listen for the event on the scope object, like this:
$scope.$on('elementMouseover.tooltip', function(event){
console.log('scope.elementMouseover.tooltip', event);
});
They both seem to be reasonable approaches from an Angular perspective. I would like to do a little more research to determine the best approach, but I can see that it is something that will be needed and make this a better product.
Chris
from angularjs-nvd3-directives.
This is pretty awesome. Look forward to further progress!
from angularjs-nvd3-directives.
Ok, Pavel. I just pushed an update that handles events. There is an example in the examples folder, discreteBar.with.event.html. Essentially, I added code that that will emit an angular event based on the specific d3.js/nvd3.js event.
The one 'trick' that has to happen is the event name needs to be different from the specific event being emitted from the chart. If the names are the same the original event will be removed and replaced with the event that you define on the scope. Essentially, all of the existing functionality will muted.
https://github.com/mbostock/d3/wiki/Internals#wiki-dispatch
Take a look and let me know how this works for you.
Thanks,
Chris
from angularjs-nvd3-directives.
Just checking in. Have you had a chance to look at this?
Thanks,
Chris
from angularjs-nvd3-directives.
Eh, not yet. This is something that I'm gonna do tomorrow.
from angularjs-nvd3-directives.
@cmaurer
Finally verified your changes. Everything works as expected!
from angularjs-nvd3-directives.
Cool. I plan on adding this to the docs. adding the '.directive' to the event could be confusing.
Thanks for the feedback.
Chris
from angularjs-nvd3-directives.
A big thumbs up from me too, just what I was needing!
from angularjs-nvd3-directives.
I also like to implement click event in discrete & Multi bar charts. Not sure what's right event name. Tried below but not working. Can you please help? Thanks
$scope.$on('click.directive', function(event){
console.log('scope.click', event);
});
from angularjs-nvd3-directives.
let me take a look.
from angularjs-nvd3-directives.
This is what I'm using, if it helps:
$scope.$on('elementClick.directive', function(event, data) { });
from angularjs-nvd3-directives.
It also appears that I am missing the following for multibar:
'chartClick', 'elementDblClick', 'elementMouseover', 'elementMouseout'
I am probably missing more on the other models as well. Thats where the docs help make sure I got them all. I agree I need to finish those.
from angularjs-nvd3-directives.
I'm using $scope.$on('elementClick.directive', function(event, data) { }); in my controller, and it captures the event and data very well.
However, upon click I would like to advance to another chart, but when I put
$location.path(data.something.specific)
within the anonymous function nothing happens.
No action, even if I hardcode a path for the router and don't use the data argument passed in. What am I missing? Any help is appreciated.
from angularjs-nvd3-directives.
Perhaps "on click" isn't the right approach, from an Angular perspective. Angular really discourages you from interfacing directly with DOM events, at least outside of a library.
Instead, think about what your intent is when you're clicking. Are you concerned with where the mouse was when you clicked, or are you concerned with the data that's represented by that clicking? In my mind, it's all about getting the set of data (x, y1, y2, ..., yn) associated with that point. There's no need to do a $scope.$emit; just expose a property for the user to grab on to.
By way of (contrived and over-simplified) example:
<div ng-controller="MyControl as parentCtrl">
<line-chart data="parentCtrl.allData" selected-data="parentCtrl.activeData"/>
</div>
In the lineChart directive, the isolate scope would include:
selectedData: "="
When the click is detected within the library, it grabs the data values and sets them to selectedData. There could also be a property for hoveredData or whatever you want to call mouseOver. As an extension you could also watch selectedData inside the library, then emulate a click or manipulate the graph to show that part of it being selected.
To reiterate: the Angular way discourages you from exposing DOM events directly, and prefers that you expose properties which can be watched externally.
from angularjs-nvd3-directives.
Related Issues (20)
- how to i18n
- Custom data field names for sunburst..?
- How to achieve horizontal interactive guide line in nvd3 charts
- Need a vertical scroll in multiBarHorizontalChart if no. of bars increases
- How to i get data when iam click on pie chart HOT 2
- Discretebar Chart HOT 1
- Is there a way to save the graph and/or all its data to an xml or xmls ?
- TypeError: nv.dispatch.render_start is not a function HOT 2
- Pie Chart Label Lines with angular-nvd3
- Cannot read property 'disabled' of undefined
- Wrap long axis labels
- TypeError: nv.dispatch.render_start is not a function HOT 1
- Tooltip Not Hide while clicking outside of chart element in IPAD Devices
- Gradient color
- Format of focus chart x axis in "lineWithFocusChart" HOT 2
- Interactive Guideline Not showing on all the data points
- Fixed Labels on xAxis
- When selecting/deselecting legends with multi lines on line chart the lines start showing incorrect colors
- Cannot output data to another component using angular 2 custom event @Output()
- Discrete Bar chart tooltip customize
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularjs-nvd3-directives.