1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304 | 1×
1×
1×
1×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
1×
602×
602×
1×
602×
602×
1×
602×
1×
1×
600×
600×
600×
600×
600×
600×
600×
27000×
27000×
600×
600×
600×
600×
1×
1284×
6×
1278×
1×
602×
602×
602×
1×
602×
602×
602×
600×
600×
602×
1×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
602×
1×
602×
602×
602×
602×
53578×
53578×
53578×
53578×
602×
1×
53578×
53578×
602×
602×
602×
602×
602×
301×
301×
52976×
52976×
52976×
52976×
602×
52976×
26488×
26488×
52976×
52976×
53578×
53578×
53578×
53578×
53578×
53578×
1×
53578×
53578×
53578×
53578×
53578×
53578×
26789×
53578×
26789×
26789×
53578×
53578×
53578×
1×
53578×
53578×
53578×
1×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
53578×
214312×
214312×
214312×
160734×
53578×
1×
214312×
214312×
214312×
214312×
214312×
1×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
214312×
160734×
160734×
160734×
80367×
80367×
160734×
160734×
160734×
214312×
1×
53578×
53578×
53578×
53578×
53578×
53578×
1×
321468×
321468×
1×
1204×
602×
602×
1×
429828×
1×
602×
602×
602×
602×
602×
602×
602×
602×
602×
2×
2×
602×
602×
1×
1×
1×
1×
| define(["require", "exports", "../editor/editor-helper", "../utility/size"], function (require, exports, editor_helper_1, size_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Ruler = (function () {
function Ruler(element, rulerHelper) {
this.interval = 4;
this.segmentWidth = 47.9988;
this.orientation = 'Horizontal';
this.tickAlignment = 'RightOrBottom';
this.markerColor = 'red';
this.thickness = 15;
this.arrangeTick = null;
this.length = 400;
this.offset = 0;
this.scale = 1;
this.rulerStartValue = 1584;
this.zeroPosition = editor_helper_1.HelperMethods.convertPointToPixel(1584);
this.addSegmentWidth = false;
this.element = element;
this.rulerHelper = rulerHelper;
}
Ruler.prototype.appendTo = function () {
this.preRender();
this.render();
};
Ruler.prototype.preRender = function () {
this.unWireEvents();
this.wireEvents();
};
Ruler.prototype.render = function () {
this.updateRulerGeometry();
};
Ruler.prototype.getModuleName = function () {
return 'Ruler';
};
Ruler.prototype.destroy = function () {
var _this = this;
this.unWireEvents();
Eif (this.rulerSpacediv) {
this.rulerSpacediv.remove();
this.rulerSpacediv = null;
}
Eif (this.rulerSVGElement) {
this.rulerSVGElement.childNodes.forEach(function (element) {
_this.rulerSVGElement.removeChild(element);
element = null;
});
this.rulerSVGElement.innerHTML = '';
this.rulerSVGElement.remove();
this.rulerSVGElement = null;
}
this.element.classList.remove('e-ruler');
};
Ruler.prototype.showHideRuler = function (show) {
if (show) {
this.element.style.display = 'block';
}
else {
this.element.style.display = 'none';
}
};
Ruler.prototype.updateRulerGeometry = function () {
this.element.style.textAlign = 'left';
this.renderRulerSpace();
this.updateRuler();
};
Ruler.prototype.renderRulerSpace = function () {
var rulerGeometry = this.getRulerGeometry();
this.rulerSpacediv = document.getElementById(this.element.id + '_ruler_space');
if (!this.rulerSpacediv) {
this.rulerSpacediv = this.rulerHelper.createHtmlElement('div', {
'id': this.element.id + '_ruler_space',
'style': 'height:' + rulerGeometry.height + 'px;width:' + rulerGeometry.width + 'px;cssFloat:' + 'left;'
});
this.element.appendChild(this.rulerSpacediv);
}
return this.rulerSpacediv;
};
Ruler.prototype.updateRuler = function () {
var rulerSize = this.getRulerSize();
var rulerGeometry = this.getRulerGeometry();
var length = 0;
var offset = 0;
var availableSize = new size_1.Size();
this.rulerSVGElement = this.getRulerSVG(rulerGeometry);
Eif (this.rulerSVGElement) {
length = this.length;
availableSize.height = rulerSize;
offset = this.offset;
Eif (length && length !== Infinity) {
var unitLength = length;
var unitOffset = offset;
this.updateSegments(unitOffset, (unitLength + Math.abs(unitOffset)), this.rulerSVGElement, rulerSize);
}
}
};
Ruler.prototype.updateSegments = function (start, end, svg, rulerSize) {
var run = start;
var trans = { trans: 0 };
this.rulerStartValue = editor_helper_1.HelperMethods.convertPixelToPoint(this.zeroPosition);
while (run < end) {
var rulerSegment = this.getNewSegment(run, svg);
Eif (rulerSegment) {
svg.appendChild(rulerSegment.segment);
run = this.updateSegment(start, end, rulerSegment, run, trans, rulerSize);
}
}
this.addSegmentWidth = false;
};
Ruler.prototype.updateSegment = function (start, end, rulerSegment, run, trans, rulerSize) {
var segWidth = this.updateSegmentWidth(this.scale);
if (run === start) {
this.startValue = Math.floor(start / segWidth) * segWidth / this.scale;
this.startValue = (this.startValue % 1) !== 0 ? Number((this.startValue).toFixed(1)) : this.startValue;
rulerSegment.label.textContent = this.rulerStartValue.toString();
this.defStartValue = run = this.startValue * this.scale;
if (this.orientation === 'Horizontal') {
this.hRulerOffset = start - run;
}
else {
this.vRulerOffset = start - run;
}
}
else {
this.startValue = editor_helper_1.HelperMethods.convertPixelToPoint(run);
this.startValue = (this.startValue % 1) !== 0 ? Number((this.startValue).toFixed(1)) : this.startValue;
var labeltext = void 0;
if (this.rulerStartValue === 0) {
this.addSegmentWidth = true;
}
if (this.addSegmentWidth) {
labeltext = Math.abs(this.rulerStartValue + 36);
}
else {
labeltext = Math.abs(this.rulerStartValue - 36);
}
rulerSegment.label.textContent = (labeltext).toString();
this.rulerStartValue = labeltext;
}
this.updateTickLabel(rulerSegment, rulerSize);
var translate = (this.orientation === 'Horizontal') ? ((trans.trans + 0.5) + ',0.5') : ('0.5,' + (trans.trans + 0.5));
rulerSegment.segment.setAttribute('transform', 'translate(' + translate + ') scale(' + 1 + ',1)');
trans.trans += segWidth * this.scale;
run += segWidth;
return run;
};
Ruler.prototype.updateTickLabel = function (rulerSegment, rulerSize) {
var bBox = rulerSegment.segment.lastChild.getBBox();
var isHorizontal = (this.orientation === 'Horizontal') ? true : false;
var isRightOrBottom = (this.tickAlignment === 'RightOrBottom') ? true : false;
var x = isHorizontal ? -4 : 0;
var y = isHorizontal ? (isRightOrBottom ? (rulerSize / 2 + (11 / 2) - (11 / 2)) :
(rulerSize / 2 + (11 / 2))) : bBox.height;
if (isHorizontal) {
y = y + 2;
}
if (!isHorizontal) {
x = x + 10;
y = y + 2;
}
var translate = isRightOrBottom ? (-(bBox.width + 2) + ',' + ((rulerSize / 2) - bBox.height)) :
(-(bBox.width + 2) + ',' + ((rulerSize / 2) - bBox.height / 2));
var attr = isHorizontal ? { 'x': x, 'y': y } :
{ 'x': x, 'y': y, 'transform': 'rotate(270)' + 'translate(' + translate + ')' };
this.rulerHelper.setAttributeSvg(rulerSegment.segment.lastChild, attr);
};
Ruler.prototype.getNewSegment = function (run, svg) {
var segment = this.createNewTicks(run, svg);
var label = this.createTickLabel(svg, segment);
return { segment: segment, label: label };
};
Ruler.prototype.createNewTicks = function (run, svg) {
var tick;
var tickInterval;
var segmentWidth = this.updateSegmentWidth(this.scale);
var attr = { 'class': 'e-de-ruler-segment' };
var g = this.rulerHelper.createSvgElement('g', attr);
var rectattr = { 'class': 'e-de-ruler-segment1' };
var rect = this.rulerHelper.createSvgElement('rect', rectattr);
var width = this.orientation === 'Horizontal' ? (segmentWidth * this.scale) : 15;
var height = this.orientation === 'Horizontal' ? 15 : segmentWidth;
rect.setAttribute('x', '0');
rect.setAttribute('y', '0');
rect.setAttribute('width', width.toString());
rect.setAttribute('height', height.toString());
rect.setAttribute('fill', 'lightgrey');
for (var i = 0; i < this.interval; i++) {
tickInterval = segmentWidth / this.interval;
tick = this.createTick(svg, tickInterval, i + 1, run);
if (tick) {
g.appendChild(tick);
}
}
return g;
};
Ruler.prototype.getLinePoint = function (svg, tickInterval, length) {
var segmentWidth = this.updateSegmentWidth(this.scale);
var rulerSize = this.getRulerSize();
tickInterval = tickInterval * (length - 1);
length = ((tickInterval % segmentWidth) === 0) ? rulerSize : rulerSize * 0.3;
return length;
};
Ruler.prototype.createTick = function (svg, tickInterval, length, run) {
var ruler;
var linePoint = this.getLinePoint(svg, tickInterval, length);
var rulerSize = this.getRulerSize();
var isHorizontal = (this.orientation === 'Horizontal') ? true : false;
var isRightOrBottom = (this.tickAlignment === 'RightOrBottom') ? true : false;
var point = tickInterval * (length - 1) * this.scale;
var x1 = isHorizontal ? point : (isRightOrBottom ? rulerSize : 0);
var x2 = isHorizontal ? point : (isRightOrBottom ? (rulerSize - linePoint) : (rulerSize - (rulerSize - linePoint)));
var y1 = isHorizontal ? (isRightOrBottom ? rulerSize : (rulerSize - (rulerSize - linePoint))) : point;
var y2 = isHorizontal ? (isRightOrBottom ? (rulerSize - linePoint) : 0) : point;
var line;
if (y2 !== 0) {
y1 = y1 - 6;
y2 = y2 - 6;
if (!isHorizontal) {
x1 = x1 - 6;
x2 = x2 - 6;
}
var attr = { 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2, 'stroke-width': '0.25', 'stroke': 'black' };
line = this.rulerHelper.createSvgElement('line', attr);
line.setAttribute('class', 'e-de-ruler-tick');
}
return line;
};
Ruler.prototype.createTickLabel = function (svg, segment) {
var text;
Eif (segment) {
var attr = { 'class': 'e-de-ruler-tick-label', 'style': 'font-weight: 400' };
text = this.rulerHelper.createSvgElement('text', attr);
segment.appendChild(text);
}
return text;
};
Ruler.prototype.updateSegmentWidth = function (scale) {
Eif (this.segmentWidth !== 100) {
return this.segmentWidth;
}
var five = 25;
var multiples = 1;
var div;
var fifty = 100;
var scaleRound = Math.pow(2, Math.round(Math.log(scale) / Math.log(2)));
div = fifty;
div = (fifty / scaleRound);
while (div > 100) {
multiples /= 10;
div /= 10;
}
while (div < 25) {
multiples *= 10;
div *= 10;
}
if (div >= five && div % five !== 0) {
div = Math.round(div / five) * five;
}
return div * scale / multiples;
};
Ruler.prototype.getRulerGeometry = function () {
if (this.orientation === 'Horizontal') {
return new size_1.Size(this.length, this.element ? this.element.getBoundingClientRect().height : 0);
}
else {
return new size_1.Size(this.element ? this.element.getBoundingClientRect().width : 0, this.length);
}
};
Ruler.prototype.getRulerSize = function () {
return this.thickness;
};
Ruler.prototype.getRulerSVG = function (rulerGeometry) {
var rulerSpace;
var rulerSize = this.getRulerSize();
var svg;
Eif (this.element) {
rulerSpace = document.getElementById(this.element.id + '_ruler_space');
Eif (rulerSpace) {
var attr = {
'id': this.element.id + '_Ruler_svg',
width: this.orientation === 'Horizontal' ? this.length : rulerSize + 'px',
height: this.orientation === 'Horizontal' ? rulerSize : (rulerGeometry.height) + 'px',
style: 'position:inherit;'
};
svg = this.rulerHelper.createSvgElement('svg', attr);
if (rulerSpace.childNodes.length > 0) {
for (var i = rulerSpace.childNodes.length - 1; i >= 0; i--) {
rulerSpace.childNodes[parseInt(i.toString(), 10)].parentNode.removeChild(rulerSpace.childNodes[parseInt(i.toString(), 10)]);
}
}
rulerSpace.appendChild(svg);
}
}
return svg;
};
Ruler.prototype.wireEvents = function () {
};
Ruler.prototype.unWireEvents = function () {
};
return Ruler;
}());
exports.Ruler = Ruler;
});
|