-
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
Clickable legends #3641
Changes from 59 commits
7fb7866
8bdcd7c
68f0bba
6a9a336
3e58851
fb0c811
a7490c2
2803c47
745cfbc
416cb6a
765d28a
8e4b47c
cd7353c
c17f132
5c11aaf
8fb8dfa
8ea33be
5ad0617
3085962
ffb35ad
439f625
2d6a29c
c7bfd38
9a86651
0327be4
e4f7d14
3314dd0
983fbe2
eee7ee1
2d65598
918f587
28290a2
f054ca3
391a571
ae73e96
b846d4c
deca719
bece5b4
ef3da96
1bf987f
960292d
12a21b8
418c153
c94727e
a5ca179
d6a6587
ae16129
ebaeb49
d244ddb
b36434e
f6954cf
ac3243c
c19a0af
4c8548e
5495c7f
67c7c44
57e8858
17a6ae5
9ca8f33
ad2d228
13f8a1a
6a63f54
69524a5
1060a41
153a60a
d1c3b14
c243f8d
7dbba6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
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. |
||
return _(returnNames(slices.children, 0, columns)) | ||
.sortBy(function (obj) { | ||
return obj.index; | ||
}) | ||
.pluck('key') | ||
.unique() | ||
.value(); | ||
} | ||
}; | ||
}; | ||
}); |
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) { | ||
var data = obj.columns || obj.rows || [obj]; | ||
var names = []; | ||
|
||
if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); } | ||
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 might be more helpful if it's before the var data = obj... assignment |
||
|
||
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); | ||
}; | ||
}; | ||
}); |
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; | ||
}; | ||
}; | ||
}); |
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; | ||
}; | ||
}; | ||
}); |
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,14 @@ 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 |
||
if (getLabels(data).length === 1 && getLabels(data)[0] === '') return [(this.get('yAxisLabel'))]; | ||
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. Perhaps you should use variable for this if statement. |
||
return getLabels(data); | ||
} | ||
return this.pieNames(); | ||
}; | ||
|
||
/** | ||
* Returns true for positive numbers | ||
*/ | ||
|
@@ -468,7 +463,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; | ||
|
@@ -502,8 +497,9 @@ define(function (require) { | |
.sortBy(function (obj) { | ||
return obj.index; | ||
}) | ||
.pluck('key') | ||
.unique() | ||
.unique(function (d) { | ||
return d.label; | ||
}) | ||
.value(); | ||
} | ||
}; | ||
|
@@ -536,9 +532,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) { | ||
|
@@ -550,7 +545,7 @@ define(function (require) { | |
}); | ||
}); | ||
|
||
return _.uniq(names); | ||
return _.uniq(names, 'label'); | ||
}; | ||
|
||
/** | ||
|
@@ -602,7 +597,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; | ||
})); | ||
}; | ||
|
||
/** | ||
|
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.
Perhaps this could be clearer using if statements.