Skip to content

Commit bc0ae2c

Browse files
committed
only refactor plot_schema and revert commit 7b45928.
1 parent 7b45928 commit bc0ae2c

File tree

6 files changed

+41
-45
lines changed

6 files changed

+41
-45
lines changed

src/plot_api/container_array_match.js

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

1010
'use strict';
1111

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

1514
/*
1615
* containerArrayMatch: does this attribute string point into a
@@ -26,6 +25,8 @@ var regexpContainers = require('../registry').layoutArrayRegexes;
2625
* or the whole object)
2726
*/
2827
module.exports = function containerArrayMatch(astr) {
28+
var rootContainers = Registry.layoutArrayContainers;
29+
var regexpContainers = Registry.layoutArrayRegexes;
2930
var rootPart = astr.split('[')[0];
3031
var arrayStr;
3132
var match;

src/plot_api/edit_types.js

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

99
'use strict';
1010

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

1415
var traceOpts = {
1516
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');
1516
var Lib = require('../lib');
16-
var subplotsRegistry = require('../plots/plots').subplotsRegistry;
17+
var Plots = require('../plots/plots');
18+
var AxisIds = require('../plots/cartesian/axis_ids');
1719
var Color = require('../components/color');
1820

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;
21+
var cleanId = AxisIds.cleanId;
22+
var getFromTrace = AxisIds.getFromTrace;
23+
var traceIs = Registry.traceIs;
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 = (subplotsRegistry.cartesian || {}).attrRegex;
57-
var polarAttrRegex = (subplotsRegistry.polar || {}).attrRegex;
58-
var ternaryAttrRegex = (subplotsRegistry.ternary || {}).attrRegex;
59-
var sceneAttrRegex = (subplotsRegistry.gl3d || {}).attrRegex;
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;
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 = subplotsRegistry.gl3d.cleanId(trace.scene);
328+
trace.scene = Plots.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 = getModule(trace);
342+
var _module = Registry.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 getComponentMethod = require('../registry').getComponentMethod;
16+
var Registry = require('../registry');
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 = getComponentMethod(componentType, 'supplyLayoutDefaults');
79-
var draw = getComponentMethod(componentType, 'draw');
80-
var drawOne = getComponentMethod(componentType, 'drawOne');
78+
var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults');
79+
var draw = Registry.getComponentMethod(componentType, 'draw');
80+
var drawOne = Registry.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/template_api.js

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

1212
var Lib = require('../lib');
13+
var isPlainObject = Lib.isPlainObject;
1314
var PlotSchema = require('./plot_schema');
14-
var supplyDefaults = require('../plots/plots').supplyDefaults;
15+
var Plots = require('../plots/plots');
1516
var plotAttributes = require('../plots/attributes');
1617
var Template = require('./plot_template');
1718
var 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
*/
3833
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);
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) {
128123
function 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

253248
function getLayoutInfo(layout, path) {
254249
return PlotSchema.getLayoutValObject(
255-
layout, nestedProperty({}, path).parts
250+
layout, Lib.nestedProperty({}, path).parts
256251
);
257252
}
258253

259254
function 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
*/
292287
exports.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;

src/plot_api/to_image.js

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

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

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

1716
var helpers = require('../snapshot/helpers');
@@ -173,7 +172,7 @@ function toImage(gd, opts) {
173172
var width = clonedGd._fullLayout.width;
174173
var height = clonedGd._fullLayout.height;
175174

176-
purge(clonedGd);
175+
plotApi.purge(clonedGd);
177176
document.body.removeChild(clonedGd);
178177

179178
if(format === 'svg') {
@@ -214,7 +213,7 @@ function toImage(gd, opts) {
214213
}
215214

216215
return new Promise(function(resolve, reject) {
217-
plot(clonedGd, data, layoutImage, configImage)
216+
plotApi.plot(clonedGd, data, layoutImage, configImage)
218217
.then(redrawFunc)
219218
.then(wait)
220219
.then(convert)

0 commit comments

Comments
 (0)