Skip to content

Commit

Permalink
fix: fix ruler scale render
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshenhai committed Nov 19, 2023
1 parent 878f3a2 commit a5a3d16
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/core/src/middleware/ruler/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ interface RulerScale {
isSubKeyNum: boolean;
}

function calcRulerScaleList(opts: { scale: number; viewLength: number; viewOffset: number }): RulerScale[] {
function calcRulerScaleList(opts: { axis: 'X' | 'Y'; scale: number; viewLength: number; viewOffset: number }): RulerScale[] {
const { scale, viewLength, viewOffset } = opts;
const list: RulerScale[] = [];
let rulerUnit = 10;

rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
rulerUnit = Math.max(10, Math.min(rulerUnit, 1000));
rulerUnit = Math.max(1, Math.min(rulerUnit, 1000));

const rulerKeyUnit = rulerUnit * 10;
const rulerSubKeyUnit = rulerUnit * 5;
Expand All @@ -43,18 +43,15 @@ function calcRulerScaleList(opts: { scale: number; viewLength: number; viewOffse
const firstNum = (startNum - remainderNum + viewUnit) / scale;
const firstPosition = startPosition + (viewUnit - remainderNum);
while (firstPosition + index * viewUnit < viewLength) {
const num = firstNum + index * rulerUnit;
const position = firstPosition + index * viewUnit;
const num = formatNumber(firstNum + index * rulerUnit, { decimalPlaces: 0 });
const position = formatNumber(firstPosition + index * viewUnit, { decimalPlaces: 0 });
const rulerScale = {
num: formatNumber(num, { decimalPlaces: 0 }),
num,
position,
showNum: num % rulerKeyUnit === 0,
isKeyNum: num % rulerKeyUnit === 0,
isSubKeyNum: num % rulerSubKeyUnit === 0
};
// if (viewUnit >= rulerSubKeyUnit) {
// rulerScale.isKeyNum = true;
// }
list.push(rulerScale);
index++;
}
Expand All @@ -67,6 +64,7 @@ export function calcXRulerScaleList(opts: { viewScaleInfo: ViewScaleInfo; viewSi
const { scale, offsetLeft } = viewScaleInfo;
const { width } = viewSizeInfo;
return calcRulerScaleList({
axis: 'X',
scale,
viewLength: width,
viewOffset: offsetLeft
Expand All @@ -78,6 +76,7 @@ export function calcYRulerScaleList(opts: { viewScaleInfo: ViewScaleInfo; viewSi
const { scale, offsetTop } = viewScaleInfo;
const { height } = viewSizeInfo;
return calcRulerScaleList({
axis: 'Y',
scale,
viewLength: height,
viewOffset: offsetTop
Expand Down

0 comments on commit a5a3d16

Please sign in to comment.