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

Skip to content

Commit c24e444

Browse files
committed
fix ternary zoom
1 parent 7dbd964 commit c24e444

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/plots/ternary/ternary.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ var TOPPATH = 'm0,1l' + (CLEN / 2) + ',' + (CLEN * 0.87) +
362362
'l2.6,-1.5l-' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +
363363
'l-' + (CLEN / 2 + 2.6) + ',' + (CLEN * 0.87 + 4.5) +
364364
'l2.6,1.5l' + (CLEN / 2) + ',-' + (CLEN * 0.87) + 'Z';
365+
var STARTMARKER = 'm0.5,0.5h5v-2h-5v-5h-2v5h-5v2h5v5h2Z';
365366

366367
// I guess this could be shared with cartesian... but for now it's separate.
367368
var SHOWZOOMOUTTIP = true;
@@ -440,12 +441,16 @@ proto.init_interactions = function() {
440441
clearSelect();
441442
}
442443

444+
function getAFrac(x, y) { return 1 - (y / _this.h); }
445+
function getBFrac(x, y) { return 1 - ((x + (_this.h - y) / Math.sqrt(3)) / _this.w); }
446+
function getCFrac(x, y) { return ((x - (_this.h - y) / Math.sqrt(3)) / _this.w); }
447+
443448
function zoomMove(dx0, dy0) {
444449
var x1 = x0 + dx0,
445450
y1 = y0 + dy0,
446-
afrac = Math.max(0, 1 - Math.max(y0, y1) / _this.h),
447-
bfrac = Math.max(0, 1 - Math.max(x0 + y0 / Math.sqrt(3), x1 + y1 / Math.sqrt(3)) / _this.w),
448-
cfrac = Math.max(0, Math.min(x0 - y0 / Math.sqrt(3), x1 - y1 / Math.sqrt(3)) / _this.w),
451+
afrac = Math.max(0, Math.min(1, getAFrac(x0, y0), getAFrac(x1, y1))),
452+
bfrac = Math.max(0, Math.min(1, getBFrac(x0, y0), getBFrac(x1, y1))),
453+
cfrac = Math.max(0, Math.min(1, getCFrac(x0, y0), getCFrac(x1, y1))),
449454
xLeft = ((afrac / 2) + cfrac) * _this.w,
450455
xRight = (1 - (afrac / 2) - bfrac) * _this.w,
451456
xCenter = (xLeft + xRight) / 2,
@@ -467,7 +472,8 @@ proto.init_interactions = function() {
467472
zb.attr('d', path0 + 'M' + xLeft + ',' + yBottom +
468473
'H' + xRight + 'L' + xCenter + ',' + yTop +
469474
'L' + xLeft + ',' + yBottom + 'Z');
470-
corners.attr('d', 'M' + xLeft + ',' + yBottom + BLPATH +
475+
corners.attr('d', 'M' + x0 + ',' + y0 + STARTMARKER +
476+
'M' + xLeft + ',' + yBottom + BLPATH +
471477
'M' + xRight + ',' + yBottom + BRPATH +
472478
'M' + xCenter + ',' + yTop + TOPPATH);
473479
}

0 commit comments

Comments
 (0)