@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,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformMatrix = exports.getSymbolsPosition = exports.getUnitPatternSize = exports.drawBackground = exports.initCanvas = exports.getPixelRatio = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 获取设备像素比
|
|
6
|
+
*/
|
|
7
|
+
function getPixelRatio() {
|
|
8
|
+
return typeof window === 'object' ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : 2;
|
|
9
|
+
}
|
|
10
|
+
exports.getPixelRatio = getPixelRatio;
|
|
11
|
+
/**
|
|
12
|
+
* 初始化 cavnas,设置宽高等
|
|
13
|
+
*/
|
|
14
|
+
function initCanvas(width, height) {
|
|
15
|
+
if (height === void 0) { height = width; }
|
|
16
|
+
var canvas = document.createElement('canvas');
|
|
17
|
+
var pixelRatio = getPixelRatio();
|
|
18
|
+
// 画布尺寸
|
|
19
|
+
canvas.width = width * pixelRatio;
|
|
20
|
+
canvas.height = height * pixelRatio;
|
|
21
|
+
// 显示尺寸
|
|
22
|
+
canvas.style.width = width + "px";
|
|
23
|
+
canvas.style.height = height + "px";
|
|
24
|
+
var ctx = canvas.getContext('2d');
|
|
25
|
+
ctx.scale(pixelRatio, pixelRatio);
|
|
26
|
+
return canvas;
|
|
27
|
+
}
|
|
28
|
+
exports.initCanvas = initCanvas;
|
|
29
|
+
/**
|
|
30
|
+
* 绘制背景
|
|
31
|
+
*
|
|
32
|
+
* @param context
|
|
33
|
+
* @param cfg
|
|
34
|
+
* @param width
|
|
35
|
+
* @param height
|
|
36
|
+
*/
|
|
37
|
+
function drawBackground(context, cfg, width, height) {
|
|
38
|
+
if (height === void 0) { height = width; }
|
|
39
|
+
var backgroundColor = cfg.backgroundColor, opacity = cfg.opacity;
|
|
40
|
+
context.globalAlpha = opacity;
|
|
41
|
+
context.fillStyle = backgroundColor;
|
|
42
|
+
context.beginPath();
|
|
43
|
+
context.fillRect(0, 0, width, height);
|
|
44
|
+
context.closePath();
|
|
45
|
+
}
|
|
46
|
+
exports.drawBackground = drawBackground;
|
|
47
|
+
/**
|
|
48
|
+
* 计算贴图单元大小
|
|
49
|
+
*
|
|
50
|
+
* @param size 元素大小
|
|
51
|
+
* @param padding 圆点间隔
|
|
52
|
+
* @param isStagger 是否交错
|
|
53
|
+
* @reutrn 返回贴图单元大小
|
|
54
|
+
*/
|
|
55
|
+
function getUnitPatternSize(size, padding, isStagger) {
|
|
56
|
+
// 如果交错, unitSize 放大两倍
|
|
57
|
+
var unitSize = size + padding;
|
|
58
|
+
return isStagger ? unitSize * 2 : unitSize;
|
|
59
|
+
}
|
|
60
|
+
exports.getUnitPatternSize = getUnitPatternSize;
|
|
61
|
+
/**
|
|
62
|
+
* 计算有交错情况的元素坐标
|
|
63
|
+
*
|
|
64
|
+
* @param unitSize 贴图单元大小
|
|
65
|
+
* @param isStagger 是否交错
|
|
66
|
+
* @reutrn 元素中心坐标 x,y 数组集合
|
|
67
|
+
*/
|
|
68
|
+
function getSymbolsPosition(unitSize, isStagger) {
|
|
69
|
+
// 如果交错, 交错绘制 dot
|
|
70
|
+
var symbolsPos = isStagger
|
|
71
|
+
? [
|
|
72
|
+
[unitSize * (1 / 4), unitSize * (1 / 4)],
|
|
73
|
+
[unitSize * (3 / 4), unitSize * (3 / 4)],
|
|
74
|
+
]
|
|
75
|
+
: [[unitSize * (1 / 2), unitSize * (1 / 2)]];
|
|
76
|
+
return symbolsPos;
|
|
77
|
+
}
|
|
78
|
+
exports.getSymbolsPosition = getSymbolsPosition;
|
|
79
|
+
/**
|
|
80
|
+
* 给整个 pattern贴图 做变换, 目前支持旋转
|
|
81
|
+
*
|
|
82
|
+
* @param pattern 整个贴图
|
|
83
|
+
* @param dpr 设备像素比
|
|
84
|
+
* @param rotation 旋转角度
|
|
85
|
+
*/
|
|
86
|
+
function transformMatrix(dpr, rotation) {
|
|
87
|
+
var radian = (rotation * Math.PI) / 180;
|
|
88
|
+
var matrix = {
|
|
89
|
+
a: Math.cos(radian) * (1 / dpr),
|
|
90
|
+
b: Math.sin(radian) * (1 / dpr),
|
|
91
|
+
c: -Math.sin(radian) * (1 / dpr),
|
|
92
|
+
d: Math.cos(radian) * (1 / dpr),
|
|
93
|
+
e: 0,
|
|
94
|
+
f: 0,
|
|
95
|
+
};
|
|
96
|
+
return matrix;
|
|
97
|
+
}
|
|
98
|
+
exports.transformMatrix = transformMatrix;
|
|
99
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/utils/pattern/util.ts"],"names":[],"mappings":"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","sourcesContent":["import { PatternCfg } from '../../types/pattern';\n\n/**\n * 获取设备像素比\n */\nexport function getPixelRatio(): number {\n return typeof window === 'object' ? window?.devicePixelRatio : 2;\n}\n\n/**\n * 初始化 cavnas,设置宽高等\n */\nexport function initCanvas(width: number, height: number = width): HTMLCanvasElement {\n const canvas = document.createElement('canvas');\n\n const pixelRatio = getPixelRatio();\n // 画布尺寸\n canvas.width = width * pixelRatio;\n canvas.height = height * pixelRatio;\n // 显示尺寸\n canvas.style.width = `${width}px`;\n canvas.style.height = `${height}px`;\n\n const ctx = canvas.getContext('2d');\n ctx.scale(pixelRatio, pixelRatio);\n\n return canvas;\n}\n\n/**\n * 绘制背景\n *\n * @param context\n * @param cfg\n * @param width\n * @param height\n */\nexport function drawBackground(\n context: CanvasRenderingContext2D,\n cfg: PatternCfg,\n width: number,\n height: number = width\n) {\n const { backgroundColor, opacity } = cfg;\n\n context.globalAlpha = opacity;\n context.fillStyle = backgroundColor;\n\n context.beginPath();\n context.fillRect(0, 0, width, height);\n context.closePath();\n}\n\n/**\n * 计算贴图单元大小\n *\n * @param size 元素大小\n * @param padding 圆点间隔\n * @param isStagger 是否交错\n * @reutrn 返回贴图单元大小\n */\nexport function getUnitPatternSize(size: number, padding: number, isStagger: boolean): number {\n // 如果交错, unitSize 放大两倍\n const unitSize = size + padding;\n return isStagger ? unitSize * 2 : unitSize;\n}\n\n/**\n * 计算有交错情况的元素坐标\n *\n * @param unitSize 贴图单元大小\n * @param isStagger 是否交错\n * @reutrn 元素中心坐标 x,y 数组集合\n */\nexport function getSymbolsPosition(unitSize: number, isStagger: boolean): number[][] {\n // 如果交错, 交错绘制 dot\n const symbolsPos = isStagger\n ? [\n [unitSize * (1 / 4), unitSize * (1 / 4)],\n [unitSize * (3 / 4), unitSize * (3 / 4)],\n ]\n : [[unitSize * (1 / 2), unitSize * (1 / 2)]];\n return symbolsPos;\n}\n\n/**\n * 给整个 pattern贴图 做变换, 目前支持旋转\n *\n * @param pattern 整个贴图\n * @param dpr 设备像素比\n * @param rotation 旋转角度\n */\nexport function transformMatrix(dpr: number, rotation: number) {\n const radian = (rotation * Math.PI) / 180;\n const matrix = {\n a: Math.cos(radian) * (1 / dpr),\n b: Math.sin(radian) * (1 / dpr),\n c: -Math.sin(radian) * (1 / dpr),\n d: Math.cos(radian) * (1 / dpr),\n e: 0,\n f: 0,\n };\n return matrix;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2plot",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"description": "An
|
|
3
|
+
"version": "2.3.35",
|
|
4
|
+
"description": "An nteractive and responsive charting library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
7
7
|
"plot",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"site:develop": "cross-env PORT=8080 gatsby develop --open -H 0.0.0.0",
|
|
29
29
|
"site:build": "npm run site:clean && gatsby build --prefix-paths",
|
|
30
30
|
"site:clean": "gatsby clean",
|
|
31
|
-
"site:deploy": "npm run build && npm run site:build && gh-pages -d public",
|
|
31
|
+
"site:deploy": "npm run build && npm run site:build --max-old-space-size=4096--no-warnings && gh-pages -d public",
|
|
32
32
|
"fix": "eslint --ext .ts ./src ./__tests__ --fix && prettier --write ./src ./__tests__ && lint-md --fix ./examples ./docs",
|
|
33
33
|
"build": "run-s clean lib dist size",
|
|
34
34
|
"size": "limit-size",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lint": "eslint --ext .ts ./src ./__tests__ && prettier --check ./src ./__tests__ && lint-md ./examples ./docs",
|
|
41
41
|
"lint-staged": "lint-staged",
|
|
42
42
|
"test": "jest",
|
|
43
|
-
"test-live": "cross-env DEBUG_MODE=1 jest --watch ./__tests__",
|
|
43
|
+
"test-live": "cross-env DEBUG_MODE=1 jest --watch ./__tests__/",
|
|
44
44
|
"coverage": "jest -w 16 --coverage",
|
|
45
45
|
"ci": "run-s lint coverage build",
|
|
46
46
|
"changelog": "generate-changelog",
|
|
@@ -56,9 +56,10 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@antv/event-emitter": "^0.1.2",
|
|
59
|
-
"@antv/g2": "^4.1.
|
|
59
|
+
"@antv/g2": "^4.1.26",
|
|
60
60
|
"d3-hierarchy": "^2.0.0",
|
|
61
61
|
"d3-regression": "^1.3.5",
|
|
62
|
+
"fmin": "^0.0.2",
|
|
62
63
|
"pdfast": "^0.2.0",
|
|
63
64
|
"size-sensor": "^1.0.1",
|
|
64
65
|
"tslib": "^2.0.3"
|
|
@@ -126,7 +127,8 @@
|
|
|
126
127
|
"!**/node_modules/**",
|
|
127
128
|
"!**/vendor/**",
|
|
128
129
|
"!**/_template/**",
|
|
129
|
-
"!**/interactions/**"
|
|
130
|
+
"!**/interactions/**",
|
|
131
|
+
"!**/venn/layout/**"
|
|
130
132
|
],
|
|
131
133
|
"testRegex": "/__tests__/.*-spec\\.ts?$"
|
|
132
134
|
},
|
|
@@ -142,11 +144,11 @@
|
|
|
142
144
|
"limit-size": [
|
|
143
145
|
{
|
|
144
146
|
"path": "dist/g2plot.min.js",
|
|
145
|
-
"limit": "
|
|
147
|
+
"limit": "985 Kb"
|
|
146
148
|
},
|
|
147
149
|
{
|
|
148
150
|
"path": "dist/g2plot.min.js",
|
|
149
|
-
"limit": "
|
|
151
|
+
"limit": "275 Kb",
|
|
150
152
|
"gzip": true
|
|
151
153
|
}
|
|
152
154
|
],
|
package/src/adaptor/common.ts
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Util } from '@antv/g2';
|
|
2
|
+
import { get } from '@antv/util';
|
|
3
|
+
import { getCanvasPattern } from '../utils/pattern';
|
|
4
|
+
import { Params } from '../core/adaptor';
|
|
5
|
+
import { Datum, Options, StyleAttr } from '../types';
|
|
6
|
+
import { deepAssign } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 使用 Pattern 通道的 options,要求有 colorField/seriesField/stackField 作为分类字段(进行颜色映射)
|
|
10
|
+
*/
|
|
11
|
+
type OptionsRequiredInPattern = Omit<Options, 'data'>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pattern 通道,处理图案填充
|
|
15
|
+
* 🚀 目前支持图表类型:饼图、柱状图、条形图、玉珏图等(不支持在多 view 图表中,后续按需扩展)
|
|
16
|
+
*
|
|
17
|
+
* @param key key of style property
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export function pattern(key: string) {
|
|
21
|
+
return <O extends OptionsRequiredInPattern = OptionsRequiredInPattern>(params: Params<O>): Params<O> => {
|
|
22
|
+
const { options, chart } = params;
|
|
23
|
+
const { pattern: patternOption } = options;
|
|
24
|
+
|
|
25
|
+
// 没有 pattern 配置,则直接返回
|
|
26
|
+
if (!patternOption) {
|
|
27
|
+
return params;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** ~~~~~~~ 进行贴图图案处理 ~~~~~~~ */
|
|
31
|
+
|
|
32
|
+
const style: StyleAttr = (datum?: Datum, ...args: any[]) => {
|
|
33
|
+
const { defaultColor } = chart.getTheme();
|
|
34
|
+
let color = defaultColor;
|
|
35
|
+
|
|
36
|
+
const colorAttribute = chart.geometries?.[0]?.getAttribute('color');
|
|
37
|
+
if (colorAttribute) {
|
|
38
|
+
const colorField = colorAttribute.getFields()[0];
|
|
39
|
+
const seriesValue = get(datum, colorField);
|
|
40
|
+
color = Util.getMappingValue(colorAttribute, seriesValue, colorAttribute.values?.[0] || defaultColor);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let pattern: CanvasPattern = patternOption as CanvasPattern;
|
|
44
|
+
|
|
45
|
+
// 1. 如果 patternOption 是一个回调,则获取回调结果。`(datum: Datum, color: string) => CanvasPattern`
|
|
46
|
+
if (typeof patternOption === 'function') {
|
|
47
|
+
pattern = patternOption.call(this, datum, color);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2. 如果 pattern 不是 CanvasPattern,则进一步处理,否则直接赋予给 fill
|
|
51
|
+
if (pattern instanceof CanvasPattern === false) {
|
|
52
|
+
// 通过 createPattern(PatternStyle) 转换为 CanvasPattern
|
|
53
|
+
pattern = getCanvasPattern(deepAssign({}, { cfg: { backgroundColor: color } }, pattern));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const styleOption = options[key] as StyleAttr;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...(typeof styleOption === 'function' ? styleOption.call(this, datum, ...args) : styleOption || {}),
|
|
60
|
+
fill: pattern || color,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return deepAssign({}, params, { options: { [key]: style } });
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/core/plot.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Chart, Event, Element } from '@antv/g2';
|
|
|
2
2
|
import { each } from '@antv/util';
|
|
3
3
|
import EE from '@antv/event-emitter';
|
|
4
4
|
import { bind } from 'size-sensor';
|
|
5
|
-
import { Options, StateName, StateCondition, Size, StateObject } from '../types';
|
|
5
|
+
import { Options, StateName, StateCondition, Size, StateObject, Annotation } from '../types';
|
|
6
6
|
import { getContainerSize, getAllElementsRecursively, deepAssign, pick } from '../utils';
|
|
7
7
|
import { Adaptor } from './adaptor';
|
|
8
8
|
|
|
@@ -236,6 +236,48 @@ export abstract class Plot<O extends PickOptions> extends EE {
|
|
|
236
236
|
this.chart.changeSize(width, height);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* 增加图表标注。通过 id 标识,如果匹配到,就做更新
|
|
241
|
+
*/
|
|
242
|
+
public addAnnotations(annotations: Annotation[]): void {
|
|
243
|
+
const incoming = [...annotations];
|
|
244
|
+
const controller = this.chart.getController('annotation');
|
|
245
|
+
const current = controller.getComponents().map((co) => co.extra);
|
|
246
|
+
|
|
247
|
+
controller.clear(true);
|
|
248
|
+
for (let i = 0; i < current.length; i++) {
|
|
249
|
+
let annotation = current[i];
|
|
250
|
+
|
|
251
|
+
const findIndex = incoming.findIndex((item) => item.id && item.id === annotation.id);
|
|
252
|
+
if (findIndex !== -1) {
|
|
253
|
+
annotation = deepAssign({}, annotation, incoming[findIndex]);
|
|
254
|
+
incoming.splice(findIndex, 1);
|
|
255
|
+
}
|
|
256
|
+
controller.annotation(annotation);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
incoming.forEach((annotation) => controller.annotation(annotation));
|
|
260
|
+
this.chart.render(true);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 删除图表标注。通过 id 标识,如果匹配到,就做删除
|
|
265
|
+
*/
|
|
266
|
+
public removeAnnotations(annotations: Array<{ id: string } & Partial<Annotation>>): void {
|
|
267
|
+
const controller = this.chart.getController('annotation');
|
|
268
|
+
const current = controller.getComponents().map((co) => co.extra);
|
|
269
|
+
|
|
270
|
+
controller.clear(true);
|
|
271
|
+
for (let i = 0; i < current.length; i++) {
|
|
272
|
+
const annotation = current[i];
|
|
273
|
+
|
|
274
|
+
if (!annotations.find((item) => item.id && item.id === annotation.id)) {
|
|
275
|
+
controller.annotation(annotation);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.chart.render(true);
|
|
280
|
+
}
|
|
239
281
|
/**
|
|
240
282
|
* 销毁
|
|
241
283
|
*/
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const version = '2.3.
|
|
1
|
+
export const version = '2.3.35';
|
|
2
2
|
|
|
3
3
|
// G2 自定义能力透出
|
|
4
4
|
import * as G2 from '@antv/g2';
|
|
@@ -102,6 +102,10 @@ export type { BoxOptions } from './plots/box';
|
|
|
102
102
|
export { Violin } from './plots/violin';
|
|
103
103
|
export type { ViolinOptions } from './plots/violin';
|
|
104
104
|
|
|
105
|
+
// 韦恩图及类型定义 | author by [visiky](https://github.com/visiky)
|
|
106
|
+
export { Venn } from './plots/venn';
|
|
107
|
+
export type { VennOptions } from './plots/venn';
|
|
108
|
+
|
|
105
109
|
// K线图及类型定义 | author by [jhwong](https://github.com/jinhuiWong), [visiky](https://github.com/visiky)
|
|
106
110
|
export { Stock } from './plots/stock';
|
|
107
111
|
export type { StockOptions } from './plots/stock';
|
|
@@ -158,6 +162,9 @@ export type { CirclePackingOptions } from './plots/circle-packing';
|
|
|
158
162
|
/** 所有开放图表都使用 G2Plot.P 作为入口开发,理论上官方的所有图表都可以走 G2Plot.P 的入口(暂时不处理) */
|
|
159
163
|
export { P } from './plugin';
|
|
160
164
|
|
|
165
|
+
/** 开放 getCanvasPatterng 方法 */
|
|
166
|
+
export { getCanvasPattern } from './utils/pattern';
|
|
167
|
+
|
|
161
168
|
// 已经废弃,更名为 Mix
|
|
162
169
|
export { Mix as MultiView } from './plots/mix';
|
|
163
170
|
export type { MixOptions as MultiViewOptions } from './plots/mix';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
2
|
import { each } from '@antv/util';
|
|
3
|
-
import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot } from '../../adaptor/common';
|
|
3
|
+
import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot, pattern } from '../../adaptor/common';
|
|
4
4
|
import { findGeometry } from '../../utils';
|
|
5
5
|
import { Params } from '../../core/adaptor';
|
|
6
6
|
import { area, point, line } from '../../adaptor/geometries';
|
|
@@ -134,10 +134,11 @@ function adjust(params: Params<AreaOptions>): Params<AreaOptions> {
|
|
|
134
134
|
export function adaptor(params: Params<AreaOptions>) {
|
|
135
135
|
// flow 的方式处理所有的配置到 G2 API
|
|
136
136
|
return flow(
|
|
137
|
+
theme,
|
|
138
|
+
pattern('areaStyle'),
|
|
137
139
|
geometry,
|
|
138
140
|
meta,
|
|
139
141
|
adjust,
|
|
140
|
-
theme,
|
|
141
142
|
axis,
|
|
142
143
|
legend,
|
|
143
144
|
tooltip,
|
|
@@ -2,10 +2,18 @@ import { get } from '@antv/util';
|
|
|
2
2
|
import { Types } from '@antv/g2';
|
|
3
3
|
import { point } from '../../adaptor/geometries/point';
|
|
4
4
|
import { Params } from '../../core/adaptor';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
interaction as baseInteraction,
|
|
7
|
+
animation,
|
|
8
|
+
theme,
|
|
9
|
+
legend,
|
|
10
|
+
annotation,
|
|
11
|
+
scale,
|
|
12
|
+
pattern,
|
|
13
|
+
} from '../../adaptor/common';
|
|
6
14
|
import { flow, deepAssign } from '../../utils';
|
|
7
|
-
import { getAdjustAppendPadding } from '../../utils/padding';
|
|
8
|
-
import { transformData, resolvePaddingForCircle
|
|
15
|
+
import { getAdjustAppendPadding, resolveAllPadding } from '../../utils/padding';
|
|
16
|
+
import { transformData, resolvePaddingForCircle } from './utils';
|
|
9
17
|
import { CirclePackingOptions } from './types';
|
|
10
18
|
import { RAW_FIELDS } from './constant';
|
|
11
19
|
|
|
@@ -206,6 +214,7 @@ function interaction(params: Params<CirclePackingOptions>): Params<CirclePacking
|
|
|
206
214
|
*/
|
|
207
215
|
export function adaptor(params: Params<CirclePackingOptions>) {
|
|
208
216
|
return flow(
|
|
217
|
+
pattern('pointStyle'),
|
|
209
218
|
defaultOptions,
|
|
210
219
|
padding,
|
|
211
220
|
theme,
|
|
@@ -2,7 +2,7 @@ import { Types } from '@antv/g2';
|
|
|
2
2
|
import { pack } from '../../utils/hierarchy/pack';
|
|
3
3
|
import { deepAssign, pick } from '../../utils';
|
|
4
4
|
import { HIERARCHY_DATA_TRANSFORM_PARAMS } from '../../interactions/actions/drill-down';
|
|
5
|
-
import {
|
|
5
|
+
import { resolveAllPadding } from '../../utils/padding';
|
|
6
6
|
import { CirclePackingOptions } from './types';
|
|
7
7
|
|
|
8
8
|
interface TransformDataOptions {
|
|
@@ -55,26 +55,6 @@ export function transformData(options: TransformDataOptions) {
|
|
|
55
55
|
return result;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* 根据图表的 padding 和 appendPadding 计算出图表的最终 padding
|
|
60
|
-
* @param array
|
|
61
|
-
*/
|
|
62
|
-
export function resolveAllPadding(paddings: Types.ViewPadding[]) {
|
|
63
|
-
// 先把数组里的 padding 全部转换成 normal
|
|
64
|
-
const normalPaddings = paddings.map((item) => normalPadding(item));
|
|
65
|
-
let finalPadding = [0, 0, 0, 0];
|
|
66
|
-
if (normalPaddings.length > 0) {
|
|
67
|
-
finalPadding = finalPadding.map((item, index) => {
|
|
68
|
-
// 有几个 padding 数组就遍历几次,累加
|
|
69
|
-
normalPaddings.forEach((d, i) => {
|
|
70
|
-
item += normalPaddings[i][index];
|
|
71
|
-
});
|
|
72
|
-
return item;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return finalPadding;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
58
|
/**
|
|
79
59
|
* 根据传入的 padding 和 现有的 画布大小, 输出针对圆形视图布局需要的 finalPadding 以及 finalSize
|
|
80
60
|
* @param params
|
|
@@ -15,10 +15,11 @@ import {
|
|
|
15
15
|
import { conversionTag } from '../../adaptor/conversion-tag';
|
|
16
16
|
import { connectedArea } from '../../adaptor/connected-area';
|
|
17
17
|
import { interval } from '../../adaptor/geometries';
|
|
18
|
+
import { pattern } from '../../adaptor/pattern';
|
|
19
|
+
import { brushInteraction } from '../../adaptor/brush';
|
|
18
20
|
import { flow, transformLabel, deepAssign, findGeometry, adjustYMetaByZero, pick } from '../../utils';
|
|
19
21
|
import { getDataWhetherPecentage, getDeepPercent } from '../../utils/transform/percent';
|
|
20
22
|
import { Datum } from '../../types';
|
|
21
|
-
import { brushInteraction } from '../../adaptor/brush';
|
|
22
23
|
import { ColumnOptions } from './types';
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -287,6 +288,7 @@ export function adaptor(params: Params<ColumnOptions>, isBar = false) {
|
|
|
287
288
|
return flow(
|
|
288
289
|
defaultOptions, // 处理默认配置
|
|
289
290
|
theme, // theme 需要在 geometry 之前
|
|
291
|
+
pattern('columnStyle'),
|
|
290
292
|
state,
|
|
291
293
|
geometry,
|
|
292
294
|
meta,
|
|
@@ -367,6 +367,8 @@ export function legend(params: Params<DualAxesOptions>): Params<DualAxesOptions>
|
|
|
367
367
|
} else if (isObject(legend) && legend.custom === true) {
|
|
368
368
|
chart.legend(legend);
|
|
369
369
|
} else {
|
|
370
|
+
const leftLegend = get(geometryOptions, [0, 'legend'], legend);
|
|
371
|
+
const rightLegend = get(geometryOptions, [1, 'legend'], legend);
|
|
370
372
|
// 均使用自定义图例
|
|
371
373
|
chart.once('beforepaint', () => {
|
|
372
374
|
const leftItems = data[0].length
|
|
@@ -374,7 +376,7 @@ export function legend(params: Params<DualAxesOptions>): Params<DualAxesOptions>
|
|
|
374
376
|
view: leftView,
|
|
375
377
|
geometryOption: geometryOptions[0],
|
|
376
378
|
yField: yField[0],
|
|
377
|
-
legend,
|
|
379
|
+
legend: leftLegend,
|
|
378
380
|
})
|
|
379
381
|
: [];
|
|
380
382
|
|
|
@@ -383,7 +385,7 @@ export function legend(params: Params<DualAxesOptions>): Params<DualAxesOptions>
|
|
|
383
385
|
view: rightView,
|
|
384
386
|
geometryOption: geometryOptions[1],
|
|
385
387
|
yField: yField[1],
|
|
386
|
-
legend,
|
|
388
|
+
legend: rightLegend,
|
|
387
389
|
})
|
|
388
390
|
: [];
|
|
389
391
|
|
|
@@ -398,10 +400,10 @@ export function legend(params: Params<DualAxesOptions>): Params<DualAxesOptions>
|
|
|
398
400
|
});
|
|
399
401
|
|
|
400
402
|
if (geometryOptions[0].seriesField) {
|
|
401
|
-
leftView.legend(geometryOptions[0].seriesField,
|
|
403
|
+
leftView.legend(geometryOptions[0].seriesField, leftLegend);
|
|
402
404
|
}
|
|
403
405
|
if (geometryOptions[1].seriesField) {
|
|
404
|
-
rightView.legend(geometryOptions[1].seriesField,
|
|
406
|
+
rightView.legend(geometryOptions[1].seriesField, rightLegend);
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
// 自定义图例交互
|
|
@@ -23,6 +23,8 @@ type CommonGeometryOption = {
|
|
|
23
23
|
readonly geometry?: string;
|
|
24
24
|
// label
|
|
25
25
|
readonly label?: Options['label'];
|
|
26
|
+
// legend
|
|
27
|
+
readonly legend?: Options['legend'];
|
|
26
28
|
// 色板
|
|
27
29
|
readonly color?: Options['color'];
|
|
28
30
|
// 是否分组
|
|
@@ -41,7 +43,15 @@ export type GeometryLineOption = Pick<
|
|
|
41
43
|
// 柱设置接口
|
|
42
44
|
export type GeometryColumnOption = Pick<
|
|
43
45
|
ColumnOptions,
|
|
44
|
-
|
|
46
|
+
| 'seriesField'
|
|
47
|
+
| 'isGroup'
|
|
48
|
+
| 'isStack'
|
|
49
|
+
| 'isRange'
|
|
50
|
+
| 'isPercent'
|
|
51
|
+
| 'columnWidthRatio'
|
|
52
|
+
| 'marginRatio'
|
|
53
|
+
| 'columnStyle'
|
|
54
|
+
| 'pattern'
|
|
45
55
|
> &
|
|
46
56
|
CommonGeometryOption;
|
|
47
57
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { each } from '@antv/util';
|
|
2
2
|
import { Geometry } from '@antv/g2';
|
|
3
3
|
import { Params } from '../../../core/adaptor';
|
|
4
|
-
import { point, line
|
|
4
|
+
import { point, line } from '../../../adaptor/geometries';
|
|
5
5
|
import { pick, deepAssign } from '../../../utils';
|
|
6
|
+
import { adaptor as columnAdaptor } from '../../column/adaptor';
|
|
6
7
|
import { GeometryOption } from '../types';
|
|
7
8
|
import { isLine, isColumn } from './option';
|
|
8
9
|
|
|
@@ -68,7 +69,7 @@ export function drawSingleGeometry<O extends { xField: string; yField: string; g
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
if (isColumn(geometryOption)) {
|
|
71
|
-
|
|
72
|
+
columnAdaptor(
|
|
72
73
|
deepAssign({}, params, {
|
|
73
74
|
options: {
|
|
74
75
|
...pick(options, FIELD_KEY),
|
|
@@ -23,7 +23,10 @@ export function getViewLegendItems(params: {
|
|
|
23
23
|
const legendItemName = get(view, `options.scales.${yField}.alias`) || yField;
|
|
24
24
|
// 返回 g2 设置的图例
|
|
25
25
|
const colorAttribute = geometry.getAttribute('color');
|
|
26
|
-
|
|
26
|
+
let color = view.getTheme().defaultColor;
|
|
27
|
+
if (colorAttribute) {
|
|
28
|
+
color = Util.getMappingValue(colorAttribute, legendItemName, get(colorAttribute, ['values', 0], color));
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
const marker =
|
|
29
32
|
(isFunction(userMarker)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Types } from '@antv/g2';
|
|
2
2
|
import { isArray } from '@antv/util';
|
|
3
|
-
import { flow, findGeometry
|
|
3
|
+
import { flow, findGeometry } from '../../../utils';
|
|
4
4
|
import { getTooltipMapping } from '../../../utils/tooltip';
|
|
5
5
|
import { Params } from '../../../core/adaptor';
|
|
6
6
|
import { Datum, Data } from '../../../types/common';
|
|
@@ -51,15 +51,7 @@ function geometry(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
|
51
51
|
color,
|
|
52
52
|
style: funnelStyle,
|
|
53
53
|
},
|
|
54
|
-
|
|
55
|
-
label: deepAssign(
|
|
56
|
-
{
|
|
57
|
-
layout: {
|
|
58
|
-
type: 'interval-adjust-position',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
label
|
|
62
|
-
),
|
|
54
|
+
label,
|
|
63
55
|
state,
|
|
64
56
|
},
|
|
65
57
|
});
|
|
@@ -2,7 +2,17 @@ import { get } from '@antv/util';
|
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { deepAssign, findGeometry } from '../../utils';
|
|
4
4
|
import { flow, transformLabel } from '../../utils';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
tooltip,
|
|
7
|
+
interaction,
|
|
8
|
+
animation,
|
|
9
|
+
theme,
|
|
10
|
+
scale,
|
|
11
|
+
annotation,
|
|
12
|
+
state,
|
|
13
|
+
legend,
|
|
14
|
+
pattern,
|
|
15
|
+
} from '../../adaptor/common';
|
|
6
16
|
import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
|
|
7
17
|
import { getTooltipMapping } from '../../utils/tooltip';
|
|
8
18
|
import { HeatmapOptions } from './types';
|
|
@@ -162,6 +172,7 @@ export function adaptor(params: Params<HeatmapOptions>) {
|
|
|
162
172
|
// flow 的方式处理所有的配置到 G2 API
|
|
163
173
|
return flow(
|
|
164
174
|
theme,
|
|
175
|
+
pattern('heatmapStyle'),
|
|
165
176
|
meta,
|
|
166
177
|
coordinate,
|
|
167
178
|
geometry,
|
|
@@ -16,10 +16,14 @@ export interface HeatmapOptions extends Options {
|
|
|
16
16
|
readonly shape?: string;
|
|
17
17
|
/** 热力格子中图形的尺寸比例,可选,只有当 shape 和 sizeField 至少指定一项后才生效 */
|
|
18
18
|
readonly sizeRatio?: number;
|
|
19
|
-
/** 热力图形样式 */
|
|
20
|
-
readonly heatmapStyle?: StyleAttr;
|
|
21
19
|
/** 坐标轴映射 */
|
|
22
20
|
readonly reflect?: 'x' | 'y';
|
|
23
21
|
/** 极坐标属性 */
|
|
24
22
|
readonly coordinate?: Types.CoordinateOption;
|
|
23
|
+
|
|
24
|
+
// 样式相关
|
|
25
|
+
/** 热力图形样式 */
|
|
26
|
+
readonly heatmapStyle?: StyleAttr;
|
|
27
|
+
/** 贴图图案, 在 type="density" 时不支持 */
|
|
28
|
+
readonly pattern?: Options['pattern'];
|
|
25
29
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Params } from '../../core/adaptor';
|
|
2
2
|
import { tooltip, interaction, animation, theme, scale, state } from '../../adaptor/common';
|
|
3
|
+
import { pattern } from '../../adaptor/pattern';
|
|
3
4
|
import { findGeometry, deepAssign } from '../../utils';
|
|
4
5
|
import { flow, transformLabel } from '../../utils';
|
|
5
6
|
import { interval } from '../../adaptor/geometries';
|
|
@@ -114,5 +115,16 @@ function label(params: Params<HistogramOptions>): Params<HistogramOptions> {
|
|
|
114
115
|
*/
|
|
115
116
|
export function adaptor(params: Params<HistogramOptions>) {
|
|
116
117
|
// flow 的方式处理所有的配置到 G2 API
|
|
117
|
-
return flow(
|
|
118
|
+
return flow(
|
|
119
|
+
theme,
|
|
120
|
+
pattern('columnStyle'),
|
|
121
|
+
geometry,
|
|
122
|
+
meta,
|
|
123
|
+
axis,
|
|
124
|
+
state,
|
|
125
|
+
label,
|
|
126
|
+
tooltip,
|
|
127
|
+
interaction,
|
|
128
|
+
animation
|
|
129
|
+
)(params);
|
|
118
130
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
2
|
import { get, isNil } from '@antv/util';
|
|
3
|
-
import { interaction, animation, theme, scale } from '../../adaptor/common';
|
|
3
|
+
import { interaction, animation, theme, scale, pattern } from '../../adaptor/common';
|
|
4
4
|
import { Params } from '../../core/adaptor';
|
|
5
5
|
import { flow, deepAssign, renderStatistic } from '../../utils';
|
|
6
6
|
import { interval } from '../../adaptor/geometries';
|
|
@@ -97,5 +97,5 @@ export function statistic(params: Params<LiquidOptions>, updated?: boolean): Par
|
|
|
97
97
|
*/
|
|
98
98
|
export function adaptor(params: Params<LiquidOptions>) {
|
|
99
99
|
// flow 的方式处理所有的配置到 G2 API (主题前置,会影响绘制的取色)
|
|
100
|
-
return flow(theme, geometry, statistic, scale({}), animation, interaction)(params);
|
|
100
|
+
return flow(theme, pattern('liquidStyle'), geometry, statistic, scale({}), animation, interaction)(params);
|
|
101
101
|
}
|