-
Notifications
You must be signed in to change notification settings - Fork 37
/
QuantileScale.ts
33 lines (29 loc) · 1.01 KB
/
QuantileScale.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
/*!
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/
import { ScaleCreationContext } from '@chart-parts/interfaces'
import { ScaleQuantile, scaleQuantile } from 'd3-scale'
import { DomainRangeScale } from './DomainRangeScale'
import { QuantitativeValue } from './quantitative/QuantitativeScale'
export class QuantileScale<
DomainValue extends QuantitativeValue,
RangeValue extends QuantitativeValue,
> extends DomainRangeScale<[DomainValue, DomainValue], RangeValue[], any> {
public handleRangeBind(): any[] {
throw new Error('cannot use range binding on Quantize scale')
}
public createScale(args: ScaleCreationContext) {
const domain = this.getDomain(args)
const range = this.getRange(args)
const scale: ScaleQuantile<RangeValue> = scaleQuantile()
.domain(domain)
.range(range as any) as ScaleQuantile<RangeValue>
if (!this.nameValue) {
throw new Error('scale name must be defined')
}
return {
[this.nameValue]: scale,
}
}
}