Skip to content

Commit 7b45928

Browse files
committed
reduce plot_api imports
1 parent adf9bee commit 7b45928

File tree

7 files changed

+57
-50
lines changed

7 files changed

+57
-50
lines changed

src/plot_api/container_array_match.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
'use strict';
1111

12-
var Registry = require('../registry');
12+
var rootContainers = require('../registry').layoutArrayContainers;
13+
var regexpContainers = require('../registry').layoutArrayRegexes;
1314

1415
/*
1516
* containerArrayMatch: does this attribute string point into a
@@ -25,8 +26,6 @@ var Registry = require('../registry');
2526
* or the whole object)
2627
*/
2728
module.exports = function containerArrayMatch(astr) {
28-
var rootContainers = Registry.layoutArrayContainers;
29-
var regexpContainers = Registry.layoutArrayRegexes;
3029
var rootPart = astr.split('[')[0];
3130
var arrayStr;
3231
var match;

src/plot_api/edit_types.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
'use strict';
1010

11-
var Lib = require('../lib');
12-
var extendFlat = Lib.extendFlat;
13-
var isPlainObject = Lib.isPlainObject;
11+
var extendFlat = require('../lib').extendFlat;
12+
var isPlainObject = require('../lib').isPlainObject;
1413

1514
var traceOpts = {
1615
valType: 'flaglist',

src/plot_api/helpers.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
var isNumeric = require('fast-isnumeric');
1313
var m4FromQuat = require('gl-mat4/fromQuat');
1414

15-
var Registry = require('../registry');
1615
var Lib = require('../lib');
17-
var Plots = require('../plots/plots');
18-
var AxisIds = require('../plots/cartesian/axis_ids');
16+
var subplotsRegistry = require('../plots/plots').subplotsRegistry;
1917
var Color = require('../components/color');
2018

21-
var cleanId = AxisIds.cleanId;
22-
var getFromTrace = AxisIds.getFromTrace;
23-
var traceIs = Registry.traceIs;
19+
var cleanId = require('../plots/cartesian/axis_ids').cleanId;
20+
var getFromTrace = require('../plots/cartesian/axis_ids').getFromTrace;
21+
22+
var traceIs = require('../registry').traceIs;
23+
var getModule = require('../registry').getModule;
2424

2525
// clear the promise queue if one of them got rejected
2626
exports.clearPromiseQueue = function(gd) {
@@ -53,10 +53,10 @@ exports.cleanLayout = function(layout) {
5353
delete layout.scene1;
5454
}
5555

56-
var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex;
57-
var polarAttrRegex = (Plots.subplotsRegistry.polar || {}).attrRegex;
58-
var ternaryAttrRegex = (Plots.subplotsRegistry.ternary || {}).attrRegex;
59-
var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex;
56+
var axisAttrRegex = (subplotsRegistry.cartesian || {}).attrRegex;
57+
var polarAttrRegex = (subplotsRegistry.polar || {}).attrRegex;
58+
var ternaryAttrRegex = (subplotsRegistry.ternary || {}).attrRegex;
59+
var sceneAttrRegex = (subplotsRegistry.gl3d || {}).attrRegex;
6060

6161
var keys = Object.keys(layout);
6262
for(i = 0; i < keys.length; i++) {
@@ -325,7 +325,7 @@ exports.cleanData = function(data) {
325325

326326
// scene ids scene1 -> scene
327327
if(traceIs(trace, 'gl3d') && trace.scene) {
328-
trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene);
328+
trace.scene = subplotsRegistry.gl3d.cleanId(trace.scene);
329329
}
330330

331331
if(!traceIs(trace, 'pie') && !traceIs(trace, 'bar') && trace.type !== 'waterfall') {
@@ -339,7 +339,7 @@ exports.cleanData = function(data) {
339339
}
340340

341341
// fix typo in colorscale definition
342-
var _module = Registry.getModule(trace);
342+
var _module = getModule(trace);
343343
if(_module && _module.colorbar) {
344344
var containerName = _module.colorbar.container;
345345
var container = containerName ? trace[containerName] : trace;

src/plot_api/manage_arrays.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var isPlainObject = require('../lib/is_plain_object');
1313
var noop = require('../lib/noop');
1414
var Loggers = require('../lib/loggers');
1515
var sorterAsc = require('../lib/search').sorterAsc;
16-
var Registry = require('../registry');
16+
var getComponentMethod = require('../registry').getComponentMethod;
1717

1818

1919
exports.containerArrayMatch = require('./container_array_match');
@@ -75,9 +75,9 @@ var isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) {
7575
*/
7676
exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags, _nestedProperty) {
7777
var componentType = np.astr;
78-
var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults');
79-
var draw = Registry.getComponentMethod(componentType, 'draw');
80-
var drawOne = Registry.getComponentMethod(componentType, 'drawOne');
78+
var supplyComponentDefaults = getComponentMethod(componentType, 'supplyLayoutDefaults');
79+
var draw = getComponentMethod(componentType, 'draw');
80+
var drawOne = getComponentMethod(componentType, 'drawOne');
8181
var replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || (draw === noop);
8282
var layout = gd.layout;
8383
var fullLayout = gd._fullLayout;

src/plot_api/plot_schema.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var editTypes = require('./edit_types');
2727
var extendFlat = Lib.extendFlat;
2828
var extendDeepAll = Lib.extendDeepAll;
2929
var isPlainObject = Lib.isPlainObject;
30+
var isArrayOrTypedArray = Lib.isArrayOrTypedArray;
31+
var nestedProperty = Lib.nestedProperty;
32+
var valObjectMeta = Lib.valObjectMeta;
3033

3134
var IS_SUBPLOT_OBJ = '_isSubplotObj';
3235
var IS_LINKED_TO_ARRAY = '_isLinkedToArray';
@@ -65,7 +68,7 @@ exports.get = function() {
6568

6669
return {
6770
defs: {
68-
valObjects: Lib.valObjectMeta,
71+
valObjects: valObjectMeta,
6972
metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']),
7073
editType: {
7174
traces: editTypes.traces,
@@ -204,19 +207,19 @@ exports.findArrayAttributes = function(trace) {
204207
var item = container[stack[i]];
205208
var newAstrPartial = astrPartial + stack[i];
206209
if(i === stack.length - 1) {
207-
if(Lib.isArrayOrTypedArray(item)) {
210+
if(isArrayOrTypedArray(item)) {
208211
arrayAttributes.push(baseAttrName + newAstrPartial);
209212
}
210213
} else {
211214
if(isArrayStack[i]) {
212215
if(Array.isArray(item)) {
213216
for(var j = 0; j < item.length; j++) {
214-
if(Lib.isPlainObject(item[j])) {
217+
if(isPlainObject(item[j])) {
215218
crawlIntoTrace(item[j], i + 1, newAstrPartial + '[' + j + '].');
216219
}
217220
}
218221
}
219-
} else if(Lib.isPlainObject(item)) {
222+
} else if(isPlainObject(item)) {
220223
crawlIntoTrace(item, i + 1, newAstrPartial + '.');
221224
}
222225
}
@@ -463,9 +466,9 @@ function getTraceAttributes(type) {
463466

464467
// prune global-level trace attributes that are already defined in a trace
465468
exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) {
466-
Lib.nestedProperty(copyBaseAttributes, fullAttrString).set(undefined);
469+
nestedProperty(copyBaseAttributes, fullAttrString).set(undefined);
467470
// Prune undefined attributes
468-
if(attr === undefined) Lib.nestedProperty(copyModuleAttributes, fullAttrString).set(undefined);
471+
if(attr === undefined) nestedProperty(copyModuleAttributes, fullAttrString).set(undefined);
469472
});
470473

471474
// base attributes (same for all trace types)
@@ -597,7 +600,7 @@ function getTransformAttributes(type) {
597600

598601
function getFramesAttributes() {
599602
var attrs = {
600-
frames: Lib.extendDeepAll({}, frameAttributes)
603+
frames: extendDeepAll({}, frameAttributes)
601604
};
602605

603606
formatAttributes(attrs);
@@ -699,15 +702,15 @@ function assignPolarLayoutAttrs(layoutAttributes) {
699702
}
700703

701704
function handleBasePlotModule(layoutAttributes, _module, astr) {
702-
var np = Lib.nestedProperty(layoutAttributes, astr);
705+
var np = nestedProperty(layoutAttributes, astr);
703706
var attrs = extendDeepAll({}, _module.layoutAttributes);
704707

705708
attrs[IS_SUBPLOT_OBJ] = true;
706709
np.set(attrs);
707710
}
708711

709712
function insertAttrs(baseAttrs, newAttrs, astr) {
710-
var np = Lib.nestedProperty(baseAttrs, astr);
713+
var np = nestedProperty(baseAttrs, astr);
711714

712715
np.set(extendDeepAll(np.get() || {}, newAttrs));
713716
}

src/plot_api/template_api.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
'use strict';
1111

1212
var Lib = require('../lib');
13-
var isPlainObject = Lib.isPlainObject;
1413
var PlotSchema = require('./plot_schema');
15-
var Plots = require('../plots/plots');
14+
var supplyDefaults = require('../plots/plots').supplyDefaults;
1615
var plotAttributes = require('../plots/attributes');
1716
var Template = require('./plot_template');
1817
var 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
*/
3338
exports.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) {
123128
function 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

248253
function getLayoutInfo(layout, path) {
249254
return PlotSchema.getLayoutValObject(
250-
layout, Lib.nestedProperty({}, path).parts
255+
layout, nestedProperty({}, path).parts
251256
);
252257
}
253258

254259
function 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
*/
287292
exports.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;

src/plot_api/to_image.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
var isNumeric = require('fast-isnumeric');
1212

13-
var plotApi = require('./plot_api');
13+
var plot = require('./plot_api').plot;
14+
var purge = require('./plot_api').purge;
1415
var Lib = require('../lib');
1516

1617
var helpers = require('../snapshot/helpers');
@@ -172,7 +173,7 @@ function toImage(gd, opts) {
172173
var width = clonedGd._fullLayout.width;
173174
var height = clonedGd._fullLayout.height;
174175

175-
plotApi.purge(clonedGd);
176+
purge(clonedGd);
176177
document.body.removeChild(clonedGd);
177178

178179
if(format === 'svg') {
@@ -213,7 +214,7 @@ function toImage(gd, opts) {
213214
}
214215

215216
return new Promise(function(resolve, reject) {
216-
plotApi.plot(clonedGd, data, layoutImage, configImage)
217+
plot(clonedGd, data, layoutImage, configImage)
217218
.then(redrawFunc)
218219
.then(wait)
219220
.then(convert)

0 commit comments

Comments
 (0)