-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify AvailabilityScale interface to provide a function and remove f…
…unctions from AvailabilityLevel
- Loading branch information
Jihou Tsao
committed
Sep 16, 2022
1 parent
bf9ebc8
commit 5b48edf
Showing
6 changed files
with
50 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,17 @@ | ||
//import { lighten } from 'color2k'; | ||
import { AvailabilityScale } from './models/availability/AvailabilityScale'; | ||
import { defaultAvailabilityScale } from './models/availability/DefaultAvailabilityScale'; | ||
|
||
export class AvailabilityLevel { | ||
public level = 1; // one-indexed | ||
public readonly scale: AvailabilityScale; | ||
public readonly level: number; // one-indexed | ||
public readonly label: string; | ||
public readonly color: string; | ||
|
||
constructor(level = 1, scale = defaultAvailabilityScale) { | ||
constructor( | ||
level = 1, | ||
scale: AvailabilityScale = defaultAvailabilityScale | ||
) { | ||
this.level = level; | ||
this.scale = scale; | ||
} | ||
|
||
get color(): string { | ||
if (this.level in this.scale.colors) { | ||
return this.scale.colors[this.level]; | ||
} | ||
|
||
return 'black'; | ||
// TODO: rewrite function to interpolate color | ||
/* | ||
const midpoint: number = (this.scale.levels + 1) / 2; | ||
if (this.level === midpoint) return NEUTRAL_COLOR; | ||
if (this.level === 1) return BUSY_COLOR; | ||
if (this.level === this.scale.levels) return AVAILABLE_COLOR; | ||
//const adjustment = Math.abs(midpoint - this.level) / this.max; | ||
if (this.level < midpoint) { | ||
const adjustment = (1.5 * (this.level - 1)) / this.scale.levels; | ||
return lighten(BUSY_COLOR, adjustment); | ||
} else { | ||
const adjustment = | ||
(1.5 * (this.scale.levels - this.level)) / this.scale.levels; | ||
return lighten(AVAILABLE_COLOR, adjustment); | ||
} | ||
*/ | ||
this.label = scale.label(this.level); | ||
this.color = scale.color(this.level); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
export interface AvailabilityScale { | ||
levels: number; | ||
labels: { | ||
[level: number]: string; | ||
}; | ||
colors: { | ||
[level: number]: string; | ||
}; | ||
label(level: number): string; | ||
color(level: number): string; | ||
} |
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