1010'use strict' ;
1111
1212var Lib = require ( '../lib' ) ;
13+ var isPlainObject = Lib . isPlainObject ;
1314var PlotSchema = require ( './plot_schema' ) ;
14- var supplyDefaults = require ( '../plots/plots' ) . supplyDefaults ;
15+ var Plots = require ( '../plots/plots' ) ;
1516var plotAttributes = require ( '../plots/attributes' ) ;
1617var Template = require ( './plot_template' ) ;
1718var dfltConfig = require ( './plot_config' ) . dfltConfig ;
1819
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-
2520/**
2621 * Plotly.makeTemplate: create a template off an existing figure to reuse
2722 * style attributes on other figures.
@@ -36,9 +31,9 @@ var nestedProperty = Lib.nestedProperty;
3631 * `layout.template` in another figure.
3732 */
3833exports . 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 ) ;
4237 var data = figure . data || [ ] ;
4338 var layout = figure . layout || { } ;
4439 // copy over a few items to help follow the schema
@@ -69,7 +64,7 @@ exports.makeTemplate = function(figure) {
6964 var traceTemplate = { } ;
7065 walkStyleKeys ( trace , traceTemplate , getTraceInfo . bind ( null , trace ) ) ;
7166
72- var traceType = coerce ( trace , { } , plotAttributes , 'type' ) ;
67+ var traceType = Lib . coerce ( trace , { } , plotAttributes , 'type' ) ;
7368 var typeTemplates = template . data [ traceType ] ;
7469 if ( ! typeTemplates ) typeTemplates = template . data [ traceType ] = [ ] ;
7570 typeTemplates . push ( traceTemplate ) ;
@@ -110,13 +105,13 @@ exports.makeTemplate = function(figure) {
110105 mergeTemplates ( oldTypeTemplates [ i % oldTypeLen ] , typeTemplates [ i ] ) ;
111106 }
112107 for ( i = typeLen ; i < oldTypeLen ; i ++ ) {
113- typeTemplates . push ( extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
108+ typeTemplates . push ( Lib . extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
114109 }
115110 }
116111 }
117112 for ( traceType in oldDataTemplate ) {
118113 if ( ! ( traceType in template . data ) ) {
119- template . data [ traceType ] = extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
114+ template . data [ traceType ] = Lib . extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
120115 }
121116 }
122117 }
@@ -128,7 +123,7 @@ exports.makeTemplate = function(figure) {
128123function mergeTemplates ( oldTemplate , newTemplate ) {
129124 // we don't care about speed here, just make sure we have a totally
130125 // distinct object from the previous template
131- oldTemplate = extendDeep ( { } , oldTemplate ) ;
126+ oldTemplate = Lib . extendDeep ( { } , oldTemplate ) ;
132127
133128 // sort keys so we always get annotationdefaults before annotations etc
134129 // so arrayTemplater will work right
@@ -234,8 +229,8 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
234229 var pathInArray = getNextPath ( child , namedIndex , nextPath ) ;
235230 walkStyleKeys ( item , templateOut , getAttributeInfo , pathInArray ,
236231 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 ) ;
239234 dfltProp . set ( itemPropInArray . get ( ) ) ;
240235 itemPropInArray . set ( null ) ;
241236
@@ -244,21 +239,21 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
244239 }
245240 }
246241 } else {
247- var templateProp = nestedProperty ( templateOut , nextPath ) ;
242+ var templateProp = Lib . nestedProperty ( templateOut , nextPath ) ;
248243 templateProp . set ( child ) ;
249244 }
250245 }
251246}
252247
253248function getLayoutInfo ( layout , path ) {
254249 return PlotSchema . getLayoutValObject (
255- layout , nestedProperty ( { } , path ) . parts
250+ layout , Lib . nestedProperty ( { } , path ) . parts
256251 ) ;
257252}
258253
259254function getTraceInfo ( trace , path ) {
260255 return PlotSchema . getTraceValObject (
261- trace , nestedProperty ( { } , path ) . parts
256+ trace , Lib . nestedProperty ( { } , path ) . parts
262257 ) ;
263258}
264259
@@ -290,7 +285,7 @@ function getNextPath(parent, key, path) {
290285 * a full readable description of the issue.
291286 */
292287exports . validateTemplate = function ( figureIn , template ) {
293- var figure = extendDeep ( { } , {
288+ var figure = Lib . extendDeep ( { } , {
294289 _context : dfltConfig ,
295290 data : figureIn . data ,
296291 layout : figureIn . layout
@@ -303,7 +298,7 @@ exports.validateTemplate = function(figureIn, template) {
303298
304299 figure . layout = layout ;
305300 figure . layout . template = template ;
306- supplyDefaults ( figure ) ;
301+ Plots . supplyDefaults ( figure ) ;
307302
308303 var fullLayout = figure . _fullLayout ;
309304 var fullData = figure . _fullData ;
0 commit comments