提交 c8c5a15e 编写于 作者: S SHUANG SU 提交者: sushuang

fix:

(1) Fix that tooltip shows multiple values around both sides of the pointer. Fix #9829.
(2) Fix a probably typo (diff < maxDistance) introduced by https://github.com/apache/incubator-echarts/commit/4ef66e1d892485ced1dbfcf915135e7740bb7cc3
(3) Remove the previous logic to resolve #2869. Because currently if there are multiple values on the same axis tick, both of them will be found and displayed in tooltip by default. The related historical commits:
https://github.com/apache/incubator-echarts/commit/60d341f4ed9e33381099624962a8388eef8a9547  (fix #2869)
https://github.com/apache/incubator-echarts/commit/3426bd0e544b16f90a476cd36a79119c3570a63b  (support find multiple values on the same axis tick).
上级 ac941880
......@@ -1159,23 +1159,31 @@ listProto.indicesOfNearest = function (dim, value, maxDistance) {
maxDistance = Infinity;
}
var minDist = Number.MAX_VALUE;
var minDist = Infinity;
var minDiff = -1;
var nearestIndicesLen = 0;
for (var i = 0, len = this.count(); i < len; i++) {
var diff = value - this.get(dim, i /*, stack */);
var diff = value - this.get(dim, i);
var dist = Math.abs(diff);
if (diff <= maxDistance && dist <= minDist) {
// For the case of two data are same on xAxis, which has sequence data.
// Show the nearest index
// https://github.com/ecomfe/echarts/issues/2869
if (dist < minDist || (diff >= 0 && minDiff < 0)) {
if (dist <= maxDistance) {
// When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
// we'd better not push both of them to `nearestIndices`, otherwise it is easy to
// get more than one item in `nearestIndices` (more specifically, in `tooltip`).
// So we chose the one that `diff >= 0` in this csae.
if (dist < minDist
|| (dist === minDist && diff >= 0 && minDiff < 0)
) {
minDist = dist;
minDiff = diff;
nearestIndices.length = 0;
nearestIndicesLen = 0;
}
if (diff === minDiff) {
nearestIndices[nearestIndicesLen++] = i;
}
nearestIndices.push(i);
}
}
nearestIndices.length = nearestIndicesLen;
return nearestIndices;
};
......
......@@ -128,6 +128,7 @@
"toolbox-tooltip": 1,
"tooltip": 10,
"tooltip-axisPointer": 20,
"tooltip-axisPointer2": 1,
"tooltip-cascade": 4,
"tooltip-event": 1,
"tooltip-link": 2,
......
[{"name":"Action 1","ops":[{"type":"mousemove","time":530,"x":31,"y":450},{"type":"mousemove","time":736,"x":57,"y":450},{"type":"mousemove","time":959,"x":82,"y":449},{"type":"mousemove","time":1163,"x":92,"y":447},{"type":"mousemove","time":1389,"x":93,"y":447},{"type":"mousemove","time":1634,"x":93,"y":447},{"type":"mousemove","time":1835,"x":114,"y":448},{"type":"mousemove","time":2051,"x":131,"y":448},{"type":"mousemove","time":2278,"x":142,"y":448},{"type":"mousemove","time":2522,"x":145,"y":447},{"type":"mousemove","time":3210,"x":148,"y":447},{"type":"mousemove","time":3428,"x":155,"y":445},{"type":"mousemove","time":3631,"x":156,"y":445},{"type":"mousemove","time":3834,"x":164,"y":445},{"type":"mousemove","time":4048,"x":183,"y":442},{"type":"mousemove","time":4251,"x":212,"y":439},{"type":"mousemove","time":4459,"x":221,"y":439},{"type":"mousemove","time":4662,"x":222,"y":439},{"type":"mousemove","time":4803,"x":224,"y":439},{"type":"mousemove","time":5005,"x":256,"y":435},{"type":"mousemove","time":5209,"x":281,"y":433},{"type":"mousemove","time":5411,"x":303,"y":433},{"type":"mousemove","time":5718,"x":307,"y":433},{"type":"mousemove","time":5933,"x":328,"y":431},{"type":"mousemove","time":6147,"x":352,"y":430},{"type":"mousemove","time":6373,"x":360,"y":430},{"type":"mousemove","time":6605,"x":361,"y":430},{"type":"mousemove","time":6949,"x":361,"y":430},{"type":"mousemove","time":7182,"x":374,"y":430},{"type":"mousemove","time":7404,"x":401,"y":430},{"type":"mousemove","time":7642,"x":402,"y":430},{"type":"mousemove","time":7821,"x":405,"y":430},{"type":"mousemove","time":8024,"x":418,"y":430},{"type":"mousemove","time":8251,"x":430,"y":430},{"type":"mousemove","time":8674,"x":434,"y":430},{"type":"mousemove","time":8903,"x":448,"y":431},{"type":"mousemove","time":9104,"x":498,"y":424},{"type":"mousemove","time":9330,"x":506,"y":424},{"type":"mousemove","time":9773,"x":511,"y":424},{"type":"mousemove","time":9995,"x":523,"y":426},{"type":"mousemove","time":10207,"x":543,"y":424},{"type":"mousemove","time":10415,"x":570,"y":422},{"type":"mousemove","time":10649,"x":577,"y":422},{"type":"mousemove","time":10921,"x":581,"y":422},{"type":"mousemove","time":11149,"x":645,"y":419},{"type":"mousemove","time":11375,"x":646,"y":418}],"scrollY":0,"scrollX":0,"timestamp":1573747705006}]
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册