@antv/g2 5.0.8 → 5.0.10

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.
Files changed (84) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +4 -4
  3. package/esm/api/chart.d.ts +11 -2
  4. package/esm/api/chart.js +92 -44
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/node.d.ts +1 -0
  7. package/esm/api/node.js +11 -1
  8. package/esm/api/node.js.map +1 -1
  9. package/esm/api/utils.d.ts +8 -0
  10. package/esm/api/utils.js +146 -20
  11. package/esm/api/utils.js.map +1 -1
  12. package/esm/component/axis.js +21 -3
  13. package/esm/component/axis.js.map +1 -1
  14. package/esm/component/utils.d.ts +1 -1
  15. package/esm/component/utils.js +17 -3
  16. package/esm/component/utils.js.map +1 -1
  17. package/esm/index.d.ts +1 -1
  18. package/esm/index.js +3 -1
  19. package/esm/index.js.map +1 -1
  20. package/esm/interaction/brushHighlight.d.ts +3 -3
  21. package/esm/interaction/brushHighlight.js +12 -10
  22. package/esm/interaction/brushHighlight.js.map +1 -1
  23. package/esm/interaction/brushXHighlight.d.ts +1 -1
  24. package/esm/interaction/brushYHighlight.d.ts +1 -1
  25. package/esm/interaction/tooltip.js +5 -2
  26. package/esm/interaction/tooltip.js.map +1 -1
  27. package/esm/runtime/plot.js +21 -15
  28. package/esm/runtime/plot.js.map +1 -1
  29. package/esm/runtime/scale.js +1 -1
  30. package/esm/runtime/scale.js.map +1 -1
  31. package/esm/theme/academy.js +2 -1
  32. package/esm/theme/academy.js.map +1 -1
  33. package/esm/theme/classic.js +2 -2
  34. package/esm/theme/classic.js.map +1 -1
  35. package/esm/theme/classicDark.js +2 -2
  36. package/esm/theme/classicDark.js.map +1 -1
  37. package/lib/api/chart.d.ts +11 -2
  38. package/lib/api/chart.js +90 -42
  39. package/lib/api/chart.js.map +1 -1
  40. package/lib/api/node.d.ts +1 -0
  41. package/lib/api/node.js +11 -1
  42. package/lib/api/node.js.map +1 -1
  43. package/lib/api/utils.d.ts +8 -0
  44. package/lib/api/utils.js +149 -21
  45. package/lib/api/utils.js.map +1 -1
  46. package/lib/component/axis.js +21 -3
  47. package/lib/component/axis.js.map +1 -1
  48. package/lib/component/utils.d.ts +1 -1
  49. package/lib/component/utils.js +17 -3
  50. package/lib/component/utils.js.map +1 -1
  51. package/lib/index.d.ts +1 -1
  52. package/lib/index.js +3 -1
  53. package/lib/index.js.map +1 -1
  54. package/lib/interaction/brushHighlight.d.ts +3 -3
  55. package/lib/interaction/brushHighlight.js +12 -10
  56. package/lib/interaction/brushHighlight.js.map +1 -1
  57. package/lib/interaction/brushXHighlight.d.ts +1 -1
  58. package/lib/interaction/brushYHighlight.d.ts +1 -1
  59. package/lib/interaction/tooltip.js +5 -2
  60. package/lib/interaction/tooltip.js.map +1 -1
  61. package/lib/runtime/plot.js +21 -15
  62. package/lib/runtime/plot.js.map +1 -1
  63. package/lib/runtime/scale.js +1 -1
  64. package/lib/runtime/scale.js.map +1 -1
  65. package/lib/theme/academy.js +2 -1
  66. package/lib/theme/academy.js.map +1 -1
  67. package/lib/theme/classic.js +2 -2
  68. package/lib/theme/classic.js.map +1 -1
  69. package/lib/theme/classicDark.js +2 -2
  70. package/lib/theme/classicDark.js.map +1 -1
  71. package/package.json +2 -2
  72. package/src/api/chart.ts +104 -53
  73. package/src/api/node.ts +10 -1
  74. package/src/api/utils.ts +139 -20
  75. package/src/component/axis.ts +33 -12
  76. package/src/component/utils.ts +9 -4
  77. package/src/index.ts +10 -1
  78. package/src/interaction/brushHighlight.ts +12 -10
  79. package/src/interaction/tooltip.ts +5 -2
  80. package/src/runtime/plot.ts +43 -20
  81. package/src/runtime/scale.ts +1 -1
  82. package/src/theme/academy.ts +2 -1
  83. package/src/theme/classic.ts +2 -2
  84. package/src/theme/classicDark.ts +2 -2
package/src/api/chart.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IRenderer, RendererPlugin, Canvas as GCanvas } from '@antv/g';
2
2
  import { Renderer as CanvasRenderer } from '@antv/g-canvas';
3
3
  import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
4
- import { debounce, deepMix } from '@antv/util';
4
+ import { debounce } 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';
@@ -27,6 +27,8 @@ import {
27
27
  removeContainer,
28
28
  sizeOf,
29
29
  optionsOf,
30
+ updateRoot,
31
+ createEmptyPromise,
30
32
  } from './utils';
31
33
 
32
34
  export const G2_CHART_KEY = 'G2_CHART_KEY';
@@ -84,13 +86,16 @@ export class Chart extends View<ChartOptions> {
84
86
  private _container: HTMLElement;
85
87
  private _context: G2Context;
86
88
  private _emitter: EventEmitter;
87
- private _options: G2ViewTree;
88
89
  private _width: number;
89
90
  private _height: number;
90
91
  private _renderer: IRenderer;
91
92
  private _plugins: RendererPlugin[];
92
93
  // Identifies whether bindAutoFit.
93
94
  private _hasBindAutoFit = false;
95
+ private _rendering = false;
96
+ private _trailing = false;
97
+ private _trailingResolve = null;
98
+ private _trailingReject = null;
94
99
 
95
100
  constructor(options: ChartOptions) {
96
101
  const { container, canvas, renderer, plugins, ...rest } = options || {};
@@ -103,45 +108,24 @@ export class Chart extends View<ChartOptions> {
103
108
  }
104
109
 
105
110
  render(): Promise<Chart> {
111
+ if (this._rendering) return this._addToTrailing();
112
+ if (!this._context.canvas) this._createCanvas();
106
113
  this._bindAutoFit();
107
-
108
- if (!this._context.canvas) {
109
- // Init width and height.
110
- const { width, height } = sizeOf(this.options(), this._container);
111
- // Create canvas if it does not exist.
112
- // DragAndDropPlugin is for interaction.
113
- // It is OK to register more than one time, G will handle this.
114
- this._plugins.push(new DragAndDropPlugin());
115
- this._plugins.forEach((d) => this._renderer.registerPlugin(d));
116
- this._context.canvas = new GCanvas({
117
- container: this._container,
118
- width,
119
- height,
120
- renderer: this._renderer,
121
- });
122
- }
123
-
124
- return new Promise((resolve, reject) => {
125
- try {
126
- const options = this.options();
127
- const { key = G2_CHART_KEY } = options;
128
- const { width, height } = sizeOf(options, this._container);
129
-
130
- // Update actual size and key.
131
- this._width = width;
132
- this._height = height;
133
- this._key = key;
134
-
135
- render(
136
- { key: this._key, ...options, width, height },
137
- this._context,
138
- () => resolve(this),
139
- reject,
140
- );
141
- } catch (e) {
142
- reject(e);
143
- }
144
- });
114
+ this._rendering = true;
115
+ const finished = new Promise<Chart>((resolve, reject) =>
116
+ render(
117
+ this._computedOptions(),
118
+ this._context,
119
+ this._createResolve(resolve),
120
+ this._createReject(reject),
121
+ ),
122
+ );
123
+ const [finished1, resolve, reject] = createEmptyPromise<Chart>();
124
+ finished
125
+ .then(resolve)
126
+ .catch(reject)
127
+ .then(() => this._renderTrailing());
128
+ return finished1;
145
129
  }
146
130
 
147
131
  /**
@@ -161,20 +145,11 @@ export class Chart extends View<ChartOptions> {
161
145
  * @returns {Chart|G2ViewTree}
162
146
  */
163
147
  options(options?: G2ViewTree): Chart | G2ViewTree {
164
- if (arguments.length === 0) {
165
- return this._options || optionsOf(this);
166
- }
167
- this._options = deepMix(this._options || optionsOf(this), options);
148
+ if (arguments.length === 0) return optionsOf(this);
149
+ updateRoot(this, options);
168
150
  return this;
169
151
  }
170
152
 
171
- // @todo Remove it when implement updateRoot.
172
- changeData(data: any): Promise<Chart> {
173
- // Update options data.
174
- this.options({ data });
175
- return super.changeData(data);
176
- }
177
-
178
153
  getContainer(): HTMLElement {
179
154
  return this._container;
180
155
  }
@@ -206,7 +181,7 @@ export class Chart extends View<ChartOptions> {
206
181
  clear() {
207
182
  const options = this.options();
208
183
  this.emit(ChartEvent.BEFORE_CLEAR);
209
- this._options = {};
184
+ this._reset();
210
185
  destroy(options, this._context, false);
211
186
  this.emit(ChartEvent.AFTER_CLEAR);
212
187
  }
@@ -215,7 +190,7 @@ export class Chart extends View<ChartOptions> {
215
190
  const options = this.options();
216
191
  this.emit(ChartEvent.BEFORE_DESTROY);
217
192
  this._unbindAutoFit();
218
- this._options = {};
193
+ this._reset();
219
194
  destroy(options, this._context, true);
220
195
  removeContainer(this._container);
221
196
  this.emit(ChartEvent.AFTER_DESTROY);
@@ -252,6 +227,82 @@ export class Chart extends View<ChartOptions> {
252
227
  return finished;
253
228
  }
254
229
 
230
+ private _reset() {
231
+ this.type = 'view';
232
+ this.value = {};
233
+ this.children = [];
234
+ }
235
+
236
+ private _renderTrailing() {
237
+ if (!this._trailing) return;
238
+ this._trailing = false;
239
+ this.render()
240
+ .then(() => {
241
+ const trailingResolve = this._trailingResolve.bind(this);
242
+ this._trailingResolve = null;
243
+ trailingResolve(this);
244
+ })
245
+ .catch((error) => {
246
+ const trailingReject = this._trailingReject.bind(this);
247
+ this._trailingReject = null;
248
+ trailingReject(error);
249
+ });
250
+ }
251
+
252
+ private _createResolve(resolve: (chart: Chart) => void) {
253
+ return () => {
254
+ this._rendering = false;
255
+ resolve(this);
256
+ };
257
+ }
258
+
259
+ private _createReject(reject: (error: Error) => void) {
260
+ return (error: Error) => {
261
+ this._rendering = false;
262
+ reject(error);
263
+ };
264
+ }
265
+
266
+ // Update actual size and key.
267
+ private _computedOptions() {
268
+ const options = this.options();
269
+ const { key = G2_CHART_KEY } = options;
270
+ const { width, height } = sizeOf(options, this._container);
271
+ this._width = width;
272
+ this._height = height;
273
+ this._key = key;
274
+ return { key: this._key, ...options, width, height };
275
+ }
276
+
277
+ // Create canvas if it does not exist.
278
+ // DragAndDropPlugin is for interaction.
279
+ // It is OK to register more than one time, G will handle this.
280
+ private _createCanvas() {
281
+ const { width, height } = sizeOf(this.options(), this._container);
282
+ this._plugins.push(new DragAndDropPlugin());
283
+ this._plugins.forEach((d) => this._renderer.registerPlugin(d));
284
+ this._context.canvas = new GCanvas({
285
+ container: this._container,
286
+ width,
287
+ height,
288
+ renderer: this._renderer,
289
+ });
290
+ }
291
+
292
+ private _addToTrailing(): Promise<Chart> {
293
+ // Resolve previous promise, and give up this task.
294
+ this._trailingResolve?.(this);
295
+
296
+ // Create new task.
297
+ this._trailing = true;
298
+ const promise = new Promise<Chart>((resolve, reject) => {
299
+ this._trailingResolve = resolve;
300
+ this._trailingReject = reject;
301
+ });
302
+
303
+ return promise;
304
+ }
305
+
255
306
  private _onResize = debounce(() => {
256
307
  this.forceFit();
257
308
  }, 300);
package/src/api/node.ts CHANGED
@@ -6,7 +6,7 @@ import { Chart } from './chart';
6
6
  function bfs(node: Node, callback?: (...args: any[]) => void) {
7
7
  const discovered: Node[] = [node];
8
8
  while (discovered.length) {
9
- const currentNode = discovered.pop();
9
+ const currentNode = discovered.shift();
10
10
  callback && callback(currentNode);
11
11
  const children = currentNode.children || [];
12
12
  for (const child of children) {
@@ -115,6 +115,15 @@ export class Node<
115
115
  return nodes;
116
116
  }
117
117
 
118
+ getNodeByType(type: string): Node {
119
+ let node = null;
120
+ bfs(this, (current: Node) => {
121
+ if (node) return;
122
+ if (type === current.type) node = current;
123
+ });
124
+ return node;
125
+ }
126
+
118
127
  /**
119
128
  * Apply specified callback to the node value.
120
129
  */
package/src/api/utils.ts CHANGED
@@ -1,5 +1,33 @@
1
+ import { deepMix } from '@antv/util';
2
+ import { G2ViewTree } from '../runtime';
1
3
  import { getContainerSize } from '../utils/size';
2
4
  import { Node } from './node';
5
+ import { mark } from './mark';
6
+ import { composition } from './composition';
7
+
8
+ // Keys can specified by new Chart({...}).
9
+ // Keys can bubble form mark-level options to view-level options.
10
+ export const VIEW_KEYS = [
11
+ 'width',
12
+ 'height',
13
+ 'padding',
14
+ 'paddingLeft',
15
+ 'paddingRight',
16
+ 'paddingBottom',
17
+ 'paddingTop',
18
+ 'inset',
19
+ 'insetLeft',
20
+ 'insetRight',
21
+ 'insetTop',
22
+ 'insetBottom',
23
+ 'margin',
24
+ 'marginLeft',
25
+ 'marginRight',
26
+ 'marginTop',
27
+ 'marginBottom',
28
+ 'autoFit',
29
+ 'theme',
30
+ ];
3
31
 
4
32
  export function normalizeContainer(
5
33
  container: string | HTMLElement,
@@ -22,25 +50,7 @@ export function removeContainer(container: HTMLElement) {
22
50
  export function normalizeRoot(node: Node) {
23
51
  if (node.type !== null) return node;
24
52
  const root = node.children[node.children.length - 1];
25
- root.attr('width', node.attr('width'));
26
- root.attr('height', node.attr('height'));
27
- root.attr('paddingLeft', node.attr('paddingLeft'));
28
- root.attr('paddingTop', node.attr('paddingTop'));
29
- root.attr('paddingBottom', node.attr('paddingBottom'));
30
- root.attr('paddingRight', node.attr('paddingRight'));
31
- root.attr('insetLeft', node.attr('insetLeft'));
32
- root.attr('insetRight', node.attr('insetRight'));
33
- root.attr('insetBottom', node.attr('insetBottom'));
34
- root.attr('insetTop', node.attr('insetTop'));
35
- root.attr('marginLeft', node.attr('marginLeft'));
36
- root.attr('marginBottom', node.attr('marginBottom'));
37
- root.attr('marginTop', node.attr('marginTop'));
38
- root.attr('marginRight', node.attr('marginRight'));
39
- root.attr('autoFit', node.attr('autoFit'));
40
- root.attr('padding', node.attr('padding'));
41
- root.attr('margin', node.attr('margin'));
42
- root.attr('inset', node.attr('inset'));
43
- root.attr('theme', node.attr('theme'));
53
+ for (const key of VIEW_KEYS) root.attr(key, node.attr(key));
44
54
  return root;
45
55
  }
46
56
 
@@ -66,7 +76,8 @@ export function optionsOf(node: Node): Record<string, any> {
66
76
  while (discovered.length) {
67
77
  const node = discovered.pop();
68
78
  const value = nodeValue.get(node);
69
- for (const child of node.children) {
79
+ const { children = [] } = node;
80
+ for (const child of children) {
70
81
  const childValue = valueOf(child);
71
82
  const { children = [] } = value;
72
83
  children.push(childValue);
@@ -77,3 +88,111 @@ export function optionsOf(node: Node): Record<string, any> {
77
88
  }
78
89
  return nodeValue.get(root);
79
90
  }
91
+
92
+ function isMark(type: string): boolean {
93
+ return new Set(Object.keys(mark)).has(type);
94
+ }
95
+
96
+ function normalizeRootOptions(node: Node, options: G2ViewTree) {
97
+ const { type: oldType } = node;
98
+ const { type = oldType } = options;
99
+ if (type === 'view') return options;
100
+ if (typeof type !== 'string') return options;
101
+ if (!isMark(type)) return options;
102
+ const view = { type: 'view' };
103
+ const mark = { ...options };
104
+ for (const key of VIEW_KEYS) {
105
+ if (mark[key] !== undefined) {
106
+ view[key] = mark[key];
107
+ delete mark[key];
108
+ }
109
+ }
110
+ return { ...view, children: [mark] };
111
+ }
112
+
113
+ function typeCtor(type: string): new () => Node {
114
+ const node = { ...mark, ...composition };
115
+ const ctor = node[type];
116
+ if (!ctor) throw new Error(`Unknown mark: ${type}.`);
117
+ return ctor;
118
+ }
119
+
120
+ // Create node from options.
121
+ function createNode(options: G2ViewTree): Node {
122
+ const { type, children, ...value } = options;
123
+ if (typeof type !== 'string') return;
124
+ const Ctor = typeCtor(type);
125
+ const node = new Ctor();
126
+ node.value = value;
127
+ return node;
128
+ }
129
+
130
+ // Update node by options.
131
+ function updateNode(node: Node, newOptions: G2ViewTree) {
132
+ const { type, children, ...value } = newOptions;
133
+ if (node.type === type || type === undefined) {
134
+ // Update node.
135
+ node.value = deepMix(node.value, value);
136
+ } else if (typeof type === 'string') {
137
+ // Transform node.
138
+ node.type = type;
139
+ node.value = value;
140
+ }
141
+ }
142
+
143
+ // Create a nested node tree from newOptions, and append it to the parent.
144
+ function appendNode(parent: Node, newOptions: G2ViewTree) {
145
+ if (!parent) return;
146
+ const discovered = [[parent, newOptions]];
147
+ while (discovered.length) {
148
+ const [parent, nodeOptions] = discovered.shift();
149
+ const node = createNode(nodeOptions);
150
+ if (Array.isArray(parent.children)) parent.children.push(node);
151
+ const { children } = nodeOptions;
152
+ if (Array.isArray(children)) {
153
+ for (const child of children) {
154
+ discovered.push([node, child]);
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+ // Update node tree from options.
161
+ export function updateRoot(node: Node, options: G2ViewTree) {
162
+ const rootOptions = normalizeRootOptions(node, options);
163
+ const discovered: [Node, Node, G2ViewTree][] = [[null, node, rootOptions]];
164
+ while (discovered.length) {
165
+ const [parent, oldNode, newNode] = discovered.shift();
166
+ // If there is no oldNode, create a node tree directly.
167
+ if (!oldNode) {
168
+ appendNode(parent, newNode);
169
+ } else {
170
+ updateNode(oldNode, newNode);
171
+ const { children: newChildren } = newNode;
172
+ const { children: oldChildren } = oldNode;
173
+ if (Array.isArray(newChildren) && Array.isArray(oldChildren)) {
174
+ // Only update node specified in newChildren,
175
+ // the extra oldChildren will remain still.
176
+ for (let i = 0; i < newChildren.length; i++) {
177
+ const newChild = newChildren[i];
178
+ const oldChild = oldChildren[i];
179
+ discovered.push([oldNode, oldChild, newChild]);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ export function createEmptyPromise<T>(): [
187
+ Promise<T>,
188
+ (reason?: any) => void,
189
+ (value: T | PromiseLike<T>) => void,
190
+ ] {
191
+ let reject: (reason?: any) => void;
192
+ let resolve: (value: T | PromiseLike<T>) => void;
193
+ const cloned = new Promise<T>((res, rej) => {
194
+ resolve = res;
195
+ reject = rej;
196
+ });
197
+ return [cloned, resolve, reject];
198
+ }
@@ -148,7 +148,12 @@ function getData(
148
148
 
149
149
  const ticks = ticksOf(scale, domain, tickMethod);
150
150
  const filteredTicks = tickFilter ? ticks.filter(tickFilter) : ticks;
151
- const toString = (d) => (typeof d === 'object' && !!d ? d : String(d));
151
+ const toString = (d) =>
152
+ d instanceof Date
153
+ ? String(d)
154
+ : typeof d === 'object' && !!d
155
+ ? d
156
+ : String(d);
152
157
  const labelFormatter =
153
158
  defaultTickFormatter || scale.getFormatter?.() || toString;
154
159
  const applyInset = createInset(position, coordinate);
@@ -266,7 +271,7 @@ function inferArcStyle(
266
271
  ...common,
267
272
  labelAlign: 'parallel',
268
273
  labelDirection: 'negative',
269
- labelSpacing: 8,
274
+ labelSpacing: 4,
270
275
  tickDirection: 'negative',
271
276
  gridDirection: 'positive',
272
277
  };
@@ -397,6 +402,7 @@ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
397
402
  );
398
403
 
399
404
  const { axis: axisTheme } = theme;
405
+
400
406
  return new AxisComponent({
401
407
  style: adaptor(
402
408
  deepMix({}, axisTheme, defaultStyle, {
@@ -507,19 +513,34 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
507
513
  bbox,
508
514
  coordinate,
509
515
  );
516
+
517
+ const data = getData(
518
+ scale,
519
+ domain,
520
+ tickCount,
521
+ labelFormatter,
522
+ tickFilter,
523
+ tickMethod,
524
+ position,
525
+ coordinate,
526
+ );
527
+
528
+ // Bind computed bbox if exists.
529
+ const labels = indexBBox
530
+ ? data.map((d, i) => {
531
+ const bbox = indexBBox.get(i);
532
+ if (!bbox) return d;
533
+ // bbox: [label, bbox]
534
+ // Make than indexBBox can match current label.
535
+ if (bbox[0] !== d.label) return d;
536
+ return { ...d, bbox: bbox[1] };
537
+ })
538
+ : data;
539
+
510
540
  const finalAxisStyle = {
511
541
  ...internalAxisStyle,
512
542
  type: 'linear' as const,
513
- data: getData(
514
- scale,
515
- domain,
516
- tickCount,
517
- labelFormatter,
518
- tickFilter,
519
- tickMethod,
520
- position,
521
- coordinate,
522
- ),
543
+ data: labels,
523
544
  crossSize: size,
524
545
  titleText: titleContent(title),
525
546
  labelOverlap: inferLabelOverlap(transform, internalAxisStyle),
@@ -158,11 +158,16 @@ export function adaptor<T>(style: T) {
158
158
  'title',
159
159
  'trunc',
160
160
  ];
161
+ // @ts-ignore
162
+ const { style: styles, ...rest } = style;
161
163
  const finalStyle = {};
162
- Object.entries(style).forEach(([key, value]) => {
163
- if (reservedKeys.includes(key))
164
+ Object.entries(rest).forEach(([key, value]) => {
165
+ if (reservedKeys.includes(key)) {
164
166
  finalStyle[`show${upperFirst(key)}`] = value;
165
- else finalStyle[key] = value;
167
+ } else finalStyle[key] = value;
166
168
  });
167
- return finalStyle as T;
169
+ return {
170
+ ...finalStyle,
171
+ ...styles,
172
+ };
168
173
  }
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import { runtime } from '@antv/g';
2
+
3
+ runtime.enableCSSParsing = false;
4
+
1
5
  export {
2
6
  render,
3
7
  renderToMountedElement,
@@ -10,8 +14,13 @@ export {
10
14
  LABEL_CLASS_NAME,
11
15
  AREA_CLASS_NAME,
12
16
  } from './runtime';
17
+
13
18
  export type { G2Context } from './runtime';
19
+
14
20
  export { createLibrary } from './stdlib';
21
+
15
22
  export { Chart, MarkNode, CompositionNode, register } from './api';
16
- export * from './spec';
23
+
17
24
  export { ChartEvent } from './utils/event';
25
+
26
+ export * from './spec';
@@ -315,7 +315,7 @@ export function brush(
315
315
  };
316
316
 
317
317
  // Update mask and invoke brushended callback.
318
- const updateMask = (start, end) => {
318
+ const updateMask = (start, end, emit = true) => {
319
319
  const [x, y, x1, y1] = normalizeBounds(
320
320
  start[0],
321
321
  start[1],
@@ -326,7 +326,7 @@ export function brush(
326
326
  const [fx, fy, fx1, fy1] = brushRegion(x, y, x1, y1, extent);
327
327
  if (reverse) updateReverseMask(fx, fy, fx1, fy1);
328
328
  else updateNormalMask(fx, fy, fx1, fy1);
329
- brushed(fx, fy, fx1, fy1);
329
+ brushed(fx, fy, fx1, fy1, emit);
330
330
  return [fx, fy, fx1, fy1];
331
331
  };
332
332
 
@@ -470,11 +470,11 @@ export function brush(
470
470
 
471
471
  return {
472
472
  mask,
473
- move(x, y, x1, y1) {
473
+ move(x, y, x1, y1, emit = true) {
474
474
  if (!mask) initMask(x, y);
475
475
  start = [x, y];
476
476
  end = [x1, y1];
477
- updateMask([x, y], [x1, y1]);
477
+ updateMask([x, y], [x1, y1], emit);
478
478
  },
479
479
  remove() {
480
480
  if (mask) removeMask();
@@ -632,12 +632,14 @@ export function brushHighlight(
632
632
  emitter.emit('brush:end', { nativeEvent: true });
633
633
  handler();
634
634
  },
635
- brushed: (x, y, x1, y1) => {
635
+ brushed: (x, y, x1, y1, emit) => {
636
636
  const selection = selectionOf(x, y, x1, y1, scale, coordinate);
637
- emitter.emit('brush:highlight', {
638
- nativeEvent: true,
639
- data: { selection },
640
- });
637
+ if (emit) {
638
+ emitter.emit('brush:highlight', {
639
+ nativeEvent: true,
640
+ data: { selection },
641
+ });
642
+ }
641
643
  const handler = series ? seriesBrushed : brushed;
642
644
  handler(x, y, x1, y1);
643
645
  },
@@ -648,7 +650,7 @@ export function brushHighlight(
648
650
  if (nativeEvent) return;
649
651
  const { selection } = data;
650
652
  const [x, y, x1, y1] = pixelsOf(selection, scale, coordinate);
651
- brushHandler.move(x, y, x1, y1);
653
+ brushHandler.move(x, y, x1, y1, false);
652
654
  };
653
655
  emitter.on('brush:highlight', onHighlight);
654
656
 
@@ -75,9 +75,12 @@ function createTooltip(
75
75
  enterable,
76
76
  title: '',
77
77
  offset: [10, 10],
78
+ template: {
79
+ prefixCls: 'g2-',
80
+ },
78
81
  style: {
79
- '.tooltip': {},
80
- '.tooltip-title': {
82
+ '.g2-tooltip': {},
83
+ '.g2-tooltip-title': {
81
84
  overflow: 'hidden',
82
85
  'white-space': 'nowrap',
83
86
  'text-overflow': 'ellipsis',