Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

drawTable.js.flow 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. drawBorderTop,
  3. drawBorderJoin,
  4. drawBorderBottom
  5. } from './drawBorder';
  6. import drawRow from './drawRow';
  7. /**
  8. * @param {Array} rows
  9. * @param {Object} border
  10. * @param {Array} columnSizeIndex
  11. * @param {Array} rowSpanIndex
  12. * @param {Function} drawHorizontalLine
  13. * @returns {string}
  14. */
  15. export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {
  16. let output;
  17. let realRowIndex;
  18. let rowHeight;
  19. const rowCount = rows.length;
  20. realRowIndex = 0;
  21. output = '';
  22. if (drawHorizontalLine(realRowIndex, rowCount)) {
  23. output += drawBorderTop(columnSizeIndex, border);
  24. }
  25. rows.forEach((row, index0) => {
  26. output += drawRow(row, border);
  27. if (!rowHeight) {
  28. rowHeight = rowSpanIndex[realRowIndex];
  29. realRowIndex++;
  30. }
  31. rowHeight--;
  32. if (rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
  33. output += drawBorderJoin(columnSizeIndex, border);
  34. }
  35. });
  36. if (drawHorizontalLine(realRowIndex, rowCount)) {
  37. output += drawBorderBottom(columnSizeIndex, border);
  38. }
  39. return output;
  40. };