10
10
'use strict' ;
11
11
12
12
var Lib = require ( '../lib' ) ;
13
+ var isPlainObject = Lib . isPlainObject ;
13
14
var PlotSchema = require ( './plot_schema' ) ;
14
- var supplyDefaults = require ( '../plots/plots' ) . supplyDefaults ;
15
+ var Plots = require ( '../plots/plots' ) ;
15
16
var plotAttributes = require ( '../plots/attributes' ) ;
16
17
var Template = require ( './plot_template' ) ;
17
18
var dfltConfig = require ( './plot_config' ) . dfltConfig ;
18
19
19
- var coerce = Lib . coerce ;
20
- var extendDeep = Lib . extendDeep ;
21
- var getGraphDiv = Lib . getGraphDiv ;
22
- var isPlainObject = Lib . isPlainObject ;
23
- var nestedProperty = Lib . nestedProperty ;
24
-
25
20
/**
26
21
* Plotly.makeTemplate: create a template off an existing figure to reuse
27
22
* style attributes on other figures.
@@ -36,9 +31,9 @@ var nestedProperty = Lib.nestedProperty;
36
31
* `layout.template` in another figure.
37
32
*/
38
33
exports . makeTemplate = function ( figure ) {
39
- figure = isPlainObject ( figure ) ? figure : getGraphDiv ( figure ) ;
40
- figure = extendDeep ( { _context : dfltConfig } , { data : figure . data , layout : figure . layout } ) ;
41
- supplyDefaults ( figure ) ;
34
+ figure = Lib . isPlainObject ( figure ) ? figure : Lib . getGraphDiv ( figure ) ;
35
+ figure = Lib . extendDeep ( { _context : dfltConfig } , { data : figure . data , layout : figure . layout } ) ;
36
+ Plots . supplyDefaults ( figure ) ;
42
37
var data = figure . data || [ ] ;
43
38
var layout = figure . layout || { } ;
44
39
// copy over a few items to help follow the schema
@@ -69,7 +64,7 @@ exports.makeTemplate = function(figure) {
69
64
var traceTemplate = { } ;
70
65
walkStyleKeys ( trace , traceTemplate , getTraceInfo . bind ( null , trace ) ) ;
71
66
72
- var traceType = coerce ( trace , { } , plotAttributes , 'type' ) ;
67
+ var traceType = Lib . coerce ( trace , { } , plotAttributes , 'type' ) ;
73
68
var typeTemplates = template . data [ traceType ] ;
74
69
if ( ! typeTemplates ) typeTemplates = template . data [ traceType ] = [ ] ;
75
70
typeTemplates . push ( traceTemplate ) ;
@@ -110,13 +105,13 @@ exports.makeTemplate = function(figure) {
110
105
mergeTemplates ( oldTypeTemplates [ i % oldTypeLen ] , typeTemplates [ i ] ) ;
111
106
}
112
107
for ( i = typeLen ; i < oldTypeLen ; i ++ ) {
113
- typeTemplates . push ( extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
108
+ typeTemplates . push ( Lib . extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
114
109
}
115
110
}
116
111
}
117
112
for ( traceType in oldDataTemplate ) {
118
113
if ( ! ( traceType in template . data ) ) {
119
- template . data [ traceType ] = extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
114
+ template . data [ traceType ] = Lib . extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
120
115
}
121
116
}
122
117
}
@@ -128,7 +123,7 @@ exports.makeTemplate = function(figure) {
128
123
function mergeTemplates ( oldTemplate , newTemplate ) {
129
124
// we don't care about speed here, just make sure we have a totally
130
125
// distinct object from the previous template
131
- oldTemplate = extendDeep ( { } , oldTemplate ) ;
126
+ oldTemplate = Lib . extendDeep ( { } , oldTemplate ) ;
132
127
133
128
// sort keys so we always get annotationdefaults before annotations etc
134
129
// so arrayTemplater will work right
@@ -234,8 +229,8 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
234
229
var pathInArray = getNextPath ( child , namedIndex , nextPath ) ;
235
230
walkStyleKeys ( item , templateOut , getAttributeInfo , pathInArray ,
236
231
getNextPath ( child , namedIndex , nextBasePath ) ) ;
237
- var itemPropInArray = nestedProperty ( templateOut , pathInArray ) ;
238
- var dfltProp = nestedProperty ( templateOut , dfltPath ) ;
232
+ var itemPropInArray = Lib . nestedProperty ( templateOut , pathInArray ) ;
233
+ var dfltProp = Lib . nestedProperty ( templateOut , dfltPath ) ;
239
234
dfltProp . set ( itemPropInArray . get ( ) ) ;
240
235
itemPropInArray . set ( null ) ;
241
236
@@ -244,21 +239,21 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
244
239
}
245
240
}
246
241
} else {
247
- var templateProp = nestedProperty ( templateOut , nextPath ) ;
242
+ var templateProp = Lib . nestedProperty ( templateOut , nextPath ) ;
248
243
templateProp . set ( child ) ;
249
244
}
250
245
}
251
246
}
252
247
253
248
function getLayoutInfo ( layout , path ) {
254
249
return PlotSchema . getLayoutValObject (
255
- layout , nestedProperty ( { } , path ) . parts
250
+ layout , Lib . nestedProperty ( { } , path ) . parts
256
251
) ;
257
252
}
258
253
259
254
function getTraceInfo ( trace , path ) {
260
255
return PlotSchema . getTraceValObject (
261
- trace , nestedProperty ( { } , path ) . parts
256
+ trace , Lib . nestedProperty ( { } , path ) . parts
262
257
) ;
263
258
}
264
259
@@ -290,7 +285,7 @@ function getNextPath(parent, key, path) {
290
285
* a full readable description of the issue.
291
286
*/
292
287
exports . validateTemplate = function ( figureIn , template ) {
293
- var figure = extendDeep ( { } , {
288
+ var figure = Lib . extendDeep ( { } , {
294
289
_context : dfltConfig ,
295
290
data : figureIn . data ,
296
291
layout : figureIn . layout
@@ -303,7 +298,7 @@ exports.validateTemplate = function(figureIn, template) {
303
298
304
299
figure . layout = layout ;
305
300
figure . layout . template = template ;
306
- supplyDefaults ( figure ) ;
301
+ Plots . supplyDefaults ( figure ) ;
307
302
308
303
var fullLayout = figure . _fullLayout ;
309
304
var fullData = figure . _fullData ;
0 commit comments