@antv/g2 5.0.15 → 5.0.16

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.
@@ -14,6 +14,14 @@ export function dataOf(element, view) {
14
14
  return selectedMark.data[index];
15
15
  }
16
16
 
17
+ // For extended shape.
18
+ function maybeElementRoot(node) {
19
+ if (node.className === 'element') return node;
20
+ let root = node.parent;
21
+ while (root && root.className !== 'element') root = root.parent;
22
+ return root;
23
+ }
24
+
17
25
  function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
18
26
  return (e) => {
19
27
  if (!predicate(e)) return;
@@ -26,17 +34,20 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
26
34
  // There is no target for pointerupoutside event if out of canvas.
27
35
  if (!target) return;
28
36
 
29
- const { className: elementType, markType } = target;
37
+ const { className } = target;
30
38
 
31
39
  // If target area is plot area, do not emit extra events.
32
- if (elementType === 'plot') return;
40
+ if (className === 'plot') return;
33
41
 
34
- // Emit wrapped events.
42
+ // If target is element or child of element.
43
+ const elementRoot = maybeElementRoot(target);
44
+ if (!elementRoot) return;
45
+ const { className: elementType, markType } = elementRoot;
35
46
  if (elementType === 'element') {
36
47
  const e1 = {
37
48
  ...e,
38
49
  nativeEvent: true,
39
- data: { data: dataOf(target, view) },
50
+ data: { data: dataOf(elementRoot, view) },
40
51
  };
41
52
  emitter.emit(`element:${eventType}`, e1);
42
53
  emitter.emit(`${markType}:${eventType}`, e1);
@@ -38,6 +38,7 @@ import { documentOf, useLibrary } from './library';
38
38
  import { initializeMark } from './mark';
39
39
  import {
40
40
  applyScale,
41
+ assignScale,
41
42
  collectScales,
42
43
  inferScale,
43
44
  syncFacetsScales,
@@ -535,6 +536,7 @@ async function initializeMarks(
535
536
  (total, { scale }) => deepMix(total, scale),
536
537
  {},
537
538
  );
539
+ const { scaleKey } = channels[0];
538
540
 
539
541
  // Use the fields of the first channel as the title.
540
542
  const { values: FV } = channels[0];
@@ -550,14 +552,10 @@ async function initializeMarks(
550
552
  // Use the name of the first channel as the scale name.
551
553
  const { name } = channels[0];
552
554
  const values = channels.flatMap(({ values }) => values.map((d) => d.value));
553
- const scale = inferScale(
554
- name,
555
- values,
556
- options,
557
- coordinates,
558
- theme,
559
- library,
560
- );
555
+ const scale = {
556
+ ...inferScale(name, values, options, coordinates, theme, library),
557
+ key: scaleKey,
558
+ };
561
559
  channels.forEach((channel) => (channel.scale = scale));
562
560
  }
563
561
 
@@ -622,7 +620,7 @@ function initializeState(
622
620
  const { name } = descriptor;
623
621
  const scale = useRelationScale(descriptor, library);
624
622
  scales.push(scale);
625
- scaleInstance[name] = scale;
623
+ assignScale(scaleInstance, { [name]: scale });
626
624
  }
627
625
  component.scaleInstances = scales;
628
626
  }
@@ -651,7 +649,7 @@ function initializeState(
651
649
  const markScaleInstance = mapObject(scale, (options) => {
652
650
  return useRelationScale(options, library);
653
651
  });
654
- Object.assign(scaleInstance, markScaleInstance);
652
+ assignScale(scaleInstance, markScaleInstance);
655
653
  const value = applyScale(channels, markScaleInstance);
656
654
 
657
655
  // Calc points and transformation for each data,
@@ -920,16 +918,23 @@ async function plotView(
920
918
  const [x, y] = node.getBounds().min;
921
919
  return [x, y];
922
920
  });
923
- update.transition(function (data, index) {
924
- maybeFacetElement(this, parent, origin);
925
- const node = shapeFunction(data, index);
926
- const animation = updateFunction(data, [this], [node]);
927
- if (animation === null) {
921
+ selection
922
+ .transition(function (data, index) {
923
+ maybeFacetElement(this, parent, origin);
924
+ const node = shapeFunction(data, index);
925
+ const animation = updateFunction(data, [this], [node]);
926
+ if (animation !== null) return animation;
928
927
  if (this.nodeName === node.nodeName) copyAttributes(this, node);
929
- else this.parentNode.replaceChild(node, this);
930
- }
931
- return animation;
932
- });
928
+ else {
929
+ this.parentNode.replaceChild(node, this);
930
+ node.className = ELEMENT_CLASS_NAME;
931
+ // @ts-ignore
932
+ node.markType = type;
933
+ }
934
+ return animation;
935
+ })
936
+ .attr('markType', type)
937
+ .attr('className', ELEMENT_CLASS_NAME);
933
938
  }),
934
939
  (exit) => {
935
940
  return exit
@@ -1,5 +1,5 @@
1
1
  import { Linear, createInterpolateValue } from '@antv/scale';
2
- import { extent } from 'd3-array';
2
+ import { extent, max } from 'd3-array';
3
3
  import * as d3ScaleChromatic from 'd3-scale-chromatic';
4
4
  import { deepMix, omit, upperFirst } from '@antv/util';
5
5
  import { firstOf, lastOf, unique } from '../utils/array';
@@ -161,6 +161,33 @@ export function useRelation(
161
161
  return [conditionalize, deconditionalize];
162
162
  }
163
163
 
164
+ export function assignScale(
165
+ target: Record<string, Scale>,
166
+ source: Record<string, Scale>,
167
+ ): Record<string, Scale> {
168
+ const keys = Object.keys(target);
169
+ for (const scale of Object.values(source)) {
170
+ const { name, key } = scale.getOptions();
171
+ if (typeof key === 'string') {
172
+ if (!(key in target)) target[key] = scale;
173
+ } else {
174
+ // For scale.key = Symbol('independent')
175
+ if (!(name in target)) target[name] = scale;
176
+ else {
177
+ const I = keys
178
+ .filter((d) => d.startsWith(name))
179
+ // Reg is for extract `1` from `x1`;
180
+ .map((d) => +(d.replace(name, '') || 0));
181
+ const index = max(I) + 1;
182
+ const newKey = `${name}${index}`;
183
+ target[newKey] = scale;
184
+ scale.getOptions().key = newKey;
185
+ }
186
+ }
187
+ }
188
+ return target;
189
+ }
190
+
164
191
  export function useRelationScale(
165
192
  options: Record<string, any>,
166
193
  library: G2Library,