-
Notifications
You must be signed in to change notification settings - Fork 37
/
PowScale.ts
34 lines (28 loc) · 967 Bytes
/
PowScale.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*!
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/
import { ScaleCreationContext, Scales } from '@chart-parts/interfaces'
import { scalePow } from 'd3-scale'
import { QuantitativeScale, QuantitativeValue } from './QuantitativeScale'
export class PowScale extends QuantitativeScale<QuantitativeValue, number> {
protected defaultZero = true
private exponentValue?: number
public exponent(value?: number): this {
this.exponentValue = value
return this
}
protected createScale(args: ScaleCreationContext): Scales {
const domain = this.getDomain(args)
const range = this.getRange(args)
const result = scalePow().domain(domain).range(range)
this.addCommonProperties(result)
if (this.exponentValue !== undefined) {
result.exponent(this.exponentValue)
}
if (!this.nameValue) {
throw new Error('scale name must be set')
}
return { [this.nameValue]: result }
}
}