-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Update config diff check method to handle nested arrays #7579
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 6 commits
b480d04
34a669e
364466a
3b3816f
20c534f
47be541
ef102cc
1b65938
0da832e
2767f07
01e698a
8ceebdf
3bc5b7e
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 @@ | ||
| - Update config diff check method to handle nested arrays [[#7579](https://github.com/plotly/plotly.js/pull/7579)] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,7 +455,7 @@ function getParent(attr) { | |
| if (tail > 0) return attr.substr(0, tail); | ||
| } | ||
|
|
||
| /* | ||
| /** | ||
| * hasParent: does an attribute object contain a parent of the given attribute? | ||
| * for example, given 'images[2].x' do we also have 'images' or 'images[2]'? | ||
| * | ||
|
|
@@ -475,6 +475,7 @@ exports.hasParent = function (aobj, attr) { | |
| return false; | ||
| }; | ||
|
|
||
| const AX_LETTERS = ['x', 'y', 'z']; | ||
| /** | ||
| * Empty out types for all axes containing these traces so we auto-set them again | ||
| * | ||
|
|
@@ -483,12 +484,11 @@ exports.hasParent = function (aobj, attr) { | |
| * @param {object} layoutUpdate: any update being done concurrently to the layout, | ||
| * which may supercede clearing the axis types | ||
| */ | ||
| var axLetters = ['x', 'y', 'z']; | ||
| exports.clearAxisTypes = function (gd, traces, layoutUpdate) { | ||
| for (var i = 0; i < traces.length; i++) { | ||
| var trace = gd._fullData[i]; | ||
| for (var j = 0; j < 3; j++) { | ||
| var ax = getFromTrace(gd, trace, axLetters[j]); | ||
| var ax = getFromTrace(gd, trace, AX_LETTERS[j]); | ||
|
|
||
| // do not clear log type - that's never an auto result so must have been intentional | ||
| if (ax && ax.type !== 'log') { | ||
|
|
@@ -507,3 +507,35 @@ exports.clearAxisTypes = function (gd, traces, layoutUpdate) { | |
| } | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Check if a collection (object or array) has changed given two versions of | ||
| * the collection: old and new. | ||
| * | ||
| * @param {Object|Array} oldCollection: Old version of collection to compare | ||
| * @param {Object|Array} newCollection: New version of collection to compare | ||
| */ | ||
| const hasCollectionChanged = (oldCollection, newCollection) => { | ||
|
||
| const isArrayOrObject = (...vals) => vals.every((v) => Lib.isPlainObject(v)) || vals.every((v) => Array.isArray(v)); | ||
| if ([oldCollection, newCollection].every((a) => Array.isArray(a))) { | ||
| if (oldCollection.length !== newCollection.length) return true; | ||
|
|
||
| for (let i = 0; i < oldCollection.length; i++) { | ||
| const oldVal = oldCollection[i]; | ||
| const newVal = newCollection[i]; | ||
| if (oldVal !== newVal) return isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true; | ||
| } | ||
| } else { | ||
| if (Object.keys(oldCollection).length !== Object.keys(newCollection).length) return true; | ||
|
|
||
| for (const k in oldCollection) { | ||
| if (k.startsWith('_')) return false; | ||
|
||
| const oldVal = oldCollection[k]; | ||
| const newVal = newCollection[k]; | ||
| if (oldVal !== newVal) return isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
| exports.hasCollectionChanged = hasCollectionChanged; | ||
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.
put at top of file perhaps? I would normally expect constants not inside a function to be defined at the top of the file.
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.
Can do.