UNPKG

3.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.StackEnter = void 0;
4const util_1 = require("@antv/util");
5const d3_array_1 = require("d3-array");
6const helper_1 = require("./utils/helper");
7/**
8 * Group marks by channels into groups and stacking their enterDelay
9 * to make marks show up groups by groups.
10 * It will update enterDelay channel for each mark by its enterDuration and group.
11 * @todo Support orderBy.
12 * @todo Sort among groups(e.g. reverse).
13 * @todo Stack enter in groups rather than between groups?
14 * @todo Auto inter this statistic for scaleInY animation in stacked interval?
15 * @todo All the groups shared the enterDuration?
16 */
17const StackEnter = (options) => {
18 const { groupBy = ['x'], reducer = (I, V) => V[I[0]], orderBy = null, reverse = false, duration, } = options;
19 return (I, mark) => {
20 const { encode } = mark;
21 // Extract group information by each specified channel,
22 // and skip if all values of channels are empty.
23 const by = Array.isArray(groupBy) ? groupBy : [groupBy];
24 const groupEntries = by.map((k) => [k, (0, helper_1.columnOf)(encode, k)[0]]);
25 if (groupEntries.length === 0)
26 return [I, mark];
27 // Nest group index and flatten them in right order among timeline.
28 // [[1, 2, 3, 4, 5, 6]] ->
29 // [[1, 2, 3], [4, 5, 6]] ->
30 // [[1], [2], [3], [4], [5], [6]]
31 let groups = [I];
32 for (const [, V] of groupEntries) {
33 const newGroups = [];
34 for (const I of groups) {
35 const G = Array.from((0, d3_array_1.group)(I, (i) => V[i]).values());
36 // @todo sort by x.
37 newGroups.push(...G);
38 }
39 groups = newGroups;
40 }
41 // const {color} = encode;
42 if (orderBy) {
43 const [V] = (0, helper_1.columnOf)(encode, orderBy);
44 if (V)
45 groups.sort((I, J) => reducer(I, V) - reducer(J, V));
46 if (reverse)
47 groups.reverse();
48 }
49 // Stack delay for each group.
50 const t = (duration || 3000) / groups.length;
51 const [ED] = duration
52 ? [(0, helper_1.constant)(I, t)] // If specified duration, generate enter duration for each.
53 : (0, helper_1.maybeColumnOf)(encode, 'enterDuration', (0, helper_1.constant)(I, t));
54 const [EDL] = (0, helper_1.maybeColumnOf)(encode, 'enterDelay', (0, helper_1.constant)(I, 0));
55 const newEnterDelay = new Array(I.length);
56 for (let i = 0, pd = 0; i < groups.length; i++) {
57 const I = groups[i];
58 const maxDuration = (0, d3_array_1.max)(I, (i) => +ED[i]);
59 for (const j of I)
60 newEnterDelay[j] = +EDL[j] + pd;
61 pd += maxDuration;
62 }
63 return [
64 I,
65 (0, util_1.deepMix)({}, mark, {
66 encode: {
67 enterDuration: (0, helper_1.visualColumn)(ED),
68 enterDelay: (0, helper_1.visualColumn)(newEnterDelay),
69 },
70 }),
71 ];
72 };
73};
74exports.StackEnter = StackEnter;
75exports.StackEnter.props = {};
76//# sourceMappingURL=stackEnter.js.map
\No newline at end of file