-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bf2b76
commit dcebd92
Showing
5 changed files
with
44 additions
and
22 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 was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/components/DashboardsBar/__tests__/getRowsFromHeight.spec.js
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 { getRowsFromHeight } from '../getRowsFromHeight.js' | ||
|
||
test('getRowsFromHeight returns an integer', () => { | ||
const res = getRowsFromHeight(100) | ||
expect(Number.isInteger(res)).toBeTruthy() | ||
}) | ||
|
||
const testCases = [ | ||
{ height: 0, rows: 0 }, | ||
{ height: 36, rows: 1 }, | ||
{ height: 100, rows: 3 }, | ||
{ height: 200, rows: 5 }, | ||
{ height: 300, rows: 8 }, | ||
{ height: 400, rows: 10 }, | ||
{ height: 500, rows: 13 }, | ||
] | ||
|
||
testCases.forEach(({ height, rows }) => { | ||
test(`getRowsFromHeight returns ${rows} for height ${height}`, () => { | ||
expect(getRowsFromHeight(height)).toBe(rows) | ||
}) | ||
}) |
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,9 +1,15 @@ | ||
const ROW_HEIGHT = 32 | ||
const PADDING_TOP = 6 | ||
const SHOWMORE_BUTTON_HEIGHT = 0 // No longer shown under the chip area | ||
/* ROW_HEIGHT is the height of a chip + the gap between chips. | ||
But this isn't correct for the first or last row in the dashboards bar | ||
because the gap is only applied between rows, not at the top or bottom. | ||
So the first and last row are actually 3px shorter than the other rows, i.e. 35px | ||
But in order to keep the calculation simple, we'll just use 38px for all rows, while | ||
subtracting 3px from PADDING_TOP (which is actually 6px) | ||
*/ | ||
const ROW_HEIGHT = 38 // 32px chip + 6px gap | ||
const PADDING_TOP = 3 | ||
|
||
export const getRowsFromHeight = (height) => { | ||
return Math.round( | ||
(height - SHOWMORE_BUTTON_HEIGHT - PADDING_TOP) / ROW_HEIGHT | ||
) | ||
return Math.abs(Math.round( | ||
(height - PADDING_TOP) / ROW_HEIGHT | ||
)) | ||
} |
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