Skip to content

Commit 4b5c4bb

Browse files
committed
implement cliponaxis: false for scatterternary
- similar to the cartesian case, keep track of subplots that have 1 or more `cliponaxis: false` traces - override setConvert's ax.isPtWithinRange - add relative clip path def (to appropriately clip lines group)
1 parent 1909034 commit 4b5c4bb

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

src/plots/ternary/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
6767
if(!newFullLayout[oldTernaryKey] && !!oldTernary) {
6868
oldTernary.plotContainer.remove();
6969
oldTernary.clipDef.remove();
70+
oldTernary.clipDefRelative.remove();
7071
}
7172
}
7273

src/plots/ternary/ternary.js

+50-5
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ proto.init = function(fullLayout) {
4646
};
4747

4848
proto.plot = function(ternaryCalcData, fullLayout) {
49-
var _this = this,
50-
ternaryLayout = fullLayout[_this.id],
51-
graphSize = fullLayout._size;
49+
var _this = this;
50+
var ternaryLayout = fullLayout[_this.id];
51+
var graphSize = fullLayout._size;
52+
53+
_this._hasClipOnAxisFalse = false;
54+
for(var i = 0; i < ternaryCalcData.length; i++) {
55+
var trace = ternaryCalcData[i][0].trace;
56+
57+
if(trace.cliponaxis === false) {
58+
_this._hasClipOnAxisFalse = true;
59+
break;
60+
}
61+
}
5262

5363
_this.adjustLayout(ternaryLayout, graphSize);
5464

@@ -66,12 +76,19 @@ proto.makeFramework = function() {
6676
.classed('clips', true);
6777

6878
// clippath for this ternary subplot
69-
var clipId = 'clip' + _this.layoutId + _this.id;
79+
var clipId = _this.clipId = 'clip' + _this.layoutId + _this.id;
7080
_this.clipDef = defGroup.selectAll('#' + clipId)
7181
.data([0]);
7282
_this.clipDef.enter().append('clipPath').attr('id', clipId)
7383
.append('path').attr('d', 'M0,0Z');
7484

85+
// 'relative' clippath (i.e. no translation) for this ternary subplot
86+
var clipIdRelative = _this.clipIdRelative = 'clip-relative' + _this.layoutId + _this.id;
87+
_this.clipDefRelative = defGroup.selectAll('#' + clipIdRelative)
88+
.data([0]);
89+
_this.clipDefRelative.enter().append('clipPath').attr('id', clipIdRelative)
90+
.append('path').attr('d', 'M0,0Z');
91+
7592
// container for everything in this ternary subplot
7693
_this.plotContainer = _this.container.selectAll('g.' + _this.id)
7794
.data([0]);
@@ -120,7 +137,7 @@ proto.makeFramework = function() {
120137
.attr('class', function(d) { return 'grid ' + d; })
121138
.each(function(d) { _this.layers[d] = d3.select(this); });
122139

123-
_this.plotContainer.selectAll('.backplot,.frontplot,.grids')
140+
_this.plotContainer.selectAll('.backplot,.grids')
124141
.call(Drawing.setClipUrl, clipId);
125142
};
126143

@@ -175,6 +192,16 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
175192
};
176193
setConvert(_this.xaxis, _this.graphDiv._fullLayout);
177194
_this.xaxis.setScale();
195+
_this.xaxis.isPtWithinRange = function(d) {
196+
return (
197+
d.a >= _this.aaxis.range[0] &&
198+
d.a <= _this.aaxis.range[1] &&
199+
d.b >= _this.baxis.range[1] &&
200+
d.b <= _this.baxis.range[0] &&
201+
d.c >= _this.caxis.range[1] &&
202+
d.c <= _this.caxis.range[0]
203+
);
204+
};
178205

179206
_this.yaxis = {
180207
type: 'linear',
@@ -187,6 +214,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
187214
};
188215
setConvert(_this.yaxis, _this.graphDiv._fullLayout);
189216
_this.yaxis.setScale();
217+
_this.yaxis.isPtWithinRange = function() { return true; };
190218

191219
// set up the modified axes for tick drawing
192220
var yDomain0 = _this.yaxis.domain[0];
@@ -257,6 +285,9 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
257285
_this.clipDef.select('path').attr('d', triangleClip);
258286
_this.layers.plotbg.select('path').attr('d', triangleClip);
259287

288+
var triangleClipRelative = 'M0,' + h + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';
289+
_this.clipDefRelative.select('path').attr('d', triangleClipRelative);
290+
260291
var plotTransform = 'translate(' + x0 + ',' + y0 + ')';
261292
_this.plotContainer.selectAll('.scatterlayer,.maplayer')
262293
.attr('transform', plotTransform);
@@ -302,6 +333,9 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
302333
if(!_this.graphDiv._context.staticPlot) {
303334
_this.initInteractions();
304335
}
336+
337+
_this.plotContainer.select('.frontplot')
338+
.call(Drawing.setClipUrl, _this._hasClipOnAxisFalse ? null : _this.clipId);
305339
};
306340

307341
proto.drawAxes = function(doTitles) {
@@ -589,6 +623,17 @@ proto.initInteractions = function() {
589623

590624
_this.drawAxes(false);
591625
_this.plotContainer.selectAll('.crisp').classed('crisp', false);
626+
627+
if(_this._hasClipOnAxisFalse) {
628+
var scatterPoints = _this.plotContainer
629+
.select('.scatterlayer').selectAll('.points');
630+
631+
scatterPoints.selectAll('.point')
632+
.call(Drawing.hideOutsideRangePoints, _this);
633+
634+
scatterPoints.selectAll('.textpoint')
635+
.call(Drawing.hideOutsideRangePoints, _this);
636+
}
592637
}
593638

594639
function dragDone(dragged, numClicks) {

src/traces/scatterternary/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module.exports = {
9595
smoothing: scatterLineAttrs.smoothing
9696
},
9797
connectgaps: scatterAttrs.connectgaps,
98+
cliponaxis: scatterAttrs.cliponaxis,
9899
fill: extendFlat({}, scatterAttrs.fill, {
99100
values: ['none', 'toself', 'tonext'],
100101
description: [

src/traces/scatterternary/defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9999
dfltHoverOn.push('fills');
100100
}
101101
coerce('hoveron', dfltHoverOn.join('+') || 'points');
102+
103+
coerce('cliponaxis');
102104
};

src/traces/scatterternary/plot.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module.exports = function plot(ternary, moduleCalcData) {
2222
var plotinfo = {
2323
xaxis: ternary.xaxis,
2424
yaxis: ternary.yaxis,
25-
plot: plotContainer
25+
plot: plotContainer,
26+
clipId: ternary.clipIdRelative,
27+
_hasClipOnAxisFalse: ternary._hasClipOnAxisFalse
2628
};
2729

2830
// add ref to ternary subplot object in fullData traces

0 commit comments

Comments
 (0)