1010'use strict' ;
1111
1212var Lib = require ( '../lib' ) ;
13- var isPlainObject = Lib . isPlainObject ;
1413var PlotSchema = require ( './plot_schema' ) ;
15- var Plots = require ( '../plots/plots' ) ;
14+ var supplyDefaults = require ( '../plots/plots' ) . supplyDefaults ;
1615var plotAttributes = require ( '../plots/attributes' ) ;
1716var Template = require ( './plot_template' ) ;
1817var dfltConfig = require ( './plot_config' ) . dfltConfig ;
1918
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+
2025/**
2126 * Plotly.makeTemplate: create a template off an existing figure to reuse
2227 * style attributes on other figures.
@@ -31,9 +36,9 @@ var dfltConfig = require('./plot_config').dfltConfig;
3136 * `layout.template` in another figure.
3237 */
3338exports . makeTemplate = function ( 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 ) ;
39+ figure = isPlainObject ( figure ) ? figure : getGraphDiv ( figure ) ;
40+ figure = extendDeep ( { _context : dfltConfig } , { data : figure . data , layout : figure . layout } ) ;
41+ supplyDefaults ( figure ) ;
3742 var data = figure . data || [ ] ;
3843 var layout = figure . layout || { } ;
3944 // copy over a few items to help follow the schema
@@ -64,7 +69,7 @@ exports.makeTemplate = function(figure) {
6469 var traceTemplate = { } ;
6570 walkStyleKeys ( trace , traceTemplate , getTraceInfo . bind ( null , trace ) ) ;
6671
67- var traceType = Lib . coerce ( trace , { } , plotAttributes , 'type' ) ;
72+ var traceType = coerce ( trace , { } , plotAttributes , 'type' ) ;
6873 var typeTemplates = template . data [ traceType ] ;
6974 if ( ! typeTemplates ) typeTemplates = template . data [ traceType ] = [ ] ;
7075 typeTemplates . push ( traceTemplate ) ;
@@ -105,13 +110,13 @@ exports.makeTemplate = function(figure) {
105110 mergeTemplates ( oldTypeTemplates [ i % oldTypeLen ] , typeTemplates [ i ] ) ;
106111 }
107112 for ( i = typeLen ; i < oldTypeLen ; i ++ ) {
108- typeTemplates . push ( Lib . extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
113+ typeTemplates . push ( extendDeep ( { } , oldTypeTemplates [ i ] ) ) ;
109114 }
110115 }
111116 }
112117 for ( traceType in oldDataTemplate ) {
113118 if ( ! ( traceType in template . data ) ) {
114- template . data [ traceType ] = Lib . extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
119+ template . data [ traceType ] = extendDeep ( [ ] , oldDataTemplate [ traceType ] ) ;
115120 }
116121 }
117122 }
@@ -123,7 +128,7 @@ exports.makeTemplate = function(figure) {
123128function mergeTemplates ( oldTemplate , newTemplate ) {
124129 // we don't care about speed here, just make sure we have a totally
125130 // distinct object from the previous template
126- oldTemplate = Lib . extendDeep ( { } , oldTemplate ) ;
131+ oldTemplate = extendDeep ( { } , oldTemplate ) ;
127132
128133 // sort keys so we always get annotationdefaults before annotations etc
129134 // so arrayTemplater will work right
@@ -229,8 +234,8 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
229234 var pathInArray = getNextPath ( child , namedIndex , nextPath ) ;
230235 walkStyleKeys ( item , templateOut , getAttributeInfo , pathInArray ,
231236 getNextPath ( child , namedIndex , nextBasePath ) ) ;
232- var itemPropInArray = Lib . nestedProperty ( templateOut , pathInArray ) ;
233- var dfltProp = Lib . nestedProperty ( templateOut , dfltPath ) ;
237+ var itemPropInArray = nestedProperty ( templateOut , pathInArray ) ;
238+ var dfltProp = nestedProperty ( templateOut , dfltPath ) ;
234239 dfltProp . set ( itemPropInArray . get ( ) ) ;
235240 itemPropInArray . set ( null ) ;
236241
@@ -239,21 +244,21 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
239244 }
240245 }
241246 } else {
242- var templateProp = Lib . nestedProperty ( templateOut , nextPath ) ;
247+ var templateProp = nestedProperty ( templateOut , nextPath ) ;
243248 templateProp . set ( child ) ;
244249 }
245250 }
246251}
247252
248253function getLayoutInfo ( layout , path ) {
249254 return PlotSchema . getLayoutValObject (
250- layout , Lib . nestedProperty ( { } , path ) . parts
255+ layout , nestedProperty ( { } , path ) . parts
251256 ) ;
252257}
253258
254259function getTraceInfo ( trace , path ) {
255260 return PlotSchema . getTraceValObject (
256- trace , Lib . nestedProperty ( { } , path ) . parts
261+ trace , nestedProperty ( { } , path ) . parts
257262 ) ;
258263}
259264
@@ -285,7 +290,7 @@ function getNextPath(parent, key, path) {
285290 * a full readable description of the issue.
286291 */
287292exports . validateTemplate = function ( figureIn , template ) {
288- var figure = Lib . extendDeep ( { } , {
293+ var figure = extendDeep ( { } , {
289294 _context : dfltConfig ,
290295 data : figureIn . data ,
291296 layout : figureIn . layout
@@ -298,7 +303,7 @@ exports.validateTemplate = function(figureIn, template) {
298303
299304 figure . layout = layout ;
300305 figure . layout . template = template ;
301- Plots . supplyDefaults ( figure ) ;
306+ supplyDefaults ( figure ) ;
302307
303308 var fullLayout = figure . _fullLayout ;
304309 var fullData = figure . _fullData ;
0 commit comments