-
Notifications
You must be signed in to change notification settings - Fork 1
/
columnRow.js
67 lines (55 loc) · 1.75 KB
/
columnRow.js
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
const WIDTH_SETTINGS = {
minSizeValueCol: 39,
minSizeValuePixel: 370,
normalSizeValue: 10,
extraSizeValue: 5,
extraUnitLocation: [4]
};
const HEIGHT_SETTINGS = {
minSizeValueRow: 12,
minSizeValuePixel: 300,
normalSizeValue: 20,
extraSizeValue: 25,
extraUnitLocation: [2, 7]
};
const getLastNumber = num => +num.toString().slice(+num.toString().length - 1);
const convertWidth = value => {
const isExtraValue = getLastNumber(value) === WIDTH_SETTINGS.extraUnitLocation[0] ? WIDTH_SETTINGS.extraSizeValue : 0;
if (value >= WIDTH_SETTINGS.minSizeValueCol) {
let pixelUnit = WIDTH_SETTINGS.minSizeValuePixel + isExtraValue;
let colUnit = WIDTH_SETTINGS.minSizeValueCol;
while (colUnit !== value && Number.isInteger(value)) {
++colUnit;
if (getLastNumber(colUnit) !== WIDTH_SETTINGS.extraUnitLocation[0]) {
pixelUnit += WIDTH_SETTINGS.normalSizeValue;
}
}
return pixelUnit || WIDTH_SETTINGS.minSizeValuePixel;
} else {
return WIDTH_SETTINGS.minSizeValuePixel;
}
};
const convertHeight = value => {
if (value >= HEIGHT_SETTINGS.minSizeValueRow) {
let pixelUnit = HEIGHT_SETTINGS.minSizeValuePixel;
let rowUnit = HEIGHT_SETTINGS.minSizeValueRow;
while (rowUnit !== value && Number.isInteger(value)) {
++rowUnit;
if (
getLastNumber(rowUnit) !== HEIGHT_SETTINGS.extraUnitLocation[0] &&
getLastNumber(rowUnit) !== HEIGHT_SETTINGS.extraUnitLocation[1]
) {
pixelUnit += HEIGHT_SETTINGS.normalSizeValue;
} else {
pixelUnit += HEIGHT_SETTINGS.extraSizeValue;
}
}
return pixelUnit || HEIGHT_SETTINGS.minSizeValuePixel;
} else {
return HEIGHT_SETTINGS.minSizeValuePixel;
}
};
module.exports = {
convertWidth,
convertHeight
};