@antv/g2 5.1.12 → 5.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/api/utils.js +22 -12
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +13 -7
- package/esm/component/axis.js.map +1 -1
- package/esm/component/utils.js +2 -2
- package/esm/component/utils.js.map +1 -1
- package/esm/coordinate/polar.d.ts +1 -1
- package/esm/coordinate/polar.js +3 -1
- package/esm/coordinate/polar.js.map +1 -1
- package/esm/interaction/event.js +15 -3
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/utils.js +1 -1
- package/esm/interaction/utils.js.map +1 -1
- package/esm/mark/liquid.js +2 -2
- package/esm/mark/liquid.js.map +1 -1
- package/esm/runtime/component.js +1 -1
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +6 -1
- package/esm/runtime/plot.js.map +1 -1
- package/esm/spec/transform.d.ts +2 -0
- package/esm/transform/pack.d.ts +2 -1
- package/esm/transform/pack.js +49 -43
- package/esm/transform/pack.js.map +1 -1
- package/esm/utils/angle.d.ts +4 -0
- package/esm/utils/angle.js +18 -0
- package/esm/utils/angle.js.map +1 -1
- package/lib/api/utils.js +22 -12
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +13 -7
- package/lib/component/axis.js.map +1 -1
- package/lib/component/utils.js +2 -2
- package/lib/component/utils.js.map +1 -1
- package/lib/coordinate/polar.d.ts +1 -1
- package/lib/coordinate/polar.js +3 -1
- package/lib/coordinate/polar.js.map +1 -1
- package/lib/interaction/event.js +15 -3
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/utils.js +1 -1
- package/lib/interaction/utils.js.map +1 -1
- package/lib/mark/liquid.js +2 -2
- package/lib/mark/liquid.js.map +1 -1
- package/lib/runtime/component.js +1 -1
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +6 -1
- package/lib/runtime/plot.js.map +1 -1
- package/lib/spec/transform.d.ts +2 -0
- package/lib/transform/pack.d.ts +2 -1
- package/lib/transform/pack.js +49 -43
- package/lib/transform/pack.js.map +1 -1
- package/lib/utils/angle.d.ts +4 -0
- package/lib/utils/angle.js +20 -1
- package/lib/utils/angle.js.map +1 -1
- package/package.json +2 -2
- package/src/api/utils.ts +35 -10
- package/src/component/axis.ts +17 -10
- package/src/component/utils.ts +2 -2
- package/src/coordinate/polar.ts +6 -1
- package/src/interaction/event.ts +20 -7
- package/src/interaction/utils.ts +1 -1
- package/src/mark/liquid.ts +6 -2
- package/src/runtime/component.ts +1 -1
- package/src/runtime/plot.ts +13 -3
- package/src/spec/transform.ts +2 -0
- package/src/transform/pack.ts +51 -45
- package/src/utils/angle.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.14",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"build": "run-p build:*",
|
|
42
42
|
"bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
|
|
43
43
|
"ci": "run-s lint test build",
|
|
44
|
-
"prepublishOnly": "
|
|
44
|
+
"prepublishOnly": "",
|
|
45
45
|
"prepare": "husky install",
|
|
46
46
|
"upload": "node scripts/upload/snapshot.js",
|
|
47
47
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
package/src/api/utils.ts
CHANGED
|
@@ -133,25 +133,44 @@ function isMark(
|
|
|
133
133
|
return new Set(Object.keys(mark)).has(type);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
function isComposition(
|
|
137
|
+
type: string | ((...args: any[]) => any),
|
|
138
|
+
composition: Record<string, new () => Node>,
|
|
139
|
+
): boolean {
|
|
140
|
+
return (
|
|
141
|
+
typeof type !== 'function' && new Set(Object.keys(composition)).has(type)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
136
145
|
function normalizeRootOptions(
|
|
137
146
|
node: Node,
|
|
138
147
|
options: G2ViewTree,
|
|
139
148
|
previousType: string,
|
|
140
149
|
marks: Record<string, new () => Node>,
|
|
150
|
+
composition: Record<string, new () => Node>,
|
|
141
151
|
) {
|
|
142
152
|
const { type: oldType } = node;
|
|
143
153
|
const { type = previousType || oldType } = options;
|
|
144
|
-
if (type
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
if (isComposition(type, composition)) {
|
|
155
|
+
for (const key of VIEW_KEYS) {
|
|
156
|
+
if (node.attr(key) !== undefined && options[key] === undefined) {
|
|
157
|
+
options[key] = node.attr(key);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return options;
|
|
161
|
+
}
|
|
162
|
+
if (isMark(type, marks)) {
|
|
163
|
+
const view = { type: 'view' };
|
|
164
|
+
const mark = { ...options };
|
|
165
|
+
for (const key of VIEW_KEYS) {
|
|
166
|
+
if (mark[key] !== undefined) {
|
|
167
|
+
view[key] = mark[key];
|
|
168
|
+
delete mark[key];
|
|
169
|
+
}
|
|
152
170
|
}
|
|
171
|
+
return { ...view, children: [mark] };
|
|
153
172
|
}
|
|
154
|
-
return
|
|
173
|
+
return options;
|
|
155
174
|
}
|
|
156
175
|
|
|
157
176
|
function typeCtor(
|
|
@@ -232,7 +251,13 @@ export function updateRoot(
|
|
|
232
251
|
mark: Record<string, new () => Node>,
|
|
233
252
|
composition: Record<string, new () => Node>,
|
|
234
253
|
) {
|
|
235
|
-
const rootOptions = normalizeRootOptions(
|
|
254
|
+
const rootOptions = normalizeRootOptions(
|
|
255
|
+
node,
|
|
256
|
+
options,
|
|
257
|
+
definedType,
|
|
258
|
+
mark,
|
|
259
|
+
composition,
|
|
260
|
+
);
|
|
236
261
|
const discovered: [Node, Node, G2ViewTree][] = [[null, node, rootOptions]];
|
|
237
262
|
while (discovered.length) {
|
|
238
263
|
const [parent, oldNode, newNode] = discovered.shift();
|
package/src/component/axis.ts
CHANGED
|
@@ -328,6 +328,7 @@ function inferAxisLinearOverrideStyle(
|
|
|
328
328
|
orientation: GCO,
|
|
329
329
|
bbox: BBox,
|
|
330
330
|
coordinate: Coordinate,
|
|
331
|
+
xScale: Scale,
|
|
331
332
|
): {
|
|
332
333
|
startPos?: [number, number];
|
|
333
334
|
endPos?: [number, number];
|
|
@@ -387,14 +388,23 @@ function inferAxisLinearOverrideStyle(
|
|
|
387
388
|
actualCy + innerR * sin,
|
|
388
389
|
];
|
|
389
390
|
|
|
391
|
+
const getAxisXDomainLength = () => {
|
|
392
|
+
const { domain } = xScale.getOptions();
|
|
393
|
+
return domain.length;
|
|
394
|
+
};
|
|
395
|
+
const controllAngleCount =
|
|
396
|
+
isPolar(coordinate) && xScale ? getAxisXDomainLength() : 3;
|
|
397
|
+
|
|
390
398
|
return {
|
|
391
399
|
startPos,
|
|
392
400
|
endPos,
|
|
393
|
-
gridClosed: endAngle - startAngle
|
|
401
|
+
gridClosed: Math.abs(endAngle - startAngle - 360) < 1e-6,
|
|
394
402
|
gridCenter: [actualCx, actualCy],
|
|
395
|
-
gridControlAngles: new Array(
|
|
403
|
+
gridControlAngles: new Array(controllAngleCount)
|
|
396
404
|
.fill(0)
|
|
397
|
-
.map(
|
|
405
|
+
.map(
|
|
406
|
+
(d, i, arr) => ((endAngle - startAngle) / controllAngleCount) * i,
|
|
407
|
+
),
|
|
398
408
|
};
|
|
399
409
|
}
|
|
400
410
|
}
|
|
@@ -547,11 +557,10 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
547
557
|
indexBBox,
|
|
548
558
|
...userDefinitions
|
|
549
559
|
} = options;
|
|
550
|
-
|
|
551
|
-
return ({ scales: [scale], value, coordinate, theme }) => {
|
|
560
|
+
return ({ scales, value, coordinate, theme }) => {
|
|
552
561
|
const { bbox } = value;
|
|
553
|
-
const
|
|
554
|
-
|
|
562
|
+
const [scale] = scales;
|
|
563
|
+
const { domain, xScale } = scale.getOptions();
|
|
555
564
|
const defaultStyle = inferDefaultStyle(
|
|
556
565
|
scale,
|
|
557
566
|
coordinate,
|
|
@@ -560,7 +569,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
560
569
|
position,
|
|
561
570
|
orientation,
|
|
562
571
|
);
|
|
563
|
-
|
|
564
572
|
const internalAxisStyle = {
|
|
565
573
|
...defaultStyle,
|
|
566
574
|
...style,
|
|
@@ -578,6 +586,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
578
586
|
orientation,
|
|
579
587
|
bbox,
|
|
580
588
|
coordinate,
|
|
589
|
+
xScale,
|
|
581
590
|
);
|
|
582
591
|
|
|
583
592
|
const threeDOverrideStyle = infer3DAxisLinearOverrideStyle(coordinate);
|
|
@@ -604,7 +613,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
604
613
|
return { ...d, bbox: bbox[1] };
|
|
605
614
|
})
|
|
606
615
|
: data;
|
|
607
|
-
|
|
608
616
|
const finalAxisStyle = {
|
|
609
617
|
...internalAxisStyle,
|
|
610
618
|
type: 'linear' as const,
|
|
@@ -654,7 +662,6 @@ const axisFactor: (
|
|
|
654
662
|
: useDefinedLabelFormatter;
|
|
655
663
|
const labelFilter = (datum: any, index: number, array: any[]) =>
|
|
656
664
|
userDefinedLabelFilter(ticks[index], index, ticks);
|
|
657
|
-
|
|
658
665
|
const normalizedOptions = {
|
|
659
666
|
...options,
|
|
660
667
|
labelFormatter,
|
package/src/component/utils.ts
CHANGED
|
@@ -65,8 +65,8 @@ export function inferComponentLayout(
|
|
|
65
65
|
const layout = {
|
|
66
66
|
top: ['row', 'flex-start', 'center'],
|
|
67
67
|
bottom: ['row', 'flex-start', 'center'],
|
|
68
|
-
left: ['column', '
|
|
69
|
-
right: ['column', '
|
|
68
|
+
left: ['column', 'flex-start', 'center'],
|
|
69
|
+
right: ['column', 'flex-start', 'center'],
|
|
70
70
|
center: ['column', 'center', 'center'],
|
|
71
71
|
};
|
|
72
72
|
|
package/src/coordinate/polar.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { convertAngles } from '../utils/angle';
|
|
1
2
|
import { CoordinateComponent as CC } from '../runtime';
|
|
2
3
|
import { PolarCoordinate } from '../spec';
|
|
3
4
|
|
|
@@ -10,7 +11,11 @@ export const getPolarOptions = (options: PolarOptions = {}) => {
|
|
|
10
11
|
innerRadius: 0,
|
|
11
12
|
outerRadius: 1,
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
const polarOption = { ...defaultOptions, ...options };
|
|
15
|
+
return {
|
|
16
|
+
...polarOption,
|
|
17
|
+
...convertAngles(polarOption.startAngle, polarOption.endAngle),
|
|
18
|
+
};
|
|
14
19
|
};
|
|
15
20
|
/**
|
|
16
21
|
* Polar transformation for circular charts using center of canvas as origin.
|
package/src/interaction/event.ts
CHANGED
|
@@ -31,6 +31,11 @@ function maybeElementRoot(node) {
|
|
|
31
31
|
return maybeRoot(node, (node) => node.className === 'element');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// For extended label.
|
|
35
|
+
function maybeLabelRoot(node) {
|
|
36
|
+
return maybeRoot(node, (node) => node.className === 'label');
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
35
40
|
return (e) => {
|
|
36
41
|
if (!predicate(e)) return;
|
|
@@ -52,19 +57,27 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
|
52
57
|
const elementRoot = maybeElementRoot(target);
|
|
53
58
|
// If target is component or child of component.
|
|
54
59
|
const componentRoot = maybeComponentRoot(target);
|
|
55
|
-
|
|
60
|
+
// If target is babel or child of babel.
|
|
61
|
+
const babelRoot = maybeLabelRoot(target);
|
|
62
|
+
|
|
63
|
+
const root = elementRoot || componentRoot || babelRoot;
|
|
64
|
+
|
|
56
65
|
if (!root) return;
|
|
57
66
|
const { className: elementType, markType } = root;
|
|
67
|
+
const e1 = {
|
|
68
|
+
...e,
|
|
69
|
+
nativeEvent: true,
|
|
70
|
+
};
|
|
58
71
|
if (elementType === 'element') {
|
|
59
|
-
|
|
60
|
-
...e,
|
|
61
|
-
nativeEvent: true,
|
|
62
|
-
data: { data: dataOf(root, view) },
|
|
63
|
-
};
|
|
72
|
+
e1['data'] = { data: dataOf(root, view) };
|
|
64
73
|
emitter.emit(`element:${eventType}`, e1);
|
|
65
74
|
emitter.emit(`${markType}:${eventType}`, e1);
|
|
75
|
+
} else if (elementType === 'label') {
|
|
76
|
+
//label children [Text2, Rect2, Path2],
|
|
77
|
+
e1['data'] = { data: root.attributes.datum };
|
|
78
|
+
emitter.emit(`label:${eventType}`, e1);
|
|
79
|
+
emitter.emit(`${className}:${eventType}`, e1);
|
|
66
80
|
} else {
|
|
67
|
-
const e1 = { ...e, nativeEvent: true };
|
|
68
81
|
emitter.emit(`component:${eventType}`, e1);
|
|
69
82
|
emitter.emit(`${className}:${eventType}`, e1);
|
|
70
83
|
}
|
package/src/interaction/utils.ts
CHANGED
|
@@ -433,7 +433,7 @@ export function renderBackground({
|
|
|
433
433
|
const shapeOf = isOrdinalShape() ? bandShapeOf : cloneShapeOf;
|
|
434
434
|
const shape = shapeOf(element, finalStyle);
|
|
435
435
|
shape.className = BACKGROUND_CLASS_NAME;
|
|
436
|
-
element.parentNode.appendChild(shape);
|
|
436
|
+
element.parentNode.parentNode.appendChild(shape);
|
|
437
437
|
element.background = shape;
|
|
438
438
|
};
|
|
439
439
|
|
package/src/mark/liquid.ts
CHANGED
|
@@ -64,7 +64,11 @@ export const Liquid: CC<LiquidOptions> = (options) => {
|
|
|
64
64
|
|
|
65
65
|
const newData = [{ percent, type: 'liquid' }];
|
|
66
66
|
|
|
67
|
-
const
|
|
67
|
+
const contentStyle = {
|
|
68
|
+
...subObject(style, 'text'),
|
|
69
|
+
...subObject(style, 'content'),
|
|
70
|
+
};
|
|
71
|
+
|
|
68
72
|
const outline = subObject(style, 'outline');
|
|
69
73
|
const wave = subObject(style, 'wave');
|
|
70
74
|
const background = subObject(style, 'background');
|
|
@@ -91,7 +95,7 @@ export const Liquid: CC<LiquidOptions> = (options) => {
|
|
|
91
95
|
deepMix({}, DEFAULT_TEXT_OPTIONS, {
|
|
92
96
|
style: {
|
|
93
97
|
text: `${prettyNumber(percent * 100)} %`,
|
|
94
|
-
...
|
|
98
|
+
...contentStyle,
|
|
95
99
|
},
|
|
96
100
|
animate,
|
|
97
101
|
}),
|
package/src/runtime/component.ts
CHANGED
|
@@ -876,7 +876,7 @@ function computeCategoryLegendSize(
|
|
|
876
876
|
const titleHeight = titleBBox ? titleBBox.height : 0;
|
|
877
877
|
const maxHeight = crossSize - titleHeight;
|
|
878
878
|
for (const { width } of labelBBoxes) {
|
|
879
|
-
const w = widthOf(width);
|
|
879
|
+
const w = widthOf(width, colPadding);
|
|
880
880
|
maxSize = Math.max(maxSize, w);
|
|
881
881
|
if (pos + height > maxHeight) {
|
|
882
882
|
cols++;
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vector2 } from '@antv/coord';
|
|
2
2
|
import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
|
|
3
|
-
import { deepMix, upperFirst } from '@antv/util';
|
|
3
|
+
import { deepMix, get, upperFirst } from '@antv/util';
|
|
4
4
|
import { group, groups, sort } from 'd3-array';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
InteractionComponent,
|
|
67
67
|
LabelTransform,
|
|
68
68
|
LabelTransformComponent,
|
|
69
|
+
Scale,
|
|
69
70
|
Shape,
|
|
70
71
|
ShapeComponent,
|
|
71
72
|
Theme,
|
|
@@ -710,7 +711,7 @@ function initializeState(
|
|
|
710
711
|
processAxisZ(components);
|
|
711
712
|
|
|
712
713
|
// Scale from marks and components.
|
|
713
|
-
const scaleInstance = {};
|
|
714
|
+
const scaleInstance: Record<string, Scale> = {};
|
|
714
715
|
|
|
715
716
|
// Initialize scale from components.
|
|
716
717
|
for (const component of components) {
|
|
@@ -720,8 +721,17 @@ function initializeState(
|
|
|
720
721
|
const { name } = descriptor;
|
|
721
722
|
const scale = useRelationScale(descriptor, library);
|
|
722
723
|
scales.push(scale);
|
|
724
|
+
// Delivery the scale of axisX to the AxisY,
|
|
725
|
+
// in order to calculate the angle of axisY component when rendering radar chart.
|
|
726
|
+
if (name === 'y') {
|
|
727
|
+
scale.update({
|
|
728
|
+
...scale.getOptions(),
|
|
729
|
+
xScale: scaleInstance.x,
|
|
730
|
+
});
|
|
731
|
+
}
|
|
723
732
|
assignScale(scaleInstance, { [name]: scale });
|
|
724
733
|
}
|
|
734
|
+
|
|
725
735
|
component.scaleInstances = scales;
|
|
726
736
|
}
|
|
727
737
|
|
|
@@ -938,7 +948,7 @@ async function plotView(
|
|
|
938
948
|
);
|
|
939
949
|
const { attributes } = newComponent;
|
|
940
950
|
const [node] = element.childNodes;
|
|
941
|
-
return node.update(attributes);
|
|
951
|
+
return node.update(attributes, false);
|
|
942
952
|
}),
|
|
943
953
|
)
|
|
944
954
|
.transitions();
|
package/src/spec/transform.ts
CHANGED
package/src/transform/pack.ts
CHANGED
|
@@ -1,58 +1,64 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
2
|
import { TransformComponent as TC } from '../runtime';
|
|
3
3
|
import { calcBBox } from '../utils/vector';
|
|
4
|
+
import { PackTransform } from '../spec';
|
|
4
5
|
|
|
5
|
-
export type PackOptions =
|
|
6
|
+
export type PackOptions = Omit<PackTransform, 'type'>;
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
function pack(options: PackOptions) {
|
|
9
|
+
const { padding = 0, direction = 'col' } = options;
|
|
10
|
+
return (P, count, layout) => {
|
|
11
|
+
const pcount = P.length;
|
|
12
|
+
if (pcount === 0) return [];
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// col * row >= count
|
|
15
|
+
// row is close to col * aspect, so
|
|
16
|
+
// col * (col * aspect) >= count
|
|
17
|
+
const { innerWidth, innerHeight } = layout;
|
|
18
|
+
const aspect = innerHeight / innerWidth;
|
|
19
|
+
let col = Math.ceil(Math.sqrt(count / aspect));
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
// Increase col to avoid total height of packed shape
|
|
22
|
+
// being large than height of bbox.
|
|
23
|
+
let size = innerWidth / col;
|
|
24
|
+
let row = Math.ceil(count / col);
|
|
25
|
+
let h0 = row * size;
|
|
26
|
+
while (h0 > innerHeight) {
|
|
27
|
+
col = col + 1;
|
|
28
|
+
size = innerWidth / col;
|
|
29
|
+
row = Math.ceil(count / col);
|
|
30
|
+
h0 = row * size;
|
|
31
|
+
}
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// Some offset to increase the space usage.
|
|
34
|
+
const space = innerHeight - row * size;
|
|
35
|
+
const intervalY = row <= 1 ? 0 : space / (row - 1);
|
|
36
|
+
const [offsetX, offsetY] =
|
|
37
|
+
row <= 1
|
|
38
|
+
? [
|
|
39
|
+
(innerWidth - pcount * size) / (pcount - 1),
|
|
40
|
+
(innerHeight - size) / 2,
|
|
41
|
+
]
|
|
42
|
+
: [0, 0];
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
return P.map((points, m) => {
|
|
45
|
+
const [x, y, width, height] = calcBBox(points);
|
|
46
|
+
const i = direction === 'col' ? m % col : Math.floor(m / row);
|
|
47
|
+
const j = direction === 'col' ? Math.floor(m / col) : m % row;
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
const newX = i * size;
|
|
50
|
+
const newY = (row - j - 1) * size + space;
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const sx = (size - padding) / width;
|
|
53
|
+
const sy = (size - padding) / height;
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
|
55
|
-
});
|
|
55
|
+
// Translate the shape and mark to make sure the center of
|
|
56
|
+
// shape is overlap before and after scale transformation.
|
|
57
|
+
const tx = newX - x + offsetX * i + (1 / 2) * padding;
|
|
58
|
+
const ty = newY - y - intervalY * j - offsetY + (1 / 2) * padding;
|
|
59
|
+
return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
/**
|
|
@@ -60,9 +66,9 @@ function modifier(P, count, layout) {
|
|
|
60
66
|
* @todo Improve or change algorithm to increase space usage.
|
|
61
67
|
* @todo Take some special case into account.
|
|
62
68
|
*/
|
|
63
|
-
export const Pack: TC<PackOptions> = () => {
|
|
69
|
+
export const Pack: TC<PackOptions> = (options) => {
|
|
64
70
|
return (I, mark) => {
|
|
65
|
-
return [I, deepMix({}, mark, { modifier, axis: false })];
|
|
71
|
+
return [I, deepMix({}, mark, { modifier: pack(options), axis: false })];
|
|
66
72
|
};
|
|
67
73
|
};
|
|
68
74
|
|
package/src/utils/angle.ts
CHANGED
|
@@ -5,3 +5,25 @@ export function toRadian(degree: number): number {
|
|
|
5
5
|
export function toDegree(radian: number): number {
|
|
6
6
|
return (radian * 180) / Math.PI;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
// convert the angle to the range of 0 to 4*Math.PI
|
|
10
|
+
export function convertAngles(startAngle: number, endAngle: number) {
|
|
11
|
+
startAngle = startAngle % (2 * Math.PI);
|
|
12
|
+
endAngle = endAngle % (2 * Math.PI);
|
|
13
|
+
|
|
14
|
+
if (startAngle < 0) {
|
|
15
|
+
startAngle = 2 * Math.PI + startAngle;
|
|
16
|
+
}
|
|
17
|
+
if (endAngle < 0) {
|
|
18
|
+
endAngle = 2 * Math.PI + endAngle;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (startAngle >= endAngle) {
|
|
22
|
+
endAngle = endAngle + 2 * Math.PI;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
startAngle,
|
|
27
|
+
endAngle,
|
|
28
|
+
};
|
|
29
|
+
}
|