All files / lib/util linear-scale.js

0% Statements 0/7
100% Branches 0/0
0% Functions 0/3
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                                 
export default class LinearScale {
  constructor(domain, range) {
    this.domain = domain
    this.range = range
  }
 
  compute(val) {
    const { domain: d, range: r } = this
    return ((val - d[0]) / (d[1] - d[0])) * (r[1] - r[0]) + r[0]
  }
 
  invert(val) {
    const { domain: d, range: r } = this
    return ((val - r[0]) / (r[1] - r[0])) * (d[1] - d[0]) + d[0]
  }
}