@antv/g2 5.3.3-beta.0 → 5.3.3

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 (145) hide show
  1. package/dist/g2.lite.min.js +30 -22
  2. package/dist/g2.min.js +30 -22
  3. package/esm/api/runtime.d.ts +10 -0
  4. package/esm/api/runtime.js +63 -3
  5. package/esm/api/runtime.js.map +1 -1
  6. package/esm/data/utils/venn/fmin/bisect.d.ts +3 -0
  7. package/esm/data/utils/venn/fmin/bisect.js +30 -0
  8. package/esm/data/utils/venn/fmin/bisect.js.map +1 -0
  9. package/esm/data/utils/venn/fmin/blas1.d.ts +7 -0
  10. package/esm/data/utils/venn/fmin/blas1.js +38 -0
  11. package/esm/data/utils/venn/fmin/blas1.js.map +1 -0
  12. package/esm/data/utils/venn/fmin/conjugateGradient.d.ts +6 -0
  13. package/esm/data/utils/venn/fmin/conjugateGradient.js +91 -0
  14. package/esm/data/utils/venn/fmin/conjugateGradient.js.map +1 -0
  15. package/esm/data/utils/venn/fmin/gradientDescent.d.ts +10 -0
  16. package/esm/data/utils/venn/fmin/gradientDescent.js +66 -0
  17. package/esm/data/utils/venn/fmin/gradientDescent.js.map +1 -0
  18. package/esm/data/utils/venn/fmin/index.d.ts +34 -0
  19. package/esm/data/utils/venn/fmin/index.js +35 -0
  20. package/esm/data/utils/venn/fmin/index.js.map +1 -0
  21. package/esm/data/utils/venn/fmin/linesearch.d.ts +1 -0
  22. package/esm/data/utils/venn/fmin/linesearch.js +60 -0
  23. package/esm/data/utils/venn/fmin/linesearch.js.map +1 -0
  24. package/esm/data/utils/venn/fmin/nelderMead.d.ts +5 -0
  25. package/esm/data/utils/venn/fmin/nelderMead.js +133 -0
  26. package/esm/data/utils/venn/fmin/nelderMead.js.map +1 -0
  27. package/esm/data/utils/venn/layout.d.ts +2 -2
  28. package/esm/data/utils/venn/layout.js +1 -1
  29. package/esm/data/utils/venn/layout.js.map +1 -1
  30. package/esm/index.d.ts +2 -2
  31. package/esm/index.js +2 -2
  32. package/esm/index.js.map +1 -1
  33. package/esm/interaction/elementSelect.js +32 -2
  34. package/esm/interaction/elementSelect.js.map +1 -1
  35. package/esm/interaction/tooltip.d.ts +57 -0
  36. package/esm/interaction/tooltip.js +142 -82
  37. package/esm/interaction/tooltip.js.map +1 -1
  38. package/esm/interaction/utils.d.ts +2 -2
  39. package/esm/interaction/utils.js +10 -2
  40. package/esm/interaction/utils.js.map +1 -1
  41. package/esm/mark/line.js +4 -1
  42. package/esm/mark/line.js.map +1 -1
  43. package/esm/runtime/component.js +5 -2
  44. package/esm/runtime/component.js.map +1 -1
  45. package/esm/runtime/plot.js +6 -3
  46. package/esm/runtime/plot.js.map +1 -1
  47. package/esm/runtime/types/common.d.ts +1 -0
  48. package/esm/shape/connector/connector.js +19 -15
  49. package/esm/shape/connector/connector.js.map +1 -1
  50. package/esm/spec/transform.d.ts +1 -0
  51. package/esm/theme/create.d.ts +0 -1
  52. package/esm/theme/create.js +0 -1
  53. package/esm/theme/create.js.map +1 -1
  54. package/esm/transform/group.d.ts +0 -1
  55. package/esm/transform/group.js.map +1 -1
  56. package/esm/transform/groupN.d.ts +1 -1
  57. package/esm/utils/style.js +11 -2
  58. package/esm/utils/style.js.map +1 -1
  59. package/esm/utils/traverse-elements.d.ts +2 -0
  60. package/esm/utils/traverse-elements.js +13 -0
  61. package/esm/utils/traverse-elements.js.map +1 -0
  62. package/lib/api/runtime.d.ts +10 -0
  63. package/lib/api/runtime.js +70 -10
  64. package/lib/api/runtime.js.map +1 -1
  65. package/lib/data/utils/venn/fmin/bisect.d.ts +3 -0
  66. package/lib/data/utils/venn/fmin/bisect.js +34 -0
  67. package/lib/data/utils/venn/fmin/bisect.js.map +1 -0
  68. package/lib/data/utils/venn/fmin/blas1.d.ts +7 -0
  69. package/lib/data/utils/venn/fmin/blas1.js +48 -0
  70. package/lib/data/utils/venn/fmin/blas1.js.map +1 -0
  71. package/lib/data/utils/venn/fmin/conjugateGradient.d.ts +6 -0
  72. package/lib/data/utils/venn/fmin/conjugateGradient.js +96 -0
  73. package/lib/data/utils/venn/fmin/conjugateGradient.js.map +1 -0
  74. package/lib/data/utils/venn/fmin/gradientDescent.d.ts +10 -0
  75. package/lib/data/utils/venn/fmin/gradientDescent.js +71 -0
  76. package/lib/data/utils/venn/fmin/gradientDescent.js.map +1 -0
  77. package/lib/data/utils/venn/fmin/index.d.ts +34 -0
  78. package/lib/data/utils/venn/fmin/index.js +49 -0
  79. package/lib/data/utils/venn/fmin/index.js.map +1 -0
  80. package/lib/data/utils/venn/fmin/linesearch.d.ts +1 -0
  81. package/lib/data/utils/venn/fmin/linesearch.js +64 -0
  82. package/lib/data/utils/venn/fmin/linesearch.js.map +1 -0
  83. package/lib/data/utils/venn/fmin/nelderMead.d.ts +5 -0
  84. package/lib/data/utils/venn/fmin/nelderMead.js +137 -0
  85. package/lib/data/utils/venn/fmin/nelderMead.js.map +1 -0
  86. package/lib/data/utils/venn/layout.d.ts +2 -2
  87. package/lib/data/utils/venn/layout.js +1 -1
  88. package/lib/data/utils/venn/layout.js.map +1 -1
  89. package/lib/index.d.ts +2 -2
  90. package/lib/index.js +2 -1
  91. package/lib/index.js.map +1 -1
  92. package/lib/interaction/elementSelect.js +32 -2
  93. package/lib/interaction/elementSelect.js.map +1 -1
  94. package/lib/interaction/tooltip.d.ts +57 -0
  95. package/lib/interaction/tooltip.js +145 -82
  96. package/lib/interaction/tooltip.js.map +1 -1
  97. package/lib/interaction/utils.d.ts +2 -2
  98. package/lib/interaction/utils.js +10 -2
  99. package/lib/interaction/utils.js.map +1 -1
  100. package/lib/mark/line.js +3 -0
  101. package/lib/mark/line.js.map +1 -1
  102. package/lib/runtime/component.js +5 -2
  103. package/lib/runtime/component.js.map +1 -1
  104. package/lib/runtime/plot.js +6 -3
  105. package/lib/runtime/plot.js.map +1 -1
  106. package/lib/runtime/types/common.d.ts +1 -0
  107. package/lib/shape/connector/connector.js +19 -15
  108. package/lib/shape/connector/connector.js.map +1 -1
  109. package/lib/spec/transform.d.ts +1 -0
  110. package/lib/theme/create.d.ts +0 -1
  111. package/lib/theme/create.js +0 -1
  112. package/lib/theme/create.js.map +1 -1
  113. package/lib/transform/group.d.ts +0 -1
  114. package/lib/transform/group.js.map +1 -1
  115. package/lib/transform/groupN.d.ts +1 -1
  116. package/lib/utils/style.js +11 -2
  117. package/lib/utils/style.js.map +1 -1
  118. package/lib/utils/traverse-elements.d.ts +2 -0
  119. package/lib/utils/traverse-elements.js +17 -0
  120. package/lib/utils/traverse-elements.js.map +1 -0
  121. package/package.json +3 -3
  122. package/src/api/runtime.ts +107 -3
  123. package/src/data/utils/venn/fmin/bisect.ts +32 -0
  124. package/src/data/utils/venn/fmin/blas1.ts +42 -0
  125. package/src/data/utils/venn/fmin/conjugateGradient.ts +106 -0
  126. package/src/data/utils/venn/fmin/gradientDescent.ts +75 -0
  127. package/src/data/utils/venn/fmin/index.ts +35 -0
  128. package/src/data/utils/venn/fmin/linesearch.ts +70 -0
  129. package/src/data/utils/venn/fmin/nelderMead.ts +147 -0
  130. package/src/data/utils/venn/layout.ts +1 -1
  131. package/src/index.ts +2 -2
  132. package/src/interaction/elementSelect.ts +32 -3
  133. package/src/interaction/tooltip.ts +213 -132
  134. package/src/interaction/utils.ts +12 -5
  135. package/src/mark/line.ts +3 -1
  136. package/src/runtime/component.ts +5 -3
  137. package/src/runtime/plot.ts +6 -1
  138. package/src/runtime/types/common.ts +1 -0
  139. package/src/shape/connector/connector.ts +30 -19
  140. package/src/spec/transform.ts +1 -0
  141. package/src/theme/create.ts +0 -1
  142. package/src/transform/group.ts +0 -1
  143. package/src/transform/groupN.ts +1 -1
  144. package/src/utils/style.ts +11 -1
  145. package/src/utils/traverse-elements.ts +16 -0
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright 2016, Ben Frederickson
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ *
8
+ * * Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ *
11
+ * * Redistributions in binary form must reproduce the above copyright notice,
12
+ * this list of conditions and the following disclaimer in the documentation
13
+ * and/or other materials provided with the distribution.
14
+ *
15
+ * * Neither the name of the author nor the names of contributors may be used to
16
+ * endorse or promote products derived from this software without specific prior
17
+ * written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+ export { bisect } from './bisect';
32
+ export { nelderMead } from './nelderMead';
33
+ export { conjugateGradient, conjugateGradientSolve } from './conjugateGradient';
34
+ export { gradientDescent, gradientDescentLineSearch } from './gradientDescent';
35
+ export { zeros, zerosM, norm2, weightedSum, scale } from './blas1';
@@ -0,0 +1,70 @@
1
+ import { dot, weightedSum } from './blas1';
2
+
3
+ /// searches along line 'pk' for a point that satifies the wolfe conditions
4
+ /// See 'Numerical Optimization' by Nocedal and Wright p59-60
5
+ /// f : objective function
6
+ /// pk : search direction
7
+ /// current: object containing current gradient/loss
8
+ /// next: output: contains next gradient/loss
9
+ /// returns a: step size taken
10
+ export function wolfeLineSearch(f, pk, current, next, a, c1?: any, c2?: any) {
11
+ const phi0 = current.fx;
12
+ const phiPrime0 = dot(current.fxprime, pk);
13
+ let phi = phi0;
14
+ let phi_old = phi0;
15
+ let phiPrime = phiPrime0;
16
+ let a0 = 0;
17
+
18
+ a = a || 1;
19
+ c1 = c1 || 1e-6;
20
+ c2 = c2 || 0.1;
21
+
22
+ function zoom(a_lo, a_high, phi_lo) {
23
+ for (let iteration = 0; iteration < 16; ++iteration) {
24
+ a = (a_lo + a_high) / 2;
25
+ weightedSum(next.x, 1.0, current.x, a, pk);
26
+ phi = next.fx = f(next.x, next.fxprime);
27
+ phiPrime = dot(next.fxprime, pk);
28
+
29
+ if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {
30
+ a_high = a;
31
+ } else {
32
+ if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
33
+ return a;
34
+ }
35
+
36
+ if (phiPrime * (a_high - a_lo) >= 0) {
37
+ a_high = a_lo;
38
+ }
39
+
40
+ a_lo = a;
41
+ phi_lo = phi;
42
+ }
43
+ }
44
+
45
+ return 0;
46
+ }
47
+
48
+ for (let iteration = 0; iteration < 10; ++iteration) {
49
+ weightedSum(next.x, 1.0, current.x, a, pk);
50
+ phi = next.fx = f(next.x, next.fxprime);
51
+ phiPrime = dot(next.fxprime, pk);
52
+ if (phi > phi0 + c1 * a * phiPrime0 || (iteration && phi >= phi_old)) {
53
+ return zoom(a0, a, phi_old);
54
+ }
55
+
56
+ if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
57
+ return a;
58
+ }
59
+
60
+ if (phiPrime >= 0) {
61
+ return zoom(a, a0, phi);
62
+ }
63
+
64
+ phi_old = phi;
65
+ a0 = a;
66
+ a *= 2;
67
+ }
68
+
69
+ return a;
70
+ }
@@ -0,0 +1,147 @@
1
+ import { dot, norm2, weightedSum } from './blas1';
2
+
3
+ /** minimizes a function using the downhill simplex method */
4
+ export function nelderMead(f, x0, parameters?: any) {
5
+ parameters = parameters || {};
6
+
7
+ const maxIterations = parameters.maxIterations || x0.length * 200;
8
+ const nonZeroDelta = parameters.nonZeroDelta || 1.05;
9
+ const zeroDelta = parameters.zeroDelta || 0.001;
10
+ const minErrorDelta = parameters.minErrorDelta || 1e-6;
11
+ const minTolerance = parameters.minErrorDelta || 1e-5;
12
+ const rho = parameters.rho !== undefined ? parameters.rho : 1;
13
+ const chi = parameters.chi !== undefined ? parameters.chi : 2;
14
+ const psi = parameters.psi !== undefined ? parameters.psi : -0.5;
15
+ const sigma = parameters.sigma !== undefined ? parameters.sigma : 0.5;
16
+ let maxDiff;
17
+
18
+ // initialize simplex.
19
+ const N = x0.length;
20
+ const simplex = new Array(N + 1);
21
+ simplex[0] = x0;
22
+ simplex[0].fx = f(x0);
23
+ simplex[0].id = 0;
24
+ for (let i = 0; i < N; ++i) {
25
+ const point = x0.slice();
26
+ point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;
27
+ simplex[i + 1] = point;
28
+ simplex[i + 1].fx = f(point);
29
+ simplex[i + 1].id = i + 1;
30
+ }
31
+
32
+ function updateSimplex(value) {
33
+ for (let i = 0; i < value.length; i++) {
34
+ simplex[N][i] = value[i];
35
+ }
36
+ simplex[N].fx = value.fx;
37
+ }
38
+
39
+ const sortOrder = (a, b) => a.fx - b.fx;
40
+
41
+ const centroid = x0.slice();
42
+ const reflected = x0.slice();
43
+ const contracted = x0.slice();
44
+ const expanded = x0.slice();
45
+
46
+ for (let iteration = 0; iteration < maxIterations; ++iteration) {
47
+ simplex.sort(sortOrder);
48
+
49
+ if (parameters.history) {
50
+ // copy the simplex (since later iterations will mutate) and
51
+ // sort it to have a consistent order between iterations
52
+ const sortedSimplex = simplex.map((x) => {
53
+ const state = x.slice();
54
+ state.fx = x.fx;
55
+ state.id = x.id;
56
+ return state;
57
+ });
58
+ sortedSimplex.sort((a, b) => a.id - b.id);
59
+
60
+ parameters.history.push({
61
+ x: simplex[0].slice(),
62
+ fx: simplex[0].fx,
63
+ simplex: sortedSimplex,
64
+ });
65
+ }
66
+
67
+ maxDiff = 0;
68
+ for (let i = 0; i < N; ++i) {
69
+ maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
70
+ }
71
+
72
+ if (
73
+ Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta &&
74
+ maxDiff < minTolerance
75
+ ) {
76
+ break;
77
+ }
78
+
79
+ // compute the centroid of all but the worst point in the simplex
80
+ for (let i = 0; i < N; ++i) {
81
+ centroid[i] = 0;
82
+ for (let j = 0; j < N; ++j) {
83
+ centroid[i] += simplex[j][i];
84
+ }
85
+ centroid[i] /= N;
86
+ }
87
+
88
+ // reflect the worst point past the centroid and compute loss at reflected
89
+ // point
90
+ const worst = simplex[N];
91
+ weightedSum(reflected, 1 + rho, centroid, -rho, worst);
92
+ reflected.fx = f(reflected);
93
+
94
+ // if the reflected point is the best seen, then possibly expand
95
+ if (reflected.fx < simplex[0].fx) {
96
+ weightedSum(expanded, 1 + chi, centroid, -chi, worst);
97
+ expanded.fx = f(expanded);
98
+ if (expanded.fx < reflected.fx) {
99
+ updateSimplex(expanded);
100
+ } else {
101
+ updateSimplex(reflected);
102
+ }
103
+ }
104
+
105
+ // if the reflected point is worse than the second worst, we need to
106
+ // contract
107
+ else if (reflected.fx >= simplex[N - 1].fx) {
108
+ let shouldReduce = false;
109
+
110
+ if (reflected.fx > worst.fx) {
111
+ // do an inside contraction
112
+ weightedSum(contracted, 1 + psi, centroid, -psi, worst);
113
+ contracted.fx = f(contracted);
114
+ if (contracted.fx < worst.fx) {
115
+ updateSimplex(contracted);
116
+ } else {
117
+ shouldReduce = true;
118
+ }
119
+ } else {
120
+ // do an outside contraction
121
+ weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);
122
+ contracted.fx = f(contracted);
123
+ if (contracted.fx < reflected.fx) {
124
+ updateSimplex(contracted);
125
+ } else {
126
+ shouldReduce = true;
127
+ }
128
+ }
129
+
130
+ if (shouldReduce) {
131
+ // if we don't contract here, we're done
132
+ if (sigma >= 1) break;
133
+
134
+ // do a reduction
135
+ for (let i = 1; i < simplex.length; ++i) {
136
+ weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);
137
+ simplex[i].fx = f(simplex[i]);
138
+ }
139
+ }
140
+ } else {
141
+ updateSimplex(reflected);
142
+ }
143
+ }
144
+
145
+ simplex.sort(sortOrder);
146
+ return { fx: simplex[0].fx, x: simplex[0] };
147
+ }
@@ -6,7 +6,7 @@ import {
6
6
  scale,
7
7
  zeros,
8
8
  zerosM,
9
- } from 'fmin';
9
+ } from './fmin';
10
10
  import {
11
11
  circleCircleIntersection,
12
12
  circleOverlap,
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { corelib, plotlib, graphlib, geolib, stdlib } from './lib';
1
+ import { litelib, corelib, plotlib, graphlib, geolib, stdlib } from './lib';
2
2
  import { extend, Runtime } from './api';
3
3
  import { API, CompositionAPI } from './api/extend';
4
4
  import { G2Spec } from './spec';
5
5
  import type { SymbolFactor } from './utils/marker';
6
6
 
7
- export { corelib, plotlib, graphlib, geolib, stdlib };
7
+ export { litelib, corelib, plotlib, graphlib, geolib, stdlib };
8
8
 
9
9
  export * from './exports';
10
10
 
@@ -2,6 +2,7 @@ import { DisplayObject } from '@antv/g';
2
2
  import { group } from '@antv/vendor/d3-array';
3
3
  import { deepMix } from '@antv/util';
4
4
  import { subObject } from '../utils/helper';
5
+ import { traverseElements } from '../utils/traverse-elements';
5
6
  import {
6
7
  createValueof,
7
8
  createDatumof,
@@ -41,7 +42,7 @@ export function elementSelect(
41
42
  }: Record<string, any>,
42
43
  ) {
43
44
  const elements = elementsof(root);
44
- const elementSet = new Set(elements);
45
+ const elementSet: Set<DisplayObject> = new Set(elements);
45
46
  const findElement = createFindElementByEvent({
46
47
  elementsof,
47
48
  root,
@@ -183,18 +184,46 @@ export function elementSelect(
183
184
  });
184
185
  };
185
186
 
187
+ const isClickElementOrGroup = (element: DisplayObject): boolean => {
188
+ if (elementSet.has(element)) return true;
189
+
190
+ for (const group of elementSet) {
191
+ const found = traverseElements(group, (el) => el === element);
192
+ if (found) return true;
193
+ }
194
+
195
+ return false;
196
+ };
197
+
198
+ const getRealElement = (element: DisplayObject): DisplayObject => {
199
+ if (elementSet.has(element)) return element;
200
+ for (const group of elementSet) {
201
+ let match: DisplayObject | null = null;
202
+ traverseElements(group, (el) => {
203
+ if (el === element) match = group;
204
+ });
205
+ if (match) return match;
206
+ }
207
+ return element;
208
+ };
209
+
186
210
  const click = (event) => {
187
211
  const { target: element, nativeEvent = true } = event;
188
212
 
189
213
  const select = !isMultiSelectMode ? singleSelect : multipleSelect;
190
214
  let el = element;
191
- const isClickElement = elementSet.has(element);
215
+ const isClickElement = isClickElementOrGroup(element);
192
216
 
193
217
  if (!region || isClickElement) {
194
218
  // Click non-element shape, reset.
195
219
  // Such as the rest of content area(background).
196
220
  if (!isClickElement) return clear();
197
- return select({ event, element: el, nativeEvent, groupBy: groupKey });
221
+ return select({
222
+ event,
223
+ element: getRealElement(el),
224
+ nativeEvent,
225
+ groupBy: groupKey,
226
+ });
198
227
  } else {
199
228
  // Click background region area, select elements in the region.
200
229
  // Get element at cursor.x position.