-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
restyle/relayout refactor #1999
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
4d3e2ec
95d7d71
3326ecc
a948cce
dd52922
f90f079
e036fea
69e0188
bbfe399
29931ec
fad72a2
e895b32
7a7dc6d
c87b01a
658e5cb
f49ae5e
7ea0d25
284c87f
b9826c8
7c38a4a
96cc57f
cb94e95
238e248
42662ba
50aa1ca
62a1392
87b26d5
040ed1b
388a7fe
6e8a68c
4f8fc66
97ddf48
fe7db79
68f5dbc
d15e541
7ec1634
a107466
42805c2
8d9feaf
0a98a6d
e4227aa
0729921
407ae5a
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 |
---|---|---|
|
@@ -208,6 +208,142 @@ exports.findArrayAttributes = function(trace) { | |
return arrayAttributes; | ||
}; | ||
|
||
/* | ||
* Find the valObject for one attribute in an existing trace | ||
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. Is a 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. Less vaguely, 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. hah yeah, 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. Not a big deal. Just another part of the code I haven't gone too deep in. To clear up a common misconception though, naming in CS is a very easy problem (randomly generated strings will do). Naming for maximum interpretability is the hard part. 😄 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. I feel like 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.
|
||
* | ||
* @param {object} trace | ||
* full trace object that contains a reference to `_module.attributes` | ||
* @param {object} parts | ||
* an array of parts, like ['transforms', 1, 'value'] | ||
* typically from nestedProperty(...).parts | ||
* | ||
* @return {object|false} | ||
* the valObject for this attribute, or the last found parent | ||
* in some cases the innermost valObject will not exist, for example | ||
* `valType: 'any'` attributes where we might set a part of the attribute. | ||
* In that case, stop at the deepest valObject we *do* find. | ||
*/ | ||
exports.getTraceValObject = function(trace, parts) { | ||
var head = parts[0]; | ||
var i = 1; // index to start recursing from | ||
var moduleAttrs, valObject; | ||
|
||
if(head === 'transforms') { | ||
if(!Array.isArray(trace.transforms)) return false; | ||
var tNum = parts[1]; | ||
if(!isIndex(tNum) || tNum >= trace.transforms.length) { | ||
return false; | ||
} | ||
moduleAttrs = (Registry.transformsRegistry[trace.transforms[tNum].type] || {}).attributes; | ||
valObject = moduleAttrs && moduleAttrs[parts[2]]; | ||
i = 3; // start recursing only inside the transform | ||
} | ||
else if(trace.type === 'area') { | ||
valObject = polarAreaAttrs[head]; | ||
} | ||
else { | ||
// first look in the module for this trace | ||
// components have already merged their trace attributes in here | ||
var _module = trace._module; | ||
if(!_module) _module = (Registry.modules[trace.type || baseAttributes.type.dflt] || {})._module; | ||
if(!_module) return false; | ||
|
||
moduleAttrs = _module.attributes; | ||
valObject = moduleAttrs && moduleAttrs[head]; | ||
|
||
// then look in the global attributes | ||
if(!valObject) valObject = baseAttributes[head]; | ||
|
||
// finally look in the subplot attributes | ||
if(!valObject) { | ||
var subplotModule = _module.basePlotModule; | ||
if(subplotModule && subplotModule.attributes) { | ||
valObject = subplotModule.attributes[head]; | ||
} | ||
} | ||
} | ||
|
||
return recurseIntoValObject(valObject, parts, i); | ||
}; | ||
|
||
/* | ||
* Find the valObject for one layout attribute | ||
* | ||
* @param {array} parts | ||
* an array of parts, like ['annotations', 1, 'x'] | ||
* typically from nestedProperty(...).parts | ||
* | ||
* @return {object|false} | ||
* the valObject for this attribute, or the last found parent | ||
* in some cases the innermost valObject will not exist, for example | ||
* `valType: 'any'` attributes where we might set a part of the attribute. | ||
* In that case, stop at the deepest valObject we *do* find. | ||
*/ | ||
exports.getLayoutValObject = function(parts) { | ||
var valObject = layoutHeadAttr(parts[0]); | ||
|
||
return recurseIntoValObject(valObject, parts, 1); | ||
}; | ||
|
||
function layoutHeadAttr(head) { | ||
if(head in baseLayoutAttributes) return baseLayoutAttributes[head]; | ||
if(head in Registry.traceLayoutAttributes) return Registry.traceLayoutAttributes[head]; | ||
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. I vaguely remember reading that 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. Is |
||
|
||
var key, _module; | ||
|
||
for(key in Registry.componentsRegistry) { | ||
_module = Registry.componentsRegistry[key]; | ||
if(head === _module.name) return _module.layoutAttributes; | ||
} | ||
|
||
for(key in Registry.subplotsRegistry) { | ||
_module = Registry.subplotsRegistry[key]; | ||
if(_module.attrRegex && _module.attrRegex.test(head)) return _module.layoutAttributes; | ||
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. Beautiful. |
||
} | ||
|
||
if(head === 'radialaxis' || head === 'angularaxis') { | ||
return polarAxisAttrs[head]; | ||
} | ||
return polarAxisAttrs.layout[head] || false; | ||
} | ||
|
||
function recurseIntoValObject(valObject, parts, i) { | ||
if(!valObject) return false; | ||
|
||
if(valObject._isLinkedToArray) { | ||
// skip array index, abort if we try to dive into an array without an index | ||
if(isIndex(parts[i])) i++; | ||
else if(i < parts.length) return false; | ||
} | ||
|
||
// now recurse as far as we can. Occasionally we have an attribute | ||
// setting an internal part below what's | ||
for(; i < parts.length; i++) { | ||
var newValObject = valObject[parts[i]]; | ||
if(Lib.isPlainObject(newValObject)) valObject = newValObject; | ||
else break; | ||
|
||
if(i === parts.length - 1) break; | ||
|
||
if(valObject._isLinkedToArray) { | ||
i++; | ||
if(!isIndex(parts[i])) return false; | ||
} | ||
else if(valObject.valType === 'info_array') { | ||
i++; | ||
var index = parts[i]; | ||
if(!isIndex(index) || index >= valObject.items.length) return false; | ||
valObject = valObject.items[index]; | ||
} | ||
} | ||
|
||
return valObject; | ||
} | ||
|
||
function isIndex(val) { | ||
return val === Math.round(val) && val >= 0; | ||
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.
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. Oh, javascript.
(AFAIK, there is never a reason to use that, but it still seems surprising every time.) 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. plotly.js would be very unhappy if you use 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. 🔈 plotly.js is 100% broken with |
||
} | ||
|
||
function getTraceAttributes(type) { | ||
var _module, basePlotModule; | ||
|
||
|
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.
🆘 semi-useless lint comment alert 🆘
jsDOC is enabled on comments starting with
/**
(see http://usejsdoc.org/about-getting-started.html). As we don't extract those jsDOC comment (yet), adding this extra*
would just make that comment look prettier in my editor. Non-blocking.