@antv/g2 5.0.19 → 5.0.21

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 (302) hide show
  1. package/README.md +32 -34
  2. package/README.zh-CN.md +99 -0
  3. package/dist/g2-lite.min.js +4 -4
  4. package/dist/g2.min.js +4 -4
  5. package/esm/api/chart.d.ts +13 -855
  6. package/esm/api/chart.js.map +1 -1
  7. package/esm/api/extend.d.ts +2 -1
  8. package/esm/api/extend.js.map +1 -1
  9. package/esm/api/library.d.ts +1 -0
  10. package/esm/api/runtime.js +2 -2
  11. package/esm/api/runtime.js.map +1 -1
  12. package/esm/api/utils.d.ts +5 -0
  13. package/esm/api/utils.js +3 -2
  14. package/esm/api/utils.js.map +1 -1
  15. package/esm/component/axis.d.ts +11 -1
  16. package/esm/component/axis.js +46 -11
  17. package/esm/component/axis.js.map +1 -1
  18. package/esm/component/axisX.js +7 -4
  19. package/esm/component/axisX.js.map +1 -1
  20. package/esm/component/axisY.js +6 -2
  21. package/esm/component/axisY.js.map +1 -1
  22. package/esm/component/axisZ.d.ts +8 -0
  23. package/esm/component/axisZ.js +14 -0
  24. package/esm/component/axisZ.js.map +1 -0
  25. package/esm/component/index.d.ts +1 -0
  26. package/esm/component/index.js +1 -0
  27. package/esm/component/index.js.map +1 -1
  28. package/esm/component/scrollbar.d.ts +2 -1
  29. package/esm/component/scrollbar.js +1 -1
  30. package/esm/component/scrollbar.js.map +1 -1
  31. package/esm/composition/mark.js +3 -1
  32. package/esm/composition/mark.js.map +1 -1
  33. package/esm/coordinate/cartesian3D.d.ts +7 -0
  34. package/esm/coordinate/cartesian3D.js +6 -0
  35. package/esm/coordinate/cartesian3D.js.map +1 -0
  36. package/esm/coordinate/index.d.ts +2 -0
  37. package/esm/coordinate/index.js +1 -0
  38. package/esm/coordinate/index.js.map +1 -1
  39. package/esm/data/index.d.ts +2 -0
  40. package/esm/data/index.js +1 -0
  41. package/esm/data/index.js.map +1 -1
  42. package/esm/data/log.d.ts +7 -0
  43. package/esm/data/log.js +11 -0
  44. package/esm/data/log.js.map +1 -0
  45. package/esm/index.d.ts +1 -1
  46. package/esm/index.js +1 -1
  47. package/esm/index.js.map +1 -1
  48. package/esm/interaction/brushFilter.js +18 -16
  49. package/esm/interaction/brushFilter.js.map +1 -1
  50. package/esm/interaction/chartIndex.js +25 -22
  51. package/esm/interaction/chartIndex.js.map +1 -1
  52. package/esm/interaction/event.js +20 -9
  53. package/esm/interaction/event.js.map +1 -1
  54. package/esm/interaction/fisheye.js +17 -13
  55. package/esm/interaction/fisheye.js.map +1 -1
  56. package/esm/interaction/legendFilter.js +32 -26
  57. package/esm/interaction/legendFilter.js.map +1 -1
  58. package/esm/interaction/sliderFilter.js +8 -9
  59. package/esm/interaction/sliderFilter.js.map +1 -1
  60. package/esm/interaction/tooltip.d.ts +1 -1
  61. package/esm/interaction/tooltip.js +39 -4
  62. package/esm/interaction/tooltip.js.map +1 -1
  63. package/esm/lib/core.d.ts +1 -0
  64. package/esm/lib/core.js +2 -1
  65. package/esm/lib/core.js.map +1 -1
  66. package/esm/lib/index.d.ts +1 -0
  67. package/esm/lib/index.js +1 -0
  68. package/esm/lib/index.js.map +1 -1
  69. package/esm/lib/std.d.ts +1 -0
  70. package/esm/lib/threed.d.ts +5 -0
  71. package/esm/lib/threed.js +11 -0
  72. package/esm/lib/threed.js.map +1 -0
  73. package/esm/mark/index.d.ts +1 -0
  74. package/esm/mark/index.js +1 -0
  75. package/esm/mark/index.js.map +1 -1
  76. package/esm/mark/point3D.d.ts +9 -0
  77. package/esm/mark/point3D.js +76 -0
  78. package/esm/mark/point3D.js.map +1 -0
  79. package/esm/mark/utils.d.ts +7 -0
  80. package/esm/mark/utils.js +6 -0
  81. package/esm/mark/utils.js.map +1 -1
  82. package/esm/runtime/component.js +6 -3
  83. package/esm/runtime/component.js.map +1 -1
  84. package/esm/runtime/coordinate.js +9 -4
  85. package/esm/runtime/coordinate.js.map +1 -1
  86. package/esm/runtime/layout.d.ts +1 -0
  87. package/esm/runtime/layout.js +109 -29
  88. package/esm/runtime/layout.js.map +1 -1
  89. package/esm/runtime/plot.js +26 -9
  90. package/esm/runtime/plot.js.map +1 -1
  91. package/esm/runtime/render.js +12 -3
  92. package/esm/runtime/render.js.map +1 -1
  93. package/esm/runtime/types/common.d.ts +4 -0
  94. package/esm/runtime/types/component.d.ts +8 -2
  95. package/esm/runtime/types/options.d.ts +5 -1
  96. package/esm/shape/index.d.ts +2 -0
  97. package/esm/shape/index.js +2 -0
  98. package/esm/shape/index.js.map +1 -1
  99. package/esm/shape/point3D/cube.d.ts +6 -0
  100. package/esm/shape/point3D/cube.js +70 -0
  101. package/esm/shape/point3D/cube.js.map +1 -0
  102. package/esm/shape/point3D/sphere.d.ts +6 -0
  103. package/esm/shape/point3D/sphere.js +70 -0
  104. package/esm/shape/point3D/sphere.js.map +1 -0
  105. package/esm/shape/shape/shape.js +2 -2
  106. package/esm/shape/shape/shape.js.map +1 -1
  107. package/esm/shape/utils.d.ts +2 -2
  108. package/esm/shape/utils.js +2 -2
  109. package/esm/shape/utils.js.map +1 -1
  110. package/esm/spec/component.d.ts +1 -1
  111. package/esm/spec/composition.d.ts +2 -0
  112. package/esm/spec/coordinate.d.ts +5 -2
  113. package/esm/spec/dataTransform.d.ts +3 -2
  114. package/esm/spec/index.d.ts +1 -0
  115. package/esm/spec/index.js.map +1 -1
  116. package/esm/spec/interaction.d.ts +2 -1
  117. package/esm/spec/mark.d.ts +2 -2
  118. package/esm/transform/index.d.ts +1 -0
  119. package/esm/transform/index.js +1 -0
  120. package/esm/transform/index.js.map +1 -1
  121. package/esm/transform/maybeZeroZ.d.ts +6 -0
  122. package/esm/transform/maybeZeroZ.js +22 -0
  123. package/esm/transform/maybeZeroZ.js.map +1 -0
  124. package/esm/utils/size.d.ts +1 -0
  125. package/esm/utils/size.js +1 -0
  126. package/esm/utils/size.js.map +1 -1
  127. package/lib/api/chart.d.ts +13 -855
  128. package/lib/api/chart.js.map +1 -1
  129. package/lib/api/extend.d.ts +2 -1
  130. package/lib/api/extend.js.map +1 -1
  131. package/lib/api/library.d.ts +1 -0
  132. package/lib/api/runtime.js +2 -2
  133. package/lib/api/runtime.js.map +1 -1
  134. package/lib/api/utils.d.ts +5 -0
  135. package/lib/api/utils.js +3 -2
  136. package/lib/api/utils.js.map +1 -1
  137. package/lib/component/axis.d.ts +11 -1
  138. package/lib/component/axis.js +48 -12
  139. package/lib/component/axis.js.map +1 -1
  140. package/lib/component/axisX.js +6 -3
  141. package/lib/component/axisX.js.map +1 -1
  142. package/lib/component/axisY.js +5 -1
  143. package/lib/component/axisY.js.map +1 -1
  144. package/lib/component/axisZ.d.ts +8 -0
  145. package/lib/component/axisZ.js +19 -0
  146. package/lib/component/axisZ.js.map +1 -0
  147. package/lib/component/index.d.ts +1 -0
  148. package/lib/component/index.js +3 -1
  149. package/lib/component/index.js.map +1 -1
  150. package/lib/component/scrollbar.d.ts +2 -1
  151. package/lib/component/scrollbar.js +1 -1
  152. package/lib/component/scrollbar.js.map +1 -1
  153. package/lib/composition/mark.js +3 -1
  154. package/lib/composition/mark.js.map +1 -1
  155. package/lib/coordinate/cartesian3D.d.ts +7 -0
  156. package/lib/coordinate/cartesian3D.js +10 -0
  157. package/lib/coordinate/cartesian3D.js.map +1 -0
  158. package/lib/coordinate/index.d.ts +2 -0
  159. package/lib/coordinate/index.js +3 -1
  160. package/lib/coordinate/index.js.map +1 -1
  161. package/lib/data/index.d.ts +2 -0
  162. package/lib/data/index.js +3 -1
  163. package/lib/data/index.js.map +1 -1
  164. package/lib/data/log.d.ts +7 -0
  165. package/lib/data/log.js +15 -0
  166. package/lib/data/log.js.map +1 -0
  167. package/lib/index.d.ts +1 -1
  168. package/lib/index.js +2 -1
  169. package/lib/index.js.map +1 -1
  170. package/lib/interaction/brushFilter.js +18 -16
  171. package/lib/interaction/brushFilter.js.map +1 -1
  172. package/lib/interaction/chartIndex.js +25 -22
  173. package/lib/interaction/chartIndex.js.map +1 -1
  174. package/lib/interaction/event.js +20 -9
  175. package/lib/interaction/event.js.map +1 -1
  176. package/lib/interaction/fisheye.js +17 -13
  177. package/lib/interaction/fisheye.js.map +1 -1
  178. package/lib/interaction/legendFilter.js +32 -26
  179. package/lib/interaction/legendFilter.js.map +1 -1
  180. package/lib/interaction/sliderFilter.js +8 -9
  181. package/lib/interaction/sliderFilter.js.map +1 -1
  182. package/lib/interaction/tooltip.d.ts +1 -1
  183. package/lib/interaction/tooltip.js +38 -3
  184. package/lib/interaction/tooltip.js.map +1 -1
  185. package/lib/lib/core.d.ts +1 -0
  186. package/lib/lib/core.js +1 -0
  187. package/lib/lib/core.js.map +1 -1
  188. package/lib/lib/index.d.ts +1 -0
  189. package/lib/lib/index.js +3 -1
  190. package/lib/lib/index.js.map +1 -1
  191. package/lib/lib/std.d.ts +1 -0
  192. package/lib/lib/threed.d.ts +5 -0
  193. package/lib/lib/threed.js +15 -0
  194. package/lib/lib/threed.js.map +1 -0
  195. package/lib/mark/index.d.ts +1 -0
  196. package/lib/mark/index.js +3 -1
  197. package/lib/mark/index.js.map +1 -1
  198. package/lib/mark/point3D.d.ts +9 -0
  199. package/lib/mark/point3D.js +80 -0
  200. package/lib/mark/point3D.js.map +1 -0
  201. package/lib/mark/utils.d.ts +7 -0
  202. package/lib/mark/utils.js +8 -1
  203. package/lib/mark/utils.js.map +1 -1
  204. package/lib/runtime/component.js +6 -3
  205. package/lib/runtime/component.js.map +1 -1
  206. package/lib/runtime/coordinate.js +8 -3
  207. package/lib/runtime/coordinate.js.map +1 -1
  208. package/lib/runtime/layout.d.ts +1 -0
  209. package/lib/runtime/layout.js +112 -31
  210. package/lib/runtime/layout.js.map +1 -1
  211. package/lib/runtime/plot.js +25 -8
  212. package/lib/runtime/plot.js.map +1 -1
  213. package/lib/runtime/render.js +12 -3
  214. package/lib/runtime/render.js.map +1 -1
  215. package/lib/runtime/types/common.d.ts +4 -0
  216. package/lib/runtime/types/component.d.ts +8 -2
  217. package/lib/runtime/types/options.d.ts +5 -1
  218. package/lib/shape/index.d.ts +2 -0
  219. package/lib/shape/index.js +6 -2
  220. package/lib/shape/index.js.map +1 -1
  221. package/lib/shape/point3D/cube.d.ts +6 -0
  222. package/lib/shape/point3D/cube.js +74 -0
  223. package/lib/shape/point3D/cube.js.map +1 -0
  224. package/lib/shape/point3D/sphere.d.ts +6 -0
  225. package/lib/shape/point3D/sphere.js +74 -0
  226. package/lib/shape/point3D/sphere.js.map +1 -0
  227. package/lib/shape/shape/shape.js +2 -2
  228. package/lib/shape/shape/shape.js.map +1 -1
  229. package/lib/shape/utils.d.ts +2 -2
  230. package/lib/shape/utils.js +2 -2
  231. package/lib/shape/utils.js.map +1 -1
  232. package/lib/spec/component.d.ts +1 -1
  233. package/lib/spec/composition.d.ts +2 -0
  234. package/lib/spec/coordinate.d.ts +5 -2
  235. package/lib/spec/dataTransform.d.ts +3 -2
  236. package/lib/spec/index.d.ts +1 -0
  237. package/lib/spec/index.js.map +1 -1
  238. package/lib/spec/interaction.d.ts +2 -1
  239. package/lib/spec/mark.d.ts +2 -2
  240. package/lib/transform/index.d.ts +1 -0
  241. package/lib/transform/index.js +3 -1
  242. package/lib/transform/index.js.map +1 -1
  243. package/lib/transform/maybeZeroZ.d.ts +6 -0
  244. package/lib/transform/maybeZeroZ.js +26 -0
  245. package/lib/transform/maybeZeroZ.js.map +1 -0
  246. package/lib/utils/size.d.ts +1 -0
  247. package/lib/utils/size.js +1 -0
  248. package/lib/utils/size.js.map +1 -1
  249. package/package.json +10 -3
  250. package/src/api/chart.ts +3 -3
  251. package/src/api/extend.ts +5 -3
  252. package/src/api/runtime.ts +2 -2
  253. package/src/api/utils.ts +3 -2
  254. package/src/component/axis.ts +65 -9
  255. package/src/component/axisX.ts +8 -3
  256. package/src/component/axisY.ts +8 -3
  257. package/src/component/axisZ.ts +25 -0
  258. package/src/component/index.ts +1 -0
  259. package/src/component/scrollbar.ts +3 -2
  260. package/src/composition/mark.ts +4 -0
  261. package/src/coordinate/cartesian3D.ts +11 -0
  262. package/src/coordinate/index.ts +2 -0
  263. package/src/data/index.ts +2 -0
  264. package/src/data/log.ts +16 -0
  265. package/src/index.ts +1 -1
  266. package/src/interaction/brushFilter.ts +31 -28
  267. package/src/interaction/chartIndex.ts +26 -23
  268. package/src/interaction/event.ts +22 -9
  269. package/src/interaction/fisheye.ts +16 -12
  270. package/src/interaction/legendFilter.ts +45 -40
  271. package/src/interaction/sliderFilter.ts +15 -16
  272. package/src/interaction/tooltip.ts +47 -3
  273. package/src/lib/core.ts +2 -0
  274. package/src/lib/index.ts +1 -0
  275. package/src/lib/threed.ts +11 -0
  276. package/src/mark/index.ts +1 -0
  277. package/src/mark/point3D.ts +90 -0
  278. package/src/mark/utils.ts +7 -0
  279. package/src/runtime/component.ts +6 -0
  280. package/src/runtime/coordinate.ts +18 -10
  281. package/src/runtime/layout.ts +178 -33
  282. package/src/runtime/plot.ts +33 -10
  283. package/src/runtime/render.ts +14 -3
  284. package/src/runtime/types/common.ts +4 -0
  285. package/src/runtime/types/component.ts +10 -1
  286. package/src/runtime/types/options.ts +5 -0
  287. package/src/shape/index.ts +2 -0
  288. package/src/shape/point3D/cube.ts +68 -0
  289. package/src/shape/point3D/sphere.ts +68 -0
  290. package/src/shape/shape/shape.ts +9 -6
  291. package/src/shape/utils.ts +4 -4
  292. package/src/spec/component.ts +1 -1
  293. package/src/spec/composition.ts +2 -0
  294. package/src/spec/coordinate.ts +6 -0
  295. package/src/spec/dataTransform.ts +5 -0
  296. package/src/spec/index.ts +1 -0
  297. package/src/spec/interaction.ts +3 -1
  298. package/src/spec/mark.ts +7 -1
  299. package/src/transform/index.ts +1 -0
  300. package/src/transform/maybeZeroZ.ts +25 -0
  301. package/src/utils/size.ts +2 -0
  302. package/README.en-US.md +0 -99
@@ -11,6 +11,7 @@ export const Mark: CC<MarkOptions> = ({
11
11
  const {
12
12
  width,
13
13
  height,
14
+ depth,
14
15
  paddingLeft,
15
16
  paddingRight,
16
17
  paddingTop,
@@ -33,6 +34,7 @@ export const Mark: CC<MarkOptions> = ({
33
34
  interaction,
34
35
  x,
35
36
  y,
37
+ z,
36
38
  key,
37
39
  frame,
38
40
  labelTransform,
@@ -48,9 +50,11 @@ export const Mark: CC<MarkOptions> = ({
48
50
  type: 'standardView',
49
51
  x,
50
52
  y,
53
+ z,
51
54
  key,
52
55
  width,
53
56
  height,
57
+ depth,
54
58
  padding,
55
59
  paddingLeft,
56
60
  paddingRight,
@@ -0,0 +1,11 @@
1
+ import { Coordinate3DComponent as CC } from '../runtime';
2
+ import { Cartesian3DCoordinate } from '../spec';
3
+
4
+ export type Cartesian3DOptions = Cartesian3DCoordinate;
5
+
6
+ /**
7
+ * Default coordinate3D transformation for all charts.
8
+ */
9
+ export const Cartesian3D: CC<Cartesian3DCoordinate> = () => [['cartesian3D']];
10
+
11
+ Cartesian3D.props = {};
@@ -1,4 +1,5 @@
1
1
  export { Cartesian } from './cartesian';
2
+ export { Cartesian3D } from './cartesian3D';
2
3
  export { Polar, getPolarOptions } from './polar';
3
4
  export { Helix } from './helix';
4
5
  export { Transpose } from './transpose';
@@ -9,6 +10,7 @@ export { Fisheye } from './fisheye';
9
10
  export { Radar } from './radar';
10
11
 
11
12
  export type { CartesianOptions } from './cartesian';
13
+ export type { Cartesian3DOptions } from './cartesian3D';
12
14
  export type { PolarOptions } from './polar';
13
15
  export type { HelixOptions } from './helix';
14
16
  export type { TransposeOptions } from './transpose';
package/src/data/index.ts CHANGED
@@ -17,6 +17,7 @@ export { Join } from './join';
17
17
  export { Slice } from './slice';
18
18
  export { KDE } from './kde';
19
19
  export { Venn } from './venn';
20
+ export { Log } from './log';
20
21
 
21
22
  export type { FetchOptions } from './fetch';
22
23
  export type { FoldOptions } from './fold';
@@ -37,3 +38,4 @@ export type { JoinOptions } from './join';
37
38
  export type { SliceOptions } from './slice';
38
39
  export type { KDEOptions } from './kde';
39
40
  export type { VennOptions } from './venn';
41
+ export type { LogDataOptions } from './log';
@@ -0,0 +1,16 @@
1
+ import { DataComponent as DC } from '../runtime';
2
+ import { LogDataTransform } from '../spec';
3
+
4
+ export type LogDataOptions = Omit<LogDataTransform, 'type'>;
5
+
6
+ /**
7
+ * Console.log the data section for dev debugger.
8
+ */
9
+ export const Log: DC<LogDataOptions> = () => {
10
+ return (data) => {
11
+ console.log('G2 data section:', data);
12
+ return data;
13
+ };
14
+ };
15
+
16
+ Log.props = {};
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ export {
15
15
  AREA_CLASS_NAME,
16
16
  } from './runtime';
17
17
 
18
- export { corelib, stdlib, litelib } from './lib';
18
+ export { corelib, stdlib, litelib, threedlib } from './lib';
19
19
 
20
20
  export * from './mark';
21
21
 
@@ -82,7 +82,7 @@ export function brushFilter(
82
82
 
83
83
  export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
84
84
  return (target, viewInstances, emitter) => {
85
- const { container, view, options: viewOptions, update } = target;
85
+ const { container, view, options: viewOptions, update, setState } = target;
86
86
  const plotArea = selectPlotArea(container);
87
87
  const defaultOptions = {
88
88
  maskFill: '#777',
@@ -110,26 +110,35 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
110
110
 
111
111
  // Update the domain of x and y scale to filter data.
112
112
  const [domainX, domainY] = selection;
113
- const { marks } = viewOptions;
114
- const newMarks = marks.map((mark) =>
115
- deepMix(
116
- {
117
- // Hide label to keep smooth transition.
118
- axis: {
119
- ...(hideX && { x: { transform: [{ type: 'hide' }] } }),
120
- ...(hideY && { y: { transform: [{ type: 'hide' }] } }),
113
+
114
+ setState('brushFilter', (options) => {
115
+ const { marks } = options;
116
+ const newMarks = marks.map((mark) =>
117
+ deepMix(
118
+ {
119
+ // Hide label to keep smooth transition.
120
+ axis: {
121
+ ...(hideX && { x: { transform: [{ type: 'hide' }] } }),
122
+ ...(hideY && { y: { transform: [{ type: 'hide' }] } }),
123
+ },
121
124
  },
122
- },
123
- mark,
124
- {
125
- // Set nice to false to avoid modify domain.
126
- scale: {
127
- x: { domain: domainX, nice: false },
128
- y: { domain: domainY, nice: false },
125
+ mark,
126
+ {
127
+ // Set nice to false to avoid modify domain.
128
+ scale: {
129
+ x: { domain: domainX, nice: false },
130
+ y: { domain: domainY, nice: false },
131
+ },
129
132
  },
130
- },
131
- ),
132
- );
133
+ ),
134
+ );
135
+
136
+ return {
137
+ ...viewOptions,
138
+ marks: newMarks,
139
+ clip: true, // Clip shapes out of plot area.
140
+ };
141
+ });
133
142
 
134
143
  // Emit event.
135
144
  emitter.emit('brush:filter', {
@@ -137,13 +146,7 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
137
146
  data: { selection: [domainX, domainY] },
138
147
  });
139
148
 
140
- // Rerender and update view.
141
- const newOptions = {
142
- ...viewOptions,
143
- marks: newMarks,
144
- clip: true, // Clip shapes out of plot area.
145
- };
146
- const newState = await update(newOptions);
149
+ const newState = await update();
147
150
  newView = newState.view;
148
151
  filtering = false;
149
152
  filtered = true;
@@ -160,10 +163,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
160
163
  ...event,
161
164
  data: { selection: [domainX, domainY] },
162
165
  });
163
-
164
166
  filtered = false;
165
167
  newView = view;
166
- update(viewOptions);
168
+ setState('brushFilter');
169
+ update();
167
170
  },
168
171
  extent: undefined,
169
172
  emitter,
@@ -58,7 +58,7 @@ export function ChartIndex({
58
58
  ...style
59
59
  }: Record<string, any>) {
60
60
  return (context) => {
61
- const { options, view, container, update } = context;
61
+ const { view, container, update, setState } = context;
62
62
  const { markState, scale, coordinate } = view;
63
63
 
64
64
  // Get line mark value, exit if it is not existed.
@@ -70,18 +70,6 @@ export function ChartIndex({
70
70
  const I = Y.map((_, i) => i);
71
71
  const sortedX: number[] = sort(I.map((i) => X[i]));
72
72
 
73
- // Clone options and get line mark.
74
- const clonedOptions = deepMix({}, options);
75
- const lineMark = clonedOptions.marks.find((d) => d.type === 'line');
76
-
77
- // Update domain of y scale for the line mark.
78
- const r = (I: number[]) => max(I, (i) => +Y[i]) / min(I, (i) => +Y[i]);
79
- const k = max(rollup(I, r, (i) => S[i]).values());
80
- const domainY = [1 / k, k];
81
- deepMix(lineMark, {
82
- scale: { y: { domain: domainY } },
83
- });
84
-
85
73
  // Prepare shapes.
86
74
  const plotArea = selectPlotArea(container);
87
75
  const lines = container.getElementsByClassName(ELEMENT_CLASS_NAME);
@@ -142,16 +130,31 @@ export function ChartIndex({
142
130
 
143
131
  updateRule(focus, date);
144
132
 
145
- // Update normalize options.
146
- const normalizeY = maybeTransform(lineMark);
147
- normalizeY.groupBy = 'color';
148
- normalizeY.basis = (I, Y) => {
149
- const i = I[bisector((i) => X[+i]).center(I, date)];
150
- return Y[i];
151
- };
152
- // Disable animation.
153
- for (const mark of clonedOptions.marks) mark.animate = false;
154
- const newState = await update(clonedOptions);
133
+ setState('chartIndex', (options) => {
134
+ // Clone options and get line mark.
135
+ const clonedOptions = deepMix({}, options);
136
+ const lineMark = clonedOptions.marks.find((d) => d.type === 'line');
137
+
138
+ // Update domain of y scale for the line mark.
139
+ const r = (I: number[]) => max(I, (i) => +Y[i]) / min(I, (i) => +Y[i]);
140
+ const k = max(rollup(I, r, (i) => S[i]).values());
141
+ const domainY = [1 / k, k];
142
+ deepMix(lineMark, {
143
+ scale: { y: { domain: domainY } },
144
+ });
145
+ // Update normalize options.
146
+ const normalizeY = maybeTransform(lineMark);
147
+ normalizeY.groupBy = 'color';
148
+ normalizeY.basis = (I, Y) => {
149
+ const i = I[bisector((i) => X[+i]).center(I, date)];
150
+ return Y[i];
151
+ };
152
+ // Disable animation.
153
+ for (const mark of clonedOptions.marks) mark.animate = false;
154
+ return clonedOptions;
155
+ });
156
+
157
+ const newState = await update();
155
158
  newView = newState.view;
156
159
  };
157
160
 
@@ -14,14 +14,23 @@ 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;
17
+ function maybeRoot(node, rootOf) {
18
+ if (rootOf(node)) return node;
20
19
  let root = node.parent;
21
- while (root && root.className !== 'element') root = root.parent;
20
+ while (root && !rootOf(root)) root = root.parent;
22
21
  return root;
23
22
  }
24
23
 
24
+ // For extended component
25
+ function maybeComponentRoot(node) {
26
+ return maybeRoot(node, (node) => node.className === 'component');
27
+ }
28
+
29
+ // For extended shape.
30
+ function maybeElementRoot(node) {
31
+ return maybeRoot(node, (node) => node.className === 'element');
32
+ }
33
+
25
34
  function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
26
35
  return (e) => {
27
36
  if (!predicate(e)) return;
@@ -41,19 +50,23 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
41
50
 
42
51
  // If target is element or child of element.
43
52
  const elementRoot = maybeElementRoot(target);
44
- if (!elementRoot) return;
45
- const { className: elementType, markType } = elementRoot;
53
+ // If target is component or child of component.
54
+ const componentRoot = maybeComponentRoot(target);
55
+ const root = elementRoot || componentRoot;
56
+ if (!root) return;
57
+ const { className: elementType, markType } = root;
46
58
  if (elementType === 'element') {
47
59
  const e1 = {
48
60
  ...e,
49
61
  nativeEvent: true,
50
- data: { data: dataOf(elementRoot, view) },
62
+ data: { data: dataOf(root, view) },
51
63
  };
52
64
  emitter.emit(`element:${eventType}`, e1);
53
65
  emitter.emit(`${markType}:${eventType}`, e1);
54
66
  } else {
55
- // @todo Handle click axis and legend.
56
- emitter.emit(`${elementType}:${eventType}`, e);
67
+ const e1 = { ...e, nativeEvent: true };
68
+ emitter.emit(`component:${eventType}`, e1);
69
+ emitter.emit(`${className}:${eventType}`, e1);
57
70
  }
58
71
  };
59
72
  }
@@ -22,26 +22,30 @@ export function Fisheye({
22
22
  trailing = false,
23
23
  }: Record<string, any>) {
24
24
  return (context) => {
25
- const { options, update, container } = context;
25
+ const { options, update, setState, container } = context;
26
26
  const plotArea = selectPlotArea(container);
27
27
 
28
- // Clone options and mutate it.
29
- // Disable animation.
30
- const clonedOptions = deepMix({}, options);
31
- for (const mark of clonedOptions.marks) mark.animate = false;
32
28
  const updateFocus = throttle(
33
29
  (event) => {
34
30
  const focus = mousePosition(plotArea, event);
35
31
  if (!focus) {
36
- update(options);
32
+ setState('fisheye');
33
+ update();
37
34
  return;
38
35
  }
39
- const [x, y] = focus;
40
- const fisheye = maybeCoordinate(clonedOptions);
41
- fisheye.focusX = x;
42
- fisheye.focusY = y;
43
- fisheye.visual = true;
44
- update(clonedOptions);
36
+ setState('fisheye', (options) => {
37
+ // Clone options and mutate it.
38
+ // Disable animation.
39
+ const clonedOptions = deepMix({}, options);
40
+ for (const mark of clonedOptions.marks) mark.animate = false;
41
+ const [x, y] = focus;
42
+ const fisheye = maybeCoordinate(clonedOptions);
43
+ fisheye.focusX = x;
44
+ fisheye.focusY = y;
45
+ fisheye.visual = true;
46
+ return clonedOptions;
47
+ });
48
+ update();
45
49
  },
46
50
  wait,
47
51
  { leading, trailing },
@@ -200,52 +200,57 @@ function legendFilterContinuous(_, { legend, filter, emitter, channel }) {
200
200
 
201
201
  export function LegendFilter() {
202
202
  return (context, _, emitter) => {
203
- const { container, view, options: viewOptions, update } = context;
203
+ const { container, view, update, setState } = context;
204
204
 
205
+ const channelsOf = (legend) => {
206
+ return dataOf(legend).scales.map((d) => d.name);
207
+ };
205
208
  const legends = [
206
209
  ...legendsOf(container),
207
210
  ...legendsContinuousOf(container),
208
211
  ];
212
+ const allChannels = legends.flatMap(channelsOf);
209
213
 
210
214
  const filter = throttle(
211
- async (channel, value, ordinal: boolean, channels) => {
212
- const { marks } = viewOptions;
213
- // Add filter transform for every marks,
214
- // which will skip for mark without color channel.
215
- const newMarks = marks.map((mark) => {
216
- if (mark.type === 'legends') return mark;
217
-
218
- // Inset after aggregate transform, such as group, and bin.
219
- const { transform = [] } = mark;
220
- const index = transform.findIndex(
221
- ({ type }) => type.startsWith('group') || type.startsWith('bin'),
222
- );
223
- const newTransform = [...transform];
224
- newTransform.splice(index + 1, 0, {
225
- type: 'filter',
226
- [channel]: { value, ordinal },
227
- });
228
-
229
- // Set domain of scale to preserve encoding.
230
- const newScale = Object.fromEntries(
231
- channels.map((channel) => [
232
- channel,
233
- { domain: view.scale[channel].getOptions().domain },
234
- ]),
235
- );
236
-
237
- return deepMix({}, mark, {
238
- transform: newTransform,
239
- scale: newScale,
240
- ...(!ordinal && { animate: false }),
241
- legend: { [channel]: { preserve: true } },
215
+ async (legend, channel, value, ordinal: boolean, channels) => {
216
+ setState(legend, (viewOptions) => {
217
+ const { marks } = viewOptions;
218
+ // Add filter transform for every marks,
219
+ // which will skip for mark without color channel.
220
+ const newMarks = marks.map((mark) => {
221
+ if (mark.type === 'legends') return mark;
222
+
223
+ // Inset after aggregate transform, such as group, and bin.
224
+ const { transform = [] } = mark;
225
+ const index = transform.findIndex(
226
+ ({ type }) => type.startsWith('group') || type.startsWith('bin'),
227
+ );
228
+ const newTransform = [...transform];
229
+ newTransform.splice(index + 1, 0, {
230
+ type: 'filter',
231
+ [channel]: { value, ordinal },
232
+ });
233
+
234
+ // Set domain of scale to preserve encoding.
235
+ const newScale = Object.fromEntries(
236
+ channels.map((channel) => [
237
+ channel,
238
+ { domain: view.scale[channel].getOptions().domain },
239
+ ]),
240
+ );
241
+
242
+ return deepMix({}, mark, {
243
+ transform: newTransform,
244
+ scale: newScale,
245
+ ...(!ordinal && { animate: false }),
246
+ legend: Object.fromEntries(
247
+ allChannels.map((d) => [d, { preserve: true }]),
248
+ ),
249
+ });
242
250
  });
251
+ return { ...viewOptions, marks: newMarks };
243
252
  });
244
- const newOptions = {
245
- ...viewOptions,
246
- marks: newMarks,
247
- };
248
- await update(newOptions);
253
+ await update();
249
254
  },
250
255
  50,
251
256
  { trailing: true },
@@ -253,7 +258,7 @@ export function LegendFilter() {
253
258
 
254
259
  const removes = legends.map((legend) => {
255
260
  const { name: channel, domain } = dataOf(legend).scales[0];
256
- const channels = dataOf(legend).scales.map((d) => d.name);
261
+ const channels = channelsOf(legend);
257
262
  if (legend.className === CATEGORY_LEGEND_CLASS_NAME) {
258
263
  return legendFilterOrdinal(container, {
259
264
  legends: itemsOf,
@@ -264,7 +269,7 @@ export function LegendFilter() {
264
269
  const { index } = datum;
265
270
  return domain[index];
266
271
  },
267
- filter: (value) => filter(channel, value, true, channels),
272
+ filter: (value) => filter(legend, channel, value, true, channels),
268
273
  state: legend.attributes.state,
269
274
  channel,
270
275
  emitter,
@@ -272,7 +277,7 @@ export function LegendFilter() {
272
277
  } else {
273
278
  return legendFilterContinuous(container, {
274
279
  legend,
275
- filter: (value) => filter(channel, value, false, channels),
280
+ filter: (value) => filter(legend, channel, value, false, channels),
276
281
  emitter,
277
282
  channel,
278
283
  });
@@ -68,7 +68,7 @@ export function SliderFilter({
68
68
  trailing = false,
69
69
  }: any) {
70
70
  return (context, _, emitter) => {
71
- const { container, view, options, update } = context;
71
+ const { container, view, update, setState } = context;
72
72
  const sliders = container.getElementsByClassName(className);
73
73
  if (!sliders.length) return () => {};
74
74
 
@@ -138,18 +138,6 @@ export function SliderFilter({
138
138
  channelDomain[channel0] = domain0;
139
139
  channelDomain[channel1] = domain1;
140
140
 
141
- // Filter data.
142
- const newOptions = filterDataByDomain(
143
- options,
144
- {
145
- // Set nice to false to avoid modify domain.
146
- [channel0]: { domain: domain0, nice: false },
147
- [channel1]: { domain: domain1, nice: false },
148
- },
149
- prefix,
150
- hasState,
151
- );
152
-
153
141
  if (nativeEvent) {
154
142
  // Emit events.
155
143
  const X = isX ? domain0 : domain1;
@@ -161,13 +149,24 @@ export function SliderFilter({
161
149
  });
162
150
  }
163
151
 
164
- await update({
165
- ...newOptions,
152
+ setState(slider, (options) => ({
153
+ ...filterDataByDomain(
154
+ options,
155
+ {
156
+ // Set nice to false to avoid modify domain.
157
+ [channel0]: { domain: domain0, nice: false },
158
+ [channel1]: { domain: domain1, nice: false },
159
+ },
160
+ prefix,
161
+ hasState,
162
+ ),
166
163
  paddingLeft,
167
164
  paddingTop,
168
165
  paddingBottom,
169
166
  paddingRight,
170
- });
167
+ }));
168
+
169
+ await update();
171
170
  filtering = false;
172
171
  },
173
172
  wait,
@@ -1,4 +1,4 @@
1
- import { DisplayObject, IElement, Line } from '@antv/g';
1
+ import { Circle, DisplayObject, IElement, Line } from '@antv/g';
2
2
  import { sort, group, mean, bisector, minIndex } from 'd3-array';
3
3
  import { deepMix, lowerFirst, throttle } from '@antv/util';
4
4
  import { Tooltip as TooltipComponent } from '@antv/gui';
@@ -333,6 +333,38 @@ function hideRuleY(root) {
333
333
  }
334
334
  }
335
335
 
336
+ function updateMarker(root, { data, style, items }) {
337
+ if (root.markers) root.markers.forEach((d) => d.remove());
338
+ const markers = data.map((d) => {
339
+ const [{ color, element }, point] = d;
340
+ const fill =
341
+ color || // encode value
342
+ element.style.fill ||
343
+ element.style.stroke;
344
+ const shape = new Circle({
345
+ style: {
346
+ cx: point[0],
347
+ cy: point[1],
348
+ fill,
349
+ r: 4,
350
+ stroke: '#fff',
351
+ strokeWidth: 2,
352
+ ...style,
353
+ },
354
+ });
355
+ return shape;
356
+ });
357
+ for (const marker of markers) root.appendChild(marker);
358
+ root.markers = markers;
359
+ }
360
+
361
+ function hideMarker(root) {
362
+ if (root.markers) {
363
+ root.markers.forEach((d) => d.remove());
364
+ root.markers = [];
365
+ }
366
+ }
367
+
336
368
  function interactionKeyof(markState, key) {
337
369
  return Array.from(markState.values()).some(
338
370
  // @ts-ignore
@@ -384,6 +416,7 @@ export function seriesTooltip(
384
416
  mount,
385
417
  bounding,
386
418
  disableNative = false,
419
+ marker = true,
387
420
  style: _style = {},
388
421
  ...rest
389
422
  }: Record<string, any>,
@@ -430,7 +463,6 @@ export function seriesTooltip(
430
463
  }),
431
464
  );
432
465
 
433
- const ruleStyle = subObject(style, 'crosshairs');
434
466
  const { x: scaleX } = scale;
435
467
 
436
468
  // Apply offset for band scale x.
@@ -499,7 +531,7 @@ export function seriesTooltip(
499
531
  const d = seriesData(element, index);
500
532
  const { x, y } = d;
501
533
  const p = coordinate.map([(x || 0) + offsetX, y || 0]);
502
- selectedSeriesData.push([d, p] as const);
534
+ selectedSeriesData.push([{ ...d, element }, p] as const);
503
535
  }
504
536
  }
505
537
 
@@ -557,6 +589,7 @@ export function seriesTooltip(
557
589
 
558
590
  if (crosshairs) {
559
591
  const points = filteredSeriesData.map((d) => d[1]);
592
+ const ruleStyle = subObject(style, 'crosshairs');
560
593
  updateRuleY(root, points, {
561
594
  ...ruleStyle,
562
595
  plotWidth,
@@ -572,6 +605,15 @@ export function seriesTooltip(
572
605
  });
573
606
  }
574
607
 
608
+ if (marker) {
609
+ const markerStyles = subObject(style, 'marker');
610
+ updateMarker(root, {
611
+ data: filteredSeriesData,
612
+ items: tooltipData.items,
613
+ style: markerStyles,
614
+ });
615
+ }
616
+
575
617
  emitter.emit('tooltip:show', {
576
618
  ...event,
577
619
  nativeEvent: true,
@@ -585,6 +627,7 @@ export function seriesTooltip(
585
627
  const hide = () => {
586
628
  hideTooltip({ root, single, emitter, mount });
587
629
  if (crosshairs) hideRuleY(root);
630
+ if (marker) hideMarker(root);
588
631
  };
589
632
 
590
633
  const onTooltipShow = ({ nativeEvent, data }) => {
@@ -622,6 +665,7 @@ export function seriesTooltip(
622
665
  emitter.off('tooltip:hide', onTooltipHide);
623
666
  destroyTooltip(root);
624
667
  if (crosshairs) hideRuleY(root);
668
+ if (marker) hideMarker(root);
625
669
  };
626
670
  }
627
671
 
package/src/lib/core.ts CHANGED
@@ -159,6 +159,7 @@ import {
159
159
  Join as DataJoin,
160
160
  Sort as DataSort,
161
161
  KDE as DataKDE,
162
+ Log as DataLog,
162
163
  } from '../data';
163
164
  import {
164
165
  OverlapDodgeY,
@@ -183,6 +184,7 @@ export function corelib() {
183
184
  'data.map': DataMap,
184
185
  'data.join': DataJoin,
185
186
  'data.kde': DataKDE,
187
+ 'data.log': DataLog,
186
188
  'transform.stackY': StackY,
187
189
  'transform.binX': BinX,
188
190
  'transform.bin': Bin,
package/src/lib/index.ts CHANGED
@@ -2,5 +2,6 @@ export { corelib } from './core';
2
2
  export { geolib } from './geo';
3
3
  export { graphlib } from './graph';
4
4
  export { plotlib } from './plot';
5
+ export { threedlib } from './threed';
5
6
  export { stdlib } from './std';
6
7
  export { litelib } from './lite';