@@ -107,12 +107,14 @@ plots.traceIs = function traceIs(traceType, category) {
107107/**
108108 * plots.registerSubplot: register a subplot type
109109 *
110- * @param {string } subplotType subplot type
111- * (these must also be categories defined with plots.register)
112- * @param {string or array of strings } attr attribute name in traces and layout
113- * @param {string or array of strings } idRoot root of id
114- * (setting the possible value for attrName)
115- * @param {object } attributes attribute(s) for traces of this subplot type
110+ * @param {object } _module subplot module:
111+ *
112+ * @param {string or array of strings } attr
113+ * attribute name in traces and layout
114+ * @param {string or array of strings } idRoot
115+ * root of id (setting the possible value for attrName)
116+ * @param {object } attributes
117+ * attribute(s) for traces of this subplot type
116118 *
117119 * In trace objects `attr` is the object key taking a valid `id` as value
118120 * (the set of all valid ids is generated below and stored in idRegex).
@@ -123,33 +125,36 @@ plots.traceIs = function traceIs(traceType, category) {
123125 *
124126 * TODO use these in Lib.coerce
125127 */
126- plots . registerSubplot = function ( subplotType , attr , idRoot , attributes ) {
127- if ( subplotsRegistry [ subplotType ] ) {
128- throw new Error ( 'subplot ' + subplotType + ' already registered' ) ;
128+ plots . registerSubplot = function ( _module ) {
129+ var plotType = _module . type ;
130+
131+ if ( subplotsRegistry [ plotType ] ) {
132+ throw new Error ( 'plot type' + plotType + ' already registered' ) ;
129133 }
130134
135+ var attr = _module . attr ,
136+ idRoot = _module . idRoot ;
137+
131138 var regexStart = '^' ,
132139 regexEnd = '([2-9]|[1-9][0-9]+)?$' ,
133- hasXY = ( subplotType === 'cartesian' || subplotsRegistry === 'gl2d' ) ;
140+ hasXY = ( plotType === 'cartesian' || subplotsRegistry === 'gl2d' ) ;
134141
135142 function makeRegex ( mid ) {
136143 return new RegExp ( regexStart + mid + regexEnd ) ;
137144 }
138145
139146 // not sure what's best for the 'cartesian' type at this point
140- subplotsRegistry [ subplotType ] = {
141- attr : attr ,
142- idRoot : idRoot ,
143- attributes : attributes ,
144- // register the regex representing the set of all valid attribute names
145- attrRegex : hasXY ?
146- { x : makeRegex ( attr [ 0 ] ) , y : makeRegex ( attr [ 1 ] ) } :
147- makeRegex ( attr ) ,
148- // register the regex representing the set of all valid attribute ids
149- idRegex : hasXY ?
150- { x : makeRegex ( idRoot [ 0 ] ) , y : makeRegex ( idRoot [ 1 ] ) } :
151- makeRegex ( idRoot )
152- } ;
147+ subplotsRegistry [ plotType ] = _module ;
148+
149+ // register the regex representing the set of all valid attribute names
150+ subplotsRegistry [ plotType ] . attrRegex = hasXY ?
151+ { x : makeRegex ( attr [ 0 ] ) , y : makeRegex ( attr [ 1 ] ) } :
152+ makeRegex ( attr ) ;
153+
154+ // register the regex representing the set of all valid attribute ids
155+ subplotsRegistry [ plotType ] . idRegex = hasXY ?
156+ { x : makeRegex ( idRoot [ 0 ] ) , y : makeRegex ( idRoot [ 1 ] ) } :
157+ makeRegex ( idRoot ) ;
153158} ;
154159
155160// TODO separate the 'find subplot' step (which looks in layout)
0 commit comments