1 | import {Transform, ingest} from 'vega-dataflow';
|
2 | import {tickCount, tickFormat, tickValues, validTicks} from 'vega-scale';
|
3 | import {inherits} from 'vega-util';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export default function AxisTicks(params) {
|
22 | Transform.call(this, null, params);
|
23 | }
|
24 |
|
25 | var prototype = inherits(AxisTicks, Transform);
|
26 |
|
27 | prototype.transform = function(_, pulse) {
|
28 | if (this.value && !_.modified()) {
|
29 | return pulse.StopPropagation;
|
30 | }
|
31 |
|
32 | var locale = pulse.dataflow.locale(),
|
33 | out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS),
|
34 | ticks = this.value,
|
35 | scale = _.scale,
|
36 | tally = _.count == null ? (_.values ? _.values.length : 10) : _.count,
|
37 | count = tickCount(scale, tally, _.minstep),
|
38 | format = _.format || tickFormat(locale, scale, count, _.formatSpecifier, _.formatType, !!_.values),
|
39 | values = _.values ? validTicks(scale, _.values, count) : tickValues(scale, count);
|
40 |
|
41 | if (ticks) out.rem = ticks;
|
42 |
|
43 | ticks = values.map(function(value, i) {
|
44 | return ingest({
|
45 | index: i / (values.length - 1 || 1),
|
46 | value: value,
|
47 | label: format(value)
|
48 | });
|
49 | });
|
50 |
|
51 | if (_.extra && ticks.length) {
|
52 |
|
53 |
|
54 | ticks.push(ingest({
|
55 | index: -1,
|
56 | extra: {value: ticks[0].value},
|
57 | label: ''
|
58 | }));
|
59 | }
|
60 |
|
61 | out.source = ticks;
|
62 | out.add = ticks;
|
63 | this.value = ticks;
|
64 |
|
65 | return out;
|
66 | };
|