Skip to content

Commit f714449

Browse files
committed
extend line & fills to polar center when pts < radialaxis.range[0]
1 parent 9a71ba3 commit f714449

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

src/plots/polar/polar.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ proto.updateLayout = function(fullLayout, polarLayout) {
203203
var yOffset2 = _this.yOffset2 = gs.t + gs.h * (1 - yDomain2[1]);
204204
// circle radius in px
205205
var radius = _this.radius = xLength2 / dxSectorBBox;
206-
// circle center position x position in px
206+
// circle center position in px
207207
var cx = _this.cx = xOffset2 - radius * sectorBBox[0];
208-
// circle center position y position in px
209208
var cy = _this.cy = yOffset2 + radius * sectorBBox[3];
209+
// circle center in the coordinate system of plot area
210+
var cxx = _this.cxx = cx - xOffset2;
211+
var cyy = _this.cyy = cy - yOffset2;
210212

211213
_this.updateRadialAxis(fullLayout, polarLayout);
212214
_this.updateRadialAxisTitle(fullLayout, polarLayout);
@@ -248,7 +250,7 @@ proto.updateLayout = function(fullLayout, polarLayout) {
248250

249251
_this.clipPaths.circle.select('path')
250252
.attr('d', pathSectorClosed(radius, sector))
251-
.attr('transform', strTranslate(cx - xOffset2, cy - yOffset2));
253+
.attr('transform', strTranslate(cxx, cyy));
252254

253255
// remove crispEdges - all the off-square angles in polar plots
254256
// make these counterproductive.
@@ -567,6 +569,8 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
567569
var radius = _this.radius;
568570
var cx = _this.cx;
569571
var cy = _this.cy;
572+
var cxx = _this.cxx;
573+
var cyy = _this.cyy;
570574
var xOffset2 = _this.xOffset2;
571575
var yOffset2 = _this.yOffset2;
572576
var sector = polarLayout.sector;
@@ -588,9 +592,6 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
588592
var sector0;
589593
// angle about circle center at drag start
590594
var a0;
591-
// circle center in the main-drag coordinate system
592-
var cxx = cx - xOffset2;
593-
var cyy = cy - yOffset2;
594595

595596
function xy2r(x, y) {
596597
var xx = x - cxx;

src/traces/scatter/line_points.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ module.exports = function linePoints(d, opts) {
6060

6161
// turn one calcdata point into pixel coordinates
6262
function getPt(index) {
63-
var x = xa.c2p(d[index].x);
64-
var y = ya.c2p(d[index].y);
65-
if(x === BADNUM || y === BADNUM) return false;
63+
var di = d[index];
64+
var x = xa.c2p(di.x);
65+
var y = ya.c2p(di.y);
66+
if(x === BADNUM || y === BADNUM) return di.intoCenter || false;
6667
return [x, y];
6768
}
6869

src/traces/scatterpolar/plot.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ module.exports = function plot(subplot, moduleCalcData) {
4848
cdi.x = rr * Math.cos(rad);
4949
cdi.y = rr * Math.sin(rad);
5050
continue;
51+
} else {
52+
// flag for scatter/line_points.js
53+
// to extend line (and fills) into center
54+
cdi.intoCenter = [subplot.cxx, subplot.cyy];
5155
}
5256
}
5357

test/image/baselines/polar_fills.png

33.1 KB
Loading

test/image/mocks/polar_fills.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,37 @@
1313
"theta": [ 0, 90, 180, 270, 350, 360 ],
1414
"fill": "toself",
1515
"hoveron": "fills"
16+
}, {
17+
"type": "scatterpolar",
18+
"mode": "lines",
19+
"r": [5, 1, 2, 4, 5],
20+
"theta": [0, 90, 180, 270, 0],
21+
"fill": "toself",
22+
"hoveron": "fills",
23+
"subplot": "polar2"
1624
}],
1725
"layout": {
1826
"polar": {
27+
"domain": {
28+
"x": [0, 1],
29+
"y": [0, 0.46]
30+
},
1931
"radialaxis": {
2032
"range": [0, 5]
2133
}
2234
},
23-
"showlegend": false
35+
"polar2": {
36+
"domain": {
37+
"x": [0, 1],
38+
"y": [0.54, 1]
39+
},
40+
"radialaxis": {
41+
"range": [2, 5]
42+
}
43+
},
44+
"showlegend": false,
45+
"margin": {"t": 40, "b": 40},
46+
"width": 500,
47+
"height": 800
2448
}
2549
}

0 commit comments

Comments
 (0)