From 7b459284f11719f6b97684946546c6582768ca6d Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 24 Apr 2019 22:57:35 -0400 Subject: [PATCH 1/2] reduce plot_api imports --- src/plot_api/container_array_match.js | 5 ++-- src/plot_api/edit_types.js | 5 ++-- src/plot_api/helpers.js | 24 ++++++++--------- src/plot_api/manage_arrays.js | 8 +++--- src/plot_api/plot_schema.js | 21 ++++++++------- src/plot_api/template_api.js | 37 +++++++++++++++------------ src/plot_api/to_image.js | 7 ++--- 7 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/plot_api/container_array_match.js b/src/plot_api/container_array_match.js index 45e6192d01c..56abed71158 100644 --- a/src/plot_api/container_array_match.js +++ b/src/plot_api/container_array_match.js @@ -9,7 +9,8 @@ 'use strict'; -var Registry = require('../registry'); +var rootContainers = require('../registry').layoutArrayContainers; +var regexpContainers = require('../registry').layoutArrayRegexes; /* * containerArrayMatch: does this attribute string point into a @@ -25,8 +26,6 @@ var Registry = require('../registry'); * or the whole object) */ module.exports = function containerArrayMatch(astr) { - var rootContainers = Registry.layoutArrayContainers; - var regexpContainers = Registry.layoutArrayRegexes; var rootPart = astr.split('[')[0]; var arrayStr; var match; diff --git a/src/plot_api/edit_types.js b/src/plot_api/edit_types.js index 73972c449c6..4b78ab15f23 100644 --- a/src/plot_api/edit_types.js +++ b/src/plot_api/edit_types.js @@ -8,9 +8,8 @@ 'use strict'; -var Lib = require('../lib'); -var extendFlat = Lib.extendFlat; -var isPlainObject = Lib.isPlainObject; +var extendFlat = require('../lib').extendFlat; +var isPlainObject = require('../lib').isPlainObject; var traceOpts = { valType: 'flaglist', diff --git a/src/plot_api/helpers.js b/src/plot_api/helpers.js index 72fb27472d4..d910d41e8a0 100644 --- a/src/plot_api/helpers.js +++ b/src/plot_api/helpers.js @@ -12,15 +12,15 @@ var isNumeric = require('fast-isnumeric'); var m4FromQuat = require('gl-mat4/fromQuat'); -var Registry = require('../registry'); var Lib = require('../lib'); -var Plots = require('../plots/plots'); -var AxisIds = require('../plots/cartesian/axis_ids'); +var subplotsRegistry = require('../plots/plots').subplotsRegistry; var Color = require('../components/color'); -var cleanId = AxisIds.cleanId; -var getFromTrace = AxisIds.getFromTrace; -var traceIs = Registry.traceIs; +var cleanId = require('../plots/cartesian/axis_ids').cleanId; +var getFromTrace = require('../plots/cartesian/axis_ids').getFromTrace; + +var traceIs = require('../registry').traceIs; +var getModule = require('../registry').getModule; // clear the promise queue if one of them got rejected exports.clearPromiseQueue = function(gd) { @@ -53,10 +53,10 @@ exports.cleanLayout = function(layout) { delete layout.scene1; } - var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex; - var polarAttrRegex = (Plots.subplotsRegistry.polar || {}).attrRegex; - var ternaryAttrRegex = (Plots.subplotsRegistry.ternary || {}).attrRegex; - var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex; + var axisAttrRegex = (subplotsRegistry.cartesian || {}).attrRegex; + var polarAttrRegex = (subplotsRegistry.polar || {}).attrRegex; + var ternaryAttrRegex = (subplotsRegistry.ternary || {}).attrRegex; + var sceneAttrRegex = (subplotsRegistry.gl3d || {}).attrRegex; var keys = Object.keys(layout); for(i = 0; i < keys.length; i++) { @@ -325,7 +325,7 @@ exports.cleanData = function(data) { // scene ids scene1 -> scene if(traceIs(trace, 'gl3d') && trace.scene) { - trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene); + trace.scene = subplotsRegistry.gl3d.cleanId(trace.scene); } if(!traceIs(trace, 'pie') && !traceIs(trace, 'bar') && trace.type !== 'waterfall') { @@ -339,7 +339,7 @@ exports.cleanData = function(data) { } // fix typo in colorscale definition - var _module = Registry.getModule(trace); + var _module = getModule(trace); if(_module && _module.colorbar) { var containerName = _module.colorbar.container; var container = containerName ? trace[containerName] : trace; diff --git a/src/plot_api/manage_arrays.js b/src/plot_api/manage_arrays.js index 3bea13ca6a7..fc3caaa98e3 100644 --- a/src/plot_api/manage_arrays.js +++ b/src/plot_api/manage_arrays.js @@ -13,7 +13,7 @@ var isPlainObject = require('../lib/is_plain_object'); var noop = require('../lib/noop'); var Loggers = require('../lib/loggers'); var sorterAsc = require('../lib/search').sorterAsc; -var Registry = require('../registry'); +var getComponentMethod = require('../registry').getComponentMethod; exports.containerArrayMatch = require('./container_array_match'); @@ -75,9 +75,9 @@ var isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) { */ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags, _nestedProperty) { var componentType = np.astr; - var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults'); - var draw = Registry.getComponentMethod(componentType, 'draw'); - var drawOne = Registry.getComponentMethod(componentType, 'drawOne'); + var supplyComponentDefaults = getComponentMethod(componentType, 'supplyLayoutDefaults'); + var draw = getComponentMethod(componentType, 'draw'); + var drawOne = getComponentMethod(componentType, 'drawOne'); var replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || (draw === noop); var layout = gd.layout; var fullLayout = gd._fullLayout; diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 516a79c0fcf..1b1551e0143 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -27,6 +27,9 @@ var editTypes = require('./edit_types'); var extendFlat = Lib.extendFlat; var extendDeepAll = Lib.extendDeepAll; var isPlainObject = Lib.isPlainObject; +var isArrayOrTypedArray = Lib.isArrayOrTypedArray; +var nestedProperty = Lib.nestedProperty; +var valObjectMeta = Lib.valObjectMeta; var IS_SUBPLOT_OBJ = '_isSubplotObj'; var IS_LINKED_TO_ARRAY = '_isLinkedToArray'; @@ -65,7 +68,7 @@ exports.get = function() { return { defs: { - valObjects: Lib.valObjectMeta, + valObjects: valObjectMeta, metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']), editType: { traces: editTypes.traces, @@ -204,19 +207,19 @@ exports.findArrayAttributes = function(trace) { var item = container[stack[i]]; var newAstrPartial = astrPartial + stack[i]; if(i === stack.length - 1) { - if(Lib.isArrayOrTypedArray(item)) { + if(isArrayOrTypedArray(item)) { arrayAttributes.push(baseAttrName + newAstrPartial); } } else { if(isArrayStack[i]) { if(Array.isArray(item)) { for(var j = 0; j < item.length; j++) { - if(Lib.isPlainObject(item[j])) { + if(isPlainObject(item[j])) { crawlIntoTrace(item[j], i + 1, newAstrPartial + '[' + j + '].'); } } } - } else if(Lib.isPlainObject(item)) { + } else if(isPlainObject(item)) { crawlIntoTrace(item, i + 1, newAstrPartial + '.'); } } @@ -463,9 +466,9 @@ function getTraceAttributes(type) { // prune global-level trace attributes that are already defined in a trace exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) { - Lib.nestedProperty(copyBaseAttributes, fullAttrString).set(undefined); + nestedProperty(copyBaseAttributes, fullAttrString).set(undefined); // Prune undefined attributes - if(attr === undefined) Lib.nestedProperty(copyModuleAttributes, fullAttrString).set(undefined); + if(attr === undefined) nestedProperty(copyModuleAttributes, fullAttrString).set(undefined); }); // base attributes (same for all trace types) @@ -597,7 +600,7 @@ function getTransformAttributes(type) { function getFramesAttributes() { var attrs = { - frames: Lib.extendDeepAll({}, frameAttributes) + frames: extendDeepAll({}, frameAttributes) }; formatAttributes(attrs); @@ -699,7 +702,7 @@ function assignPolarLayoutAttrs(layoutAttributes) { } function handleBasePlotModule(layoutAttributes, _module, astr) { - var np = Lib.nestedProperty(layoutAttributes, astr); + var np = nestedProperty(layoutAttributes, astr); var attrs = extendDeepAll({}, _module.layoutAttributes); attrs[IS_SUBPLOT_OBJ] = true; @@ -707,7 +710,7 @@ function handleBasePlotModule(layoutAttributes, _module, astr) { } function insertAttrs(baseAttrs, newAttrs, astr) { - var np = Lib.nestedProperty(baseAttrs, astr); + var np = nestedProperty(baseAttrs, astr); np.set(extendDeepAll(np.get() || {}, newAttrs)); } diff --git a/src/plot_api/template_api.js b/src/plot_api/template_api.js index 7f9aaddc977..3f005ce78ef 100644 --- a/src/plot_api/template_api.js +++ b/src/plot_api/template_api.js @@ -10,13 +10,18 @@ 'use strict'; var Lib = require('../lib'); -var isPlainObject = Lib.isPlainObject; var PlotSchema = require('./plot_schema'); -var Plots = require('../plots/plots'); +var supplyDefaults = require('../plots/plots').supplyDefaults; var plotAttributes = require('../plots/attributes'); var Template = require('./plot_template'); var dfltConfig = require('./plot_config').dfltConfig; +var coerce = Lib.coerce; +var extendDeep = Lib.extendDeep; +var getGraphDiv = Lib.getGraphDiv; +var isPlainObject = Lib.isPlainObject; +var nestedProperty = Lib.nestedProperty; + /** * Plotly.makeTemplate: create a template off an existing figure to reuse * style attributes on other figures. @@ -31,9 +36,9 @@ var dfltConfig = require('./plot_config').dfltConfig; * `layout.template` in another figure. */ exports.makeTemplate = function(figure) { - figure = Lib.isPlainObject(figure) ? figure : Lib.getGraphDiv(figure); - figure = Lib.extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout}); - Plots.supplyDefaults(figure); + figure = isPlainObject(figure) ? figure : getGraphDiv(figure); + figure = extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout}); + supplyDefaults(figure); var data = figure.data || []; var layout = figure.layout || {}; // copy over a few items to help follow the schema @@ -64,7 +69,7 @@ exports.makeTemplate = function(figure) { var traceTemplate = {}; walkStyleKeys(trace, traceTemplate, getTraceInfo.bind(null, trace)); - var traceType = Lib.coerce(trace, {}, plotAttributes, 'type'); + var traceType = coerce(trace, {}, plotAttributes, 'type'); var typeTemplates = template.data[traceType]; if(!typeTemplates) typeTemplates = template.data[traceType] = []; typeTemplates.push(traceTemplate); @@ -105,13 +110,13 @@ exports.makeTemplate = function(figure) { mergeTemplates(oldTypeTemplates[i % oldTypeLen], typeTemplates[i]); } for(i = typeLen; i < oldTypeLen; i++) { - typeTemplates.push(Lib.extendDeep({}, oldTypeTemplates[i])); + typeTemplates.push(extendDeep({}, oldTypeTemplates[i])); } } } for(traceType in oldDataTemplate) { if(!(traceType in template.data)) { - template.data[traceType] = Lib.extendDeep([], oldDataTemplate[traceType]); + template.data[traceType] = extendDeep([], oldDataTemplate[traceType]); } } } @@ -123,7 +128,7 @@ exports.makeTemplate = function(figure) { function mergeTemplates(oldTemplate, newTemplate) { // we don't care about speed here, just make sure we have a totally // distinct object from the previous template - oldTemplate = Lib.extendDeep({}, oldTemplate); + oldTemplate = extendDeep({}, oldTemplate); // sort keys so we always get annotationdefaults before annotations etc // so arrayTemplater will work right @@ -229,8 +234,8 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { var pathInArray = getNextPath(child, namedIndex, nextPath); walkStyleKeys(item, templateOut, getAttributeInfo, pathInArray, getNextPath(child, namedIndex, nextBasePath)); - var itemPropInArray = Lib.nestedProperty(templateOut, pathInArray); - var dfltProp = Lib.nestedProperty(templateOut, dfltPath); + var itemPropInArray = nestedProperty(templateOut, pathInArray); + var dfltProp = nestedProperty(templateOut, dfltPath); dfltProp.set(itemPropInArray.get()); itemPropInArray.set(null); @@ -239,7 +244,7 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { } } } else { - var templateProp = Lib.nestedProperty(templateOut, nextPath); + var templateProp = nestedProperty(templateOut, nextPath); templateProp.set(child); } } @@ -247,13 +252,13 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { function getLayoutInfo(layout, path) { return PlotSchema.getLayoutValObject( - layout, Lib.nestedProperty({}, path).parts + layout, nestedProperty({}, path).parts ); } function getTraceInfo(trace, path) { return PlotSchema.getTraceValObject( - trace, Lib.nestedProperty({}, path).parts + trace, nestedProperty({}, path).parts ); } @@ -285,7 +290,7 @@ function getNextPath(parent, key, path) { * a full readable description of the issue. */ exports.validateTemplate = function(figureIn, template) { - var figure = Lib.extendDeep({}, { + var figure = extendDeep({}, { _context: dfltConfig, data: figureIn.data, layout: figureIn.layout @@ -298,7 +303,7 @@ exports.validateTemplate = function(figureIn, template) { figure.layout = layout; figure.layout.template = template; - Plots.supplyDefaults(figure); + supplyDefaults(figure); var fullLayout = figure._fullLayout; var fullData = figure._fullData; diff --git a/src/plot_api/to_image.js b/src/plot_api/to_image.js index c1a8c8733e1..4bda66ec4b7 100644 --- a/src/plot_api/to_image.js +++ b/src/plot_api/to_image.js @@ -10,7 +10,8 @@ var isNumeric = require('fast-isnumeric'); -var plotApi = require('./plot_api'); +var plot = require('./plot_api').plot; +var purge = require('./plot_api').purge; var Lib = require('../lib'); var helpers = require('../snapshot/helpers'); @@ -172,7 +173,7 @@ function toImage(gd, opts) { var width = clonedGd._fullLayout.width; var height = clonedGd._fullLayout.height; - plotApi.purge(clonedGd); + purge(clonedGd); document.body.removeChild(clonedGd); if(format === 'svg') { @@ -213,7 +214,7 @@ function toImage(gd, opts) { } return new Promise(function(resolve, reject) { - plotApi.plot(clonedGd, data, layoutImage, configImage) + plot(clonedGd, data, layoutImage, configImage) .then(redrawFunc) .then(wait) .then(convert) From bc0ae2cb3eaa98e9587108bf635a3e1edc20acdd Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 8 May 2019 09:28:36 -0400 Subject: [PATCH 2/2] only refactor plot_schema and revert commit 7b459284f11719f6b97684946546c6582768ca6d. --- src/plot_api/container_array_match.js | 5 ++-- src/plot_api/edit_types.js | 5 ++-- src/plot_api/helpers.js | 24 ++++++++--------- src/plot_api/manage_arrays.js | 8 +++--- src/plot_api/template_api.js | 37 ++++++++++++--------------- src/plot_api/to_image.js | 7 +++-- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/plot_api/container_array_match.js b/src/plot_api/container_array_match.js index 56abed71158..45e6192d01c 100644 --- a/src/plot_api/container_array_match.js +++ b/src/plot_api/container_array_match.js @@ -9,8 +9,7 @@ 'use strict'; -var rootContainers = require('../registry').layoutArrayContainers; -var regexpContainers = require('../registry').layoutArrayRegexes; +var Registry = require('../registry'); /* * containerArrayMatch: does this attribute string point into a @@ -26,6 +25,8 @@ var regexpContainers = require('../registry').layoutArrayRegexes; * or the whole object) */ module.exports = function containerArrayMatch(astr) { + var rootContainers = Registry.layoutArrayContainers; + var regexpContainers = Registry.layoutArrayRegexes; var rootPart = astr.split('[')[0]; var arrayStr; var match; diff --git a/src/plot_api/edit_types.js b/src/plot_api/edit_types.js index 4b78ab15f23..73972c449c6 100644 --- a/src/plot_api/edit_types.js +++ b/src/plot_api/edit_types.js @@ -8,8 +8,9 @@ 'use strict'; -var extendFlat = require('../lib').extendFlat; -var isPlainObject = require('../lib').isPlainObject; +var Lib = require('../lib'); +var extendFlat = Lib.extendFlat; +var isPlainObject = Lib.isPlainObject; var traceOpts = { valType: 'flaglist', diff --git a/src/plot_api/helpers.js b/src/plot_api/helpers.js index d910d41e8a0..72fb27472d4 100644 --- a/src/plot_api/helpers.js +++ b/src/plot_api/helpers.js @@ -12,15 +12,15 @@ var isNumeric = require('fast-isnumeric'); var m4FromQuat = require('gl-mat4/fromQuat'); +var Registry = require('../registry'); var Lib = require('../lib'); -var subplotsRegistry = require('../plots/plots').subplotsRegistry; +var Plots = require('../plots/plots'); +var AxisIds = require('../plots/cartesian/axis_ids'); var Color = require('../components/color'); -var cleanId = require('../plots/cartesian/axis_ids').cleanId; -var getFromTrace = require('../plots/cartesian/axis_ids').getFromTrace; - -var traceIs = require('../registry').traceIs; -var getModule = require('../registry').getModule; +var cleanId = AxisIds.cleanId; +var getFromTrace = AxisIds.getFromTrace; +var traceIs = Registry.traceIs; // clear the promise queue if one of them got rejected exports.clearPromiseQueue = function(gd) { @@ -53,10 +53,10 @@ exports.cleanLayout = function(layout) { delete layout.scene1; } - var axisAttrRegex = (subplotsRegistry.cartesian || {}).attrRegex; - var polarAttrRegex = (subplotsRegistry.polar || {}).attrRegex; - var ternaryAttrRegex = (subplotsRegistry.ternary || {}).attrRegex; - var sceneAttrRegex = (subplotsRegistry.gl3d || {}).attrRegex; + var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex; + var polarAttrRegex = (Plots.subplotsRegistry.polar || {}).attrRegex; + var ternaryAttrRegex = (Plots.subplotsRegistry.ternary || {}).attrRegex; + var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex; var keys = Object.keys(layout); for(i = 0; i < keys.length; i++) { @@ -325,7 +325,7 @@ exports.cleanData = function(data) { // scene ids scene1 -> scene if(traceIs(trace, 'gl3d') && trace.scene) { - trace.scene = subplotsRegistry.gl3d.cleanId(trace.scene); + trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene); } if(!traceIs(trace, 'pie') && !traceIs(trace, 'bar') && trace.type !== 'waterfall') { @@ -339,7 +339,7 @@ exports.cleanData = function(data) { } // fix typo in colorscale definition - var _module = getModule(trace); + var _module = Registry.getModule(trace); if(_module && _module.colorbar) { var containerName = _module.colorbar.container; var container = containerName ? trace[containerName] : trace; diff --git a/src/plot_api/manage_arrays.js b/src/plot_api/manage_arrays.js index fc3caaa98e3..3bea13ca6a7 100644 --- a/src/plot_api/manage_arrays.js +++ b/src/plot_api/manage_arrays.js @@ -13,7 +13,7 @@ var isPlainObject = require('../lib/is_plain_object'); var noop = require('../lib/noop'); var Loggers = require('../lib/loggers'); var sorterAsc = require('../lib/search').sorterAsc; -var getComponentMethod = require('../registry').getComponentMethod; +var Registry = require('../registry'); exports.containerArrayMatch = require('./container_array_match'); @@ -75,9 +75,9 @@ var isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) { */ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags, _nestedProperty) { var componentType = np.astr; - var supplyComponentDefaults = getComponentMethod(componentType, 'supplyLayoutDefaults'); - var draw = getComponentMethod(componentType, 'draw'); - var drawOne = getComponentMethod(componentType, 'drawOne'); + var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults'); + var draw = Registry.getComponentMethod(componentType, 'draw'); + var drawOne = Registry.getComponentMethod(componentType, 'drawOne'); var replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || (draw === noop); var layout = gd.layout; var fullLayout = gd._fullLayout; diff --git a/src/plot_api/template_api.js b/src/plot_api/template_api.js index 3f005ce78ef..7f9aaddc977 100644 --- a/src/plot_api/template_api.js +++ b/src/plot_api/template_api.js @@ -10,18 +10,13 @@ 'use strict'; var Lib = require('../lib'); +var isPlainObject = Lib.isPlainObject; var PlotSchema = require('./plot_schema'); -var supplyDefaults = require('../plots/plots').supplyDefaults; +var Plots = require('../plots/plots'); var plotAttributes = require('../plots/attributes'); var Template = require('./plot_template'); var dfltConfig = require('./plot_config').dfltConfig; -var coerce = Lib.coerce; -var extendDeep = Lib.extendDeep; -var getGraphDiv = Lib.getGraphDiv; -var isPlainObject = Lib.isPlainObject; -var nestedProperty = Lib.nestedProperty; - /** * Plotly.makeTemplate: create a template off an existing figure to reuse * style attributes on other figures. @@ -36,9 +31,9 @@ var nestedProperty = Lib.nestedProperty; * `layout.template` in another figure. */ exports.makeTemplate = function(figure) { - figure = isPlainObject(figure) ? figure : getGraphDiv(figure); - figure = extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout}); - supplyDefaults(figure); + figure = Lib.isPlainObject(figure) ? figure : Lib.getGraphDiv(figure); + figure = Lib.extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout}); + Plots.supplyDefaults(figure); var data = figure.data || []; var layout = figure.layout || {}; // copy over a few items to help follow the schema @@ -69,7 +64,7 @@ exports.makeTemplate = function(figure) { var traceTemplate = {}; walkStyleKeys(trace, traceTemplate, getTraceInfo.bind(null, trace)); - var traceType = coerce(trace, {}, plotAttributes, 'type'); + var traceType = Lib.coerce(trace, {}, plotAttributes, 'type'); var typeTemplates = template.data[traceType]; if(!typeTemplates) typeTemplates = template.data[traceType] = []; typeTemplates.push(traceTemplate); @@ -110,13 +105,13 @@ exports.makeTemplate = function(figure) { mergeTemplates(oldTypeTemplates[i % oldTypeLen], typeTemplates[i]); } for(i = typeLen; i < oldTypeLen; i++) { - typeTemplates.push(extendDeep({}, oldTypeTemplates[i])); + typeTemplates.push(Lib.extendDeep({}, oldTypeTemplates[i])); } } } for(traceType in oldDataTemplate) { if(!(traceType in template.data)) { - template.data[traceType] = extendDeep([], oldDataTemplate[traceType]); + template.data[traceType] = Lib.extendDeep([], oldDataTemplate[traceType]); } } } @@ -128,7 +123,7 @@ exports.makeTemplate = function(figure) { function mergeTemplates(oldTemplate, newTemplate) { // we don't care about speed here, just make sure we have a totally // distinct object from the previous template - oldTemplate = extendDeep({}, oldTemplate); + oldTemplate = Lib.extendDeep({}, oldTemplate); // sort keys so we always get annotationdefaults before annotations etc // so arrayTemplater will work right @@ -234,8 +229,8 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { var pathInArray = getNextPath(child, namedIndex, nextPath); walkStyleKeys(item, templateOut, getAttributeInfo, pathInArray, getNextPath(child, namedIndex, nextBasePath)); - var itemPropInArray = nestedProperty(templateOut, pathInArray); - var dfltProp = nestedProperty(templateOut, dfltPath); + var itemPropInArray = Lib.nestedProperty(templateOut, pathInArray); + var dfltProp = Lib.nestedProperty(templateOut, dfltPath); dfltProp.set(itemPropInArray.get()); itemPropInArray.set(null); @@ -244,7 +239,7 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { } } } else { - var templateProp = nestedProperty(templateOut, nextPath); + var templateProp = Lib.nestedProperty(templateOut, nextPath); templateProp.set(child); } } @@ -252,13 +247,13 @@ function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) { function getLayoutInfo(layout, path) { return PlotSchema.getLayoutValObject( - layout, nestedProperty({}, path).parts + layout, Lib.nestedProperty({}, path).parts ); } function getTraceInfo(trace, path) { return PlotSchema.getTraceValObject( - trace, nestedProperty({}, path).parts + trace, Lib.nestedProperty({}, path).parts ); } @@ -290,7 +285,7 @@ function getNextPath(parent, key, path) { * a full readable description of the issue. */ exports.validateTemplate = function(figureIn, template) { - var figure = extendDeep({}, { + var figure = Lib.extendDeep({}, { _context: dfltConfig, data: figureIn.data, layout: figureIn.layout @@ -303,7 +298,7 @@ exports.validateTemplate = function(figureIn, template) { figure.layout = layout; figure.layout.template = template; - supplyDefaults(figure); + Plots.supplyDefaults(figure); var fullLayout = figure._fullLayout; var fullData = figure._fullData; diff --git a/src/plot_api/to_image.js b/src/plot_api/to_image.js index 4bda66ec4b7..c1a8c8733e1 100644 --- a/src/plot_api/to_image.js +++ b/src/plot_api/to_image.js @@ -10,8 +10,7 @@ var isNumeric = require('fast-isnumeric'); -var plot = require('./plot_api').plot; -var purge = require('./plot_api').purge; +var plotApi = require('./plot_api'); var Lib = require('../lib'); var helpers = require('../snapshot/helpers'); @@ -173,7 +172,7 @@ function toImage(gd, opts) { var width = clonedGd._fullLayout.width; var height = clonedGd._fullLayout.height; - purge(clonedGd); + plotApi.purge(clonedGd); document.body.removeChild(clonedGd); if(format === 'svg') { @@ -214,7 +213,7 @@ function toImage(gd, opts) { } return new Promise(function(resolve, reject) { - plot(clonedGd, data, layoutImage, configImage) + plotApi.plot(clonedGd, data, layoutImage, configImage) .then(redrawFunc) .then(wait) .then(convert)