-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refine variable/file names (#164)
* Remove 'index', 'span' words * Rename in mapData * Continue rename Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
- Loading branch information
Showing
22 changed files
with
193 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import wrapCell from './wrapCell'; | ||
|
||
/** | ||
* Calculates height of cell content in regard to its width and word wrapping. | ||
*/ | ||
export default (value: string, columnWidth: number, useWrapWord = false): number => { | ||
return wrapCell(value, columnWidth, useWrapWord).length; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import calculateCellWidths from './calculateCellWidths'; | ||
import type { | ||
Row, | ||
} from './types/internal'; | ||
|
||
/** | ||
* Produces an array of values that describe the largest value length (width) in every column. | ||
*/ | ||
export default (rows: Row[]): number[] => { | ||
if (!rows[0]) { | ||
throw new Error('Dataset must have at least one row.'); | ||
} | ||
|
||
const columnWidths = new Array(rows[0].length).fill(0); | ||
|
||
rows.forEach((row) => { | ||
const cellWidths = calculateCellWidths(row); | ||
|
||
cellWidths.forEach((cellWidth, cellIndex) => { | ||
columnWidths[cellIndex] = Math.max(columnWidths[cellIndex], cellWidth); | ||
}); | ||
}); | ||
|
||
return columnWidths; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import calculateCellHeight from './calculateCellHeight'; | ||
import type { | ||
BaseConfig, | ||
Row, | ||
} from './types/internal'; | ||
|
||
/** | ||
* Produces an array of values that describe the largest value length (height) in every row. | ||
*/ | ||
export default (rows: Row[], config: BaseConfig): number[] => { | ||
return rows.map((row) => { | ||
let rowHeight = 1; | ||
|
||
row.forEach((cell, cellIndex) => { | ||
const cellHeight = calculateCellHeight(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord); | ||
|
||
rowHeight = Math.max(rowHeight, cellHeight); | ||
}); | ||
|
||
return rowHeight; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import flatten from 'lodash.flatten'; | ||
import type { | ||
BaseConfig, | ||
Row, | ||
} from './types/internal'; | ||
import wrapCell from './wrapCell'; | ||
|
||
export default (unmappedRows: Row[], rowHeights: number[], config: BaseConfig): Row[] => { | ||
const tableWidth = unmappedRows[0].length; | ||
|
||
const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => { | ||
const outputRowHeight = rowHeights[unmappedRowIndex]; | ||
const outputRow: Row[] = Array.from({length: outputRowHeight}, () => { | ||
return new Array(tableWidth).fill(''); | ||
}); | ||
|
||
// rowHeight | ||
// [{row index within rowSaw; index2}] | ||
// [{cell index within a virtual row; index1}] | ||
|
||
unmappedRow.forEach((cell, cellIndex) => { | ||
const cellLines = wrapCell(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord); | ||
|
||
cellLines.forEach((cellLine, cellLineIndex) => { | ||
outputRow[cellLineIndex][cellIndex] = cellLine; | ||
}); | ||
}); | ||
|
||
return outputRow; | ||
}); | ||
|
||
return flatten(mappedRows); | ||
}; |
Oops, something went wrong.