1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.StackEnter = void 0;
|
4 | const util_1 = require("@antv/util");
|
5 | const d3_array_1 = require("d3-array");
|
6 | const helper_1 = require("./utils/helper");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const 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 |
|
22 |
|
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 |
|
28 |
|
29 |
|
30 |
|
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 |
|
37 | newGroups.push(...G);
|
38 | }
|
39 | groups = newGroups;
|
40 | }
|
41 |
|
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 |
|
50 | const t = (duration || 3000) / groups.length;
|
51 | const [ED] = duration
|
52 | ? [(0, helper_1.constant)(I, t)]
|
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 | };
|
74 | exports.StackEnter = StackEnter;
|
75 | exports.StackEnter.props = {};
|
76 |
|
\ | No newline at end of file |