pdf2.js
6.17 KB
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
class PDF2 {
"use strict";
constructor() {
/** Coordinate container that occupies the whole page **/
this.A4 = new Div(
new Vector(0, 0),
new Vector(595, 842)
);
this.containerSize = 86;
}
pdf(data) {
/**
* The lambdas serve as "apply" functions
* Each function processes an element, executed in order of appeareance in HTML.
* They all return a coordinate "pointer" to draw.
*/
const pdfthis = this;
const functionMapping = [
(pointer, data) => pdfthis.headerToPDF(pointer, data['header']),
(pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']),
(pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']),
(pointer, data) => pdfthis.frenosToPDF(pointer, data['frenos']),
(pointer, data) => pdfthis.traseroToPDF(pointer, data['trasero']),
(pointer, data) => pdfthis.gaseshumosToPDF(pointer, data['gaseshumos'])
];
/**
* We pass the pointer to each function, which then modify it and passes it to the next,
* We start with (0%,0%)
*/
functionMapping.reduce(
(pointer, treeMaker) => treeMaker(pointer, data),
pdfthis.A4.position
);
return this.A4;
}
headerToPDF(pointer, data) {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3)));
header.addRelativeChildren([
new Text("Dominio: " + data['dominio'], new Vector(Pos.beg_margin, Pos.two_thirds)),
new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds))
]);
return pointer.addxy(0, 3);
}
alineadorToPDF(pointer, data) {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
alineador.addRelativeChildren([
new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third)),
new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds)),
new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds))
]);
return pointer.addxy(0, 5);
}
suspensionToPDF(pointer, data) {
const suspension = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 15)));
const divsize = new Vector(this.containerSize, Pos.middle);
const ejes = suspension.addRelativeChildren([
new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize)
]);
const table = (container, eje, RI, peso, RD) => {
container.addRelativeChildren([
new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)),
new Text(RI, new Vector(Pos.beg + 10, Pos.end)),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds)),
new Text(peso, new Vector(Pos.middle - 3, Pos.end)),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end))
]);
};
for (let i = 0; i < ejes.length; i++) {
const x = data[i];
table(ejes[i], i - 1, x["ren_izq"], x["peso"], x["ren_der"])
}
return pointer.addxy(0, 15);
}
frenosToPDF(pointer, data) {
const frenos = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 60)));
const divsize = new Vector(this.containerSize, Pos.quarter);
const ejes = frenos.addRelativeChildren(
new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize)
)
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
container.addRelativeChildren([
new Text(`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10)),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10)),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10))
]);
};
for (let i = 0; i < ejes.length; i++) {
const x = data[i];
table(ejes[i], i - 1, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"]);
}
return pointer.addxy(0, 60);
}
traseroToPDF(pointer, data) {
const trasero = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
trasero.addRelativeChildren([
new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)),
new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end)),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds)),
new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end)),
]);
return pointer.addxy(0, 9);
}
gaseshumosToPDF(pointer, data) {
const gaseshumos = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
gaseshumos.addRelativeChildren([
new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds))
]);
return pointer.addxy(0, 9);
}
}