-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move shared code for cell rendering into utils (#510)
- Loading branch information
Showing
6 changed files
with
97 additions
and
131 deletions.
There are no files selected for viewing
11 changes: 9 additions & 2 deletions
11
vuu-ui/packages/vuu-datagrid-extras/src/cell-renderers/background-cell/BackgroundCell.tsx
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
4 changes: 2 additions & 2 deletions
4
vuu-ui/packages/vuu-datagrid/src/cell-renderers/background-cell.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export type valueChangeDirection = "up1" | "up2" | "down1" | "down2" | ""; | ||
|
||
export const UP1 = "up1"; | ||
export const UP2 = "up2"; | ||
export const DOWN1 = "down1"; | ||
export const DOWN2 = "down2"; | ||
|
||
export const isValidNumber = (n: unknown): n is number => | ||
typeof n === "number" && isFinite(n); | ||
|
||
export function getMovingValueDirection( | ||
newValue: number, | ||
direction?: valueChangeDirection, | ||
prevValue?: number, | ||
/** the number of decimal places to take into account when highlighting a change */ | ||
decimalPlaces?: number | ||
): valueChangeDirection { | ||
if ( | ||
!isFinite(newValue) || | ||
prevValue === undefined || | ||
direction === undefined | ||
) { | ||
return ""; | ||
} else { | ||
let diff = newValue - prevValue; | ||
if (diff) { | ||
// make sure there is still a diff when reduced to number of decimals to be displayed | ||
if (typeof decimalPlaces === "number") { | ||
diff = | ||
+newValue.toFixed(decimalPlaces) - +prevValue.toFixed(decimalPlaces); | ||
} | ||
} | ||
|
||
if (diff) { | ||
if (direction === "") { | ||
if (diff < 0) { | ||
return DOWN1; | ||
} else { | ||
return UP1; | ||
} | ||
} else if (diff > 0) { | ||
if (direction === DOWN1 || direction === DOWN2 || direction === UP2) { | ||
return UP1; | ||
} else { | ||
return UP2; | ||
} | ||
} else if ( | ||
direction === UP1 || | ||
direction === UP2 || | ||
direction === DOWN2 | ||
) { | ||
return DOWN1; | ||
} else { | ||
return DOWN2; | ||
} | ||
} else { | ||
return ""; | ||
} | ||
} | ||
} |
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