Skip to content

Commit 2289657

Browse files
committed
rm _gd ref in fullLayout axis containers
- make setConvert take fullLayout, use fullLayout._size in setScale instead of gd._fullLayout._size - add _input ref to fullLayout axis, use that in doAutorange to copy back computed range to input layout
1 parent 11073f2 commit 2289657

File tree

9 files changed

+38
-46
lines changed

9 files changed

+38
-46
lines changed

src/components/colorbar/draw.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ module.exports = function draw(gd, id) {
185185
}
186186

187187
// Prepare the Plotly axis object
188-
handleAxisDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);
188+
handleAxisDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions, fullLayout);
189189
handleAxisPositionDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);
190190

191191
cbAxisOut._id = 'y' + id;
192-
cbAxisOut._gd = gd;
193192

194193
// position can't go in through supplyDefaults
195194
// because that restricts it to [0,1]

src/plots/cartesian/axes.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,10 @@ axes.doAutoRange = function(ax) {
328328

329329
// doAutoRange will get called on fullLayout,
330330
// but we want to report its results back to layout
331-
var axIn = ax._gd.layout[ax._name];
332331

333-
if(!axIn) ax._gd.layout[ax._name] = axIn = {};
334-
335-
if(axIn !== ax) {
336-
axIn.range = ax.range.slice();
337-
axIn.autorange = ax.autorange;
338-
}
332+
var axIn = ax._input;
333+
axIn.range = ax.range.slice();
334+
axIn.autorange = ax.autorange;
339335
}
340336
};
341337

@@ -1137,7 +1133,7 @@ axes.tickText = function(ax, x, hover) {
11371133
};
11381134

11391135
function tickTextObj(ax, x, text) {
1140-
var tf = ax.tickfont || ax._gd._fullLayout.font;
1136+
var tf = ax.tickfont || {};
11411137

11421138
return {
11431139
x: x,
@@ -1347,7 +1343,7 @@ function numFormat(v, ax, fmtoverride, hover) {
13471343
if(dp) v = v.substr(0, dp + tickRound).replace(/\.?0+$/, '');
13481344
}
13491345
// insert appropriate decimal point and thousands separator
1350-
v = Lib.numSeparate(v, ax._gd._fullLayout.separators, separatethousands);
1346+
v = Lib.numSeparate(v, ax.separators, separatethousands);
13511347
}
13521348

13531349
// add exponent

src/plots/cartesian/axis_defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var autoType = require('./axis_autotype');
3939
* data: the plot data to use in choosing auto type
4040
* bgColor: the plot background color, to calculate default gridline colors
4141
*/
42-
module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options) {
42+
module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {
4343
var letter = options.letter,
4444
font = options.font || {},
4545
defaultTitle = 'Click to enter ' +
@@ -78,7 +78,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7878
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
7979
}
8080

81-
setConvert(containerOut);
81+
setConvert(containerOut, layoutOut);
8282

8383
var dfltColor = coerce('color');
8484
// if axis.color was provided, use it for fonts too; otherwise,

src/plots/cartesian/layout_defaults.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
138138

139139
for(i = 0; i < axesList.length; i++) {
140140
axName = axesList[i];
141-
axLayoutIn = layoutIn[axName] || {};
142-
axLayoutOut = {};
141+
142+
if(!Lib.isPlainObject(layoutIn[axName])) {
143+
layoutIn[axName] = {};
144+
}
145+
146+
axLayoutIn = layoutIn[axName];
147+
axLayoutOut = layoutOut[axName] = {};
143148

144149
var axLetter = axName.charAt(0);
145150

@@ -164,13 +169,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
164169

165170
handlePositionDefaults(axLayoutIn, axLayoutOut, coerce, positioningOptions);
166171

167-
layoutOut[axName] = axLayoutOut;
168-
169-
// so we don't have to repeat autotype unnecessarily,
170-
// copy an autotype back to layoutIn
171-
if(!layoutIn[axName] && axLayoutIn.type !== '-') {
172-
layoutIn[axName] = {type: axLayoutIn.type};
173-
}
172+
axLayoutOut._input = axLayoutIn;
174173
}
175174

176175
// quick second pass for range slider and selector defaults

src/plots/cartesian/set_convert.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function num(v) {
6161
* also clears the autorange bounds ._min and ._max
6262
* and the autotick constraints ._minDtick, ._forceTick0
6363
*/
64-
module.exports = function setConvert(ax) {
64+
module.exports = function setConvert(ax, fullLayout) {
65+
fullLayout = fullLayout || {};
6566

6667
// clipMult: how many axis lengths past the edge do we render?
6768
// for panning, 1-2 would suffice, but for zooming more is nice.
@@ -319,7 +320,7 @@ module.exports = function setConvert(ax) {
319320

320321
// set scaling to pixels
321322
ax.setScale = function(usePrivateRange) {
322-
var gs = ax._gd._fullLayout._size,
323+
var gs = fullLayout._size,
323324
axLetter = ax._id.charAt(0);
324325

325326
// TODO cleaner way to handle this case
@@ -328,7 +329,7 @@ module.exports = function setConvert(ax) {
328329
// make sure we have a domain (pull it in from the axis
329330
// this one is overlaying if necessary)
330331
if(ax.overlaying) {
331-
var ax2 = axisIds.getFromId(ax._gd, ax.overlaying);
332+
var ax2 = axisIds.getFromId({ _fullLayout: fullLayout }, ax.overlaying);
332333
ax.domain = ax2.domain;
333334
}
334335

@@ -360,7 +361,6 @@ module.exports = function setConvert(ax) {
360361
Lib.notifier(
361362
'Something went wrong with axis scaling',
362363
'long');
363-
ax._gd._replotting = false;
364364
throw new Error('axis scaling');
365365
}
366366
};
@@ -417,6 +417,10 @@ module.exports = function setConvert(ax) {
417417
ax._min = [];
418418
ax._max = [];
419419

420+
// copy ref to fullLayout.separators so that
421+
// methods in Axes can use it w/o having to pass fullLayout
422+
ax.separators = fullLayout.separators;
423+
420424
// and for bar charts and box plots: reset forced minimum tick spacing
421425
delete ax._minDtick;
422426
delete ax._forceTick0;

src/plots/geo/geo.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,9 @@ function createMockAxis(fullLayout) {
465465
var mockAxis = {
466466
type: 'linear',
467467
showexponent: 'all',
468-
exponentformat: Axes.layoutAttributes.exponentformat.dflt,
469-
_gd: { _fullLayout: fullLayout }
468+
exponentformat: Axes.layoutAttributes.exponentformat.dflt
470469
};
471470

472-
Axes.setConvert(mockAxis);
471+
Axes.setConvert(mockAxis, fullLayout);
473472
return mockAxis;
474473
}

src/plots/plots.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,10 @@ plots.supplyDefaults = function(gd) {
491491
// TODO may return a promise
492492
plots.doAutoMargin(gd);
493493

494-
// can't quite figure out how to get rid of this... each axis needs
495-
// a reference back to the DOM object for just a few purposes
494+
// set scale after auto margin routine
496495
var axList = Plotly.Axes.list(gd);
497496
for(i = 0; i < axList.length; i++) {
498497
var ax = axList[i];
499-
ax._gd = gd;
500498
ax.setScale();
501499
}
502500

src/plots/ternary/ternary.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,9 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
176176
xDomainCenter - xDomainFinal / 2,
177177
xDomainCenter + xDomainFinal / 2
178178
],
179-
_id: 'x',
180-
_gd: _this.graphDiv
179+
_id: 'x'
181180
};
182-
setConvert(_this.xaxis);
181+
setConvert(_this.xaxis, _this.graphDiv._fullLayout);
183182
_this.xaxis.setScale();
184183

185184
_this.yaxis = {
@@ -189,10 +188,9 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
189188
yDomainCenter - yDomainFinal / 2,
190189
yDomainCenter + yDomainFinal / 2
191190
],
192-
_id: 'y',
193-
_gd: _this.graphDiv
191+
_id: 'y'
194192
};
195-
setConvert(_this.yaxis);
193+
setConvert(_this.yaxis, _this.graphDiv._fullLayout);
196194
_this.yaxis.setScale();
197195

198196
// set up the modified axes for tick drawing
@@ -212,12 +210,12 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
212210
_axislayer: _this.layers.aaxis,
213211
_gridlayer: _this.layers.agrid,
214212
_pos: 0, // _this.xaxis.domain[0] * graphSize.w,
215-
_gd: _this.graphDiv,
216213
_id: 'y',
217214
_length: w,
218215
_gridpath: 'M0,0l' + h + ',-' + (w / 2)
219216
});
220-
setConvert(aaxis);
217+
setConvert(aaxis, _this.graphDiv._fullLayout);
218+
aaxis.setScale();
221219

222220
// baxis goes across the bottom (backward). We can set it up as an x axis
223221
// without any enclosing transformation.
@@ -230,12 +228,12 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
230228
_gridlayer: _this.layers.bgrid,
231229
_counteraxis: _this.aaxis,
232230
_pos: 0, // (1 - yDomain0) * graphSize.h,
233-
_gd: _this.graphDiv,
234231
_id: 'x',
235232
_length: w,
236233
_gridpath: 'M0,0l-' + (w / 2) + ',-' + h
237234
});
238-
setConvert(baxis);
235+
setConvert(baxis, _this.graphDiv._fullLayout);
236+
baxis.setScale();
239237
aaxis._counteraxis = baxis;
240238

241239
// caxis goes down the right side. Set it up as a y axis, with
@@ -250,12 +248,12 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
250248
_gridlayer: _this.layers.cgrid,
251249
_counteraxis: _this.baxis,
252250
_pos: 0, // _this.xaxis.domain[1] * graphSize.w,
253-
_gd: _this.graphDiv,
254251
_id: 'y',
255252
_length: w,
256253
_gridpath: 'M0,0l-' + h + ',' + (w / 2)
257254
});
258-
setConvert(caxis);
255+
setConvert(caxis, _this.graphDiv._fullLayout);
256+
caxis.setScale();
259257

260258
var triangleClip = 'M' + x0 + ',' + (y0 + h) + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';
261259
_this.clipDef.select('path').attr('d', triangleClip);

test/jasmine/tests/axes_test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,8 @@ describe('Test axes', function() {
14851485

14861486
describe('calcTicks and tickText', function() {
14871487
function mockCalc(ax) {
1488-
Axes.setConvert(ax);
14891488
ax.tickfont = {};
1490-
ax._gd = {_fullLayout: {separators: '.,'}};
1489+
Axes.setConvert(ax, {separators: '.,'});
14911490
return Axes.calcTicks(ax).map(function(v) { return v.text; });
14921491
}
14931492

0 commit comments

Comments
 (0)