This repository has been archived by the owner on Dec 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscales.js
66 lines (58 loc) · 1.51 KB
/
scales.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import invertRange from './invertRange';
import invertRangeExtent from './invertRangeExtent';
import {
band as scaleBand,
point as scalePoint
} from './scaleBand';
import {
binLinear as scaleBinLinear,
binOrdinal as scaleBinOrdinal
} from './scaleBin';
import scaleSequential from './scaleSequential';
import * as $ from 'd3-scale';
/**
* Augment scales with their type and needed inverse methods.
*/
function create(type, constructor) {
return function scale() {
var s = constructor();
if (!s.invertRange) {
s.invertRange = s.invert ? invertRange(s)
: s.invertExtent ? invertRangeExtent(s)
: undefined;
}
s.type = type;
return s;
};
}
export default function scale(type, scale) {
if (arguments.length > 1) {
scales[type] = create(type, scale);
return this;
} else {
return scales.hasOwnProperty(type) ? scales[type] : undefined;
}
}
var scales = {
// base scale types
identity: $.scaleIdentity,
linear: $.scaleLinear,
log: $.scaleLog,
ordinal: $.scaleOrdinal,
pow: $.scalePow,
sqrt: $.scaleSqrt,
quantile: $.scaleQuantile,
quantize: $.scaleQuantize,
threshold: $.scaleThreshold,
time: $.scaleTime,
utc: $.scaleUtc,
// extended scale types
band: scaleBand,
point: scalePoint,
sequential: scaleSequential,
'bin-linear': scaleBinLinear,
'bin-ordinal': scaleBinOrdinal
};
for (var key in scales) {
scale(key, scales[key]);
}