Skip to content

Commit

Permalink
avoid tooltip truncation if possible
Browse files Browse the repository at this point in the history
use whole chart area for displaying tooltip
  • Loading branch information
kaidohallik committed Mar 12, 2017
1 parent a6473fa commit 996927c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/core/core.tooltip.js
Expand Up @@ -328,9 +328,10 @@ module.exports = function(Chart) {
/**
* @Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
*/
function getBackgroundPoint(vm, size, alignment) {
function getBackgroundPoint(vm, size, alignment, chart) {
// Background Position
var x = vm.x;
var xCaret;
var y = vm.y;

var caretSize = vm.caretSize,
Expand All @@ -345,6 +346,13 @@ module.exports = function(Chart) {
x -= size.width;
} else if (xAlign === 'center') {
x -= (size.width / 2);
xCaret = x;
if (x + size.width > chart.width) {
x = chart.width - size.width;
}
if (x < 0) {
x = 0;
}
}

if (yAlign === 'top') {
Expand All @@ -369,6 +377,7 @@ module.exports = function(Chart) {

return {
x: x,
xCaret: xCaret,
y: y
};
}
Expand Down Expand Up @@ -469,6 +478,7 @@ module.exports = function(Chart) {
};
var backgroundPoint = {
x: existingModel.x,
xCaret: existingModel.xCaret,
y: existingModel.y
};
var tooltipSize = {
Expand Down Expand Up @@ -532,14 +542,15 @@ module.exports = function(Chart) {
tooltipSize = getTooltipSize(this, model);
alignment = determineAlignment(this, tooltipSize);
// Final Size and Position
backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment);
backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
} else {
model.opacity = 0;
}

model.xAlign = alignment.xAlign;
model.yAlign = alignment.yAlign;
model.x = backgroundPoint.x;
model.xCaret = backgroundPoint.xCaret;
model.y = backgroundPoint.y;
model.width = tooltipSize.width;
model.height = tooltipSize.height;
Expand Down Expand Up @@ -605,7 +616,11 @@ module.exports = function(Chart) {
x1 = x2 - caretSize;
x3 = x2 + caretSize;
} else {
x2 = ptX + (width / 2);
if (tooltipPoint.xCaret) {
x2 = tooltipPoint.xCaret + (width / 2);
} else {
x2 = ptX + (width / 2);
}
x1 = x2 - caretSize;
x3 = x2 + caretSize;
}
Expand Down Expand Up @@ -783,6 +798,7 @@ module.exports = function(Chart) {
};
var pt = {
x: vm.x,
xCaret: vm.xCaret,
y: vm.y
};

Expand Down

0 comments on commit 996927c

Please sign in to comment.