Skip to content

Commit d35d13b

Browse files
committed
DRY up polar mock cartesian axis 'range' logic
1 parent 52ed444 commit d35d13b

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

src/plots/polar/polar.js

+43-27
Original file line numberDiff line numberDiff line change
@@ -271,29 +271,15 @@ proto.updateLayout = function(fullLayout, polarLayout) {
271271
_this.updateRadialAxis(fullLayout, polarLayout);
272272
_this.updateRadialAxisTitle(fullLayout, polarLayout);
273273

274-
var radialRange = _this.radialAxis.range;
275-
var rSpan = radialRange[1] - radialRange[0];
276-
277-
var xaxis = _this.xaxis = {
278-
type: 'linear',
274+
_this.xaxis = _this.mockCartesianAxis(fullLayout, polarLayout, {
279275
_id: 'x',
280-
range: [sectorBBox[0] * rSpan, sectorBBox[2] * rSpan],
281276
domain: xDomain2
282-
};
283-
setConvertCartesian(xaxis, fullLayout);
284-
xaxis.setScale();
277+
});
285278

286-
var yaxis = _this.yaxis = {
287-
type: 'linear',
279+
_this.yaxis = _this.mockCartesianAxis(fullLayout, polarLayout, {
288280
_id: 'y',
289-
range: [sectorBBox[1] * rSpan, sectorBBox[3] * rSpan],
290281
domain: yDomain2
291-
};
292-
setConvertCartesian(yaxis, fullLayout);
293-
yaxis.setScale();
294-
295-
xaxis.isPtWithinRange = function(d) { return _this.isPtWithinSector(d); };
296-
yaxis.isPtWithinRange = function() { return true; };
282+
});
297283

298284
_this.clipPaths.forTraces.select('path')
299285
.attr('d', pathSectorClosed(radius, sector, _this.vangles))
@@ -330,6 +316,35 @@ proto.mockAxis = function(fullLayout, polarLayout, axLayout, opts) {
330316
return ax;
331317
};
332318

319+
proto.mockCartesianAxis = function(fullLayout, polarLayout, opts) {
320+
var _this = this;
321+
var axId = opts._id;
322+
323+
var ax = Lib.extendFlat({type: 'linear'}, opts);
324+
setConvertCartesian(ax, fullLayout);
325+
326+
var bboxIndices = {
327+
x: [0, 2],
328+
y: [1, 3]
329+
};
330+
331+
ax.setRange = function() {
332+
var sectorBBox = _this.sectorBBox;
333+
var radialRange = _this.radialAxis.range;
334+
var rSpan = radialRange[1] - radialRange[0];
335+
var ind = bboxIndices[axId];
336+
ax.range = [sectorBBox[ind[0]] * rSpan, sectorBBox[ind[1]] * rSpan];
337+
};
338+
339+
ax.isPtWithinRange = axId === 'x' ?
340+
function(d) { return _this.isPtWithinSector(d); } :
341+
function() { return true; };
342+
343+
ax.setRange();
344+
ax.setScale();
345+
return ax;
346+
};
347+
333348
proto.doAutoRange = function(fullLayout, polarLayout) {
334349
var gd = this.gd;
335350
var radialAxis = this.radialAxis;
@@ -974,28 +989,29 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
974989

975990
// make sure new range[1] does not change the range[0] -> range[1] sign
976991
if((drange > 0) !== (rprime > range0[0])) return;
992+
993+
// update radial range -> update c2g -> update _m,_b
977994
rng1 = radialAxis.range[1] = rprime;
995+
radialAxis.setGeometry();
996+
radialAxis.setScale();
997+
998+
_this.xaxis.setRange();
999+
_this.xaxis.setScale();
1000+
_this.yaxis.setRange();
1001+
_this.yaxis.setScale();
9781002

979-
doTicksSingle(gd, _this.radialAxis, true);
1003+
doTicksSingle(gd, radialAxis, true);
9801004
layers['radial-grid']
9811005
.attr('transform', strTranslate(cx, cy))
9821006
.selectAll('path').attr('transform', null);
9831007

984-
var rSpan = rng1 - range0[0];
985-
var sectorBBox = _this.sectorBBox;
986-
_this.xaxis.range = [sectorBBox[0] * rSpan, sectorBBox[2] * rSpan];
987-
_this.yaxis.range = [sectorBBox[1] * rSpan, sectorBBox[3] * rSpan];
988-
_this.xaxis.setScale();
989-
_this.yaxis.setScale();
990-
9911008
if(_this._scene) _this._scene.clear();
9921009

9931010
for(var traceType in _this.traceHash) {
9941011
var moduleCalcData = _this.traceHash[traceType];
9951012
var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);
9961013
var _module = moduleCalcData[0][0].trace._module;
9971014
var polarLayoutNow = gd._fullLayout[_this.id];
998-
9991015
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
10001016
}
10011017
}

0 commit comments

Comments
 (0)