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 | 1
1
1
1
1
7
7
7
2
7
3
7
1
7
5
7
1
6
6
6
6
6
6
7
7
3
4
6
2
2
2
2
2
1
1
1
2
2
2
2
4
4
6
5
5
5
5
5
1
1
1
5
5
5
5
1
1
6
6
5
6
6
6
1
1
| var util = require('../util');
var consts_1 = require('../consts');
var axis_1 = require('./axis');
var scale = require('./scale');
function groupdef(name, opt) {
opt = opt || {};
var group = {
name: name || undefined,
type: 'group',
properties: {
enter: {
width: opt.width || { field: { group: 'width' } },
height: opt.height || { field: { group: 'height' } }
}
}
};
if (opt.from) {
group.from = opt.from;
}
if (opt.x) {
group.properties.enter.x = opt.x;
}
if (opt.y) {
group.properties.enter.y = opt.y;
}
if (opt.axes) {
group.axes = opt.axes;
}
return group;
}
function default_1(group, encoding, layout, output, singleScaleNames, stats) {
var enter = group.properties.enter;
var facetKeys = [], cellAxes = [], from, axesGrp;
var hasRow = encoding.has(consts_1.Enctype.ROW), hasCol = encoding.has(consts_1.Enctype.COL);
enter.fill = { value: encoding.config('cellBackgroundColor') };
group.from = { data: group.marks[0].from.data };
for (var i = 0; i < group.marks.length; i++) {
var mark = group.marks[i];
if (mark.from.transform) {
delete mark.from.data;
}
else {
delete mark.from;
}
}
if (hasRow) {
Iif (!encoding.isDimension(consts_1.Enctype.ROW)) {
util.error('Row encoding should be ordinal.');
}
enter.y = { scale: consts_1.Enctype.ROW, field: encoding.fieldRef(consts_1.Enctype.ROW) };
enter.height = { 'value': layout.cellHeight };
facetKeys.push(encoding.fieldRef(consts_1.Enctype.ROW));
if (hasCol) {
from = util.duplicate(group.from);
from.transform = from.transform || [];
from.transform.unshift({ type: 'facet', groupby: [encoding.fieldRef(consts_1.Enctype.COL)] });
}
axesGrp = groupdef('x-axes', {
axes: encoding.has(consts_1.Enctype.X) ? [axis_1.default(consts_1.Enctype.X, encoding, layout, stats)] : undefined,
x: hasCol ? { scale: consts_1.Enctype.COL, field: encoding.fieldRef(consts_1.Enctype.COL) } : { value: 0 },
width: hasCol && { 'value': layout.cellWidth },
from: from
});
output.marks.unshift(axesGrp);
(output.axes = output.axes || []);
output.axes.push(axis_1.default(consts_1.Enctype.ROW, encoding, layout, stats));
}
else {
Eif (encoding.has(consts_1.Enctype.X)) {
cellAxes.push(axis_1.default(consts_1.Enctype.X, encoding, layout, stats));
}
}
if (hasCol) {
Iif (!encoding.isDimension(consts_1.Enctype.COL)) {
util.error('Col encoding should be ordinal.');
}
enter.x = { scale: consts_1.Enctype.COL, field: encoding.fieldRef(consts_1.Enctype.COL) };
enter.width = { 'value': layout.cellWidth };
facetKeys.push(encoding.fieldRef(consts_1.Enctype.COL));
if (hasRow) {
from = util.duplicate(group.from);
from.transform = from.transform || [];
from.transform.unshift({ type: 'facet', groupby: [encoding.fieldRef(consts_1.Enctype.ROW)] });
}
axesGrp = groupdef('y-axes', {
axes: encoding.has(consts_1.Enctype.Y) ? [axis_1.default(consts_1.Enctype.Y, encoding, layout, stats)] : undefined,
y: hasRow && { scale: consts_1.Enctype.ROW, field: encoding.fieldRef(consts_1.Enctype.ROW) },
x: hasRow && { value: 0 },
height: hasRow && { 'value': layout.cellHeight },
from: from
});
output.marks.unshift(axesGrp);
(output.axes = output.axes || []);
output.axes.push(axis_1.default(consts_1.Enctype.COL, encoding, layout, stats));
}
else {
Eif (encoding.has(consts_1.Enctype.Y)) {
cellAxes.push(axis_1.default(consts_1.Enctype.Y, encoding, layout, stats));
}
}
output.scales = (output.scales || []).concat(scale.defs(scale.names(enter).concat(singleScaleNames), encoding, layout, stats, true));
if (cellAxes.length > 0) {
group.axes = cellAxes;
}
var trans = (group.from.transform || (group.from.transform = []));
trans.unshift({ type: 'facet', groupby: facetKeys });
return output;
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
//# sourceMappingURL=facet.js.map |