|
@@ -18,7 +18,7 @@ export type ScaleAttrib = {
|
|
|
|
|
|
export class Scale extends Entity<ScaleAttrib, Group> {
|
|
|
private mat: Transform;
|
|
|
- pixelScale = { value: 0, unit: "" };
|
|
|
+ pixelScale: number;
|
|
|
allowable = 0.001;
|
|
|
private fontSize = 12;
|
|
|
private padding = 4;
|
|
@@ -40,11 +40,11 @@ export class Scale extends Entity<ScaleAttrib, Group> {
|
|
|
|
|
|
getScaleUnit = (pixelScale: number[]) => {
|
|
|
const scale = Math.max(...pixelScale);
|
|
|
- // const value = round(scale, 3);
|
|
|
- return {
|
|
|
- value: scale * 10000,
|
|
|
- unit: "",
|
|
|
- };
|
|
|
+ return scale * 10000;
|
|
|
+ };
|
|
|
+
|
|
|
+ getScaleText = (value: number) => {
|
|
|
+ return value + "";
|
|
|
};
|
|
|
|
|
|
initShape() {
|
|
@@ -87,15 +87,15 @@ export class Scale extends Entity<ScaleAttrib, Group> {
|
|
|
}
|
|
|
|
|
|
diffRedraw() {
|
|
|
- if (!this.mat || !this.pixelScale || isNaN(this.pixelScale.value)) return;
|
|
|
+ if (!this.mat || !this.pixelScale || isNaN(this.pixelScale)) return;
|
|
|
|
|
|
let minDeviation = 1;
|
|
|
let width;
|
|
|
let realWidth;
|
|
|
for (let w = this.attrib.minWidth; w <= this.attrib.maxWidth; w++) {
|
|
|
- const rw = w * this.pixelScale.value;
|
|
|
+ const rw = w * this.pixelScale;
|
|
|
const deviation = round(rw, 10) - rw;
|
|
|
- if (deviation < this.allowable) {
|
|
|
+ if (deviation < this.allowable && rw % 5 < 1) {
|
|
|
width = w;
|
|
|
realWidth = rw;
|
|
|
break;
|
|
@@ -105,13 +105,13 @@ export class Scale extends Entity<ScaleAttrib, Group> {
|
|
|
minDeviation = deviation;
|
|
|
}
|
|
|
}
|
|
|
- if (realWidth < 10) {
|
|
|
- realWidth = round(realWidth, 2);
|
|
|
- } else if (realWidth < 100) {
|
|
|
- realWidth = round(realWidth, 1);
|
|
|
- } else {
|
|
|
- realWidth = round(realWidth, 0);
|
|
|
- }
|
|
|
+ // if (realWidth < 10) {
|
|
|
+ // realWidth = round(realWidth, 2);
|
|
|
+ // } else if (realWidth < 100) {
|
|
|
+ // realWidth = round(realWidth, 1);
|
|
|
+ // } else {
|
|
|
+ // realWidth = round(realWidth, 0);
|
|
|
+ // }
|
|
|
|
|
|
if (width === 0 || realWidth === 0) return;
|
|
|
|
|
@@ -122,7 +122,7 @@ export class Scale extends Entity<ScaleAttrib, Group> {
|
|
|
points[4] = points[6] = width;
|
|
|
|
|
|
text.width(width);
|
|
|
- text.text(realWidth + this.pixelScale.unit);
|
|
|
+ text.text(this.getScaleText(realWidth));
|
|
|
|
|
|
const stage = this.container.stage;
|
|
|
let x = this.attrib.left;
|