1 | "use strict";
|
2 | var __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 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | exports.SymmetryY = void 0;
|
15 | const util_1 = require("@antv/util");
|
16 | const d3_array_1 = require("d3-array");
|
17 | const helper_1 = require("./utils/helper");
|
18 | const order_1 = require("./utils/order");
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const SymmetryY = (options = {}) => {
|
24 | const { groupBy = 'x' } = options;
|
25 | return (I, mark) => {
|
26 | const { encode } = mark;
|
27 | const { x } = encode, rest = __rest(encode, ["x"]);
|
28 |
|
29 | const Yn = Object.entries(rest)
|
30 | .filter(([k]) => k.startsWith('y'))
|
31 | .map(([k]) => [k, (0, helper_1.columnOf)(encode, k)[0]]);
|
32 | const newYn = Yn.map(([k]) => [k, new Array(I.length)]);
|
33 |
|
34 | const groups = (0, order_1.createGroups)(groupBy, I, mark);
|
35 | const MY = new Array(groups.length);
|
36 | for (let i = 0; i < groups.length; i++) {
|
37 | const I = groups[i];
|
38 | const Y = I.flatMap((i) => Yn.map(([, V]) => +V[i]));
|
39 | const [minY, maxY] = (0, d3_array_1.extent)(Y);
|
40 | MY[i] = (minY + maxY) / 2;
|
41 | }
|
42 | const maxMiddleY = Math.max(...MY);
|
43 | for (let m = 0; m < groups.length; m++) {
|
44 | const offset = maxMiddleY - MY[m];
|
45 | const I = groups[m];
|
46 | for (const i of I) {
|
47 | for (let j = 0; j < Yn.length; j++) {
|
48 | const [, V] = Yn[j];
|
49 | const [, newV] = newYn[j];
|
50 | newV[i] = +V[i] + offset;
|
51 | }
|
52 | }
|
53 | }
|
54 | return [
|
55 | I,
|
56 | (0, util_1.deepMix)({}, mark, {
|
57 | encode: Object.fromEntries(newYn.map(([k, v]) => [k, (0, helper_1.column)(v, (0, helper_1.columnOf)(encode, k)[1])])),
|
58 | }),
|
59 | ];
|
60 | };
|
61 | };
|
62 | exports.SymmetryY = SymmetryY;
|
63 | exports.SymmetryY.props = {};
|
64 |
|
\ | No newline at end of file |