UNPKG

2.79 kBJavaScriptView Raw
1"use strict";
2var __rest = (this && this.__rest) || function (s, e) {
3 var t = {};
4 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5 t[p] = s[p];
6 if (s != null && typeof Object.getOwnPropertySymbols === "function")
7 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9 t[p[i]] = s[p[i]];
10 }
11 return t;
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.DodgeX = void 0;
15const util_1 = require("@antv/util");
16const helper_1 = require("./utils/helper");
17const order_1 = require("./utils/order");
18/**
19 * The dodge group marks into series by color or series channel,
20 * and then produce new series channel for each series by specified order,
21 * say to form horizontal "columns" by specified channels.
22 */
23const DodgeX = (options = {}) => {
24 const { groupBy = 'x', reverse = false, orderBy, padding } = options, rest = __rest(options, ["groupBy", "reverse", "orderBy", "padding"]);
25 return (I, mark) => {
26 const { data, encode, scale } = mark;
27 const { series: scaleSeries } = scale;
28 const [Y] = (0, helper_1.columnOf)(encode, 'y');
29 const [S] = (0, helper_1.maybeColumnOf)(encode, 'series', 'color');
30 const domainSeries = (0, order_1.domainOf)(S, scaleSeries);
31 const newMark = (0, util_1.deepMix)({}, mark, {
32 scale: {
33 series: {
34 domain: domainSeries,
35 paddingInner: padding,
36 },
37 },
38 });
39 // Create groups and apply specified order for each group.
40 const groups = (0, order_1.createGroups)(groupBy, I, mark);
41 const createComparator = (0, order_1.normalizeComparator)(orderBy);
42 if (!createComparator) {
43 return [I, (0, util_1.deepMix)(newMark, { encode: { series: (0, helper_1.column)(S) } })];
44 }
45 // Sort and Update series for each mark related to series domain.
46 const comparator = createComparator(data, Y, S);
47 if (comparator)
48 (0, order_1.applyOrder)(groups, comparator);
49 const newS = new Array(I.length);
50 for (const G of groups) {
51 if (reverse)
52 G.reverse();
53 for (let i = 0; i < G.length; i++) {
54 newS[G[i]] = domainSeries[i];
55 }
56 }
57 return [
58 I,
59 (0, util_1.deepMix)(newMark, {
60 encode: {
61 series: (0, helper_1.column)(orderBy ? newS : S),
62 },
63 }),
64 ];
65 };
66};
67exports.DodgeX = DodgeX;
68exports.DodgeX.props = {};
69//# sourceMappingURL=dodgeX.js.map
\No newline at end of file