1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.StackY = void 0;
|
4 | const util_1 = require("@antv/util");
|
5 | const helper_1 = require("./utils/helper");
|
6 | const order_1 = require("./utils/order");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const StackY = (options = {}) => {
|
13 | const { groupBy = 'x', orderBy = null, reverse = false, y: fromY = 'y', y1: fromY1 = 'y1', series = true, } = options;
|
14 | return (I, mark) => {
|
15 | var _a;
|
16 | const { data, encode, style = {} } = mark;
|
17 | const [Y, fy] = (0, helper_1.columnOf)(encode, 'y');
|
18 | const [Y1, fy1] = (0, helper_1.columnOf)(encode, 'y1');
|
19 | const [S] = series
|
20 | ? (0, helper_1.maybeColumnOf)(encode, 'series', 'color')
|
21 | : (0, helper_1.columnOf)(encode, 'color');
|
22 |
|
23 | const groups = (0, order_1.createGroups)(groupBy, I, mark);
|
24 | const createComparator = (_a = (0, order_1.normalizeComparator)(orderBy)) !== null && _a !== void 0 ? _a : (() => null);
|
25 | const comparator = createComparator(data, Y, S);
|
26 | if (comparator)
|
27 | (0, order_1.applyOrder)(groups, comparator);
|
28 |
|
29 | const newY = new Array(I.length);
|
30 | const newY1 = new Array(I.length);
|
31 | const TY = new Array(I.length);
|
32 | const F = [];
|
33 | const L = [];
|
34 | for (const G of groups) {
|
35 | if (reverse)
|
36 | G.reverse();
|
37 |
|
38 | const start = Y1 ? +Y1[G[0]] : 0;
|
39 |
|
40 | const PG = [];
|
41 | const NG = [];
|
42 | for (const i of G) {
|
43 | const y = (TY[i] = +Y[i] - start);
|
44 | if (y < 0)
|
45 | NG.push(i);
|
46 | else if (y >= 0)
|
47 | PG.push(i);
|
48 | }
|
49 |
|
50 | const FG = PG.length > 0 ? PG : NG;
|
51 | const LG = NG.length > 0 ? NG : PG;
|
52 | let i = PG.length - 1;
|
53 | let j = 0;
|
54 |
|
55 | while (i > 0 && Y[FG[i]] === 0)
|
56 | i--;
|
57 |
|
58 | while (j < LG.length - 1 && Y[LG[j]] === 0)
|
59 | j++;
|
60 | F.push(FG[i]);
|
61 | L.push(LG[j]);
|
62 |
|
63 | let ny = start;
|
64 | for (const i of NG.reverse()) {
|
65 | const y = TY[i];
|
66 | ny = newY[i] = (newY1[i] = ny) + y;
|
67 | }
|
68 |
|
69 | let py = start;
|
70 | for (const i of PG) {
|
71 | const y = TY[i];
|
72 | if (y > 0)
|
73 | py = newY[i] = (newY1[i] = py) + y;
|
74 | else
|
75 | newY[i] = newY1[i] = py;
|
76 | }
|
77 | }
|
78 |
|
79 |
|
80 | const FS = new Set(F);
|
81 | const LS = new Set(L);
|
82 |
|
83 | const V = fromY === 'y' ? newY : newY1;
|
84 | const V1 = fromY1 === 'y' ? newY : newY1;
|
85 | return [
|
86 | I,
|
87 | (0, util_1.deepMix)({}, mark, {
|
88 | encode: {
|
89 | y0: (0, helper_1.inferredColumn)(Y, fy),
|
90 | y: (0, helper_1.column)(V, fy),
|
91 | y1: (0, helper_1.column)(V1, fy1),
|
92 | },
|
93 | style: Object.assign({ first: (_, i) => FS.has(i), last: (_, i) => LS.has(i) }, style),
|
94 | }),
|
95 | ];
|
96 | };
|
97 | };
|
98 | exports.StackY = StackY;
|
99 | exports.StackY.props = {};
|
100 |
|
\ | No newline at end of file |