Skip to content

Commit b5b72ff

Browse files
authored
Merge pull request #2177 from plotly/cliponaxis-dates
Cliponaxis dates
2 parents 29df012 + ae801a2 commit b5b72ff

File tree

10 files changed

+99
-44
lines changed

10 files changed

+99
-44
lines changed

src/components/drawing/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,27 @@ drawing.translatePoints = function(s, xa, ya) {
9393
});
9494
};
9595

96-
drawing.hideOutsideRangePoint = function(d, sel, xa, ya) {
96+
drawing.hideOutsideRangePoint = function(d, sel, xa, ya, xcalendar, ycalendar) {
9797
sel.attr(
9898
'display',
99-
xa.isPtWithinRange(d) && ya.isPtWithinRange(d) ? null : 'none'
99+
(xa.isPtWithinRange(d, xcalendar) && ya.isPtWithinRange(d, ycalendar)) ? null : 'none'
100100
);
101101
};
102102

103-
drawing.hideOutsideRangePoints = function(points, subplot) {
103+
drawing.hideOutsideRangePoints = function(traceGroups, subplot) {
104104
if(!subplot._hasClipOnAxisFalse) return;
105105

106106
var xa = subplot.xaxis;
107107
var ya = subplot.yaxis;
108108

109-
points.each(function(d) {
110-
drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya);
109+
traceGroups.each(function(d) {
110+
var trace = d[0].trace;
111+
var xcalendar = trace.xcalendar;
112+
var ycalendar = trace.ycalendar;
113+
114+
traceGroups.selectAll('.point,.textpoint').each(function(d) {
115+
drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya, xcalendar, ycalendar);
116+
});
111117
});
112118
};
113119

src/plots/cartesian/dragbox.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -751,21 +751,21 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
751751
.call(Drawing.setTranslate, clipDx, clipDy)
752752
.call(Drawing.setScale, xScaleFactor2, yScaleFactor2);
753753

754-
var scatterPoints = subplot.plot.selectAll('.scatterlayer .points, .boxlayer .points');
754+
var traceGroups = subplot.plot
755+
.selectAll('.scatterlayer .trace, .boxlayer .trace, .violinlayer .trace');
755756

756757
subplot.plot
757758
.call(Drawing.setTranslate, plotDx, plotDy)
758759
.call(Drawing.setScale, 1 / xScaleFactor2, 1 / yScaleFactor2);
759760

760-
// This is specifically directed at scatter traces, applying an inverse
761-
// scale to individual points to counteract the scale of the trace
762-
// as a whole:
763-
scatterPoints.selectAll('.point')
764-
.call(Drawing.setPointGroupScale, xScaleFactor2, yScaleFactor2)
765-
.call(Drawing.hideOutsideRangePoints, subplot);
766-
767-
scatterPoints.selectAll('.textpoint')
768-
.call(Drawing.setTextPointsScale, xScaleFactor2, yScaleFactor2)
761+
// This is specifically directed at marker points in scatter, box and violin traces,
762+
// applying an inverse scale to individual points to counteract
763+
// the scale of the trace as a whole:
764+
traceGroups.selectAll('.point')
765+
.call(Drawing.setPointGroupScale, xScaleFactor2, yScaleFactor2);
766+
traceGroups.selectAll('.textpoint')
767+
.call(Drawing.setTextPointsScale, xScaleFactor2, yScaleFactor2);
768+
traceGroups
769769
.call(Drawing.hideOutsideRangePoints, subplot);
770770
}
771771
}

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/plots/cartesian/transition_axes.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,16 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
161161
.call(Drawing.setTranslate, xa2._offset, ya2._offset)
162162
.call(Drawing.setScale, 1, 1);
163163

164-
var scatterPoints = subplot.plot.select('.scatterlayer').selectAll('.points');
164+
var traceGroups = subplot.plot.selectAll('.scatterlayer .trace');
165165

166166
// This is specifically directed at scatter traces, applying an inverse
167167
// scale to individual points to counteract the scale of the trace
168168
// as a whole:
169-
scatterPoints.selectAll('.point')
170-
.call(Drawing.setPointGroupScale, 1, 1)
171-
.call(Drawing.hideOutsideRangePoints, subplot);
172-
173-
scatterPoints.selectAll('.textpoint')
174-
.call(Drawing.setTextPointsScale, 1, 1)
169+
traceGroups.selectAll('.point')
170+
.call(Drawing.setPointGroupScale, 1, 1);
171+
traceGroups.selectAll('.textpoint')
172+
.call(Drawing.setTextPointsScale, 1, 1);
173+
traceGroups
175174
.call(Drawing.hideOutsideRangePoints, subplot);
176175
}
177176

src/plots/ternary/ternary.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,8 @@ proto.initInteractions = function() {
652652
_this.plotContainer.selectAll('.crisp').classed('crisp', false);
653653

654654
if(_this._hasClipOnAxisFalse) {
655-
var scatterPoints = _this.plotContainer
656-
.select('.scatterlayer').selectAll('.points');
657-
658-
scatterPoints.selectAll('.point')
659-
.call(Drawing.hideOutsideRangePoints, _this);
660-
661-
scatterPoints.selectAll('.textpoint')
655+
_this.plotContainer
656+
.select('.scatterlayer').selectAll('.trace')
662657
.call(Drawing.hideOutsideRangePoints, _this);
663658
}
664659
}

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)