Skip to content

Commit 7d7e948

Browse files
committed
Merge pull request #436 from plotly/rm-some-internal-plotly
Internal Plotly cleanup
2 parents 02e39a9 + feffccf commit 7d7e948

File tree

11 files changed

+212
-189
lines changed

11 files changed

+212
-189
lines changed

src/components/annotations/index.js

+61-59
Large diffs are not rendered by default.

src/components/shapes/index.js

+30-27
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
1312
var isNumeric = require('fast-isnumeric');
1413

14+
var Plotly = require('../../plotly');
15+
var Lib = require('../../lib');
16+
var Axes = require('../../plots/cartesian/axes');
17+
var Color = require('../color');
18+
var Drawing = require('../drawing');
19+
20+
1521
var shapes = module.exports = {};
1622

1723
shapes.layoutAttributes = require('./attributes');
@@ -29,9 +35,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
2935
var shapeOut = {};
3036

3137
function coerce(attr, dflt) {
32-
return Plotly.Lib.coerce(shapeIn, shapeOut,
33-
shapes.layoutAttributes,
34-
attr, dflt);
38+
return Lib.coerce(shapeIn, shapeOut, shapes.layoutAttributes, attr, dflt);
3539
}
3640

3741
coerce('opacity');
@@ -49,13 +53,13 @@ function handleShapeDefaults(shapeIn, fullLayout) {
4953
tdMock = {_fullLayout: fullLayout};
5054

5155
// xref, yref
52-
var axRef = Plotly.Axes.coerceRef(shapeIn, shapeOut, tdMock, axLetter);
56+
var axRef = Axes.coerceRef(shapeIn, shapeOut, tdMock, axLetter);
5357

5458
if(shapeType !== 'path') {
5559
var dflt0 = 0.25,
5660
dflt1 = 0.75;
5761
if(axRef !== 'paper') {
58-
var ax = Plotly.Axes.getFromId(tdMock, axRef),
62+
var ax = Axes.getFromId(tdMock, axRef),
5963
convertFn = linearToData(ax);
6064
dflt0 = convertFn(ax.range[0] + dflt0 * (ax.range[1] - ax.range[0]));
6165
dflt1 = convertFn(ax.range[0] + dflt1 * (ax.range[1] - ax.range[0]));
@@ -69,7 +73,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
6973
if(shapeType === 'path') {
7074
coerce('path');
7175
} else {
72-
Plotly.Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
76+
Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
7377
}
7478

7579
return shapeOut;
@@ -140,7 +144,7 @@ shapes.draw = function(gd, index, opt, value) {
140144
deleteShape(gd, index);
141145
return;
142146
}
143-
else if(value==='add' || Plotly.Lib.isPlainObject(value)) {
147+
else if(value==='add' || Lib.isPlainObject(value)) {
144148
insertShape(gd, index, value);
145149
}
146150
}
@@ -187,8 +191,8 @@ function deleteShape(gd, index) {
187191
function insertShape(gd, index, newShape) {
188192
gd._fullLayout.shapes.splice(index, 0, {});
189193

190-
var rule = Plotly.Lib.isPlainObject(newShape) ?
191-
Plotly.Lib.extendFlat({}, newShape) :
194+
var rule = Lib.isPlainObject(newShape) ?
195+
Lib.extendFlat({}, newShape) :
192196
{text: 'New text'};
193197

194198
if(gd.layout.shapes) {
@@ -225,12 +229,12 @@ function updateShape(gd, index, opt, value) {
225229
// alter the input shape as requested
226230
var optionsEdit = {};
227231
if(typeof opt === 'string' && opt) optionsEdit[opt] = value;
228-
else if(Plotly.Lib.isPlainObject(opt)) optionsEdit = opt;
232+
else if(Lib.isPlainObject(opt)) optionsEdit = opt;
229233

230234
var optionKeys = Object.keys(optionsEdit);
231235
for(i = 0; i < optionsEdit.length; i++) {
232236
var k = optionKeys[i];
233-
Plotly.Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
237+
Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
234238
}
235239

236240
var posAttrs = ['x0', 'x1', 'y0', 'y1'];
@@ -247,10 +251,10 @@ function updateShape(gd, index, opt, value) {
247251
}
248252

249253
var axLetter = posAttr.charAt(0),
250-
axOld = Plotly.Axes.getFromId(gd,
251-
Plotly.Axes.coerceRef(oldRef, {}, gd, axLetter)),
252-
axNew = Plotly.Axes.getFromId(gd,
253-
Plotly.Axes.coerceRef(optionsIn, {}, gd, axLetter)),
254+
axOld = Axes.getFromId(gd,
255+
Axes.coerceRef(oldRef, {}, gd, axLetter)),
256+
axNew = Axes.getFromId(gd,
257+
Axes.coerceRef(optionsIn, {}, gd, axLetter)),
254258
position = optionsIn[posAttr],
255259
linearizedPosition;
256260

@@ -295,13 +299,12 @@ function updateShape(gd, index, opt, value) {
295299
var path = gd._fullLayout._shapelayer.append('path')
296300
.attr(attrs)
297301
.style('opacity', options.opacity)
298-
.call(Plotly.Color.stroke, lineColor)
299-
.call(Plotly.Color.fill, options.fillcolor)
300-
.call(Plotly.Drawing.dashLine, options.line.dash, options.line.width);
302+
.call(Color.stroke, lineColor)
303+
.call(Color.fill, options.fillcolor)
304+
.call(Drawing.dashLine, options.line.dash, options.line.width);
301305

302306
if(clipAxes) {
303-
path.call(Plotly.Drawing.setClipUrl,
304-
'clip' + gd._fullLayout._uid + clipAxes);
307+
path.call(Drawing.setClipUrl, 'clip' + gd._fullLayout._uid + clipAxes);
305308
}
306309
}
307310

@@ -311,8 +314,8 @@ function decodeDate(convertToPx) {
311314

312315
function shapePath(gd, options) {
313316
var type = options.type,
314-
xa = Plotly.Axes.getFromId(gd, options.xref),
315-
ya = Plotly.Axes.getFromId(gd, options.yref),
317+
xa = Axes.getFromId(gd, options.xref),
318+
ya = Axes.getFromId(gd, options.yref),
316319
gs = gd._fullLayout._size,
317320
x2l,
318321
x2p,
@@ -450,14 +453,14 @@ shapes.calcAutorange = function(gd) {
450453
shape = shapeList[i];
451454
ppad = shape.line.width / 2;
452455
if(shape.xref !== 'paper') {
453-
ax = Plotly.Axes.getFromId(gd, shape.xref);
456+
ax = Axes.getFromId(gd, shape.xref);
454457
bounds = shapeBounds(ax, shape.x0, shape.x1, shape.path, paramIsX);
455-
if(bounds) Plotly.Axes.expand(ax, bounds, {ppad: ppad});
458+
if(bounds) Axes.expand(ax, bounds, {ppad: ppad});
456459
}
457460
if(shape.yref !== 'paper') {
458-
ax = Plotly.Axes.getFromId(gd, shape.yref);
461+
ax = Axes.getFromId(gd, shape.yref);
459462
bounds = shapeBounds(ax, shape.y0, shape.y1, shape.path, paramIsY);
460-
if(bounds) Plotly.Axes.expand(ax, bounds, {ppad: ppad});
463+
if(bounds) Axes.expand(ax, bounds, {ppad: ppad});
461464
}
462465
}
463466
};

src/lib/gl_format_color.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../plotly');
1312
var tinycolor = require('tinycolor2');
1413
var isNumeric = require('fast-isnumeric');
15-
var str2RgbaArray = require('./str2rgbarray');
1614

15+
var makeScaleFunction = require('../components/colorscale/make_scale_function');
1716
var colorDflt = require('../components/color/attributes').defaultLine;
17+
18+
var str2RgbaArray = require('./str2rgbarray');
19+
1820
var opacityDflt = 1;
1921

2022
function calculateColor(colorIn, opacityIn) {
@@ -40,7 +42,7 @@ function formatColor(containerIn, opacityIn, len) {
4042
var sclFunc, getColor, getOpacity, colori, opacityi;
4143

4244
if(containerIn.colorscale !== undefined) {
43-
sclFunc = Plotly.Colorscale.makeScaleFunction(
45+
sclFunc = makeScaleFunction(
4446
containerIn.colorscale, containerIn.cmin, containerIn.cmax
4547
);
4648
}

src/lib/show_no_webgl_msg.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../plotly');
12+
var Color = require('../components/color');
1313

1414
var noop = function() {};
1515

@@ -34,7 +34,7 @@ module.exports = function showWebGlMsg(scene) {
3434
div.textContent = 'Webgl is not supported by your browser - visit http://get.webgl.org for more info';
3535
div.style.cursor = 'pointer';
3636
div.style.fontSize = '24px';
37-
div.style.color = Plotly.Color.defaults[0];
37+
div.style.color = Color.defaults[0];
3838

3939
scene.container.appendChild(div);
4040
scene.container.style.background = '#FFFFFF';

src/plot_api/set_plot_config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var Plotly = require('../plotly');
13+
var Lib = require('../lib');
1314

1415
/**
1516
* Extends the plot config
@@ -19,5 +20,5 @@ var Plotly = require('../plotly');
1920
*
2021
*/
2122
module.exports = function setPlotConfig(configObj) {
22-
return Plotly.Lib.extendFlat(Plotly.defaultConfig, configObj);
23+
return Lib.extendFlat(Plotly.defaultConfig, configObj);
2324
};

0 commit comments

Comments
 (0)