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