@antv/g2 5.3.3 → 5.3.4-alpha.0
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/README.md +9 -0
- package/README.zh-CN.md +8 -0
- package/dist/g2.lite.min.js +5 -5
- package/dist/g2.min.js +5 -5
- package/esm/api/runtime.d.ts +2 -1
- package/esm/api/runtime.js +26 -3
- package/esm/api/runtime.js.map +1 -1
- package/esm/data/fetch.d.ts +2 -2
- package/esm/data/fetch.js +2 -2
- package/esm/data/fetch.js.map +1 -1
- package/esm/interaction/tooltip.js +5 -3
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/plot.js +2 -0
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.d.ts +1 -1
- package/esm/runtime/render.js +4 -2
- package/esm/runtime/render.js.map +1 -1
- package/lib/api/runtime.d.ts +2 -1
- package/lib/api/runtime.js +26 -3
- package/lib/api/runtime.js.map +1 -1
- package/lib/data/fetch.d.ts +2 -2
- package/lib/data/fetch.js +1 -1
- package/lib/data/fetch.js.map +1 -1
- package/lib/interaction/tooltip.js +5 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/plot.js +2 -0
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.d.ts +1 -1
- package/lib/runtime/render.js +4 -2
- package/lib/runtime/render.js.map +1 -1
- package/package.json +19 -19
- package/src/api/runtime.ts +29 -3
- package/src/data/fetch.ts +5 -4
- package/src/interaction/tooltip.ts +3 -3
- package/src/runtime/plot.ts +1 -0
- package/src/runtime/render.ts +5 -1
package/src/api/runtime.ts
CHANGED
|
@@ -65,6 +65,7 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
65
65
|
// Identifies whether bindAutoFit.
|
|
66
66
|
private _hasBindAutoFit = false;
|
|
67
67
|
private _rendering = false;
|
|
68
|
+
private _trailingClear = null;
|
|
68
69
|
private _trailing = false;
|
|
69
70
|
private _trailingResolve = null;
|
|
70
71
|
private _trailingReject = null;
|
|
@@ -105,11 +106,27 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
105
106
|
this._createReject(reject),
|
|
106
107
|
),
|
|
107
108
|
);
|
|
109
|
+
|
|
108
110
|
const [finished1, resolve, reject] = createEmptyPromise<Runtime<Spec>>();
|
|
109
111
|
finished
|
|
110
112
|
.then(resolve)
|
|
113
|
+
.then(() => {
|
|
114
|
+
// Resolve trailing clear.
|
|
115
|
+
if (this._trailingClear) {
|
|
116
|
+
const options = this.options();
|
|
117
|
+
|
|
118
|
+
this._trailingClear();
|
|
119
|
+
|
|
120
|
+
// If clear is called during trailing, recover options for next trailing render.
|
|
121
|
+
if (this._trailing) this.options(options);
|
|
122
|
+
}
|
|
123
|
+
})
|
|
111
124
|
.catch(reject)
|
|
112
|
-
.then(() =>
|
|
125
|
+
.then(() => {
|
|
126
|
+
this._trailingClear = null;
|
|
127
|
+
this._renderTrailing();
|
|
128
|
+
});
|
|
129
|
+
|
|
113
130
|
return finished1;
|
|
114
131
|
}
|
|
115
132
|
|
|
@@ -171,11 +188,20 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
171
188
|
return this;
|
|
172
189
|
}
|
|
173
190
|
|
|
174
|
-
clear() {
|
|
191
|
+
clear(isClearEvents = true) {
|
|
192
|
+
// Clear after render, otherwise render with destroyed context will return infinite promise, which will block trialing render.
|
|
193
|
+
if (this._rendering) {
|
|
194
|
+
this._trailingClear = () => {
|
|
195
|
+
this.clear(isClearEvents);
|
|
196
|
+
};
|
|
197
|
+
// Only reset options, not destroy canvas.
|
|
198
|
+
this._reset();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
175
201
|
const options = this.options();
|
|
176
202
|
this.emit(ChartEvent.BEFORE_CLEAR);
|
|
177
203
|
this._reset();
|
|
178
|
-
destroy(options, this._context, false);
|
|
204
|
+
destroy(options, this._context, false, isClearEvents);
|
|
179
205
|
this.emit(ChartEvent.AFTER_CLEAR);
|
|
180
206
|
}
|
|
181
207
|
|
package/src/data/fetch.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { autoType as d3AutoType, dsvFormat } from '@antv/vendor/d3-dsv';
|
|
2
|
+
import type { DataComponent as DC } from '../runtime';
|
|
3
|
+
import type { FetchConnector } from '../spec';
|
|
4
4
|
import { identity } from '../utils/helper';
|
|
5
5
|
|
|
6
6
|
export type FetchOptions = Omit<FetchConnector, 'type'>;
|
|
@@ -19,7 +19,8 @@ export const Fetch: DC<FetchOptions> = (options) => {
|
|
|
19
19
|
// @see: https://github.com/d3/d3-dsv#dsv_parse
|
|
20
20
|
const str = await response.text();
|
|
21
21
|
return dsvFormat(delimiter).parse(str, autoType ? d3AutoType : identity);
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
if (format === 'json') {
|
|
23
24
|
return await response.json();
|
|
24
25
|
}
|
|
25
26
|
throw new Error(`Unknown format: ${format}.`);
|
|
@@ -28,9 +28,9 @@ function getContainer(
|
|
|
28
28
|
if (mount) {
|
|
29
29
|
return typeof mount === 'string' ? document.querySelector(mount) : mount;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const view = group.ownerDocument?.defaultView;
|
|
32
|
+
if (!view) return;
|
|
33
|
+
const canvas: any = view.getContextService().getDomElement();
|
|
34
34
|
return canvas.parentElement as unknown as HTMLElement;
|
|
35
35
|
}
|
|
36
36
|
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1477,6 +1477,7 @@ function selectFacetElements(
|
|
|
1477
1477
|
elementClassName: string,
|
|
1478
1478
|
): DisplayObject[] {
|
|
1479
1479
|
const group = selection.node().parentElement;
|
|
1480
|
+
if (!group || typeof group.findAll !== 'function') return [];
|
|
1480
1481
|
return group
|
|
1481
1482
|
.findAll(
|
|
1482
1483
|
(node) =>
|
package/src/runtime/render.ts
CHANGED
|
@@ -171,13 +171,17 @@ export function destroy<T extends G2ViewTree = G2ViewTree>(
|
|
|
171
171
|
options: T,
|
|
172
172
|
context: G2Context = {},
|
|
173
173
|
isDestroyCanvas = false,
|
|
174
|
+
isClearEvents = true,
|
|
174
175
|
) {
|
|
175
176
|
const { canvas, emitter } = context;
|
|
176
177
|
if (canvas) {
|
|
177
178
|
destroyAllInteractions(canvas);
|
|
178
179
|
isDestroyCanvas ? canvas.destroy() : canvas.destroyChildren();
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
|
|
182
|
+
if (isClearEvents) {
|
|
183
|
+
emitter.off();
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
/**
|