@antv/g2 5.0.0-beta.4 → 5.0.0-beta.5

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 (348) hide show
  1. package/dist/g2-lite.min.js +5 -2
  2. package/dist/g2.min.js +5 -2
  3. package/esm/api/mark/mark.js +0 -2
  4. package/esm/api/mark/mark.js.map +1 -1
  5. package/esm/api/mark/types.d.ts +0 -2
  6. package/esm/component/axis.js +5 -4
  7. package/esm/component/axis.js.map +1 -1
  8. package/esm/component/slider.js +2 -4
  9. package/esm/component/slider.js.map +1 -1
  10. package/esm/composition/mark.js +2 -1
  11. package/esm/composition/mark.js.map +1 -1
  12. package/esm/interaction/builtin/brushHighlight.d.ts +1 -1
  13. package/esm/interaction/index.d.ts +3 -0
  14. package/esm/interaction/index.js +3 -0
  15. package/esm/interaction/index.js.map +1 -1
  16. package/esm/interaction/native/brushHighlight.d.ts +15 -0
  17. package/esm/interaction/native/brushHighlight.js +283 -0
  18. package/esm/interaction/native/brushHighlight.js.map +1 -0
  19. package/esm/interaction/native/brushXHighlight.d.ts +1 -0
  20. package/esm/interaction/native/brushXHighlight.js +8 -0
  21. package/esm/interaction/native/brushXHighlight.js.map +1 -0
  22. package/esm/interaction/native/brushYHighlight.d.ts +1 -0
  23. package/esm/interaction/native/brushYHighlight.js +8 -0
  24. package/esm/interaction/native/brushYHighlight.js.map +1 -0
  25. package/esm/interaction/native/legendFilter.js +3 -12
  26. package/esm/interaction/native/legendFilter.js.map +1 -1
  27. package/esm/interaction/native/tooltip.js +96 -28
  28. package/esm/interaction/native/tooltip.js.map +1 -1
  29. package/esm/interaction/native/utils.d.ts +4 -0
  30. package/esm/interaction/native/utils.js +23 -0
  31. package/esm/interaction/native/utils.js.map +1 -1
  32. package/esm/label-transform/contrastReverse.d.ts +9 -0
  33. package/esm/label-transform/contrastReverse.js +48 -0
  34. package/esm/label-transform/contrastReverse.js.map +1 -0
  35. package/esm/label-transform/index.d.ts +8 -8
  36. package/esm/label-transform/index.js +4 -4
  37. package/esm/label-transform/index.js.map +1 -1
  38. package/esm/label-transform/overflowHide.d.ts +7 -0
  39. package/esm/label-transform/overflowHide.js +18 -0
  40. package/esm/label-transform/overflowHide.js.map +1 -0
  41. package/esm/label-transform/overlapDodgeY.d.ts +7 -0
  42. package/esm/label-transform/{dodgeY.js → overlapDodgeY.js} +4 -4
  43. package/esm/label-transform/overlapDodgeY.js.map +1 -0
  44. package/esm/label-transform/overlapHide.d.ts +7 -0
  45. package/esm/label-transform/overlapHide.js +24 -0
  46. package/esm/label-transform/overlapHide.js.map +1 -0
  47. package/esm/runtime/plot.js +24 -6
  48. package/esm/runtime/plot.js.map +1 -1
  49. package/esm/runtime/scale.js +17 -5
  50. package/esm/runtime/scale.js.map +1 -1
  51. package/esm/runtime/transform.js +10 -4
  52. package/esm/runtime/transform.js.map +1 -1
  53. package/esm/runtime/types/common.d.ts +1 -0
  54. package/esm/runtime/types/options.d.ts +1 -0
  55. package/esm/shape/label/label.js +3 -3
  56. package/esm/shape/label/label.js.map +1 -1
  57. package/esm/shape/label/position/area.d.ts +13 -0
  58. package/esm/shape/label/position/area.js +28 -0
  59. package/esm/shape/label/position/area.js.map +1 -0
  60. package/esm/shape/label/position/bottom.d.ts +1 -0
  61. package/esm/shape/label/position/bottom.js +2 -0
  62. package/esm/shape/label/position/bottom.js.map +1 -0
  63. package/esm/shape/label/position/bottomLeft.d.ts +1 -0
  64. package/esm/shape/label/position/bottomLeft.js +2 -0
  65. package/esm/shape/label/position/bottomLeft.js.map +1 -0
  66. package/esm/shape/label/position/bottomRight.d.ts +1 -0
  67. package/esm/shape/label/position/bottomRight.js +2 -0
  68. package/esm/shape/label/position/bottomRight.js.map +1 -0
  69. package/esm/shape/label/position/default.d.ts +20 -0
  70. package/esm/shape/label/{position.js → position/default.js} +9 -45
  71. package/esm/shape/label/position/default.js.map +1 -0
  72. package/esm/shape/label/position/index.d.ts +13 -0
  73. package/esm/shape/label/position/index.js +14 -0
  74. package/esm/shape/label/position/index.js.map +1 -0
  75. package/esm/shape/label/position/inside.d.ts +1 -0
  76. package/esm/shape/label/position/inside.js +2 -0
  77. package/esm/shape/label/position/inside.js.map +1 -0
  78. package/esm/shape/label/position/left.d.ts +1 -0
  79. package/esm/shape/label/position/left.js +2 -0
  80. package/esm/shape/label/position/left.js.map +1 -0
  81. package/esm/shape/label/position/outside.d.ts +1 -0
  82. package/esm/shape/label/position/outside.js +2 -0
  83. package/esm/shape/label/position/outside.js.map +1 -0
  84. package/esm/shape/label/position/right.d.ts +1 -0
  85. package/esm/shape/label/position/right.js +2 -0
  86. package/esm/shape/label/position/right.js.map +1 -0
  87. package/esm/shape/label/position/spider.d.ts +7 -0
  88. package/esm/shape/label/position/spider.js +40 -0
  89. package/esm/shape/label/position/spider.js.map +1 -0
  90. package/esm/shape/label/position/surround.d.ts +7 -0
  91. package/esm/shape/label/position/surround.js +37 -0
  92. package/esm/shape/label/position/surround.js.map +1 -0
  93. package/esm/shape/label/position/top.d.ts +1 -0
  94. package/esm/shape/label/position/top.js +2 -0
  95. package/esm/shape/label/position/top.js.map +1 -0
  96. package/esm/shape/label/position/topLeft.d.ts +1 -0
  97. package/esm/shape/label/position/topLeft.js +2 -0
  98. package/esm/shape/label/position/topLeft.js.map +1 -0
  99. package/esm/shape/label/position/topRight.d.ts +1 -0
  100. package/esm/shape/label/position/topRight.js +2 -0
  101. package/esm/shape/label/position/topRight.js.map +1 -0
  102. package/esm/spec/composition.d.ts +2 -0
  103. package/esm/spec/geometry.d.ts +1 -1
  104. package/esm/spec/interaction.d.ts +21 -5
  105. package/esm/spec/labelTransform.d.ts +24 -11
  106. package/esm/spec/theme.d.ts +5 -2
  107. package/esm/stdlib/index.js +5 -6
  108. package/esm/stdlib/index.js.map +1 -1
  109. package/esm/theme/academy.d.ts +3 -0
  110. package/esm/theme/academy.js +402 -0
  111. package/esm/theme/academy.js.map +1 -0
  112. package/esm/theme/dark.js +3 -2
  113. package/esm/theme/dark.js.map +1 -1
  114. package/esm/theme/index.d.ts +1 -0
  115. package/esm/theme/index.js +1 -0
  116. package/esm/theme/index.js.map +1 -1
  117. package/esm/theme/light.js +4 -3
  118. package/esm/theme/light.js.map +1 -1
  119. package/esm/transform/maybeTooltip.js +3 -1
  120. package/esm/transform/maybeTooltip.js.map +1 -1
  121. package/esm/utils/bounds.d.ts +26 -0
  122. package/esm/utils/bounds.js +41 -0
  123. package/esm/utils/bounds.js.map +1 -0
  124. package/esm/utils/color.d.ts +6 -0
  125. package/esm/utils/color.js +7 -0
  126. package/esm/utils/color.js.map +1 -0
  127. package/esm/utils/coordinate.d.ts +1 -0
  128. package/esm/utils/coordinate.js +12 -0
  129. package/esm/utils/coordinate.js.map +1 -1
  130. package/esm/utils/helper.d.ts +1 -0
  131. package/esm/utils/helper.js +3 -0
  132. package/esm/utils/helper.js.map +1 -1
  133. package/lib/api/mark/mark.js +0 -2
  134. package/lib/api/mark/mark.js.map +1 -1
  135. package/lib/api/mark/types.d.ts +0 -2
  136. package/lib/component/axis.js +5 -4
  137. package/lib/component/axis.js.map +1 -1
  138. package/lib/component/slider.js +2 -4
  139. package/lib/component/slider.js.map +1 -1
  140. package/lib/composition/mark.js +2 -1
  141. package/lib/composition/mark.js.map +1 -1
  142. package/lib/interaction/builtin/brushHighlight.d.ts +1 -1
  143. package/lib/interaction/index.d.ts +3 -0
  144. package/lib/interaction/index.js +7 -1
  145. package/lib/interaction/index.js.map +1 -1
  146. package/lib/interaction/native/brushHighlight.d.ts +15 -0
  147. package/lib/interaction/native/brushHighlight.js +289 -0
  148. package/lib/interaction/native/brushHighlight.js.map +1 -0
  149. package/lib/interaction/native/brushXHighlight.d.ts +1 -0
  150. package/lib/interaction/native/brushXHighlight.js +12 -0
  151. package/lib/interaction/native/brushXHighlight.js.map +1 -0
  152. package/lib/interaction/native/brushYHighlight.d.ts +1 -0
  153. package/lib/interaction/native/brushYHighlight.js +12 -0
  154. package/lib/interaction/native/brushYHighlight.js.map +1 -0
  155. package/lib/interaction/native/legendFilter.js +4 -13
  156. package/lib/interaction/native/legendFilter.js.map +1 -1
  157. package/lib/interaction/native/tooltip.js +93 -25
  158. package/lib/interaction/native/tooltip.js.map +1 -1
  159. package/lib/interaction/native/utils.d.ts +4 -0
  160. package/lib/interaction/native/utils.js +28 -1
  161. package/lib/interaction/native/utils.js.map +1 -1
  162. package/lib/label-transform/contrastReverse.d.ts +9 -0
  163. package/lib/label-transform/contrastReverse.js +52 -0
  164. package/lib/label-transform/contrastReverse.js.map +1 -0
  165. package/lib/label-transform/index.d.ts +8 -8
  166. package/lib/label-transform/index.js +9 -9
  167. package/lib/label-transform/index.js.map +1 -1
  168. package/lib/label-transform/overflowHide.d.ts +7 -0
  169. package/lib/label-transform/overflowHide.js +22 -0
  170. package/lib/label-transform/overflowHide.js.map +1 -0
  171. package/lib/label-transform/overlapDodgeY.d.ts +7 -0
  172. package/lib/label-transform/{dodgeY.js → overlapDodgeY.js} +6 -6
  173. package/lib/label-transform/overlapDodgeY.js.map +1 -0
  174. package/lib/label-transform/overlapHide.d.ts +7 -0
  175. package/lib/label-transform/overlapHide.js +28 -0
  176. package/lib/label-transform/overlapHide.js.map +1 -0
  177. package/lib/runtime/plot.js +24 -6
  178. package/lib/runtime/plot.js.map +1 -1
  179. package/lib/runtime/scale.js +16 -4
  180. package/lib/runtime/scale.js.map +1 -1
  181. package/lib/runtime/transform.js +10 -4
  182. package/lib/runtime/transform.js.map +1 -1
  183. package/lib/runtime/types/common.d.ts +1 -0
  184. package/lib/runtime/types/options.d.ts +1 -0
  185. package/lib/shape/label/label.js +3 -3
  186. package/lib/shape/label/label.js.map +1 -1
  187. package/lib/shape/label/position/area.d.ts +13 -0
  188. package/lib/shape/label/position/area.js +32 -0
  189. package/lib/shape/label/position/area.js.map +1 -0
  190. package/lib/shape/label/position/bottom.d.ts +1 -0
  191. package/lib/shape/label/position/bottom.js +6 -0
  192. package/lib/shape/label/position/bottom.js.map +1 -0
  193. package/lib/shape/label/position/bottomLeft.d.ts +1 -0
  194. package/lib/shape/label/position/bottomLeft.js +6 -0
  195. package/lib/shape/label/position/bottomLeft.js.map +1 -0
  196. package/lib/shape/label/position/bottomRight.d.ts +1 -0
  197. package/lib/shape/label/position/bottomRight.js +6 -0
  198. package/lib/shape/label/position/bottomRight.js.map +1 -0
  199. package/lib/shape/label/position/default.d.ts +20 -0
  200. package/lib/shape/label/{position.js → position/default.js} +10 -43
  201. package/lib/shape/label/position/default.js.map +1 -0
  202. package/lib/shape/label/position/index.d.ts +13 -0
  203. package/lib/shape/label/position/index.js +30 -0
  204. package/lib/shape/label/position/index.js.map +1 -0
  205. package/lib/shape/label/position/inside.d.ts +1 -0
  206. package/lib/shape/label/position/inside.js +6 -0
  207. package/lib/shape/label/position/inside.js.map +1 -0
  208. package/lib/shape/label/position/left.d.ts +1 -0
  209. package/lib/shape/label/position/left.js +6 -0
  210. package/lib/shape/label/position/left.js.map +1 -0
  211. package/lib/shape/label/position/outside.d.ts +1 -0
  212. package/lib/shape/label/position/outside.js +6 -0
  213. package/lib/shape/label/position/outside.js.map +1 -0
  214. package/lib/shape/label/position/right.d.ts +1 -0
  215. package/lib/shape/label/position/right.js +6 -0
  216. package/lib/shape/label/position/right.js.map +1 -0
  217. package/lib/shape/label/position/spider.d.ts +7 -0
  218. package/lib/shape/label/position/spider.js +44 -0
  219. package/lib/shape/label/position/spider.js.map +1 -0
  220. package/lib/shape/label/position/surround.d.ts +7 -0
  221. package/lib/shape/label/position/surround.js +41 -0
  222. package/lib/shape/label/position/surround.js.map +1 -0
  223. package/lib/shape/label/position/top.d.ts +1 -0
  224. package/lib/shape/label/position/top.js +6 -0
  225. package/lib/shape/label/position/top.js.map +1 -0
  226. package/lib/shape/label/position/topLeft.d.ts +1 -0
  227. package/lib/shape/label/position/topLeft.js +6 -0
  228. package/lib/shape/label/position/topLeft.js.map +1 -0
  229. package/lib/shape/label/position/topRight.d.ts +1 -0
  230. package/lib/shape/label/position/topRight.js +6 -0
  231. package/lib/shape/label/position/topRight.js.map +1 -0
  232. package/lib/spec/composition.d.ts +2 -0
  233. package/lib/spec/geometry.d.ts +1 -1
  234. package/lib/spec/interaction.d.ts +21 -5
  235. package/lib/spec/labelTransform.d.ts +24 -11
  236. package/lib/spec/theme.d.ts +5 -2
  237. package/lib/stdlib/index.js +2 -3
  238. package/lib/stdlib/index.js.map +1 -1
  239. package/lib/theme/academy.d.ts +3 -0
  240. package/lib/theme/academy.js +406 -0
  241. package/lib/theme/academy.js.map +1 -0
  242. package/lib/theme/dark.js +3 -2
  243. package/lib/theme/dark.js.map +1 -1
  244. package/lib/theme/index.d.ts +1 -0
  245. package/lib/theme/index.js +3 -1
  246. package/lib/theme/index.js.map +1 -1
  247. package/lib/theme/light.js +4 -3
  248. package/lib/theme/light.js.map +1 -1
  249. package/lib/transform/maybeTooltip.js +3 -1
  250. package/lib/transform/maybeTooltip.js.map +1 -1
  251. package/lib/utils/bounds.d.ts +26 -0
  252. package/lib/utils/bounds.js +48 -0
  253. package/lib/utils/bounds.js.map +1 -0
  254. package/lib/utils/color.d.ts +6 -0
  255. package/lib/utils/color.js +11 -0
  256. package/lib/utils/color.js.map +1 -0
  257. package/lib/utils/coordinate.d.ts +1 -0
  258. package/lib/utils/coordinate.js +14 -1
  259. package/lib/utils/coordinate.js.map +1 -1
  260. package/lib/utils/helper.d.ts +1 -0
  261. package/lib/utils/helper.js +5 -1
  262. package/lib/utils/helper.js.map +1 -1
  263. package/package.json +2 -2
  264. package/src/.DS_Store +0 -0
  265. package/src/api/mark/mark.ts +0 -2
  266. package/src/api/mark/types.ts +0 -2
  267. package/src/component/axis.ts +16 -11
  268. package/src/component/slider.ts +1 -3
  269. package/src/composition/mark.ts +2 -0
  270. package/src/data/.DS_Store +0 -0
  271. package/src/interaction/index.ts +3 -0
  272. package/src/interaction/native/brushHighlight.ts +346 -0
  273. package/src/interaction/native/brushXHighlight.ts +11 -0
  274. package/src/interaction/native/brushYHighlight.ts +11 -0
  275. package/src/interaction/native/legendFilter.ts +3 -14
  276. package/src/interaction/native/tooltip.ts +119 -32
  277. package/src/interaction/native/utils.ts +31 -0
  278. package/src/label-transform/contrastReverse.ts +56 -0
  279. package/src/label-transform/index.ts +8 -8
  280. package/src/label-transform/overflowHide.ts +23 -0
  281. package/src/label-transform/{dodgeY.ts → overlapDodgeY.ts} +6 -6
  282. package/src/label-transform/overlapHide.ts +32 -0
  283. package/src/runtime/plot.ts +35 -6
  284. package/src/runtime/scale.ts +15 -7
  285. package/src/runtime/transform.ts +13 -4
  286. package/src/runtime/types/common.ts +1 -0
  287. package/src/runtime/types/options.ts +1 -0
  288. package/src/shape/.DS_Store +0 -0
  289. package/src/shape/label/label.ts +4 -3
  290. package/src/shape/label/position/area.ts +39 -0
  291. package/src/shape/label/position/bottom.ts +1 -0
  292. package/src/shape/label/position/bottomLeft.ts +1 -0
  293. package/src/shape/label/position/bottomRight.ts +1 -0
  294. package/src/shape/label/{position.ts → position/default.ts} +12 -56
  295. package/src/shape/label/position/index.ts +13 -0
  296. package/src/shape/label/position/inside.ts +1 -0
  297. package/src/shape/label/position/left.ts +1 -0
  298. package/src/shape/label/position/outside.ts +1 -0
  299. package/src/shape/label/position/right.ts +1 -0
  300. package/src/shape/label/position/spider.ts +46 -0
  301. package/src/shape/label/position/surround.ts +42 -0
  302. package/src/shape/label/position/top.ts +1 -0
  303. package/src/shape/label/position/topLeft.ts +1 -0
  304. package/src/shape/label/position/topRight.ts +1 -0
  305. package/src/spec/composition.ts +2 -0
  306. package/src/spec/geometry.ts +2 -1
  307. package/src/spec/interaction.ts +28 -4
  308. package/src/spec/labelTransform.ts +29 -11
  309. package/src/spec/theme.ts +6 -2
  310. package/src/stdlib/index.ts +19 -7
  311. package/src/theme/academy.ts +408 -0
  312. package/src/theme/dark.ts +3 -2
  313. package/src/theme/index.ts +1 -0
  314. package/src/theme/light.ts +4 -3
  315. package/src/transform/maybeTooltip.ts +3 -1
  316. package/src/utils/bounds.ts +52 -0
  317. package/src/utils/color.ts +12 -0
  318. package/src/utils/coordinate.ts +12 -0
  319. package/src/utils/helper.ts +4 -0
  320. package/esm/label-transform/dodgeY.d.ts +0 -7
  321. package/esm/label-transform/dodgeY.js.map +0 -1
  322. package/esm/label-transform/hideOverlap.d.ts +0 -4
  323. package/esm/label-transform/hideOverlap.js +0 -48
  324. package/esm/label-transform/hideOverlap.js.map +0 -1
  325. package/esm/label-transform/spider.d.ts +0 -7
  326. package/esm/label-transform/spider.js +0 -30
  327. package/esm/label-transform/spider.js.map +0 -1
  328. package/esm/label-transform/surround.d.ts +0 -7
  329. package/esm/label-transform/surround.js +0 -30
  330. package/esm/label-transform/surround.js.map +0 -1
  331. package/esm/shape/label/position.d.ts +0 -25
  332. package/esm/shape/label/position.js.map +0 -1
  333. package/lib/label-transform/dodgeY.d.ts +0 -7
  334. package/lib/label-transform/dodgeY.js.map +0 -1
  335. package/lib/label-transform/hideOverlap.d.ts +0 -4
  336. package/lib/label-transform/hideOverlap.js +0 -52
  337. package/lib/label-transform/hideOverlap.js.map +0 -1
  338. package/lib/label-transform/spider.d.ts +0 -7
  339. package/lib/label-transform/spider.js +0 -34
  340. package/lib/label-transform/spider.js.map +0 -1
  341. package/lib/label-transform/surround.d.ts +0 -7
  342. package/lib/label-transform/surround.js +0 -34
  343. package/lib/label-transform/surround.js.map +0 -1
  344. package/lib/shape/label/position.d.ts +0 -25
  345. package/lib/shape/label/position.js.map +0 -1
  346. package/src/label-transform/hideOverlap.ts +0 -62
  347. package/src/label-transform/spider.ts +0 -37
  348. package/src/label-transform/surround.ts +0 -37
@@ -193,19 +193,28 @@ export function maybeNonAnimate(
193
193
  }
194
194
 
195
195
  function isTypedChannel(channel): boolean {
196
- if (typeof channel !== 'object' || channel instanceof Date) return false;
196
+ if (
197
+ typeof channel !== 'object' ||
198
+ channel instanceof Date ||
199
+ channel === null
200
+ ) {
201
+ return false;
202
+ }
197
203
  const { type } = channel;
198
204
  return defined(type);
199
205
  }
200
206
 
201
207
  function inferChannelType(data: Record<string, Primitive>[], channel): string {
202
208
  if (typeof channel === 'function') return 'transform';
203
- if (typeof channel === 'string' && data?.[0]?.[channel] !== undefined) {
204
- return 'field';
205
- }
209
+ if (typeof channel === 'string' && isField(data, channel)) return 'field';
206
210
  return 'constant';
207
211
  }
208
212
 
213
+ function isField(data: Record<string, Primitive>[], value: string): boolean {
214
+ if (!Array.isArray(data)) return false;
215
+ return data.some((d) => d[value] !== undefined);
216
+ }
217
+
209
218
  function normalizedDataSource(data) {
210
219
  // Return null as a placeholder.
211
220
  if (!data) return { type: 'inline', value: null };
@@ -22,6 +22,7 @@ export type G2ViewDescriptor = {
22
22
  components: G2GuideComponentOptions[];
23
23
  layout: Layout;
24
24
  key: string;
25
+ clip: boolean;
25
26
  labelTransform?: LabelTransform;
26
27
  // @todo More accurate type.
27
28
  style: Record<string, any>;
@@ -82,6 +82,7 @@ export type G2View = {
82
82
  labelTransform?: G2LabelTransformOptions[];
83
83
  style?: Record<string, any>;
84
84
  tooltip?: boolean;
85
+ clip?: boolean;
85
86
  };
86
87
 
87
88
  export type G2Mark = {
Binary file
@@ -5,7 +5,7 @@ import { applyStyle } from '../../shape/utils';
5
5
  import { isTranspose, isCircular } from '../../utils/coordinate';
6
6
  import { camelCase } from '../../utils/string';
7
7
  import { Advance } from '../text/advance';
8
- import { LabelPosition } from './position';
8
+ import { LabelPosition } from './position/default';
9
9
  import * as PositionProcessor from './position';
10
10
 
11
11
  export type LabelOptions = Record<string, any>;
@@ -22,6 +22,7 @@ function getDefaultStyle(
22
22
  value: Record<string, any>,
23
23
  coordinate: Coordinate,
24
24
  theme: G2Theme,
25
+ options: LabelOptions,
25
26
  ): Record<string, any> {
26
27
  // For non-series mark, calc position for label based on
27
28
  // position and the bounds of shape.
@@ -35,7 +36,7 @@ function getDefaultStyle(
35
36
  }
36
37
  return {
37
38
  ...t,
38
- ...processor(p, points, v, coordinate),
39
+ ...processor(p, points, v, coordinate, options),
39
40
  };
40
41
  }
41
42
 
@@ -50,7 +51,7 @@ export const Label: SC<LabelOptions> = (options) => {
50
51
  rotate = 0,
51
52
  transform = '',
52
53
  ...defaultStyle
53
- } = getDefaultStyle(points, value, coordinate, theme);
54
+ } = getDefaultStyle(points, value, coordinate, theme, options);
54
55
 
55
56
  return select(new Advance())
56
57
  .call(applyStyle, defaultStyle)
@@ -0,0 +1,39 @@
1
+ import { maxIndex } from 'd3-array';
2
+ import { Coordinate } from '@antv/coord';
3
+ import { Vector2 } from '../../../runtime';
4
+ import { sub, angle } from '../../../utils/vector';
5
+ import { LabelPosition } from './default';
6
+
7
+ /**
8
+ * Only for Area label.
9
+ */
10
+ export function area(
11
+ position: LabelPosition,
12
+ points: Vector2[],
13
+ value: Record<string, any>,
14
+ coordinate: Coordinate,
15
+ ) {
16
+ const l = points.length / 2;
17
+ const Y1 = points.slice(0, l);
18
+ const Y0 = points.slice(l);
19
+ // Get the maximal space for label.
20
+ let idx = maxIndex(Y1, (p, i) => Math.abs(p[1] - Y0[i][1]));
21
+ // Do not show label at first and last.
22
+ idx = Math.max(Math.min(idx, l - 2), 1);
23
+
24
+ const mid = (i: number): Vector2 => [Y1[i][0], (Y1[i][1] + Y0[i][1]) / 2];
25
+ const point = mid(idx);
26
+ const prev = mid(idx - 1);
27
+ const next = mid(idx + 1);
28
+
29
+ // todo: G rotate only support deg.
30
+ const rotate = (angle(sub(next, prev)) / Math.PI) * 180;
31
+
32
+ return {
33
+ x: point[0],
34
+ y: point[1],
35
+ transform: `rotate(${rotate}deg)`,
36
+ textAlign: 'center',
37
+ textBaseline: 'middle',
38
+ };
39
+ }
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as bottom } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as bottomLeft } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as bottomRight } from './default';
@@ -1,10 +1,9 @@
1
- import { maxIndex } from 'd3-array';
2
1
  import { Coordinate } from '@antv/coord';
3
- import { Vector2 } from '../../runtime';
4
- import { getArcObject } from '../../shape/utils';
5
- import { isCircular, isRadial } from '../../utils/coordinate';
6
- import { maybePercentage } from '../../utils/helper';
7
- import { sub, angle, mid } from '../../utils/vector';
2
+ import { Vector2 } from '../../../runtime';
3
+ import { getArcObject } from '../../../shape/utils';
4
+ import { isCircular, isRadial } from '../../../utils/coordinate';
5
+ import { maybePercentage } from '../../../utils/helper';
6
+ import { mid } from '../../../utils/vector';
8
7
 
9
8
  export type LabelPosition =
10
9
  | 'top'
@@ -17,9 +16,11 @@ export type LabelPosition =
17
16
  | 'bottom-right'
18
17
  | 'inside'
19
18
  | 'outside'
20
- | 'area';
19
+ | 'area'
20
+ | 'spider'
21
+ | 'surround';
21
22
 
22
- function inferNonCircularStyle(
23
+ export function inferNonCircularStyle(
23
24
  position: LabelPosition,
24
25
  points: Vector2[],
25
26
  value: Record<string, any>,
@@ -66,7 +67,7 @@ function inferNonCircularStyle(
66
67
  });
67
68
  }
68
69
 
69
- function inferRadialStyle(
70
+ export function inferRadialStyle(
70
71
  position: LabelPosition,
71
72
  points: Vector2[],
72
73
  value: Record<string, any>,
@@ -114,7 +115,7 @@ function inferRotation(
114
115
  return (angle / Math.PI) * 180 + append;
115
116
  }
116
117
 
117
- function inferCircularStyle(
118
+ export function inferCircularStyle(
118
119
  position: LabelPosition,
119
120
  points: Vector2[],
120
121
  value: Record<string, any>,
@@ -193,7 +194,7 @@ function inferIdentityStyle(position, points, value, coordinate) {
193
194
  };
194
195
  }
195
196
 
196
- function getDefaultStyle(
197
+ export function getDefaultStyle(
197
198
  position: LabelPosition,
198
199
  points: Vector2[],
199
200
  value: Record<string, any>,
@@ -216,48 +217,3 @@ function getDefaultStyle(
216
217
 
217
218
  return inferDefaultStyle(position, points, value, coordinate);
218
219
  }
219
-
220
- export const top = getDefaultStyle;
221
- export const bottom = getDefaultStyle;
222
- export const right = getDefaultStyle;
223
- export const left = getDefaultStyle;
224
- export const topLeft = getDefaultStyle;
225
- export const topRight = getDefaultStyle;
226
- export const bottomLeft = getDefaultStyle;
227
- export const bottomRight = getDefaultStyle;
228
- export const inside = getDefaultStyle;
229
- export const outside = getDefaultStyle;
230
-
231
- /**
232
- * Only for Area label.
233
- */
234
- export function area(
235
- position: LabelPosition,
236
- points: Vector2[],
237
- value: Record<string, any>,
238
- coordinate: Coordinate,
239
- ) {
240
- const l = points.length / 2;
241
- const Y1 = points.slice(0, l);
242
- const Y0 = points.slice(l);
243
- // Get the maximal space for label.
244
- let idx = maxIndex(Y1, (p, i) => Math.abs(p[1] - Y0[i][1]));
245
- // Do not show label at first and last.
246
- idx = Math.max(Math.min(idx, l - 2), 1);
247
-
248
- const mid = (i: number): Vector2 => [Y1[i][0], (Y1[i][1] + Y0[i][1]) / 2];
249
- const point = mid(idx);
250
- const prev = mid(idx - 1);
251
- const next = mid(idx + 1);
252
-
253
- // todo: G rotate only support deg.
254
- const rotate = (angle(sub(next, prev)) / Math.PI) * 180;
255
-
256
- return {
257
- x: point[0],
258
- y: point[1],
259
- transform: `rotate(${rotate}deg)`,
260
- textAlign: 'center',
261
- textBaseline: 'middle',
262
- };
263
- }
@@ -0,0 +1,13 @@
1
+ export { area } from './area';
2
+ export { bottom } from './bottom';
3
+ export { bottomLeft } from './bottomLeft';
4
+ export { bottomRight } from './bottomRight';
5
+ export { inside } from './inside';
6
+ export { left } from './left';
7
+ export { outside } from './outside';
8
+ export { right } from './right';
9
+ export { spider } from './spider';
10
+ export { surround } from './surround';
11
+ export { top } from './top';
12
+ export { topLeft } from './topLeft';
13
+ export { topRight } from './topRight';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as inside } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as left } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as outside } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as right } from './default';
@@ -0,0 +1,46 @@
1
+ import { Coordinate } from '@antv/coord';
2
+ import { sub } from '../../../utils/vector';
3
+ import { Vector2 } from '../../../runtime';
4
+ import { isCircular } from '../../../utils/coordinate';
5
+ import { maybePercentage } from '../../../utils/helper';
6
+ import { inferCircularStyle, LabelPosition } from './default';
7
+
8
+ /**
9
+ * Spider label transform only suitable for the labels in polar coordinate, labels should distinguish coordinate type.
10
+ */
11
+ export function spider(
12
+ position: LabelPosition,
13
+ points: Vector2[],
14
+ value: Record<string, any>,
15
+ coordinate: Coordinate,
16
+ options,
17
+ ) {
18
+ if (!isCircular(coordinate)) return {};
19
+ const { edgeDistance = 0 } = options;
20
+
21
+ const { ...style }: any = inferCircularStyle(
22
+ 'outside',
23
+ points,
24
+ value,
25
+ coordinate,
26
+ );
27
+ const { x: coordX, width } = coordinate.getOptions();
28
+ const center = coordinate.getCenter();
29
+ // todo: How to configure spider.
30
+ const margin = maybePercentage(edgeDistance, width);
31
+
32
+ const edgeX = coordX + margin;
33
+ const edgeX1 = coordX + width - margin;
34
+
35
+ const { x: originX, x0, y0 } = style;
36
+ const dx = originX <= center[0] ? edgeX - originX : edgeX1 - originX;
37
+ style.x += dx;
38
+
39
+ const { x, y } = style;
40
+ const p0 = sub([x0, y0], center);
41
+ const p1 = sub([0, y], center);
42
+ const p1x = p0[1] ? (p0[0] * p1[1]) / p0[1] + center[0] : x;
43
+ style.connectorPoints = [[p1x - x, 0]];
44
+
45
+ return style;
46
+ }
@@ -0,0 +1,42 @@
1
+ import { Coordinate } from '@antv/coord';
2
+ import { PolarCoordinate } from 'spec';
3
+ import { Vector2 } from '../../../runtime';
4
+ import { getRadius, isCircular } from '../../../utils/coordinate';
5
+ import { angleWithQuadrant } from '../../../utils/vector';
6
+ import { inferCircularStyle, LabelPosition } from './default';
7
+
8
+ /**
9
+ * Surround label transform is used to make labels surround circular.
10
+ */
11
+ export function surround(
12
+ position: LabelPosition,
13
+ points: Vector2[],
14
+ value: Record<string, any>,
15
+ coordinate: Coordinate,
16
+ options,
17
+ ) {
18
+ if (!isCircular(coordinate)) return {};
19
+
20
+ const { offset = 12 } = options;
21
+ const { ...style }: any = inferCircularStyle(
22
+ 'outside',
23
+ points,
24
+ value,
25
+ coordinate,
26
+ );
27
+ const center = coordinate.getCenter();
28
+ const radius = getRadius(coordinate) + offset;
29
+
30
+ const { x0, y0, connector, connectorLength2 = 0 } = style;
31
+ const labelAngle = angleWithQuadrant([x0 - center[0], y0 - center[1]]);
32
+ const length2 = connector
33
+ ? connectorLength2 * (Math.sin(labelAngle) < 0 ? -1 : 1)
34
+ : 0;
35
+ const newX = center[0] + Math.sin(labelAngle) * radius;
36
+ const newY = center[1] - Math.cos(labelAngle) * radius;
37
+ style.x = newX + length2;
38
+ style.y = newY;
39
+ style.connectorPoints = [[-length2, 0]];
40
+
41
+ return style;
42
+ }
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as top } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as topLeft } from './default';
@@ -0,0 +1 @@
1
+ export { getDefaultStyle as topRight } from './default';
@@ -24,6 +24,7 @@ export type Node =
24
24
 
25
25
  export type MarkComposition = Geometry & {
26
26
  title?: Title;
27
+ clip?: boolean;
27
28
  };
28
29
 
29
30
  export type ViewComposition = {
@@ -63,6 +64,7 @@ export type ViewComposition = {
63
64
  on?: Record<string, EventType | EventType[]>;
64
65
  // @todo
65
66
  style?: Record<string, any>;
67
+ clip?: boolean;
66
68
  };
67
69
 
68
70
  export type SpaceLayerComposition = {
@@ -92,7 +92,8 @@ export type ChannelTypes =
92
92
  | 'groupKey'
93
93
  | 'label'
94
94
  | 'position'
95
- | 'series';
95
+ | 'series'
96
+ | `tooltip${number}`;
96
97
 
97
98
  export type BaseGeometry<
98
99
  T extends GeometryTypes,
@@ -14,7 +14,10 @@ export type Interaction =
14
14
  | FisheyeInteraction
15
15
  | ChartIndex
16
16
  | CustomInteraction
17
- | LegendFilterInteraction;
17
+ | LegendFilterInteraction
18
+ | BrushHighlightInteraction
19
+ | BrushXHighlightInteraction
20
+ | BrushYHighlightInteraction;
18
21
  // | ElementListHighlightInteraction
19
22
  // | LegendActiveInteraction
20
23
  // | LegendHighlightInteraction
@@ -37,6 +40,9 @@ export type InteractionTypes =
37
40
  | 'fisheye'
38
41
  | 'tooltip'
39
42
  | 'legendFilter'
43
+ | 'brushXHighlight'
44
+ | 'brushYHighlight'
45
+ | 'brushHighlight'
40
46
  | InteractionComponent;
41
47
  // | 'elementListHighlight'
42
48
  // | 'legendActive'
@@ -56,9 +62,27 @@ export type BrushInteraction = {
56
62
 
57
63
  export type BrushHighlightInteraction = {
58
64
  type?: 'brushHighlight';
59
- brushType?: 'rect' | 'rectX' | 'rectY' | 'polygon';
60
- multiple?: boolean;
61
- };
65
+ reverse?: boolean;
66
+ shared?: boolean;
67
+ series?: boolean;
68
+ facet?: boolean;
69
+ } & Record<`${'mask' | 'highlighted' | 'unhighlighted'}${any}`, any>;
70
+
71
+ export type BrushXHighlightInteraction = {
72
+ type?: 'brushXHighlight';
73
+ reverse?: boolean;
74
+ shared?: boolean;
75
+ series?: boolean;
76
+ facet?: boolean;
77
+ } & Record<`${'mask' | 'highlighted' | 'unhighlighted'}${any}`, any>;
78
+
79
+ export type BrushYHighlightInteraction = {
80
+ type?: 'brushYHighlight';
81
+ reverse?: boolean;
82
+ shared?: boolean;
83
+ series?: boolean;
84
+ facet?: boolean;
85
+ } & Record<`${'mask' | 'highlighted' | 'unhighlighted'}${any}`, any>;
62
86
 
63
87
  export type BrushVisibleInteraction = {
64
88
  type?: 'brushVisible';
@@ -1,21 +1,39 @@
1
- export type LabelTransform = HideOverlapLabelTransform | DodgeYLabelTransform;
1
+ import { DisplayObject } from '@antv/g';
2
2
 
3
- export type HideOverlapLabelTransform = {
4
- type?: 'hideOverlap';
3
+ export type LabelTransform =
4
+ | OverlapHideTransform
5
+ | OverlapDodgeYTransform
6
+ | ContrastReverseTransform
7
+ | OverflowHideTransform;
8
+
9
+ export type OverlapHideTransform = {
10
+ type?: 'overlapHide';
11
+ /**
12
+ * The hide priority, is the comparator for label.sort().
13
+ */
14
+ priority?: (a: DisplayObject, b: DisplayObject) => number;
5
15
  };
6
16
 
7
- export type DodgeYLabelTransform = {
8
- type?: 'dodgeY';
9
- maxIter?: number;
17
+ export type OverlapDodgeYTransform = {
18
+ type?: 'overlapDodgeY';
19
+ maxIterations?: number;
10
20
  maxError?: number;
11
21
  padding?: number;
12
22
  };
13
23
 
14
- export type SpiderLabelTransform = {
15
- type?: 'spider';
16
- edgeDistance?: string | number;
24
+ export type ContrastReverseTransform = {
25
+ type: 'contrastReverse';
26
+ /**
27
+ * Transform when the contrast ratio < threshold.
28
+ * Default is `4.5`.
29
+ */
30
+ threshold?: number;
31
+ /**
32
+ * The optional color palette, default is [#000, #fff].
33
+ */
34
+ palette?: string[];
17
35
  };
18
36
 
19
- export type SurroundLabelTransform = {
20
- type?: 'surround';
37
+ export type OverflowHideTransform = {
38
+ type: 'overflowHide';
21
39
  };
package/src/spec/theme.ts CHANGED
@@ -3,9 +3,9 @@ import {
3
3
  ThemeComponent,
4
4
  } from '../runtime/types/component';
5
5
 
6
- export type Theme = LightTheme | DarkTheme | CustomTheme;
6
+ export type Theme = LightTheme | DarkTheme | AcademyTheme | CustomTheme;
7
7
 
8
- export type ThemeTypes = 'light' | 'dark' | ThemeComponent;
8
+ export type ThemeTypes = 'light' | 'dark' | 'academy' | ThemeComponent;
9
9
 
10
10
  export type LightTheme = {
11
11
  type?: 'light';
@@ -15,6 +15,10 @@ export type DarkTheme = {
15
15
  type?: 'dark';
16
16
  } & ThemeOptions;
17
17
 
18
+ export type AcademyTheme = {
19
+ type?: 'academy';
20
+ } & ThemeOptions;
21
+
18
22
  export type CustomTheme = {
19
23
  type?: ThemeComponent;
20
24
  } & ThemeOptions;
@@ -131,7 +131,7 @@ import {
131
131
  HollowPath,
132
132
  Shape as CustomShape,
133
133
  } from '../shape';
134
- import { Light, Dark } from '../theme';
134
+ import { Light, Dark, Academy } from '../theme';
135
135
  import {
136
136
  AxisX,
137
137
  AxisY,
@@ -171,6 +171,9 @@ import {
171
171
  Fisheye as ChartFisheye,
172
172
  Tooltip,
173
173
  LegendFilter,
174
+ BrushHighlight,
175
+ BrushXHighlight,
176
+ BrushYHighlight,
174
177
  // ElementHighlightByX,
175
178
  // ElementHighlightByColor,
176
179
  // ElementListHighlight,
@@ -255,7 +258,12 @@ import {
255
258
  Join,
256
259
  Sort,
257
260
  } from '../data';
258
- import { HideOverlap, DodgeY, Spider, Surround } from '../label-transform';
261
+ import {
262
+ OverlapDodgeY,
263
+ OverflowHide,
264
+ ContrastReverse,
265
+ OverlapHide,
266
+ } from '../label-transform';
259
267
  import { geoLibrary } from '../geo';
260
268
 
261
269
  export function createLibrary(): G2Library {
@@ -455,6 +463,7 @@ export function createLibrary(): G2Library {
455
463
  'shape.path.hollow': HollowPath,
456
464
  'theme.light': Light,
457
465
  'theme.dark': Dark,
466
+ 'theme.academy': Academy,
458
467
  'component.axisX': AxisX,
459
468
  'component.axisY': AxisY,
460
469
  'component.legendCategory': LegendCategory,
@@ -485,6 +494,9 @@ export function createLibrary(): G2Library {
485
494
  'interaction.chartIndex': ChartIndex,
486
495
  'interaction.tooltip': Tooltip,
487
496
  'interaction.legendFilter': LegendFilter,
497
+ 'interaction.brushHighlight': BrushHighlight,
498
+ 'interaction.brushXHighlight': BrushXHighlight,
499
+ 'interaction.brushYHighlight': BrushYHighlight,
488
500
  // 'interaction.elementSelected': ElementSelected,
489
501
  // 'interaction.elementHighlight': ElementHighlight,
490
502
  // 'interaction.elementHighlightByX': ElementHighlightByX,
@@ -495,7 +507,7 @@ export function createLibrary(): G2Library {
495
507
  // 'interaction.tooltip': Tooltip,
496
508
  // 'interaction.fisheye': FisheyeInteraction,
497
509
  // 'interaction.brush': Brush,
498
- // 'interaction.brushHighlight': BrushHighlight,
510
+
499
511
  // 'interaction.brushVisible': BrushVisible,
500
512
  // 'interaction.activeRegion': ActiveRegion,
501
513
  // 'interaction.ellipsisText': EllipsisText,
@@ -507,10 +519,10 @@ export function createLibrary(): G2Library {
507
519
  'composition.repeatMatrix': RepeatMatrix,
508
520
  'composition.facetCircle': FacetCircle,
509
521
  'composition.timingKeyframe': TimingKeyframe,
510
- 'labelTransform.hideOverlap': HideOverlap,
511
- 'labelTransform.dodgeY': DodgeY,
512
- 'labelTransform.spider': Spider,
513
- 'labelTransform.surround': Surround,
522
+ 'labelTransform.overlapHide': OverlapHide,
523
+ 'labelTransform.overlapDodgeY': OverlapDodgeY,
524
+ 'labelTransform.overflowHide': OverflowHide,
525
+ 'labelTransform.contrastReverse': ContrastReverse,
514
526
  ...geoLibrary,
515
527
  };
516
528
  }