@@ -13,134 +13,32 @@ var d3 = require('d3');
13
13
var isNumeric = require ( 'fast-isnumeric' ) ;
14
14
15
15
var Plotly = require ( '../plotly' ) ;
16
+ var Registry = require ( '../registry' ) ;
16
17
var Lib = require ( '../lib' ) ;
17
18
var Color = require ( '../components/color' ) ;
18
19
19
20
var plots = module . exports = { } ;
20
21
21
- var modules = plots . modules = { } ,
22
- allTypes = plots . allTypes = [ ] ,
23
- allCategories = plots . allCategories = { } ,
24
- subplotsRegistry = plots . subplotsRegistry = { } ,
25
- transformsRegistry = plots . transformsRegistry = { } ;
22
+ // Expose registry methods that used to be on Plots for backward-compatibility
23
+ plots . modules = Registry . modules ;
24
+ plots . allTypes = Registry . allTypes ;
25
+ plots . allCategories = Registry . allCategories ;
26
+ plots . subplotsRegistry = Registry . subplotsRegistry ;
27
+ plots . transformsRegistry = Registry . transformsRegistry ;
28
+ plots . traceIs = Registry . traceIs ;
29
+ plots . getModule = Registry . getModule ;
26
30
27
31
plots . attributes = require ( './attributes' ) ;
28
- plots . attributes . type . values = allTypes ;
32
+ plots . attributes . type . values = plots . allTypes ;
29
33
plots . fontAttrs = require ( './font_attributes' ) ;
30
34
plots . layoutAttributes = require ( './layout_attributes' ) ;
31
35
32
36
// TODO make this a plot attribute?
33
37
plots . fontWeight = 'normal' ;
34
38
35
- /**
36
- * plots.register: register a module as the handler for a trace type
37
- *
38
- * @param {object } _module the module that will handle plotting this trace type
39
- * @param {string } thisType
40
- * @param {array of strings } categoriesIn all the categories this type is in,
41
- * tested by calls: Plotly.Plots.traceIs(trace, oneCategory)
42
- * @param {object } meta meta information about the trace type
43
- */
44
- plots . register = function ( _module , thisType , categoriesIn , meta ) {
45
- if ( modules [ thisType ] ) {
46
- Lib . log ( 'Type ' + thisType + ' already registered' ) ;
47
- return ;
48
- }
49
-
50
- var categoryObj = { } ;
51
- for ( var i = 0 ; i < categoriesIn . length ; i ++ ) {
52
- categoryObj [ categoriesIn [ i ] ] = true ;
53
- allCategories [ categoriesIn [ i ] ] = true ;
54
- }
55
-
56
- modules [ thisType ] = {
57
- _module : _module ,
58
- categories : categoryObj
59
- } ;
60
-
61
- if ( meta && Object . keys ( meta ) . length ) {
62
- modules [ thisType ] . meta = meta ;
63
- }
64
-
65
- allTypes . push ( thisType ) ;
66
- } ;
67
-
68
- function getTraceType ( traceType ) {
69
- if ( typeof traceType === 'object' ) traceType = traceType . type ;
70
- return traceType ;
71
- }
72
-
73
- plots . getModule = function ( trace ) {
74
- if ( trace . r !== undefined ) {
75
- Lib . warn ( 'Tried to put a polar trace ' +
76
- 'on an incompatible graph of cartesian ' +
77
- 'data. Ignoring this dataset.' , trace
78
- ) ;
79
- return false ;
80
- }
81
-
82
- var _module = modules [ getTraceType ( trace ) ] ;
83
- if ( ! _module ) return false ;
84
- return _module . _module ;
85
- } ;
86
-
87
-
88
- /**
89
- * plots.traceIs: is this trace type in this category?
90
- *
91
- * traceType: a trace (object) or trace type (string)
92
- * category: a category (string)
93
- */
94
- plots . traceIs = function traceIs ( traceType , category ) {
95
- traceType = getTraceType ( traceType ) ;
96
-
97
- if ( traceType === 'various' ) return false ; // FIXME
39
+ var subplotsRegistry = plots . subplotsRegistry ;
40
+ var transformsRegistry = plots . transformsRegistry ;
98
41
99
- var _module = modules [ traceType ] ;
100
-
101
- if ( ! _module ) {
102
- if ( traceType !== undefined ) {
103
- Lib . log ( 'Unrecognized trace type ' + traceType + '.' ) ;
104
- }
105
- _module = modules [ plots . attributes . type . dflt ] ;
106
- }
107
-
108
- return ! ! _module . categories [ category ] ;
109
- } ;
110
-
111
-
112
- /**
113
- * plots.registerSubplot: register a subplot type
114
- *
115
- * @param {object } _module subplot module:
116
- *
117
- * @param {string or array of strings } attr
118
- * attribute name in traces and layout
119
- * @param {string or array of strings } idRoot
120
- * root of id (setting the possible value for attrName)
121
- * @param {object } attributes
122
- * attribute(s) for traces of this subplot type
123
- *
124
- * In trace objects `attr` is the object key taking a valid `id` as value
125
- * (the set of all valid ids is generated below and stored in idRegex).
126
- *
127
- * In the layout object, a or several valid `attr` name(s) can be keys linked
128
- * to a nested attribute objects
129
- * (the set of all valid attr names is generated below and stored in attrRegex).
130
- *
131
- * TODO use these in Lib.coerce
132
- */
133
- plots . registerSubplot = function ( _module ) {
134
- var plotType = _module . name ;
135
-
136
- if ( subplotsRegistry [ plotType ] ) {
137
- Lib . log ( 'Plot type ' + plotType + ' already registered.' ) ;
138
- return ;
139
- }
140
-
141
- // not sure what's best for the 'cartesian' type at this point
142
- subplotsRegistry [ plotType ] = _module ;
143
- } ;
144
42
145
43
/**
146
44
* Find subplot ids in data.
0 commit comments