@antv/g2plot 2.4.19 → 2.4.22
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 +1626 -0
- package/README.en-US.md +2 -2
- package/README.md +2 -2
- package/dist/g2plot.min.js +2 -2
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/brush.js +2 -3
- package/esm/adaptor/brush.js.map +1 -1
- package/esm/adaptor/common.js +2 -11
- package/esm/adaptor/common.js.map +1 -1
- package/esm/adaptor/geometries/base.d.ts +2 -2
- package/esm/adaptor/geometries/base.js +3 -1
- package/esm/adaptor/geometries/base.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interactions/brush.d.ts +18 -6
- package/esm/interactions/brush.js +35 -25
- package/esm/interactions/brush.js.map +1 -1
- package/esm/plots/box/adaptor.js +2 -2
- package/esm/plots/box/adaptor.js.map +1 -1
- package/esm/plots/chord/adaptor.js +2 -13
- package/esm/plots/chord/adaptor.js.map +1 -1
- package/esm/plots/chord/constant.d.ts +4 -4
- package/esm/plots/chord/constant.js +4 -4
- package/esm/plots/chord/constant.js.map +1 -1
- package/esm/plots/column/adaptor.js +3 -1
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/facet/types.d.ts +1 -2
- package/esm/plots/facet/types.js.map +1 -1
- package/esm/plots/facet/utils.js +2 -11
- package/esm/plots/facet/utils.js.map +1 -1
- package/esm/plots/funnel/adaptor.d.ts +5 -0
- package/esm/plots/funnel/adaptor.js +31 -2
- package/esm/plots/funnel/adaptor.js.map +1 -1
- package/esm/plots/funnel/geometries/basic.d.ts +5 -0
- package/esm/plots/funnel/geometries/basic.js +8 -4
- package/esm/plots/funnel/geometries/basic.js.map +1 -1
- package/esm/plots/funnel/geometries/common.d.ts +1 -0
- package/esm/plots/funnel/geometries/common.js +5 -2
- package/esm/plots/funnel/geometries/common.js.map +1 -1
- package/esm/plots/funnel/geometries/compare.d.ts +1 -0
- package/esm/plots/funnel/geometries/compare.js +37 -30
- package/esm/plots/funnel/geometries/compare.js.map +1 -1
- package/esm/plots/funnel/index.d.ts +1 -0
- package/esm/plots/funnel/index.js +1 -0
- package/esm/plots/funnel/index.js.map +1 -1
- package/esm/plots/funnel/interactions/funnel-conversion-tag.d.ts +9 -0
- package/esm/plots/funnel/interactions/funnel-conversion-tag.js +57 -0
- package/esm/plots/funnel/interactions/funnel-conversion-tag.js.map +1 -0
- package/esm/plots/funnel/interactions/index.d.ts +5 -0
- package/esm/plots/funnel/interactions/index.js +10 -0
- package/esm/plots/funnel/interactions/index.js.map +1 -0
- package/esm/plots/funnel/types.d.ts +1 -0
- package/esm/plots/funnel/types.js.map +1 -1
- package/esm/plots/gauge/utils.js +6 -5
- package/esm/plots/gauge/utils.js.map +1 -1
- package/esm/plots/heatmap/adaptor.js +9 -11
- package/esm/plots/heatmap/adaptor.js.map +1 -1
- package/esm/plots/histogram/adaptor.js +3 -0
- package/esm/plots/histogram/adaptor.js.map +1 -1
- package/esm/plots/pie/adaptor.js +3 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/plots/pie/types.d.ts +6 -1
- package/esm/plots/pie/types.js.map +1 -1
- package/esm/plots/progress/adaptor.js +1 -2
- package/esm/plots/progress/adaptor.js.map +1 -1
- package/esm/plots/progress/utils.d.ts +1 -0
- package/esm/plots/progress/utils.js +4 -1
- package/esm/plots/progress/utils.js.map +1 -1
- package/esm/plots/sankey/adaptor.js +2 -11
- package/esm/plots/sankey/adaptor.js.map +1 -1
- package/esm/plots/stock/utils.d.ts +3 -1
- package/esm/plots/stock/utils.js +4 -2
- package/esm/plots/stock/utils.js.map +1 -1
- package/esm/plots/violin/adaptor.js +2 -10
- package/esm/plots/violin/adaptor.js.map +1 -1
- package/esm/types/common.d.ts +4 -3
- package/esm/types/common.js.map +1 -1
- package/esm/types/interaction.d.ts +5 -0
- package/esm/types/interaction.js.map +1 -1
- package/esm/utils/conversion.js +4 -3
- package/esm/utils/conversion.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/view.d.ts +8 -1
- package/esm/utils/view.js +27 -0
- package/esm/utils/view.js.map +1 -1
- package/lib/adaptor/brush.js +2 -3
- package/lib/adaptor/brush.js.map +1 -1
- package/lib/adaptor/common.js +1 -10
- package/lib/adaptor/common.js.map +1 -1
- package/lib/adaptor/geometries/base.d.ts +2 -2
- package/lib/adaptor/geometries/base.js +3 -1
- package/lib/adaptor/geometries/base.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interactions/brush.d.ts +18 -6
- package/lib/interactions/brush.js +35 -25
- package/lib/interactions/brush.js.map +1 -1
- package/lib/plots/box/adaptor.js +1 -1
- package/lib/plots/box/adaptor.js.map +1 -1
- package/lib/plots/chord/adaptor.js +1 -12
- package/lib/plots/chord/adaptor.js.map +1 -1
- package/lib/plots/chord/constant.d.ts +4 -4
- package/lib/plots/chord/constant.js +4 -4
- package/lib/plots/chord/constant.js.map +1 -1
- package/lib/plots/column/adaptor.js +3 -1
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/facet/types.d.ts +1 -2
- package/lib/plots/facet/types.js.map +1 -1
- package/lib/plots/facet/utils.js +1 -10
- package/lib/plots/facet/utils.js.map +1 -1
- package/lib/plots/funnel/adaptor.d.ts +5 -0
- package/lib/plots/funnel/adaptor.js +32 -2
- package/lib/plots/funnel/adaptor.js.map +1 -1
- package/lib/plots/funnel/geometries/basic.d.ts +5 -0
- package/lib/plots/funnel/geometries/basic.js +8 -3
- package/lib/plots/funnel/geometries/basic.js.map +1 -1
- package/lib/plots/funnel/geometries/common.d.ts +1 -0
- package/lib/plots/funnel/geometries/common.js +6 -3
- package/lib/plots/funnel/geometries/common.js.map +1 -1
- package/lib/plots/funnel/geometries/compare.d.ts +1 -0
- package/lib/plots/funnel/geometries/compare.js +38 -30
- package/lib/plots/funnel/geometries/compare.js.map +1 -1
- package/lib/plots/funnel/index.d.ts +1 -0
- package/lib/plots/funnel/index.js +1 -0
- package/lib/plots/funnel/index.js.map +1 -1
- package/lib/plots/funnel/interactions/funnel-conversion-tag.d.ts +9 -0
- package/lib/plots/funnel/interactions/funnel-conversion-tag.js +60 -0
- package/lib/plots/funnel/interactions/funnel-conversion-tag.js.map +1 -0
- package/lib/plots/funnel/interactions/index.d.ts +5 -0
- package/lib/plots/funnel/interactions/index.js +13 -0
- package/lib/plots/funnel/interactions/index.js.map +1 -0
- package/lib/plots/funnel/types.d.ts +1 -0
- package/lib/plots/funnel/types.js.map +1 -1
- package/lib/plots/gauge/utils.js +5 -4
- package/lib/plots/gauge/utils.js.map +1 -1
- package/lib/plots/heatmap/adaptor.js +8 -10
- package/lib/plots/heatmap/adaptor.js.map +1 -1
- package/lib/plots/histogram/adaptor.js +3 -0
- package/lib/plots/histogram/adaptor.js.map +1 -1
- package/lib/plots/pie/adaptor.js +3 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/plots/pie/types.d.ts +6 -1
- package/lib/plots/pie/types.js.map +1 -1
- package/lib/plots/progress/adaptor.js +1 -2
- package/lib/plots/progress/adaptor.js.map +1 -1
- package/lib/plots/progress/utils.d.ts +1 -0
- package/lib/plots/progress/utils.js +4 -1
- package/lib/plots/progress/utils.js.map +1 -1
- package/lib/plots/sankey/adaptor.js +2 -11
- package/lib/plots/sankey/adaptor.js.map +1 -1
- package/lib/plots/stock/utils.d.ts +3 -1
- package/lib/plots/stock/utils.js +4 -2
- package/lib/plots/stock/utils.js.map +1 -1
- package/lib/plots/violin/adaptor.js +2 -10
- package/lib/plots/violin/adaptor.js.map +1 -1
- package/lib/types/common.d.ts +4 -3
- package/lib/types/common.js.map +1 -1
- package/lib/types/interaction.d.ts +5 -0
- package/lib/types/interaction.js.map +1 -1
- package/lib/utils/conversion.js +4 -3
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/view.d.ts +8 -1
- package/lib/utils/view.js +29 -1
- package/lib/utils/view.js.map +1 -1
- package/package.json +4 -2
- package/src/adaptor/brush.ts +2 -2
- package/src/adaptor/common.ts +2 -11
- package/src/adaptor/geometries/base.ts +5 -3
- package/src/index.ts +1 -1
- package/src/interactions/brush.ts +38 -25
- package/src/plots/box/adaptor.ts +2 -2
- package/src/plots/chord/adaptor.ts +2 -14
- package/src/plots/chord/constant.ts +4 -4
- package/src/plots/column/adaptor.ts +3 -1
- package/src/plots/facet/types.ts +1 -1
- package/src/plots/facet/utils.ts +4 -12
- package/src/plots/funnel/adaptor.ts +32 -2
- package/src/plots/funnel/geometries/basic.ts +10 -5
- package/src/plots/funnel/geometries/common.ts +6 -3
- package/src/plots/funnel/geometries/compare.ts +50 -41
- package/src/plots/funnel/index.ts +1 -0
- package/src/plots/funnel/interactions/funnel-conversion-tag.ts +57 -0
- package/src/plots/funnel/interactions/index.ts +11 -0
- package/src/plots/funnel/types.ts +1 -0
- package/src/plots/gauge/utils.ts +5 -4
- package/src/plots/heatmap/adaptor.ts +10 -11
- package/src/plots/histogram/adaptor.ts +2 -0
- package/src/plots/pie/adaptor.ts +3 -1
- package/src/plots/pie/types.ts +6 -1
- package/src/plots/progress/adaptor.ts +1 -2
- package/src/plots/progress/utils.ts +4 -1
- package/src/plots/sankey/adaptor.ts +2 -11
- package/src/plots/stock/utils.ts +4 -3
- package/src/plots/violin/adaptor.ts +2 -11
- package/src/types/common.ts +5 -3
- package/src/types/interaction.ts +6 -0
- package/src/utils/conversion.ts +6 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/view.ts +34 -1
package/lib/utils/index.js
CHANGED
|
@@ -34,6 +34,8 @@ Object.defineProperty(exports, "measureTextWidth", { enumerable: true, get: func
|
|
|
34
34
|
var number_1 = require("./number");
|
|
35
35
|
Object.defineProperty(exports, "isBetween", { enumerable: true, get: function () { return number_1.isBetween; } });
|
|
36
36
|
Object.defineProperty(exports, "isRealNumber", { enumerable: true, get: function () { return number_1.isRealNumber; } });
|
|
37
|
+
var view_2 = require("./view");
|
|
38
|
+
Object.defineProperty(exports, "addViewAnimation", { enumerable: true, get: function () { return view_2.addViewAnimation; } });
|
|
37
39
|
tslib_1.__exportStar(require("./data"), exports);
|
|
38
40
|
tslib_1.__exportStar(require("./padding"), exports);
|
|
39
41
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,yCAAoD;AAA3C,gGAAA,GAAG,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,kGAAA,KAAK,OAAA;AAC9B,6BAAyC;AAAhC,uGAAA,gBAAgB,OAAA;AACzB,qDAA2B;AAC3B,+BAAiE;AAAxD,oGAAA,YAAY,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,uGAAA,eAAe,OAAA;AAChD,iCAAyC;AAAhC,uGAAA,cAAc,OAAA;AACvB,+BAAuC;AAA9B,qGAAA,aAAa,OAAA;AACtB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,yCAAoE;AAA3D,4GAAA,eAAe,OAAA;AAAE,iHAAA,oBAAoB,OAAA;AAC9C,+CAAkD;AAAzC,gHAAA,gBAAgB,OAAA;AACzB,mCAAmD;AAA1C,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAChC,iDAAuB;AACvB,oDAA0B","sourcesContent":["export { flow } from './flow';\nexport { pick } from './pick';\nexport { template } from './template';\nexport { log, invariant, LEVEL } from './invariant';\nexport { getContainerSize } from './dom';\nexport * from './geometry';\nexport { findViewById, getViews, getSiblingViews } from './view';\nexport { transformLabel } from './label';\nexport { getSplinePath } from './path';\nexport { deepAssign } from './deep-assign';\nexport { kebabCase } from './kebab-case';\nexport { renderStatistic, renderGaugeStatistic } from './statistic';\nexport { measureTextWidth } from './measure-text';\nexport { isBetween, isRealNumber } from './number';\nexport * from './data';\nexport * from './padding';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,yCAAoD;AAA3C,gGAAA,GAAG,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,kGAAA,KAAK,OAAA;AAC9B,6BAAyC;AAAhC,uGAAA,gBAAgB,OAAA;AACzB,qDAA2B;AAC3B,+BAAiE;AAAxD,oGAAA,YAAY,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,uGAAA,eAAe,OAAA;AAChD,iCAAyC;AAAhC,uGAAA,cAAc,OAAA;AACvB,+BAAuC;AAA9B,qGAAA,aAAa,OAAA;AACtB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,yCAAoE;AAA3D,4GAAA,eAAe,OAAA;AAAE,iHAAA,oBAAoB,OAAA;AAC9C,+CAAkD;AAAzC,gHAAA,gBAAgB,OAAA;AACzB,mCAAmD;AAA1C,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAChC,+BAA0C;AAAjC,wGAAA,gBAAgB,OAAA;AACzB,iDAAuB;AACvB,oDAA0B","sourcesContent":["export { flow } from './flow';\nexport { pick } from './pick';\nexport { template } from './template';\nexport { log, invariant, LEVEL } from './invariant';\nexport { getContainerSize } from './dom';\nexport * from './geometry';\nexport { findViewById, getViews, getSiblingViews } from './view';\nexport { transformLabel } from './label';\nexport { getSplinePath } from './path';\nexport { deepAssign } from './deep-assign';\nexport { kebabCase } from './kebab-case';\nexport { renderStatistic, renderGaugeStatistic } from './statistic';\nexport { measureTextWidth } from './measure-text';\nexport { isBetween, isRealNumber } from './number';\nexport { addViewAnimation } from './view';\nexport * from './data';\nexport * from './padding';\n"]}
|
package/lib/utils/view.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { View } from '@antv/g2';
|
|
1
|
+
import { Geometry, View, Types } from '@antv/g2';
|
|
2
|
+
import { Options } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* 在 Chart 中查找特定 id 的子 View
|
|
4
5
|
* @param chart
|
|
@@ -19,3 +20,9 @@ export declare function getViews(view: View): View[];
|
|
|
19
20
|
* @ignore
|
|
20
21
|
*/
|
|
21
22
|
export declare function getSiblingViews(view: View): View[];
|
|
23
|
+
/**
|
|
24
|
+
* 所有的 Geometries 都使用同一动画(各个图形如有区别,自行覆盖)并添加处理动画回调
|
|
25
|
+
* @param view View
|
|
26
|
+
* @param animation 动画配置
|
|
27
|
+
*/
|
|
28
|
+
export declare function addViewAnimation(view: View, animation: Options['animation'], geometries?: Geometry<Types.ShapePoint>[]): void;
|
package/lib/utils/view.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSiblingViews = exports.getViews = exports.findViewById = void 0;
|
|
3
|
+
exports.addViewAnimation = exports.getSiblingViews = exports.getViews = exports.findViewById = void 0;
|
|
4
|
+
var util_1 = require("@antv/util");
|
|
4
5
|
/**
|
|
5
6
|
* 在 Chart 中查找特定 id 的子 View
|
|
6
7
|
* @param chart
|
|
@@ -31,4 +32,31 @@ function getSiblingViews(view) {
|
|
|
31
32
|
return getViews(view).filter(function (sub) { return sub !== view; });
|
|
32
33
|
}
|
|
33
34
|
exports.getSiblingViews = getSiblingViews;
|
|
35
|
+
/**
|
|
36
|
+
* 所有的 Geometries 都使用同一动画(各个图形如有区别,自行覆盖)并添加处理动画回调
|
|
37
|
+
* @param view View
|
|
38
|
+
* @param animation 动画配置
|
|
39
|
+
*/
|
|
40
|
+
function addViewAnimation(view, animation, geometries) {
|
|
41
|
+
if (geometries === void 0) { geometries = view.geometries; }
|
|
42
|
+
// 同时设置整个 view 动画选项
|
|
43
|
+
if (typeof animation === 'boolean') {
|
|
44
|
+
view.animate(animation);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
view.animate(true);
|
|
48
|
+
}
|
|
49
|
+
// 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
|
|
50
|
+
util_1.each(geometries, function (g) {
|
|
51
|
+
var animationCfg;
|
|
52
|
+
if (util_1.isFunction(animation)) {
|
|
53
|
+
animationCfg = animation(g.type || g.shapeType, g) || true;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
animationCfg = animation;
|
|
57
|
+
}
|
|
58
|
+
g.animate(animationCfg);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.addViewAnimation = addViewAnimation;
|
|
34
62
|
//# sourceMappingURL=view.js.map
|
package/lib/utils/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/utils/view.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/utils/view.ts"],"names":[],"mappings":";;;AACA,mCAA8C;AAI9C;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAW,EAAE,EAAU;IAClD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAC,IAAU,IAAK,OAAA,IAAI,CAAC,EAAE,KAAK,EAAE,EAAd,CAAc,CAAC,CAAC;AAC1D,CAAC;AAFD,oCAEC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAU;IACjC,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACpC,CAAC;AAHD,4BAGC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,IAAU;IACxC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,IAAI,EAAZ,CAAY,CAAC,CAAC;AACtD,CAAC;AAFD,0CAEC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,IAAU,EACV,SAA+B,EAC/B,UAA0D;IAA1D,2BAAA,EAAA,aAA2C,IAAI,CAAC,UAAU;IAE1D,mBAAmB;IACnB,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE;QAClC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;KACzB;SAAM;QACL,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACpB;IAED,sCAAsC;IACtC,WAAI,CAAC,UAAU,EAAE,UAAC,CAAW;QAC3B,IAAI,YAAY,CAAC;QACjB,IAAI,iBAAU,CAAC,SAAS,CAAC,EAAE;YACzB,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;SAC5D;aAAM;YACL,YAAY,GAAG,SAAS,CAAC;SAC1B;QAED,CAAC,CAAC,OAAO,CAAC,YAAyB,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAvBD,4CAuBC","sourcesContent":["import { Geometry, View, Types } from '@antv/g2';\nimport { each, isFunction } from '@antv/util';\nimport { Options } from '../types';\nimport { Animation } from '../types/animation';\n\n/**\n * 在 Chart 中查找特定 id 的子 View\n * @param chart\n * @param id\n */\nexport function findViewById(chart: View, id: string): View {\n return chart.views.find((view: View) => view.id === id);\n}\n\n/**\n * 获取同 view 同一级的所有 views\n * @param view 当前 view\n * @returns 同一级的 views\n * @ignore\n */\nexport function getViews(view: View): View[] {\n const parent = view.parent;\n return parent ? parent.views : [];\n}\n\n/**\n * 获取同 view 同一级的 views,不包括自身\n * @param view 当前 view\n * @returns 同一级的 views\n * @ignore\n */\nexport function getSiblingViews(view: View): View[] {\n return getViews(view).filter((sub) => sub !== view);\n}\n\n/**\n * 所有的 Geometries 都使用同一动画(各个图形如有区别,自行覆盖)并添加处理动画回调\n * @param view View\n * @param animation 动画配置\n */\nexport function addViewAnimation(\n view: View,\n animation: Options['animation'],\n geometries: Geometry<Types.ShapePoint>[] = view.geometries\n) {\n // 同时设置整个 view 动画选项\n if (typeof animation === 'boolean') {\n view.animate(animation);\n } else {\n view.animate(true);\n }\n\n // 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)\n each(geometries, (g: Geometry) => {\n let animationCfg;\n if (isFunction(animation)) {\n animationCfg = animation(g.type || g.shapeType, g) || true;\n } else {\n animationCfg = animation;\n }\n\n g.animate(animationCfg as Animation);\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2plot",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.22",
|
|
4
4
|
"description": "An interactive and responsive charting library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -160,6 +160,8 @@
|
|
|
160
160
|
"monaco-editor": "0.21.3",
|
|
161
161
|
"@babel/plugin-transform-spread": "7.12.1",
|
|
162
162
|
"@babel/standalone": "7.12.6",
|
|
163
|
-
"d3-array": "2.12.1"
|
|
163
|
+
"d3-array": "2.12.1",
|
|
164
|
+
"remark-mdx": "1.6.22",
|
|
165
|
+
"@types/lodash": "4.14.182"
|
|
164
166
|
}
|
|
165
167
|
}
|
package/src/adaptor/brush.ts
CHANGED
|
@@ -39,8 +39,8 @@ export function brushInteraction<O extends Options = Options>(params: Params<O>)
|
|
|
39
39
|
}
|
|
40
40
|
const obj: Writable<Interaction> = { type, enable };
|
|
41
41
|
|
|
42
|
-
if (brush
|
|
43
|
-
obj.cfg = getInteractionCfg(type, brush.type, brush
|
|
42
|
+
if (brush) {
|
|
43
|
+
obj.cfg = getInteractionCfg(type, brush.type, brush);
|
|
44
44
|
}
|
|
45
45
|
interactions.push(obj);
|
|
46
46
|
});
|
package/src/adaptor/common.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Interaction } from '../types/interaction';
|
|
|
6
6
|
import { Transformations } from '../types/coordinate';
|
|
7
7
|
import { Axis } from '../types/axis';
|
|
8
8
|
import { AXIS_META_CONFIG_KEYS } from '../constant';
|
|
9
|
-
import { pick, deepAssign } from '../utils';
|
|
9
|
+
import { pick, deepAssign, addViewAnimation } from '../utils';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 通用 legend 配置, 适用于带 colorField 或 seriesField 的图表
|
|
@@ -69,17 +69,8 @@ export function animation<O extends Pick<Options, 'animation'>>(params: Params<O
|
|
|
69
69
|
const { chart, options } = params;
|
|
70
70
|
const { animation } = options;
|
|
71
71
|
|
|
72
|
-
// 同时设置整个 view 动画选项
|
|
73
|
-
if (typeof animation === 'boolean') {
|
|
74
|
-
chart.animate(animation);
|
|
75
|
-
} else {
|
|
76
|
-
chart.animate(true);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
72
|
// 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
|
|
80
|
-
|
|
81
|
-
g.animate(animation);
|
|
82
|
-
});
|
|
73
|
+
addViewAnimation(chart, animation);
|
|
83
74
|
|
|
84
75
|
return params;
|
|
85
76
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { uniq, isFunction, isObject, isString, isNumber, isEmpty } from '@antv/util';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
|
-
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum } from '../../types';
|
|
3
|
+
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum, RawFields } from '../../types';
|
|
4
4
|
import { Label } from '../../types/label';
|
|
5
5
|
import { State } from '../../types/state';
|
|
6
6
|
import { transformLabel } from '../../utils';
|
|
@@ -43,7 +43,7 @@ export type Geometry = {
|
|
|
43
43
|
/** tooltip 的映射字段 */
|
|
44
44
|
readonly tooltipFields?: string[] | false;
|
|
45
45
|
/** 其他原始字段, 用于 mapping 回调参数 */
|
|
46
|
-
readonly rawFields?:
|
|
46
|
+
readonly rawFields?: RawFields;
|
|
47
47
|
/** 图形映射规则 */
|
|
48
48
|
readonly mapping?: MappingOptions;
|
|
49
49
|
/** label 映射通道,因为历史原因导致实现略有区别 */
|
|
@@ -73,9 +73,11 @@ export function getMappingField(
|
|
|
73
73
|
mappingFields: string[];
|
|
74
74
|
tileMappingField: string;
|
|
75
75
|
} {
|
|
76
|
-
const { type, xField, yField, colorField, shapeField, sizeField, styleField
|
|
76
|
+
const { type, xField, yField, colorField, shapeField, sizeField, styleField } = o;
|
|
77
|
+
let { rawFields } = o;
|
|
77
78
|
|
|
78
79
|
let fields = [];
|
|
80
|
+
rawFields = (isFunction(rawFields) ? rawFields(type, field) : rawFields) || [];
|
|
79
81
|
|
|
80
82
|
// 因为 color 会影响到数据分组,以及最后的图形映射。所以导致 bar 图中的 widthRatio 设置不生效
|
|
81
83
|
// 所以对于 color 字段,仅仅保留 colorField 好了! + rawFields
|
package/src/index.ts
CHANGED
|
@@ -22,20 +22,21 @@ function isPointInView(context) {
|
|
|
22
22
|
/**
|
|
23
23
|
* 获取 交互 start 阶段的相关配置
|
|
24
24
|
*/
|
|
25
|
-
export function getInteractionCfg(interactionType: string, brushType?: string,
|
|
25
|
+
export function getInteractionCfg(interactionType: string, brushType?: string, options?: BrushCfg) {
|
|
26
|
+
const { mask, isStartEnable } = options || {};
|
|
26
27
|
const maskType = brushType || 'rect';
|
|
27
28
|
|
|
28
29
|
switch (interactionType) {
|
|
29
30
|
case 'brush':
|
|
30
31
|
return {
|
|
31
32
|
showEnable: [
|
|
32
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
33
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
33
34
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
34
35
|
],
|
|
35
36
|
start: [
|
|
36
37
|
{
|
|
37
38
|
trigger: 'mousedown',
|
|
38
|
-
isEnable: isPointInView,
|
|
39
|
+
isEnable: isStartEnable || isPointInView,
|
|
39
40
|
action: ['brush:start', `${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
40
41
|
// 对应第二个action的参数
|
|
41
42
|
arg: [null, { maskStyle: mask?.style }],
|
|
@@ -71,18 +72,26 @@ export function getInteractionCfg(interactionType: string, brushType?: string, m
|
|
|
71
72
|
case 'brush-highlight':
|
|
72
73
|
return {
|
|
73
74
|
showEnable: [
|
|
74
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
75
|
-
{ trigger: '
|
|
75
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
76
|
+
{ trigger: 'plot:mousemove', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
77
|
+
{
|
|
78
|
+
trigger: 'plot:mousemove',
|
|
79
|
+
action: 'cursor:default',
|
|
80
|
+
isEnable: (context) => (isStartEnable ? !isStartEnable(context) : false),
|
|
81
|
+
},
|
|
82
|
+
{ trigger: 'mask:mouseenter', action: 'cursor:move', isEnable: isStartEnable || (() => true) },
|
|
76
83
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
77
84
|
{ trigger: 'mask:mouseleave', action: 'cursor:crosshair' },
|
|
78
85
|
],
|
|
79
86
|
start: [
|
|
80
87
|
{
|
|
81
88
|
trigger: 'plot:mousedown',
|
|
82
|
-
isEnable
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
isEnable:
|
|
90
|
+
isStartEnable ||
|
|
91
|
+
((context) => {
|
|
92
|
+
// 不要点击在 mask 上重新开始
|
|
93
|
+
return !context.isInShape('mask');
|
|
94
|
+
}),
|
|
86
95
|
action: [`${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
87
96
|
// 对应第 1 个action的参数
|
|
88
97
|
arg: [{ maskStyle: mask?.style }],
|
|
@@ -122,13 +131,13 @@ export function getInteractionCfg(interactionType: string, brushType?: string, m
|
|
|
122
131
|
case 'brush-x':
|
|
123
132
|
return {
|
|
124
133
|
showEnable: [
|
|
125
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
134
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
126
135
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
127
136
|
],
|
|
128
137
|
start: [
|
|
129
138
|
{
|
|
130
139
|
trigger: 'mousedown',
|
|
131
|
-
isEnable: isPointInView,
|
|
140
|
+
isEnable: isStartEnable || isPointInView,
|
|
132
141
|
action: ['brush-x:start', `${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
133
142
|
// 对应第二个action的参数
|
|
134
143
|
arg: [null, { maskStyle: mask?.style }],
|
|
@@ -153,18 +162,20 @@ export function getInteractionCfg(interactionType: string, brushType?: string, m
|
|
|
153
162
|
case 'brush-x-highlight':
|
|
154
163
|
return {
|
|
155
164
|
showEnable: [
|
|
156
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
157
|
-
{ trigger: 'mask:mouseenter', action: 'cursor:move' },
|
|
165
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
166
|
+
{ trigger: 'mask:mouseenter', action: 'cursor:move', isEnable: isStartEnable || (() => true) },
|
|
158
167
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
159
168
|
{ trigger: 'mask:mouseleave', action: 'cursor:crosshair' },
|
|
160
169
|
],
|
|
161
170
|
start: [
|
|
162
171
|
{
|
|
163
172
|
trigger: 'plot:mousedown',
|
|
164
|
-
isEnable
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
isEnable:
|
|
174
|
+
isStartEnable ||
|
|
175
|
+
((context) => {
|
|
176
|
+
// 不要点击在 mask 上重新开始
|
|
177
|
+
return !context.isInShape('mask');
|
|
178
|
+
}),
|
|
168
179
|
action: [`${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
169
180
|
// 对应第 1 个action的参数
|
|
170
181
|
arg: [{ maskStyle: mask?.style }],
|
|
@@ -204,13 +215,13 @@ export function getInteractionCfg(interactionType: string, brushType?: string, m
|
|
|
204
215
|
case 'brush-y':
|
|
205
216
|
return {
|
|
206
217
|
showEnable: [
|
|
207
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
218
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
208
219
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
209
220
|
],
|
|
210
221
|
start: [
|
|
211
222
|
{
|
|
212
223
|
trigger: 'mousedown',
|
|
213
|
-
isEnable: isPointInView,
|
|
224
|
+
isEnable: isStartEnable || isPointInView,
|
|
214
225
|
action: ['brush-y:start', `${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
215
226
|
// 对应第二个action的参数
|
|
216
227
|
arg: [null, { maskStyle: mask?.style }],
|
|
@@ -235,18 +246,20 @@ export function getInteractionCfg(interactionType: string, brushType?: string, m
|
|
|
235
246
|
case 'brush-y-highlight':
|
|
236
247
|
return {
|
|
237
248
|
showEnable: [
|
|
238
|
-
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
|
|
239
|
-
{ trigger: 'mask:mouseenter', action: 'cursor:move' },
|
|
249
|
+
{ trigger: 'plot:mouseenter', action: 'cursor:crosshair', isEnable: isStartEnable || (() => true) },
|
|
250
|
+
{ trigger: 'mask:mouseenter', action: 'cursor:move', isEnable: isStartEnable || (() => true) },
|
|
240
251
|
{ trigger: 'plot:mouseleave', action: 'cursor:default' },
|
|
241
252
|
{ trigger: 'mask:mouseleave', action: 'cursor:crosshair' },
|
|
242
253
|
],
|
|
243
254
|
start: [
|
|
244
255
|
{
|
|
245
256
|
trigger: 'plot:mousedown',
|
|
246
|
-
isEnable
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
257
|
+
isEnable:
|
|
258
|
+
isStartEnable ||
|
|
259
|
+
((context) => {
|
|
260
|
+
// 不要点击在 mask 上重新开始
|
|
261
|
+
return !context.isInShape('mask');
|
|
262
|
+
}),
|
|
250
263
|
action: [`${maskType}-mask:start`, `${maskType}-mask:show`],
|
|
251
264
|
// 对应第 1 个action的参数
|
|
252
265
|
arg: [{ maskStyle: mask?.style }],
|
package/src/plots/box/adaptor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isArray } from '@antv/util';
|
|
2
2
|
import { Types } from '@antv/g2';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
|
-
import { interaction, animation, theme, tooltip } from '../../adaptor/common';
|
|
4
|
+
import { interaction, animation, theme, tooltip, annotation } from '../../adaptor/common';
|
|
5
5
|
import { point, schema } from '../../adaptor/geometries';
|
|
6
6
|
import { flow, pick, deepAssign } from '../../utils';
|
|
7
7
|
import { AXIS_META_CONFIG_KEYS } from '../../constant';
|
|
@@ -167,5 +167,5 @@ export function legend(params: Params<BoxOptions>): Params<BoxOptions> {
|
|
|
167
167
|
* @param params
|
|
168
168
|
*/
|
|
169
169
|
export function adaptor(params: Params<BoxOptions>) {
|
|
170
|
-
return flow(field, outliersPoint, meta, axis, legend, tooltip, interaction, animation, theme)(params);
|
|
170
|
+
return flow(field, outliersPoint, meta, axis, legend, tooltip, annotation(), interaction, animation, theme)(params);
|
|
171
171
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { Geometry } from '@antv/g2';
|
|
2
|
-
import { each } from '@antv/util';
|
|
3
1
|
import { interaction, theme, state } from '../../adaptor/common';
|
|
4
2
|
import { Params } from '../../core/adaptor';
|
|
5
3
|
import { flow, pick } from '../../utils';
|
|
6
4
|
import { polygon, edge } from '../../adaptor/geometries';
|
|
7
5
|
import { chordLayout } from '../../utils/transform/chord';
|
|
8
|
-
import { getAllGeometriesRecursively, transformDataToNodeLinkData } from '../../utils';
|
|
6
|
+
import { getAllGeometriesRecursively, transformDataToNodeLinkData, addViewAnimation } from '../../utils';
|
|
9
7
|
import { ChordOptions } from './types';
|
|
10
8
|
import { X_FIELD, Y_FIELD, NODE_COLOR_FIELD, EDGE_COLOR_FIELD } from './constant';
|
|
11
9
|
|
|
@@ -170,17 +168,7 @@ function animation(params: Params<ChordOptions>): Params<ChordOptions> {
|
|
|
170
168
|
const { chart, options } = params;
|
|
171
169
|
const { animation } = options;
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
if (typeof animation === 'boolean') {
|
|
175
|
-
chart.animate(animation);
|
|
176
|
-
} else {
|
|
177
|
-
chart.animate(true);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
|
|
181
|
-
each(getAllGeometriesRecursively(chart), (g: Geometry) => {
|
|
182
|
-
g.animate(animation);
|
|
183
|
-
});
|
|
171
|
+
addViewAnimation(chart, animation, getAllGeometriesRecursively(chart));
|
|
184
172
|
|
|
185
173
|
return params;
|
|
186
174
|
}
|
|
@@ -22,14 +22,14 @@ export const DEFAULT_OPTIONS = {
|
|
|
22
22
|
const centerX = (x[0] + x[1]) / 2;
|
|
23
23
|
const offsetX = centerX > 0.5 ? -4 : 4;
|
|
24
24
|
return {
|
|
25
|
-
labelEmit: true,
|
|
26
|
-
style: {
|
|
27
|
-
fill: '#8c8c8c',
|
|
28
|
-
},
|
|
29
25
|
offsetX,
|
|
30
26
|
content: name,
|
|
31
27
|
};
|
|
32
28
|
},
|
|
29
|
+
labelEmit: true,
|
|
30
|
+
style: {
|
|
31
|
+
fill: '#8c8c8c',
|
|
32
|
+
},
|
|
33
33
|
},
|
|
34
34
|
tooltip: {
|
|
35
35
|
showTitle: false,
|
|
@@ -251,6 +251,7 @@ function columnTooltip(params: Params<ColumnOptions>): Params<ColumnOptions> {
|
|
|
251
251
|
let tooltipOptions = tooltip;
|
|
252
252
|
// fix: https://github.com/antvis/G2Plot/issues/2572
|
|
253
253
|
if (isGroup && isStack) {
|
|
254
|
+
const { customItems } = tooltipOptions;
|
|
254
255
|
const tooltipFormatter =
|
|
255
256
|
tooltipOptions?.formatter ||
|
|
256
257
|
((datum: Datum) => ({ name: `${datum[seriesField]} - ${datum[groupField]}`, value: datum[yField] }));
|
|
@@ -271,7 +272,8 @@ function columnTooltip(params: Params<ColumnOptions>): Params<ColumnOptions> {
|
|
|
271
272
|
});
|
|
272
273
|
});
|
|
273
274
|
});
|
|
274
|
-
|
|
275
|
+
// fix https://github.com/antvis/G2Plot/issues/3367
|
|
276
|
+
return customItems ? customItems(items) : items;
|
|
275
277
|
},
|
|
276
278
|
};
|
|
277
279
|
}
|
package/src/plots/facet/types.ts
CHANGED
package/src/plots/facet/utils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { View } from '@antv/g2';
|
|
2
2
|
import { each } from '@antv/util';
|
|
3
3
|
import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
|
|
4
4
|
import { AXIS_META_CONFIG_KEYS } from '../../constant';
|
|
5
|
-
import { pick, deepAssign } from '../../utils';
|
|
6
|
-
import { Axis, Interaction } from '../../types';
|
|
5
|
+
import { pick, deepAssign, addViewAnimation } from '../../utils';
|
|
6
|
+
import { Axis, Interaction, Options } from '../../types';
|
|
7
7
|
import { IView } from './types';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -74,15 +74,7 @@ export function execViewAdaptor(viewOfG2: View, options: IView): void {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// 7. animation (先做动画)
|
|
77
|
-
|
|
78
|
-
viewOfG2.animate(false);
|
|
79
|
-
} else {
|
|
80
|
-
viewOfG2.animate(true);
|
|
81
|
-
// 所有的 Geometry 都使用同一动画(各个图形如有区别,todo 自行覆盖)
|
|
82
|
-
each(viewOfG2.geometries, (g: Geometry) => {
|
|
83
|
-
g.animate(animation);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
77
|
+
addViewAnimation(viewOfG2, animation as Options['animation']);
|
|
86
78
|
|
|
87
79
|
if (tooltip) {
|
|
88
80
|
// 8. tooltip
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isFunction, clone } from '@antv/util';
|
|
1
|
+
import { isFunction, clone, each } from '@antv/util';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
|
-
import {
|
|
3
|
+
import { animation, theme, scale, annotation, tooltip } from '../../adaptor/common';
|
|
4
4
|
import { getLocale } from '../../core/locale';
|
|
5
5
|
import { Datum } from '../../types';
|
|
6
6
|
import { flow, deepAssign } from '../../utils';
|
|
@@ -11,6 +11,8 @@ import { compareFunnel } from './geometries/compare';
|
|
|
11
11
|
import { facetFunnel } from './geometries/facet';
|
|
12
12
|
import { dynamicHeightFunnel } from './geometries/dynamic-height';
|
|
13
13
|
import { FUNNEL_CONVERSATION, FUNNEL_PERCENT } from './constant';
|
|
14
|
+
import { interactionStart, FUNNEL_LEGEND_FILTER } from './interactions';
|
|
15
|
+
import type { Interaction } from './types';
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
*
|
|
@@ -137,6 +139,34 @@ function legend(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
|
137
139
|
return params;
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Interaction 配置
|
|
144
|
+
* @param params
|
|
145
|
+
*/
|
|
146
|
+
export function interaction<O extends Pick<FunnelOptions, 'interactions'>>(params: Params<O>): Params<O> {
|
|
147
|
+
const { chart, options } = params;
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
const { interactions, dynamicHeight } = options;
|
|
150
|
+
|
|
151
|
+
each(interactions, (i: Interaction) => {
|
|
152
|
+
if (i.enable === false) {
|
|
153
|
+
chart.removeInteraction(i.type);
|
|
154
|
+
} else {
|
|
155
|
+
chart.interaction(i.type, i.cfg || {});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// 动态高度 不进行交互操作
|
|
159
|
+
if (!dynamicHeight) {
|
|
160
|
+
chart.interaction(FUNNEL_LEGEND_FILTER, {
|
|
161
|
+
start: [{ ...interactionStart, arg: options }],
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
chart.removeInteraction(FUNNEL_LEGEND_FILTER);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return params;
|
|
168
|
+
}
|
|
169
|
+
|
|
140
170
|
/**
|
|
141
171
|
* 漏斗图适配器
|
|
142
172
|
* @param chart
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Types } from '@antv/g2';
|
|
2
|
-
import { isArray } from '@antv/util';
|
|
2
|
+
import { isArray, get, map } from '@antv/util';
|
|
3
3
|
import { flow, findGeometry } from '../../../utils';
|
|
4
4
|
import { getTooltipMapping } from '../../../utils/tooltip';
|
|
5
5
|
import { Params } from '../../../core/adaptor';
|
|
@@ -80,10 +80,15 @@ function transpose(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
|
80
80
|
* 转化率组件
|
|
81
81
|
* @param params
|
|
82
82
|
*/
|
|
83
|
-
function conversionTag(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
84
|
-
const { options } = params;
|
|
83
|
+
export function conversionTag(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
84
|
+
const { options, chart } = params;
|
|
85
85
|
const { maxSize } = options;
|
|
86
86
|
|
|
87
|
+
// 获取形状位置,再转化为需要的转化率位置
|
|
88
|
+
const dataArray = get(chart, ['geometries', '0', 'dataArray'], []);
|
|
89
|
+
const size = get(chart, ['options', 'data', 'length']);
|
|
90
|
+
const x = map(dataArray, (item) => get(item, ['0', 'nextPoints', '0', 'x']) * size - 0.5);
|
|
91
|
+
|
|
87
92
|
const getLineCoordinate = (
|
|
88
93
|
datum: Datum,
|
|
89
94
|
datumIndex: number,
|
|
@@ -93,8 +98,8 @@ function conversionTag(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
|
93
98
|
const percent = maxSize - (maxSize - datum[FUNNEL_MAPPING_VALUE]) / 2;
|
|
94
99
|
return {
|
|
95
100
|
...initLineOption,
|
|
96
|
-
start: [datumIndex - 0.5, percent],
|
|
97
|
-
end: [datumIndex - 0.5, percent + 0.05],
|
|
101
|
+
start: [x[datumIndex - 1] || datumIndex - 0.5, percent],
|
|
102
|
+
end: [x[datumIndex - 1] || datumIndex - 0.5, percent + 0.05],
|
|
98
103
|
};
|
|
99
104
|
};
|
|
100
105
|
|
|
@@ -5,6 +5,8 @@ import { FUNNEL_PERCENT, FUNNEL_CONVERSATION, FUNNEL_MAPPING_VALUE } from '../co
|
|
|
5
5
|
import { Params } from '../../../core/adaptor';
|
|
6
6
|
import { FunnelOptions } from '../types';
|
|
7
7
|
|
|
8
|
+
export const CONVERSION_TAG_NAME = 'CONVERSION_TAG_NAME';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* 漏斗图 transform
|
|
10
12
|
* @param geometry
|
|
@@ -47,16 +49,17 @@ export function conversionTagComponent(
|
|
|
47
49
|
) {
|
|
48
50
|
return function (params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
49
51
|
const { chart, options } = params;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const { data } = chart.getOptions();
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const { conversionTag, filteredData } = options;
|
|
53
54
|
|
|
55
|
+
const data = filteredData || chart.getOptions().data;
|
|
54
56
|
if (conversionTag) {
|
|
55
57
|
const { formatter } = conversionTag;
|
|
56
58
|
data.forEach((obj, index) => {
|
|
57
59
|
if (index <= 0 || Number.isNaN(obj[FUNNEL_MAPPING_VALUE])) return;
|
|
58
60
|
const lineOption = getLineCoordinate(obj, index, data, {
|
|
59
61
|
top: true,
|
|
62
|
+
name: CONVERSION_TAG_NAME,
|
|
60
63
|
text: {
|
|
61
64
|
content: isFunction(formatter) ? formatter(obj, data) : formatter,
|
|
62
65
|
offsetX: conversionTag.offsetX,
|