Skip to content

Internal Plotly cleanup #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 61 additions & 59 deletions src/components/annotations/index.js

Large diffs are not rendered by default.

57 changes: 30 additions & 27 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@

'use strict';

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

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var Color = require('../color');
var Drawing = require('../drawing');


var shapes = module.exports = {};

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

function coerce(attr, dflt) {
return Plotly.Lib.coerce(shapeIn, shapeOut,
shapes.layoutAttributes,
attr, dflt);
return Lib.coerce(shapeIn, shapeOut, shapes.layoutAttributes, attr, dflt);
}

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

// xref, yref
var axRef = Plotly.Axes.coerceRef(shapeIn, shapeOut, tdMock, axLetter);
var axRef = Axes.coerceRef(shapeIn, shapeOut, tdMock, axLetter);

if(shapeType !== 'path') {
var dflt0 = 0.25,
dflt1 = 0.75;
if(axRef !== 'paper') {
var ax = Plotly.Axes.getFromId(tdMock, axRef),
var ax = Axes.getFromId(tdMock, axRef),
convertFn = linearToData(ax);
dflt0 = convertFn(ax.range[0] + dflt0 * (ax.range[1] - ax.range[0]));
dflt1 = convertFn(ax.range[0] + dflt1 * (ax.range[1] - ax.range[0]));
Expand All @@ -69,7 +73,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
if(shapeType === 'path') {
coerce('path');
} else {
Plotly.Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
}

return shapeOut;
Expand Down Expand Up @@ -140,7 +144,7 @@ shapes.draw = function(gd, index, opt, value) {
deleteShape(gd, index);
return;
}
else if(value==='add' || Plotly.Lib.isPlainObject(value)) {
else if(value==='add' || Lib.isPlainObject(value)) {
insertShape(gd, index, value);
}
}
Expand Down Expand Up @@ -187,8 +191,8 @@ function deleteShape(gd, index) {
function insertShape(gd, index, newShape) {
gd._fullLayout.shapes.splice(index, 0, {});

var rule = Plotly.Lib.isPlainObject(newShape) ?
Plotly.Lib.extendFlat({}, newShape) :
var rule = Lib.isPlainObject(newShape) ?
Lib.extendFlat({}, newShape) :
{text: 'New text'};

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

var optionKeys = Object.keys(optionsEdit);
for(i = 0; i < optionsEdit.length; i++) {
var k = optionKeys[i];
Plotly.Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
}

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

var axLetter = posAttr.charAt(0),
axOld = Plotly.Axes.getFromId(gd,
Plotly.Axes.coerceRef(oldRef, {}, gd, axLetter)),
axNew = Plotly.Axes.getFromId(gd,
Plotly.Axes.coerceRef(optionsIn, {}, gd, axLetter)),
axOld = Axes.getFromId(gd,
Axes.coerceRef(oldRef, {}, gd, axLetter)),
axNew = Axes.getFromId(gd,
Axes.coerceRef(optionsIn, {}, gd, axLetter)),
position = optionsIn[posAttr],
linearizedPosition;

Expand Down Expand Up @@ -295,13 +299,12 @@ function updateShape(gd, index, opt, value) {
var path = gd._fullLayout._shapelayer.append('path')
.attr(attrs)
.style('opacity', options.opacity)
.call(Plotly.Color.stroke, lineColor)
.call(Plotly.Color.fill, options.fillcolor)
.call(Plotly.Drawing.dashLine, options.line.dash, options.line.width);
.call(Color.stroke, lineColor)
.call(Color.fill, options.fillcolor)
.call(Drawing.dashLine, options.line.dash, options.line.width);

if(clipAxes) {
path.call(Plotly.Drawing.setClipUrl,
'clip' + gd._fullLayout._uid + clipAxes);
path.call(Drawing.setClipUrl, 'clip' + gd._fullLayout._uid + clipAxes);
}
}

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

function shapePath(gd, options) {
var type = options.type,
xa = Plotly.Axes.getFromId(gd, options.xref),
ya = Plotly.Axes.getFromId(gd, options.yref),
xa = Axes.getFromId(gd, options.xref),
ya = Axes.getFromId(gd, options.yref),
gs = gd._fullLayout._size,
x2l,
x2p,
Expand Down Expand Up @@ -450,14 +453,14 @@ shapes.calcAutorange = function(gd) {
shape = shapeList[i];
ppad = shape.line.width / 2;
if(shape.xref !== 'paper') {
ax = Plotly.Axes.getFromId(gd, shape.xref);
ax = Axes.getFromId(gd, shape.xref);
bounds = shapeBounds(ax, shape.x0, shape.x1, shape.path, paramIsX);
if(bounds) Plotly.Axes.expand(ax, bounds, {ppad: ppad});
if(bounds) Axes.expand(ax, bounds, {ppad: ppad});
}
if(shape.yref !== 'paper') {
ax = Plotly.Axes.getFromId(gd, shape.yref);
ax = Axes.getFromId(gd, shape.yref);
bounds = shapeBounds(ax, shape.y0, shape.y1, shape.path, paramIsY);
if(bounds) Plotly.Axes.expand(ax, bounds, {ppad: ppad});
if(bounds) Axes.expand(ax, bounds, {ppad: ppad});
}
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

'use strict';

var Plotly = require('../plotly');
var tinycolor = require('tinycolor2');
var isNumeric = require('fast-isnumeric');
var str2RgbaArray = require('./str2rgbarray');

var makeScaleFunction = require('../components/colorscale/make_scale_function');
var colorDflt = require('../components/color/attributes').defaultLine;

var str2RgbaArray = require('./str2rgbarray');

var opacityDflt = 1;

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

if(containerIn.colorscale !== undefined) {
sclFunc = Plotly.Colorscale.makeScaleFunction(
sclFunc = makeScaleFunction(
containerIn.colorscale, containerIn.cmin, containerIn.cmax
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/show_no_webgl_msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var Plotly = require('../plotly');
var Color = require('../components/color');

var noop = function() {};

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

scene.container.appendChild(div);
scene.container.style.background = '#FFFFFF';
Expand Down
3 changes: 2 additions & 1 deletion src/plot_api/set_plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

var Plotly = require('../plotly');
var Lib = require('../lib');

/**
* Extends the plot config
Expand All @@ -19,5 +20,5 @@ var Plotly = require('../plotly');
*
*/
module.exports = function setPlotConfig(configObj) {
return Plotly.Lib.extendFlat(Plotly.defaultConfig, configObj);
return Lib.extendFlat(Plotly.defaultConfig, configObj);
};
Loading