all files / src/ Tabla.js

100% Statements 38/38
100% Branches 0/0
100% Functions 11/11
100% Lines 38/38
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 27×         27×         18×       16× 48× 48× 48×         12× 36×       27×   12×        
const TextCell = require("../src/textcell");
const UnderlinedCell = require("../src/underlinedcell");
const RTextCell = require("../src/rtextcell");
const StretchCell = require("../src/stretchcell");
const {addMapClass, findClass} = require('./registry-class');
colWidths = (filas) => {
    return filas[0].map(function(_, i) {
      return filas.reduce(function(max, row) {
        return Math.max(max, row[i].minWidth);
      }, 0);
    });
};
 
colHeights = (filas) => {
  return filas.map(function(row) {
    return row.reduce(function(max, cell) {
      return Math.max(max, cell.minHeight);
    }, 0);
});
};
 
  dataTable  = (data) => {
    var keys = Object.keys(data[0]);
    var categorias = keys.map(function(categoria) {
      return keys.map(function(categoria) {
        return new UnderlinedCell(categoria.toString());
        });
    });
    //Magia para evitar error de arrays, conversiones
    categorias = categorias.splice(0, 1);
    var datos = data.map(function(fila) {
      return keys.map(function(i) {
        let value = fila[i];
        let {className, currClass, params} = findClass(value);
        return new currClass(...params);
      });
    });
    return categorias.concat(datos);
  };
 
  drawTable = (filas) => {
    let width = colWidths(filas);
    let height = colHeights(filas);
    dibujarLinea = (datos, numeroLinea) => {
        return datos.map(function(fila) {
          return fila[numeroLinea];
        }).join(" ");
    };
 
    dibujarFilas = (fila, numlinea) => {
        var content = fila.map(function(elemento, numCol) {
            return elemento.draw(width[numCol], height[numlinea]);
        });
        return content[0].map(function(_, nlinea) {
          return dibujarLinea(content, nlinea);
        }).join("\n");
    }
    return filas.map(dibujarFilas).join("\n");
 };
  createTable = (data) => {  };