@antv/g2 5.0.0-beta.7 → 5.0.0-beta.8

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 (230) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/api/chart.d.ts +6 -2
  4. package/esm/api/chart.js +31 -14
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/composition/base.d.ts +18 -1
  7. package/esm/api/composition/base.js +44 -1
  8. package/esm/api/composition/base.js.map +1 -1
  9. package/esm/api/mark/base.d.ts +22 -0
  10. package/esm/api/mark/base.js +54 -0
  11. package/esm/api/mark/base.js.map +1 -0
  12. package/esm/api/mark/mark.d.ts +1 -7
  13. package/esm/api/mark/mark.js +1 -13
  14. package/esm/api/mark/mark.js.map +1 -1
  15. package/esm/api/props.js +0 -20
  16. package/esm/api/props.js.map +1 -1
  17. package/esm/component/axis.js +4 -0
  18. package/esm/component/axis.js.map +1 -1
  19. package/esm/component/legendContinuous.d.ts +1 -0
  20. package/esm/component/legendContinuous.js +14 -16
  21. package/esm/component/legendContinuous.js.map +1 -1
  22. package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
  23. package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  24. package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
  25. package/esm/interaction/index.d.ts +1 -0
  26. package/esm/interaction/index.js +1 -0
  27. package/esm/interaction/index.js.map +1 -1
  28. package/esm/interaction/native/elementHighlight.d.ts +7 -2
  29. package/esm/interaction/native/elementHighlight.js +72 -19
  30. package/esm/interaction/native/elementHighlight.js.map +1 -1
  31. package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
  32. package/esm/interaction/native/elementHighlightByColor.js +19 -3
  33. package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
  34. package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
  35. package/esm/interaction/native/elementHighlightByX.js +19 -3
  36. package/esm/interaction/native/elementHighlightByX.js.map +1 -1
  37. package/esm/interaction/native/elementSelect.d.ts +1 -1
  38. package/esm/interaction/native/elementSelect.js +42 -21
  39. package/esm/interaction/native/elementSelect.js.map +1 -1
  40. package/esm/interaction/native/elementSelectByColor.js +3 -2
  41. package/esm/interaction/native/elementSelectByColor.js.map +1 -1
  42. package/esm/interaction/native/elementSelectByX.js +3 -2
  43. package/esm/interaction/native/elementSelectByX.js.map +1 -1
  44. package/esm/interaction/native/legendFilter.d.ts +4 -0
  45. package/esm/interaction/native/legendFilter.js +7 -4
  46. package/esm/interaction/native/legendFilter.js.map +1 -1
  47. package/esm/interaction/native/legendHighlight.d.ts +4 -0
  48. package/esm/interaction/native/legendHighlight.js +94 -0
  49. package/esm/interaction/native/legendHighlight.js.map +1 -0
  50. package/esm/interaction/native/utils.d.ts +13 -2
  51. package/esm/interaction/native/utils.js +151 -26
  52. package/esm/interaction/native/utils.js.map +1 -1
  53. package/esm/label-transform/overlapDodgeY.js +0 -8
  54. package/esm/label-transform/overlapDodgeY.js.map +1 -1
  55. package/esm/mark/area.js +1 -1
  56. package/esm/mark/area.js.map +1 -1
  57. package/esm/runtime/plot.js +4 -4
  58. package/esm/runtime/plot.js.map +1 -1
  59. package/esm/runtime/render.js +18 -13
  60. package/esm/runtime/render.js.map +1 -1
  61. package/esm/runtime/types/options.d.ts +4 -2
  62. package/esm/shape/area/hv.d.ts +3 -0
  63. package/esm/shape/area/hv.js +9 -0
  64. package/esm/shape/area/hv.js.map +1 -0
  65. package/esm/shape/area/hvh.d.ts +3 -0
  66. package/esm/shape/area/{step.js → hvh.js} +3 -3
  67. package/esm/shape/area/hvh.js.map +1 -0
  68. package/esm/shape/area/vh.d.ts +3 -0
  69. package/esm/shape/area/vh.js +9 -0
  70. package/esm/shape/area/vh.js.map +1 -0
  71. package/esm/shape/index.d.ts +6 -2
  72. package/esm/shape/index.js +3 -1
  73. package/esm/shape/index.js.map +1 -1
  74. package/esm/shape/interval/color.d.ts +1 -0
  75. package/esm/shape/interval/color.js +65 -53
  76. package/esm/shape/interval/color.js.map +1 -1
  77. package/esm/spec/composition.d.ts +0 -3
  78. package/esm/spec/interaction.d.ts +24 -11
  79. package/esm/spec/transform.d.ts +13 -3
  80. package/esm/stdlib/index.js +3 -8
  81. package/esm/stdlib/index.js.map +1 -1
  82. package/esm/transform/sample.js +42 -26
  83. package/esm/transform/sample.js.map +1 -1
  84. package/esm/transform/utils/lttb.d.ts +5 -0
  85. package/esm/transform/utils/lttb.js +56 -0
  86. package/esm/transform/utils/lttb.js.map +1 -0
  87. package/esm/utils/event.d.ts +0 -2
  88. package/esm/utils/event.js +0 -18
  89. package/esm/utils/event.js.map +1 -1
  90. package/esm/utils/scale.d.ts +1 -0
  91. package/esm/utils/scale.js +3 -3
  92. package/esm/utils/scale.js.map +1 -1
  93. package/esm/utils/vector.d.ts +1 -1
  94. package/esm/utils/vector.js +1 -1
  95. package/lib/api/chart.d.ts +6 -2
  96. package/lib/api/chart.js +33 -13
  97. package/lib/api/chart.js.map +1 -1
  98. package/lib/api/composition/base.d.ts +18 -1
  99. package/lib/api/composition/base.js +44 -1
  100. package/lib/api/composition/base.js.map +1 -1
  101. package/lib/api/mark/base.d.ts +22 -0
  102. package/lib/api/mark/base.js +58 -0
  103. package/lib/api/mark/base.js.map +1 -0
  104. package/lib/api/mark/mark.d.ts +1 -7
  105. package/lib/api/mark/mark.js +28 -41
  106. package/lib/api/mark/mark.js.map +1 -1
  107. package/lib/api/props.js +0 -20
  108. package/lib/api/props.js.map +1 -1
  109. package/lib/component/axis.js +4 -0
  110. package/lib/component/axis.js.map +1 -1
  111. package/lib/component/legendContinuous.d.ts +1 -0
  112. package/lib/component/legendContinuous.js +14 -16
  113. package/lib/component/legendContinuous.js.map +1 -1
  114. package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
  115. package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  116. package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
  117. package/lib/interaction/index.d.ts +1 -0
  118. package/lib/interaction/index.js +3 -1
  119. package/lib/interaction/index.js.map +1 -1
  120. package/lib/interaction/native/elementHighlight.d.ts +7 -2
  121. package/lib/interaction/native/elementHighlight.js +71 -18
  122. package/lib/interaction/native/elementHighlight.js.map +1 -1
  123. package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
  124. package/lib/interaction/native/elementHighlightByColor.js +18 -2
  125. package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
  126. package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
  127. package/lib/interaction/native/elementHighlightByX.js +18 -2
  128. package/lib/interaction/native/elementHighlightByX.js.map +1 -1
  129. package/lib/interaction/native/elementSelect.d.ts +1 -1
  130. package/lib/interaction/native/elementSelect.js +41 -20
  131. package/lib/interaction/native/elementSelect.js.map +1 -1
  132. package/lib/interaction/native/elementSelectByColor.js +2 -1
  133. package/lib/interaction/native/elementSelectByColor.js.map +1 -1
  134. package/lib/interaction/native/elementSelectByX.js +2 -1
  135. package/lib/interaction/native/elementSelectByX.js.map +1 -1
  136. package/lib/interaction/native/legendFilter.d.ts +4 -0
  137. package/lib/interaction/native/legendFilter.js +10 -3
  138. package/lib/interaction/native/legendFilter.js.map +1 -1
  139. package/lib/interaction/native/legendHighlight.d.ts +4 -0
  140. package/lib/interaction/native/legendHighlight.js +98 -0
  141. package/lib/interaction/native/legendHighlight.js.map +1 -0
  142. package/lib/interaction/native/utils.d.ts +13 -2
  143. package/lib/interaction/native/utils.js +154 -27
  144. package/lib/interaction/native/utils.js.map +1 -1
  145. package/lib/label-transform/overlapDodgeY.js +0 -8
  146. package/lib/label-transform/overlapDodgeY.js.map +1 -1
  147. package/lib/mark/area.js +1 -1
  148. package/lib/mark/area.js.map +1 -1
  149. package/lib/runtime/plot.js +3 -3
  150. package/lib/runtime/plot.js.map +1 -1
  151. package/lib/runtime/render.js +20 -12
  152. package/lib/runtime/render.js.map +1 -1
  153. package/lib/runtime/types/options.d.ts +4 -2
  154. package/lib/shape/area/hv.d.ts +3 -0
  155. package/lib/shape/area/hv.js +13 -0
  156. package/lib/shape/area/hv.js.map +1 -0
  157. package/lib/shape/area/hvh.d.ts +3 -0
  158. package/lib/shape/area/{step.js → hvh.js} +5 -5
  159. package/lib/shape/area/hvh.js.map +1 -0
  160. package/lib/shape/area/vh.d.ts +3 -0
  161. package/lib/shape/area/vh.js +13 -0
  162. package/lib/shape/area/vh.js.map +1 -0
  163. package/lib/shape/index.d.ts +6 -2
  164. package/lib/shape/index.js +7 -3
  165. package/lib/shape/index.js.map +1 -1
  166. package/lib/shape/interval/color.d.ts +1 -0
  167. package/lib/shape/interval/color.js +67 -54
  168. package/lib/shape/interval/color.js.map +1 -1
  169. package/lib/spec/composition.d.ts +0 -3
  170. package/lib/spec/interaction.d.ts +24 -11
  171. package/lib/spec/transform.d.ts +13 -3
  172. package/lib/stdlib/index.js +1 -1
  173. package/lib/stdlib/index.js.map +1 -1
  174. package/lib/transform/sample.js +42 -26
  175. package/lib/transform/sample.js.map +1 -1
  176. package/lib/transform/utils/lttb.d.ts +5 -0
  177. package/lib/transform/utils/lttb.js +60 -0
  178. package/lib/transform/utils/lttb.js.map +1 -0
  179. package/lib/utils/event.d.ts +0 -2
  180. package/lib/utils/event.js +1 -21
  181. package/lib/utils/event.js.map +1 -1
  182. package/lib/utils/scale.d.ts +1 -0
  183. package/lib/utils/scale.js +5 -4
  184. package/lib/utils/scale.js.map +1 -1
  185. package/lib/utils/vector.d.ts +1 -1
  186. package/lib/utils/vector.js +1 -1
  187. package/package.json +4 -3
  188. package/src/.DS_Store +0 -0
  189. package/src/api/chart.ts +37 -16
  190. package/src/api/composition/base.ts +46 -1
  191. package/src/api/mark/base.ts +58 -0
  192. package/src/api/mark/mark.ts +1 -20
  193. package/src/api/props.ts +0 -23
  194. package/src/component/axis.ts +7 -0
  195. package/src/component/legendContinuous.ts +15 -5
  196. package/src/data/.DS_Store +0 -0
  197. package/src/interaction/index.ts +1 -0
  198. package/src/interaction/native/elementHighlight.ts +78 -12
  199. package/src/interaction/native/elementHighlightByColor.ts +9 -4
  200. package/src/interaction/native/elementHighlightByX.ts +9 -5
  201. package/src/interaction/native/elementSelect.ts +58 -15
  202. package/src/interaction/native/elementSelectByColor.ts +4 -1
  203. package/src/interaction/native/elementSelectByX.ts +4 -1
  204. package/src/interaction/native/legendFilter.ts +8 -4
  205. package/src/interaction/native/legendHighlight.ts +87 -0
  206. package/src/interaction/native/utils.ts +183 -26
  207. package/src/label-transform/overlapDodgeY.ts +0 -7
  208. package/src/mark/area.ts +1 -1
  209. package/src/runtime/plot.ts +4 -4
  210. package/src/runtime/render.ts +26 -13
  211. package/src/runtime/types/options.ts +10 -2
  212. package/src/shape/.DS_Store +0 -0
  213. package/src/shape/area/hv.ts +20 -0
  214. package/src/shape/area/{step.ts → hvh.ts} +3 -3
  215. package/src/shape/area/vh.ts +20 -0
  216. package/src/shape/index.ts +7 -2
  217. package/src/shape/interval/color.ts +86 -54
  218. package/src/spec/composition.ts +0 -1
  219. package/src/spec/interaction.ts +35 -11
  220. package/src/spec/transform.ts +27 -2
  221. package/src/stdlib/index.ts +8 -6
  222. package/src/transform/sample.ts +54 -18
  223. package/src/transform/utils/lttb.ts +73 -0
  224. package/src/utils/event.ts +0 -26
  225. package/src/utils/scale.ts +4 -4
  226. package/src/utils/vector.ts +1 -1
  227. package/esm/shape/area/step.d.ts +0 -3
  228. package/esm/shape/area/step.js.map +0 -1
  229. package/lib/shape/area/step.d.ts +0 -3
  230. package/lib/shape/area/step.js.map +0 -1
@@ -2,9 +2,10 @@ import { Canvas as GCanvas, DisplayObject, Group } 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
4
  import { deepMix } from '@antv/util';
5
+ import EventEmitter from '@antv/event-emitter';
5
6
  import { createLibrary } from '../stdlib';
6
7
  import { select } from '../utils/selection';
7
- import { emitEvent, CHART_LIFE_CIRCLE, offEvent } from '../utils/event';
8
+ import { CHART_LIFE_CIRCLE } from '../utils/event';
8
9
  import { G2Context, G2ViewTree } from './types/options';
9
10
  import { plot } from './plot';
10
11
 
@@ -65,12 +66,17 @@ export function render<T extends G2ViewTree = G2ViewTree>(
65
66
  // Initialize the context if it is not provided.
66
67
  const { width = 640, height = 480, on } = options;
67
68
  const keyed = inferKeys(options);
68
- const { canvas = Canvas(width, height), library = createLibrary() } = context;
69
+ const {
70
+ canvas = Canvas(width, height),
71
+ library = createLibrary(),
72
+ emitter = new EventEmitter(),
73
+ } = context;
69
74
  context.canvas = canvas;
70
75
  context.library = library;
76
+ context.emitter = emitter;
71
77
  canvas.resize(width, height);
72
78
 
73
- emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_RENDER);
79
+ emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
74
80
 
75
81
  // Plot the chart and mutate context.
76
82
  // Make sure that plot chart after container is ready for every time.
@@ -79,8 +85,10 @@ export function render<T extends G2ViewTree = G2ViewTree>(
79
85
  .then(() =>
80
86
  plot<T>({ ...keyed, width, height }, selection, library, context),
81
87
  )
82
- .then(callback)
83
- .then(() => emitEvent(on, CHART_LIFE_CIRCLE.AFTER_RENDER));
88
+ .then(() => {
89
+ emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
90
+ callback?.();
91
+ });
84
92
 
85
93
  // Return the container HTML element wraps the canvas or svg element.
86
94
  return normalizeContainer(canvas.getConfig().container);
@@ -94,7 +102,11 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
94
102
  // Initialize the context if it is not provided.
95
103
  const { width = 640, height = 480, on } = options;
96
104
  const keyed = inferKeys(options);
97
- const { library = createLibrary(), group = new Group() } = context;
105
+ const {
106
+ library = createLibrary(),
107
+ group = new Group(),
108
+ emitter = new EventEmitter(),
109
+ } = context;
98
110
 
99
111
  if (!group?.parentElement) {
100
112
  throw new Error(
@@ -105,13 +117,15 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
105
117
  const selection = select(group);
106
118
  context.group = group;
107
119
  context.library = library;
120
+ context.emitter = emitter;
108
121
 
109
- emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_RENDER);
122
+ emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
110
123
  // Plot the chart and mutate context.
111
124
  // Make sure that plot chart after container is ready for every time.
112
- plot<T>({ ...keyed, width, height }, selection, library, context)
113
- .then(callback)
114
- .then(() => emitEvent(on, CHART_LIFE_CIRCLE.AFTER_RENDER));
125
+ plot<T>({ ...keyed, width, height }, selection, library, context).then(() => {
126
+ emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
127
+ callback?.();
128
+ });
115
129
 
116
130
  // Return the Group wraps the canvas or svg element.
117
131
  return group;
@@ -121,12 +135,11 @@ export function destroy<T extends G2ViewTree = G2ViewTree>(
121
135
  options: T,
122
136
  context: G2Context = {},
123
137
  ) {
124
- const { on } = options;
125
- const { canvas } = context;
138
+ const { canvas, emitter } = context;
126
139
  if (canvas) {
127
140
  canvas.destroy();
128
141
  }
129
- offEvent(on);
142
+ emitter.off();
130
143
  }
131
144
 
132
145
  function normalizeContainer(container: HTMLElement | string): HTMLElement {
@@ -1,6 +1,13 @@
1
1
  import { Canvas, IAnimation as GAnimation } from '@antv/g';
2
2
  import type { DisplayObject } from '@antv/g';
3
- import { G2Title, GuideComponentPosition, Layout, Primitive } from './common';
3
+ import EventEmitter from '@antv/event-emitter';
4
+ import {
5
+ G2Title,
6
+ G2ViewDescriptor,
7
+ GuideComponentPosition,
8
+ Layout,
9
+ Primitive,
10
+ } from './common';
4
11
  import {
5
12
  G2BaseComponent,
6
13
  StatisticComponent,
@@ -46,9 +53,10 @@ export type G2Library = Record<
46
53
  export type G2Context = {
47
54
  library?: G2Library;
48
55
  canvas?: Canvas;
56
+ emitter?: EventEmitter;
49
57
  group?: DisplayObject;
50
58
  animations?: GAnimation[];
51
- bindAutoFit?: boolean;
59
+ views?: G2ViewDescriptor[];
52
60
  };
53
61
 
54
62
  export type G2View = {
Binary file
@@ -0,0 +1,20 @@
1
+ import { curveStepAfter } from 'd3-shape';
2
+ import { ShapeComponent as SC } from '../../runtime';
3
+ import { Curve } from './curve';
4
+
5
+ export type HVOptions = Record<string, any>;
6
+
7
+ export const HV: SC<HVOptions> = (options) => {
8
+ return (P, value, coordinate, theme) => {
9
+ return Curve({ curve: curveStepAfter, ...options })(
10
+ P,
11
+ value,
12
+ coordinate,
13
+ theme,
14
+ );
15
+ };
16
+ };
17
+
18
+ HV.props = {
19
+ ...Curve.props,
20
+ };
@@ -2,14 +2,14 @@ import { curveStep } from 'd3-shape';
2
2
  import { ShapeComponent as SC } from '../../runtime';
3
3
  import { Curve } from './curve';
4
4
 
5
- export type StepOptions = Record<string, any>;
5
+ export type HVHOptions = Record<string, any>;
6
6
 
7
- export const Step: SC<StepOptions> = (options) => {
7
+ export const HVH: SC<HVHOptions> = (options) => {
8
8
  return (P, value, coordinate, theme) => {
9
9
  return Curve({ curve: curveStep, ...options })(P, value, coordinate, theme);
10
10
  };
11
11
  };
12
12
 
13
- Step.props = {
13
+ HVH.props = {
14
14
  ...Curve.props,
15
15
  };
@@ -0,0 +1,20 @@
1
+ import { curveStepBefore } from 'd3-shape';
2
+ import { ShapeComponent as SC } from '../../runtime';
3
+ import { Curve } from './curve';
4
+
5
+ export type VHOptions = Record<string, any>;
6
+
7
+ export const VH: SC<VHOptions> = (options) => {
8
+ return (P, value, coordinate, theme) => {
9
+ return Curve({ curve: curveStepBefore, ...options })(
10
+ P,
11
+ value,
12
+ coordinate,
13
+ theme,
14
+ );
15
+ };
16
+ };
17
+
18
+ VH.props = {
19
+ ...Curve.props,
20
+ };
@@ -31,7 +31,9 @@ export { Text } from './text/text';
31
31
  export { Badge } from './text/badge';
32
32
  export { Area } from './area/area';
33
33
  export { Smooth as SmoothArea } from './area/smooth';
34
- export { Step } from './area/step';
34
+ export { HVH as HVHArea } from './area/hvh';
35
+ export { VH as VHArea } from './area/vh';
36
+ export { HV as HVArea } from './area/hv';
35
37
  export { Link } from './link/link';
36
38
  export { Smooth as SmoothEdge } from './link/smooth';
37
39
  export { VHV as VHVEdge } from './link/vhv';
@@ -83,7 +85,10 @@ export type { TextOptions } from './text/text';
83
85
  export type { BadgeOptions } from './text/badge';
84
86
  export type { AreaOptions } from './area/area';
85
87
  export type { SmoothOptions as SmoothAreaOptions } from './area/smooth';
86
- export type { StepOptions } from './area/step';
88
+ export type { HVHOptions as HVHAreaOptions } from './area/hvh';
89
+ export type { VHOptions as VHAreaOptions } from './area/vh';
90
+ export type { HVOptions as HVAreaOptions } from './area/hv';
91
+
87
92
  export type { LinkOptions } from './link/link';
88
93
  export type { ImageOptions } from './image/image';
89
94
  export type { PolygonOptions } from './polygon/polygon';
@@ -17,6 +17,72 @@ export type ColorOptions = {
17
17
  [key: string]: any;
18
18
  };
19
19
 
20
+ // Render rect in different coordinate.
21
+ export function rect(
22
+ points,
23
+ value,
24
+ coordinate,
25
+ style: Record<string, any> = {},
26
+ ) {
27
+ const {
28
+ inset = 0,
29
+ radius = 0,
30
+ insetLeft = inset,
31
+ insetTop = inset,
32
+ insetRight = inset,
33
+ insetBottom = inset,
34
+ radiusBottomLeft = radius,
35
+ radiusBottomRight = radius,
36
+ radiusTopLeft = radius,
37
+ radiusTopRight = radius,
38
+ ...rest
39
+ } = style;
40
+ if (!isPolar(coordinate) && !isHelix(coordinate)) {
41
+ const tpShape = !!isTranspose(coordinate);
42
+
43
+ const [p0, , p2] = tpShape ? reorder(points) : points;
44
+ const [x, y] = p0;
45
+ const [width, height] = sub(p2, p0);
46
+ // Deal with width or height is negative.
47
+ const absX = width > 0 ? x : x + width;
48
+ const absY = height > 0 ? y : y + height;
49
+ const absWidth = Math.abs(width);
50
+ const absHeight = Math.abs(height);
51
+ const finalX = absX + insetLeft;
52
+ const finalY = absY + insetTop;
53
+ const finalWidth = absWidth - (insetLeft + insetRight);
54
+ const finalHeight = absHeight - (insetTop + insetBottom);
55
+
56
+ return select(new Rect({}))
57
+ .style('x', finalX)
58
+ .style('y', finalY)
59
+ .style('width', finalWidth)
60
+ .style('height', finalHeight)
61
+ .style('radius', [
62
+ radiusTopLeft,
63
+ radiusTopRight,
64
+ radiusBottomRight,
65
+ radiusBottomLeft,
66
+ ])
67
+ .call(applyStyle, rest)
68
+ .node();
69
+ }
70
+
71
+ // Render path in polar coordinate.
72
+ const { y, y1 } = value;
73
+ const center = coordinate.getCenter() as Vector2;
74
+ const arcObject = getArcObject(coordinate, points, [y, y1]);
75
+ const path = arc()
76
+ .cornerRadius(radius as number)
77
+ .padAngle((inset * Math.PI) / 180);
78
+
79
+ return select(new Path({}))
80
+ .style('path', path(arcObject))
81
+ .style('transform', `translate(${center[0]}, ${center[1]})`)
82
+ .call(applyStyle, rest)
83
+ .node();
84
+ }
85
+
20
86
  /**
21
87
  * Render rect in different coordinate.
22
88
  * Calc arc path based on control points directly rather startAngle, endAngle, innerRadius,
@@ -36,7 +102,6 @@ export const Color: SC<ColorOptions> = (options) => {
36
102
  return (points, value, coordinate, theme) => {
37
103
  const { mark, shape, defaultShape } = value;
38
104
  const {
39
- // [colorAttribute]: defaultColor,
40
105
  defaultColor,
41
106
  radius: defaultRadius = 0,
42
107
  ...defaults
@@ -55,70 +120,37 @@ export const Color: SC<ColorOptions> = (options) => {
55
120
  innerRadiusTopRight = innerRadius,
56
121
  innerRadiusBottomRight = innerRadius,
57
122
  innerRadiusBottomLeft = innerRadius,
123
+ lineWidth = colorAttribute === 'stroke' || stroke ? defaultLineWidth : 0,
58
124
  inset = 0,
59
125
  insetLeft = inset,
60
126
  insetRight = inset,
61
127
  insetBottom = inset,
62
128
  insetTop = inset,
63
- lineWidth = colorAttribute === 'stroke' || stroke ? defaultLineWidth : 0,
64
129
  ...rest
65
130
  } = style;
66
131
  const { color = defaultColor, opacity } = value;
67
132
 
68
- // Render rect in non-polar coordinate.
69
- if (!isPolar(coordinate) && !isHelix(coordinate)) {
70
- const tpShape = !!isTranspose(coordinate);
71
-
72
- const [p0, , p2] = tpShape ? reorder(points) : points;
73
- const [x, y] = p0;
74
- const [width, height] = sub(p2, p0);
75
- // Deal with width or height is negative.
76
- const absX = width > 0 ? x : x + width;
77
- const absY = height > 0 ? y : y + height;
78
- const absWidth = Math.abs(width);
79
- const absHeight = Math.abs(height);
80
- const finalX = absX + insetLeft;
81
- const finalY = absY + insetTop;
82
- const finalWidth = absWidth - (insetLeft + insetRight);
83
- const finalHeight = absHeight - (insetTop + insetBottom);
84
-
85
- return select(new Rect({}))
86
- .call(applyStyle, defaults)
87
- .style('lineWidth', lineWidth)
88
- .style('x', finalX)
89
- .style('y', finalY)
90
- .style('width', finalWidth)
91
- .style('height', finalHeight)
92
- .style('stroke', stroke === undefined ? color : stroke)
93
- .style(toOpacityKey(options), opacity)
94
- .style(colorAttribute, color)
95
- .style('radius', [
96
- first ? radiusTopLeft : innerRadiusTopLeft,
97
- first ? radiusTopRight : innerRadiusTopRight,
98
- last ? radiusBottomRight : innerRadiusBottomRight,
99
- last ? radiusBottomLeft : innerRadiusBottomLeft,
100
- ])
101
- .call(applyStyle, rest)
102
- .node();
103
- }
104
-
105
- // Render path in polar coordinate.
106
- const { y, y1 } = value;
107
- const center = coordinate.getCenter() as Vector2;
108
- const arcObject = getArcObject(coordinate, points, [y, y1]);
109
- const path = arc()
110
- .cornerRadius(radius as number)
111
- .padAngle((inset * Math.PI) / 180);
133
+ // Extended style, which is not supported by native g shape,
134
+ // should apply at first.
135
+ const extendedStyle = {
136
+ radius,
137
+ radiusTopLeft: first ? radiusTopLeft : innerRadiusTopLeft,
138
+ radiusTopRight: first ? radiusTopRight : innerRadiusTopRight,
139
+ radiusBottomRight: last ? radiusBottomRight : innerRadiusBottomRight,
140
+ radiusBottomLeft: last ? radiusBottomLeft : innerRadiusBottomLeft,
141
+ inset,
142
+ insetLeft,
143
+ insetRight,
144
+ insetBottom,
145
+ insetTop,
146
+ };
112
147
 
113
- return select(new Path({}))
114
- .call(applyStyle, defaults)
115
- .style('path', path(arcObject))
116
- .style('transform', `translate(${center[0]}, ${center[1]})`)
117
- .style('stroke', color || stroke)
118
- .style('lineWidth', lineWidth)
119
- .style(colorAttribute, color)
148
+ return select(rect(points, value, coordinate, extendedStyle))
149
+ .call(applyStyle, { ...defaults, ...rest })
120
150
  .style(toOpacityKey(options), opacity)
121
- .call(applyStyle, style)
151
+ .style(colorAttribute, color)
152
+ .style('lineWidth', lineWidth)
153
+ .style('stroke', stroke === undefined ? color : stroke)
122
154
  .node();
123
155
  };
124
156
  };
@@ -61,7 +61,6 @@ export type ViewComposition = {
61
61
  axis?: Record<string, any>;
62
62
  // @todo
63
63
  legend?: Record<string, any>;
64
- on?: Record<string, EventType | EventType[]>;
65
64
  // @todo
66
65
  style?: Record<string, any>;
67
66
  clip?: boolean;
@@ -12,9 +12,10 @@ export type Interaction =
12
12
  | ElementSelectInteraction
13
13
  | TooltipInteraction
14
14
  | FisheyeInteraction
15
- | ChartIndex
15
+ | ChartIndexInteraction
16
16
  | CustomInteraction
17
17
  | LegendFilterInteraction
18
+ | LegendHighlightInteraction
18
19
  | BrushHighlightInteraction
19
20
  | BrushXHighlightInteraction
20
21
  | BrushYHighlightInteraction
@@ -45,6 +46,7 @@ export type InteractionTypes =
45
46
  | 'fisheye'
46
47
  | 'tooltip'
47
48
  | 'legendFilter'
49
+ | 'legendHighlight'
48
50
  | 'brushXHighlight'
49
51
  | 'brushYHighlight'
50
52
  | 'brushHighlight'
@@ -125,33 +127,54 @@ export type ElementHighlightInteraction = {
125
127
  type?: 'elementHighlight';
126
128
  // @todo: Style supported by G.
127
129
  link?: boolean;
128
- } & Record<`${'link' | 'highlighted' | 'unhighlighted'}${any}`, any>;
130
+ background?: boolean;
131
+ offset?: number;
132
+ } & Record<
133
+ `${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
134
+ any
135
+ >;
129
136
 
130
137
  export type ElementSelectInteraction = {
131
138
  type?: 'elementSelect';
132
139
  single?: boolean;
133
- } & Record<`${'selected' | 'link' | 'unselected'}${any}`, any>;
140
+ background?: true;
141
+ offset?: number;
142
+ } & Record<`${'selected' | 'link' | 'unselected' | 'background'}${any}`, any>;
134
143
 
135
144
  export type ElementSelectByColorInteraction = {
136
145
  type?: 'elementSelectByColor';
137
146
  single?: boolean;
147
+ offset?: number;
138
148
  } & Record<`${'selected' | 'link' | 'unselected'}${any}`, any>;
139
149
 
140
150
  export type ElementSelectByXInteraction = {
141
151
  type?: 'elementSelectByX';
142
152
  single?: boolean;
143
- } & Record<`${'selected' | 'link' | 'unselected'}${any}`, any>;
153
+ background?: true;
154
+ offset?: number;
155
+ } & Record<`${'selected' | 'link' | 'unselected' | 'background'}${any}`, any>;
144
156
 
145
157
  export type ElementHighlightByXInteraction = {
146
158
  type?: 'elementHighlightByX';
147
159
  x?: string;
148
160
  link?: boolean;
149
- } & Record<`${'link' | 'highlighted' | 'unhighlighted'}${any}`, any>;
161
+ background?: boolean;
162
+ offset?: number;
163
+ } & Record<
164
+ `${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
165
+ any
166
+ >;
150
167
 
151
168
  export type ElementHighlightByColorInteraction = {
152
169
  type?: 'elementHighlightByColor';
153
170
  color?: string;
154
- } & Record<`${'link' | 'highlighted' | 'unhighlighted'}${any}`, any>;
171
+ background?: boolean;
172
+ link?: boolean;
173
+ offset?: number;
174
+ } & Record<
175
+ `${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
176
+ any
177
+ >;
155
178
 
156
179
  export type LegendFilterInteraction = {
157
180
  type?: 'legendFilter';
@@ -159,7 +182,12 @@ export type LegendFilterInteraction = {
159
182
  [key: string]: any; // @todo
160
183
  } & Record<`${'marker' | 'label'}Unselected${any}`, any>;
161
184
 
162
- export type ChartIndex = {
185
+ export type LegendHighlightInteraction = {
186
+ type?: 'legendHighlight';
187
+ [key: string]: any; // @todo
188
+ } & Record<`${'marker' | 'label'}Unhighlighted${any}`, any>;
189
+
190
+ export type ChartIndexInteraction = {
163
191
  type?: 'chartIndex';
164
192
  wait?: number;
165
193
  leading?: boolean;
@@ -181,10 +209,6 @@ export type LegendActiveInteraction = {
181
209
  type?: 'legendActive';
182
210
  };
183
211
 
184
- export type LegendHighlightInteraction = {
185
- type?: 'legendHighlight';
186
- };
187
-
188
212
  export type TooltipInteraction = Omit<TooltipAction, 'type'> & {
189
213
  type?: 'tooltip';
190
214
  shared?: boolean;
@@ -254,11 +254,36 @@ export type BinTransform = {
254
254
  thresholdsY?: number;
255
255
  } & { [key in ChannelTypes]?: Reducer };
256
256
 
257
+ export type SampleFunction = (
258
+ I: number[],
259
+ X: number[],
260
+ Y: number[],
261
+ thresholds: number,
262
+ ) => number[];
263
+
257
264
  export type SampleTransform = {
258
265
  type?: 'sample';
259
- groupBy?: string | string[];
266
+ /**
267
+ * Sample strategy. Default is 'median'.
268
+ */
269
+ strategy?:
270
+ | 'lttb'
271
+ | 'median'
272
+ | 'max'
273
+ | 'min'
274
+ | 'first'
275
+ | 'last'
276
+ | SampleFunction;
277
+ /**
278
+ * The thresholds of sample, when data size great then thresholds, sample will take effect.
279
+ * Default is 2000.
280
+ */
260
281
  thresholds?: number;
261
- } & { [key in ChannelTypes]?: Reducer };
282
+ /**
283
+ * Group data by fields, for series data.
284
+ */
285
+ groupBy?: string | string[];
286
+ };
262
287
 
263
288
  export type FilterTransform = {
264
289
  type?: 'filter';
@@ -114,7 +114,9 @@ import {
114
114
  Connector as ConnectorShape,
115
115
  Area,
116
116
  SmoothArea,
117
- Step,
117
+ HVHArea,
118
+ VHArea,
119
+ HVArea,
118
120
  SmoothEdge,
119
121
  VHVEdge,
120
122
  Arc,
@@ -159,10 +161,6 @@ import {
159
161
  GrowInY,
160
162
  } from '../animation';
161
163
  import {
162
- // ElementHighlight,
163
- // ElementSelected,
164
- // Tooltip,
165
- // Fisheye as FisheyeInteraction,
166
164
  ElementHighlight,
167
165
  ElementHighlightByX,
168
166
  ElementHighlightByColor,
@@ -173,6 +171,7 @@ import {
173
171
  Fisheye as ChartFisheye,
174
172
  Tooltip,
175
173
  LegendFilter,
174
+ LegendHighlight,
176
175
  BrushHighlight,
177
176
  BrushXHighlight,
178
177
  BrushYHighlight,
@@ -447,7 +446,9 @@ export function createLibrary(): G2Library {
447
446
  'shape.text.text': Text,
448
447
  'shape.area.area': Area,
449
448
  'shape.area.smooth': SmoothArea,
450
- 'shape.area.step': Step,
449
+ 'shape.area.hvh': HVHArea,
450
+ 'shape.area.vh': VHArea,
451
+ 'shape.area.hv': HVArea,
451
452
  'shape.link.smooth': SmoothEdge,
452
453
  'shape.link.vhv': VHVEdge,
453
454
  'shape.link.arc': Arc,
@@ -503,6 +504,7 @@ export function createLibrary(): G2Library {
503
504
  'interaction.chartIndex': ChartIndex,
504
505
  'interaction.tooltip': Tooltip,
505
506
  'interaction.legendFilter': LegendFilter,
507
+ 'interaction.legendHighlight': LegendHighlight,
506
508
  'interaction.brushHighlight': BrushHighlight,
507
509
  'interaction.brushXHighlight': BrushXHighlight,
508
510
  'interaction.brushYHighlight': BrushYHighlight,
@@ -1,14 +1,46 @@
1
+ // @ts-ignore medianIndex exist in d3-array@3.2.0, but @types/d3-array Expired.
2
+ import { maxIndex, minIndex, medianIndex } from 'd3-array';
1
3
  import { TransformComponent as TC, Primitive } from '../runtime';
2
- import { SampleTransform } from '../spec';
4
+ import { SampleTransform, SampleFunction } from '../spec';
3
5
  import { createGroups } from './utils/order';
4
- import { GroupN } from './groupN';
6
+ import { columnOf } from './utils/helper';
7
+ import { lttb } from './utils/lttb';
5
8
 
6
9
  export type SampleOptions = Omit<SampleTransform, 'type'>;
7
10
 
11
+ function normalizeSample(
12
+ strategy: SampleTransform['strategy'],
13
+ ): SampleFunction {
14
+ if (typeof strategy === 'function') return strategy;
15
+ if (strategy === 'lttb') return lttb;
16
+
17
+ const strategies = {
18
+ first: (f: number[]) => [f[0]],
19
+ last: (f: number[]) => [f[f.length - 1]],
20
+ min: (f: number[], X: number[], Y: number[]) => [
21
+ f[minIndex(f, (i) => Y[i])],
22
+ ],
23
+ max: (f: number[], X: number[], Y: number[]) => [
24
+ f[maxIndex(f, (i) => Y[i])],
25
+ ],
26
+ median: (f: number[], X: number[], Y: number[]) => [
27
+ f[medianIndex(f, (i) => Y[i])],
28
+ ],
29
+ };
30
+ const sampleFunction = strategies[strategy] || strategies.median;
31
+ return (I: number[], X: number[], Y: number[], thresholds: number) => {
32
+ // Sepreate group to frames, then sample each frame.
33
+ // Keep more data as possible.
34
+ const frameSize = Math.max(1, Math.floor(I.length / thresholds));
35
+ const frames = getFrames(I, frameSize);
36
+ return frames.flatMap((frame) => sampleFunction(frame, X, Y));
37
+ };
38
+ }
39
+
8
40
  /**
9
41
  * Split the array into frame with each frameSize.
10
42
  */
11
- function getFrames(I: Primitive[], frameSize: number) {
43
+ function getFrames(I: Primitive[], frameSize: number): number[][] {
12
44
  const size = I.length;
13
45
  const frames = [];
14
46
  let i = 0;
@@ -23,22 +55,26 @@ function getFrames(I: Primitive[], frameSize: number) {
23
55
  * sample data for each group when data.length >= threshold(default = 2000).
24
56
  */
25
57
  export const Sample: TC<SampleOptions> = (options = {}) => {
26
- const { groupBy: by, thresholds = 2000, ...rest } = options;
27
-
28
- const groupBy = (I, mark) => {
29
- const groups = createGroups(by, I, mark);
30
- // Skip
31
- if (groups.every((g) => g.length <= thresholds)) return null;
32
-
33
- return groups.flatMap((g) => {
34
- // Keep more data as possible.
35
- // After sampled, the length of each group.
36
- const frameSize = Math.max(1, Math.floor(g.length / thresholds));
37
- const frames = getFrames(g, frameSize);
38
- return frames;
39
- });
58
+ const {
59
+ strategy = 'median',
60
+ thresholds = 2000,
61
+ groupBy = 'series',
62
+ } = options;
63
+ const sampleFunction = normalizeSample(strategy);
64
+
65
+ return (I, mark) => {
66
+ const { encode } = mark;
67
+ const groups = createGroups(groupBy, I, mark);
68
+ const [X] = columnOf(encode, 'x');
69
+ const [Y] = columnOf(encode, 'y');
70
+
71
+ return [
72
+ groups.flatMap((g) =>
73
+ sampleFunction(g, X as number[], Y as number[], thresholds),
74
+ ),
75
+ mark,
76
+ ];
40
77
  };
41
- return GroupN({ ...rest, groupBy });
42
78
  };
43
79
 
44
80
  Sample.props = {};