-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add ability to rename grouped traces #1919
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 from 1 commit
aef38e5
d886c9e
e6f5e13
7a2316d
4e6a0aa
952e4ea
8f37fc7
dd035ef
7298a0c
64d2bcd
57dfe4a
c0089ea
42d76e0
efcef43
daac59d
6aefb41
be0e693
4943e3a
4b04131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,10 @@ var NAME = 1; | |
var VALUE = 2; | ||
var BOTH = 3; | ||
|
||
module.exports = function keyedContainer(baseObj, path) { | ||
module.exports = function keyedContainer(baseObj, path, keyName, valueName) { | ||
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. Interesting. I like it. @rreusser can you of other situations where this could be useful? 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. Yeah. It's also used in group styles, for one, though that case might be slightly more complicated. Also frames, though again, slightly more complicated. It's more a matter of realizing that unless we allow custom keys in the schema, abstracting this pattern seems like the only sane way forward. |
||
|
||
keyName = keyName || 'name'; | ||
valueName = valueName || 'value'; | ||
var i, arr; | ||
var changeTypes = {}; | ||
|
||
|
@@ -31,7 +34,7 @@ module.exports = function keyedContainer(baseObj, path) { | |
// Construct an index: | ||
var indexLookup = {}; | ||
for(i = 0; i < arr.length; i++) { | ||
indexLookup[arr[i].name] = i; | ||
indexLookup[arr[i][keyName]] = i; | ||
} | ||
|
||
var obj = { | ||
|
@@ -43,18 +46,21 @@ module.exports = function keyedContainer(baseObj, path) { | |
changeType = BOTH; | ||
idx = arr.length; | ||
indexLookup[name] = idx; | ||
} else if(value !== arr[idx].value) { | ||
} else if(value !== arr[idx][valueName]) { | ||
changeType = VALUE; | ||
} | ||
arr[idx] = {name: name, value: value}; | ||
var newValue = {}; | ||
newValue[keyName] = name; | ||
newValue[valueName] = value; | ||
arr[idx] = newValue; | ||
|
||
changeTypes[idx] = changeTypes[idx] | changeType; | ||
|
||
return obj; | ||
}, | ||
get: function(name) { | ||
var idx = indexLookup[name]; | ||
return idx === undefined ? undefined : arr[idx].value; | ||
return idx === undefined ? undefined : arr[idx][valueName]; | ||
}, | ||
rename: function(name, newName) { | ||
var idx = indexLookup[name]; | ||
|
@@ -65,7 +71,7 @@ module.exports = function keyedContainer(baseObj, path) { | |
indexLookup[newName] = idx; | ||
delete indexLookup[name]; | ||
|
||
arr[idx].name = newName; | ||
arr[idx][keyName] = newName; | ||
|
||
return obj; | ||
}, | ||
|
@@ -76,7 +82,7 @@ module.exports = function keyedContainer(baseObj, path) { | |
changeTypes[i] = changeTypes[i] | BOTH; | ||
} | ||
for(i = idx; i < arr.length; i++) { | ||
indexLookup[arr[i].name]--; | ||
indexLookup[arr[i][keyName]]--; | ||
} | ||
arr.splice(idx, 1); | ||
delete(indexLookup[name]); | ||
|
@@ -92,10 +98,10 @@ module.exports = function keyedContainer(baseObj, path) { | |
astr = path + '[' + idx + ']'; | ||
if(arr[idx]) { | ||
if(changeTypes[idx] & NAME) { | ||
update[astr + '.name'] = arr[idx].name; | ||
update[astr + '.' + keyName] = arr[idx][keyName]; | ||
} | ||
if(changeTypes[idx] & VALUE) { | ||
update[astr + '.value'] = arr[idx].value; | ||
update[astr + '.' + valueName] = arr[idx][valueName]; | ||
} | ||
} else { | ||
update[astr] = null; | ||
|
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.
hmm, there is a use case for a blank name - maybe less so for groupby than for regular traces, but sometimes you want the title for one trace to stand in for a few traces below it. You could argue then that this should just be testing for an actual empty string
''
but a space' '
should be allowed as the name.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.
okay, I could just check
=== ''
instead.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.
✅