Skip to content

Commit

Permalink
fix: getSnapRecords() - pick data more accurate in pie chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed May 8, 2018
1 parent 4201494 commit d3d6ddc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/geom/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,16 @@ class Geom extends Base {

// 特别针对饼图做处理
if (this.hasAdjust('stack') && coord.isPolar && coord.transposed && xScale.values.length === 1) {
let yValue = yScale.invert(invertPoint.y);
yValue = self._getSnap(yScale, yValue, tmp);
tmp.forEach(function(obj) {
if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
rst.push(obj);
}
});
if (invertPointX >= 0 && invertPointX <= 1) { // 精确拾取
let yValue = yScale.invert(invertPoint.y);
yValue = self._getSnap(yScale, yValue, tmp);
tmp.forEach(obj => {
if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
rst.push(obj);
}
});
}

} else {
rst = tmp;
}
Expand Down
7 changes: 4 additions & 3 deletions test/bug/issue-67-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ describe('getSnapRecords', () => {

let records;
canvas.onclick = ev => {
const point = chart.get('canvas').getPointByClient(ev.clientX, ev.clientY);
const point = F2.Util.getRelativePosition({ x: ev.clientX, y: ev.clientY }, chart.get('canvas'));
records = chart.getSnapRecords(point);
console.log(records);
};

gestureSimulator(canvas, 'click', {
clientX: 231,
clientY: 61
clientX: 218,
clientY: 52
});

setTimeout(function() {
Expand Down

0 comments on commit d3d6ddc

Please sign in to comment.