@antv/g2plot 2.3.31 → 2.3.35
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/CHANGELOG.md +1270 -0
- package/{README.zh-CN.md → README.en-US.md} +33 -42
- package/README.md +43 -32
- package/dist/g2plot.min.js +3 -18
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/common.d.ts +1 -0
- package/esm/adaptor/common.js +1 -0
- package/esm/adaptor/common.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +10 -0
- package/esm/adaptor/pattern.js +54 -0
- package/esm/adaptor/pattern.js.map +1 -0
- package/esm/core/plot.d.ts +11 -1
- package/esm/core/plot.js +42 -1
- package/esm/core/plot.js.map +1 -1
- package/esm/index.d.ts +5 -1
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +2 -2
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/adaptor.js +4 -4
- package/esm/plots/circle-packing/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/utils.d.ts +0 -5
- package/esm/plots/circle-packing/utils.js +1 -20
- package/esm/plots/circle-packing/utils.js.map +1 -1
- package/esm/plots/column/adaptor.js +3 -2
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/adaptor.js +6 -4
- package/esm/plots/dual-axes/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/types.d.ts +2 -1
- package/esm/plots/dual-axes/types.js.map +1 -1
- package/esm/plots/dual-axes/util/geometry.js +3 -2
- package/esm/plots/dual-axes/util/geometry.js.map +1 -1
- package/esm/plots/dual-axes/util/legend.js +4 -1
- package/esm/plots/dual-axes/util/legend.js.map +1 -1
- package/esm/plots/funnel/geometries/basic.js +2 -7
- package/esm/plots/funnel/geometries/basic.js.map +1 -1
- package/esm/plots/heatmap/adaptor.js +2 -2
- package/esm/plots/heatmap/adaptor.js.map +1 -1
- package/esm/plots/heatmap/types.d.ts +4 -2
- package/esm/plots/heatmap/types.js.map +1 -1
- package/esm/plots/histogram/adaptor.js +2 -1
- package/esm/plots/histogram/adaptor.js.map +1 -1
- package/esm/plots/liquid/adaptor.js +2 -2
- package/esm/plots/liquid/adaptor.js.map +1 -1
- package/esm/plots/pie/adaptor.js +2 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/plots/radial-bar/adaptor.js +2 -1
- package/esm/plots/radial-bar/adaptor.js.map +1 -1
- package/esm/plots/rose/adaptor.js +2 -2
- package/esm/plots/rose/adaptor.js.map +1 -1
- package/esm/plots/sunburst/adaptor.js +2 -2
- package/esm/plots/sunburst/adaptor.js.map +1 -1
- package/esm/plots/tiny-area/adaptor.js +2 -2
- package/esm/plots/tiny-area/adaptor.js.map +1 -1
- package/esm/plots/tiny-column/adaptor.js +2 -2
- package/esm/plots/tiny-column/adaptor.js.map +1 -1
- package/esm/plots/treemap/adaptor.js +2 -1
- package/esm/plots/treemap/adaptor.js.map +1 -1
- package/esm/plots/venn/adaptor.d.ts +23 -0
- package/esm/plots/venn/adaptor.js +177 -0
- package/esm/plots/venn/adaptor.js.map +1 -0
- package/esm/plots/venn/constant.d.ts +7 -0
- package/esm/plots/venn/constant.js +33 -0
- package/esm/plots/venn/constant.js.map +1 -0
- package/esm/plots/venn/index.d.ts +24 -0
- package/esm/plots/venn/index.js +47 -0
- package/esm/plots/venn/index.js.map +1 -0
- package/esm/plots/venn/interaction/action.d.ts +18 -0
- package/esm/plots/venn/interaction/action.js +77 -0
- package/esm/plots/venn/interaction/action.js.map +1 -0
- package/esm/plots/venn/interaction/index.d.ts +1 -0
- package/esm/plots/venn/interaction/index.js +15 -0
- package/esm/plots/venn/interaction/index.js.map +1 -0
- package/esm/plots/venn/label.d.ts +1 -0
- package/esm/plots/venn/label.js +31 -0
- package/esm/plots/venn/label.js.map +1 -0
- package/esm/plots/venn/layout/circleintersection.d.ts +29 -0
- package/esm/plots/venn/layout/circleintersection.js +186 -0
- package/esm/plots/venn/layout/circleintersection.js.map +1 -0
- package/esm/plots/venn/layout/diagram.d.ts +17 -0
- package/esm/plots/venn/layout/diagram.js +193 -0
- package/esm/plots/venn/layout/diagram.js.map +1 -0
- package/esm/plots/venn/layout/layout.d.ts +27 -0
- package/esm/plots/venn/layout/layout.js +593 -0
- package/esm/plots/venn/layout/layout.js.map +1 -0
- package/esm/plots/venn/shape.d.ts +1 -0
- package/esm/plots/venn/shape.js +42 -0
- package/esm/plots/venn/shape.js.map +1 -0
- package/esm/plots/venn/types.d.ts +27 -0
- package/esm/plots/venn/types.js +2 -0
- package/esm/plots/venn/types.js.map +1 -0
- package/esm/plots/venn/utils.d.ts +28 -0
- package/esm/plots/venn/utils.js +93 -0
- package/esm/plots/venn/utils.js.map +1 -0
- package/esm/types/annotation.d.ts +5 -1
- package/esm/types/annotation.js.map +1 -1
- package/esm/types/attr.d.ts +4 -1
- package/esm/types/attr.js.map +1 -1
- package/esm/types/common.d.ts +3 -1
- package/esm/types/common.js.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/pattern.d.ts +47 -0
- package/esm/types/pattern.js +1 -0
- package/esm/types/pattern.js.map +1 -0
- package/esm/utils/color/blend.d.ts +20 -0
- package/esm/utils/color/blend.js +92 -0
- package/esm/utils/color/blend.js.map +1 -0
- package/esm/utils/padding.d.ts +5 -0
- package/esm/utils/padding.js +19 -0
- package/esm/utils/padding.js.map +1 -1
- package/esm/utils/pattern/dot.d.ts +32 -0
- package/esm/utils/pattern/dot.js +69 -0
- package/esm/utils/pattern/dot.js.map +1 -0
- package/esm/utils/pattern/index.d.ts +17 -0
- package/esm/utils/pattern/index.js +27 -0
- package/esm/utils/pattern/index.js.map +1 -0
- package/esm/utils/pattern/line.d.ts +25 -0
- package/esm/utils/pattern/line.js +56 -0
- package/esm/utils/pattern/line.js.map +1 -0
- package/esm/utils/pattern/square.d.ts +28 -0
- package/esm/utils/pattern/square.js +61 -0
- package/esm/utils/pattern/square.js.map +1 -0
- package/esm/utils/pattern/util.d.ts +50 -0
- package/esm/utils/pattern/util.js +90 -0
- package/esm/utils/pattern/util.js.map +1 -0
- package/lib/adaptor/common.d.ts +1 -0
- package/lib/adaptor/common.js +2 -0
- package/lib/adaptor/common.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +10 -0
- package/lib/adaptor/pattern.js +58 -0
- package/lib/adaptor/pattern.js.map +1 -0
- package/lib/core/plot.d.ts +11 -1
- package/lib/core/plot.js +41 -0
- package/lib/core/plot.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +1 -1
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/adaptor.js +2 -2
- package/lib/plots/circle-packing/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/utils.d.ts +0 -5
- package/lib/plots/circle-packing/utils.js +2 -22
- package/lib/plots/circle-packing/utils.js.map +1 -1
- package/lib/plots/column/adaptor.js +3 -2
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/adaptor.js +6 -4
- package/lib/plots/dual-axes/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/types.d.ts +2 -1
- package/lib/plots/dual-axes/types.js.map +1 -1
- package/lib/plots/dual-axes/util/geometry.js +2 -1
- package/lib/plots/dual-axes/util/geometry.js.map +1 -1
- package/lib/plots/dual-axes/util/legend.js +4 -1
- package/lib/plots/dual-axes/util/legend.js.map +1 -1
- package/lib/plots/funnel/geometries/basic.js +1 -6
- package/lib/plots/funnel/geometries/basic.js.map +1 -1
- package/lib/plots/heatmap/adaptor.js +1 -1
- package/lib/plots/heatmap/adaptor.js.map +1 -1
- package/lib/plots/heatmap/types.d.ts +4 -2
- package/lib/plots/heatmap/types.js.map +1 -1
- package/lib/plots/histogram/adaptor.js +2 -1
- package/lib/plots/histogram/adaptor.js.map +1 -1
- package/lib/plots/liquid/adaptor.js +1 -1
- package/lib/plots/liquid/adaptor.js.map +1 -1
- package/lib/plots/pie/adaptor.js +2 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/plots/radial-bar/adaptor.js +2 -1
- package/lib/plots/radial-bar/adaptor.js.map +1 -1
- package/lib/plots/rose/adaptor.js +1 -1
- package/lib/plots/rose/adaptor.js.map +1 -1
- package/lib/plots/sunburst/adaptor.js +1 -1
- package/lib/plots/sunburst/adaptor.js.map +1 -1
- package/lib/plots/tiny-area/adaptor.js +1 -1
- package/lib/plots/tiny-area/adaptor.js.map +1 -1
- package/lib/plots/tiny-column/adaptor.js +1 -1
- package/lib/plots/tiny-column/adaptor.js.map +1 -1
- package/lib/plots/treemap/adaptor.js +2 -1
- package/lib/plots/treemap/adaptor.js.map +1 -1
- package/lib/plots/venn/adaptor.d.ts +23 -0
- package/lib/plots/venn/adaptor.js +183 -0
- package/lib/plots/venn/adaptor.js.map +1 -0
- package/lib/plots/venn/constant.d.ts +7 -0
- package/lib/plots/venn/constant.js +36 -0
- package/lib/plots/venn/constant.js.map +1 -0
- package/lib/plots/venn/index.d.ts +24 -0
- package/lib/plots/venn/index.js +50 -0
- package/lib/plots/venn/index.js.map +1 -0
- package/lib/plots/venn/interaction/action.d.ts +18 -0
- package/lib/plots/venn/interaction/action.js +80 -0
- package/lib/plots/venn/interaction/action.js.map +1 -0
- package/lib/plots/venn/interaction/index.d.ts +1 -0
- package/lib/plots/venn/interaction/index.js +17 -0
- package/lib/plots/venn/interaction/index.js.map +1 -0
- package/lib/plots/venn/label.d.ts +1 -0
- package/lib/plots/venn/label.js +33 -0
- package/lib/plots/venn/label.js.map +1 -0
- package/lib/plots/venn/layout/circleintersection.d.ts +29 -0
- package/lib/plots/venn/layout/circleintersection.js +196 -0
- package/lib/plots/venn/layout/circleintersection.js.map +1 -0
- package/lib/plots/venn/layout/diagram.d.ts +17 -0
- package/lib/plots/venn/layout/diagram.js +201 -0
- package/lib/plots/venn/layout/diagram.js.map +1 -0
- package/lib/plots/venn/layout/layout.d.ts +27 -0
- package/lib/plots/venn/layout/layout.js +606 -0
- package/lib/plots/venn/layout/layout.js.map +1 -0
- package/lib/plots/venn/shape.d.ts +1 -0
- package/lib/plots/venn/shape.js +44 -0
- package/lib/plots/venn/shape.js.map +1 -0
- package/lib/plots/venn/types.d.ts +27 -0
- package/lib/plots/venn/types.js +4 -0
- package/lib/plots/venn/types.js.map +1 -0
- package/lib/plots/venn/utils.d.ts +28 -0
- package/lib/plots/venn/utils.js +98 -0
- package/lib/plots/venn/utils.js.map +1 -0
- package/lib/types/annotation.d.ts +5 -1
- package/lib/types/annotation.js.map +1 -1
- package/lib/types/attr.d.ts +4 -1
- package/lib/types/attr.js.map +1 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/types/common.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/pattern.d.ts +47 -0
- package/lib/types/pattern.js +3 -0
- package/lib/types/pattern.js.map +1 -0
- package/lib/utils/color/blend.d.ts +20 -0
- package/lib/utils/color/blend.js +98 -0
- package/lib/utils/color/blend.js.map +1 -0
- package/lib/utils/padding.d.ts +5 -0
- package/lib/utils/padding.js +21 -1
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/pattern/dot.d.ts +32 -0
- package/lib/utils/pattern/dot.js +74 -0
- package/lib/utils/pattern/dot.js.map +1 -0
- package/lib/utils/pattern/index.d.ts +17 -0
- package/lib/utils/pattern/index.js +31 -0
- package/lib/utils/pattern/index.js.map +1 -0
- package/lib/utils/pattern/line.d.ts +25 -0
- package/lib/utils/pattern/line.js +61 -0
- package/lib/utils/pattern/line.js.map +1 -0
- package/lib/utils/pattern/square.d.ts +28 -0
- package/lib/utils/pattern/square.js +66 -0
- package/lib/utils/pattern/square.js.map +1 -0
- package/lib/utils/pattern/util.d.ts +50 -0
- package/lib/utils/pattern/util.js +99 -0
- package/lib/utils/pattern/util.js.map +1 -0
- package/package.json +10 -8
- package/src/adaptor/common.ts +2 -0
- package/src/adaptor/pattern.ts +66 -0
- package/src/core/plot.ts +43 -1
- package/src/index.ts +8 -1
- package/src/plots/area/adaptor.ts +3 -2
- package/src/plots/circle-packing/adaptor.ts +12 -3
- package/src/plots/circle-packing/utils.ts +1 -21
- package/src/plots/column/adaptor.ts +3 -1
- package/src/plots/dual-axes/adaptor.ts +6 -4
- package/src/plots/dual-axes/types.ts +11 -1
- package/src/plots/dual-axes/util/geometry.ts +3 -2
- package/src/plots/dual-axes/util/legend.ts +4 -1
- package/src/plots/funnel/geometries/basic.ts +2 -10
- package/src/plots/heatmap/adaptor.ts +12 -1
- package/src/plots/heatmap/types.ts +6 -2
- package/src/plots/histogram/adaptor.ts +13 -1
- package/src/plots/liquid/adaptor.ts +2 -2
- package/src/plots/pie/adaptor.ts +2 -0
- package/src/plots/radial-bar/adaptor.ts +2 -0
- package/src/plots/rose/adaptor.ts +2 -1
- package/src/plots/sunburst/adaptor.ts +2 -1
- package/src/plots/tiny-area/adaptor.ts +2 -2
- package/src/plots/tiny-column/adaptor.ts +2 -2
- package/src/plots/treemap/adaptor.ts +13 -1
- package/src/plots/venn/adaptor.ts +227 -0
- package/src/plots/venn/constant.ts +35 -0
- package/src/plots/venn/index.ts +47 -0
- package/src/plots/venn/interaction/action.ts +67 -0
- package/src/plots/venn/interaction/index.ts +17 -0
- package/src/plots/venn/label.ts +26 -0
- package/src/plots/venn/layout/circleintersection.ts +223 -0
- package/src/plots/venn/layout/diagram.ts +219 -0
- package/src/plots/venn/layout/layout.ts +734 -0
- package/src/plots/venn/shape.ts +53 -0
- package/src/plots/venn/types.ts +25 -0
- package/src/plots/venn/utils.ts +100 -0
- package/src/types/annotation.ts +3 -1
- package/src/types/attr.ts +7 -1
- package/src/types/common.ts +3 -1
- package/src/types/index.ts +1 -0
- package/src/types/pattern.ts +50 -0
- package/src/utils/color/blend.ts +103 -0
- package/src/utils/padding.ts +20 -0
- package/src/utils/pattern/dot.ts +86 -0
- package/src/utils/pattern/index.ts +45 -0
- package/src/utils/pattern/line.ts +70 -0
- package/src/utils/pattern/square.ts +78 -0
- package/src/utils/pattern/util.ts +104 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SquarePatternCfg } from '../../types/pattern';
|
|
2
|
+
import { deepAssign } from '../../utils';
|
|
3
|
+
import {
|
|
4
|
+
getUnitPatternSize,
|
|
5
|
+
initCanvas,
|
|
6
|
+
drawBackground,
|
|
7
|
+
getSymbolsPosition,
|
|
8
|
+
transformMatrix,
|
|
9
|
+
getPixelRatio,
|
|
10
|
+
} from './util';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* squarePattern 的 默认配置
|
|
14
|
+
*/
|
|
15
|
+
export const defaultSquarePatternCfg = {
|
|
16
|
+
size: 6,
|
|
17
|
+
padding: 1,
|
|
18
|
+
isStagger: true,
|
|
19
|
+
backgroundColor: 'transparent',
|
|
20
|
+
opacity: 1,
|
|
21
|
+
rotation: 0,
|
|
22
|
+
fill: '#fff',
|
|
23
|
+
fillOpacity: 0.5,
|
|
24
|
+
stroke: 'transparent',
|
|
25
|
+
lineWidth: 0,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 绘制square
|
|
30
|
+
*
|
|
31
|
+
* @param context canvasContext
|
|
32
|
+
* @param cfg squarePattern 的配置
|
|
33
|
+
* @param x和y square的中心位置
|
|
34
|
+
*/
|
|
35
|
+
export function drawSquare(context: CanvasRenderingContext2D, cfg: SquarePatternCfg, x: number, y: number) {
|
|
36
|
+
const { stroke, size, fill, lineWidth, fillOpacity } = cfg;
|
|
37
|
+
|
|
38
|
+
context.globalAlpha = fillOpacity;
|
|
39
|
+
context.strokeStyle = stroke;
|
|
40
|
+
context.lineWidth = lineWidth;
|
|
41
|
+
context.fillStyle = fill;
|
|
42
|
+
// 因为正方形绘制从左上角开始,所以x,y做个偏移
|
|
43
|
+
context.strokeRect(x - size / 2, y - size / 2, size, size);
|
|
44
|
+
context.fillRect(x - size / 2, y - size / 2, size, size);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 创建 squarePattern
|
|
49
|
+
*/
|
|
50
|
+
export function createSquarePattern(cfg?: SquarePatternCfg): CanvasPattern {
|
|
51
|
+
const squareCfg = deepAssign({}, defaultSquarePatternCfg, cfg);
|
|
52
|
+
|
|
53
|
+
const { size, padding, isStagger, rotation } = squareCfg;
|
|
54
|
+
|
|
55
|
+
// 计算 画布大小,squares的位置
|
|
56
|
+
const unitSize = getUnitPatternSize(size, padding, isStagger);
|
|
57
|
+
const squares = getSymbolsPosition(unitSize, isStagger); // 计算方法与 dots 一样
|
|
58
|
+
|
|
59
|
+
// 初始化 patternCanvas
|
|
60
|
+
const canvas = initCanvas(unitSize, unitSize);
|
|
61
|
+
const ctx = canvas.getContext('2d');
|
|
62
|
+
|
|
63
|
+
// 绘制 background,squares
|
|
64
|
+
drawBackground(ctx, squareCfg, unitSize);
|
|
65
|
+
for (const [x, y] of squares) {
|
|
66
|
+
drawSquare(ctx, squareCfg, x, y);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const pattern = ctx.createPattern(canvas, 'repeat');
|
|
70
|
+
|
|
71
|
+
if (pattern) {
|
|
72
|
+
const dpr = getPixelRatio();
|
|
73
|
+
const matrix = transformMatrix(dpr, rotation);
|
|
74
|
+
pattern.setTransform(matrix);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return pattern;
|
|
78
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { PatternCfg } from '../../types/pattern';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 获取设备像素比
|
|
5
|
+
*/
|
|
6
|
+
export function getPixelRatio(): number {
|
|
7
|
+
return typeof window === 'object' ? window?.devicePixelRatio : 2;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 初始化 cavnas,设置宽高等
|
|
12
|
+
*/
|
|
13
|
+
export function initCanvas(width: number, height: number = width): HTMLCanvasElement {
|
|
14
|
+
const canvas = document.createElement('canvas');
|
|
15
|
+
|
|
16
|
+
const pixelRatio = getPixelRatio();
|
|
17
|
+
// 画布尺寸
|
|
18
|
+
canvas.width = width * pixelRatio;
|
|
19
|
+
canvas.height = height * pixelRatio;
|
|
20
|
+
// 显示尺寸
|
|
21
|
+
canvas.style.width = `${width}px`;
|
|
22
|
+
canvas.style.height = `${height}px`;
|
|
23
|
+
|
|
24
|
+
const ctx = canvas.getContext('2d');
|
|
25
|
+
ctx.scale(pixelRatio, pixelRatio);
|
|
26
|
+
|
|
27
|
+
return canvas;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 绘制背景
|
|
32
|
+
*
|
|
33
|
+
* @param context
|
|
34
|
+
* @param cfg
|
|
35
|
+
* @param width
|
|
36
|
+
* @param height
|
|
37
|
+
*/
|
|
38
|
+
export function drawBackground(
|
|
39
|
+
context: CanvasRenderingContext2D,
|
|
40
|
+
cfg: PatternCfg,
|
|
41
|
+
width: number,
|
|
42
|
+
height: number = width
|
|
43
|
+
) {
|
|
44
|
+
const { backgroundColor, opacity } = cfg;
|
|
45
|
+
|
|
46
|
+
context.globalAlpha = opacity;
|
|
47
|
+
context.fillStyle = backgroundColor;
|
|
48
|
+
|
|
49
|
+
context.beginPath();
|
|
50
|
+
context.fillRect(0, 0, width, height);
|
|
51
|
+
context.closePath();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 计算贴图单元大小
|
|
56
|
+
*
|
|
57
|
+
* @param size 元素大小
|
|
58
|
+
* @param padding 圆点间隔
|
|
59
|
+
* @param isStagger 是否交错
|
|
60
|
+
* @reutrn 返回贴图单元大小
|
|
61
|
+
*/
|
|
62
|
+
export function getUnitPatternSize(size: number, padding: number, isStagger: boolean): number {
|
|
63
|
+
// 如果交错, unitSize 放大两倍
|
|
64
|
+
const unitSize = size + padding;
|
|
65
|
+
return isStagger ? unitSize * 2 : unitSize;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 计算有交错情况的元素坐标
|
|
70
|
+
*
|
|
71
|
+
* @param unitSize 贴图单元大小
|
|
72
|
+
* @param isStagger 是否交错
|
|
73
|
+
* @reutrn 元素中心坐标 x,y 数组集合
|
|
74
|
+
*/
|
|
75
|
+
export function getSymbolsPosition(unitSize: number, isStagger: boolean): number[][] {
|
|
76
|
+
// 如果交错, 交错绘制 dot
|
|
77
|
+
const symbolsPos = isStagger
|
|
78
|
+
? [
|
|
79
|
+
[unitSize * (1 / 4), unitSize * (1 / 4)],
|
|
80
|
+
[unitSize * (3 / 4), unitSize * (3 / 4)],
|
|
81
|
+
]
|
|
82
|
+
: [[unitSize * (1 / 2), unitSize * (1 / 2)]];
|
|
83
|
+
return symbolsPos;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 给整个 pattern贴图 做变换, 目前支持旋转
|
|
88
|
+
*
|
|
89
|
+
* @param pattern 整个贴图
|
|
90
|
+
* @param dpr 设备像素比
|
|
91
|
+
* @param rotation 旋转角度
|
|
92
|
+
*/
|
|
93
|
+
export function transformMatrix(dpr: number, rotation: number) {
|
|
94
|
+
const radian = (rotation * Math.PI) / 180;
|
|
95
|
+
const matrix = {
|
|
96
|
+
a: Math.cos(radian) * (1 / dpr),
|
|
97
|
+
b: Math.sin(radian) * (1 / dpr),
|
|
98
|
+
c: -Math.sin(radian) * (1 / dpr),
|
|
99
|
+
d: Math.cos(radian) * (1 / dpr),
|
|
100
|
+
e: 0,
|
|
101
|
+
f: 0,
|
|
102
|
+
};
|
|
103
|
+
return matrix;
|
|
104
|
+
}
|