Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 381de10

Browse files
committed
fix ternary pan
1 parent c24e444 commit 381de10

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/plots/ternary/ternary.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ proto.init_interactions = function() {
399399
else if(dragModeNow === 'pan') {
400400
dragOptions.moveFn = plotDrag;
401401
dragOptions.doneFn = dragDone;
402+
panPrep();
402403
clearSelect();
403404
}
404405
else if(dragModeNow === 'select' || dragModeNow === 'lasso') {
@@ -413,7 +414,11 @@ proto.init_interactions = function() {
413414
var dragBBox = dragger.getBoundingClientRect();
414415
x0 = startX - dragBBox.left;
415416
y0 = startY - dragBBox.top;
416-
mins0 = {a: _this.aaxis.range[0], b: _this.baxis.range[1], c: _this.caxis.range[1]};
417+
mins0 = {
418+
a: _this.aaxis.range[0],
419+
b: _this.baxis.range[1],
420+
c: _this.caxis.range[1]
421+
};
417422
mins = mins0;
418423
span0 = _this.aaxis.range[1] - mins0.a;
419424
lum = tinycolor(_this.graphDiv._fullLayout[_this.id].bgcolor).getLuminance();
@@ -512,13 +517,22 @@ proto.init_interactions = function() {
512517
}
513518
}
514519

520+
function panPrep() {
521+
mins0 = {
522+
a: _this.aaxis.range[0],
523+
b: _this.baxis.range[1],
524+
c: _this.caxis.range[1]
525+
};
526+
mins = mins0;
527+
}
528+
515529
function plotDrag(dx, dy) {
516530
var dxScaled = dx / _this.xaxis._m,
517531
dyScaled = dy / _this.yaxis._m;
518532
mins = {
519533
a: mins0.a - dyScaled,
520-
b: mins0.b + dxScaled + dyScaled / 2,
521-
c: mins0.c - dxScaled + dyScaled / 2
534+
b: mins0.b + (dxScaled + dyScaled) / 2,
535+
c: mins0.c - (dxScaled - dyScaled) / 2
522536
};
523537
var minsorted = [mins.a, mins.b, mins.c].sort(),
524538
minindices = {
@@ -528,12 +542,12 @@ proto.init_interactions = function() {
528542
};
529543
if(minsorted[0] < 0) {
530544
if(minsorted[1] + minsorted[0] / 2 < 0) {
531-
minsorted[2] -= minsorted[0] + minsorted[1];
545+
minsorted[2] += minsorted[0] + minsorted[1];
532546
minsorted[0] = minsorted[1] = 0;
533547
}
534548
else {
535-
minsorted[2] -= minsorted[0] / 2;
536-
minsorted[1] -= minsorted[0] / 2;
549+
minsorted[2] += minsorted[0] / 2;
550+
minsorted[1] += minsorted[0] / 2;
537551
minsorted[0] = 0;
538552
}
539553
mins = {
@@ -552,8 +566,8 @@ proto.init_interactions = function() {
552566

553567
// move the ticks
554568
_this.aaxis.range = [mins.a, _this.sum - mins.b - mins.c];
555-
_this.baxis.range = [mins.b, _this.sum - mins.a - mins.c];
556-
_this.caxis.range = [mins.c, _this.sum - mins.b - mins.b];
569+
_this.baxis.range = [_this.sum - mins.a - mins.c, mins.b];
570+
_this.caxis.range = [_this.sum - mins.a - mins.b, mins.c];
557571

558572
Axes.doTicks(_this.graphDiv, _this.aaxis, true);
559573
Axes.doTicks(_this.graphDiv, _this.baxis, true);

0 commit comments

Comments
 (0)