99
1010'use strict' ;
1111
12- var Lib = require ( '../lib' ) ;
12+ var nestedProperty = require ( '../lib/nested_property' ) ;
13+ var isPlainObject = require ( '../lib/is_plain_object' ) ;
14+ var noop = require ( '../lib/noop' ) ;
15+ var Loggers = require ( '../lib/loggers' ) ;
1316var Registry = require ( '../registry' ) ;
1417
1518
19+ exports . containerArrayMatch = require ( './container_array_match' ) ;
20+
1621var isAddVal = exports . isAddVal = function isAddVal ( val ) {
17- return val === 'add' || Lib . isPlainObject ( val ) ;
22+ return val === 'add' || isPlainObject ( val ) ;
1823} ;
1924
2025var isRemoveVal = exports . isRemoveVal = function isRemoveVal ( val ) {
2126 return val === null || val === 'remove' ;
2227} ;
2328
24- /*
25- * containerArrayMatch: does this attribute string point into a
26- * layout container array?
27- *
28- * @param {String } astr: an attribute string, like *annotations[2].text*
29- *
30- * @returns {Object | false } Returns false if `astr` doesn't match a container
31- * array. If it does, returns:
32- * {array: {String}, index: {Number}, property: {String}}
33- * ie the attribute string for the array, the index within the array (or ''
34- * if the whole array) and the property within that (or '' if the whole array
35- * or the whole object)
36- */
37- exports . containerArrayMatch = function containerArrayMatch ( astr ) {
38- var rootContainers = Registry . layoutArrayContainers ,
39- regexpContainers = Registry . layoutArrayRegexes ,
40- rootPart = astr . split ( '[' ) [ 0 ] ,
41- arrayStr ,
42- match ;
43-
44- // look for regexp matches first, because they may be nested inside root matches
45- // eg updatemenus[i].buttons is nested inside updatemenus
46- for ( var i = 0 ; i < regexpContainers . length ; i ++ ) {
47- match = astr . match ( regexpContainers [ i ] ) ;
48- if ( match && match . index === 0 ) {
49- arrayStr = match [ 0 ] ;
50- break ;
51- }
52- }
53-
54- // now look for root matches
55- if ( ! arrayStr ) arrayStr = rootContainers [ rootContainers . indexOf ( rootPart ) ] ;
56-
57- if ( ! arrayStr ) return false ;
58-
59- var tail = astr . substr ( arrayStr . length ) ;
60- if ( ! tail ) return { array : arrayStr , index : '' , property : '' } ;
61-
62- match = tail . match ( / ^ \[ ( 0 | [ 1 - 9 ] [ 0 - 9 ] * ) \] ( \. ( .+ ) ) ? $ / ) ;
63- if ( ! match ) return false ;
64-
65- return { array : arrayStr , index : Number ( match [ 1 ] ) , property : match [ 3 ] || '' } ;
66- } ;
67-
6829/*
6930 * editContainerArray: for managing arrays of layout components in relayout
7031 * handles them all with a consistent interface.
@@ -113,14 +74,14 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
11374 supplyComponentDefaults = Registry . getComponentMethod ( componentType , 'supplyLayoutDefaults' ) ,
11475 draw = Registry . getComponentMethod ( componentType , 'draw' ) ,
11576 drawOne = Registry . getComponentMethod ( componentType , 'drawOne' ) ,
116- replotLater = flags . replot || flags . recalc || ( supplyComponentDefaults === Lib . noop ) ||
117- ( draw === Lib . noop ) ,
77+ replotLater = flags . replot || flags . recalc || ( supplyComponentDefaults === noop ) ||
78+ ( draw === noop ) ,
11879 layout = gd . layout ,
11980 fullLayout = gd . _fullLayout ;
12081
12182 if ( edits [ '' ] ) {
12283 if ( Object . keys ( edits ) . length > 1 ) {
123- Lib . warn ( 'Full array edits are incompatible with other edits' ,
84+ Loggers . warn ( 'Full array edits are incompatible with other edits' ,
12485 componentType ) ;
12586 }
12687
@@ -129,7 +90,7 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
12990 if ( isRemoveVal ( fullVal ) ) np . set ( null ) ;
13091 else if ( Array . isArray ( fullVal ) ) np . set ( fullVal ) ;
13192 else {
132- Lib . warn ( 'Unrecognized full array edit value' , componentType , fullVal ) ;
93+ Loggers . warn ( 'Unrecognized full array edit value' , componentType , fullVal ) ;
13394 return true ;
13495 }
13596
@@ -164,13 +125,13 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
164125 adding = isAddVal ( objVal ) ;
165126
166127 if ( componentNum < 0 || componentNum > componentArray . length - ( adding ? 0 : 1 ) ) {
167- Lib . warn ( 'index out of range' , componentType , componentNum ) ;
128+ Loggers . warn ( 'index out of range' , componentType , componentNum ) ;
168129 continue ;
169130 }
170131
171132 if ( objVal !== undefined ) {
172133 if ( objKeys . length > 1 ) {
173- Lib . warn (
134+ Loggers . warn (
174135 'Insertion & removal are incompatible with edits to the same index.' ,
175136 componentType , componentNum ) ;
176137 }
@@ -183,15 +144,15 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
183144 componentArray . splice ( componentNum , 0 , objVal ) ;
184145 }
185146 else {
186- Lib . warn ( 'Unrecognized full object edit value' ,
147+ Loggers . warn ( 'Unrecognized full object edit value' ,
187148 componentType , componentNum , objVal ) ;
188149 }
189150
190151 if ( firstIndexChange === - 1 ) firstIndexChange = componentNum ;
191152 }
192153 else {
193154 for ( j = 0 ; j < objKeys . length ; j ++ ) {
194- Lib . nestedProperty ( componentArray [ componentNum ] , objKeys [ j ] ) . set ( objEdits [ objKeys [ j ] ] ) ;
155+ nestedProperty ( componentArray [ componentNum ] , objKeys [ j ] ) . set ( objEdits [ objKeys [ j ] ] ) ;
195156 }
196157 }
197158 }
@@ -210,7 +171,7 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
210171
211172 // finally draw all the components we need to
212173 // if we added or removed any, redraw all after it
213- if ( drawOne !== Lib . noop ) {
174+ if ( drawOne !== noop ) {
214175 var indicesToDraw ;
215176 if ( firstIndexChange === - 1 ) {
216177 // there's no re-indexing to do, so only redraw components that changed
0 commit comments