Skip to content

Commit 5380851

Browse files
committed
亚像素优化
1 parent fb8ca42 commit 5380851

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/component/base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,11 @@ define(function(require) {
889889
// 亚像素优化
890890
function subPixelOptimize(position, lineWidth) {
891891
if (lineWidth % 2 == 1) {
892-
position += position == Math.ceil(position) ? 0.5 : 0;
892+
//position += position == Math.ceil(position) ? 0.5 : 0;
893+
position = Math.floor(position) + 0.5;
894+
}
895+
else {
896+
position = Math.round(position);
893897
}
894898
return position;
895899
}

src/component/categoryAxis.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,15 @@ define(function (require) {
625625

626626
// 根据类目轴数据索引换算位置
627627
function getCoordByIndex(dataIndex) {
628-
if (dataIndex < 0) {
628+
if (dataIndex <= 0) {
629629
if (option.position == 'bottom' || option.position == 'top') {
630630
return grid.getX();
631631
}
632632
else {
633633
return grid.getYend();
634634
}
635635
}
636-
else if (dataIndex >= option.data.length) {
636+
else if (dataIndex >= option.data.length - 1) {
637637
if (option.position == 'bottom' || option.position == 'top') {
638638
return grid.getXend();
639639
}
@@ -644,7 +644,6 @@ define(function (require) {
644644
else {
645645
var gap = getGap();
646646
var position = option.boundaryGap ? gap : 0;
647-
648647
position += dataIndex * gap;
649648

650649
if (option.position == 'bottom'
@@ -657,12 +656,7 @@ define(function (require) {
657656
// 纵向
658657
position = grid.getYend() - position;
659658
}
660-
661-
return (dataIndex === 0 || dataIndex == option.data.length - 1)
662-
? position
663-
: Math.floor(position);
664-
665-
// return getCoord(option.data[dataIndex]);
659+
return Math.floor(position);
666660
}
667661
}
668662

src/component/tooltip.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ define(function (require) {
6666
var _zrWidth = zr.getWidth();
6767

6868
var _lastTipShape = false;
69+
var _axisLineWidth = 0;
6970
var _axisLineShape = {
7071
shape : 'line',
7172
id : zr.newShapeId('tooltip'),
@@ -513,7 +514,10 @@ define(function (require) {
513514
}
514515
);
515516
y = zrEvent.getY(_event) + 10;
516-
x = categoryAxis.getCoordByIndex(dataIndex);
517+
x = self.subPixelOptimize(
518+
categoryAxis.getCoordByIndex(dataIndex),
519+
_axisLineWidth
520+
);
517521
_styleAxisPointer(
518522
seriesArray,
519523
x, grid.getY(),
@@ -567,7 +571,10 @@ define(function (require) {
567571
}
568572
);
569573
x = zrEvent.getX(_event) + 10;
570-
y = categoryAxis.getCoordByIndex(dataIndex);
574+
y = self.subPixelOptimize(
575+
categoryAxis.getCoordByIndex(dataIndex),
576+
_axisLineWidth
577+
);
571578
_styleAxisPointer(
572579
seriesArray,
573580
grid.getX(), y,
@@ -1303,6 +1310,8 @@ define(function (require) {
13031310
_tDom.style.position = 'absolute'; // 不是多余的,别删!
13041311
self.hasAppend = false;
13051312
_setSelectedMap();
1313+
1314+
_axisLineWidth = option.tooltip.axisPointer.lineStyle.width;
13061315
}
13071316

13081317
/**
@@ -1325,6 +1334,7 @@ define(function (require) {
13251334
option.tooltip.padding
13261335
);
13271336
_setSelectedMap();
1337+
_axisLineWidth = option.tooltip.axisPointer.lineStyle.width;
13281338
}
13291339
}
13301340

0 commit comments

Comments
 (0)