1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Pack = void 0;
|
4 | const util_1 = require("@antv/util");
|
5 | const vector_1 = require("../utils/vector");
|
6 | function pack(options) {
|
7 | const { padding = 0, direction = 'col' } = options;
|
8 | return (P, count, layout) => {
|
9 | const pcount = P.length;
|
10 | if (pcount === 0)
|
11 | return [];
|
12 |
|
13 |
|
14 |
|
15 | const { innerWidth, innerHeight } = layout;
|
16 | const aspect = innerHeight / innerWidth;
|
17 | let col = Math.ceil(Math.sqrt(count / aspect));
|
18 |
|
19 |
|
20 | let size = innerWidth / col;
|
21 | let row = Math.ceil(count / col);
|
22 | let h0 = row * size;
|
23 | while (h0 > innerHeight) {
|
24 | col = col + 1;
|
25 | size = innerWidth / col;
|
26 | row = Math.ceil(count / col);
|
27 | h0 = row * size;
|
28 | }
|
29 |
|
30 | const space = innerHeight - row * size;
|
31 | const intervalY = row <= 1 ? 0 : space / (row - 1);
|
32 | const [offsetX, offsetY] = row <= 1
|
33 | ? [
|
34 | (innerWidth - pcount * size) / (pcount - 1),
|
35 | (innerHeight - size) / 2,
|
36 | ]
|
37 | : [0, 0];
|
38 | return P.map((points, m) => {
|
39 | const [x, y, width, height] = (0, vector_1.calcBBox)(points);
|
40 | const i = direction === 'col' ? m % col : Math.floor(m / row);
|
41 | const j = direction === 'col' ? Math.floor(m / col) : m % row;
|
42 | const newX = i * size;
|
43 | const newY = (row - j - 1) * size + space;
|
44 | const sx = (size - padding) / width;
|
45 | const sy = (size - padding) / height;
|
46 |
|
47 |
|
48 | const tx = newX - x + offsetX * i + (1 / 2) * padding;
|
49 | const ty = newY - y - intervalY * j - offsetY + (1 / 2) * padding;
|
50 | return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
51 | });
|
52 | };
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | const Pack = (options) => {
|
60 | return (I, mark) => {
|
61 | return [I, (0, util_1.deepMix)({}, mark, { modifier: pack(options), axis: false })];
|
62 | };
|
63 | };
|
64 | exports.Pack = Pack;
|
65 | exports.Pack.props = {};
|
66 |
|
\ | No newline at end of file |