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.

mapDataUsingRowHeightIndex.js.flow 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import _ from 'lodash';
  2. import wrapString from './wrapString';
  3. import wrapWord from './wrapWord';
  4. /**
  5. * @param {Array} unmappedRows
  6. * @param {number[]} rowHeightIndex
  7. * @param {Object} config
  8. * @returns {Array}
  9. */
  10. export default (unmappedRows, rowHeightIndex, config) => {
  11. const tableWidth = unmappedRows[0].length;
  12. const mappedRows = unmappedRows.map((cells, index0) => {
  13. const rowHeight = _.times(rowHeightIndex[index0], () => {
  14. return new Array(tableWidth).fill('');
  15. });
  16. // rowHeight
  17. // [{row index within rowSaw; index2}]
  18. // [{cell index within a virtual row; index1}]
  19. cells.forEach((value, index1) => {
  20. let chunkedValue;
  21. if (config.columns[index1].wrapWord) {
  22. chunkedValue = wrapWord(value, config.columns[index1].width);
  23. } else {
  24. chunkedValue = wrapString(value, config.columns[index1].width);
  25. }
  26. chunkedValue.forEach((part, index2) => {
  27. rowHeight[index2][index1] = part;
  28. });
  29. });
  30. return rowHeight;
  31. });
  32. return _.flatten(mappedRows);
  33. };