-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make frame with nulls clear items & array containers #1118
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 all commits
69bffe1
4c49755
d21d782
138ac35
d0953a0
174b640
36859f1
66f8bb7
8ed1957
9de2f77
5de6ff0
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 |
---|---|---|
|
@@ -102,13 +102,12 @@ exports.cleanLayout = function(layout) { | |
} | ||
} | ||
|
||
if(layout.annotations !== undefined && !Array.isArray(layout.annotations)) { | ||
Lib.warn('Annotations must be an array.'); | ||
delete layout.annotations; | ||
} | ||
var annotationsLen = (layout.annotations || []).length; | ||
var annotationsLen = Array.isArray(layout.annotations) ? layout.annotations.length : 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. this commit was enough to fix bug discovered in http://codepen.io/etpinard/pen/xRGgwW |
||
for(i = 0; i < annotationsLen; i++) { | ||
var ann = layout.annotations[i]; | ||
|
||
if(!Lib.isPlainObject(ann)) continue; | ||
|
||
if(ann.ref) { | ||
if(ann.ref === 'paper') { | ||
ann.xref = 'paper'; | ||
|
@@ -120,17 +119,17 @@ exports.cleanLayout = function(layout) { | |
} | ||
delete ann.ref; | ||
} | ||
|
||
cleanAxRef(ann, 'xref'); | ||
cleanAxRef(ann, 'yref'); | ||
} | ||
|
||
if(layout.shapes !== undefined && !Array.isArray(layout.shapes)) { | ||
Lib.warn('Shapes must be an array.'); | ||
delete layout.shapes; | ||
} | ||
var shapesLen = (layout.shapes || []).length; | ||
var shapesLen = Array.isArray(layout.shapes) ? layout.shapes.length : 0; | ||
for(i = 0; i < shapesLen; i++) { | ||
var shape = layout.shapes[i]; | ||
|
||
if(!Lib.isPlainObject(shape)) continue; | ||
|
||
cleanAxRef(shape, 'xref'); | ||
cleanAxRef(shape, 'yref'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright 2012-2016, 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 Lib = require('../lib'); | ||
|
||
|
||
/** Convenience wrapper for making array container logic DRY and consistent | ||
* | ||
* @param {object} parentObjIn | ||
* user input object where the container in question is linked | ||
* (i.e. either a user trace object or the user layout object) | ||
* | ||
* @param {object} parentObjOut | ||
* full object where the coerced container will be linked | ||
* (i.e. either a full trace object or the full layout object) | ||
* | ||
* @param {object} opts | ||
* options object: | ||
* - name {string} | ||
* name of the key linking the container in question | ||
* - handleItemDefaults {function} | ||
* defaults method to be called on each item in the array container in question | ||
* | ||
* Its arguments are: | ||
* - itemIn {object} item in user layout | ||
* - itemOut {object} item in full layout | ||
* - parentObj {object} (as in closure) | ||
* - opts {object} (as in closure) | ||
* - itemOpts {object} | ||
* - itemIsNotPlainObject {boolean} | ||
* N.B. | ||
* | ||
* - opts is passed to handleItemDefaults so it can also store | ||
* links to supplementary data (e.g. fullData for layout components) | ||
* | ||
*/ | ||
module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut, opts) { | ||
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. similar to The logic below is pretty trivial, but might as well 🔒 down the behavior for all array containers. |
||
var name = opts.name; | ||
|
||
var contIn = Array.isArray(parentObjIn[name]) ? parentObjIn[name] : [], | ||
contOut = parentObjOut[name] = []; | ||
|
||
for(var i = 0; i < contIn.length; i++) { | ||
var itemIn = contIn[i], | ||
itemOut = {}, | ||
itemOpts = {}; | ||
|
||
if(!Lib.isPlainObject(itemIn)) { | ||
itemOpts.itemIsNotPlainObject = true; | ||
itemIn = {}; | ||
} | ||
|
||
opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts, itemOpts); | ||
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. Sure, that's fine. I still don't quite see where the handler will use the original |
||
|
||
itemOut._input = itemIn; | ||
itemOut._index = i; | ||
|
||
contOut.push(itemOut); | ||
} | ||
}; |
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.
🌴