@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.
@@ -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(() => this._renderTrailing());
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 { dsvFormat, autoType as d3AutoType } from '@antv/vendor/d3-dsv';
2
- import { FetchConnector } from '../spec';
3
- import { DataComponent as DC } from '../runtime';
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
- } else if (format === 'json') {
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 canvas: any = group.ownerDocument.defaultView
32
- .getContextService()
33
- .getDomElement();
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
 
@@ -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) =>
@@ -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
- emitter.off();
181
+
182
+ if (isClearEvents) {
183
+ emitter.off();
184
+ }
181
185
  }
182
186
 
183
187
  /**