Skip to content

Commit

Permalink
chore: cleanup code to bring coverage back up
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Sep 30, 2017
1 parent d230e94 commit 1a12eb8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
77 changes: 77 additions & 0 deletions src/createColors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,83 @@ import test from 'ava'

import { createColors } from './createColors'

test('match colormap output', t => {
const actual = createColors([0, 0, 255], [0, 255, 128], 72)

t.deepEqual(actual, [[0, 0, 255, 1],
[0, 4, 253, 1],
[0, 7, 251, 1],
[0, 11, 250, 1],
[0, 14, 248, 1],
[0, 18, 246, 1],
[0, 22, 244, 1],
[0, 25, 242, 1],
[0, 29, 241, 1],
[0, 32, 239, 1],
[0, 36, 237, 1],
[0, 40, 235, 1],
[0, 43, 234, 1],
[0, 47, 232, 1],
[0, 50, 230, 1],
[0, 54, 228, 1],
[0, 57, 226, 1],
[0, 61, 225, 1],
[0, 65, 223, 1],
[0, 68, 221, 1],
[0, 72, 219, 1],
[0, 75, 217, 1],
[0, 79, 216, 1],
[0, 83, 214, 1],
[0, 86, 212, 1],
[0, 90, 210, 1],
[0, 93, 208, 1],
[0, 97, 207, 1],
[0, 101, 205, 1],
[0, 104, 203, 1],
[0, 108, 201, 1],
[0, 111, 200, 1],
[0, 115, 198, 1],
[0, 119, 196, 1],
[0, 122, 194, 1],
[0, 126, 192, 1],
[0, 129, 191, 1],
[0, 133, 189, 1],
[0, 136, 187, 1],
[0, 140, 185, 1],
[0, 144, 183, 1],
[0, 147, 182, 1],
[0, 151, 180, 1],
[0, 154, 178, 1],
[0, 158, 176, 1],
[0, 162, 175, 1],
[0, 165, 173, 1],
[0, 169, 171, 1],
[0, 172, 169, 1],
[0, 176, 167, 1],
[0, 180, 166, 1],
[0, 183, 164, 1],
[0, 187, 162, 1],
[0, 190, 160, 1],
[0, 194, 158, 1],
[0, 198, 157, 1],
[0, 201, 155, 1],
[0, 205, 153, 1],
[0, 208, 151, 1],
[0, 212, 149, 1],
[0, 215, 148, 1],
[0, 219, 146, 1],
[0, 223, 144, 1],
[0, 226, 142, 1],
[0, 230, 141, 1],
[0, 233, 139, 1],
[0, 237, 137, 1],
[0, 241, 135, 1],
[0, 244, 133, 1],
[0, 248, 132, 1],
[0, 251, 130, 1],
[0, 255, 128, 1]])
})

test('match actual colors', t => {
let actual = createColors([150, 0, 90], [0, 0, 200], 72, [0, 1])

Expand Down
11 changes: 5 additions & 6 deletions src/createColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ export function createColors(from: RGB, to: RGB, shades: number, alpha: Alpha =
to[1] - from[1],
to[2] - from[2]
]
if (alpha) {
start.push(alpha[0])
diff.push(alpha[1] - alpha[0])
}

start.push(alpha[0])
diff.push(alpha[1] - alpha[0])

const inc = 1 /
Math.max(shades - 1, 1)
Math.max(shades - 1, 1)

for (let i = 0; i < shades; i++) {
const color = [
Math.round(start[0] + i * diff[0] * inc),
Math.round(start[1] + i * diff[1] * inc),
Math.round(start[2] + i * diff[2] * inc),
alpha ? start[3] + i * diff[3] * inc : 1
start[3] + i * diff[3] * inc
]
rgba.push(color)
}
Expand Down

0 comments on commit 1a12eb8

Please sign in to comment.