@antv/g2 5.0.3 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +7 -5
- package/esm/api/chart.js +39 -25
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +1 -0
- package/esm/api/composition/base.js +2 -2
- package/esm/api/composition/base.js.map +1 -1
- package/esm/component/axis.d.ts +5 -2
- package/esm/component/axis.js +30 -19
- package/esm/component/axis.js.map +1 -1
- package/esm/component/constant.d.ts +14 -0
- package/esm/component/constant.js +235 -0
- package/esm/component/constant.js.map +1 -0
- package/esm/component/legendContinuousBlockSize.js +2 -1
- package/esm/component/legendContinuousBlockSize.js.map +1 -1
- package/esm/component/legendContinuousSize.js +14 -5
- package/esm/component/legendContinuousSize.js.map +1 -1
- package/esm/component/slider.js +8 -5
- package/esm/component/slider.js.map +1 -1
- package/esm/interaction/brushFilter.d.ts +1 -1
- package/esm/interaction/brushFilter.js +22 -8
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.js +1 -1
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXFilter.d.ts +1 -1
- package/esm/interaction/brushYFilter.d.ts +1 -1
- package/esm/interaction/legendFilter.js +6 -3
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +16 -7
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +38 -17
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/component.js +2 -92
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +4 -2
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +3 -1
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/transform.js +5 -7
- package/esm/runtime/transform.js.map +1 -1
- package/esm/shape/label/label.js +3 -2
- package/esm/shape/label/label.js.map +1 -1
- package/esm/shape/lineXY/line.d.ts +22 -1
- package/esm/shape/lineXY/line.js +12 -1
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/link/link.d.ts +2 -1
- package/esm/shape/link/link.js +5 -41
- package/esm/shape/link/link.js.map +1 -1
- package/esm/shape/text/advance.js +2 -4
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.d.ts +4 -0
- package/esm/shape/utils.js.map +1 -1
- package/esm/shape/vector/vector.d.ts +1 -0
- package/esm/shape/vector/vector.js +12 -8
- package/esm/shape/vector/vector.js.map +1 -1
- package/esm/transform/sort.js +13 -3
- package/esm/transform/sort.js.map +1 -1
- package/esm/utils/size.d.ts +0 -10
- package/esm/utils/size.js +0 -23
- package/esm/utils/size.js.map +1 -1
- package/lib/api/chart.d.ts +7 -5
- package/lib/api/chart.js +38 -24
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +1 -0
- package/lib/api/composition/base.js +2 -2
- package/lib/api/composition/base.js.map +1 -1
- package/lib/component/axis.d.ts +5 -2
- package/lib/component/axis.js +30 -19
- package/lib/component/axis.js.map +1 -1
- package/lib/component/constant.d.ts +14 -0
- package/lib/component/constant.js +238 -0
- package/lib/component/constant.js.map +1 -0
- package/lib/component/legendContinuousBlockSize.js +2 -1
- package/lib/component/legendContinuousBlockSize.js.map +1 -1
- package/lib/component/legendContinuousSize.js +14 -5
- package/lib/component/legendContinuousSize.js.map +1 -1
- package/lib/component/slider.js +8 -5
- package/lib/component/slider.js.map +1 -1
- package/lib/interaction/brushFilter.d.ts +1 -1
- package/lib/interaction/brushFilter.js +22 -8
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.js +1 -1
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXFilter.d.ts +1 -1
- package/lib/interaction/brushYFilter.d.ts +1 -1
- package/lib/interaction/legendFilter.js +6 -3
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +16 -7
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +37 -16
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/component.js +2 -92
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +4 -2
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +3 -1
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/transform.js +5 -7
- package/lib/runtime/transform.js.map +1 -1
- package/lib/shape/label/label.js +3 -2
- package/lib/shape/label/label.js.map +1 -1
- package/lib/shape/lineXY/line.d.ts +22 -1
- package/lib/shape/lineXY/line.js +12 -1
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/link/link.d.ts +2 -1
- package/lib/shape/link/link.js +5 -41
- package/lib/shape/link/link.js.map +1 -1
- package/lib/shape/text/advance.js +2 -4
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.d.ts +4 -0
- package/lib/shape/utils.js.map +1 -1
- package/lib/shape/vector/vector.d.ts +1 -0
- package/lib/shape/vector/vector.js +12 -8
- package/lib/shape/vector/vector.js.map +1 -1
- package/lib/transform/sort.js +13 -3
- package/lib/transform/sort.js.map +1 -1
- package/lib/utils/size.d.ts +0 -10
- package/lib/utils/size.js +1 -25
- package/lib/utils/size.js.map +1 -1
- package/package.json +2 -2
- package/src/api/chart.ts +49 -42
- package/src/api/composition/base.ts +4 -2
- package/src/component/axis.ts +55 -23
- package/src/component/constant.ts +237 -0
- package/src/component/legendContinuousBlockSize.ts +2 -3
- package/src/component/legendContinuousSize.ts +21 -12
- package/src/component/slider.ts +10 -5
- package/src/interaction/brushFilter.ts +25 -8
- package/src/interaction/brushHighlight.ts +1 -1
- package/src/interaction/legendFilter.ts +6 -3
- package/src/interaction/sliderFilter.ts +21 -7
- package/src/interaction/tooltip.ts +64 -28
- package/src/runtime/component.ts +2 -98
- package/src/runtime/plot.ts +4 -1
- package/src/runtime/render.ts +3 -1
- package/src/runtime/transform.ts +5 -7
- package/src/shape/label/label.ts +13 -2
- package/src/shape/lineXY/line.ts +45 -2
- package/src/shape/link/link.ts +6 -38
- package/src/shape/text/advance.ts +11 -2
- package/src/shape/utils.ts +4 -0
- package/src/shape/vector/vector.ts +12 -9
- package/src/transform/sort.ts +12 -3
- package/src/utils/size.ts +0 -31
- package/CHANGELOG.md +0 -38
|
@@ -17,25 +17,29 @@ const g_1 = require("@antv/g");
|
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
const selection_1 = require("../../utils/selection");
|
|
19
19
|
/**
|
|
20
|
+
* Connect 2 points with a single line with arrow.
|
|
20
21
|
* ----->
|
|
21
22
|
*/
|
|
22
23
|
const Vector = (options) => {
|
|
23
|
-
const { arrowSize = '40%' } = options, style = __rest(options, ["arrowSize"]);
|
|
24
|
+
const { arrow = true, arrowSize = '40%' } = options, style = __rest(options, ["arrow", "arrowSize"]);
|
|
24
25
|
return (points, value, coordinate, theme) => {
|
|
25
|
-
const { mark, shape, defaultShape,
|
|
26
|
+
const { mark, shape, defaultShape, transform } = value;
|
|
26
27
|
const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
|
|
28
|
+
const { color = defaultColor } = value;
|
|
27
29
|
const [from, to] = points;
|
|
28
|
-
// Calculate arrow end point.
|
|
29
|
-
const [arrow1, arrow2] = (0, utils_1.arrowPoints)(from, to, { arrowSize });
|
|
30
30
|
// Draw line
|
|
31
31
|
const path = (0, d3_path_1.path)();
|
|
32
32
|
path.moveTo(...from);
|
|
33
33
|
path.lineTo(...to);
|
|
34
34
|
// Draw 2 arrows.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (arrow) {
|
|
36
|
+
// Calculate arrow end point.
|
|
37
|
+
const [arrow1, arrow2] = (0, utils_1.arrowPoints)(from, to, { arrowSize });
|
|
38
|
+
path.moveTo(...to);
|
|
39
|
+
path.lineTo(...arrow1);
|
|
40
|
+
path.moveTo(...to);
|
|
41
|
+
path.lineTo(...arrow2);
|
|
42
|
+
}
|
|
39
43
|
return (0, selection_1.select)(new g_1.Path())
|
|
40
44
|
.call(utils_1.applyStyle, shapeTheme)
|
|
41
45
|
.style('d', path.toString())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector.js","sourceRoot":"src/","sources":["shape/vector/vector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAyC;AACzC,+BAA+B;AAC/B,oCAAgF;AAChF,qDAA+C;AAK/C
|
|
1
|
+
{"version":3,"file":"vector.js","sourceRoot":"src/","sources":["shape/vector/vector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAyC;AACzC,+BAA+B;AAC/B,oCAAgF;AAChF,qDAA+C;AAK/C;;;GAGG;AACI,MAAM,MAAM,GAAsB,CAAC,OAAO,EAAE,EAAE;IACnD,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,SAAS,GAAG,KAAK,KAAe,OAAO,EAAjB,KAAK,UAAK,OAAO,EAAvD,sBAA6C,CAAU,CAAC;IAC9D,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QAC1C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;QACvD,MAAM,KAAkC,IAAA,qBAAa,EACnD,KAAK,EACL,IAAI,EACJ,KAAK,EACL,YAAY,CACb,EALK,EAAE,YAAY,OAKnB,EALwB,UAAU,cAA7B,gBAA+B,CAKpC,CAAC;QACF,MAAM,EAAE,KAAK,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC;QACvC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC;QAE1B,YAAY;QACZ,MAAM,IAAI,GAAG,IAAA,cAAM,GAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAEnB,iBAAiB;QACjB,IAAI,KAAK,EAAE;YACT,6BAA6B;YAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAA,mBAAW,EAAC,IAAI,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;SACxB;QAED,OAAO,IAAA,kBAAM,EAAC,IAAI,QAAI,EAAE,CAAC;aACtB,IAAI,CAAC,kBAAU,EAAE,UAAU,CAAC;aAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;aAC3B,KAAK,CAAC,QAAQ,EAAE,KAAK,IAAI,YAAY,CAAC;aACtC,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC;aAC7B,IAAI,CAAC,kBAAU,EAAE,KAAK,CAAC;aACvB,IAAI,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC,CAAC;AApCW,QAAA,MAAM,UAoCjB;AAEF,cAAM,CAAC,KAAK,GAAG;IACb,aAAa,EAAE,MAAM;IACrB,qBAAqB,EAAE,QAAQ;IAC/B,sBAAsB,EAAE,UAAU;IAClC,oBAAoB,EAAE,SAAS;CAChC,CAAC"}
|
package/lib/transform/sort.js
CHANGED
|
@@ -37,7 +37,7 @@ function createReducer(channel, options, encode) {
|
|
|
37
37
|
throw new Error(`Unknown reducer: ${reducer}`);
|
|
38
38
|
}
|
|
39
39
|
function sortQuantitative(I, mark, options) {
|
|
40
|
-
const { reverse,
|
|
40
|
+
const { reverse, channel } = options;
|
|
41
41
|
const { encode } = mark;
|
|
42
42
|
const [V] = (0, helper_1.columnOf)(encode, channel);
|
|
43
43
|
const sortedI = (0, d3_array_1.sort)(I, (i) => V[i]);
|
|
@@ -46,12 +46,22 @@ function sortQuantitative(I, mark, options) {
|
|
|
46
46
|
// const s = typeof slice === 'number' ? [0, slice] : slice;
|
|
47
47
|
return [sortedI, mark];
|
|
48
48
|
}
|
|
49
|
+
// If domain is specified, only sort data in the domain.
|
|
50
|
+
function filterIndex(I, values, specifiedDomain) {
|
|
51
|
+
if (!Array.isArray(specifiedDomain))
|
|
52
|
+
return I;
|
|
53
|
+
const domain = new Set(specifiedDomain);
|
|
54
|
+
return I.filter((i) => domain.has(values[i]));
|
|
55
|
+
}
|
|
49
56
|
function sortOrdinal(I, mark, options) {
|
|
57
|
+
var _a;
|
|
50
58
|
const { reverse, slice, channel } = options, rest = __rest(options, ["reverse", "slice", "channel"]);
|
|
51
|
-
const { encode } = mark;
|
|
59
|
+
const { encode, scale = {} } = mark;
|
|
60
|
+
const domain = (_a = scale[channel]) === null || _a === void 0 ? void 0 : _a.domain;
|
|
52
61
|
const [T] = (0, helper_1.columnOf)(encode, channel);
|
|
53
62
|
const normalizeReducer = createReducer(channel, rest, encode);
|
|
54
|
-
const
|
|
63
|
+
const SI = filterIndex(I, T, domain);
|
|
64
|
+
const sortedDomain = (0, d3_array_1.groupSort)(SI, normalizeReducer, (i) => T[i]);
|
|
55
65
|
if (reverse)
|
|
56
66
|
sortedDomain.reverse();
|
|
57
67
|
const s = typeof slice === 'number' ? [0, slice] : slice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.js","sourceRoot":"src/","sources":["transform/sort.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,uCASkB;AAElB,2CAA0C;AAE1C,SAAS,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM;IAC7C,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,GAAG,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EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IACrE,OAAO;QACL,CAAC;QACD,IAAA,cAAO,EAAC,IAAI,EAAE;YACZ,KAAK,EAAE;gBACL,CAAC,OAAO,CAAC,EAAE;oBACT,MAAM,EAAE,YAAY;iBACrB;aACF;SACF,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;GAEG;AACI,MAAM,IAAI,GAAoB,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE;IACpD,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,KAAc,OAAO,EAAhB,IAAI,UAAK,OAAO,EAAtE,0CAA4D,CAAU,CAAC;IAC7E,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;QACjB,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,gBAAgB,CAAC,CAAC,EAAE,IAAI,kBAC7B,OAAO;gBACP,KAAK;gBACL,OAAO,IACJ,IAAI,EACP,CAAC;SACJ;QACD,OAAO,WAAW,CAAC,CAAC,EAAE,IAAI,kBAAI,OAAO,EAAE,KAAK,EAAE,OAAO,IAAK,IAAI,EAAG,CAAC;IACpE,CAAC,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,IAAI,QAaf;AAEF,YAAI,CAAC,KAAK,GAAG,EAAE,CAAC"}
|
package/lib/utils/size.d.ts
CHANGED
|
@@ -9,16 +9,6 @@ type Size = {
|
|
|
9
9
|
* @returns the element width and height
|
|
10
10
|
*/
|
|
11
11
|
export declare function getContainerSize(container: HTMLElement): Size;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @description Calculate the chart size.
|
|
15
|
-
* @param container DOM container element.
|
|
16
|
-
* @param autoFit Should auto fit.
|
|
17
|
-
* @param width Chart width which is set by user.
|
|
18
|
-
* @param height Chart height which is set by user.
|
|
19
|
-
* @returns chart width and height.
|
|
20
|
-
*/
|
|
21
|
-
export declare function getChartSize(container: HTMLElement, autoFit: boolean, width: number, height: number): Size;
|
|
22
12
|
/**
|
|
23
13
|
* @description Calculate the real canvas size by view options.
|
|
24
14
|
*/
|
package/lib/utils/size.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBBoxSize = exports.
|
|
3
|
+
exports.getBBoxSize = exports.getContainerSize = void 0;
|
|
4
4
|
const parseInt10 = (d) => (d ? parseInt(d) : 0);
|
|
5
5
|
/**
|
|
6
6
|
* @description Get the element's bounding size.
|
|
@@ -20,30 +20,6 @@ function getContainerSize(container) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
exports.getContainerSize = getContainerSize;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @description Calculate the chart size.
|
|
26
|
-
* @param container DOM container element.
|
|
27
|
-
* @param autoFit Should auto fit.
|
|
28
|
-
* @param width Chart width which is set by user.
|
|
29
|
-
* @param height Chart height which is set by user.
|
|
30
|
-
* @returns chart width and height.
|
|
31
|
-
*/
|
|
32
|
-
function getChartSize(container, autoFit, width, height) {
|
|
33
|
-
if (!autoFit) {
|
|
34
|
-
return {
|
|
35
|
-
width,
|
|
36
|
-
height,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
// Get size from wrapper container.
|
|
40
|
-
const size = getContainerSize(container);
|
|
41
|
-
return {
|
|
42
|
-
width: size.width,
|
|
43
|
-
height: size.height,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
exports.getChartSize = getChartSize;
|
|
47
23
|
/**
|
|
48
24
|
* @description Calculate the real canvas size by view options.
|
|
49
25
|
*/
|
package/lib/utils/size.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.js","sourceRoot":"src/","sources":["utils/size.ts"],"names":[],"mappings":";;;AAOA,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAExD;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,SAAsB;IACrD,iCAAiC;IAEjC,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAE1C,MAAM,YAAY,GAAG,SAAS,CAAC,WAAW,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,SAAS,CAAC,YAAY,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzE,MAAM,YAAY,GAChB,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACjE,MAAM,aAAa,GACjB,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK,EAAE,YAAY,GAAG,YAAY;QAClC,MAAM,EAAE,aAAa,GAAG,aAAa;KACtC,CAAC;AACJ,CAAC;AAjBD,4CAiBC;AAED
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"src/","sources":["utils/size.ts"],"names":[],"mappings":";;;AAOA,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAExD;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,SAAsB;IACrD,iCAAiC;IAEjC,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAE1C,MAAM,YAAY,GAAG,SAAS,CAAC,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CD,kCAqCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
|
|
29
29
|
"build": "run-p build:*",
|
|
30
30
|
"bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
|
|
31
|
-
"ci": "run-s lint
|
|
31
|
+
"ci": "run-s lint build",
|
|
32
32
|
"prepublishOnly": "npm run ci",
|
|
33
33
|
"prepare": "husky install",
|
|
34
34
|
"upload": "node scripts/uploadSnapshot.js",
|
package/src/api/chart.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { debounce, deepMix, omit } from '@antv/util';
|
|
|
5
5
|
import EventEmitter from '@antv/event-emitter';
|
|
6
6
|
import { G2Context, render, destroy } from '../runtime';
|
|
7
7
|
import { ViewComposition } from '../spec';
|
|
8
|
-
import {
|
|
8
|
+
import { getContainerSize } from '../utils/size';
|
|
9
9
|
import { ChartEvent } from '../utils/event';
|
|
10
10
|
import { G2ViewTree } from '../runtime/types/options';
|
|
11
11
|
import { Node } from './node';
|
|
@@ -95,6 +95,13 @@ function Canvas(
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
function sizeOf(options, container) {
|
|
99
|
+
const { autoFit } = options;
|
|
100
|
+
if (autoFit) return getContainerSize(container);
|
|
101
|
+
const { width = 640, height = 480 } = options;
|
|
102
|
+
return { width, height };
|
|
103
|
+
}
|
|
104
|
+
|
|
98
105
|
export function optionsOf(node: Node): Record<string, any> {
|
|
99
106
|
const root = normalizeRoot(node);
|
|
100
107
|
const discovered: Node[] = [root];
|
|
@@ -169,36 +176,23 @@ export class Chart extends View<ChartOptions> {
|
|
|
169
176
|
private _context: G2Context;
|
|
170
177
|
private _emitter: EventEmitter;
|
|
171
178
|
private _options: G2ViewTree;
|
|
179
|
+
private _width: number;
|
|
180
|
+
private _height: number;
|
|
172
181
|
|
|
173
182
|
constructor(options: ChartOptions) {
|
|
174
|
-
const { container, canvas,
|
|
183
|
+
const { container, canvas, ...rest } = options || {};
|
|
175
184
|
super(rest, 'view');
|
|
176
|
-
this.attr('key', key);
|
|
177
185
|
this._container = normalizeContainer(container);
|
|
178
186
|
this._emitter = new EventEmitter();
|
|
179
187
|
this._context = { library, emitter: this._emitter, canvas };
|
|
180
|
-
this.
|
|
188
|
+
this._bindAutoFit();
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
render(): Promise<Chart> {
|
|
184
192
|
if (!this._context.canvas) {
|
|
185
193
|
// Init width and height.
|
|
186
|
-
const {
|
|
187
|
-
|
|
188
|
-
height = 480,
|
|
189
|
-
renderer,
|
|
190
|
-
plugins,
|
|
191
|
-
autoFit,
|
|
192
|
-
} = this.options();
|
|
193
|
-
const { width: adjustedWidth, height: adjustedHeight } = getChartSize(
|
|
194
|
-
this._container,
|
|
195
|
-
autoFit,
|
|
196
|
-
width,
|
|
197
|
-
height,
|
|
198
|
-
);
|
|
199
|
-
this.width(adjustedWidth);
|
|
200
|
-
this.height(adjustedHeight);
|
|
201
|
-
|
|
194
|
+
const { renderer, plugins } = this.options();
|
|
195
|
+
const { width, height } = sizeOf(this.options(), this._container);
|
|
202
196
|
// Create canvas if it does not exist.
|
|
203
197
|
this._context.canvas = Canvas(
|
|
204
198
|
this._container,
|
|
@@ -211,12 +205,27 @@ export class Chart extends View<ChartOptions> {
|
|
|
211
205
|
|
|
212
206
|
return new Promise((resolve, reject) => {
|
|
213
207
|
try {
|
|
214
|
-
|
|
208
|
+
const options = this.options();
|
|
209
|
+
const { key = G2_CHART_KEY } = options;
|
|
210
|
+
const { width, height } = sizeOf(options, this._container);
|
|
211
|
+
|
|
212
|
+
// Update actual size and key.
|
|
213
|
+
this._width = width;
|
|
214
|
+
this._height = height;
|
|
215
|
+
this._key = key;
|
|
216
|
+
|
|
217
|
+
render(
|
|
218
|
+
{ key: this._key, ...options, width, height },
|
|
219
|
+
this._context,
|
|
220
|
+
() => resolve(this),
|
|
221
|
+
reject,
|
|
222
|
+
);
|
|
215
223
|
} catch (e) {
|
|
216
224
|
reject(e);
|
|
217
225
|
}
|
|
218
226
|
});
|
|
219
227
|
}
|
|
228
|
+
|
|
220
229
|
/**
|
|
221
230
|
* @overload
|
|
222
231
|
* @returns {G2ViewTree}
|
|
@@ -283,7 +292,7 @@ export class Chart extends View<ChartOptions> {
|
|
|
283
292
|
destroy() {
|
|
284
293
|
const options = this.options();
|
|
285
294
|
this.emit(ChartEvent.BEFORE_DESTROY);
|
|
286
|
-
this.
|
|
295
|
+
this._unbindAutoFit();
|
|
287
296
|
this._options = {};
|
|
288
297
|
destroy(options, this._context, true);
|
|
289
298
|
removeContainer(this._container);
|
|
@@ -291,26 +300,24 @@ export class Chart extends View<ChartOptions> {
|
|
|
291
300
|
}
|
|
292
301
|
|
|
293
302
|
forceFit() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
303
|
+
// Don't call changeSize to prevent update width and height of options.
|
|
304
|
+
// @ts-ignore
|
|
305
|
+
this.options.autoFit = true;
|
|
306
|
+
this.emit(ChartEvent.BEFORE_CHANGE_SIZE);
|
|
307
|
+
const finished = this.render();
|
|
308
|
+
finished.then(() => {
|
|
309
|
+
this.emit(ChartEvent.AFTER_CHANGE_SIZE);
|
|
310
|
+
});
|
|
311
|
+
return finished;
|
|
304
312
|
}
|
|
305
313
|
|
|
306
|
-
changeSize(
|
|
307
|
-
|
|
308
|
-
if (width === adjustedWidth && height === adjustedHeight) {
|
|
314
|
+
changeSize(width: number, height: number): Promise<Chart> {
|
|
315
|
+
if (width === this._width && height === this._height) {
|
|
309
316
|
return Promise.resolve(this);
|
|
310
317
|
}
|
|
311
318
|
this.emit(ChartEvent.BEFORE_CHANGE_SIZE);
|
|
312
|
-
this.width(
|
|
313
|
-
this.height(
|
|
319
|
+
this.width(width);
|
|
320
|
+
this.height(height);
|
|
314
321
|
const finished = this.render();
|
|
315
322
|
finished.then(() => {
|
|
316
323
|
this.emit(ChartEvent.AFTER_CHANGE_SIZE);
|
|
@@ -318,23 +325,23 @@ export class Chart extends View<ChartOptions> {
|
|
|
318
325
|
return finished;
|
|
319
326
|
}
|
|
320
327
|
|
|
321
|
-
private
|
|
328
|
+
private _onResize = debounce(() => {
|
|
322
329
|
this.forceFit();
|
|
323
330
|
}, 300);
|
|
324
331
|
|
|
325
|
-
private
|
|
332
|
+
private _bindAutoFit() {
|
|
326
333
|
const options = this.options();
|
|
327
334
|
const { autoFit } = options;
|
|
328
335
|
if (autoFit) {
|
|
329
|
-
window.addEventListener('resize', this.
|
|
336
|
+
window.addEventListener('resize', this._onResize);
|
|
330
337
|
}
|
|
331
338
|
}
|
|
332
339
|
|
|
333
|
-
private
|
|
340
|
+
private _unbindAutoFit() {
|
|
334
341
|
const options = this.options();
|
|
335
342
|
const { autoFit } = options;
|
|
336
343
|
if (autoFit) {
|
|
337
|
-
window.removeEventListener('resize', this.
|
|
344
|
+
window.removeEventListener('resize', this._onResize);
|
|
338
345
|
}
|
|
339
346
|
}
|
|
340
347
|
}
|
|
@@ -9,6 +9,8 @@ export class CompositionNode<
|
|
|
9
9
|
ParentValue extends Record<string, any> = Record<string, any>,
|
|
10
10
|
ChildValue extends Record<string, any> = Record<string, any>,
|
|
11
11
|
> extends Node<Value, ParentValue, ChildValue> {
|
|
12
|
+
protected _key: string;
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Change current node data and its children data.
|
|
14
16
|
*/
|
|
@@ -31,7 +33,7 @@ export class CompositionNode<
|
|
|
31
33
|
const chart = this.getRoot();
|
|
32
34
|
const { views } = chart.getContext();
|
|
33
35
|
if (!views?.length) return undefined;
|
|
34
|
-
return views.find((view) => view.key === this.
|
|
36
|
+
return views.find((view) => view.key === this._key);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
getScale(): Record<string, Scale> {
|
|
@@ -53,7 +55,7 @@ export class CompositionNode<
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
getGroup(): DisplayObject {
|
|
56
|
-
const key = this.
|
|
58
|
+
const key = this._key;
|
|
57
59
|
if (!key) return undefined;
|
|
58
60
|
const chart = this.getRoot();
|
|
59
61
|
const chartGroup = chart.getContext().canvas.getRoot();
|
package/src/component/axis.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Coordinate } from '@antv/coord';
|
|
2
|
+
import type { DisplayObject } from '@antv/g';
|
|
2
3
|
import { Axis as AxisComponent } from '@antv/gui';
|
|
3
4
|
import { Linear as LinearScale } from '@antv/scale';
|
|
4
5
|
import { deepMix } from '@antv/util';
|
|
@@ -23,15 +24,22 @@ import {
|
|
|
23
24
|
radiusOf,
|
|
24
25
|
} from '../utils/coordinate';
|
|
25
26
|
import { capitalizeFirst } from '../utils/helper';
|
|
26
|
-
import { adaptor, isVertical,
|
|
27
|
+
import { adaptor, isVertical, titleContent } from './utils';
|
|
27
28
|
|
|
28
29
|
export type AxisOptions = {
|
|
29
30
|
position?: GCP;
|
|
30
31
|
zIndex?: number;
|
|
31
32
|
title?: string | string[];
|
|
32
33
|
direction?: 'left' | 'center' | 'right';
|
|
33
|
-
labelFormatter?: (
|
|
34
|
-
|
|
34
|
+
labelFormatter?: (datum: any, index: number, array: any[]) => string;
|
|
35
|
+
labelFilter?: (datum: any, index: number, array: any[]) => boolean;
|
|
36
|
+
tickFormatter?: (
|
|
37
|
+
datum: any,
|
|
38
|
+
index: number,
|
|
39
|
+
array: any[],
|
|
40
|
+
vector: [number, number],
|
|
41
|
+
) => DisplayObject;
|
|
42
|
+
tickFilter?: (datum: any, index: number, array: any[]) => boolean;
|
|
35
43
|
tickMethod?: (
|
|
36
44
|
start: number | Date,
|
|
37
45
|
end: number | Date,
|
|
@@ -121,7 +129,7 @@ function createInset(position, coordinate) {
|
|
|
121
129
|
/**
|
|
122
130
|
* Calc ticks based on scale and coordinate.
|
|
123
131
|
*/
|
|
124
|
-
function
|
|
132
|
+
function getData(
|
|
125
133
|
scale: Scale,
|
|
126
134
|
domain: any[],
|
|
127
135
|
tickCount: number,
|
|
@@ -140,26 +148,31 @@ function getTicks(
|
|
|
140
148
|
|
|
141
149
|
const ticks = ticksOf(scale, domain, tickMethod);
|
|
142
150
|
const filteredTicks = tickFilter ? ticks.filter(tickFilter) : ticks;
|
|
143
|
-
const
|
|
144
|
-
const
|
|
151
|
+
const toString = (d) => (typeof d === 'object' && !!d ? d : String(d));
|
|
152
|
+
const labelFormatter =
|
|
153
|
+
defaultTickFormatter || scale.getFormatter?.() || toString;
|
|
145
154
|
const applyInset = createInset(position, coordinate);
|
|
146
155
|
const applyFisheye = createFisheye(position, coordinate);
|
|
156
|
+
const isHorizontal = (position) =>
|
|
157
|
+
['top', 'bottom', 'center', 'outer'].includes(position);
|
|
147
158
|
|
|
159
|
+
// @todo GUI should consider the overlap problem for the first
|
|
160
|
+
// and label of arc axis.
|
|
148
161
|
if (isPolar(coordinate) || isTranspose(coordinate)) {
|
|
149
|
-
|
|
162
|
+
return filteredTicks.map((d, i, array) => {
|
|
150
163
|
const offset = scale.getBandWidth?.(d) / 2 || 0;
|
|
151
164
|
const tick = applyInset(scale.map(d) + offset);
|
|
165
|
+
const shouldReverse =
|
|
166
|
+
(isRadial(coordinate) && position === 'center') ||
|
|
167
|
+
(isTranspose(coordinate) &&
|
|
168
|
+
scale.getTicks?.() &&
|
|
169
|
+
isHorizontal(position));
|
|
152
170
|
return {
|
|
153
|
-
value:
|
|
171
|
+
value: shouldReverse ? 1 - tick : tick,
|
|
154
172
|
label: toString(labelFormatter(prettyNumber(d), i, array)),
|
|
155
173
|
id: String(i),
|
|
156
174
|
};
|
|
157
175
|
});
|
|
158
|
-
// @todo GUI should consider the overlap problem for the first
|
|
159
|
-
// and label of arc axis.
|
|
160
|
-
return isRadial(coordinate) && position === 'center'
|
|
161
|
-
? reverseTicks(axisTicks)
|
|
162
|
-
: axisTicks;
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
return filteredTicks.map((d, i, array) => {
|
|
@@ -353,7 +366,7 @@ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
353
366
|
size,
|
|
354
367
|
position,
|
|
355
368
|
orientation,
|
|
356
|
-
labelFormatter
|
|
369
|
+
labelFormatter,
|
|
357
370
|
tickFilter,
|
|
358
371
|
tickCount,
|
|
359
372
|
tickMethod,
|
|
@@ -365,7 +378,7 @@ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
365
378
|
return ({ scales: [scale], value, coordinate, theme }) => {
|
|
366
379
|
const { bbox } = value;
|
|
367
380
|
const { domain } = scale.getOptions();
|
|
368
|
-
const
|
|
381
|
+
const data = getData(
|
|
369
382
|
scale,
|
|
370
383
|
domain,
|
|
371
384
|
tickCount,
|
|
@@ -391,7 +404,7 @@ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
391
404
|
style: adaptor(
|
|
392
405
|
deepMix({}, axisTheme, defaultStyle, {
|
|
393
406
|
type: 'arc',
|
|
394
|
-
data
|
|
407
|
+
data,
|
|
395
408
|
titleText: titleContent(title),
|
|
396
409
|
grid,
|
|
397
410
|
...rest,
|
|
@@ -456,7 +469,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
456
469
|
const {
|
|
457
470
|
direction = 'left',
|
|
458
471
|
important = {},
|
|
459
|
-
labelFormatter
|
|
472
|
+
labelFormatter,
|
|
460
473
|
order,
|
|
461
474
|
orientation,
|
|
462
475
|
position,
|
|
@@ -500,7 +513,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
500
513
|
const finalAxisStyle = {
|
|
501
514
|
...internalAxisStyle,
|
|
502
515
|
type: 'linear' as const,
|
|
503
|
-
data:
|
|
516
|
+
data: getData(
|
|
504
517
|
scale,
|
|
505
518
|
domain,
|
|
506
519
|
tickCount,
|
|
@@ -520,7 +533,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
520
533
|
...overrideStyle,
|
|
521
534
|
...important,
|
|
522
535
|
};
|
|
523
|
-
|
|
524
536
|
return new AxisComponent({
|
|
525
537
|
className: 'axis',
|
|
526
538
|
style: adaptor(finalAxisStyle),
|
|
@@ -532,10 +544,30 @@ const axisFactor: (
|
|
|
532
544
|
axis: typeof ArcAxisComponent | typeof LinearAxisComponent,
|
|
533
545
|
) => GCC<AxisOptions> = (axis) => {
|
|
534
546
|
return (options) => {
|
|
535
|
-
const {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
547
|
+
const {
|
|
548
|
+
labelFormatter: useDefinedLabelFormatter,
|
|
549
|
+
labelFilter: userDefinedLabelFilter = () => true,
|
|
550
|
+
} = options;
|
|
551
|
+
|
|
552
|
+
return (context) => {
|
|
553
|
+
const {
|
|
554
|
+
scales: [scale],
|
|
555
|
+
} = context;
|
|
556
|
+
const ticks = scale.getTicks?.() || scale.getOptions().domain;
|
|
557
|
+
const labelFormatter =
|
|
558
|
+
typeof useDefinedLabelFormatter === 'string'
|
|
559
|
+
? format(useDefinedLabelFormatter)
|
|
560
|
+
: useDefinedLabelFormatter;
|
|
561
|
+
const labelFilter = (datum: any, index: number, array: any[]) =>
|
|
562
|
+
userDefinedLabelFilter(ticks[index], index, ticks);
|
|
563
|
+
|
|
564
|
+
const normalizedOptions = {
|
|
565
|
+
...options,
|
|
566
|
+
labelFormatter,
|
|
567
|
+
labelFilter,
|
|
568
|
+
};
|
|
569
|
+
return axis(normalizedOptions)(context);
|
|
570
|
+
};
|
|
539
571
|
};
|
|
540
572
|
};
|
|
541
573
|
|