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

Clickable legends #3641

Merged
merged 68 commits into from
Jul 16, 2015
Merged

Clickable legends #3641

merged 68 commits into from
Jul 16, 2015

Conversation

stormpython
Copy link
Contributor

Closes #2760.

The pull requests adds the ability to filter data by clicking li values in the legend. To implement this pr, I needed to restructure the way the legend is instantiated. Previously, the legend only received labels (among other things as input). In this pull, the legend gets the entire data set. This is needed so that we can pass the aggConfig object in the click event response. The aggConfig object contains the appropriate functions used to filter items.

In addition, to changes in the legend, the dispatch eventResponse function needed to be modified since not all the values in the legend's data object correspond with those from elements in the chart. Changes here may affect other areas of the code base that rely on the eventResponse function code.

I've also added a pointer on mouseover of the legend to signify to the user there is a click event listener here.

There are some important things to consider when reviewing this pull request. Its important to make sure that none of the other click events on the chart are affected. And, its important to test that the highlighting functions between the charts and the legend are still working properly for all chart types.

This pull request requires more than one reviewer.

Additional fixes

Closes #3873.
This appears to be a regression in which hovering over pie labels does not highlight legend values for numbers and dates. The reason for this has to due with the fact that for numbers and dates in the legend, the values were passed thru a field formatter function, and the resulting string values were changed. This was a problem because the data-label for pie slices was different from the data-label for legend items. We use the data-label to select both elements and when they differ, it leads to one (i.e. a pie slice or a legend value) being highlighted and not the other.

In addition, to make legend values clickable for numbers and dates, we need to include the unformatted label values. Therefore, to fix this issue, I removed formatting the legend labels from the vislib/components/label directory and moved that functionality to only format the text value for the legend label in legend.js. This allows the data-label for pie slices and legend values to be the same and since they are unformatted, allows for clickable legends.

@stormpython
Copy link
Contributor Author

I am still working on this pull request. I need to add tests, as well as hook up the click event to the proper listener to filter on legend click.

@simianhacker
Copy link
Member

It still doesn't seem to be triggering the click handler for the Vis object.

@stormpython
Copy link
Contributor Author

@simianhacker

I fixed the test issues as well as the issue with clickable legends not being hooked up. It should be hooked up and working (mostly) properly. There is however one issue, which is when splitting a chart by range values, the returning queries still appears to contain ranges that were not selected. For example, here is the before picture (i.e. before I clicked on a specific value in the legend to filter on):

screen shot 2015-04-24 at 4 47 16 pm

Now, here I click on the legend value - 1000.0-2000.0. I expect to see only that value in the legend and results, but instead I still get the other range that I did not select, i.e. 0-1000.0.

screen shot 2015-04-24 at 4 49 19 pm

I am not sure why this is. Perhaps @simianhacker you have an idea why this occurs.

if (obj.values && obj.values.length) {
var values = self._filterZeroInjectedValues(obj.values);
var aggConfigResult = values.length && values[0].aggConfigResult ?
values[0].aggConfigResult.$parent : undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Can you can you change this to:

var aggConfigResult;
if (values.length && values[0].aggConfigResult) {
  aggConfigResult = values[0].aggConfigResult.$parent;
}

Multiline ternaries are against our style guide

@@ -73,6 +60,14 @@ define(function (require) {
}
}

Data.prototype._getLabels = function (data) {
if (this.type === 'series') {
if (getLabels(data).length === 1 && getLabels(data)[0] === '') return [(this.get('yAxisLabel'))];
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you should use variable for this if statement.

@stormpython
Copy link
Contributor Author

@panda01 I addressed your comments above. You may still be in the process of reviewing the pr, so I will keep you assigned.

@stormpython stormpython assigned jbudz and unassigned panda01 Jul 15, 2015
var data = obj.columns || obj.rows || [obj];
var names = [];

if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); }
Copy link
Member

Choose a reason for hiding this comment

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

This might be more helpful if it's before the var data = obj... assignment

@jbudz
Copy link
Member

jbudz commented Jul 15, 2015

I was able to filter down to no data and get a console error. Not sure if filtering to no data is intentional, but I'm assuming the error isn't. Other than this and my comment above, looks good.

filter

@jbudz jbudz assigned stormpython and unassigned jbudz Jul 15, 2015
@stormpython
Copy link
Contributor Author

@jbudz I made the change and fixed the bug above. Can you confirm that you no longer see the bug above? Having a hard time reproducing.

@stormpython stormpython assigned jbudz and unassigned stormpython Jul 15, 2015
@jbudz
Copy link
Member

jbudz commented Jul 15, 2015

@stormpython Confirming, no more error.

@jbudz jbudz assigned stormpython and unassigned jbudz Jul 15, 2015
@stormpython
Copy link
Contributor Author

This pr has been reviewed by at least 6 people, with 3 LGTMs. I will give it one more look over and if everything is ok, merge it tomorrow.

stormpython added a commit that referenced this pull request Jul 16, 2015
@stormpython stormpython merged commit 2ce474f into elastic:master Jul 16, 2015
@stormpython stormpython deleted the clickable-legends branch July 16, 2015 15:15
@spalger spalger mentioned this pull request Sep 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hover does not highlight legend on pie w/ numeric values Clickable legend values
8 participants