@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
@@ -2,30 +2,34 @@ import { Coordinate } from '@antv/coord';
2
2
  import { Axis as AxisComponent } from '@antv/gui';
3
3
  import { Linear as LinearScale } from '@antv/scale';
4
4
  import { deepMix } from '@antv/util';
5
- import { format } from 'd3-format';
6
5
  import { extent } from 'd3-array';
6
+ import { format } from 'd3-format';
7
7
  import {
8
+ BBox,
9
+ G2Theme,
10
+ GuideComponentComponent as GCC,
11
+ GuideComponentOrientation as GCO,
12
+ GuideComponentPosition as GCP,
13
+ Scale,
14
+ } from '../runtime';
15
+ import {
16
+ angleOf,
17
+ isFisheye,
8
18
  isParallel,
9
19
  isPolar,
10
- isTranspose,
11
- isTheta,
12
20
  isRadial,
13
- isFisheye,
21
+ isTheta,
22
+ isTranspose,
23
+ isNonCartesian,
24
+ radiusOf,
14
25
  } from '../utils/coordinate';
15
26
  import { capitalizeFirst } from '../utils/helper';
16
- import {
17
- BBox,
18
- GuideComponentComponent as GCC,
19
- GuideComponentPosition,
20
- Scale,
21
- } from '../runtime';
22
27
  import { titleContent } from './utils';
23
28
 
24
29
  export type AxisOptions = {
25
- position?: GuideComponentPosition;
30
+ position?: GCP;
26
31
  zIndex?: number;
27
32
  title?: string | string[];
28
- d;
29
33
  direction?: 'left' | 'center' | 'right';
30
34
  labelFormatter?: (d: any, index: number, array: any) => string;
31
35
  tickFilter?: (datum: any, index: number, array: any) => boolean;
@@ -36,25 +40,11 @@ export type AxisOptions = {
36
40
  ) => number[];
37
41
  tickCount?: number;
38
42
  grid: any;
43
+ // options won't be overridden
44
+ important: Record<string, any>;
39
45
  [key: string]: any;
40
46
  };
41
47
 
42
- function angleOf(coordinate: Coordinate): [number, number] {
43
- const { transformations } = coordinate.getOptions();
44
- const [, startAngle, endAngle] = transformations.find(
45
- (d) => d[0] === 'polar',
46
- );
47
- return [(+startAngle * 180) / Math.PI, (+endAngle * 180) / Math.PI];
48
- }
49
-
50
- function radiusOf(coordinate: Coordinate): [number, number] {
51
- const { transformations } = coordinate.getOptions();
52
- const [, , , innerRadius, outerRadius] = transformations.find(
53
- (d) => d[0] === 'polar',
54
- );
55
- return [+innerRadius, +outerRadius];
56
- }
57
-
58
48
  function sizeOf(coordinate: Coordinate): [number, number] {
59
49
  // @ts-ignore
60
50
  const { innerWidth, innerHeight } = coordinate.getOptions();
@@ -102,6 +92,14 @@ function ticksOf(
102
92
  return tickMethod(min, max, tickCount);
103
93
  }
104
94
 
95
+ function isHorizontal(orientation: GCO) {
96
+ return orientation === 'horizontal' || orientation === 0;
97
+ }
98
+
99
+ function isVertical(orientation: GCO) {
100
+ return orientation === 'vertical' || orientation === -Math.PI / 2;
101
+ }
102
+
105
103
  function prettyNumber(n: number) {
106
104
  if (typeof n !== 'number') return n;
107
105
  return Math.abs(n) < 1e-15 ? n : parseFloat(n.toFixed(15));
@@ -139,7 +137,7 @@ function getTicks(
139
137
  defaultTickFormatter: AxisOptions['labelFormatter'],
140
138
  tickFilter: AxisOptions['tickFilter'],
141
139
  tickMethod: AxisOptions['tickMethod'],
142
- position: GuideComponentPosition,
140
+ position: GCP,
143
141
  coordinate: Coordinate,
144
142
  ) {
145
143
  if (tickCount !== undefined || tickMethod !== undefined) {
@@ -167,7 +165,7 @@ function getTicks(
167
165
  });
168
166
  // @todo GUI should consider the overlap problem for the first
169
167
  // and label of arc axis.
170
- return isRadial(coordinate) && position === 'arcY'
168
+ return isRadial(coordinate) && position === 'center'
171
169
  ? reverseTicks(axisTicks)
172
170
  : axisTicks;
173
171
  }
@@ -183,9 +181,9 @@ function getTicks(
183
181
  });
184
182
  }
185
183
 
186
- function getGridLength(position: GuideComponentPosition, coordinate) {
184
+ function inferGridLength(position: GCP, coordinate: Coordinate) {
187
185
  const [width, height] = sizeOf(coordinate);
188
- if (position === 'bottom' || position === 'top') return height;
186
+ if (position.includes('bottom') || position.includes('top')) return height;
189
187
  return width;
190
188
  }
191
189
 
@@ -198,15 +196,24 @@ function labelTransforms(autoHide?: boolean, autoRotate?: boolean) {
198
196
  }
199
197
 
200
198
  function inferArcStyle(
201
- position: GuideComponentPosition,
199
+ position: GCP,
200
+ bbox: BBox,
202
201
  innerRadius: number,
203
202
  outerRadius: number,
204
203
  coordinate: Coordinate,
205
204
  ) {
205
+ const { x, y, width, height } = bbox;
206
+ const center: [number, number] = [x + width / 2, y + height / 2];
207
+ const radius = Math.min(width, height) / 2;
208
+ const [startAngle, endAngle] = angleOf(coordinate);
209
+
206
210
  const [w, h] = sizeOf(coordinate);
207
211
  const r = Math.min(w, h) / 2;
208
212
 
209
213
  const common = {
214
+ center,
215
+ radius,
216
+ angleRange: [startAngle, endAngle],
210
217
  titleFillOpacity: 0,
211
218
  titlePosition: 'inner',
212
219
  showLine: false,
@@ -214,7 +221,7 @@ function inferArcStyle(
214
221
  gridLength: (outerRadius - innerRadius) * r,
215
222
  };
216
223
 
217
- if (position === 'arcInner') {
224
+ if (position === 'inner') {
218
225
  const [w, h] = sizeOf(coordinate);
219
226
  const r = Math.min(w, h) / 2;
220
227
  return {
@@ -227,6 +234,7 @@ function inferArcStyle(
227
234
  };
228
235
  }
229
236
 
237
+ // arc outer
230
238
  return {
231
239
  ...common,
232
240
  labelAlign: 'parallel',
@@ -243,74 +251,111 @@ function inferGrid(value: boolean, coordinate: Coordinate, scale: Scale) {
243
251
  return value === undefined ? !!scale.getTicks : value;
244
252
  }
245
253
 
246
- function inferOverrideStyle(
247
- position: GuideComponentPosition,
254
+ function inferAxisLinearOverrideStyle(
255
+ position: GCP,
256
+ orientation: GCO,
248
257
  bbox: BBox,
249
258
  coordinate: Coordinate,
250
259
  ): {
251
- startPos: [number, number];
252
- endPos: [number, number];
260
+ startPos?: [number, number];
261
+ endPos?: [number, number];
253
262
  showLine?: boolean;
254
263
  [k: string]: any;
255
264
  } {
256
- const [, cy] = coordinate.getCenter();
257
265
  const { x, y, width, height } = bbox;
258
266
 
259
267
  if (position === 'bottom') {
260
- return {
261
- startPos: [x, y],
262
- endPos: [x + width, y],
263
- };
264
- } else if (position === 'left' || position === 'centerVertical') {
265
- return {
266
- startPos: [x + width, y],
267
- endPos: [x + width, y + height],
268
- showLine: position === 'centerVertical' ? true : undefined,
269
- };
270
- } else if (position === 'right') {
271
- return {
272
- endPos: [x, y + height],
273
- startPos: [x, y],
274
- };
275
- } else if (position === 'arcY') {
276
- const [startAngle, endAngle] = angleOf(coordinate);
277
- return {
278
- startPos: [x, y],
279
- endPos: [x + width, y + height],
280
- gridCenter: [bbox.x, cy + bbox.y],
281
- gridControlAngles: new Array(3)
282
- .fill(0)
283
- .map(
284
- (d, i, arr) =>
285
- 90 + startAngle + ((endAngle - startAngle) / (arr.length - 1)) * i,
286
- ),
287
- };
268
+ return { startPos: [x, y], endPos: [x + width, y] };
269
+ }
270
+ if (position === 'left') {
271
+ return { startPos: [x + width, y], endPos: [x + width, y + height] };
272
+ }
273
+ if (position === 'right') {
274
+ return { endPos: [x, y + height], startPos: [x, y] };
275
+ }
276
+ if (position === 'top') {
277
+ return { startPos: [x, y + height], endPos: [x + width, y + height] };
278
+ }
279
+ // linear axis, maybe in parallel, polar, radial or radar systems.
280
+ if (position === 'center') {
281
+ // axisY
282
+ if (orientation === 'vertical') {
283
+ return {
284
+ startPos: [x + width, y],
285
+ endPos: [x + width, y + height],
286
+ showLine: true,
287
+ };
288
+ }
289
+ // axisX
290
+ else if (orientation === 'horizontal') {
291
+ return {
292
+ startPos: [x, y + height],
293
+ endPos: [x + width, y + height],
294
+ showLine: true,
295
+ };
296
+ }
297
+ // axis with rotate
298
+ else if (typeof orientation === 'number') {
299
+ const [cx, cy] = coordinate.getCenter();
300
+ const [innerRadius, outerRadius] = radiusOf(coordinate);
301
+ const [startAngle, endAngle] = angleOf(coordinate);
302
+ const r = height / 2;
303
+
304
+ const innerR = innerRadius * r;
305
+ const outerR = outerRadius * r;
306
+
307
+ const [actualCx, actualCy] = [cx + x, cy + y];
308
+ const [cos, sin] = [Math.cos(orientation), Math.sin(orientation)];
309
+
310
+ const startPos: [number, number] = [
311
+ actualCx + outerR * cos,
312
+ actualCy + outerR * sin,
313
+ ];
314
+ const endPos: [number, number] = [
315
+ actualCx + innerR * cos,
316
+ actualCy + innerR * sin,
317
+ ];
318
+
319
+ return {
320
+ startPos,
321
+ endPos,
322
+ gridClosed: endAngle - startAngle === 360,
323
+ gridCenter: [cx + x, y + cy],
324
+ gridControlAngles: new Array(3)
325
+ .fill(0)
326
+ .map(
327
+ (d, i, arr) =>
328
+ 90 +
329
+ startAngle +
330
+ ((endAngle - startAngle) / (arr.length - 1)) * i,
331
+ ),
332
+ };
333
+ }
288
334
  }
289
335
 
290
- return {
291
- startPos: [x, y + height],
292
- endPos: [x + width, y + height],
293
- showLine: position === 'centerHorizontal' ? true : undefined,
294
- };
336
+ // position is inner or outer for arc axis won't be here
337
+
338
+ return {};
295
339
  }
296
340
 
297
- const ArcAxis = (options) => {
341
+ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
298
342
  const {
299
343
  order,
300
344
  size,
301
345
  position,
346
+ orientation,
302
347
  labelFormatter = (d) => `${d}`,
303
348
  tickFilter,
304
349
  tickCount,
305
350
  tickMethod,
306
351
  title,
307
352
  grid: showGrid = false,
353
+ important = {},
308
354
  ...rest
309
355
  } = options;
310
- return (scale, value, coordinate, theme) => {
311
- const { domain, bbox } = value;
312
- const { x, y, width, height } = bbox;
313
- const center: [number, number] = [x + width / 2, y + height / 2];
356
+ return ([scale], value, coordinate, theme) => {
357
+ const { bbox } = value;
358
+ const { domain } = scale.getOptions();
314
359
  const ticks = getTicks(
315
360
  scale,
316
361
  domain,
@@ -322,39 +367,62 @@ const ArcAxis = (options) => {
322
367
  coordinate,
323
368
  );
324
369
 
325
- const radius = Math.min(width, height) / 2;
326
- const [startAngle, endAngle] = angleOf(coordinate);
327
370
  const [innerRadius, outerRadius] = radiusOf(coordinate);
328
371
 
329
372
  const defaultStyle = inferArcStyle(
330
373
  position,
374
+ bbox,
331
375
  innerRadius,
332
376
  outerRadius,
333
377
  coordinate,
334
378
  );
379
+
335
380
  const { axis: axisTheme } = theme;
336
381
  return new AxisComponent({
337
382
  style: deepMix({}, axisTheme, defaultStyle, {
338
383
  type: 'arc',
339
- center,
340
- radius,
341
- angleRange: [startAngle, endAngle],
342
384
  data: ticks,
343
385
  title: titleContent(title),
344
386
  showGrid,
345
387
  ...rest,
388
+ ...important,
346
389
  }),
347
390
  });
348
391
  };
349
392
  };
350
393
 
351
- function inferDefaultStyle(scale, theme, position, direction) {
352
- const p = position === 'centerVertical' ? 'left' : position;
394
+ function inferThemeStyle(
395
+ scale: Scale,
396
+ coordinate: Coordinate,
397
+ theme: G2Theme,
398
+ direction,
399
+ position: GCP,
400
+ orientation: GCO,
401
+ ) {
402
+ const baseStyle = theme.axis;
403
+ let furtherStyle = theme.axisLinear;
353
404
 
354
- const themeStyle = Object.assign(
355
- {},
356
- theme.axis,
357
- theme[`axis${capitalizeFirst(p)}`] || theme.axisTop,
405
+ if (['top', 'right', 'bottom', 'left'].includes(position)) {
406
+ furtherStyle = theme[`axis${capitalizeFirst(position)}`];
407
+ }
408
+ return Object.assign({}, baseStyle, furtherStyle);
409
+ }
410
+
411
+ function inferDefaultStyle(
412
+ scale: Scale,
413
+ coordinate: Coordinate,
414
+ theme: G2Theme,
415
+ direction,
416
+ position: GCP,
417
+ orientation: GCO,
418
+ ) {
419
+ const themeStyle = inferThemeStyle(
420
+ scale,
421
+ coordinate,
422
+ theme,
423
+ direction,
424
+ position,
425
+ orientation,
358
426
  );
359
427
 
360
428
  if (position === 'bottom') {
@@ -364,48 +432,41 @@ function inferDefaultStyle(scale, theme, position, direction) {
364
432
  titleTransformOrigin: 'center',
365
433
  titleTransform: scale.getTicks ? 'translate(-100%, 0)' : undefined,
366
434
  };
367
- } else if (position === 'arcY') {
435
+ }
436
+ if (position === 'center') {
368
437
  return {
369
438
  ...themeStyle,
370
439
  labelDirection: direction === 'right' ? 'negative' : 'positive',
371
440
  labelTransform: direction === 'center' ? 'translate(50%, 0)' : '',
372
441
  tickDirection: direction === 'right' ? 'negative' : 'positive',
373
442
  labelSpacing: direction === 'center' ? 0 : 4,
443
+ titleSpacing: isVertical(orientation) ? 10 : 0,
374
444
  tick: direction === 'center' ? false : undefined,
375
445
  };
376
446
  }
377
-
378
447
  return themeStyle;
379
448
  }
380
449
 
381
- function isHorizontal(position): boolean {
382
- switch (position) {
383
- case 'top':
384
- case 'bottom':
385
- case 'centerHorizontal':
386
- return true;
387
- default:
388
- return false;
389
- }
390
- }
391
-
392
- const LinearAxis: GCC<AxisOptions> = (options) => {
450
+ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
393
451
  const {
394
452
  order,
395
453
  size,
396
454
  transform,
397
455
  position,
456
+ orientation,
398
457
  title,
399
458
  labelFormatter = (d) => `${d}`,
400
459
  direction = 'left',
401
460
  tickCount,
402
461
  tickFilter,
403
462
  tickMethod,
463
+ important = {},
404
464
  ...userDefinitions
405
465
  } = options;
406
466
 
407
- return (scale, value, coordinate, theme) => {
408
- const { domain, bbox } = value;
467
+ return ([scale], value, coordinate, theme) => {
468
+ const { bbox } = value;
469
+ const { domain } = scale.getOptions();
409
470
 
410
471
  const ticks = getTicks(
411
472
  scale,
@@ -418,7 +479,14 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
418
479
  coordinate,
419
480
  );
420
481
 
421
- const defaultStyle = inferDefaultStyle(scale, theme, position, direction);
482
+ const defaultStyle = inferDefaultStyle(
483
+ scale,
484
+ coordinate,
485
+ theme,
486
+ direction,
487
+ position,
488
+ orientation,
489
+ );
422
490
  const {
423
491
  labelAutoRotate = true,
424
492
  labelAutoHide = false,
@@ -429,14 +497,14 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
429
497
  } = Object.assign({}, defaultStyle, userDefinitions);
430
498
 
431
499
  const showGrid = inferGrid(grid, coordinate, scale);
432
- const gridLength = getGridLength(position, coordinate);
500
+ const gridLength = inferGridLength(position, coordinate);
433
501
 
434
- const { showLine = line, ...overrideStyle } = inferOverrideStyle(
502
+ const { showLine = line, ...overrideStyle } = inferAxisLinearOverrideStyle(
435
503
  position,
504
+ orientation,
436
505
  bbox,
437
506
  coordinate,
438
507
  );
439
-
440
508
  const axisStyle = {
441
509
  ...defaultStyle,
442
510
  type: 'linear' as const,
@@ -452,34 +520,40 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
452
520
  showLine: true,
453
521
  ...(!showLine ? { lineOpacity: 0 } : null),
454
522
  ...overrideStyle,
523
+ ...important,
455
524
  };
456
525
 
457
526
  return new AxisComponent({
458
527
  className: 'axis',
459
- style: {
460
- ...axisStyle,
461
- horizontal: isHorizontal(position),
462
- },
528
+ style: axisStyle,
463
529
  });
464
530
  };
465
531
  };
466
532
 
467
- /**
468
- * Guide Component for position channel(e.g. x, y).
469
- */
470
- export const Axis: GCC<AxisOptions> = (options) => {
471
- const { position, labelFormatter: f = (d) => `${d}` } = options;
472
- const labelFormatter = typeof f === 'string' ? format(f) : f;
473
- const normalizedOptions = { ...options, labelFormatter };
474
- return (scale, value, coordinate, theme) => {
475
- return position === 'arc' || position === 'arcInner'
476
- ? ArcAxis(normalizedOptions)(scale, value, coordinate, theme)
477
- : LinearAxis(normalizedOptions)(scale, value, coordinate, theme);
533
+ const axisFactor: (
534
+ axis: typeof ArcAxisComponent | typeof LinearAxisComponent,
535
+ ) => GCC<AxisOptions> = (axis) => {
536
+ return (options) => {
537
+ const { labelFormatter: f = (d) => `${d}` } = options;
538
+ const labelFormatter = typeof f === 'string' ? format(f) : f;
539
+ const normalizedOptions = { ...options, labelFormatter };
540
+ return (...args) => axis(normalizedOptions)(...args);
478
541
  };
479
542
  };
480
543
 
481
- Axis.props = {
482
- defaultPosition: 'left',
544
+ export const LinearAxis = axisFactor(LinearAxisComponent);
545
+
546
+ export const ArcAxis = axisFactor(ArcAxisComponent);
547
+
548
+ LinearAxis.props = {
549
+ defaultPosition: 'center',
550
+ defaultSize: 45,
551
+ defaultOrder: 0,
552
+ };
553
+
554
+ ArcAxis.props = {
555
+ defaultPosition: 'outer',
556
+ defaultOrientation: 'vertical',
483
557
  defaultSize: 45,
484
558
  defaultOrder: 0,
485
559
  };
@@ -0,0 +1,16 @@
1
+ import { GuideComponentComponent as GCC } from '../runtime';
2
+ import { ArcAxis, AxisOptions } from './axis';
3
+
4
+ export type AxisYOptions = AxisOptions;
5
+
6
+ /**
7
+ * ArcAxis component bind to x scale.
8
+ */
9
+ export const AxisArc: GCC<AxisYOptions> = (options) => {
10
+ return ArcAxis(options);
11
+ };
12
+
13
+ AxisArc.props = {
14
+ ...ArcAxis.props,
15
+ defaultPosition: 'left',
16
+ };
@@ -0,0 +1,73 @@
1
+ import { Coordinate } from '@antv/coord';
2
+ import { G2Theme, GuideComponentComponent as GCC } from '../runtime';
3
+ import { angleOf } from '../utils/coordinate';
4
+ import { AxisOptions, LinearAxis } from './axis';
5
+
6
+ export type AxisRadarOptions = AxisOptions & {
7
+ radar: {
8
+ count: number;
9
+ index: number;
10
+ };
11
+ };
12
+
13
+ function inferTitleTransform(orientation: number) {
14
+ const internalOrientation = orientation % (Math.PI * 2);
15
+
16
+ if (internalOrientation === Math.PI / 2) {
17
+ return { titleTransform: 'translate(0, 50%)' };
18
+ }
19
+ if (internalOrientation > -Math.PI / 2 && internalOrientation < Math.PI / 2) {
20
+ return { titleTransform: 'translate(50%, 0)' };
21
+ }
22
+ if (
23
+ internalOrientation > Math.PI / 2 &&
24
+ internalOrientation < (Math.PI * 3) / 2
25
+ ) {
26
+ return { titleTransform: 'translate(-50%, 0)' };
27
+ }
28
+ return {};
29
+ }
30
+
31
+ function inferAxisStyle(
32
+ options: AxisRadarOptions,
33
+ theme: G2Theme,
34
+ coordinate: Coordinate,
35
+ value: Record<string, any>,
36
+ ) {
37
+ const { radar } = options;
38
+ const {
39
+ scales: [{ name }],
40
+ } = value;
41
+ const [startAngle, endAngle] = angleOf(coordinate);
42
+ const { axisRadar: radarTheme = {} } = theme;
43
+
44
+ return {
45
+ ...radarTheme,
46
+ showGrid: name === 'position',
47
+ gridConnect: 'line',
48
+ gridControlAngles: new Array(radar.count).fill(0).map((_, i) => {
49
+ const angle = (endAngle - startAngle) / radar.count;
50
+ // the zero angle of grid is 90 degree
51
+ return startAngle + angle * i + 90;
52
+ }),
53
+ };
54
+ }
55
+
56
+ export const AxisRadar: GCC<AxisRadarOptions> = (options) => {
57
+ const { important = {}, ...restOptions } = options;
58
+ return (scales, value, coordinate, theme) => {
59
+ return LinearAxis({
60
+ ...restOptions,
61
+ ...inferTitleTransform(options.orientation),
62
+ important: {
63
+ ...inferAxisStyle(options, theme, coordinate, value),
64
+ ...important,
65
+ },
66
+ })(scales, value, coordinate, theme);
67
+ };
68
+ };
69
+
70
+ AxisRadar.props = {
71
+ ...LinearAxis.props,
72
+ defaultPosition: 'center',
73
+ };
@@ -1,16 +1,19 @@
1
+ import { Axis } from '@antv/gui';
1
2
  import { GuideComponentComponent as GCC } from '../runtime';
2
- import { Axis, AxisOptions } from './axis';
3
+ import { LinearAxis, AxisOptions } from './axis';
3
4
 
4
5
  export type AxisXOptions = AxisOptions;
5
6
 
6
7
  /**
7
- * Axis component bind to x scale.
8
+ * LinearAxis component bind to x scale.
8
9
  */
9
10
  export const AxisX: GCC<AxisXOptions> = (options) => {
10
- return Axis(options);
11
+ return LinearAxis(options);
11
12
  };
12
13
 
13
14
  AxisX.props = {
14
- ...Axis.props,
15
+ ...LinearAxis.props,
15
16
  defaultPosition: 'bottom',
16
17
  };
18
+
19
+ export function axisXConfig() {}
@@ -1,16 +1,16 @@
1
1
  import { GuideComponentComponent as GCC } from '../runtime';
2
- import { Axis, AxisOptions } from './axis';
2
+ import { AxisOptions, LinearAxis } from './axis';
3
3
 
4
4
  export type AxisYOptions = AxisOptions;
5
5
 
6
6
  /**
7
- * Axis component bind to y scale.
7
+ * LinearAxis component bind to y scale.
8
8
  */
9
9
  export const AxisY: GCC<AxisYOptions> = (options) => {
10
- return Axis(options);
10
+ return LinearAxis(options);
11
11
  };
12
12
 
13
13
  AxisY.props = {
14
- ...Axis.props,
14
+ ...LinearAxis.props,
15
15
  defaultPosition: 'left',
16
16
  };
@@ -1,7 +1,12 @@
1
+ export { LinearAxis as AxisLinear, ArcAxis as AxisArc } from './axis';
1
2
  export { AxisX } from './axisX';
2
3
  export { AxisY } from './axisY';
4
+ export { AxisRadar } from './axisRadar';
3
5
  export { LegendCategory } from './legendCategory';
4
6
  export { LegendContinuous } from './legendContinuous';
7
+ export { LegendContinuousBlock } from './legendContinuousBlock';
8
+ export { LegendContinuousBlockSize } from './legendContinuousBlockSize';
9
+ export { LegendContinuousSize } from './legendContinuousSize';
5
10
  export { TitleComponent } from './title';
6
11
  export { SliderX } from './sliderX';
7
12
  export { SliderY } from './sliderY';
@@ -12,6 +17,9 @@ export type { AxisXOptions } from './axisX';
12
17
  export type { AxisYOptions } from './axisY';
13
18
  export type { LegendCategoryOptions } from './legendCategory';
14
19
  export type { LegendContinuousOptions } from './legendContinuous';
20
+ export type { LegendContinuousBlockOptions } from './legendContinuousBlock';
21
+ export type { LegendContinuousBlockSizeOptions } from './legendContinuousBlockSize';
22
+ export type { LegendContinuousSizeOptions } from './legendContinuousSize';
15
23
  export type { TitleComponentOptions } from './title';
16
24
  export type { SliderXOptions } from './sliderX';
17
25
  export type { SliderYOptions } from './sliderY';