Ответ 1
Позиционер подсказки гораздо больше, чем просто позиция по умолчанию. Аргументы функции содержат информацию о ваших положениях точки и размерах всплывающих подсказок, с помощью которых было бы довольно просто поместить ее вправо.
Highchart/stock позволяет вам определить ваш альтернативный позиционер следующим образом
tooltip:{
positioner:function(boxWidth, boxHeight, point){
...
}
}
Обратите внимание, что у вас есть три аргумента (boxWidth, boxHeight, point), которые вам кажутся достаточными для большинства случаев использования, чтобы вычислить нужную позицию всплывающей подсказки. boxWidth и boxHeight - это ширина и высота, которые потребуются вашей подсказке, поэтому вы можете использовать их для кросс-футляров, чтобы настроить всплывающую подсказку и не допустить ее выплескивания из графика или даже худшего обрезания.
Позиционер подсказки по умолчанию, который поставляется с highstock, выглядит следующим образом (Источник)
/**
* Place the tooltip in a chart without spilling over
* and not covering the point it self.
*/
getPosition: function (boxWidth, boxHeight, point) {
// Set up the variables
var chart = this.chart,
plotLeft = chart.plotLeft,
plotTop = chart.plotTop,
plotWidth = chart.plotWidth,
plotHeight = chart.plotHeight,
distance = pick(this.options.distance, 12), // You can use a number directly here, as you may not be able to use pick, as its an internal highchart function
pointX = point.plotX,
pointY = point.plotY,
x = pointX + plotLeft + (chart.inverted ? distance : -boxWidth - distance),
y = pointY - boxHeight + plotTop + 15, // 15 means the point is 15 pixels up from the bottom of the tooltip
alignedRight;
// It is too far to the left, adjust it
if (x < 7) {
x = plotLeft + pointX + distance;
}
// Test to see if the tooltip is too far to the right,
// if it is, move it back to be inside and then up to not cover the point.
if ((x + boxWidth) > (plotLeft + plotWidth)) {
x -= (x + boxWidth) - (plotLeft + plotWidth);
y = pointY - boxHeight + plotTop - distance;
alignedRight = true;
}
// If it is now above the plot area, align it to the top of the plot area
if (y < plotTop + 5) {
y = plotTop + 5;
// If the tooltip is still covering the point, move it below instead
if (alignedRight && pointY >= y && pointY <= (y + boxHeight)) {
y = pointY + plotTop + distance; // below
}
}
// Now if the tooltip is below the chart, move it up. It better to cover the
// point than to disappear outside the chart. #834.
if (y + boxHeight > plotTop + plotHeight) {
y = mathMax(plotTop, plotTop + plotHeight - boxHeight - distance); // below
}
return {x: x, y: y};
}
Со всей приведенной выше информацией, я думаю, у вас есть достаточные инструменты для реализации вашего требования, просто изменив эту функцию, чтобы сделать float справа, а не по умолчанию.
Я продолжу и дам вам простую реализацию подсказки позиционирования вправо, вы сможете реализовать крайние случаи на основе последующего кода позиционирования всплывающей подсказки по умолчанию
tooltip: {
positioner: function(boxWidth, boxHeight, point) {
return {x:point.plotX + 20,y:point.plotY};
}
}
Подробнее @Настройка Highcharts - Позиционирование подсказки