Skip to content

Commit

Permalink
fix: refactor deprecated String.substring method
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Elkholy <mkh117@gmail.com>
  • Loading branch information
mohatt committed Sep 6, 2024
1 parent 450e215 commit c7e8ab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ export class ListRepoCardComponent {
public scoreColorLegend: string[]

constructor(private repoScoreService: ListRepoScoreService) {
this.scoreColorLegend = repoScoreService.getScoreColors()
this.scoreColorLegend = repoScoreService.getScoreColorTheme()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@ export class ListRepoScoreService {
}

getScoreColor(type: ListRepoScoreType, score: number): { bg: string; text: string } {
const legend = this.getScoreColors()
const color = this.getScoreColorScale(type).getColor(score)
return {
bg: color,
text: this.isColorBright(color) ? legend[legend.length - 2] : legend[1],
text: this.isColorBright(color) ? this.theme[this.theme.length - 2] : this.theme[1],
}
}

getScoreColors(): string[] {
getScoreColorTheme(): string[] {
return this.theme
}

isColorBright(hex: string) {
hex = hex.replace('#', '')
const r = parseInt(hex.substr(0, 2), 16),
g = parseInt(hex.substr(2, 2), 16),
b = parseInt(hex.substr(4, 2), 16)
isColorBright(color: string) {
const hex = color.substring(color.length - 6, color.length)
const r = parseInt(hex.substring(0, 2), 16),
g = parseInt(hex.substring(2, 4), 16),
b = parseInt(hex.substring(4, 6), 16)

return 150 < (r * 299 + g * 587 + b * 114) / 1000
}
Expand Down

0 comments on commit c7e8ab2

Please sign in to comment.