/
encode.test.ts
95 lines (88 loc) · 3.24 KB
/
encode.test.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as encode from '../../../src/compile/axis/encode';
import {parseUnitModelWithScale} from '../../util';
describe('compile/axis/encode', () => {
describe('encode.labels()', () => {
it('should not rotate label for temporal field by default', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'temporal', timeUnit: 'month'}
}
});
const labels = encode.labels(model, 'x', {});
expect(labels?.angle).toBeUndefined();
});
it('should do not rotate label for temporal field if labelAngle is specified in axis config', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'temporal', timeUnit: 'month'}
},
config: {axisX: {labelAngle: 90}}
});
const labels = encode.labels(model, 'x', {});
expect(labels?.angle).toBeUndefined();
});
it('applies custom format type', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'quantitative', axis: {format: 'abc', formatType: 'customNumberFormat'}}
},
config: {customFormatTypes: true}
});
const labels = encode.labels(model, 'x', {});
expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")');
});
it('applies custom format type without format', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'quantitative', axis: {formatType: 'customNumberFormat'}}
},
config: {customFormatTypes: true}
});
const labels = encode.labels(model, 'x', {});
expect(labels.text.signal).toBe('customNumberFormat(datum.value)');
});
it('applies custom format type from config', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'quantitative'}
},
config: {customFormatTypes: true, numberFormat: 'abc', numberFormatType: 'customNumberFormat'}
});
const labels = encode.labels(model, 'x', {});
expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")');
});
it('applies custom format type from a normalized stack', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'quantitative', stack: 'normalize'}
},
config: {
customFormatTypes: true,
normalizedNumberFormat: 'abc',
normalizedNumberFormatType: 'customNumberFormat'
}
});
const labels = encode.labels(model, 'x', {});
expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")');
});
it('applies default formatting to a normalized stack', () => {
const model = parseUnitModelWithScale({
mark: 'point',
encoding: {
x: {field: 'a', type: 'quantitative', stack: 'normalize'}
},
config: {
normalizedNumberFormat: 'abc'
}
});
const labels = encode.labels(model, 'x', {});
expect(labels.text.signal).toBe('format(datum.value, "abc")');
});
});
});