Commit 7b6bdfbf by Luciano Barletta

Merge branch 'secondpdf'

2 parents 028fbbc4 e584f4bb
"use strict";
/** Coordinate container that occupies the whole page **/
const A4 = new Div(
new Vector(0, 0),
new Vector(595, 842)
);
const Pos = {
"beg": 0,
"beg_margin": 5,
"quarter": 25,
"third": 33.33,
"middle": 50,
"two_thirds": 66.67,
"three_quarters": 75,
"end_margin": 95,
"end": 100
};
const containerSize = 86;
function generateDivTree(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 functionMapping = [
(pointer, data) => headerToPDF(pointer, data['header']),
(pointer, data) => alineadorToPDF(pointer, data['alineador']),
(pointer, data) => suspensionToPDF(pointer, data['suspension']),
(pointer, data) => frenosToPDF(pointer, data['frenos']),
(pointer, data) => traseroToPDF(pointer, data['trasero']),
(pointer, data) => 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),
A4.position
);
return A4;
}
function headerToPDF(pointer, data) {
const header = A4.addChild(pointer, new Vector(Pos.end, 3));
header.addText(
"Dominio: " + data['dominio'],
new Vector(Pos.beg_margin, Pos.two_thirds)
);
header.addText(
"Fecha: " + data['fecha'],
new Vector(Pos.third, Pos.two_thirds)
);
return new Vector(pointer.x, pointer.y + 3);
}
function alineadorToPDF(pointer, data) {
const alineador = A4.addChild(pointer, new Vector(Pos.end, 5));
alineador.addText(
"Resultado Pruebas en Banco de Alineador al Paso",
new Vector(Pos.beg_margin + 2, Pos.third)
);
alineador.addText(
"Eje Delantero",
new Vector(Pos.beg_margin + 2, Pos.two_thirds)
);
alineador.addText(
data['eje_delan'],
new Vector(Pos.quarter, Pos.two_thirds)
);
return new Vector(pointer.x, pointer.y + 5);
}
function suspensionToPDF(pointer, data) {
const suspension = A4.addChild(pointer, new Vector(Pos.end, 15));
const divsize = new Vector(containerSize, Pos.middle);
const eje1 = suspension.addChild(new Vector(Pos.beg_margin + 2, Pos.beg), divsize)
const eje2 = suspension.addChild(new Vector(Pos.beg_margin + 2, Pos.middle), divsize)
const table = (container, eje, RI, peso, RD) => {
container.addTexts([
[`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)],
["Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)],
[RI, new Vector(Pos.beg + 10, Pos.end)],
["Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds)],
[peso, new Vector(Pos.middle - 3, Pos.end)],
["Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)],
[RD, new Vector(Pos.three_quarters + 5, Pos.end)]
]);
};
table(eje1, 1, data[0]["ren_izq"], data[0]["peso"], data[0]["ren_der"])
table(eje2, 2, data[1]["ren_izq"], data[1]["peso"], data[1]["ren_der"])
return new Vector(pointer.x, pointer.y + 15);
}
function frenosToPDF(pointer, data) {
const frenos = A4.addChild(pointer, new Vector(Pos.end, 60));
const divsize = new Vector(containerSize, Pos.quarter);
const eje1 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.beg), divsize);
const eje2 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize);
const eje3 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.middle), divsize);
const eje4 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize);
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
container.addTexts([
[`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10)],
["Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)],
[FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)],
["Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)],
[RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)],
["Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)],
[OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)],
["Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)],
[peso, new Vector(Pos.middle - 5, Pos.quarter + 10)],
["Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)],
[FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)],
["Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)],
[RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)],
["Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)],
[OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10)]
]);
};
let x;
x = data[0];
table(eje1, 1, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[1];
table(eje2, 2, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[2];
table(eje3, 3, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[3];
table(eje4, 4, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
return new Vector(pointer.x, pointer.y + 60);
}
function traseroToPDF(pointer, data) {
const trasero = A4.addChild(new Vector(pointer.x + Pos.beg_margin + 2, pointer.y), new Vector(containerSize, 9));
trasero.addTexts([
["Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)],
["Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)],
[data['f_izq'], new Vector(Pos.beg_margin, Pos.end)],
["Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds)],
[data['f_der'], new Vector(Pos.three_quarters, Pos.end)],
]);
return new Vector(pointer.x, pointer.y + 9);
}
function gaseshumosToPDF(pointer, data) {
const gaseshumos = A4.addChild(new Vector(pointer.x + Pos.beg_margin + 2, pointer.y), new Vector(containerSize, 9));
gaseshumos.addTexts([
["Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)],
["Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)],
[`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)],
[`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds)]
]);
return new Vector(pointer.x, pointer.y + 9);
}
function compile(tree, pdf) {
pdf.setFont("Courier");
pdf.setFontType("normal");
pdf.setFontSize(10);
tree.children.forEach( child => {
switch (child.constructor.name) {
case "Text":
pdf.text(child.text, child.position.x, child.position.y);
break;
case "Div":
if (child.drawOutline) {
child.drawDivBox(pdf);
}
compile(child, pdf);
break;
}
});
return pdf;
}
\ No newline at end of file
......@@ -8,33 +8,90 @@ class Vector {
this.x = x;
this.y = y;
}
/**
* @param {Vector} vector
*/
addv(vector) {
return new Vector(
this.x + vector.x,
this.y + vector.y
);
}
/**
* @param {number} x
* @param {number} y
*/
addxy(x = 0,y = 0) {
return new Vector(
this.x + x,
this.y + y
);
}
/**
* @param {number} n
*/
mult(n) {
return new Vector(
this.x * n,
this.y * n
);
}
}
class Line {
/**
* @param {Vector} beggining
* @param {Vector} end
*/
constructor(beggining, end) {
this.beggining = beggining;
this.end = end;
}
/**
* @param {jsPDF} pdf
*/
draw(pdf) {
pdf.line(
this.beggining.x,
this.beggining.y,
this.end.x,
this.end.y
);
}
}
class Text {
/**
* Both arguments should be real coordinates and not a percentage based on parent element
* @param {Vector} position
* @param {Vector?} size
* @param {string} text
* @param {Vector} position
* @param {object} font
*/
constructor(text, position) {
constructor(text, position, font) {
this.text = text;
this.position = position;
this.font = font
}
/**
* Compiles the true position coordinates based on percentage relative to parent element
* Assumes the elements grow to the right and down
* @param {Vector} position
* @param {jsPDF} pdf
*/
getDrawCoordinates(position) {
return new Vector(
(this.size.x * position.x / 100) + this.position.x,
(this.size.y * position.y / 100) + this.position.y,
draw(pdf) {
pdf.setFont(this.font.font);
pdf.setFontType(this.font.type);
pdf.setFontSize(this.font.size);
pdf.text(
this.text,
this.position.x,
this.position.y
);
}
}
/**
......@@ -42,11 +99,9 @@ class Text {
* It does NOT resize or realocate its children to fit, in any way.
* Its only purpose is to provide percentage based relative coordinates.
*/
class Div {
/**
* Both arguments should be real coordinates and not a percentage based on parent element
* @param {Vector} position
* @param {Vector} size
* @param {bool} draw
......@@ -58,55 +113,61 @@ class Div {
this.children = [];
}
addChild(position, size) {
if (position.x < 0 || position.x > 100)
console.error("position.x has to be an int between 0 and 100");
if (position.y < 0 || position.y > 100)
console.error("position.y has to be an int between 0 and 100");
if (size.x < 0 || size.x > 100)
console.error("size.x has to be an int between 0 and 100");
if (size.y < 0 || size.y > 100)
console.error("size.y has to be an int between 0 and 100");
let div = new Div(
this.getDrawCoordinates(position),
this.getSize(size)
);
this.children.push(div);
return div;
/** Allows any position you want **/
addAbsoluteChild(child) {
if ("draw" in child === false)
console.error("the object passed needs to have a 'draw' method that takes a jsPDF object");
this.children.push(child);
return this.children[this.children.length - 1];
}
/** Allows only positions inside the Div **/
addRelativeChild(child) {
if ("draw" in child === false)
console.error("the object passed needs to have a 'draw' method that takes a jsPDF object");
addText(text, position) {
if (position.x < 0 || position.x > 100)
console.error("position.x has to be an int between 0 and 100");
if (position.y < 0 || position.y > 100)
console.error("position.y has to be an int between 0 and 100");
if ("position" in child)
child.position = this._getDrawCoordinates(child.position);
this.children.push(new Text(
text,
this.getDrawCoordinates(position)
));
if ("size" in child)
child.size = this._getSizeCoordinates(child.size);
this.children.push(child);
return this.children[this.children.length - 1];
}
/**
* Array de arrays de la forma ['texto', VectorPosición]
* @param {array} textArray
*/
addTexts(textArray) {
textArray.forEach( args =>
this.addText(args[0], args[1])
);
addAbsoluteChildren(children) {
const pointers = [];
children.forEach(c => pointers.push(this.addAbsoluteChild(c)));
return pointers;
}
addRelativeChildren(children) {
const pointers = [];
children.forEach(c => pointers.push(this.addRelativeChild(c)));
return pointers;
}
/** Allows any position you want relative to the position of this Div. Percentage based **/
getAbsoluteVector(vector) {
return this.position.addxy(
(this.size.x * vector.x / 100),
(this.size.y * vector.y / 100)
);
}
/**
* Compiles the true position coordinates based on percentage relative to parent element
* Assumes the elements grow to the right and down
* @param {Vector} position
*/
getDrawCoordinates(position) {
return new Vector (
(this.size.x * position.x / 100) + this.position.x,
(this.size.y * position.y / 100) + this.position.y,
_getDrawCoordinates(position) {
if (position.x < 0 || position.x > 100 || position.y < 0 || position.y > 100)
console.error("position components need to be real numbers in the range [0;100]");
return this.position.addxy(
(this.size.x * position.x / 100),
(this.size.y * position.y / 100)
);
}
......@@ -115,46 +176,59 @@ class Div {
* Assumes the elements grow to the right and down
* @param {Vector?} size
*/
getSize(size) {
if (size === null) return null;
_getSizeCoordinates(size) {
if (size.x < 0 || size.x > 100 || size.y < 0 || size.y > 100)
console.error("size components need to be real numbers in the range [0;100]");
return new Vector (
this.size.x * size.x / 100,
this.size.y * size.y / 100,
);
}
/**
* Debug method to see the confines of the Div
* @param {jsPDF} pdf
*/
drawDivBox(pdf) {
/** Upper **/
pdf.line(
this.position.x,
this.position.y,
this.position.x + this.size.x,
this.position.y
);
/** Lower **/
pdf.line(
this.position.x,
this.position.y + this.size.y,
this.position.x + this.size.x,
this.position.y + this.size.y
);
/** Left **/
pdf.line(
this.position.x,
this.position.y,
this.position.x,
this.position.y + this.size.y
);
/** Right **/
pdf.line(
this.position.x + this.size.x,
this.position.y,
this.position.x + this.size.x,
this.position.y + this.size.y
);
draw(pdf) {
/** Draw the confines of the div **/
if (this.drawOutline) {
/** Upper **/
this.addAbsoluteChild(new Line(
this.position,
this.position.addxy(this.size.x, 0)
));
/** Lower **/
this.addAbsoluteChild(new Line(
this.position.addxy(0, this.size.y),
this.position.addv(this.size)
));
/** Left **/
this.addAbsoluteChild(new Line(
this.position,
this.position.addxy(0, this.size.y)
));
/** Right **/
this.addAbsoluteChild(new Line(
this.position.addxy(this.size.x, 0),
this.position.addv(this.size)
));
}
/** Recursion **/
this.children.forEach( child => child.draw(pdf) );
}
}
const Pos = {
"beg": 0,
"beg_margin": 5,
"quarter": 25,
"third": 33.33,
"middle": 50,
"two_thirds": 66.67,
"three_quarters": 75,
"end_margin": 95,
"end": 100
};
function compile(tree, pdf) {
tree.children.forEach(child => child.draw(pdf));
return pdf;
}
\ No newline at end of file
class PDF1 {
"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;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
}
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), this.font),
new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds), this.font)
]);
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), this.font),
new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds), this.font),
new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds), this.font)
]);
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, ), this.font),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds), this.font),
new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end), this.font)
]);
};
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), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter), this.font),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle), this.font),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle), this.font),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters), this.font),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10), this.font)
]);
};
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, ), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds), this.font),
new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end), this.font),
]);
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), this.font),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]);
return pointer.addxy(0, 9);
}
}
\ No newline at end of file
class PDF1 {
"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;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
}
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.maha(pointer, data['header']),
(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), this.font),
new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds), this.font)
]);
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), this.font),
new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds), this.font),
new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds), this.font)
]);
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, ), this.font),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds), this.font),
new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end), this.font)
]);
};
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), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter), this.font),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle), this.font),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle), this.font),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters), this.font),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10), this.font)
]);
};
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, ), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds), this.font),
new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end), this.font),
]);
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), this.font),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]);
return pointer.addxy(0, 9);
}
}
\ No newline at end of file
......@@ -6,93 +6,37 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
<script src="{{ url_for('static', filename = 'src/div.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/getters.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/convert.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/pdf1.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/pdf2.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename = 'styles/general.css') }}">
<!--INCLUIMOS LA FUENTE-->
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/cmu-typewriter" type="text/css" />
<title>Pruebas de Alineamiento</title>
</head>
<body>
<div id = "pdf">
<!-- Header -->
<div class="TableContainer">
{% from "functions.html" import header %}
{{ header(data['dominio'],data['fecha']) }}
</div>
<!-- Header -->
<br>
<!-- Alineador -->
<div class="TableContainer">
{% from "functions.html" import alineador %}
{{ alineador(data['alineador']['eje_delan']) }}
</div>
<!-- Alineador -->
<br>
<!-- Suspensión -->
<div class="TableContainer">
{% from "functions.html" import suspension %}
{% set susp = data['suspension'][0] %}
{{ suspension(1, susp['ren_izq'], susp['peso'], susp['ren_der']) }}
{% set susp = data['suspension'][1] %}
{{ suspension(2, susp['ren_izq'], susp['peso'], susp['ren_der']) }}
</div>
<!-- Suspensión -->
<br>
<!-- Frenos -->
<div class="TableContainer">
{% from "functions.html" import frenos %}
{% set freno = data['frenos'][0] %}
{{ frenos(1,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['frenos'][1] %}
{{ frenos(2,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['frenos'][2] %}
{{ frenos(3,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['frenos'][3] %}
{{ frenos(4,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
</div>
<!-- Frenos -->
<br>
<!-- Frenos Trasero -->
<div class="TableContainer">
{% from "functions.html" import trasero %}
{{ trasero(data['trasero']['f_izq'], data['trasero']['f_der']) }}
</div>
<!-- Frenos Trasero -->
<br>
<!-- Gases y Humos -->
<div class="TableContainer">
{% from "functions.html" import gaseshumos %}
{{ gaseshumos(data['gaseshumos']['co'], data['gaseshumos']['hc'], data['gaseshumos']['med']) }}
</div>
<!-- Gases y Humos -->
<br>
</div>
<div class="PDFButtonContainer">
<button class="PDFButton" onclick=
"window.open(compile(generateDivTree( {{ data }} ), new jsPDF('portrait', 'pt', 'a4')).output('bloburl'))";
"window.open(
compile(
(new PDF1()).pdf( {{ data }} ),
new jsPDF('portrait', 'pt', 'a4'),
)
.output('bloburl')
)";
>
Convertir a PDF - 1
</button>
<button class="PDFButton" onclick=
"window.open(
compile(
(new PDF1()).pdf( {{ data }} ),
new jsPDF('portrait', 'pt', 'a4'),
)
.output('bloburl')
)";
>
Convertir a PDF
Convertir a PDF - 2
</button>
</div>
</body>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!