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

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 (313) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +4 -4
  3. package/esm/animation/morphing.js +22 -2
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.d.ts +3 -2
  6. package/esm/api/chart.js +6 -4
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/mark/base.d.ts +1 -1
  9. package/esm/api/mark/base.js +1 -1
  10. package/esm/api/mark/base.js.map +1 -1
  11. package/esm/component/axis.d.ts +5 -7
  12. package/esm/component/axis.js +126 -98
  13. package/esm/component/axis.js.map +1 -1
  14. package/esm/component/axisArc.d.ts +7 -0
  15. package/esm/component/axisArc.js +9 -0
  16. package/esm/component/axisArc.js.map +1 -0
  17. package/esm/component/axisRadar.d.ts +9 -0
  18. package/esm/component/axisRadar.js +46 -0
  19. package/esm/component/axisRadar.js.map +1 -0
  20. package/esm/component/axisX.d.ts +2 -1
  21. package/esm/component/axisX.js +5 -4
  22. package/esm/component/axisX.js.map +1 -1
  23. package/esm/component/axisY.d.ts +1 -1
  24. package/esm/component/axisY.js +4 -4
  25. package/esm/component/axisY.js.map +1 -1
  26. package/esm/component/index.d.ts +8 -0
  27. package/esm/component/index.js +5 -0
  28. package/esm/component/index.js.map +1 -1
  29. package/esm/component/legendCategory.d.ts +5 -3
  30. package/esm/component/legendCategory.js +80 -36
  31. package/esm/component/legendCategory.js.map +1 -1
  32. package/esm/component/legendContinuous.d.ts +3 -2
  33. package/esm/component/legendContinuous.js +66 -12
  34. package/esm/component/legendContinuous.js.map +1 -1
  35. package/esm/component/legendContinuousBlock.d.ts +4 -0
  36. package/esm/component/legendContinuousBlock.js +6 -0
  37. package/esm/component/legendContinuousBlock.js.map +1 -0
  38. package/esm/component/legendContinuousBlockSize.d.ts +4 -0
  39. package/esm/component/legendContinuousBlockSize.js +6 -0
  40. package/esm/component/legendContinuousBlockSize.js.map +1 -0
  41. package/esm/component/legendContinuousSize.d.ts +4 -0
  42. package/esm/component/legendContinuousSize.js +10 -0
  43. package/esm/component/legendContinuousSize.js.map +1 -0
  44. package/esm/component/scrollbar.js +1 -1
  45. package/esm/component/scrollbar.js.map +1 -1
  46. package/esm/component/slider.js +1 -1
  47. package/esm/component/slider.js.map +1 -1
  48. package/esm/component/title.js +1 -1
  49. package/esm/component/title.js.map +1 -1
  50. package/esm/component/utils.d.ts +12 -0
  51. package/esm/component/utils.js +35 -0
  52. package/esm/component/utils.js.map +1 -1
  53. package/esm/composition/facetCircle.js +1 -1
  54. package/esm/composition/facetCircle.js.map +1 -1
  55. package/esm/coordinate/index.d.ts +3 -3
  56. package/esm/coordinate/index.js +3 -3
  57. package/esm/coordinate/index.js.map +1 -1
  58. package/esm/coordinate/polar.d.ts +6 -0
  59. package/esm/coordinate/polar.js +18 -6
  60. package/esm/coordinate/polar.js.map +1 -1
  61. package/esm/coordinate/radial.d.ts +6 -0
  62. package/esm/coordinate/radial.js +17 -5
  63. package/esm/coordinate/radial.js.map +1 -1
  64. package/esm/coordinate/theta.d.ts +7 -0
  65. package/esm/coordinate/theta.js +16 -4
  66. package/esm/coordinate/theta.js.map +1 -1
  67. package/esm/interaction/index.d.ts +1 -0
  68. package/esm/interaction/index.js +1 -0
  69. package/esm/interaction/index.js.map +1 -1
  70. package/esm/interaction/native/brushAxisHighlight.js +6 -1
  71. package/esm/interaction/native/brushAxisHighlight.js.map +1 -1
  72. package/esm/interaction/native/brushFilter.js +1 -1
  73. package/esm/interaction/native/brushFilter.js.map +1 -1
  74. package/esm/interaction/native/legendFilter.d.ts +2 -0
  75. package/esm/interaction/native/legendFilter.js +19 -3
  76. package/esm/interaction/native/legendFilter.js.map +1 -1
  77. package/esm/interaction/native/legendHighlight.js +2 -3
  78. package/esm/interaction/native/legendHighlight.js.map +1 -1
  79. package/esm/interaction/native/poptip.d.ts +5 -0
  80. package/esm/interaction/native/poptip.js +91 -0
  81. package/esm/interaction/native/poptip.js.map +1 -0
  82. package/esm/mark/pack.js +0 -1
  83. package/esm/mark/pack.js.map +1 -1
  84. package/esm/mark/treemap.js +0 -1
  85. package/esm/mark/treemap.js.map +1 -1
  86. package/esm/runtime/component.d.ts +3 -0
  87. package/esm/runtime/component.js +246 -103
  88. package/esm/runtime/component.js.map +1 -1
  89. package/esm/runtime/coordinate.d.ts +11 -0
  90. package/esm/runtime/coordinate.js +23 -16
  91. package/esm/runtime/coordinate.js.map +1 -1
  92. package/esm/runtime/layout.d.ts +1 -1
  93. package/esm/runtime/layout.js +145 -76
  94. package/esm/runtime/layout.js.map +1 -1
  95. package/esm/runtime/plot.js +1 -0
  96. package/esm/runtime/plot.js.map +1 -1
  97. package/esm/runtime/scale.d.ts +2 -1
  98. package/esm/runtime/scale.js +35 -0
  99. package/esm/runtime/scale.js.map +1 -1
  100. package/esm/runtime/transform.js +1 -1
  101. package/esm/runtime/transform.js.map +1 -1
  102. package/esm/runtime/types/common.d.ts +11 -2
  103. package/esm/runtime/types/component.d.ts +9 -7
  104. package/esm/runtime/types/options.d.ts +5 -5
  105. package/esm/runtime/types/scale.d.ts +18 -0
  106. package/esm/runtime/types/scale.js +19 -0
  107. package/esm/runtime/types/scale.js.map +1 -0
  108. package/esm/runtime/types/theme.d.ts +2 -1
  109. package/esm/shape/connector/connector.js +1 -1
  110. package/esm/shape/utils.js.map +1 -1
  111. package/esm/spec/geometry.d.ts +1 -1
  112. package/esm/spec/interaction.d.ts +11 -6
  113. package/esm/stdlib/index.js +3 -3
  114. package/esm/stdlib/index.js.map +1 -1
  115. package/esm/theme/academy.js +10 -4
  116. package/esm/theme/academy.js.map +1 -1
  117. package/esm/theme/dark.js +10 -4
  118. package/esm/theme/dark.js.map +1 -1
  119. package/esm/theme/light.js +12 -4
  120. package/esm/theme/light.js.map +1 -1
  121. package/esm/utils/angle.d.ts +2 -0
  122. package/esm/utils/angle.js +7 -0
  123. package/esm/utils/angle.js.map +1 -0
  124. package/esm/utils/array.d.ts +8 -0
  125. package/esm/utils/array.js +35 -0
  126. package/esm/utils/array.js.map +1 -1
  127. package/esm/utils/coordinate.d.ts +4 -0
  128. package/esm/utils/coordinate.js +19 -0
  129. package/esm/utils/coordinate.js.map +1 -1
  130. package/lib/animation/morphing.js +22 -2
  131. package/lib/animation/morphing.js.map +1 -1
  132. package/lib/api/chart.d.ts +3 -2
  133. package/lib/api/chart.js +6 -4
  134. package/lib/api/chart.js.map +1 -1
  135. package/lib/api/mark/base.d.ts +1 -1
  136. package/lib/api/mark/base.js +1 -1
  137. package/lib/api/mark/base.js.map +1 -1
  138. package/lib/component/axis.d.ts +5 -7
  139. package/lib/component/axis.js +127 -100
  140. package/lib/component/axis.js.map +1 -1
  141. package/lib/component/axisArc.d.ts +7 -0
  142. package/lib/component/axisArc.js +13 -0
  143. package/lib/component/axisArc.js.map +1 -0
  144. package/lib/component/axisRadar.d.ts +9 -0
  145. package/lib/component/axisRadar.js +50 -0
  146. package/lib/component/axisRadar.js.map +1 -0
  147. package/lib/component/axisX.d.ts +2 -1
  148. package/lib/component/axisX.js +6 -4
  149. package/lib/component/axisX.js.map +1 -1
  150. package/lib/component/axisY.d.ts +1 -1
  151. package/lib/component/axisY.js +3 -3
  152. package/lib/component/axisY.js.map +1 -1
  153. package/lib/component/index.d.ts +8 -0
  154. package/lib/component/index.js +12 -1
  155. package/lib/component/index.js.map +1 -1
  156. package/lib/component/legendCategory.d.ts +5 -3
  157. package/lib/component/legendCategory.js +79 -35
  158. package/lib/component/legendCategory.js.map +1 -1
  159. package/lib/component/legendContinuous.d.ts +3 -2
  160. package/lib/component/legendContinuous.js +65 -11
  161. package/lib/component/legendContinuous.js.map +1 -1
  162. package/lib/component/legendContinuousBlock.d.ts +4 -0
  163. package/lib/component/legendContinuousBlock.js +10 -0
  164. package/lib/component/legendContinuousBlock.js.map +1 -0
  165. package/lib/component/legendContinuousBlockSize.d.ts +4 -0
  166. package/lib/component/legendContinuousBlockSize.js +10 -0
  167. package/lib/component/legendContinuousBlockSize.js.map +1 -0
  168. package/lib/component/legendContinuousSize.d.ts +4 -0
  169. package/lib/component/legendContinuousSize.js +14 -0
  170. package/lib/component/legendContinuousSize.js.map +1 -0
  171. package/lib/component/scrollbar.js +1 -1
  172. package/lib/component/scrollbar.js.map +1 -1
  173. package/lib/component/slider.js +1 -1
  174. package/lib/component/slider.js.map +1 -1
  175. package/lib/component/title.js +1 -1
  176. package/lib/component/title.js.map +1 -1
  177. package/lib/component/utils.d.ts +12 -0
  178. package/lib/component/utils.js +39 -1
  179. package/lib/component/utils.js.map +1 -1
  180. package/lib/composition/facetCircle.js +1 -1
  181. package/lib/composition/facetCircle.js.map +1 -1
  182. package/lib/coordinate/index.d.ts +3 -3
  183. package/lib/coordinate/index.js +4 -1
  184. package/lib/coordinate/index.js.map +1 -1
  185. package/lib/coordinate/polar.d.ts +6 -0
  186. package/lib/coordinate/polar.js +20 -7
  187. package/lib/coordinate/polar.js.map +1 -1
  188. package/lib/coordinate/radial.d.ts +6 -0
  189. package/lib/coordinate/radial.js +19 -6
  190. package/lib/coordinate/radial.js.map +1 -1
  191. package/lib/coordinate/theta.d.ts +7 -0
  192. package/lib/coordinate/theta.js +18 -5
  193. package/lib/coordinate/theta.js.map +1 -1
  194. package/lib/interaction/index.d.ts +1 -0
  195. package/lib/interaction/index.js +3 -1
  196. package/lib/interaction/index.js.map +1 -1
  197. package/lib/interaction/native/brushAxisHighlight.js +6 -1
  198. package/lib/interaction/native/brushAxisHighlight.js.map +1 -1
  199. package/lib/interaction/native/brushFilter.js +1 -1
  200. package/lib/interaction/native/brushFilter.js.map +1 -1
  201. package/lib/interaction/native/legendFilter.d.ts +2 -0
  202. package/lib/interaction/native/legendFilter.js +22 -4
  203. package/lib/interaction/native/legendFilter.js.map +1 -1
  204. package/lib/interaction/native/legendHighlight.js +1 -2
  205. package/lib/interaction/native/legendHighlight.js.map +1 -1
  206. package/lib/interaction/native/poptip.d.ts +5 -0
  207. package/lib/interaction/native/poptip.js +95 -0
  208. package/lib/interaction/native/poptip.js.map +1 -0
  209. package/lib/mark/pack.js +0 -1
  210. package/lib/mark/pack.js.map +1 -1
  211. package/lib/mark/treemap.js +0 -1
  212. package/lib/mark/treemap.js.map +1 -1
  213. package/lib/runtime/component.d.ts +3 -0
  214. package/lib/runtime/component.js +250 -107
  215. package/lib/runtime/component.js.map +1 -1
  216. package/lib/runtime/coordinate.d.ts +11 -0
  217. package/lib/runtime/coordinate.js +26 -17
  218. package/lib/runtime/coordinate.js.map +1 -1
  219. package/lib/runtime/layout.d.ts +1 -1
  220. package/lib/runtime/layout.js +146 -77
  221. package/lib/runtime/layout.js.map +1 -1
  222. package/lib/runtime/plot.js +1 -0
  223. package/lib/runtime/plot.js.map +1 -1
  224. package/lib/runtime/scale.d.ts +2 -1
  225. package/lib/runtime/scale.js +37 -1
  226. package/lib/runtime/scale.js.map +1 -1
  227. package/lib/runtime/transform.js +1 -1
  228. package/lib/runtime/transform.js.map +1 -1
  229. package/lib/runtime/types/common.d.ts +11 -2
  230. package/lib/runtime/types/component.d.ts +9 -7
  231. package/lib/runtime/types/options.d.ts +5 -5
  232. package/lib/runtime/types/scale.d.ts +18 -0
  233. package/lib/runtime/types/scale.js +22 -0
  234. package/lib/runtime/types/scale.js.map +1 -0
  235. package/lib/runtime/types/theme.d.ts +2 -1
  236. package/lib/shape/connector/connector.js +1 -1
  237. package/lib/shape/utils.js.map +1 -1
  238. package/lib/spec/geometry.d.ts +1 -1
  239. package/lib/spec/interaction.d.ts +11 -6
  240. package/lib/stdlib/index.js +1 -1
  241. package/lib/stdlib/index.js.map +1 -1
  242. package/lib/theme/academy.js +10 -4
  243. package/lib/theme/academy.js.map +1 -1
  244. package/lib/theme/dark.js +10 -4
  245. package/lib/theme/dark.js.map +1 -1
  246. package/lib/theme/light.js +12 -4
  247. package/lib/theme/light.js.map +1 -1
  248. package/lib/utils/angle.d.ts +2 -0
  249. package/lib/utils/angle.js +12 -0
  250. package/lib/utils/angle.js.map +1 -0
  251. package/lib/utils/array.d.ts +8 -0
  252. package/lib/utils/array.js +38 -1
  253. package/lib/utils/array.js.map +1 -1
  254. package/lib/utils/coordinate.d.ts +4 -0
  255. package/lib/utils/coordinate.js +24 -1
  256. package/lib/utils/coordinate.js.map +1 -1
  257. package/package.json +5 -6
  258. package/src/animation/morphing.ts +23 -2
  259. package/src/api/chart.ts +8 -6
  260. package/src/api/mark/base.ts +1 -1
  261. package/src/component/axis.ts +199 -125
  262. package/src/component/axisArc.ts +16 -0
  263. package/src/component/axisRadar.ts +73 -0
  264. package/src/component/axisX.ts +7 -4
  265. package/src/component/axisY.ts +4 -4
  266. package/src/component/index.ts +8 -0
  267. package/src/component/legendCategory.ts +156 -35
  268. package/src/component/legendContinuous.ts +121 -30
  269. package/src/component/legendContinuousBlock.ts +17 -0
  270. package/src/component/legendContinuousBlockSize.ts +22 -0
  271. package/src/component/legendContinuousSize.ts +27 -0
  272. package/src/component/scrollbar.ts +1 -1
  273. package/src/component/slider.ts +1 -1
  274. package/src/component/title.ts +1 -1
  275. package/src/component/utils.ts +46 -0
  276. package/src/composition/facetCircle.ts +1 -1
  277. package/src/coordinate/index.ts +3 -3
  278. package/src/coordinate/polar.ts +19 -11
  279. package/src/coordinate/radial.ts +19 -10
  280. package/src/coordinate/theta.ts +18 -9
  281. package/src/interaction/index.ts +1 -0
  282. package/src/interaction/native/brushAxisHighlight.ts +9 -1
  283. package/src/interaction/native/brushFilter.ts +1 -1
  284. package/src/interaction/native/legendFilter.ts +21 -3
  285. package/src/interaction/native/legendHighlight.ts +2 -3
  286. package/src/interaction/native/poptip.ts +87 -0
  287. package/src/mark/pack.ts +0 -1
  288. package/src/mark/treemap.ts +0 -1
  289. package/src/runtime/component.ts +335 -124
  290. package/src/runtime/coordinate.ts +29 -16
  291. package/src/runtime/layout.ts +206 -97
  292. package/src/runtime/plot.ts +1 -0
  293. package/src/runtime/scale.ts +41 -0
  294. package/src/runtime/transform.ts +3 -0
  295. package/src/runtime/types/common.ts +23 -10
  296. package/src/runtime/types/component.ts +19 -10
  297. package/src/runtime/types/options.ts +15 -15
  298. package/src/runtime/types/scale.ts +20 -0
  299. package/src/runtime/types/theme.ts +2 -1
  300. package/src/shape/connector/connector.ts +1 -1
  301. package/src/shape/utils.ts +2 -0
  302. package/src/spec/geometry.ts +3 -1
  303. package/src/spec/interaction.ts +16 -8
  304. package/src/stdlib/index.ts +14 -0
  305. package/src/theme/academy.ts +10 -4
  306. package/src/theme/dark.ts +10 -4
  307. package/src/theme/light.ts +12 -4
  308. package/src/utils/angle.ts +7 -0
  309. package/src/utils/array.ts +39 -0
  310. package/src/utils/coordinate.ts +29 -0
  311. package/src/.DS_Store +0 -0
  312. package/src/data/.DS_Store +0 -0
  313. package/src/shape/.DS_Store +0 -0
@@ -1,13 +1,16 @@
1
1
  import { Coordinate } from '@antv/coord';
2
- import { group, ascending } from 'd3-array';
2
+ import { ascending, group } from 'd3-array';
3
+ import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
3
4
  import { capitalizeFirst } from '../utils/helper';
5
+ import { divide } from '../utils/array';
4
6
  import {
5
- GuideComponentPosition,
6
- Section,
7
+ GuideComponentPosition as GCP,
8
+ GuideComponentOrientation as GCO,
7
9
  Layout,
10
+ Section,
8
11
  SectionArea,
9
12
  } from './types/common';
10
- import { G2View, G2GuideComponentOptions } from './types/options';
13
+ import { G2GuideComponentOptions, G2View } from './types/options';
11
14
 
12
15
  export function computeLayout(
13
16
  components: G2GuideComponentOptions[],
@@ -31,6 +34,7 @@ export function computeLayout(
31
34
  marginTop = margin,
32
35
  marginRight = margin,
33
36
  } = options;
37
+
34
38
  return {
35
39
  ...padding,
36
40
  width,
@@ -57,11 +61,15 @@ function computePadding(
57
61
  components: G2GuideComponentOptions[],
58
62
  options: G2View,
59
63
  ) {
60
- const positions: GuideComponentPosition[] = [
64
+ const positions: GCP[] = [
61
65
  'left',
62
66
  'right',
63
67
  'top',
64
68
  'bottom',
69
+ 'top-left',
70
+ 'top-right',
71
+ 'bottom-left',
72
+ 'bottom-right',
65
73
  ];
66
74
  const positionComponents = group(components, (d) => d.position);
67
75
  const {
@@ -119,40 +127,179 @@ export function placeComponents(
119
127
  const pb = paddingBottom + marginBottom;
120
128
 
121
129
  const section: Section = {
122
- top: [pl, 0, innerWidth, pt, 0, true, ascending],
123
- right: [width - pr, pt, pr, innerHeight, 1, false, ascending],
124
- bottom: [pl, height - pb, innerWidth, pb, 0, false, ascending],
125
- left: [0, pt, pl, innerHeight, 1, true, ascending],
126
- centerVertical: [pl, pt, innerWidth, innerHeight, -1, null, null],
127
- centerHorizontal: [pl, pt, innerWidth, innerHeight, -1, null, null],
128
- arc: [pl, pt, innerWidth, innerHeight, -1, null, null],
129
- arcY: [pl, pt, innerWidth, innerHeight, -1, null, null],
130
- arcInner: [pl, pt, innerWidth, innerHeight, -1, null, null],
131
- center: [pl, pt, innerWidth, innerHeight, -1, null, null],
132
- arcCenter: [pl, pt, innerWidth, innerHeight, -1, null, null],
130
+ top: [pl, 0, innerWidth, pt, 'vertical', true, ascending],
131
+ right: [width - pr, pt, pr, innerHeight, 'horizontal', false, ascending],
132
+ bottom: [pl, height - pb, innerWidth, pb, 'vertical', false, ascending],
133
+ left: [0, pt, pl, innerHeight, 'horizontal', true, ascending],
134
+ 'top-left': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
135
+ 'top-right': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
136
+ 'bottom-left': [
137
+ pl,
138
+ height - pb,
139
+ innerWidth,
140
+ pb,
141
+ 'vertical',
142
+ false,
143
+ ascending,
144
+ ],
145
+ 'bottom-right': [
146
+ pl,
147
+ height - pb,
148
+ innerWidth,
149
+ pb,
150
+ 'vertical',
151
+ false,
152
+ ascending,
153
+ ],
154
+ center: [pl, pt, innerWidth, innerHeight, 'center', null, null],
155
+ inner: [pl, pt, innerWidth, innerHeight, 'center', null, null],
156
+ outer: [pl, pt, innerWidth, innerHeight, 'center', null, null],
133
157
  };
158
+ for (const [position, components] of positionComponents.entries()) {
159
+ const area = section[position];
160
+
161
+ /**
162
+ * @description non-entity components: axis in the center, inner, outer, component in the center
163
+ * @description entity components: other components
164
+ * @description no volumn components take up no extra space
165
+ */
166
+
167
+ const [nonEntityComponents, entityComponents] = divide(
168
+ components,
169
+ (component) => {
170
+ if (typeof component.type !== 'string') return false;
171
+ if (position === 'center') return true;
172
+ if (
173
+ component.type.startsWith('axis') &&
174
+ ['inner', 'outer'].includes(position)
175
+ ) {
176
+ return true;
177
+ }
178
+ return false;
179
+ },
180
+ );
134
181
 
135
- for (const [key, components] of positionComponents.entries()) {
136
- const area = section[key];
137
- if (key === 'centerVertical') {
138
- placeCenterVertical(components, coordinate, area);
139
- } else if (key === 'centerHorizontal') {
140
- placeCenterHorizontal(components, coordinate, area);
141
- } else if (key === 'arc') {
142
- placeArc(components, coordinate, area);
143
- } else if (key === 'arcY') {
144
- placeArcY(components, coordinate, area);
145
- } else if (key === 'arcInner') {
146
- placeArcInner(components, coordinate, area);
147
- } else if (key === 'arcCenter') {
148
- placeArcCenter(components, coordinate, area);
149
- } else {
182
+ if (nonEntityComponents.length) {
183
+ placeNonEntityComponents(nonEntityComponents, coordinate, area, position);
184
+ }
185
+ if (entityComponents.length) {
150
186
  placePaddingArea(components, coordinate, area);
151
187
  }
152
188
  }
153
189
  }
154
190
 
155
- function placeCenterVertical(
191
+ function placeNonEntityComponents(
192
+ components: G2GuideComponentOptions[],
193
+ coordinate: Coordinate,
194
+ area: SectionArea,
195
+ position: GCP,
196
+ ) {
197
+ const [axisComponents, nonAxisComponents] = divide(
198
+ components,
199
+ (component) => {
200
+ if (
201
+ typeof component.type === 'string' &&
202
+ component.type.startsWith('axis')
203
+ ) {
204
+ return true;
205
+ }
206
+ return false;
207
+ },
208
+ );
209
+
210
+ placeNonEntityAxis(axisComponents, coordinate, area, position);
211
+ // in current stage, only legend component which located in the center can be placed
212
+ placeCenter(nonAxisComponents, coordinate, area);
213
+ }
214
+
215
+ function placeNonEntityAxis(
216
+ components: G2GuideComponentOptions[],
217
+ coordinate: Coordinate,
218
+ area: SectionArea,
219
+ position: GCP,
220
+ ) {
221
+ if (position === 'center') {
222
+ if (isRadar(coordinate)) {
223
+ placeAxisRadar(components, coordinate, area, position);
224
+ } else if (isPolar(coordinate)) {
225
+ placeArcLinear(components, coordinate, area);
226
+ } else if (isParallel(coordinate)) {
227
+ placeAxisParallel(
228
+ components,
229
+ coordinate,
230
+ area,
231
+ components[0].orientation, // assume that all components have the same orientation
232
+ );
233
+ }
234
+ } else if (position === 'inner') {
235
+ placeAxisArcInner(components, coordinate, area);
236
+ } else if (position === 'outer') {
237
+ placeAxisArcOuter(components, coordinate, area);
238
+ }
239
+ }
240
+
241
+ function placeAxisArcInner(
242
+ components: G2GuideComponentOptions[],
243
+ coordinate: Coordinate,
244
+ area: SectionArea,
245
+ ) {
246
+ const [x, y, , height] = area;
247
+ const [cx, cy] = coordinate.getCenter();
248
+ const [innerRadius] = radiusOf(coordinate);
249
+ const r = height / 2;
250
+ const size = innerRadius * r;
251
+ const x0 = cx - size;
252
+ const y0 = cy - size;
253
+ for (let i = 0; i < components.length; i++) {
254
+ const component = components[i];
255
+ component.bbox = {
256
+ x: x + x0,
257
+ y: y + y0,
258
+ width: size * 2,
259
+ height: size * 2,
260
+ };
261
+ }
262
+ }
263
+
264
+ function placeAxisArcOuter(
265
+ components: G2GuideComponentOptions[],
266
+ coordinate: Coordinate,
267
+ area: SectionArea,
268
+ ) {
269
+ const [x, y, width, height] = area;
270
+ for (const component of components) {
271
+ component.bbox = { x, y, width, height };
272
+ }
273
+ }
274
+
275
+ /**
276
+ * @example arcX, arcY, axisLinear with angle
277
+ */
278
+ function placeArcLinear(
279
+ components: G2GuideComponentOptions[],
280
+ coordinate: Coordinate,
281
+ area: SectionArea,
282
+ ) {
283
+ const [x, y, width, height] = area;
284
+ for (const component of components) {
285
+ component.bbox = { x: x, y, width, height };
286
+ }
287
+ }
288
+
289
+ function placeAxisParallel(
290
+ components: G2GuideComponentOptions[],
291
+ coordinate: Coordinate,
292
+ area: SectionArea,
293
+ orientation: GCO,
294
+ ) {
295
+ if (orientation === 'horizontal') {
296
+ placeAxisParallelHorizontal(components, coordinate, area);
297
+ } else if (orientation === 'vertical') {
298
+ placeAxisParallelVertical(components, coordinate, area);
299
+ }
300
+ }
301
+
302
+ function placeAxisParallelVertical(
156
303
  components: G2GuideComponentOptions[],
157
304
  coordinate: Coordinate,
158
305
  area: SectionArea,
@@ -177,7 +324,7 @@ function placeCenterVertical(
177
324
  }
178
325
  }
179
326
 
180
- function placeCenterHorizontal(
327
+ function placeAxisParallelHorizontal(
181
328
  components: G2GuideComponentOptions[],
182
329
  coordinate: Coordinate,
183
330
  area: SectionArea,
@@ -200,13 +347,31 @@ function placeCenterHorizontal(
200
347
  const height = Y[i + 1] - y;
201
348
  component.bbox = { x, y, width, height };
202
349
  }
350
+
351
+ // override style
352
+ }
353
+
354
+ function placeAxisRadar(
355
+ components: G2GuideComponentOptions[],
356
+ coordinate: Coordinate,
357
+ area: SectionArea,
358
+ position: GCP,
359
+ ) {
360
+ const [x, y, width, height] = area;
361
+ for (const component of components) {
362
+ component.bbox = { x, y, width, height };
363
+ component.radar = {
364
+ index: components.indexOf(component),
365
+ count: components.length,
366
+ };
367
+ }
203
368
  }
204
369
 
205
370
  function placePaddingArea(
206
371
  components: G2GuideComponentOptions[],
207
372
  coordinate: Coordinate,
208
373
  area: SectionArea,
209
- ): void {
374
+ ) {
210
375
  const [x, y, width, height, direction, reverse, comparator] = area;
211
376
  const [
212
377
  mainStartKey,
@@ -218,13 +383,13 @@ function placePaddingArea(
218
383
  crossSizeKey,
219
384
  crossSizeValue,
220
385
  ] =
221
- direction === 0
386
+ direction === 'vertical'
222
387
  ? ['y', y, 'x', x, 'height', height, 'width', width]
223
388
  : ['x', x, 'y', y, 'width', width, 'height', height];
224
389
 
225
390
  // Sort components by order.
226
391
  // The smaller the order, the closer to center.
227
- components.sort((a, b) => comparator(a.order, b.order));
392
+ components.sort((a, b) => comparator?.(a.order, b.order));
228
393
 
229
394
  const startValue = reverse ? mainStartValue + mainSizeValue : mainStartValue;
230
395
  for (let i = 0, start = startValue; i < components.length; i++) {
@@ -240,40 +405,15 @@ function placePaddingArea(
240
405
  }
241
406
  }
242
407
 
243
- function placeArc(
244
- components: G2GuideComponentOptions[],
245
- coordinate: Coordinate,
246
- area: SectionArea,
247
- ) {
248
- const [x, y, width, height] = area;
249
- for (let i = 0; i < components.length; i++) {
250
- const component = components[i];
251
- component.bbox = { x, y, width, height };
252
- }
253
- }
254
-
255
- function placeArcY(
256
- components: G2GuideComponentOptions[],
257
- coordinate: Coordinate,
258
- area: SectionArea,
259
- ) {
260
- const [x, y, , height] = area;
261
- const [cx, cy] = coordinate.getCenter();
262
- const [innerRadius, outerRadius] = radiusOf(coordinate);
263
- const r = height / 2;
264
- const y0 = cy - outerRadius * r;
265
- const h = (outerRadius - innerRadius) * r;
266
- for (let i = 0; i < components.length; i++) {
267
- const component = components[i];
268
- component.bbox = { x: cx + x, y: y0 + y, width: 0, height: h };
269
- }
270
- }
271
-
272
- function placeArcCenter(
408
+ /**
409
+ * @example legend in the center of radial or polar system
410
+ */
411
+ function placeCenter(
273
412
  components: G2GuideComponentOptions[],
274
413
  coordinate: Coordinate,
275
414
  area: SectionArea,
276
415
  ) {
416
+ if (components.length === 0) return;
277
417
  const [x, y, width, height] = area;
278
418
  const [innerRadius] = radiusOf(coordinate);
279
419
  const r = ((height / 2) * innerRadius) / Math.sqrt(2);
@@ -284,34 +424,3 @@ function placeArcCenter(
284
424
  component.bbox = { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
285
425
  }
286
426
  }
287
-
288
- function placeArcInner(
289
- components: G2GuideComponentOptions[],
290
- coordinate: Coordinate,
291
- area: SectionArea,
292
- ) {
293
- const [x, y, , height] = area;
294
- const [cx, cy] = coordinate.getCenter();
295
- const [innerRadius] = radiusOf(coordinate);
296
- const r = height / 2;
297
- const size = innerRadius * r;
298
- const x0 = cx - size;
299
- const y0 = cy - size;
300
- for (let i = 0; i < components.length; i++) {
301
- const component = components[i];
302
- component.bbox = {
303
- x: x + x0,
304
- y: y + y0,
305
- width: size * 2,
306
- height: size * 2,
307
- };
308
- }
309
- }
310
-
311
- function radiusOf(coordinate: Coordinate): [number, number] {
312
- const { transformations } = coordinate.getOptions();
313
- const [, , , innerRadius, outerRadius] = transformations.find(
314
- (d) => d[0] === 'polar',
315
- );
316
- return [innerRadius as number, outerRadius as number];
317
- }
@@ -632,6 +632,7 @@ async function plotView(
632
632
  enter
633
633
  // Make this layer interactive, such as click and mousemove events.
634
634
  .append('rect')
635
+ // todo zIndex
635
636
  .style('fill', 'transparent')
636
637
  .attr('className', PLOT_CLASS_NAME)
637
638
  .call(updateBBox)
@@ -234,6 +234,7 @@ function inferScaleRange(
234
234
  case 'linear':
235
235
  case 'time':
236
236
  case 'log':
237
+ case 'pow':
237
238
  case 'sqrt': {
238
239
  const colors = categoricalColors(values, options, domain, theme, library);
239
240
  const [r0, r1] = inferRangeQ(name, colors);
@@ -498,3 +499,43 @@ export function isPosition(name: string): boolean {
498
499
  name === 'exitDuration'
499
500
  );
500
501
  }
502
+
503
+ export function isValidScale(scale: G2ScaleOptions) {
504
+ if (!scale || !scale.type) return false;
505
+ if (typeof scale.type === 'function') return true;
506
+ const { type, domain, range, interpolator } = scale;
507
+ const isValidDomain = domain && domain.length > 0;
508
+ const isValidRange = range && range.length > 0;
509
+
510
+ if (
511
+ [
512
+ 'linear',
513
+ 'sqrt',
514
+ 'log',
515
+ 'time',
516
+ 'pow',
517
+ 'threshold',
518
+ 'quantize',
519
+ 'quantile',
520
+ 'ordinal',
521
+ 'band',
522
+ 'point',
523
+ ].includes(type) &&
524
+ isValidDomain &&
525
+ isValidRange
526
+ ) {
527
+ return true;
528
+ }
529
+
530
+ if (
531
+ ['sequential'].includes(type) &&
532
+ isValidDomain &&
533
+ (isValidRange || interpolator)
534
+ ) {
535
+ return true;
536
+ }
537
+
538
+ if (['constant', 'identity'].includes(type) && isValidRange) return true;
539
+
540
+ return false;
541
+ }
@@ -174,6 +174,9 @@ export function addGuideToScale(
174
174
  ),
175
175
  color: { guide: normalize(legend, 'color') },
176
176
  size: { guide: normalize(legend, 'size') },
177
+ shape: { guide: normalize(legend, 'shape') },
178
+ // fixme: opacity is conflict with DisplayObject.opacity
179
+ // opacity: { guide: normalize(legend, 'opacity') },
177
180
  },
178
181
  });
179
182
  return [I, mark];
@@ -127,18 +127,24 @@ export type BBox = {
127
127
  height?: number;
128
128
  };
129
129
 
130
- export type GuideComponentPosition =
130
+ export type GuidePrimitivePosition =
131
131
  | 'top'
132
- | 'left'
133
132
  | 'bottom'
133
+ | 'left'
134
134
  | 'right'
135
- | 'centerVertical'
136
- | 'centerHorizontal'
137
135
  | 'center'
138
- | 'arc'
139
- | 'arcY'
140
- | 'arcInner'
141
- | 'arcCenter';
136
+ | 'inner'
137
+ | 'outer';
138
+ export type GuideCompositePosition =
139
+ | 'top-left'
140
+ | 'top-right'
141
+ | 'bottom-left'
142
+ | 'bottom-right';
143
+ export type GuideComponentPosition =
144
+ | GuidePrimitivePosition
145
+ | GuideCompositePosition;
146
+
147
+ export type GuideComponentOrientation = 'horizontal' | 'vertical' | number;
142
148
 
143
149
  export type Layout = {
144
150
  paddingLeft?: number;
@@ -162,13 +168,20 @@ export type Layout = {
162
168
  y?: number;
163
169
  };
164
170
 
165
- // @todo Using emus.
171
+ export type Direction = 'horizontal' | 'vertical' | 'center';
172
+
173
+ export type FlexLayout = {
174
+ flexDirection?: 'row' | 'column';
175
+ justifyContent?: 'flex-start' | 'flex-end' | 'center';
176
+ alignItems?: 'flex-start' | 'flex-end' | 'center';
177
+ };
178
+
166
179
  export type SectionArea = [
167
180
  x: number,
168
181
  y: number,
169
182
  width: number,
170
183
  height: number,
171
- direction: 0 | 1 | -1, // horizontal: 1, vertical: 0, center: -1
184
+ direction: Direction,
172
185
  reverse: boolean,
173
186
  comparator: (a: Primitive, b: Primitive) => number,
174
187
  ];
@@ -1,18 +1,25 @@
1
+ import { Coordinate, Transformation } from '@antv/coord';
1
2
  import { DisplayObject, IAnimation as GAnimation } from '@antv/g';
2
- import { Transformation, Coordinate } from '@antv/coord';
3
3
  import {
4
- IndexedValue,
4
+ G2View,
5
+ G2GuideComponentOptions,
6
+ G2CoordinateOptions,
7
+ G2ScaleOptions,
8
+ G2ViewTree,
9
+ } from './options';
10
+ import {
5
11
  G2Theme,
6
- Vector2,
12
+ G2ViewInstance,
7
13
  GuideComponentPosition,
14
+ GuideComponentOrientation,
15
+ IndexedValue,
8
16
  Layout,
9
- G2ViewInstance,
17
+ Vector2,
10
18
  } from './common';
11
- import { G2ViewTree } from './options';
12
- import { EncodeComponent, Encode } from './encode';
13
- import { MarkComponent, Mark } from './mark';
14
- import { TransformComponent, Transform } from './transform';
15
19
  import { DataComponent } from './data';
20
+ import { Encode, EncodeComponent } from './encode';
21
+ import { Mark, MarkComponent } from './mark';
22
+ import { Transform, TransformComponent } from './transform';
16
23
 
17
24
  export type G2ComponentNamespaces =
18
25
  | 'coordinate'
@@ -156,15 +163,17 @@ export type ThemeComponent<O = Record<string, unknown>> = G2BaseComponent<
156
163
  >;
157
164
 
158
165
  export type GuideComponent = (
159
- scale: Scale,
166
+ scales: Scale[],
160
167
  style: Record<string, any>,
161
168
  coordinate: Coordinate,
162
169
  theme: G2Theme,
163
170
  ) => DisplayObject;
164
171
  export type GuideComponentProps = {
165
- defaultPosition: GuideComponentPosition;
172
+ defaultPosition?: GuideComponentPosition;
173
+ defaultOrientation?: GuideComponentOrientation;
166
174
  defaultSize: number;
167
175
  defaultOrder: number;
176
+ [key: string]: any;
168
177
  };
169
178
  export type GuideComponentComponent<O = Record<string, unknown>> =
170
179
  G2BaseComponent<GuideComponent, O, GuideComponentProps>;
@@ -1,6 +1,6 @@
1
- import { Canvas, IAnimation as GAnimation } from '@antv/g';
2
- import type { DisplayObject } from '@antv/g';
3
1
  import EventEmitter from '@antv/event-emitter';
2
+ import type { DisplayObject } from '@antv/g';
3
+ import { Canvas, IAnimation as GAnimation } from '@antv/g';
4
4
  import {
5
5
  G2Title,
6
6
  G2ViewDescriptor,
@@ -9,28 +9,28 @@ import {
9
9
  Primitive,
10
10
  } from './common';
11
11
  import {
12
+ AdjustComponent,
13
+ AnimationComponent,
14
+ CompositionComponent,
15
+ CoordinateComponent,
12
16
  G2BaseComponent,
13
- StatisticComponent,
14
- ThemeComponent,
15
17
  G2ComponentNamespaces,
16
- CoordinateComponent,
17
- ScaleComponent,
18
- InferComponent,
19
- ShapeComponent,
20
- PaletteComponent,
21
18
  GuideComponentComponent,
22
- AnimationComponent,
19
+ InferComponent,
23
20
  InteractionComponent,
24
- CompositionComponent,
25
- AdjustComponent,
26
- Scale,
27
21
  LabelTransformComponent,
22
+ PaletteComponent,
23
+ Scale,
24
+ ScaleComponent,
25
+ ShapeComponent,
26
+ StatisticComponent,
27
+ ThemeComponent,
28
28
  } from './component';
29
29
 
30
- import { TransformComponent } from './transform';
30
+ import { DataComponent } from './data';
31
31
  import { EncodeComponent } from './encode';
32
32
  import { MarkComponent } from './mark';
33
- import { DataComponent } from './data';
33
+ import { TransformComponent } from './transform';
34
34
 
35
35
  export type G2ViewTree = {
36
36
  width?: number;
@@ -0,0 +1,20 @@
1
+ export const ContinuousScale = {
2
+ linear: 'linear',
3
+ identity: 'identity',
4
+ log: 'log',
5
+ pow: 'pow',
6
+ sqrt: 'sqrt',
7
+ sequential: 'sequential',
8
+ } as const;
9
+
10
+ export const DistributionScale = {
11
+ threshold: 'threshold',
12
+ quantize: 'quantize',
13
+ quantile: 'quantile',
14
+ } as const;
15
+
16
+ export const DiscreteScale = {
17
+ ordinal: 'ordinal',
18
+ band: 'band',
19
+ point: 'point',
20
+ } as const;
@@ -70,11 +70,12 @@ type InteractionTheme = {
70
70
 
71
71
  type ComponentTheme = {
72
72
  axis?: any;
73
- axisArcY?: any;
73
+ axisLinear?: any;
74
74
  axisTop?: any;
75
75
  axisBottom?: any;
76
76
  axisLeft?: any;
77
77
  axisRight?: any;
78
+ axisRadar?: any;
78
79
  legend?: any;
79
80
  continuousLegend?: any;
80
81
  label?: LabelStyleProps;
@@ -24,7 +24,7 @@ function inferSymbol(x: number, y: number, r: number) {
24
24
  }
25
25
 
26
26
  /**
27
- * todo support polar later.
27
+ * @todo support polar later.
28
28
  */
29
29
  function inferConnectorPath(points: Vector2[]) {
30
30
  return d3line()
@@ -1,3 +1,4 @@
1
+ import { Path } from '@antv/g';
1
2
  import { Path as D3Path } from 'd3-path';
2
3
  import { extent } from 'd3-array';
3
4
  import { Coordinate } from '@antv/coord';
@@ -8,6 +9,7 @@ import { isPolar, isTranspose } from '../utils/coordinate';
8
9
  import { angle, angleWithQuadrant, dist, sub } from '../utils/vector';
9
10
  import { Selection } from '../utils/selection';
10
11
  import { indexOf } from '../utils/array';
12
+ import * as Symbols from './point/symbol';
11
13
 
12
14
  type A = ['a' | 'A', number, number, number, number, number, number, number];
13
15
  type C = ['c' | 'C', number, number, number, number, number, number];
@@ -126,7 +126,9 @@ export type BaseGeometry<
126
126
  Record<'x' | 'y' | 'position' | `position${number}`, Axis | boolean>
127
127
  >
128
128
  | boolean;
129
- legend?: Partial<Record<'size' | 'color', Legend | boolean>> | boolean;
129
+ legend?:
130
+ | Partial<Record<'size' | 'color' | 'shape' | 'opacity', Legend | boolean>>
131
+ | boolean;
130
132
  slider?: Partial<Record<'x' | 'y', any>>;
131
133
  scrollbar?: Partial<Record<'x' | 'y', any>>;
132
134
  coordinates?: Coordinate[];