优化代码
This commit is contained in:
parent
b7d2f79462
commit
9917926a43
@ -63,14 +63,15 @@ class Vernier extends graphic.Group {
|
||||
const minY = rect.y;
|
||||
const maxX = rect.x + rect.width;
|
||||
const maxY = rect.y + rect.height;
|
||||
const direction = (Math.abs(rect.width)/rect.width);
|
||||
const directionX = (Math.abs(rect.width)/rect.width);
|
||||
const directionY = (Math.abs(rect.height)/rect.height);
|
||||
const axisLineWidthHalf = vernierStyle.axisLine.lineStyle.lineWidth/this._scaleRate/2;
|
||||
|
||||
this._axisLineX = new graphic.Line({
|
||||
...shapeRender,
|
||||
z: 9999,
|
||||
silent: true,
|
||||
position: [0, -axisLineWidthHalf*direction],
|
||||
position: [0, -axisLineWidthHalf*directionY],
|
||||
shape: {
|
||||
x1: minX,
|
||||
y1: minY,
|
||||
@ -82,11 +83,11 @@ class Vernier extends graphic.Group {
|
||||
}
|
||||
})
|
||||
|
||||
const step = 4/this._scaleRate;
|
||||
const step = vernierStyle.axisTick.lineStyle.lineWidth*2/this._scaleRate;
|
||||
const count = parseInt(Math.abs(rect.width/step));
|
||||
|
||||
for(var i = 0; i in new Array(count+1).fill(0); i++) {
|
||||
const offset = step * i * direction;
|
||||
const offset = step * i * directionX;
|
||||
const tick = i % vernierStyle.axisTick.length == 0
|
||||
const len = tick? vernierStyle.axisTick.distance*0.7: vernierStyle.axisTick.distance*0.5;
|
||||
if (tick) {
|
||||
@ -98,13 +99,13 @@ class Vernier extends graphic.Group {
|
||||
x1: minX + offset,
|
||||
y1: minY,
|
||||
x2: minX + offset,
|
||||
y2: minY - len * direction / this._scaleRate
|
||||
y2: minY - len * directionY / this._scaleRate
|
||||
},
|
||||
style: {
|
||||
...vernierStyle.axisTick.lineStyle,
|
||||
...vernierStyle.axisLabel.textStyle,
|
||||
text: i%2? '': i/vernierStyle.axisTick.length/2,
|
||||
textPosition: direction > 0? 'top': 'bottom'
|
||||
textPosition: directionY > 0? 'top': 'bottom'
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
@ -116,7 +117,7 @@ class Vernier extends graphic.Group {
|
||||
x1: minX + offset,
|
||||
y1: minY,
|
||||
x2: minX + offset,
|
||||
y2: minY - len * direction / this._scaleRate
|
||||
y2: minY - len * directionY / this._scaleRate
|
||||
},
|
||||
style: {
|
||||
...vernierStyle.axisTick.lineStyle
|
||||
@ -133,14 +134,15 @@ class Vernier extends graphic.Group {
|
||||
const minY = rect.y;
|
||||
const maxX = rect.x + rect.width;
|
||||
const maxY = rect.y + rect.height;
|
||||
const direction = (Math.abs(rect.width)/rect.width);
|
||||
const directionX = (Math.abs(rect.width)/rect.width);
|
||||
const directionY = (Math.abs(rect.height)/rect.height);
|
||||
const axisLineWidthHalf = vernierStyle.axisLine.lineStyle.lineWidth/this._scaleRate/2;
|
||||
|
||||
this._axisLineY = new graphic.Line({
|
||||
...shapeRender,
|
||||
z: 9999,
|
||||
silent: true,
|
||||
position: [-axisLineWidthHalf*direction, 0],
|
||||
position: [-axisLineWidthHalf*directionX, 0],
|
||||
shape: {
|
||||
x1: minX,
|
||||
y1: minY,
|
||||
@ -154,11 +156,11 @@ class Vernier extends graphic.Group {
|
||||
this.add(this._axisLineY);
|
||||
|
||||
|
||||
const step = 4/this._scaleRate;
|
||||
const step = vernierStyle.axisTick.lineStyle.lineWidth*2 /this._scaleRate;
|
||||
const count = parseInt(Math.abs(rect.height/step));
|
||||
|
||||
for(var i = 0; i in new Array(count+1).fill(0); i++) {
|
||||
const offset = step * i * direction;
|
||||
const offset = step * i * directionY;
|
||||
const tick = i % vernierStyle.axisTick.length == 0;
|
||||
const len = tick? vernierStyle.axisTick.distance*0.7: vernierStyle.axisTick.distance*0.5;
|
||||
if (tick) {
|
||||
@ -169,14 +171,14 @@ class Vernier extends graphic.Group {
|
||||
shape: {
|
||||
x1: minX,
|
||||
y1: minY + offset,
|
||||
x2: minX - len * direction / this._scaleRate,
|
||||
x2: minX - len * directionX / this._scaleRate,
|
||||
y2: minY + offset
|
||||
},
|
||||
style: {
|
||||
...vernierStyle.axisTick.lineStyle,
|
||||
...vernierStyle.axisLabel.textStyle,
|
||||
text: i%2? '': i/vernierStyle.axisTick.length/2,
|
||||
textPosition: direction > 0? 'left': 'right'
|
||||
textPosition: directionX > 0? 'left': 'right'
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
@ -187,7 +189,7 @@ class Vernier extends graphic.Group {
|
||||
shape: {
|
||||
x1: minX,
|
||||
y1: minY + offset,
|
||||
x2: minX - len * direction / this._scaleRate,
|
||||
x2: minX - len * directionX / this._scaleRate,
|
||||
y2: minY + offset
|
||||
},
|
||||
style: {
|
||||
|
Loading…
Reference in New Issue
Block a user