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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 | 1
1
1
1
85
85
85
1360
1360
1360
372
85
85
595
595
102
102
85
1
1
1
85
85
85
53
32
5
5
5
4
28
1
1
85
85
85
1
1
85
85
85
2
83
1
1
89
89
1
88
6
82
2
80
1
1
85
85
85
31
54
1
1
170
170
170
14
156
1
1
90
90
2
88
88
88
3
85
41
44
37
88
1
1
85
85
85
2
5
78
1
1
1
1
85
7
78
1
1
85
85
52
5
5
47
2
2
45
33
1
1
85
85
1
85
27
85
40
28
85
1
1
85
2
83
1
| var util = require('../util');
var consts_1 = require('../consts');
var time = require('./time');
function default_1(name, encoding, layout, stats) {
var isCol = name == consts_1.Enctype.COL, isRow = name == consts_1.Enctype.ROW, type = isCol ? 'x' : isRow ? 'y' : name;
var def = {
type: type,
scale: name
};
[
'format', 'grid', 'offset', 'orient', 'tickSize', 'ticks', 'title', 'titleOffset',
'layer', 'tickPadding', 'tickSize', 'tickSizeMajor', 'tickSizeMinor', 'tickSizeEnd',
'values', 'subdivide'
].forEach(function (property) {
var method;
var value = (method = exports[property]) ?
method(encoding, name, layout, stats) :
encoding.encDef(name).axis[property];
if (value !== undefined) {
def[property] = value;
}
});
var props = encoding.encDef(name).axis.properties || {};
[
'axis', 'grid', 'labels', 'title',
'ticks', 'majorTicks', 'minorTicks'
].forEach(function (property) {
var value = properties[property] ?
properties[property](encoding, name, props[property], layout, def) :
props[property];
if (value !== undefined) {
def.properties = def.properties || {};
def.properties[property] = value;
}
});
return def;
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
;
function format(encoding, name) {
var format = encoding.encDef(name).axis.format;
Iif (format !== undefined) {
return format;
}
if (encoding.isType(name, consts_1.Type.Q)) {
return encoding.numberFormat(name);
}
else if (encoding.isType(name, consts_1.Type.T)) {
var timeUnit = encoding.encDef(name).timeUnit;
Iif (!timeUnit) {
return encoding.config('timeFormat');
}
else if (timeUnit === 'year') {
return 'd';
}
}
return undefined;
}
exports.format = format;
;
function grid(encoding, name) {
var grid = encoding.axis(name).grid;
Iif (grid !== undefined) {
return grid;
}
return name === consts_1.Enctype.ROW || name === consts_1.Enctype.COL ||
(encoding.isTypes(name, [consts_1.Type.Q, consts_1.Type.T]) && !encoding.encDef(name).bin);
}
exports.grid = grid;
;
function offset(encoding, name, layout) {
var offset = encoding.encDef(name).axis.offset;
Iif (offset) {
return offset;
}
if (name === consts_1.Enctype.ROW) {
return layout.y.axisTitleOffset + 20;
}
return undefined;
}
exports.offset = offset;
;
function orient(encoding, name, layout, stats) {
var orient = encoding.encDef(name).axis.orient;
if (orient) {
return orient;
}
else if (name === consts_1.Enctype.COL) {
return 'top';
}
else if (name === consts_1.Enctype.X && encoding.has(consts_1.Enctype.Y) && encoding.isOrdinalScale(consts_1.Enctype.Y) && encoding.cardinality(consts_1.Enctype.Y, stats) > 30) {
return 'top';
}
return undefined;
}
exports.orient = orient;
;
function ticks(encoding, name) {
var ticks = encoding.encDef(name).axis.ticks;
Iif (ticks !== undefined) {
return ticks;
}
if (name === consts_1.Enctype.X && !encoding.encDef(name).bin) {
return 5;
}
return undefined;
}
exports.ticks = ticks;
;
function tickSize(encoding, name) {
var tickSize = encoding.encDef(name).axis.tickSize;
Iif (tickSize !== undefined) {
return tickSize;
}
if (name === consts_1.Enctype.ROW || name === consts_1.Enctype.COL) {
return 0;
}
return undefined;
}
exports.tickSize = tickSize;
;
function title(encoding, name, layout) {
var axisSpec = encoding.encDef(name).axis;
if (axisSpec.title !== undefined) {
return axisSpec.title;
}
var fieldTitle = encoding.fieldTitle(name);
var maxLength;
if (axisSpec.titleMaxLength) {
maxLength = axisSpec.titleMaxLength;
}
else if (name === consts_1.Enctype.X) {
maxLength = layout.cellWidth / encoding.config('characterWidth');
}
else if (name === consts_1.Enctype.Y) {
maxLength = layout.cellHeight / encoding.config('characterWidth');
}
return maxLength ? util.truncate(fieldTitle, maxLength) : fieldTitle;
}
exports.title = title;
;
function titleOffset(encoding, name) {
var value = encoding.axis(name).titleOffset;
Iif (value)
return value;
switch (name) {
case consts_1.Enctype.ROW: return 0;
case consts_1.Enctype.COL: return 35;
}
return undefined;
}
exports.titleOffset = titleOffset;
;
var properties;
(function (properties) {
function axis(encoding, name, spec) {
if (name === consts_1.Enctype.ROW || name === consts_1.Enctype.COL) {
return util.extend({
opacity: { value: 0 }
}, spec || {});
}
return spec || undefined;
}
properties.axis = axis;
function grid(encoding, name, spec, layout, def) {
var cellPadding = layout.cellPadding;
if (def.grid) {
if (name == consts_1.Enctype.COL) {
var yOffset = encoding.config('cellGridOffset');
return util.extend({
x: {
offset: layout.cellWidth * (1 + cellPadding / 2.0),
scale: 'col',
field: 'data'
},
y: {
value: -yOffset,
},
y2: {
field: { group: 'mark.group.height' },
offset: yOffset
},
stroke: { value: encoding.config('cellGridColor') },
strokeOpacity: { value: encoding.config('cellGridOpacity') }
}, spec || {});
}
else if (name == consts_1.Enctype.ROW) {
var xOffset = encoding.config('cellGridOffset');
return util.extend({
y: {
offset: -layout.cellHeight * (cellPadding / 2),
scale: 'row',
field: 'data'
},
x: {
value: def.offset - xOffset
},
x2: {
field: { group: 'mark.group.width' },
offset: def.offset + xOffset,
mult: 1
},
stroke: { value: encoding.config('cellGridColor') },
strokeOpacity: { value: encoding.config('cellGridOpacity') }
}, spec || {});
}
else {
return util.extend({
stroke: { value: encoding.config('gridColor') },
strokeOpacity: { value: encoding.config('gridOpacity') }
}, spec || {});
}
}
return spec || undefined;
}
properties.grid = grid;
function labels(encoding, name, spec, layout, def) {
var timeUnit = encoding.encDef(name).timeUnit;
if (encoding.isType(name, consts_1.Type.T) && timeUnit && (time.hasScale(timeUnit))) {
spec = util.extend({
text: { scale: 'time-' + timeUnit }
}, spec || {});
}
if (encoding.isTypes(name, [consts_1.Type.N, consts_1.Type.O]) && encoding.axis(name).labelMaxLength) {
spec = util.extend({
text: {
template: '{{ datum.data | truncate:' + encoding.axis(name).labelMaxLength + '}}'
}
}, spec || {});
}
if (name == consts_1.Enctype.X) {
if ((encoding.isDimension(consts_1.Enctype.X) || encoding.isType(consts_1.Enctype.X, consts_1.Type.T))) {
spec = util.extend({
angle: { value: 270 },
align: { value: def.orient === 'top' ? 'left' : 'right' },
baseline: { value: 'middle' }
}, spec || {});
}
}
return spec || undefined;
}
properties.labels = labels;
function title(encoding, name, spec, layout) {
if (name === consts_1.Enctype.ROW) {
return util.extend({
angle: { value: 0 },
align: { value: 'right' },
baseline: { value: 'middle' },
dy: { value: (-layout.height / 2) - 20 }
}, spec || {});
}
return spec || undefined;
}
properties.title = title;
})(properties || (properties = {}));
;
//# sourceMappingURL=axis.js.map |