-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Changes the way Events are handled in the Visualization Library #1773
Conversation
Conflicts: src/kibana/components/vislib/lib/dispatch.js src/kibana/components/vislib/visualizations/column_chart.js
Conflicts: src/kibana/components/vislib/lib/dispatch.js
Conflicts: src/kibana/components/vislib/visualizations/pie_chart.js
…orted into a main file, removed event code from visualizations and moved them into the Dispatch class to reduce code redundancy, fixed issues with legend not toggling
Not currently mergable, but it looks like this is going to break existing interactions? Can you update any existing usages and get with @simianhacker to make sure he's happy with the new implementation? |
@rashidkpc I am not sure what you mean by break existing interactions. If you are talking about interactions with the current charts, the needed changes should be in this pull request. Unless you've tested it out and found some bugs that I am unaware of. I also had a sit down earlier with @simianhacker to go over the changes. But happy to have another one if he wants. |
Conflicts: src/kibana/components/vislib/lib/legend.js
Tests are passing for me locally. Looks like a build failure. |
Changes the way Events are handled in the Visualization Library
This pull request addresses issues with the way events are currently handled in the visualization library.
Currently, in order to listen for events on the chart, the
addEvents
flag needs to be set to true in the params passed to the chart upon initialization. Given that this is not an ideal way to handle events, a refactoring of the code was in order.With this pull request, events can now be added to the Vis object, and they will be bound to each chart. There is no need to set an
addEvents
flag. For example:This is all you will need to do in order to add events to charts. You will also be able to add multiple listeners for each event. You can also add events to charts before the
render
method is called as well as after. For example:This will cause both
'click'
and'brush'
events to be bound to the chart(s).To turn off events, you have two options.
For example:
In example 1, if the
click
array has several listeners (i.e. the array !== 0), then only the specified listener is removed. The chart still listens for click events and emits the event to the listeners in the array. However, if thearray.length === 0
, then the event is removed from the chart.In example 2, the 'click' event is removed all together from the chart. Events can be removed both before and after charts have been rendered.
Changes were made in several places in the code base to accommodate the changes to the way events are handled. Changes to the parts described above are found in the
vis.js
and thehandler.js
files.In order to reduce duplicate code in the visualization modules, the visualization event code was consolidated into the
dispatch.js
class. This move required a change in the way we were handling styling changes with events, as each chart required slightly different styling for events. The css styling was moved out of javascript and into the less files. And since the less files were a mess and disorganized, they were refactored and broken up into smaller, more manageable files.Finally, tests were written for the
on
andoff
methods invis.js
and for theenable
anddisable
methods inhandler.js
. Tests still need to be written fordispatch.js
methods as well as all visualization modules.