| 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 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
92468×
92409×
59×
1×
1×
82460×
1×
1×
260×
260×
260×
1×
259×
23×
236×
1×
1×
14013×
1×
1×
60×
1×
1×
14013×
14013×
3327×
14013×
1×
45720×
1×
9442×
1×
18487×
6×
18481×
1×
1×
14023×
1×
1×
14013×
14013×
14013×
14013×
14013×
14013×
2570×
2570×
4302×
2570×
11443×
11443×
22834×
11443×
14013×
1×
1×
19786×
19786×
1×
1×
19786×
19786×
699×
19786×
19786×
6×
6×
19786×
1×
1×
60×
1×
1×
4464×
4464×
8928×
8928×
8928×
8928×
4464×
1×
1×
86751×
13418×
73333×
1×
1×
77926×
77926×
77926×
1×
1×
4464×
4464×
1×
1×
4464×
4464×
1×
1×
84044×
84044×
80462×
3582×
3582×
3582×
3582×
1×
1×
42022×
42022×
42022×
40231×
1791×
1×
| define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PER_INCH = { Pixel: 96, Inch: 1, Centimeter: 2.54, Millimeter: 25.4, Point: 72 };
var SYMBOLS = { Point: 'pt', Centimeter: 'cm', Millimeter: 'mm', Inch: 'in' };
var DEFAULT_INTERVAL = 5;
var MIN_LABEL_GAP = 36;
var SUB_UNIT_WIDTH = 108;
var MIN_MINOR_GAP = 3;
var formatters = {};
function resolveMeasurementUnit(unit) {
if (unit === 'Pixel' || unit === 'Point' || unit === 'Centimeter' || unit === 'Millimeter' || unit === 'Inch') {
return unit;
}
return 'Pixel';
}
exports.resolveMeasurementUnit = resolveMeasurementUnit;
function isPhysicalUnit(unit) {
return unit === 'Point' || unit === 'Centimeter' || unit === 'Millimeter' || unit === 'Inch';
}
exports.isPhysicalUnit = isPhysicalUnit;
function convertMeasurement(value, from, to) {
var source = resolveMeasurementUnit(from);
var target = resolveMeasurementUnit(to);
if (typeof value !== 'number') {
return NaN;
}
if (source === target) {
return value;
}
return value * PER_INCH["" + target] / PER_INCH["" + source];
}
exports.convertMeasurement = convertMeasurement;
function pixelsPerUnit(unit) {
return PER_INCH.Pixel / PER_INCH[resolveMeasurementUnit(unit)];
}
exports.pixelsPerUnit = pixelsPerUnit;
function unitSymbol(unit) {
return SYMBOLS["" + unit] || '';
}
exports.unitSymbol = unitSymbol;
function stepDecimals(step) {
var decimals = 0;
while (decimals < 10 && Math.abs(Math.round(step * Math.pow(10, decimals)) - step * Math.pow(10, decimals)) > 1e-9) {
decimals++;
}
return decimals;
}
function wholeStep(index) {
return [1, 2, 5][index % 3] * Math.pow(10, Math.floor(index / 3));
}
function fractionStep(index) {
return [5, 2, 1][index % 3] * Math.pow(10, -1 - Math.floor(index / 3));
}
function validInterval(interval) {
if (typeof interval !== 'number' || !isFinite(interval) || interval < 1) {
return DEFAULT_INTERVAL;
}
return Math.floor(interval);
}
exports.validInterval = validInterval;
function minorTickCount(interval) {
return validInterval(interval);
}
exports.minorTickCount = minorTickCount;
function computeRulerSteps(unit, zoom, minGap, interval) {
if (minGap === void 0) { minGap = MIN_LABEL_GAP; }
if (interval === void 0) { interval = DEFAULT_INTERVAL; }
var perUnit = pixelsPerUnit(unit) * zoom;
var gap = Math.max(minGap, MIN_LABEL_GAP);
var labelStep = 1;
if (perUnit >= SUB_UNIT_WIDTH) {
var index = 0;
while (fractionStep(index + 1) * perUnit >= gap && index < 60) {
index++;
}
labelStep = fractionStep(index);
}
else {
var index = 0;
while (wholeStep(index) * perUnit < gap && index < 90) {
index++;
}
labelStep = wholeStep(index);
}
return {
labelStep: labelStep,
decimals: stepDecimals(labelStep),
minorCount: minorTickCount(interval),
pixelsPerUnit: perUnit
};
}
exports.computeRulerSteps = computeRulerSteps;
function cleanNumber(value, decimals) {
var factor = Math.pow(10, decimals);
return Math.round(value * factor) / factor + 0;
}
exports.cleanNumber = cleanNumber;
function formatMeasure(value, minDecimals, maxDecimals, locale) {
var cleaned = cleanNumber(value, maxDecimals);
if (cleaned === 0) {
cleaned = 0;
}
var key = (locale || '') + '|' + minDecimals + '|' + maxDecimals;
if (!formatters["" + key]) {
var intl = new ej2_base_1.Internationalization(locale);
formatters["" + key] = intl.getNumberFormat({
minimumFractionDigits: minDecimals, maximumFractionDigits: maxDecimals, useGrouping: false
});
}
return formatters["" + key](cleaned);
}
exports.formatMeasure = formatMeasure;
function formatTooltipValue(diagramValue, unit, locale) {
return formatMeasure(convertMeasurement(diagramValue, 'Pixel', unit), 2, 2, locale) + ' ' + unitSymbol(unit);
}
exports.formatTooltipValue = formatTooltipValue;
function labelGap(unit, zoom, maxExtentPx) {
var gap = MIN_LABEL_GAP;
for (var pass = 0; pass < 2; pass++) {
var steps = computeRulerSteps(unit, zoom, gap);
var widest = Math.floor(maxExtentPx / steps.pixelsPerUnit) + 1;
var chars = String(widest).length + 1 + (steps.decimals ? steps.decimals + 1 : 0);
gap = Math.max(MIN_LABEL_GAP, chars * 6.2 + 8);
}
return gap;
}
exports.labelGap = labelGap;
function getRulerUnitState(diagram) {
if (diagram.gestureUnitState) {
return diagram.gestureUnitState;
}
return currentRulerUnitState(diagram);
}
exports.getRulerUnitState = getRulerUnitState;
function currentRulerUnitState(diagram) {
var rulers = diagram.rulerSettings;
var unit = rulers ? resolveMeasurementUnit(rulers.measurementUnit) : 'Pixel';
return { unit: unit, unitDriven: isPhysicalUnit(unit) };
}
exports.currentRulerUnitState = currentRulerUnitState;
function rulerLabelGap(diagram, unit) {
var extent = Math.max(Math.abs(diagram.scroller.horizontalOffset), Math.abs(diagram.scroller.verticalOffset)) +
Math.max(diagram.element.clientWidth, diagram.element.clientHeight) + 200;
return labelGap(unit, diagram.scroller.currentZoom, extent);
}
exports.rulerLabelGap = rulerLabelGap;
function axisInterval(diagram, horizontalRuler) {
var ruler = horizontalRuler ? diagram.rulerSettings.horizontalRuler : diagram.rulerSettings.verticalRuler;
return validInterval(ruler ? ruler.interval : DEFAULT_INTERVAL);
}
exports.axisInterval = axisInterval;
function getAxisSteps(diagram, horizontalRuler) {
var state = getRulerUnitState(diagram);
if (!state.unitDriven || !diagram.scroller) {
return null;
}
var zoom = diagram.scroller.currentZoom;
var steps = computeRulerSteps(state.unit, zoom, rulerLabelGap(diagram, state.unit), axisInterval(diagram, horizontalRuler));
var majorScreen = steps.labelStep * steps.pixelsPerUnit;
return { majorPx: majorScreen, minorPx: majorScreen / steps.minorCount, minorCount: steps.minorCount };
}
exports.getAxisSteps = getAxisSteps;
function getUnitGrid(diagram) {
var x = getAxisSteps(diagram, true);
var y = getAxisSteps(diagram, false);
if (!x || !y) {
return null;
}
return {
tileX: x.majorPx, tileY: y.majorPx, countX: x.minorCount, countY: y.minorCount,
phaseX: 0, phaseY: 0,
minorX: x.minorPx, minorY: y.minorPx
};
}
exports.getUnitGrid = getUnitGrid;
});
|