Skip to content

Commit

Permalink
td -> gd once and for all
Browse files Browse the repository at this point in the history
except for image server compatibility, we leave td in plotTile
  • Loading branch information
alexcjohnson committed Oct 26, 2016
1 parent 51a0563 commit 5ccd083
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/components/annotations/annotation_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ module.exports = function handleAnnotationDefaults(annIn, fullLayout) {
// positioning
var axLetters = ['x', 'y'],
arrowPosDflt = [-10, -30],
tdMock = {_fullLayout: fullLayout};
gdMock = {_fullLayout: fullLayout};
for(var i = 0; i < 2; i++) {
var axLetter = axLetters[i];

// xref, yref
var axRef = Axes.coerceRef(annIn, annOut, tdMock, axLetter, '', 'paper');
var axRef = Axes.coerceRef(annIn, annOut, gdMock, axLetter, '', 'paper');

// x, y
Axes.coercePosition(annOut, tdMock, coerce, axRef, axLetter, 0.5);
Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);

if(showArrow) {
var arrowPosAttr = 'a' + axLetter,
// axref, ayref
aaxRef = Axes.coerceRef(annIn, annOut, tdMock, arrowPosAttr, 'pixel');
aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');

// for now the arrow can only be on the same axis or specified as pixels
// TODO: sometime it might be interesting to allow it to be on *any* axis
Expand All @@ -66,7 +66,7 @@ module.exports = function handleAnnotationDefaults(annIn, fullLayout) {

// ax, ay
var aDflt = (aaxRef === 'pixel') ? arrowPosDflt[i] : 0.4;
Axes.coercePosition(annOut, tdMock, coerce, aaxRef, arrowPosAttr, aDflt);
Axes.coercePosition(annOut, gdMock, coerce, aaxRef, arrowPosAttr, aDflt);
}

// xanchor, yanchor
Expand Down
4 changes: 2 additions & 2 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ drawing.getPx = function(s, styleAttr) {
return Number(s.style(styleAttr).replace(/px$/, ''));
};

drawing.crispRound = function(td, lineWidth, dflt) {
drawing.crispRound = function(gd, lineWidth, dflt) {
// for lines that disable antialiasing we want to
// make sure the width is an integer, and at least 1 if it's nonzero

if(!lineWidth || !isNumeric(lineWidth)) return dflt || 0;

// but not for static plots - these don't get antialiased anyway.
if(td._context.staticPlot) return lineWidth;
if(gd._context.staticPlot) return lineWidth;

if(lineWidth < 1) return 1;
return Math.round(lineWidth);
Expand Down
4 changes: 2 additions & 2 deletions src/components/images/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ function imageDefaults(imageIn, imageOut, fullLayout) {
coerce('opacity');

for(var i = 0; i < 2; i++) {
var tdMock = { _fullLayout: fullLayout },
var gdMock = { _fullLayout: fullLayout },
axLetter = ['x', 'y'][i];

// 'paper' is the fallback axref
Axes.coerceRef(imageIn, imageOut, tdMock, axLetter, 'paper');
Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper');
}

return imageOut;
Expand Down
10 changes: 5 additions & 5 deletions src/components/shapes/shape_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ module.exports = function handleShapeDefaults(shapeIn, fullLayout) {
var axLetters = ['x', 'y'];
for(var i = 0; i < 2; i++) {
var axLetter = axLetters[i],
tdMock = {_fullLayout: fullLayout};
gdMock = {_fullLayout: fullLayout};

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

if(shapeType !== 'path') {
var dflt0 = 0.25,
Expand All @@ -49,7 +49,7 @@ module.exports = function handleShapeDefaults(shapeIn, fullLayout) {
r2pos;

if(axRef !== 'paper') {
ax = Axes.getFromId(tdMock, axRef);
ax = Axes.getFromId(gdMock, axRef);
r2pos = helpers.rangeToShapePosition(ax);
pos2r = helpers.shapePositionToRange(ax);

Expand All @@ -72,8 +72,8 @@ module.exports = function handleShapeDefaults(shapeIn, fullLayout) {
shapeIn[attr1] = pos2r(shapeIn[attr1], true);

// x0, x1 (and y0, y1)
Axes.coercePosition(shapeOut, tdMock, coerce, axRef, attr0, dflt0);
Axes.coercePosition(shapeOut, tdMock, coerce, axRef, attr1, dflt1);
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr0, dflt0);
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr1, dflt1);

// hack part 2
shapeOut[attr0] = r2pos(shapeOut[attr0]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ lib.smooth = function(arrayIn, FWHM) {
* as long as its returns are not promises (ie have no .then)
* includes one argument arg to send to all functions...
* this is mainly just to prevent us having to make wrapper functions
* when the only purpose of the wrapper is to reference gd / td
* when the only purpose of the wrapper is to reference gd
* and a final step to be executed at the end
* TODO: if there's an error and everything is sync,
* this doesn't happen yet because we want to make sure
Expand Down
4 changes: 2 additions & 2 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ exports.convertToTspans = function(_context, _callback) {
}

if(tex) {
var td = Lib.getPlotDiv(that.node());
((td && td._promises) || []).push(new Promise(function(resolve) {
var gd = Lib.getPlotDiv(that.node());
((gd && gd._promises) || []).push(new Promise(function(resolve) {
that.style({visibility: 'hidden'});
var config = {fontSize: parseInt(that.style('font-size'), 10)};

Expand Down
2 changes: 1 addition & 1 deletion src/plot_api/to_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function toImage(gd, opts) {

// first clone the GD so we can operate in a clean environment
var clone = clonePlot(gd, {format: 'png', height: opts.height, width: opts.width});
var clonedGd = clone.td;
var clonedGd = clone.gd;

// put the cloned div somewhere off screen before attaching to DOM
clonedGd.style.position = 'absolute';
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
* - for date axes: JS Dates or milliseconds, and convert to date strings
* - for other types: coerce them to numbers
*/
axes.coercePosition = function(containerOut, td, coerce, axRef, attr, dflt) {
axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {
var pos,
newPos;

if(axRef === 'paper' || axRef === 'pixel') {
pos = coerce(attr, dflt);
}
else {
var ax = axes.getFromId(td, axRef);
var ax = axes.getFromId(gd, axRef);

dflt = ax.fraction2r(dflt);
pos = coerce(attr, dflt);
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/axis_autotype.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function moreDates(a) {
return (dcnt > ncnt * 2);
}

// are the (x,y)-values in td.data mostly text?
// are the (x,y)-values in gd.data mostly text?
// require twice as many categories as numbers
function category(a) {
// test at most 1000 points
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = {
type: {
valType: 'enumerated',
// '-' means we haven't yet run autotype or couldn't find any data
// it gets turned into linear in td._fullLayout but not copied back
// to td.data like the others are.
// it gets turned into linear in gd._fullLayout but not copied back
// to gd.data like the others are.
values: ['-', 'linear', 'log', 'date', 'category'],
dflt: '-',
role: 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ module.exports = function setConvert(ax) {
// makeCalcdata: takes an x or y array and converts it
// to a position on the axis object "ax"
// inputs:
// trace - a data object from td.data
// trace - a data object from gd.data
// axLetter - a string, either 'x' or 'y', for which item
// to convert (TODO: is this now always the same as
// the first letter of ax._id?)
Expand Down
11 changes: 6 additions & 5 deletions src/snapshot/cloneplot.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ module.exports = function clonePlot(graphObj, options) {
}
}

var td = document.createElement('div');
if(options.tileClass) td.className = options.tileClass;
var gd = document.createElement('div');
if(options.tileClass) gd.className = options.tileClass;

var plotTile = {
td: td,
gd: gd,
td: gd, // for external (image server) compatibility
layout: newLayout,
data: newData,
config: {
Expand All @@ -148,8 +149,8 @@ module.exports = function clonePlot(graphObj, options) {
plotTile.config.setBackground = options.setBackground || 'opaque';
}

// attaching the default Layout the td, so you can grab it later
plotTile.td.defaultLayout = cloneLayoutOverride(options.tileClass);
// attaching the default Layout the gd, so you can grab it later
plotTile.gd.defaultLayout = cloneLayoutOverride(options.tileClass);

return plotTile;
};
2 changes: 1 addition & 1 deletion src/snapshot/toimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function toImage(gd, opts) {
var ev = new EventEmitter();

var clone = clonePlot(gd, {format: 'png'});
var clonedGd = clone.td;
var clonedGd = clone.gd;

// put the cloned div somewhere off screen before attaching to DOM
clonedGd.style.position = 'absolute';
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/snapshot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe('Plotly.Snapshot', function() {
var themeTile = Plotly.Snapshot.clone(dummyGraphObj, themeOptions);
expect(themeTile.layout.height).toEqual(THEMETILE_DEFAULT_LAYOUT.height);
expect(themeTile.layout.width).toEqual(THEMETILE_DEFAULT_LAYOUT.width);
expect(themeTile.td.defaultLayout).toEqual(THEMETILE_DEFAULT_LAYOUT);
expect(themeTile.gd.defaultLayout).toEqual(THEMETILE_DEFAULT_LAYOUT);
expect(themeTile.gd).toBe(themeTile.td); // image server compatibility
expect(themeTile.config).toEqual(config);
});

Expand Down

0 comments on commit 5ccd083

Please sign in to comment.