-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Clickable legends #3641
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
7fb7866
troubleshooting
stormpython 8bdcd7c
Merge branch 'master' into clickable-legends
stormpython 68f0bba
shaping up the click events for legend
stormpython 6a9a336
removing labels code since its no longer needed
stormpython 3e58851
fixing data-labels in the legend
stormpython fb0c811
troubleshooting mouseover on legend for area charts
stormpython a7490c2
Merge branch 'master' into clickable-legends
stormpython 2803c47
fixing broken tests
stormpython 745cfbc
removing console.log
stormpython 416cb6a
adding tests for the legend class
stormpython 765d28a
bring back aggConfigResult
stormpython 8e4b47c
adding an onclick listener test for the first li.color in the legend …
stormpython cd7353c
hooking up legend filtering
stormpython c17f132
troubleshooting issues with aggConfigResults
stormpython 5c11aaf
fixing tests and issues with clickable legend not returning the prope…
stormpython 8fb8dfa
addressing review comments
stormpython 8ea33be
Merge branch 'master' into clickable-legends
stormpython 5ad0617
Merge branch 'master' into clickable-legends
stormpython 3085962
Merge branch 'master' into clickable-legends
stormpython ffb35ad
addressing review comments, added _.deepGet to dispatch for retrievin…
stormpython 439f625
Merge branch 'master' into clickable-legends
stormpython 2d6a29c
Merge branch 'master' into clickable-legends
stormpython c7bfd38
Merge branch 'master' into clickable-legends
stormpython 9a86651
Merge branch 'master' into clickable-legends
stormpython 0327be4
troubleshooting
stormpython e4f7d14
troubleshooting bugs with pie in the legend
stormpython 3314dd0
fixing point series legend
stormpython 983fbe2
fixing bugs
stormpython eee7ee1
fixing tests
stormpython 2d65598
Merge branch 'master' into clickable-legends
stormpython 918f587
Merge branch 'master' into clickable-legends
stormpython 28290a2
Merge branch 'master' into clickable-legends
stormpython f054ca3
adding back clickable legend labels
stormpython 391a571
Merge branch 'master' into clickable-legends
stormpython ae73e96
Merge branch 'master' into clickable-legends
stormpython b846d4c
Merge branch 'master' into clickable-legends
stormpython deca719
fixing bug
stormpython bece5b4
Merge branch 'master' into clickable-legends
stormpython ef3da96
resolving issue with undefined labels in legend
stormpython 1bf987f
#3873. Fixing issue with numbers and dates not being highlighted prop…
stormpython 960292d
fixing tests
stormpython 12a21b8
removing reference to aggConfigResult.aggConfig.fieldFormatter()
stormpython 418c153
making corrections based on @spalger pr comments
stormpython c94727e
Merge branch 'master' into clickable-legends
stormpython a5ca179
fixing test in data.js
stormpython d6a6587
Merge branch 'master' into clickable-legends
stormpython ae16129
changes
stormpython ebaeb49
creating data label functions
stormpython d244ddb
changes
stormpython b36434e
troubleshooting
stormpython f6954cf
adding code to click handler to deal with legend values
stormpython ac3243c
refactoring
stormpython c19a0af
cleaning up tests, fixing issues with pie charts
stormpython 4c8548e
correcting _.uniq function
stormpython 5495c7f
removing commented code
stormpython 67c7c44
Merge branch 'master' into clickable-legends
stormpython 57e8858
Merge branch 'master' into clickable-legends
stormpython 17a6ae5
refactoring
stormpython 9ca8f33
Merge branch 'master' into clickable-legends
stormpython ad2d228
refactoring based on review comments
stormpython 13f8a1a
Merge branch 'master' into clickable-legends
stormpython 6a63f54
Merge branch 'master' into clickable-legends
stormpython 69524a5
Merge branch 'master' into clickable-legends
stormpython 1060a41
refactoring according to @jbudz 's comments.
stormpython 153a60a
fixing bug with clicking on a legend that is not associated with any …
stormpython d1c3b14
Merge branch 'master' into clickable-legends
stormpython c243f8d
removing pointer from legend when value === Count
stormpython 7dbba6b
reverting previous change
stormpython File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/kibana/components/vislib/components/labels/pie/get_pie_names.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
return function GetPieNames(Private) { | ||
var returnNames = Private(require('components/vislib/components/labels/pie/return_pie_names')); | ||
|
||
return function (data, columns) { | ||
var slices = data.slices; | ||
|
||
if (slices.children) { | ||
return _(returnNames(slices.children, 0, columns)) | ||
.sortBy(function (obj) { | ||
return obj.index; | ||
}) | ||
.pluck('key') | ||
.unique() | ||
.value(); | ||
} | ||
}; | ||
}; | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/kibana/components/vislib/components/labels/pie/pie_labels.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
return function PieLabels(Private) { | ||
var removeZeroSlices = Private(require('components/vislib/components/labels/pie/remove_zero_slices')); | ||
var getNames = Private(require('components/vislib/components/labels/pie/get_pie_names')); | ||
|
||
return function (obj) { | ||
if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); } | ||
|
||
var data = obj.columns || obj.rows || [obj]; | ||
var names = []; | ||
|
||
data.forEach(function (obj) { | ||
var columns = obj.raw ? obj.raw.columns : undefined; | ||
obj.slices = removeZeroSlices(obj.slices); | ||
|
||
getNames(obj, columns).forEach(function (name) { | ||
names.push(name); | ||
}); | ||
}); | ||
|
||
return _.uniq(names); | ||
}; | ||
}; | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/kibana/components/vislib/components/labels/pie/remove_zero_slices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
return function RemoveZeroSlices() { | ||
return function removeZeroSlices(slices) { | ||
if (!slices.children) return slices; | ||
|
||
slices = _.clone(slices); | ||
slices.children = slices.children.reduce(function (children, child) { | ||
if (child.size !== 0) { children.push(removeZeroSlices(child)); } | ||
return children; | ||
}, []); | ||
|
||
return slices; | ||
}; | ||
}; | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/kibana/components/vislib/components/labels/pie/return_pie_names.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
define(function () { | ||
return function ReturnPieNames() { | ||
return function returnNames(array, index, columns) { | ||
var names = []; | ||
|
||
array.forEach(function (obj) { | ||
names.push({ key: obj.name, index: index }); | ||
|
||
if (obj.children) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be better as an early return. |
||
returnNames(obj.children, (index + 1), columns).forEach(function (namedObj) { | ||
names.push(namedObj); | ||
}); | ||
} | ||
}); | ||
|
||
return names; | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,21 +37,8 @@ define(function (require) { | |
|
||
this.data = data; | ||
this.type = this.getDataType(); | ||
|
||
this.labels; | ||
|
||
if (this.type === 'series') { | ||
if (getLabels(data).length === 1 && getLabels(data)[0] === '') { | ||
this.labels = [(this.get('yAxisLabel'))]; | ||
} else { | ||
this.labels = getLabels(data); | ||
} | ||
} else if (this.type === 'slices') { | ||
this.labels = this.pieNames(); | ||
} | ||
|
||
this.labels = this._getLabels(this.data); | ||
this.color = this.labels ? color(this.labels) : undefined; | ||
|
||
this._normalizeOrdered(); | ||
|
||
this._attr = _.defaults(attr || {}, { | ||
|
@@ -73,6 +60,15 @@ define(function (require) { | |
} | ||
} | ||
|
||
Data.prototype._getLabels = function (data) { | ||
if (this.type === 'series') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every branch of this if resolves to a return, so no need for the |
||
var noLabel = getLabels(data).length === 1 && getLabels(data)[0] === ''; | ||
if (noLabel) return [(this.get('yAxisLabel'))]; | ||
return getLabels(data); | ||
} | ||
return this.pieNames(); | ||
}; | ||
|
||
/** | ||
* Returns true for positive numbers | ||
*/ | ||
|
@@ -485,7 +481,7 @@ define(function (require) { | |
var self = this; | ||
|
||
_.forEach(array, function (obj) { | ||
names.push({ key: obj.name, index: index }); | ||
names.push({ label: obj.name, values: obj, index: index }); | ||
|
||
if (obj.children) { | ||
var plusIndex = index + 1; | ||
|
@@ -519,8 +515,9 @@ define(function (require) { | |
.sortBy(function (obj) { | ||
return obj.index; | ||
}) | ||
.pluck('key') | ||
.unique() | ||
.unique(function (d) { | ||
return d.label; | ||
}) | ||
.value(); | ||
} | ||
}; | ||
|
@@ -553,9 +550,8 @@ define(function (require) { | |
* @method pieNames | ||
* @returns {Array} Array of unique names (strings) | ||
*/ | ||
Data.prototype.pieNames = function () { | ||
Data.prototype.pieNames = function (data) { | ||
var self = this; | ||
var data = this.getVisData(); | ||
var names = []; | ||
|
||
_.forEach(data, function (obj) { | ||
|
@@ -567,7 +563,7 @@ define(function (require) { | |
}); | ||
}); | ||
|
||
return _.uniq(names); | ||
return _.uniq(names, 'label'); | ||
}; | ||
|
||
/** | ||
|
@@ -619,7 +615,9 @@ define(function (require) { | |
* @returns {Function} Performs lookup on string and returns hex color | ||
*/ | ||
Data.prototype.getPieColorFunc = function () { | ||
return color(this.pieNames()); | ||
return color(this.pieNames(this.getVisData()).map(function (d) { | ||
return d.label; | ||
})); | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be better as an early return.