Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/13780-tooltip-reversed-y #14432

Merged
merged 4 commits into from Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 50 additions & 6 deletions samples/unit-tests/axis/reversed/demo.js
@@ -1,6 +1,16 @@
QUnit.test(
'Reversed yAxis for bar charts cause detached columns from axis (#4504)',
function (assert) {

const tooltipCenter = tooltip => {
const label = tooltip.getLabel();
return [
label.translateX + label.width / 2,
label.translateY + label.height / 2
];
};


var options = {
chart: {
type: 'column'
Expand All @@ -21,7 +31,6 @@ QUnit.test(
]
},
charts = [],
point,
y,
height,
container1,
Expand Down Expand Up @@ -50,9 +59,10 @@ QUnit.test(
charts[3] = $(container4).highcharts(options).highcharts();

$.each([charts[0], charts[3]], function (i, chart) {
point = chart.series[0].data[1].graphic;
y = parseFloat(point.attr('y'));
height = parseFloat(point.attr('height'));
const point = chart.series[0].data[1],
graphic = point.graphic;
y = parseFloat(graphic.attr('y'));
height = parseFloat(graphic.attr('height'));
assert.strictEqual(
y + height > chart.plotHeight,
true,
Expand All @@ -69,11 +79,28 @@ QUnit.test(
0,
'Zero point should be zero height (#4656)'
);

// Test tooltip position
point.onMouseOver();
if (chart.inverted) {
assert.ok(
tooltipCenter(chart.tooltip)[0] >
point.tooltipPos[0] + chart.plotLeft,
'The tooltip should be right to the graphic'
);
} else {
assert.ok(
tooltipCenter(chart.tooltip)[1] <
point.tooltipPos[1] + chart.plotTop,
'The tooltip should be above the graphic'
);
}
});

$.each([charts[1], charts[2]], function (i, chart) {
point = chart.series[0].data[1].graphic;
y = parseFloat(point.attr('y'));
const point = chart.series[0].data[1],
graphic = point.graphic;
y = parseFloat(graphic.attr('y'));
assert.strictEqual(
y < 0,
true,
Expand All @@ -90,6 +117,23 @@ QUnit.test(
0,
'Zero point should be zero height (#4656)'
);


// Test tooltip position
point.onMouseOver();
if (chart.inverted) {
assert.ok(
tooltipCenter(chart.tooltip)[0] <
point.tooltipPos[0] + chart.plotLeft,
'The tooltip should be left to the graphic'
);
} else {
assert.ok(
tooltipCenter(chart.tooltip)[1] >
point.tooltipPos[1] + chart.plotTop,
'The tooltip should be below the graphic'
);
}
});

// Clean up
Expand Down
15 changes: 13 additions & 2 deletions ts/Core/Tooltip.ts
Expand Up @@ -688,10 +688,21 @@ class Tooltip {
let first = buildDimensionArray('y'),
second = buildDimensionArray('x'),
swapped: (boolean|undefined);

// Handle negative points or reversed axis (#13780)
let flipped = !!point.negative;
if (
chart.hoverSeries &&
chart.hoverSeries.yAxis &&
chart.hoverSeries.yAxis.reversed
) {
flipped = !flipped;
}
// The far side is right or bottom
const preferFarSide = !this.followPointer && pick(
const preferFarSide = !this.followPointer &&
pick(
point.ttBelow,
!chart.inverted === !!point.negative
!chart.inverted === flipped
), // #4984

/*
Expand Down
13 changes: 0 additions & 13 deletions ts/Series/MapBubble/MapBubblePoint.ts
Expand Up @@ -88,19 +88,6 @@ class MapBubblePoint extends BubbleSeries.prototype.pointClass {

}

/* *
*
* Class Prototype
*
* */

interface MapBubblePoint {
ttBelow: boolean;
}
extend(MapBubblePoint.prototype, {
ttBelow: false
});

/* *
*
* Default Export
Expand Down
1 change: 1 addition & 0 deletions ts/Series/XRange/XRangePoint.ts
Expand Up @@ -234,6 +234,7 @@ interface XRangePoint {

}
extend(XRangePoint.prototype, {
ttBelow: false,
tooltipDateKeys: ['x', 'x2']
});

Expand Down