From b57c3fe94306c912bb35a620443729c25a22983e Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Fri, 14 Mar 2025 17:06:57 +0900 Subject: [PATCH] add toFixed attribute in QPolygon --- src/common/common.js | 1 + src/components/fabric/QPolygon.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/common.js b/src/common/common.js index 0fa678db..d82d43f0 100644 --- a/src/common/common.js +++ b/src/common/common.js @@ -202,6 +202,7 @@ export const SAVE_KEY = [ 'fontStyle', 'fontWeight', 'dormerAttributes', + 'toFixed', ] export const OBJECT_PROTOTYPE = [fabric.Line.prototype, fabric.Polygon.prototype, fabric.Triangle.prototype, fabric.Group.prototype] diff --git a/src/components/fabric/QPolygon.js b/src/components/fabric/QPolygon.js index a075b776..85bb03dd 100644 --- a/src/components/fabric/QPolygon.js +++ b/src/components/fabric/QPolygon.js @@ -23,6 +23,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, { initOptions: null, direction: null, arrow: null, + toFixed: 1, initialize: function (points, options, canvas) { this.lines = [] this.texts = [] @@ -33,11 +34,12 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, { this.innerLines = [] this.children = [] this.separatePolygon = [] + this.toFixed = options.toFixed ?? 1 // 소수점 전부 제거 points.forEach((point) => { - point.x = Number(point.x.toFixed(1)) - point.y = Number(point.y.toFixed(1)) + point.x = Number(point.x.toFixed(this.toFixed)) + point.y = Number(point.y.toFixed(this.toFixed)) }) options.selectable = options.selectable ?? true options.sort = options.sort ?? true