@inweb/viewer-visualize 26.11.0 → 26.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,9 +5,8 @@ export declare class MeasureLineItem {
5
5
  protected htmlElemTitle: HTMLElement;
6
6
  protected startPoint: number[];
7
7
  protected endPoint: number[];
8
- protected scale: number;
9
8
  protected unit: string;
10
- protected precision: any;
9
+ protected scale: number;
11
10
  protected size: number;
12
11
  protected style: CSSStyleDeclaration;
13
12
  protected viewer: any;
@@ -18,8 +17,6 @@ export declare class MeasureLineItem {
18
17
  constructor(targetElement: HTMLElement, viewer: any, moduleInstance: any);
19
18
  drawMeasureLine(): void;
20
19
  getDistance(): number;
21
- calculatePrecision(value: number): number;
22
- formatDistance(distance: number): string;
23
20
  setStartPoint(gePoint: number[]): void;
24
21
  setEndPoint(gePoint: number[], isFinish: boolean): void;
25
22
  update(): void;
@@ -27,7 +24,6 @@ export declare class MeasureLineItem {
27
24
  clear(): void;
28
25
  setUnit(unit: string): void;
29
26
  setConversionFactor(scale: number): void;
30
- setPrecision(precision: any): void;
31
27
  setStyle(style: CSSStyleDeclaration): void;
32
28
  setSelectionReactor(reactor: any): void;
33
29
  setSelectability(enable: boolean): void;
@@ -6,13 +6,12 @@ export declare class MeasureLineDragger extends OdBaseDragger {
6
6
  protected gripingRadius: number;
7
7
  protected firstPoint: number[];
8
8
  protected secondPoint: number[];
9
+ protected renameUnitTable: any;
9
10
  protected items: MeasureLineItem[];
10
11
  protected m_overlayElement: HTMLElement;
11
12
  protected previewMeasureLine: MeasureLineItem;
12
13
  protected conversionFactor: number;
13
- protected rulerUnitTable: any;
14
- protected rulerUnit: string;
15
- protected rulerPrecision: any;
14
+ protected oldRulerUnit: string;
16
15
  constructor(subject: Viewer);
17
16
  initialize(): void;
18
17
  dispose(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "26.11.0",
3
+ "version": "26.11.1",
4
4
  "description": "JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -29,10 +29,10 @@
29
29
  "docs": "typedoc"
30
30
  },
31
31
  "dependencies": {
32
- "@inweb/client": "~26.11.0",
33
- "@inweb/eventemitter2": "~26.11.0",
34
- "@inweb/markup": "~26.11.0",
35
- "@inweb/viewer-core": "~26.11.0"
32
+ "@inweb/client": "~26.11.1",
33
+ "@inweb/eventemitter2": "~26.11.1",
34
+ "@inweb/markup": "~26.11.1",
35
+ "@inweb/viewer-core": "~26.11.1"
36
36
  },
37
- "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
37
+ "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/26.11/Visualize.js"
38
38
  }
@@ -20,7 +20,6 @@
20
20
  // By use of this software, its documentation or related materials, you
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
-
24
23
  import * as utils from "./MeasureUtils";
25
24
 
26
25
  export class MeasureLineItem {
@@ -30,9 +29,8 @@ export class MeasureLineItem {
30
29
  protected htmlElemTitle: HTMLElement;
31
30
  protected startPoint: number[];
32
31
  protected endPoint: number[];
33
- protected scale: number;
34
32
  protected unit: string;
35
- protected precision: any;
33
+ protected scale: number;
36
34
  protected size: number;
37
35
  protected style: CSSStyleDeclaration;
38
36
  protected viewer: any;
@@ -51,9 +49,8 @@ export class MeasureLineItem {
51
49
  this.startPoint = null;
52
50
  this.endPoint = null;
53
51
 
54
- this.scale = 1.0;
55
52
  this.unit = "";
56
- this.precision = 2;
53
+ this.scale = 1.0;
57
54
  this.size = 10.0;
58
55
  this.lineThickness = 2;
59
56
 
@@ -156,11 +153,13 @@ export class MeasureLineItem {
156
153
  this.htmlElemLine.style.zIndex = "1";
157
154
  this.htmlElemLine.style.height = `${height}px`;
158
155
 
159
- const distance = this.getDistance();
156
+ const distance = `${this.getDistance()} ${this.unit}`;
160
157
 
161
158
  const pX = p1.x + dx / 2;
162
159
  const pY = p1.y + dy / 2;
163
160
 
161
+ const widthTitle = distance.length * 10;
162
+
164
163
  this.htmlElemTitle = utils.createHtmlElementIfNeed(this.htmlElemTitle, this.targetElement, "ruler-value");
165
164
  this.htmlElemTitle.style.display = "block";
166
165
  this.htmlElemTitle.style.cursor = "pointer";
@@ -168,8 +167,9 @@ export class MeasureLineItem {
168
167
  this.htmlElemTitle.style.color = "white";
169
168
  this.htmlElemTitle.style.position = "Absolute";
170
169
  this.htmlElemTitle.style.top = `${pY}px`;
171
- this.htmlElemTitle.style.left = `${pX}px`;
172
- this.htmlElemTitle.style.transform = "translate(-50%, -50%)";
170
+ this.htmlElemTitle.style.left = `${pX - widthTitle / 2}px`;
171
+ this.htmlElemTitle.style.width = `${widthTitle}px`;
172
+ this.htmlElemTitle.style.transformOrigin = "0px 0px";
173
173
  this.htmlElemTitle.style.borderRadius = "5px";
174
174
  this.htmlElemTitle.style.boxShadow = this.style.boxShadow;
175
175
  this.htmlElemTitle.style.border = "none";
@@ -177,7 +177,7 @@ export class MeasureLineItem {
177
177
  this.htmlElemTitle.style.zIndex = "3";
178
178
  this.htmlElemTitle.style.padding = "2px";
179
179
  this.htmlElemTitle.style.textAlign = "center";
180
- this.htmlElemTitle.innerHTML = this.formatDistance(distance);
180
+ this.htmlElemTitle.innerHTML = `${distance}`;
181
181
  } else {
182
182
  this.htmlElemLine.style.display = "none";
183
183
  this.htmlElemTitle.style.display = "none";
@@ -187,37 +187,11 @@ export class MeasureLineItem {
187
187
 
188
188
  getDistance(): number {
189
189
  let distance = utils.getDistance(this.startPoint, this.endPoint, this.moduleInstance);
190
- if (Math.abs(this.scale) > 1e-10) distance /= this.scale;
191
- return distance;
192
- }
193
-
194
- calculatePrecision(value: number) {
195
- const distance = Math.abs(value);
196
-
197
- if (distance >= 1000) return 0;
198
- if (distance >= 10) return 1;
199
- if (distance >= 0.1) return 2;
200
- if (distance >= 0.001) return 3;
201
-
202
- return distance > 0 ? Math.floor(-Math.log10(distance)) + 1 : 2;
203
- }
204
-
205
- formatDistance(distance: number): string {
206
- let digits: number;
207
-
208
- if (this.precision === "Auto") digits = this.calculatePrecision(distance);
209
- else if (Number.isFinite(this.precision)) digits = this.precision;
210
- else digits = parseFloat(this.precision);
211
-
212
- if (!Number.isFinite(digits)) digits = 2;
213
- else if (digits < 0) digits = 0;
214
- else if (digits > 10) digits = 10;
215
-
216
- let result = distance.toFixed(digits);
217
- if (this.precision === "Auto") result = result.replace(/\.0+$/, "").replace(/\.$/, "");
218
- if (+result !== distance) result = "~ " + result;
190
+ if (Math.abs(this.scale - 1.0) > 10e-5) {
191
+ distance = (distance / this.scale).toFixed(2);
192
+ }
219
193
 
220
- return `${result} ${this.unit}`;
194
+ return distance;
221
195
  }
222
196
 
223
197
  setStartPoint(gePoint: number[]): void {
@@ -259,11 +233,6 @@ export class MeasureLineItem {
259
233
  this.drawMeasureLine();
260
234
  }
261
235
 
262
- setPrecision(precision: any): void {
263
- this.precision = precision;
264
- this.drawMeasureLine();
265
- }
266
-
267
236
  setStyle(style: CSSStyleDeclaration): void {
268
237
  this.style = style;
269
238
  this.drawMeasureLine();
@@ -34,24 +34,22 @@ export class MeasureLineDragger extends OdBaseDragger {
34
34
  protected gripingRadius: number;
35
35
  protected firstPoint: number[];
36
36
  protected secondPoint: number[];
37
+ protected renameUnitTable: any;
37
38
  protected items: MeasureLineItem[];
38
39
  protected m_overlayElement: HTMLElement;
39
40
  protected previewMeasureLine: MeasureLineItem;
40
41
  protected conversionFactor: number;
41
- protected rulerUnitTable: any;
42
- protected rulerUnit: string;
43
- protected rulerPrecision: any;
42
+ protected oldRulerUnit: string;
44
43
 
45
44
  constructor(subject: Viewer) {
46
45
  super(subject);
47
-
48
46
  this.lineThickness = 2;
49
47
  this.press = false;
50
48
  this.gripingRadius = 5.0;
51
49
  this.firstPoint = null;
52
50
  this.secondPoint = null;
53
51
 
54
- this.rulerUnitTable = {
52
+ this.renameUnitTable = {
55
53
  Millimeters: "mm",
56
54
  Centimeters: "cm",
57
55
  Meters: "m",
@@ -61,16 +59,14 @@ export class MeasureLineDragger extends OdBaseDragger {
61
59
  Kilometers: "km",
62
60
  Miles: "mi",
63
61
  Micrometers: "µm",
64
- Mils: "mil",
65
62
  MicroInches: "µin",
66
63
  Default: "unit",
67
64
  };
68
65
 
69
- this.rulerUnit = subject.options.rulerUnit ?? "Default";
70
- this.rulerPrecision = subject.options.rulerPrecision ?? "Default";
71
-
72
66
  this.items = [];
73
- this.canvasEvents.push("resize", "optionsChange");
67
+ this.canvasEvents.push("resize");
68
+ this.oldRulerUnit = subject.options.rulerUnit ?? "Default";
69
+ this.optionsChange = this.optionsChange.bind(this);
74
70
  }
75
71
 
76
72
  override initialize(): void {
@@ -178,14 +174,9 @@ export class MeasureLineDragger extends OdBaseDragger {
178
174
  createMeasureLine(): MeasureLineItem {
179
175
  const viewer = this.m_module.getViewer();
180
176
  const item = new MeasureLineItem(this.m_overlayElement, viewer, this.m_module);
181
-
182
177
  item.lineThickness = this.lineThickness || item.lineThickness;
183
-
184
- const isDefaultUnit = this.rulerUnit === "Default";
185
- const isDefaultPrecision = this.rulerPrecision === "Default";
186
-
187
- item.setUnit(renameUnit(this.rulerUnitTable, isDefaultUnit ? viewer.getUnit() : this.rulerUnit));
188
-
178
+ const isDefaultUnit = !this.subject.options.rulerUnit || this.subject.options.rulerUnit === "Default";
179
+ item.setUnit(renameUnit(this.renameUnitTable, isDefaultUnit ? viewer.getUnit() : this.subject.options.rulerUnit));
189
180
  if (!isDefaultUnit) {
190
181
  const fromUnit = this.getKUnitByName(viewer.getUnit());
191
182
  const toUnit = this.getKUnitByName(this.subject.options.rulerUnit);
@@ -195,13 +186,6 @@ export class MeasureLineDragger extends OdBaseDragger {
195
186
  } else {
196
187
  item.setConversionFactor(1.0);
197
188
  }
198
-
199
- if (!isDefaultPrecision) {
200
- item.setPrecision(this.rulerPrecision);
201
- } else {
202
- item.setPrecision(2);
203
- }
204
-
205
189
  this.items.push(item);
206
190
  return item;
207
191
  }
@@ -209,38 +193,22 @@ export class MeasureLineDragger extends OdBaseDragger {
209
193
  optionsChange(event): void {
210
194
  const options: IOptions = event.data;
211
195
  const toUnitName = options.rulerUnit ?? "Default";
212
- const toPrecision = options.rulerPrecision ?? "Default";
213
-
214
- const unitChanged = this.rulerUnit !== toUnitName;
215
- const precisionChanged = this.rulerPrecision !== toPrecision;
216
-
217
- if (!unitChanged && !precisionChanged) return;
218
-
219
- this.rulerUnit = toUnitName;
220
- this.rulerPrecision = toPrecision;
196
+ if (this.oldRulerUnit === toUnitName) return;
197
+ this.oldRulerUnit = toUnitName;
221
198
 
222
199
  const drawingUnit = this.m_module.getViewer().getUnit();
223
200
  const eToUnit = this.getKUnitByName(toUnitName);
224
201
  const eFromUnit = this.getKUnitByName(drawingUnit);
225
202
 
226
203
  this.items.forEach((item) => {
227
- if (unitChanged) {
228
- if (toUnitName === "Default") {
229
- item.setUnit(renameUnit(this.rulerUnitTable, drawingUnit));
230
- item.setConversionFactor(1.0);
231
- } else {
232
- item.setUnit(renameUnit(this.rulerUnitTable, toUnitName));
233
- const multiplier = this.m_module.getViewer().getUnitsConversionCoef(eFromUnit, eToUnit);
234
- this.conversionFactor = 1 / multiplier;
235
- item.setConversionFactor(this.conversionFactor);
236
- }
237
- }
238
- if (precisionChanged) {
239
- if (toPrecision === "Default") {
240
- item.setPrecision(2);
241
- } else {
242
- item.setPrecision(toPrecision);
243
- }
204
+ if (toUnitName === "Default") {
205
+ item.setUnit(renameUnit(this.renameUnitTable, drawingUnit));
206
+ item.setConversionFactor(1.0);
207
+ } else {
208
+ item.setUnit(renameUnit(this.renameUnitTable, toUnitName));
209
+ const multiplier = this.m_module.getViewer().getUnitsConversionCoef(eFromUnit, eToUnit);
210
+ this.conversionFactor = 1 / multiplier;
211
+ item.setConversionFactor(this.conversionFactor);
244
212
  }
245
213
  });
246
214
  }
@@ -275,9 +243,6 @@ export class MeasureLineDragger extends OdBaseDragger {
275
243
  case "Micrometers":
276
244
  eUnit = this.m_module.Units.kMicrometers;
277
245
  break;
278
- case "Mils":
279
- eUnit = this.m_module.Units.kMils;
280
- break;
281
246
  case "MicroInches":
282
247
  eUnit = this.m_module.Units.kMicroInches;
283
248
  break;