-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Array edits #1403
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
Merged
Merged
Array edits #1403
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cc45189
fix basic annotation reference change bug
alexcjohnson 13a87ce
support RegExp in Lib.pushUnique
alexcjohnson 61f250c
editContainerArray: consistent handling of container array edits
alexcjohnson a9526bf
test fixin
alexcjohnson 649a831
robustify click_test
alexcjohnson d55568c
:hocho: obsolete getShapeLayer
alexcjohnson 2e6c030
break up new circular deps
alexcjohnson f7e60fb
relinkPrivateKeys inside arrayContainerDefaults
alexcjohnson d7cdc0a
revert layout_image.json - keep #1390 separate for now
alexcjohnson 7ed9eb9
fix for components using category names as coordinates
alexcjohnson 9f89dd6
fix for autorange with bad axis refs from a component
alexcjohnson 46962af
point to open issue #1111
alexcjohnson 1af058a
allow all `info_array`s to be pruned and command args to be optional
alexcjohnson c6378b1
exclude `args` from `nestedProperty` pruning
alexcjohnson 70c882b
keep _fullLayout container arrays in sync with splices in layout
alexcjohnson 5fb462f
comments and tests for plot_api/helpers.hasParent
alexcjohnson d29cbae
editContainerArray => applyContainerArrayChanges
alexcjohnson 3ef1c9b
test errors from parent/child simultaneous edits
alexcjohnson 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 hidden or 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,14 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Simple helper functions | ||
// none of these need any external deps | ||
|
||
module.exports = function identity(d) { return d; }; |
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Simple helper functions | ||
// none of these need any external deps | ||
|
||
module.exports = function noop() {}; | ||
This file contains hidden or 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,36 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Push array with unique items | ||
* | ||
* @param {array} array | ||
* array to be filled | ||
* @param {any} item | ||
* item to be or not to be inserted | ||
* @return {array} | ||
* ref to array (now possibly containing one more item) | ||
* | ||
*/ | ||
module.exports = function pushUnique(array, item) { | ||
if(item instanceof RegExp) { | ||
var itemStr = item.toString(), | ||
i; | ||
for(i = 0; i < array.length; i++) { | ||
if(array[i] instanceof RegExp && array[i].toString() === itemStr) { | ||
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. Can you add a few test cases for regex items -> https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/lib_test.js#L1246 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. |
||
return array; | ||
} | ||
} | ||
array.push(item); | ||
} | ||
else if(item && array.indexOf(item) === -1) array.push(item); | ||
|
||
return array; | ||
}; |
This file contains hidden or 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,56 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var Registry = require('../registry'); | ||
|
||
/* | ||
* containerArrayMatch: does this attribute string point into a | ||
* layout container array? | ||
* | ||
* @param {String} astr: an attribute string, like *annotations[2].text* | ||
* | ||
* @returns {Object | false} Returns false if `astr` doesn't match a container | ||
* array. If it does, returns: | ||
* {array: {String}, index: {Number}, property: {String}} | ||
* ie the attribute string for the array, the index within the array (or '' | ||
* if the whole array) and the property within that (or '' if the whole array | ||
* or the whole object) | ||
*/ | ||
module.exports = function containerArrayMatch(astr) { | ||
var rootContainers = Registry.layoutArrayContainers, | ||
regexpContainers = Registry.layoutArrayRegexes, | ||
rootPart = astr.split('[')[0], | ||
arrayStr, | ||
match; | ||
|
||
// look for regexp matches first, because they may be nested inside root matches | ||
// eg updatemenus[i].buttons is nested inside updatemenus | ||
for(var i = 0; i < regexpContainers.length; i++) { | ||
match = astr.match(regexpContainers[i]); | ||
if(match && match.index === 0) { | ||
arrayStr = match[0]; | ||
break; | ||
} | ||
} | ||
|
||
// now look for root matches | ||
if(!arrayStr) arrayStr = rootContainers[rootContainers.indexOf(rootPart)]; | ||
|
||
if(!arrayStr) return false; | ||
|
||
var tail = astr.substr(arrayStr.length); | ||
if(!tail) return {array: arrayStr, index: '', property: ''}; | ||
|
||
match = tail.match(/^\[(0|[1-9][0-9]*)\](\.(.+))?$/); | ||
if(!match) return false; | ||
|
||
return {array: arrayStr, index: Number(match[1]), property: match[3] || ''}; | ||
}; |
This file contains hidden or 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.
I thought this was about the shortest possible module one could make... but I suppose you could do:
Kind of silly... but needed to de-circularize, short of refactoring
Lib
(see #236 )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.
(resisting temptation suggest a noop factory approach)
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.
Actually it's important that
noop
is a singleton so you can use=== noop
particularly on the results ofRegistry.getComponentMethod
to see if it was found.