diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js
index a2bac67b763..71ffcf1c10d 100644
--- a/src/components/annotations/index.js
+++ b/src/components/annotations/index.js
@@ -9,9 +9,15 @@
'use strict';
-var Plotly = require('../../plotly');
var d3 = require('d3');
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 svgTextUtils = require('../../lib/svg_text_utils');
var setCursor = require('../../lib/setcursor');
var dragElement = require('../dragelement');
@@ -34,20 +40,20 @@ function handleAnnotationDefaults(annIn, fullLayout) {
var annOut = {};
function coerce(attr, dflt) {
- return Plotly.Lib.coerce(annIn, annOut, annotations.layoutAttributes, attr, dflt);
+ return Lib.coerce(annIn, annOut, annotations.layoutAttributes, attr, dflt);
}
coerce('opacity');
coerce('align');
coerce('bgcolor');
var borderColor = coerce('bordercolor'),
- borderOpacity = Plotly.Color.opacity(borderColor);
+ borderOpacity = Color.opacity(borderColor);
coerce('borderpad');
var borderWidth = coerce('borderwidth');
var showArrow = coerce('showarrow');
if(showArrow) {
coerce('arrowcolor',
- borderOpacity ? annOut.bordercolor : Plotly.Color.defaultLine);
+ borderOpacity ? annOut.bordercolor : Color.defaultLine);
coerce('arrowhead');
coerce('arrowsize');
coerce('arrowwidth', ((borderOpacity && borderWidth) || 1) * 2);
@@ -55,11 +61,11 @@ function handleAnnotationDefaults(annIn, fullLayout) {
coerce('ay');
// if you have one part of arrow length you should have both
- Plotly.Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
+ Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
}
coerce('text', showArrow ? ' ' : 'new text');
coerce('textangle');
- Plotly.Lib.coerceFont(coerce, 'font', fullLayout.font);
+ Lib.coerceFont(coerce, 'font', fullLayout.font);
// positioning
var axLetters = ['x','y'];
@@ -68,12 +74,12 @@ function handleAnnotationDefaults(annIn, fullLayout) {
tdMock = {_fullLayout: fullLayout};
// xref, yref
- var axRef = Plotly.Axes.coerceRef(annIn, annOut, tdMock, axLetter);
+ var axRef = Axes.coerceRef(annIn, annOut, tdMock, axLetter);
// x, y
var defaultPosition = 0.5;
if(axRef!=='paper') {
- var ax = Plotly.Axes.getFromId(tdMock, axRef);
+ var ax = Axes.getFromId(tdMock, axRef);
defaultPosition = ax.range[0] + defaultPosition * (ax.range[1] - ax.range[0]);
// convert date or category strings to numbers
@@ -81,7 +87,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
typeof annIn[axLetter]==='string') {
var newval;
if(ax.type==='date') {
- newval = Plotly.Lib.dateTime2ms(annIn[axLetter]);
+ newval = Lib.dateTime2ms(annIn[axLetter]);
if(newval!==false) annIn[axLetter] = newval;
}
else if((ax._categories||[]).length) {
@@ -97,7 +103,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
}
// if you have one coordinate you should have both
- Plotly.Lib.noneOrAll(annIn, annOut, ['x', 'y']);
+ Lib.noneOrAll(annIn, annOut, ['x', 'y']);
return annOut;
}
@@ -181,11 +187,11 @@ annotations.draw = function(gd, index, opt, value) {
}
return;
}
- else if(value==='add' || Plotly.Lib.isPlainObject(value)) {
+ else if(value==='add' || Lib.isPlainObject(value)) {
fullLayout.annotations.splice(index,0,{});
- var rule = Plotly.Lib.isPlainObject(value) ?
- Plotly.Lib.extendFlat({}, value) :
+ var rule = Lib.isPlainObject(value) ?
+ Lib.extendFlat({}, value) :
{text: 'New text'};
if(layout.annotations) {
@@ -219,12 +225,12 @@ annotations.draw = function(gd, index, opt, value) {
// alter the input annotation 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 < optionKeys.length; i++) {
var k = optionKeys[i];
- Plotly.Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
+ Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
}
var gs = fullLayout._size;
@@ -242,10 +248,8 @@ annotations.draw = function(gd, index, opt, value) {
continue;
}
- var axOld = Plotly.Axes.getFromId(gd,
- Plotly.Axes.coerceRef(oldRef, {}, gd, axLetter)),
- axNew = Plotly.Axes.getFromId(gd,
- Plotly.Axes.coerceRef(optionsIn, {}, gd, axLetter)),
+ var axOld = Axes.getFromId(gd, Axes.coerceRef(oldRef, {}, gd, axLetter)),
+ axNew = Axes.getFromId(gd, Axes.coerceRef(optionsIn, {}, gd, axLetter)),
position = optionsIn[axLetter],
axTypeOld = oldPrivate['_' + axLetter + 'type'];
@@ -318,8 +322,8 @@ annotations.draw = function(gd, index, opt, value) {
var options = handleAnnotationDefaults(optionsIn, fullLayout);
fullLayout.annotations[index] = options;
- var xa = Plotly.Axes.getFromId(gd, options.xref),
- ya = Plotly.Axes.getFromId(gd, options.yref),
+ var xa = Axes.getFromId(gd, options.xref),
+ ya = Axes.getFromId(gd, options.yref),
annPosPx = {x: 0, y: 0},
textangle = +options.textangle || 0;
@@ -354,8 +358,8 @@ annotations.draw = function(gd, index, opt, value) {
var annbg = ann.append('rect')
.attr('class','bg')
.style('stroke-width', borderwidth+'px')
- .call(Plotly.Color.stroke, options.bordercolor)
- .call(Plotly.Color.fill, options.bgcolor);
+ .call(Color.stroke, options.bordercolor)
+ .call(Color.fill, options.bgcolor);
var font = options.font;
@@ -365,14 +369,15 @@ annotations.draw = function(gd, index, opt, value) {
.text(options.text);
function textLayout(s) {
- s.call(Plotly.Drawing.font, font)
+ s.call(Drawing.font, font)
.attr({
'text-anchor': {
left: 'start',
right: 'end'
}[options.align] || 'middle'
});
- Plotly.util.convertToTspans(s, drawGraphicalElements);
+
+ svgTextUtils.convertToTspans(s, drawGraphicalElements);
return s;
}
@@ -384,7 +389,7 @@ annotations.draw = function(gd, index, opt, value) {
var mathjaxGroup = ann.select('.annotation-math-group'),
hasMathjax = !mathjaxGroup.empty(),
- anntextBB = Plotly.Drawing.bBox(
+ anntextBB = Drawing.bBox(
(hasMathjax ? mathjaxGroup : anntext).node()),
annwidth = anntextBB.width,
annheight = anntextBB.height,
@@ -414,7 +419,7 @@ annotations.draw = function(gd, index, opt, value) {
var annotationIsOffscreen = false;
['x', 'y'].forEach(function(axLetter) {
- var ax = Plotly.Axes.getFromId(gd,
+ var ax = Axes.getFromId(gd,
options[axLetter+'ref']||axLetter),
dimAngle = (textangle + (axLetter==='x' ? 0 : 90)) * Math.PI/180,
annSize = outerwidth * Math.abs(Math.cos(dimAngle)) +
@@ -471,11 +476,11 @@ annotations.draw = function(gd, index, opt, value) {
// make sure the arrowhead (if there is one)
// and the annotation center are visible
if(options.showarrow) {
- arrowX = Plotly.Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1);
- arrowY = Plotly.Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1);
+ arrowX = Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1);
+ arrowY = Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1);
}
- annPosPx.x = Plotly.Lib.constrain(annPosPx.x, 1, fullLayout.width - 1);
- annPosPx.y = Plotly.Lib.constrain(annPosPx.y, 1, fullLayout.height - 1);
+ annPosPx.x = Lib.constrain(annPosPx.x, 1, fullLayout.width - 1);
+ annPosPx.y = Lib.constrain(annPosPx.y, 1, fullLayout.height - 1);
var texty = borderfull - anntextBB.top,
textx = borderfull - anntextBB.left;
@@ -488,7 +493,7 @@ annotations.draw = function(gd, index, opt, value) {
anntext.selectAll('tspan.line').attr({y: texty, x: textx});
}
- annbg.call(Plotly.Drawing.setRect, borderwidth / 2, borderwidth / 2,
+ annbg.call(Drawing.setRect, borderwidth / 2, borderwidth / 2,
outerwidth-borderwidth, outerheight - borderwidth);
var annX = Math.round(annPosPx.x - outerwidth / 2),
@@ -515,9 +520,9 @@ annotations.draw = function(gd, index, opt, value) {
// create transform matrix and related functions
transform =
- Plotly.Lib.rotationXYMatrix(textangle, arrowX0, arrowY0),
- applyTransform = Plotly.Lib.apply2DTransform(transform),
- applyTransform2 = Plotly.Lib.apply2DTransform2(transform),
+ Lib.rotationXYMatrix(textangle, arrowX0, arrowY0),
+ applyTransform = Lib.apply2DTransform(transform),
+ applyTransform2 = Lib.apply2DTransform2(transform),
// calculate and transform bounding box
xHalf = annbg.attr('width')/2,
@@ -555,15 +560,14 @@ annotations.draw = function(gd, index, opt, value) {
arrowColor = options.arrowcolor;
var arrowgroup = anngroup.append('g')
- .style({opacity: Plotly.Color.opacity(arrowColor)})
+ .style({opacity: Color.opacity(arrowColor)})
.classed('annotation-arrow-g', true)
.attr('data-index', String(index));
var arrow = arrowgroup.append('path')
.attr('d', 'M'+arrowX0+','+arrowY0+'L'+arrowX+','+arrowY)
.style('stroke-width', strokewidth+'px')
- .call(Plotly.Color.stroke,
- Plotly.Color.rgb(arrowColor));
+ .call(Color.stroke, Color.rgb(arrowColor));
annotations.arrowhead(arrow, options.arrowhead, 'end', options.arrowsize);
@@ -576,8 +580,8 @@ annotations.draw = function(gd, index, opt, value) {
transform: 'translate('+arrowX+','+arrowY+')'
})
.style('stroke-width', (strokewidth+6)+'px')
- .call(Plotly.Color.stroke, 'rgba(0,0,0,0)')
- .call(Plotly.Color.fill, 'rgba(0,0,0,0)');
+ .call(Color.stroke, 'rgba(0,0,0,0)')
+ .call(Color.fill, 'rgba(0,0,0,0)');
if(gd._context.editable) {
var update,
@@ -603,8 +607,7 @@ annotations.draw = function(gd, index, opt, value) {
var annxy0 = applyTransform(annx0, anny0),
xcenter = annxy0[0] + dx,
ycenter = annxy0[1] + dy;
- ann.call(Plotly.Drawing.setPosition,
- xcenter, ycenter);
+ ann.call(Drawing.setPosition, xcenter, ycenter);
update[annbase+'.x'] = xa ?
(options.x + dx / xa._m) :
@@ -632,9 +635,9 @@ annotations.draw = function(gd, index, opt, value) {
if(options.showarrow) drawArrow(0, 0);
// create transform matrix and related functions
- var transform = Plotly.Lib.rotationXYMatrix(textangle,
+ var transform = Lib.rotationXYMatrix(textangle,
annPosPx.x, annPosPx.y),
- applyTransform = Plotly.Lib.apply2DTransform(transform);
+ applyTransform = Lib.apply2DTransform(transform);
// user dragging the annotation (text, not arrow)
if(gd._context.editable) {
@@ -650,7 +653,7 @@ annotations.draw = function(gd, index, opt, value) {
update = {};
},
moveFn: function(dx, dy) {
- ann.call(Plotly.Drawing.setPosition, x0 + dx, y0 + dy);
+ ann.call(Drawing.setPosition, x0 + dx, y0 + dy);
var csr = 'pointer';
if(options.showarrow) {
update[annbase+'.ax'] = options.ax + dx;
@@ -688,7 +691,7 @@ annotations.draw = function(gd, index, opt, value) {
x1 = xy1[0] + dx,
y1 = xy1[1] + dy;
- ann.call(Plotly.Drawing.setPosition, x1, y1);
+ ann.call(Drawing.setPosition, x1, y1);
anng.attr({
transform: 'rotate(' + textangle + ',' +
@@ -710,7 +713,7 @@ annotations.draw = function(gd, index, opt, value) {
}
if(gd._context.editable) {
- anntext.call(Plotly.util.makeEditable, ann)
+ anntext.call(svgTextUtils.makeEditable, ann)
.call(textLayout)
.on('edit', function(_text) {
options.text = _text;
@@ -732,7 +735,7 @@ annotations.draw = function(gd, index, opt, value) {
// rotate and position text and background
anng.attr({transform: 'rotate(' + textangle + ',' +
annPosPx.x + ',' + annPosPx.y + ')'})
- .call(Plotly.Drawing.setPosition, annPosPx.x, annPosPx.y);
+ .call(Drawing.setPosition, annPosPx.x, annPosPx.y);
};
// add arrowhead(s) to a path or line d3 element el3
@@ -747,8 +750,8 @@ annotations.arrowhead = function(el3, style, ends, mag) {
if(typeof ends !== 'string' || !ends) ends = 'end';
- var scale = (Plotly.Drawing.getPx(el3,'stroke-width') || 1) * mag,
- stroke = el3.style('stroke') || Plotly.Color.defaultLine,
+ var scale = (Drawing.getPx(el3,'stroke-width') || 1) * mag,
+ stroke = el3.style('stroke') || Color.defaultLine,
opacity = el3.style('stroke-opacity') || 1,
doStart = ends.indexOf('start') >= 0,
doEnd = ends.indexOf('end') >= 0,
@@ -845,13 +848,12 @@ annotations.calcAutorange = function(gd) {
annotationAxes[ann.yref] = true;
});
- var autorangedAnnos = Plotly.Axes.list(gd)
- .filter(function(ax) {
- return ax.autorange && annotationAxes[ax._id];
- });
+ var autorangedAnnos = Axes.list(gd).filter(function(ax) {
+ return ax.autorange && annotationAxes[ax._id];
+ });
if(!autorangedAnnos.length) return;
- return Plotly.Lib.syncOrAsync([
+ return Lib.syncOrAsync([
annotations.drawAll,
annAutorange
], gd);
@@ -865,8 +867,8 @@ function annAutorange(gd) {
// use the arrow and the text bg rectangle,
// as the whole anno may include hidden text in its bbox
fullLayout.annotations.forEach(function(ann) {
- var xa = Plotly.Axes.getFromId(gd, ann.xref),
- ya = Plotly.Axes.getFromId(gd, ann.yref);
+ var xa = Axes.getFromId(gd, ann.xref),
+ ya = Axes.getFromId(gd, ann.yref);
if(!(xa || ya)) return;
var halfWidth = (ann._xsize || 0)/2,
@@ -885,13 +887,13 @@ function annAutorange(gd) {
bottomSize = Math.max(bottomSize, headSize);
}
if(xa && xa.autorange) {
- Plotly.Axes.expand(xa, [xa.l2c(ann.x)],{
+ Axes.expand(xa, [xa.l2c(ann.x)],{
ppadplus: rightSize,
ppadminus: leftSize
});
}
if(ya && ya.autorange) {
- Plotly.Axes.expand(ya, [ya.l2c(ann.y)], {
+ Axes.expand(ya, [ya.l2c(ann.y)], {
ppadplus: bottomSize,
ppadminus: topSize
});
diff --git a/src/components/shapes/index.js b/src/components/shapes/index.js
index fc6fe8a522a..0f02067b20f 100644
--- a/src/components/shapes/index.js
+++ b/src/components/shapes/index.js
@@ -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');
@@ -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');
@@ -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]));
@@ -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;
@@ -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);
}
}
@@ -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) {
@@ -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'];
@@ -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;
@@ -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);
}
}
@@ -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,
@@ -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});
}
}
};
diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js
index 075dcd6b2b7..50b765dd59b 100644
--- a/src/lib/gl_format_color.js
+++ b/src/lib/gl_format_color.js
@@ -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) {
@@ -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
);
}
diff --git a/src/lib/show_no_webgl_msg.js b/src/lib/show_no_webgl_msg.js
index 203b29e1932..0231f043d46 100644
--- a/src/lib/show_no_webgl_msg.js
+++ b/src/lib/show_no_webgl_msg.js
@@ -9,7 +9,7 @@
'use strict';
-var Plotly = require('../plotly');
+var Color = require('../components/color');
var noop = function() {};
@@ -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';
diff --git a/src/plot_api/set_plot_config.js b/src/plot_api/set_plot_config.js
index 0ed11496b62..02c98addce7 100644
--- a/src/plot_api/set_plot_config.js
+++ b/src/plot_api/set_plot_config.js
@@ -10,6 +10,7 @@
'use strict';
var Plotly = require('../plotly');
+var Lib = require('../lib');
/**
* Extends the plot config
@@ -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);
};
diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js
index 1cb336e09e7..d5610fca05b 100644
--- a/src/plots/cartesian/axes.js
+++ b/src/plots/cartesian/axes.js
@@ -13,7 +13,12 @@ var d3 = require('d3');
var isNumeric = require('fast-isnumeric');
var Plotly = require('../../plotly');
+var Lib = require('../../lib');
+var svgTextUtils = require('../../lib/svg_text_utils');
var Titles = require('../../components/titles');
+var Color = require('../../components/color');
+var Drawing = require('../../components/drawing');
+
var axes = module.exports = {};
@@ -47,7 +52,7 @@ axes.coerceRef = function(containerIn, containerOut, gd, axLetter) {
};
// xref, yref
- return Plotly.Lib.coerce(containerIn, containerOut, attrDef, refAttr);
+ return Lib.coerce(containerIn, containerOut, attrDef, refAttr);
};
// empty out types for all axes containing these traces
@@ -345,8 +350,8 @@ axes.expand = function(ax, data, options) {
};
axes.autoBin = function(data,ax,nbins,is2d) {
- var datamin = Plotly.Lib.aggNums(Math.min, null, data),
- datamax = Plotly.Lib.aggNums(Math.max, null, data);
+ var datamin = Lib.aggNums(Math.min, null, data),
+ datamax = Lib.aggNums(Math.max, null, data);
if(ax.type==='category') {
return {
start: datamin - 0.5,
@@ -362,13 +367,13 @@ axes.autoBin = function(data,ax,nbins,is2d) {
// somewhat taller than the total number of bins, but don't let
// the size get smaller than the 'nice' rounded down minimum
// difference between values
- var distinctData = Plotly.Lib.distinctVals(data),
+ var distinctData = Lib.distinctVals(data),
msexp = Math.pow(10, Math.floor(
Math.log(distinctData.minDiff) / Math.LN10)),
// TODO: there are some date cases where this will fail...
- minSize = msexp*Plotly.Lib.roundUp(
+ minSize = msexp * Lib.roundUp(
distinctData.minDiff/msexp, [0.9, 1.9, 4.9, 9.9], true);
- size0 = Math.max(minSize, 2*Plotly.Lib.stdev(data) /
+ size0 = Math.max(minSize, 2 * Lib.stdev(data) /
Math.pow(data.length, is2d ? 0.25 : 0.4));
}
@@ -469,7 +474,7 @@ axes.calcTicks = function calcTicks(ax) {
}
else {
minPx = ax._id.charAt(0) === 'y' ? 40 : 80;
- nt = Plotly.Lib.constrain(ax._length / minPx, 4, 9) + 1;
+ nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
}
}
axes.autoTicks(ax,Math.abs(ax.range[1]-ax.range[0])/nt);
@@ -564,7 +569,7 @@ var roundBase10 = [2, 5, 10],
roundLog2 = [-0.301, 0, 0.301, 0.699, 1];
function roundDTick(roughDTick, base, roundingSet) {
- return base * Plotly.Lib.roundUp(roughDTick / base, roundingSet);
+ return base * Lib.roundUp(roughDTick / base, roundingSet);
}
// autoTicks: calculate best guess at pleasant ticks for this axis
@@ -743,7 +748,7 @@ axes.tickIncrement = function(x, dtick, axrev) {
else if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
x2 = x + axSign * 0.01,
- frac = Plotly.Lib.roundUp(mod(x2, 1), tickset, axrev);
+ frac = Lib.roundUp(mod(x2, 1), tickset, axrev);
return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
@@ -765,7 +770,7 @@ axes.tickFirst = function(ax) {
// make sure no ticks outside the category list
if(ax.type === 'category') {
- tmin = Plotly.Lib.constrain(tmin, 0, ax._categories.length - 1);
+ tmin = Lib.constrain(tmin, 0, ax._categories.length - 1);
}
return tmin;
}
@@ -798,7 +803,7 @@ axes.tickFirst = function(ax) {
}
else if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
- frac = Plotly.Lib.roundUp(mod(r0, 1), tickset, axrev);
+ frac = Lib.roundUp(mod(r0, 1), tickset, axrev);
return Math.floor(r0) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
@@ -1334,7 +1339,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
}
if(!axid || axid === 'redraw') {
- return Plotly.Lib.syncOrAsync(axes.list(gd, '', true).map(function(ax) {
+ return Lib.syncOrAsync(axes.list(gd, '', true).map(function(ax) {
return function() {
if(!ax._id) return;
var axDone = axes.doTicks(gd, ax._id);
@@ -1373,9 +1378,9 @@ axes.doTicks = function(gd, axid, skipTitle) {
labelStandoff =
(ax.ticks === 'outside' ? ax.ticklen : 1) + (ax.linewidth || 0),
labelShift = 0,
- gridWidth = Plotly.Drawing.crispRound(gd, ax.gridwidth, 1),
- zeroLineWidth = Plotly.Drawing.crispRound(gd, ax.zerolinewidth, gridWidth),
- tickWidth = Plotly.Drawing.crispRound(gd, ax.tickwidth, 1),
+ gridWidth = Drawing.crispRound(gd, ax.gridwidth, 1),
+ zeroLineWidth = Drawing.crispRound(gd, ax.zerolinewidth, gridWidth),
+ tickWidth = Drawing.crispRound(gd, ax.tickwidth, 1),
sides, transfn, tickpathfn,
i;
@@ -1439,7 +1444,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
if(tickpath && ax.ticks) {
ticks.enter().append('path').classed(tcls, 1).classed('ticks', 1)
.classed('crisp', 1)
- .call(Plotly.Color.stroke, ax.tickcolor)
+ .call(Color.stroke, ax.tickcolor)
.style('stroke-width', tickWidth + 'px')
.attr('d',tickpath);
ticks.attr('transform', transfn);
@@ -1500,12 +1505,10 @@ axes.doTicks = function(gd, axid, skipTitle) {
var thisLabel = d3.select(this),
newPromise = gd._promises.length;
thisLabel
- .call(Plotly.Drawing.setPosition,
- labelx(d), labely(d))
- .call(Plotly.Drawing.font,
- d.font, d.fontSize, d.fontColor)
+ .call(Drawing.setPosition, labelx(d), labely(d))
+ .call(Drawing.font, d.font, d.fontSize, d.fontColor)
.text(d.text)
- .call(Plotly.util.convertToTspans);
+ .call(svgTextUtils.convertToTspans);
newPromise = gd._promises[newPromise];
if(newPromise) {
// if we have an async label, we'll deal with that
@@ -1552,7 +1555,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
}
else {
var mjShift =
- Plotly.Drawing.bBox(mathjaxGroup.node()).width *
+ Drawing.bBox(mathjaxGroup.node()).width *
{end: -0.5, start: 0.5}[anchor];
mathjaxGroup.attr('transform', transform +
(mjShift ? 'translate(' + mjShift + ',0)' : ''));
@@ -1586,7 +1589,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
x = ax.l2p(d.x);
if(thisLabel.empty()) thisLabel = s.select('text');
- var bb = Plotly.Drawing.bBox(thisLabel.node());
+ var bb = Drawing.bBox(thisLabel.node());
lbbArray.push({
// ignore about y, just deal with x overlaps
@@ -1600,8 +1603,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
});
});
for(i = 0; i < lbbArray.length - 1; i++) {
- if(Plotly.Lib.bBoxIntersect(
- lbbArray[i], lbbArray[i + 1])) {
+ if(Lib.bBoxIntersect(lbbArray[i], lbbArray[i + 1])) {
// any overlap at all - set 30 degrees
autoangle = 30;
break;
@@ -1631,7 +1633,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
ax._boundingBox = container.node().getBoundingClientRect();
}
- var done = Plotly.Lib.syncOrAsync([
+ var done = Lib.syncOrAsync([
allLabelsReady,
fixLabelOverlaps,
calcBoundingBox
@@ -1737,7 +1739,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
}
});
grid.attr('transform', transfn)
- .call(Plotly.Color.stroke, ax.gridcolor || '#ddd')
+ .call(Color.stroke, ax.gridcolor || '#ddd')
.style('stroke-width', gridWidth + 'px');
grid.exit().remove();
@@ -1759,7 +1761,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
.classed('crisp', 1)
.attr('d', gridpath);
zl.attr('transform', transfn)
- .call(Plotly.Color.stroke, ax.zerolinecolor || Plotly.Color.defaultLine)
+ .call(Color.stroke, ax.zerolinecolor || Color.defaultLine)
.style('stroke-width', zeroLineWidth + 'px');
zl.exit().remove();
}
@@ -1939,7 +1941,7 @@ function swapAxisGroup(gd, xIds, yIds) {
var ann = gd._fullLayout.annotations[i];
if(xIds.indexOf(ann.xref) !== -1 &&
yIds.indexOf(ann.yref) !== -1) {
- Plotly.Lib.swapAttrs(layout.annotations[i],['?']);
+ Lib.swapAttrs(layout.annotations[i],['?']);
}
}
}
@@ -1948,7 +1950,7 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes) {
// in case the value is the default for either axis,
// look at the first axis in each list and see if
// this key's value is undefined
- var np = Plotly.Lib.nestedProperty,
+ var np = Lib.nestedProperty,
xVal = np(layout[xFullAxes[0]._name], key).get(),
yVal = np(layout[yFullAxes[0]._name], key).get(),
i;
diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js
index ab0efbad05b..5024e0c598a 100644
--- a/src/plots/cartesian/dragbox.js
+++ b/src/plots/cartesian/dragbox.js
@@ -13,9 +13,14 @@ var d3 = require('d3');
var tinycolor = require('tinycolor2');
var Plotly = require('../../plotly');
+var Lib = require('../../lib');
+var svgTextUtils = require('../../lib/svg_text_utils');
+var Color = require('../../components/color');
+var Drawing = require('../../components/drawing');
var setCursor = require('../../lib/setcursor');
var dragElement = require('../../components/dragelement');
+var Axes = require('./axes');
var prepSelect = require('./select');
var constants = require('./constants');
@@ -78,7 +83,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
.classed(dragClass, true)
.style({fill: 'transparent', 'stroke-width': 0})
.attr('data-subplot', plotinfo.id);
- dragger3.call(Plotly.Drawing.setRect, x, y, w, h)
+ dragger3.call(Drawing.setRect, x, y, w, h)
.call(setCursor,cursor);
var dragger = dragger3.node();
@@ -170,8 +175,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
corners = plotinfo.plot.append('path')
.attr('class', 'zoombox-corners')
.style({
- fill: Plotly.Color.background,
- stroke: Plotly.Color.defaultLine,
+ fill: Color.background,
+ stroke: Color.defaultLine,
'stroke-width': 1,
opacity: 0
})
@@ -293,7 +298,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
dragTail(zoomMode);
if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
- Plotly.Lib.notifier('Double-click to
zoom back out','long');
+ Lib.notifier('Double-click to
zoom back out','long');
SHOWZOOMOUTTIP = false;
}
}
@@ -319,7 +324,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
else if(ew === 'e') hAlign = 'right';
dragger3
- .call(Plotly.util.makeEditable, null, {
+ .call(svgTextUtils.makeEditable, null, {
immediate: true,
background: fullLayout.paper_bgcolor,
text: String(initialText),
@@ -408,7 +413,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
dragTail();
}, REDRAWDELAY);
- return Plotly.Lib.pauseEvent(e);
+ return Lib.pauseEvent(e);
}
// everything but the corners gets wheel zoom
@@ -497,7 +502,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
if(ns) pushActiveAxIds(ya);
for(i = 0; i < activeAxIds.length; i++) {
- Plotly.Axes.doTicks(gd, activeAxIds[i], true);
+ Axes.doTicks(gd, activeAxIds[i], true);
}
function redrawObjs(objArray, module) {
@@ -623,7 +628,7 @@ function getEndText(ax, end) {
dig;
if(ax.type === 'date') {
- return Plotly.Lib.ms2DateTime(initialVal, diff);
+ return Lib.ms2DateTime(initialVal, diff);
}
else if(ax.type==='log') {
dig = Math.ceil(Math.max(0, -Math.log(diff) / Math.LN10)) + 3;
diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js
index 8ff557f7674..619d0b82062 100644
--- a/src/plots/cartesian/graph_interact.js
+++ b/src/plots/cartesian/graph_interact.js
@@ -13,13 +13,17 @@ var d3 = require('d3');
var tinycolor = require('tinycolor2');
var isNumeric = require('fast-isnumeric');
-var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Events = require('../../lib/events');
+var svgTextUtils = require('../../lib/svg_text_utils');
+var Color = require('../../components/color');
+var Drawing = require('../../components/drawing');
+var dragElement = require('../../components/dragelement');
+var Axes = require('./axes');
var constants = require('./constants');
var dragBox = require('./dragbox');
-var dragElement = require('../../components/dragelement');
+
var fx = module.exports = {};
@@ -319,12 +323,12 @@ function hover(gd, evt, subplot) {
xaArray = subplots.map(function(spId) {
var ternary = (gd._fullLayout[spId] || {})._ternary;
if(ternary) return ternary.xaxis;
- return Plotly.Axes.getFromId(gd, spId, 'x');
+ return Axes.getFromId(gd, spId, 'x');
}),
yaArray = subplots.map(function(spId) {
var ternary = (gd._fullLayout[spId] || {})._ternary;
if(ternary) return ternary.yaxis;
- return Plotly.Axes.getFromId(gd, spId, 'y');
+ return Axes.getFromId(gd, spId, 'y');
}),
hovermode = evt.hovermode || fullLayout.hovermode;
@@ -455,7 +459,7 @@ function hover(gd, evt, subplot) {
// point properties - override all of these
index: false, // point index in trace - only used by plotly.js hoverdata consumers
distance: Math.min(distance, constants.MAXDIST), // pixel distance or pseudo-distance
- color: Plotly.Color.defaultLine, // trace color
+ color: Color.defaultLine, // trace color
x0: undefined,
x1: undefined,
y0: undefined,
@@ -528,8 +532,8 @@ function hover(gd, evt, subplot) {
hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; });
- var bgColor = Plotly.Color.combine(
- fullLayout.plot_bgcolor || Plotly.Color.background,
+ var bgColor = Color.combine(
+ fullLayout.plot_bgcolor || Color.background,
fullLayout.paper_bgcolor
);
@@ -627,17 +631,17 @@ function cleanPoint(d, hovermode) {
d.posref = hovermode==='y' ? (d.x0+d.x1)/2 : (d.y0+d.y1)/2;
// then constrain all the positions to be on the plot
- d.x0 = Plotly.Lib.constrain(d.x0, 0, d.xa._length);
- d.x1 = Plotly.Lib.constrain(d.x1, 0, d.xa._length);
- d.y0 = Plotly.Lib.constrain(d.y0, 0, d.ya._length);
- d.y1 = Plotly.Lib.constrain(d.y1, 0, d.ya._length);
+ d.x0 = Lib.constrain(d.x0, 0, d.xa._length);
+ d.x1 = Lib.constrain(d.x1, 0, d.xa._length);
+ d.y0 = Lib.constrain(d.y0, 0, d.ya._length);
+ d.y1 = Lib.constrain(d.y1, 0, d.ya._length);
// and convert the x and y label values into objects
// formatted as text, with font info
var logOffScale;
if(d.xLabelVal!==undefined) {
logOffScale = (d.xa.type==='log' && d.xLabelVal<=0);
- var xLabelObj = Plotly.Axes.tickText(d.xa,
+ var xLabelObj = Axes.tickText(d.xa,
d.xa.c2l(logOffScale ? -d.xLabelVal : d.xLabelVal), 'hover');
if(logOffScale) {
if(d.xLabelVal===0) d.xLabel = '0';
@@ -649,7 +653,7 @@ function cleanPoint(d, hovermode) {
if(d.yLabelVal!==undefined) {
logOffScale = (d.ya.type==='log' && d.yLabelVal<=0);
- var yLabelObj = Plotly.Axes.tickText(d.ya,
+ var yLabelObj = Axes.tickText(d.ya,
d.ya.c2l(logOffScale ? -d.yLabelVal : d.yLabelVal), 'hover');
if(logOffScale) {
if(d.yLabelVal===0) d.yLabel = '0';
@@ -663,10 +667,10 @@ function cleanPoint(d, hovermode) {
// for box means and error bars, add the range to the label
if(d.xerr!==undefined) {
- var xeText = Plotly.Axes.tickText(d.xa, d.xa.c2l(d.xerr), 'hover').text;
+ var xeText = Axes.tickText(d.xa, d.xa.c2l(d.xerr), 'hover').text;
if(d.xerrneg!==undefined) {
d.xLabel += ' +' + xeText + ' / -' +
- Plotly.Axes.tickText(d.xa, d.xa.c2l(d.xerrneg), 'hover').text;
+ Axes.tickText(d.xa, d.xa.c2l(d.xerrneg), 'hover').text;
}
else d.xLabel += ' ± ' + xeText;
@@ -676,10 +680,10 @@ function cleanPoint(d, hovermode) {
if(hovermode==='x') d.distance += 1;
}
if(d.yerr!==undefined) {
- var yeText = Plotly.Axes.tickText(d.ya, d.ya.c2l(d.yerr), 'hover').text;
+ var yeText = Axes.tickText(d.ya, d.ya.c2l(d.yerr), 'hover').text;
if(d.yerrneg!==undefined) {
d.yLabel += ' +' + yeText + ' / -' +
- Plotly.Axes.tickText(d.ya, d.ya.c2l(d.yerrneg), 'hover').text;
+ Axes.tickText(d.ya, d.ya.c2l(d.yerrneg), 'hover').text;
}
else d.yLabel += ' ± ' + yeText;
@@ -716,7 +720,7 @@ fx.loneHover = function(hoverItem, opts) {
// a dom