forked from bcgov/wps
-
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.
ASA: Color coded fuel types (bcgov#3220)
- Loading branch information
Showing
3 changed files
with
80 additions
and
33 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getColorByFuelTypeCode } from 'features/fba/components/viz/color' | ||
|
||
const colorByFuelTypeCodeTestMap = new Map() | ||
colorByFuelTypeCodeTestMap.set('C-1', 'rgb(209, 255, 115)') | ||
colorByFuelTypeCodeTestMap.set('C-2', 'rgb(34, 102, 51)') | ||
colorByFuelTypeCodeTestMap.set('C-3', 'rgb(131, 199, 149)') | ||
colorByFuelTypeCodeTestMap.set('C-4', 'rgb(112, 168, 0)') | ||
colorByFuelTypeCodeTestMap.set('C-5', 'rgb(223, 184, 230)') | ||
colorByFuelTypeCodeTestMap.set('C-6', 'rgb(172, 102, 237)') | ||
colorByFuelTypeCodeTestMap.set('C-7', 'rgb(112, 12, 242)') | ||
colorByFuelTypeCodeTestMap.set('D-1/D-2', 'rgb(137, 112, 68)') | ||
colorByFuelTypeCodeTestMap.set('S-1', 'rgb(251, 190, 185)') | ||
colorByFuelTypeCodeTestMap.set('S-2', 'rgb(247, 104, 161)') | ||
colorByFuelTypeCodeTestMap.set('S-3', 'rgb(174, 1, 126)') | ||
colorByFuelTypeCodeTestMap.set('O-1a/O-1b', 'rgb(255, 255, 190)') | ||
colorByFuelTypeCodeTestMap.set('M-1/M-2', 'rgb(255, 211, 127)') | ||
|
||
describe('getColorByFuelTypeCode', () => { | ||
it('should return the correct colour for each fuel type code', () => { | ||
const keys = colorByFuelTypeCodeTestMap.keys() | ||
for (const key of keys) { | ||
expect(getColorByFuelTypeCode(key)).toBe(colorByFuelTypeCodeTestMap.get(key)) | ||
} | ||
}) | ||
it('should return a default color when a matching key is not found', () => { | ||
expect(getColorByFuelTypeCode('foo')).toBe('rgb(0, 255, 255)') | ||
}) | ||
}) |
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 @@ | ||
// A Map of fuel type codes to the colour typically used in BCWS | ||
const colorByFuelTypeCode = new Map() | ||
colorByFuelTypeCode.set('C-1', 'rgb(209, 255, 115)') | ||
colorByFuelTypeCode.set('C-2', 'rgb(34, 102, 51)') | ||
colorByFuelTypeCode.set('C-3', 'rgb(131, 199, 149)') | ||
colorByFuelTypeCode.set('C-4', 'rgb(112, 168, 0)') | ||
colorByFuelTypeCode.set('C-5', 'rgb(223, 184, 230)') | ||
colorByFuelTypeCode.set('C-6', 'rgb(172, 102, 237)') | ||
colorByFuelTypeCode.set('C-7', 'rgb(112, 12, 242)') | ||
colorByFuelTypeCode.set('D-1/D-2', 'rgb(137, 112, 68)') | ||
colorByFuelTypeCode.set('S-1', 'rgb(251, 190, 185)') | ||
colorByFuelTypeCode.set('S-2', 'rgb(247, 104, 161)') | ||
colorByFuelTypeCode.set('S-3', 'rgb(174, 1, 126)') | ||
colorByFuelTypeCode.set('O-1a/O-1b', 'rgb(255, 255, 190)') | ||
colorByFuelTypeCode.set('M-1/M-2', 'rgb(255, 211, 127)') | ||
|
||
// Retrieve a color from the Map base don the fuel type code. | ||
// Provide a default value in case a non-standard code is encountered so we don't end up with empty pie slices. | ||
export const getColorByFuelTypeCode = (code: string): string => { | ||
const color = colorByFuelTypeCode.get(code) | ||
return color ?? 'rgb(0, 255, 255)' | ||
} |