Skip to content

Commit ae801a2

Browse files
committed
get cliponaxis: false working for non-linear axes
1 parent 72b64bc commit ae801a2

File tree

7 files changed

+77
-18
lines changed

7 files changed

+77
-18
lines changed

src/components/drawing/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ drawing.translatePoints = function(s, xa, ya) {
9292
});
9393
};
9494

95-
drawing.hideOutsideRangePoint = function(d, sel, xa, ya) {
95+
drawing.hideOutsideRangePoint = function(d, sel, xa, ya, xcalendar, ycalendar) {
9696
sel.attr(
9797
'display',
98-
xa.isPtWithinRange(d) && ya.isPtWithinRange(d) ? null : 'none'
98+
(xa.isPtWithinRange(d, xcalendar) && ya.isPtWithinRange(d, ycalendar)) ? null : 'none'
9999
);
100100
};
101101

@@ -106,8 +106,12 @@ drawing.hideOutsideRangePoints = function(traceGroups, subplot) {
106106
var ya = subplot.yaxis;
107107

108108
traceGroups.each(function(d) {
109+
var trace = d[0].trace;
110+
var xcalendar = trace.xcalendar;
111+
var ycalendar = trace.ycalendar;
112+
109113
traceGroups.selectAll('.point,.textpoint').each(function(d) {
110-
drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya);
114+
drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya, xcalendar, ycalendar);
111115
});
112116
});
113117
};

src/plots/cartesian/set_convert.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,14 @@ module.exports = function setConvert(ax, fullLayout) {
435435
);
436436
};
437437

438-
if(axLetter === 'x') {
439-
ax.isPtWithinRange = function(d) {
440-
var x = d.x;
441-
return x >= ax.range[0] && x <= ax.range[1];
442-
};
443-
} else {
444-
ax.isPtWithinRange = function(d) {
445-
var y = d.y;
446-
return y >= ax.range[0] && y <= ax.range[1];
447-
};
448-
}
438+
ax.isPtWithinRange = function(d, calendar) {
439+
var coord = ax.c2l(d[axLetter], null, calendar);
440+
441+
return (
442+
coord >= ax.r2l(ax.range[0]) &&
443+
coord <= ax.r2l(ax.range[1])
444+
);
445+
};
449446

450447
// for autoranging: arrays of objects:
451448
// {val: axis value, pad: pixel padding}

src/traces/scatter/plot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
445445
Drawing.singlePointStyle(d, sel, trace, markerScale, lineScale, gd);
446446

447447
if(plotinfo.layerClipId) {
448-
Drawing.hideOutsideRangePoint(d, sel, xa, ya);
448+
Drawing.hideOutsideRangePoint(d, sel, xa, ya, trace.xcalendar, trace.ycalendar);
449449
}
450450

451451
if(trace.customdata) {
@@ -481,7 +481,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
481481

482482
if(hasNode) {
483483
if(plotinfo.layerClipId) {
484-
Drawing.hideOutsideRangePoint(d, g, xa, ya);
484+
Drawing.hideOutsideRangePoint(d, g, xa, ya, trace.xcalendar, trace.ycalendar);
485485
}
486486
} else {
487487
g.remove();
Loading
-1.57 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"data": [{
3+
"name": "gregorian input dates",
4+
"x": ["2017-11-1", "2017-11-2", "2017-11-3", "2017-11-4", "2017-11-5", "2017-11-6", "2017-11-7"],
5+
"y": [4734, 7793, 7784, 6628, 5644, 6224, 5058],
6+
"text": [4734, 7793, 7784, 6628, 5644, 6224, 5058],
7+
"mode": "lines+markers+text",
8+
"marker": {"size": 30},
9+
"textposition": "top right",
10+
"hoverinfo": "x+y",
11+
"cliponaxis": false
12+
}, {
13+
"name": "julian input dates",
14+
"y": ["2017-11-1", "2017-11-2", "2017-11-3", "2017-11-4", "2017-11-5", "2017-11-6", "2017-11-7"],
15+
"x": [4734, 7793, 7784, 6628, 5644, 6224, 5058],
16+
"text": [4734, 7793, 7784, 6628, 5644, 6224, 5058],
17+
"mode": "lines+markers+text",
18+
"marker": {"size": 30},
19+
"textposition": "bottom left",
20+
"hoverinfo": "x+y",
21+
"cliponaxis": false,
22+
"ycalendar": "julian",
23+
"xaxis": "x2",
24+
"yaxis": "y2"
25+
}],
26+
"layout": {
27+
"dragmode": "pan",
28+
"width": 700,
29+
"height": 400,
30+
"xaxis": {
31+
"domain": [0, 0.48],
32+
"title": "gregorian date axis",
33+
"range": ["2017-11-1", "2017-11-7"]
34+
},
35+
"yaxis": {
36+
"type": "log" ,
37+
"title": "log axis"
38+
},
39+
"xaxis2": {
40+
"type": "log",
41+
"domain": [0.52, 1],
42+
"title": "log axis",
43+
"anchor": "y2"
44+
},
45+
"yaxis2": {
46+
"anchor": "x2",
47+
"side": "right",
48+
"title": "gregorian date axis",
49+
"range": ["2017-11-14", "2017-11-20"]
50+
},
51+
"legend": {
52+
"x": 0,
53+
"y": 1.1,
54+
"xanchor": "left",
55+
"yanchor": "bottom"
56+
}
57+
}
58+
}

test/image/mocks/cliponaxis_false.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
{
3737
"mode": "markers",
38-
"x": [1, 1, 2, 3, 3, 2],
38+
"x": ["a", "a", "b", "c", "c", "b"],
3939
"y": [2, 1, 1, 1, 2, 2],
4040
"marker": {
4141
"size": [15, 20, 40, 25, 50, 40],
@@ -75,7 +75,7 @@
7575
},
7676
"xaxis2": {
7777
"anchor": "y2",
78-
"range": [1, 3],
78+
"range": [0, 2],
7979
"domain": [0.52, 1],
8080
"showline": true,
8181
"linewidth": 2,

0 commit comments

Comments
 (0)