@visactor/vrender-components 0.18.0-alpha.0 → 0.18.0-alpha.2

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 (199) hide show
  1. package/cjs/axis/base.js +24 -24
  2. package/cjs/axis/base.js.map +1 -1
  3. package/cjs/axis/grid/base.js +1 -1
  4. package/cjs/axis/grid/base.js.map +1 -1
  5. package/cjs/axis/line.js +59 -52
  6. package/cjs/axis/line.js.map +1 -1
  7. package/cjs/axis/overlap/auto-hide.d.ts +1 -0
  8. package/cjs/axis/overlap/auto-hide.js +10 -2
  9. package/cjs/axis/overlap/auto-hide.js.map +1 -1
  10. package/cjs/axis/overlap/auto-limit.d.ts +1 -0
  11. package/cjs/axis/overlap/auto-limit.js +5 -3
  12. package/cjs/axis/overlap/auto-limit.js.map +1 -1
  13. package/cjs/axis/type.d.ts +1 -0
  14. package/cjs/axis/type.js.map +1 -1
  15. package/cjs/brush/brush.js +4 -4
  16. package/cjs/brush/brush.js.map +1 -1
  17. package/cjs/checkbox/checkbox.js +2 -1
  18. package/cjs/checkbox/checkbox.js.map +1 -1
  19. package/cjs/core/type.d.ts +10 -8
  20. package/cjs/core/type.js.map +1 -1
  21. package/cjs/data-zoom/data-zoom.d.ts +6 -1
  22. package/cjs/data-zoom/data-zoom.js +180 -118
  23. package/cjs/data-zoom/data-zoom.js.map +1 -1
  24. package/cjs/data-zoom/type.d.ts +1 -0
  25. package/cjs/data-zoom/type.js.map +1 -1
  26. package/cjs/index.d.ts +2 -1
  27. package/cjs/index.js +3 -2
  28. package/cjs/index.js.map +1 -1
  29. package/cjs/indicator/indicator.d.ts +3 -1
  30. package/cjs/indicator/indicator.js +60 -46
  31. package/cjs/indicator/indicator.js.map +1 -1
  32. package/cjs/indicator/type.d.ts +1 -0
  33. package/cjs/indicator/type.js.map +1 -1
  34. package/cjs/label/arc.d.ts +2 -2
  35. package/cjs/label/arc.js +38 -35
  36. package/cjs/label/arc.js.map +1 -1
  37. package/cjs/label/base.d.ts +6 -8
  38. package/cjs/label/base.js +92 -65
  39. package/cjs/label/base.js.map +1 -1
  40. package/cjs/label/line.js +3 -4
  41. package/cjs/label/line.js.map +1 -1
  42. package/cjs/label/type.d.ts +15 -8
  43. package/cjs/label/type.js.map +1 -1
  44. package/cjs/label/util.d.ts +4 -0
  45. package/cjs/label/util.js +24 -3
  46. package/cjs/label/util.js.map +1 -1
  47. package/cjs/legend/base.js +1 -1
  48. package/cjs/legend/base.js.map +1 -1
  49. package/cjs/legend/color/color.d.ts +7 -0
  50. package/cjs/legend/color/color.js +16 -2
  51. package/cjs/legend/color/color.js.map +1 -1
  52. package/cjs/legend/discrete/discrete.d.ts +6 -2
  53. package/cjs/legend/discrete/discrete.js +139 -69
  54. package/cjs/legend/discrete/discrete.js.map +1 -1
  55. package/cjs/legend/discrete/type.d.ts +17 -7
  56. package/cjs/legend/discrete/type.js.map +1 -1
  57. package/cjs/legend/register.js +2 -2
  58. package/cjs/legend/register.js.map +1 -1
  59. package/cjs/legend/size/size.d.ts +1 -0
  60. package/cjs/legend/size/size.js +4 -1
  61. package/cjs/legend/size/size.js.map +1 -1
  62. package/cjs/legend/type.d.ts +2 -2
  63. package/cjs/legend/type.js.map +1 -1
  64. package/cjs/marker/area.js +5 -1
  65. package/cjs/marker/area.js.map +1 -1
  66. package/cjs/marker/base.d.ts +1 -0
  67. package/cjs/marker/base.js +6 -3
  68. package/cjs/marker/base.js.map +1 -1
  69. package/cjs/marker/line.js +7 -1
  70. package/cjs/marker/line.js.map +1 -1
  71. package/cjs/marker/point.d.ts +1 -0
  72. package/cjs/marker/point.js +24 -11
  73. package/cjs/marker/point.js.map +1 -1
  74. package/cjs/marker/type.d.ts +1 -0
  75. package/cjs/marker/type.js.map +1 -1
  76. package/cjs/pager/pager.js +5 -3
  77. package/cjs/pager/pager.js.map +1 -1
  78. package/cjs/scrollbar/scrollbar.js +19 -5
  79. package/cjs/scrollbar/scrollbar.js.map +1 -1
  80. package/cjs/segment/segment.js +1 -1
  81. package/cjs/segment/segment.js.map +1 -1
  82. package/cjs/slider/slider.d.ts +27 -0
  83. package/cjs/slider/slider.js +102 -13
  84. package/cjs/slider/slider.js.map +1 -1
  85. package/cjs/slider/type.d.ts +9 -1
  86. package/cjs/slider/type.js.map +1 -1
  87. package/cjs/tag/tag.js +28 -42
  88. package/cjs/tag/tag.js.map +1 -1
  89. package/cjs/title/title.js +2 -2
  90. package/cjs/title/title.js.map +1 -1
  91. package/cjs/tooltip/tooltip.js +1 -1
  92. package/cjs/tooltip/tooltip.js.map +1 -1
  93. package/cjs/util/limit-shape.d.ts +4 -0
  94. package/cjs/util/limit-shape.js +13 -4
  95. package/cjs/util/limit-shape.js.map +1 -1
  96. package/cjs/util/text.d.ts +5 -2
  97. package/cjs/util/text.js +19 -6
  98. package/cjs/util/text.js.map +1 -1
  99. package/es/axis/base.js +22 -26
  100. package/es/axis/base.js.map +1 -1
  101. package/es/axis/grid/base.js +1 -1
  102. package/es/axis/grid/base.js.map +1 -1
  103. package/es/axis/line.js +59 -50
  104. package/es/axis/line.js.map +1 -1
  105. package/es/axis/overlap/auto-hide.d.ts +1 -0
  106. package/es/axis/overlap/auto-hide.js +10 -2
  107. package/es/axis/overlap/auto-hide.js.map +1 -1
  108. package/es/axis/overlap/auto-limit.d.ts +1 -0
  109. package/es/axis/overlap/auto-limit.js +5 -3
  110. package/es/axis/overlap/auto-limit.js.map +1 -1
  111. package/es/axis/type.d.ts +1 -0
  112. package/es/axis/type.js.map +1 -1
  113. package/es/brush/brush.js +4 -4
  114. package/es/brush/brush.js.map +1 -1
  115. package/es/checkbox/checkbox.js +2 -1
  116. package/es/checkbox/checkbox.js.map +1 -1
  117. package/es/core/type.d.ts +10 -8
  118. package/es/core/type.js.map +1 -1
  119. package/es/data-zoom/data-zoom.d.ts +6 -1
  120. package/es/data-zoom/data-zoom.js +179 -116
  121. package/es/data-zoom/data-zoom.js.map +1 -1
  122. package/es/data-zoom/type.d.ts +1 -0
  123. package/es/data-zoom/type.js.map +1 -1
  124. package/es/index.d.ts +2 -1
  125. package/es/index.js +3 -1
  126. package/es/index.js.map +1 -1
  127. package/es/indicator/indicator.d.ts +3 -1
  128. package/es/indicator/indicator.js +57 -47
  129. package/es/indicator/indicator.js.map +1 -1
  130. package/es/indicator/type.d.ts +1 -0
  131. package/es/indicator/type.js.map +1 -1
  132. package/es/label/arc.d.ts +2 -2
  133. package/es/label/arc.js +38 -35
  134. package/es/label/arc.js.map +1 -1
  135. package/es/label/base.d.ts +6 -8
  136. package/es/label/base.js +92 -65
  137. package/es/label/base.js.map +1 -1
  138. package/es/label/line.js +3 -4
  139. package/es/label/line.js.map +1 -1
  140. package/es/label/type.d.ts +15 -8
  141. package/es/label/type.js.map +1 -1
  142. package/es/label/util.d.ts +4 -0
  143. package/es/label/util.js +22 -2
  144. package/es/label/util.js.map +1 -1
  145. package/es/legend/base.js +1 -1
  146. package/es/legend/base.js.map +1 -1
  147. package/es/legend/color/color.d.ts +7 -0
  148. package/es/legend/color/color.js +17 -3
  149. package/es/legend/color/color.js.map +1 -1
  150. package/es/legend/discrete/discrete.d.ts +6 -2
  151. package/es/legend/discrete/discrete.js +141 -67
  152. package/es/legend/discrete/discrete.js.map +1 -1
  153. package/es/legend/discrete/type.d.ts +17 -7
  154. package/es/legend/discrete/type.js.map +1 -1
  155. package/es/legend/register.js +3 -1
  156. package/es/legend/register.js.map +1 -1
  157. package/es/legend/size/size.d.ts +1 -0
  158. package/es/legend/size/size.js +4 -1
  159. package/es/legend/size/size.js.map +1 -1
  160. package/es/legend/type.d.ts +2 -2
  161. package/es/legend/type.js.map +1 -1
  162. package/es/marker/area.js +6 -2
  163. package/es/marker/area.js.map +1 -1
  164. package/es/marker/base.d.ts +1 -0
  165. package/es/marker/base.js +6 -3
  166. package/es/marker/base.js.map +1 -1
  167. package/es/marker/line.js +8 -2
  168. package/es/marker/line.js.map +1 -1
  169. package/es/marker/point.d.ts +1 -0
  170. package/es/marker/point.js +25 -11
  171. package/es/marker/point.js.map +1 -1
  172. package/es/marker/type.d.ts +1 -0
  173. package/es/marker/type.js.map +1 -1
  174. package/es/pager/pager.js +4 -3
  175. package/es/pager/pager.js.map +1 -1
  176. package/es/scrollbar/scrollbar.js +19 -5
  177. package/es/scrollbar/scrollbar.js.map +1 -1
  178. package/es/segment/segment.js +1 -1
  179. package/es/segment/segment.js.map +1 -1
  180. package/es/slider/slider.d.ts +27 -0
  181. package/es/slider/slider.js +102 -13
  182. package/es/slider/slider.js.map +1 -1
  183. package/es/slider/type.d.ts +9 -1
  184. package/es/slider/type.js.map +1 -1
  185. package/es/tag/tag.js +29 -45
  186. package/es/tag/tag.js.map +1 -1
  187. package/es/title/title.js +3 -3
  188. package/es/title/title.js.map +1 -1
  189. package/es/tooltip/tooltip.js +1 -1
  190. package/es/tooltip/tooltip.js.map +1 -1
  191. package/es/util/limit-shape.d.ts +4 -0
  192. package/es/util/limit-shape.js +11 -3
  193. package/es/util/limit-shape.js.map +1 -1
  194. package/es/util/text.d.ts +5 -2
  195. package/es/util/text.js +17 -5
  196. package/es/util/text.js.map +1 -1
  197. package/package.json +3 -3
  198. package/dist/index.js +0 -29932
  199. package/dist/index.min.js +0 -1
@@ -2,12 +2,10 @@ import { merge, isValid, array, isValidNumber, get } from "@visactor/vutils";
2
2
 
3
3
  import { AbstractComponent } from "../core/base";
4
4
 
5
- import { measureTextSize } from "../util";
5
+ import { isRichText, measureTextSize, richTextAttributeTransform } from "../util";
6
6
 
7
7
  import { DEFAULT_INDICATOR_THEME } from "./config";
8
8
 
9
- import { DEFAULT_HTML_TEXT_SPEC } from "../constant";
10
-
11
9
  import { loadIndicatorComponent } from "./register";
12
10
 
13
11
  loadIndicatorComponent();
@@ -17,7 +15,7 @@ export class Indicator extends AbstractComponent {
17
15
  super(...arguments), this.name = "indicator";
18
16
  }
19
17
  render() {
20
- var _a, _b, _c;
18
+ var _a;
21
19
  const {visible: visible, title: title = {}, content: content, size: size, limitRatio: limitRatio = 1 / 0} = this.attribute, limit = Math.min(size.width, size.height) * limitRatio, group = this.createOrUpdateChild("indicator-container", {
22
20
  x: 0,
23
21
  y: 0,
@@ -26,20 +24,7 @@ export class Indicator extends AbstractComponent {
26
24
  if (!0 !== visible) return void (group && group.hideAll());
27
25
  if (isValid(title)) if (!1 !== title.visible) {
28
26
  const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, "title.style"), title.style);
29
- "rich" === titleStyle.type ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({
30
- textConfig: titleStyle.text
31
- }, titleStyle), {
32
- visible: title.visible,
33
- x: 0,
34
- y: 0,
35
- width: null !== (_a = titleStyle.width) && void 0 !== _a ? _a : 0,
36
- height: null !== (_b = titleStyle.height) && void 0 !== _b ? _b : 0
37
- }), "richtext") : "html" === titleStyle.type ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({
38
- textConfig: [],
39
- html: Object.assign(Object.assign({
40
- dom: titleStyle.text
41
- }, DEFAULT_HTML_TEXT_SPEC), titleStyle)
42
- }, titleStyle), {
27
+ isRichText(titleStyle) ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, richTextAttributeTransform(titleStyle)), {
43
28
  visible: title.visible,
44
29
  x: 0,
45
30
  y: 0
@@ -48,64 +33,89 @@ export class Indicator extends AbstractComponent {
48
33
  visible: title.visible,
49
34
  x: 0,
50
35
  y: 0
51
- }), "text"), title.autoFit && isValidNumber(limit) && this._setAutoFit(limit, this._title, title),
36
+ }), "text"), title.autoFit && isValidNumber(limit) && this._setLocalAutoFit(limit, this._title, title),
52
37
  title.autoLimit && isValidNumber(limitRatio) && this._title.setAttribute("maxLineWidth", limit);
53
38
  } else {
54
39
  const titleNode = group.find((node => "indicator-title" === node.name), !1);
55
40
  titleNode && group.removeChild(titleNode), this._title = void 0;
56
41
  }
57
- const titleHeight = this._title ? this._title.AABBBounds.height() : 0;
58
42
  if (isValid(content)) {
59
- const titleSpace = this._title && title.space ? title.space : 0, contents = array(content), contentComponents = [];
60
- let lastContentHeight = 0;
43
+ const contents = array(content), contentComponents = [];
61
44
  contents.forEach(((contentItem, i) => {
62
- var _a, _b;
63
45
  if (!1 !== contentItem.visible) {
64
46
  const contentStyle = merge({}, get(DEFAULT_INDICATOR_THEME, "content.style"), contentItem.style);
65
47
  let contentComponent;
66
- contentComponent = "rich" === contentStyle.type ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({
67
- textConfig: contentStyle.text
68
- }, contentStyle), {
69
- visible: title.visible,
70
- x: 0,
71
- y: titleHeight + titleSpace + lastContentHeight,
72
- width: null !== (_a = contentStyle.width) && void 0 !== _a ? _a : 0,
73
- height: null !== (_b = contentStyle.height) && void 0 !== _b ? _b : 0
74
- }), "richtext") : "html" === contentStyle.type ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({
75
- textConfig: [],
76
- html: Object.assign(Object.assign({
77
- dom: contentStyle.text
78
- }, DEFAULT_HTML_TEXT_SPEC), contentStyle)
79
- }, contentStyle), {
48
+ contentComponent = isRichText(contentStyle) ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, richTextAttributeTransform(contentStyle)), {
80
49
  visible: title.visible,
81
50
  x: 0,
82
- y: titleHeight + titleSpace + lastContentHeight
51
+ y: 0
83
52
  }), "richtext") : group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, contentStyle), {
84
53
  lineHeight: isValid(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,
85
54
  visible: contentItem.visible,
86
55
  x: 0,
87
- y: titleHeight + titleSpace + lastContentHeight
88
- }), "text"), contentItem.autoFit && isValidNumber(limit) && this._setAutoFit(limit, contentComponent, contentItem),
56
+ y: 0
57
+ }), "text"), contentItem.autoFit && isValidNumber(limit) && this._setLocalAutoFit(limit, contentComponent, contentItem),
89
58
  contentItem.autoLimit && isValidNumber(limitRatio) && contentComponent.setAttribute("maxLineWidth", limit),
90
59
  contentComponents.push(contentComponent);
91
- const contentSpace = contentItem.space ? contentItem.space : 0;
92
- lastContentHeight += contentComponent.AABBBounds.height() + contentSpace;
93
60
  } else {
94
61
  const contentItemNode = group.find((node => node.name === "indicator-content-" + i), !1);
95
62
  contentItemNode && group.removeChild(contentItemNode);
96
63
  }
97
64
  })), this._content = contentComponents;
98
65
  }
99
- const totalHeight = null !== (_c = null == group ? void 0 : group.AABBBounds.height()) && void 0 !== _c ? _c : 0;
66
+ this._setGlobalAutoFit(limit), this._setYPosition();
67
+ const totalHeight = null !== (_a = null == group ? void 0 : group.AABBBounds.height()) && void 0 !== _a ? _a : 0;
100
68
  group.setAttribute("y", size.height / 2 - totalHeight / 2), group.setAttribute("x", size.width / 2);
101
69
  }
102
- _setAutoFit(limit, indicatorItem, indicatorItemSpec) {
103
- var _a, _b, _c, _d, _e, _f;
104
- const originWidth = measureTextSize(null !== (_b = null === (_a = indicatorItemSpec.style) || void 0 === _a ? void 0 : _a.text) && void 0 !== _b ? _b : "", null !== (_c = indicatorItemSpec.style) && void 0 !== _c ? _c : {}).width;
70
+ _setLocalAutoFit(limit, indicatorItem, indicatorItemSpec) {
71
+ var _a, _b, _c, _d, _e, _f, _g, _h;
72
+ if ("default" !== (null !== (_a = indicatorItemSpec.fitStrategy) && void 0 !== _a ? _a : "default")) return;
73
+ const originWidth = measureTextSize(null !== (_c = null === (_b = indicatorItemSpec.style) || void 0 === _b ? void 0 : _b.text) && void 0 !== _c ? _c : "", null !== (_d = indicatorItemSpec.style) && void 0 !== _d ? _d : {}, null === (_e = this.stage) || void 0 === _e ? void 0 : _e.getTheme().text.fontFamily).width;
105
74
  if (originWidth > 0) {
106
- const ratio = limit * (null !== (_d = indicatorItemSpec.fitPercent) && void 0 !== _d ? _d : .5) / originWidth, fontSize = Math.floor((null !== (_f = null === (_e = indicatorItemSpec.style) || void 0 === _e ? void 0 : _e.fontSize) && void 0 !== _f ? _f : 20) * ratio);
75
+ const ratio = limit * (null !== (_f = indicatorItemSpec.fitPercent) && void 0 !== _f ? _f : .5) / originWidth, fontSize = Math.floor((null !== (_h = null === (_g = indicatorItemSpec.style) || void 0 === _g ? void 0 : _g.fontSize) && void 0 !== _h ? _h : 20) * ratio);
107
76
  indicatorItem.setAttribute("fontSize", fontSize), indicatorItem.setAttribute("lineHeight", isValid(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize);
108
77
  }
109
78
  }
79
+ _setGlobalAutoFit(limit) {
80
+ var _a, _b, _c, _d, _e, _f, _g;
81
+ const r = limit / 2, autoFitTexts = [];
82
+ let otherHeight = 0;
83
+ const titleSpec = null !== (_a = this.attribute.title) && void 0 !== _a ? _a : {};
84
+ titleSpec.autoFit && "inscribed" === titleSpec.fitStrategy ? (this._title.setAttribute("fontSize", 12),
85
+ autoFitTexts.push({
86
+ text: this._title,
87
+ spec: null !== (_b = this.attribute.title) && void 0 !== _b ? _b : {}
88
+ })) : otherHeight += null !== (_f = null === (_e = null === (_d = null === (_c = this._title) || void 0 === _c ? void 0 : _c.AABBBounds) || void 0 === _d ? void 0 : _d.height) || void 0 === _e ? void 0 : _e.call(_d)) && void 0 !== _f ? _f : 0;
89
+ const titleSpace = null !== (_g = titleSpec.space) && void 0 !== _g ? _g : 0;
90
+ if (otherHeight += titleSpace, array(this.attribute.content).filter((contentSpec => !1 !== contentSpec.visible)).forEach(((contentSpec, index) => {
91
+ var _a, _b, _c, _d;
92
+ const contentText = this._content[index];
93
+ contentSpec.autoFit && "inscribed" === contentSpec.fitStrategy ? (contentText.setAttribute("fontSize", 12),
94
+ autoFitTexts.push({
95
+ text: contentText,
96
+ spec: contentSpec
97
+ })) : otherHeight += null !== (_c = null === (_b = null === (_a = null == contentText ? void 0 : contentText.AABBBounds) || void 0 === _a ? void 0 : _a.height) || void 0 === _b ? void 0 : _b.call(_a)) && void 0 !== _c ? _c : 0;
98
+ const contentSpace = null !== (_d = contentSpec.space) && void 0 !== _d ? _d : 0;
99
+ otherHeight += contentSpace;
100
+ })), autoFitTexts.length <= 0) return;
101
+ const ra = 12 / autoFitTexts.reduce(((width, textItem) => Math.max(width, textItem.text.AABBBounds.width())), 0) * autoFitTexts.length, h = otherHeight / 2, a = ra ** 2 + 1, b = 2 * h * ra, c = h ** 2 - r ** 2, y = 2 * (ra * ((-b + Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)) + h), lineHeight = (y - otherHeight) / autoFitTexts.length;
102
+ isValidNumber(y) && autoFitTexts.forEach((textItem => {
103
+ var _a;
104
+ const specLineHeight = null === (_a = textItem.spec.style) || void 0 === _a ? void 0 : _a.lineHeight;
105
+ textItem.text.setAttribute("fontSize", lineHeight), textItem.text.setAttribute("lineHeight", isValid(specLineHeight) ? specLineHeight : lineHeight);
106
+ }));
107
+ }
108
+ _setYPosition() {
109
+ var _a, _b, _c, _d, _e, _f;
110
+ let lastContentHeight = 0;
111
+ const titleHeight = null !== (_d = null === (_c = null === (_b = null === (_a = this._title) || void 0 === _a ? void 0 : _a.AABBBounds) || void 0 === _b ? void 0 : _b.height) || void 0 === _c ? void 0 : _c.call(_b)) && void 0 !== _d ? _d : 0, titleSpace = null !== (_f = null === (_e = this.attribute.title) || void 0 === _e ? void 0 : _e.space) && void 0 !== _f ? _f : 0;
112
+ array(this.attribute.content).filter((contentSpec => !1 !== contentSpec.visible)).forEach(((contentSpec, index) => {
113
+ var _a;
114
+ const contentText = this._content[index];
115
+ contentText.setAttribute("y", titleHeight + titleSpace + lastContentHeight);
116
+ const contentSpace = null !== (_a = contentSpec.space) && void 0 !== _a ? _a : 0;
117
+ lastContentHeight += contentText.AABBBounds.height() + contentSpace;
118
+ }));
119
+ }
110
120
  }
111
121
  //# sourceMappingURL=indicator.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE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CAAC,CAAC,GAAG,WAAW,CAAC;YAC5E,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAA,MAAA,iBAAiB,CAAC,KAAK,0CAAE,QAAQ,mCAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;YAC/E,aAAa,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACjD,aAAa,CAAC,YAAY,CACxB,YAAY,EACZ,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAC5F,CAAC;SACH;IACH,CAAC;CACF","file":"indicator.js","sourcesContent":["/**\n * @description 指标卡组件\n */\nimport type { IGroup, INode, IText, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport { merge, isValid, array, isValidNumber, get } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { measureTextSize } from '../util';\nimport type { IndicatorAttributes, IndicatorItemSpec } from './type';\nimport { DEFAULT_INDICATOR_THEME } from './config';\nimport { DEFAULT_HTML_TEXT_SPEC } from '../constant';\nimport { loadIndicatorComponent } from './register';\n\nloadIndicatorComponent();\nexport class Indicator extends AbstractComponent<Required<IndicatorAttributes>> {\n name = 'indicator';\n\n private _title?: IText;\n private _content?: IText | IText[];\n\n protected render() {\n const { visible, title = {}, content, size, limitRatio = Infinity } = this.attribute as IndicatorAttributes;\n\n const limit = Math.min(size.width, size.height) * limitRatio;\n\n const group = this.createOrUpdateChild('indicator-container', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n // 指标卡全部隐藏\n if (visible !== true) {\n group && group.hideAll();\n return;\n }\n\n if (isValid(title)) {\n if (title.visible !== false) {\n const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'title.style'), title.style);\n if (titleStyle.type === 'rich') {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n textConfig: titleStyle.text,\n ...titleStyle,\n visible: title.visible,\n x: 0,\n y: 0,\n width: titleStyle.width ?? 0,\n height: titleStyle.height ?? 0\n },\n 'richtext'\n ) as IText;\n } else if (titleStyle.type === 'html') {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n textConfig: [],\n html: {\n dom: titleStyle.text as string,\n ...DEFAULT_HTML_TEXT_SPEC,\n ...titleStyle\n },\n ...titleStyle,\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'richtext'\n ) as IText;\n } else {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n ...titleStyle,\n /**\n * 加入以下逻辑:如果没有声明lineHeight,默认 lineHeight 等于 fontSize\n * 因为如果不声明 vrender 底层会默认给文本加上 2px 的高度,会影响布局计算\n * 注意:在autoFit改变fontsize时,lineHeight也要同步修改\n */\n lineHeight: isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (title.autoFit && isValidNumber(limit)) {\n this._setAutoFit(limit, this._title, title);\n }\n\n //auto-limit\n if (title.autoLimit && isValidNumber(limitRatio)) {\n this._title.setAttribute('maxLineWidth', limit);\n }\n } else {\n /**\n * indicator部分隐藏\n * 例如title隐藏了,content还保留。直接设置visible:false 计算group.AABBounts是错的,影响上下居中。\n * 这里把隐藏的nodes删除后,group.AABBounts计算才正确。\n */\n const titleNode = group.find(node => node.name === 'indicator-title', false);\n titleNode && group.removeChild(titleNode as INode);\n this._title = undefined;\n }\n }\n\n const titleHeight = this._title ? this._title.AABBBounds.height() : 0;\n\n if (isValid(content)) {\n const titleSpace = this._title ? (title.space ? title.space : 0) : 0;\n const contents: IndicatorItemSpec[] = array(content);\n const contentComponents: IText[] = [];\n let lastContentHeight = 0;\n contents.forEach((contentItem, i) => {\n if (contentItem.visible !== false) {\n const contentStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'content.style'), contentItem.style);\n let contentComponent;\n if (contentStyle.type === 'rich') {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n textConfig: contentStyle.text,\n ...contentStyle,\n visible: title.visible,\n x: 0,\n y: titleHeight + titleSpace + lastContentHeight,\n width: contentStyle.width ?? 0,\n height: contentStyle.height ?? 0\n },\n 'richtext'\n ) as IText;\n } else if (contentStyle.type === 'html') {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n textConfig: [],\n html: {\n dom: contentStyle.text as string,\n ...DEFAULT_HTML_TEXT_SPEC,\n ...contentStyle\n },\n ...contentStyle,\n visible: title.visible,\n x: 0,\n y: titleHeight + titleSpace + lastContentHeight\n },\n 'richtext'\n ) as IText;\n } else {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n ...contentStyle,\n lineHeight: isValid(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,\n visible: contentItem.visible,\n x: 0,\n y: titleHeight + titleSpace + lastContentHeight\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (contentItem.autoFit && isValidNumber(limit)) {\n this._setAutoFit(limit, contentComponent, contentItem);\n }\n\n //auto-limit\n if (contentItem.autoLimit && isValidNumber(limitRatio)) {\n contentComponent.setAttribute('maxLineWidth', limit);\n }\n\n contentComponents.push(contentComponent);\n const contentSpace = contentItem.space ? contentItem.space : 0;\n lastContentHeight += contentComponent.AABBBounds.height() + contentSpace;\n } else {\n /**\n * indicator部分隐藏\n */\n const contentItemNode = group.find(node => node.name === 'indicator-content-' + i, false);\n contentItemNode && group.removeChild(contentItemNode as INode);\n }\n });\n this._content = contentComponents;\n }\n\n const totalHeight = group?.AABBBounds.height() ?? 0;\n group.setAttribute('y', size.height / 2 - totalHeight / 2);\n group.setAttribute('x', size.width / 2);\n }\n\n private _setAutoFit(limit: number, indicatorItem: IText, indicatorItemSpec: IndicatorItemSpec) {\n const originWidth = measureTextSize(\n (indicatorItemSpec.style?.text ?? '') as string | number | number[] | string[],\n (indicatorItemSpec.style ?? {}) as Partial<ITextGraphicAttribute>\n ).width;\n if (originWidth > 0) {\n const ratio = (limit * (indicatorItemSpec.fitPercent ?? 0.5)) / originWidth;\n const fontSize = Math.floor((indicatorItemSpec.style?.fontSize ?? 20) * ratio);\n indicatorItem.setAttribute('fontSize', fontSize);\n indicatorItem.setAttribute(\n 'lineHeight',\n isValid(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize\n );\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAElF,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,sBAAsB,EAAE,CAAC;AACzB,MAAM,OAAO,SAAU,SAAQ,iBAAgD;IAA/E;;QACE,SAAI,GAAG,WAAW,CAAC;IA4OrB,CAAC;IAvOW,MAAM;;QACd,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAgC,CAAC;QAE5G,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;QAE7D,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,qBAAqB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,CAAW,CAAC;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CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YAClG,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEO,aAAa;;QACnB,IAAI,iBAAiB,GAAG,CAAC,CAAC;QAE1B,MAAM,WAAW,GAAG,MAAA,MAAA,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU,0CAAE,MAAM,kDAAI,mCAAI,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACpD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAC1B,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,KAAK,KAAK,CAAC;aACpD,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;;YAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACzC,WAAW,CAAC,YAAY,CAAC,GAAG,EAAE,WAAW,GAAG,UAAU,GAAG,iBAAiB,CAAC,CAAC;YAC5E,MAAM,YAAY,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,CAAC,CAAC;YAC5C,iBAAiB,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;CACF","file":"indicator.js","sourcesContent":["/**\n * @description 指标卡组件\n */\nimport type { IGroup, INode, IText, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport { merge, isValid, array, isValidNumber, get } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { IndicatorAttributes, IndicatorItemSpec } from './type';\nimport { DEFAULT_INDICATOR_THEME } from './config';\nimport { loadIndicatorComponent } from './register';\n\nloadIndicatorComponent();\nexport class Indicator extends AbstractComponent<Required<IndicatorAttributes>> {\n name = 'indicator';\n\n private _title?: IText;\n private _content?: IText | IText[];\n\n protected render() {\n const { visible, title = {}, content, size, limitRatio = Infinity } = this.attribute as IndicatorAttributes;\n\n const limit = Math.min(size.width, size.height) * limitRatio;\n\n const group = this.createOrUpdateChild('indicator-container', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n // 指标卡全部隐藏\n if (visible !== true) {\n group && group.hideAll();\n return;\n }\n\n if (isValid(title)) {\n if (title.visible !== false) {\n const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'title.style'), title.style);\n if (isRichText(titleStyle)) {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n ...richTextAttributeTransform(titleStyle),\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'richtext'\n ) as IText;\n } else {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n ...titleStyle,\n /**\n * 加入以下逻辑:如果没有声明lineHeight,默认 lineHeight 等于 fontSize\n * 因为如果不声明 vrender 底层会默认给文本加上 2px 的高度,会影响布局计算\n * 注意:在autoFit改变fontsize时,lineHeight也要同步修改\n */\n lineHeight: isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (title.autoFit && isValidNumber(limit)) {\n this._setLocalAutoFit(limit, this._title, title);\n }\n\n //auto-limit\n if (title.autoLimit && isValidNumber(limitRatio)) {\n this._title.setAttribute('maxLineWidth', limit);\n }\n } else {\n /**\n * indicator部分隐藏\n * 例如title隐藏了,content还保留。直接设置visible:false 计算group.AABBounts是错的,影响上下居中。\n * 这里把隐藏的nodes删除后,group.AABBounts计算才正确。\n */\n const titleNode = group.find(node => node.name === 'indicator-title', false);\n titleNode && group.removeChild(titleNode as INode);\n this._title = undefined;\n }\n }\n\n if (isValid(content)) {\n const contents: IndicatorItemSpec[] = array(content);\n const contentComponents: IText[] = [];\n contents.forEach((contentItem, i) => {\n if (contentItem.visible !== false) {\n const contentStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'content.style'), contentItem.style);\n let contentComponent;\n if (isRichText(contentStyle)) {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n ...richTextAttributeTransform(contentStyle),\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'richtext'\n ) as IText;\n } else {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n ...contentStyle,\n lineHeight: isValid(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,\n visible: contentItem.visible,\n x: 0,\n y: 0\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (contentItem.autoFit && isValidNumber(limit)) {\n this._setLocalAutoFit(limit, contentComponent, contentItem);\n }\n\n //auto-limit\n if (contentItem.autoLimit && isValidNumber(limitRatio)) {\n contentComponent.setAttribute('maxLineWidth', limit);\n }\n\n contentComponents.push(contentComponent);\n } else {\n /**\n * indicator部分隐藏\n */\n const contentItemNode = group.find(node => node.name === 'indicator-content-' + i, false);\n contentItemNode && group.removeChild(contentItemNode as INode);\n }\n });\n this._content = contentComponents;\n }\n\n this._setGlobalAutoFit(limit);\n this._setYPosition();\n\n const totalHeight = group?.AABBBounds.height() ?? 0;\n group.setAttribute('y', size.height / 2 - totalHeight / 2);\n group.setAttribute('x', size.width / 2);\n }\n\n private _setLocalAutoFit(limit: number, indicatorItem: IText, indicatorItemSpec: IndicatorItemSpec) {\n // only apply local auto fit for default auto fit text\n if ((indicatorItemSpec.fitStrategy ?? 'default') !== 'default') {\n return;\n }\n const originWidth = measureTextSize(\n (indicatorItemSpec.style?.text ?? '') as string | number | number[] | string[],\n (indicatorItemSpec.style ?? {}) as Partial<ITextGraphicAttribute>,\n this.stage?.getTheme().text.fontFamily\n ).width;\n if (originWidth > 0) {\n const ratio = (limit * (indicatorItemSpec.fitPercent ?? 0.5)) / originWidth;\n const fontSize = Math.floor((indicatorItemSpec.style?.fontSize ?? 20) * ratio);\n indicatorItem.setAttribute('fontSize', fontSize);\n indicatorItem.setAttribute(\n 'lineHeight',\n isValid(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize\n );\n }\n }\n\n private _setGlobalAutoFit(limit: number) {\n // compute the inscribed rect width & height for all texts\n // the font size will be determined by the longest text\n // 1. hx^2 + hy^2 = r^2\n // 2. hy = ra * hx + h\n // -> (ra^2 + 1) * x^2 + (2 * h * ra) * x + (h^2 - r^2) = 0\n\n const r = limit / 2;\n\n // unify the initial font size for auto fit texts\n const singleHeight = 12;\n const autoFitTexts: { text: IText; spec: IndicatorItemSpec }[] = [];\n // other text height\n let otherHeight = 0;\n // non auto fit title height\n const titleSpec = this.attribute.title ?? {};\n if (titleSpec.autoFit && titleSpec.fitStrategy === 'inscribed') {\n this._title.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: this._title, spec: this.attribute.title ?? {} });\n } else {\n otherHeight += this._title?.AABBBounds?.height?.() ?? 0;\n }\n const titleSpace = titleSpec.space ?? 0;\n otherHeight += titleSpace;\n // non auto fit content height\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n if (contentSpec.autoFit && contentSpec.fitStrategy === 'inscribed') {\n contentText.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: contentText, spec: contentSpec });\n } else {\n otherHeight += contentText?.AABBBounds?.height?.() ?? 0;\n }\n const contentSpace = contentSpec.space ?? 0;\n otherHeight += contentSpace;\n });\n if (autoFitTexts.length <= 0) {\n return;\n }\n\n // max width for all auto fit texts\n const maxWidth = autoFitTexts.reduce((width, textItem) => {\n return Math.max(width, textItem.text.AABBBounds.width());\n }, 0);\n\n // y = x * (singleHeight / maxWidth * textCount) + otherHeight\n // hy = hx * (singleHeight / maxWidth * textCount) + otherHeight / 2\n const ra = (singleHeight / maxWidth) * autoFitTexts.length;\n const h = otherHeight / 2;\n const a = ra ** 2 + 1;\n const b = 2 * h * ra;\n const c = h ** 2 - r ** 2;\n const hx = (-b + Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a);\n const hy = ra * hx + h;\n const y = 2 * hy;\n const lineHeight = (y - otherHeight) / autoFitTexts.length;\n if (isValidNumber(y)) {\n autoFitTexts.forEach(textItem => {\n const specLineHeight = textItem.spec.style?.lineHeight;\n textItem.text.setAttribute('fontSize', lineHeight);\n textItem.text.setAttribute('lineHeight', isValid(specLineHeight) ? specLineHeight : lineHeight);\n });\n }\n }\n\n private _setYPosition() {\n let lastContentHeight = 0;\n\n const titleHeight = this._title?.AABBBounds?.height?.() ?? 0;\n const titleSpace = this.attribute.title?.space ?? 0;\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n contentText.setAttribute('y', titleHeight + titleSpace + lastContentHeight);\n const contentSpace = contentSpec.space ?? 0;\n lastContentHeight += contentText.AABBBounds.height() + contentSpace;\n });\n }\n}\n"]}
@@ -18,5 +18,6 @@ export interface IndicatorItemSpec {
18
18
  autoLimit?: boolean;
19
19
  autoFit?: boolean;
20
20
  fitPercent?: number;
21
+ fitStrategy?: 'default' | 'inscribed';
21
22
  style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;
22
23
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/indicator/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { IGroupGraphicAttribute, ITextGraphicAttribute, IRichTextCharacter } from '@visactor/vrender-core';\nimport type { TextContent } from '../core/type';\n\nexport interface IndicatorAttributes extends IGroupGraphicAttribute {\n /**\n * 是否显示指标卡组件\n * @default true\n */\n visible?: boolean;\n /**\n * 内容尺寸\n */\n size: { width: number; height: number };\n /**\n * 指标卡 x 方向偏移\n * @default 0\n */\n dx?: number;\n /**\n * 指标卡 y 方向偏移\n * @default 0\n */\n dy?: number;\n /**\n * 指标卡宽度占内容区域的最大比值(从0到1)\n */\n limitRatio?: number;\n /**\n * 指标卡标题文字配置\n */\n title?: IndicatorItemSpec;\n /**\n * 指标卡内容文字配置\n */\n content?: IndicatorItemSpec[] | IndicatorItemSpec;\n}\n\nexport interface IndicatorItemSpec {\n /**\n * 是否显示当前项\n * @default true\n */\n visible?: boolean;\n /**\n * title.space: title 和 content 之间的间距\n * contentItem.space: content 之间的间距\n */\n space?: number;\n /**\n * 是否自适应文字空间进行缩略\n * 按照原字体大小,根据空间大小缩略文字\n * @default false\n */\n autoLimit?: boolean;\n /**\n * 是否自适应文字空间缩放文字大小\n * 不缩略文字,改变字体大小以适应空间\n * @default false\n */\n autoFit?: boolean;\n /**\n * 自适应文字宽度与可用空间的比例\n * @default 0.5\n */\n fitPercent?: number;\n /**\n * 文字样式\n */\n style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;\n}\n"]}
1
+ {"version":3,"sources":["../src/indicator/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { IGroupGraphicAttribute, ITextGraphicAttribute, IRichTextCharacter } from '@visactor/vrender-core';\nimport type { TextContent } from '../core/type';\n\nexport interface IndicatorAttributes extends IGroupGraphicAttribute {\n /**\n * 是否显示指标卡组件\n * @default true\n */\n visible?: boolean;\n /**\n * 内容尺寸\n */\n size: { width: number; height: number };\n /**\n * 指标卡 x 方向偏移\n * @default 0\n */\n dx?: number;\n /**\n * 指标卡 y 方向偏移\n * @default 0\n */\n dy?: number;\n /**\n * 指标卡宽度占内容区域的最大比值(从0到1)\n */\n limitRatio?: number;\n /**\n * 指标卡标题文字配置\n */\n title?: IndicatorItemSpec;\n /**\n * 指标卡内容文字配置\n */\n content?: IndicatorItemSpec[] | IndicatorItemSpec;\n}\n\nexport interface IndicatorItemSpec {\n /**\n * 是否显示当前项\n * @default true\n */\n visible?: boolean;\n /**\n * title.space: title 和 content 之间的间距\n * contentItem.space: content 之间的间距\n */\n space?: number;\n /**\n * 是否自适应文字空间进行缩略\n * 按照原字体大小,根据空间大小缩略文字\n * @default false\n */\n autoLimit?: boolean;\n /**\n * 是否自适应文字空间缩放文字大小\n * 不缩略文字,改变字体大小以适应空间\n * @default false\n */\n autoFit?: boolean;\n /**\n * 自适应文字宽度与可用空间的比例\n * @default 0.5\n */\n fitPercent?: number;\n /**\n * 自适应文字策略\n * @default 'local'\n */\n fitStrategy?: 'default' | 'inscribed';\n /**\n * 文字样式\n */\n style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;\n}\n"]}
package/es/label/arc.d.ts CHANGED
@@ -45,7 +45,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
45
45
  x: number;
46
46
  y: number;
47
47
  } | undefined;
48
- protected _layout(data?: LabelItem[]): (IRichText | IText)[];
48
+ protected _layout(texts: (IText | IRichText)[]): (IRichText | IText)[];
49
49
  protected layoutArcLabels(position: BaseLabelAttrs['position'], attribute: any, currentMarks?: IGraphic[], data?: LabelItem[], textBoundsArray?: any, ellipsisWidth?: number): ArcInfo[];
50
50
  private _layoutInsideLabels;
51
51
  private _layoutOutsideLabels;
@@ -64,7 +64,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
64
64
  private _restoreY;
65
65
  private _checkYRange;
66
66
  private _coverLabels;
67
- protected _labelLine(text: LabelItem): ILine;
67
+ protected _createLabelLine(text: IText, baseMark?: IGraphic): ILine;
68
68
  protected computeRadius(r: number, width?: number, height?: number, k?: number): number;
69
69
  protected computeLayoutRadius(width: number, height: number): number;
70
70
  protected _canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds): boolean;
package/es/label/arc.js CHANGED
@@ -42,24 +42,27 @@ export class ArcLabel extends LabelBase {
42
42
  y: 0
43
43
  };
44
44
  }
45
- _layout(data = []) {
46
- const labels = super._layout(data), textBoundsArray = labels.map((label => this.getGraphicBounds(label))), ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), {
47
- text: "..."
48
- }), ellipsisText = this._createLabelText(ellipsisLabelAttribute), ellipsisTextBounds = this.getGraphicBounds(ellipsisText), ellipsisWidth = ellipsisTextBounds.x2 - ellipsisTextBounds.x1, arcs = this.layoutArcLabels(this.attribute.position, this.attribute, Array.from(this._idToGraphic.values()), data, textBoundsArray, ellipsisWidth);
45
+ _layout(texts) {
46
+ const labels = super._layout(texts), textBoundsArray = labels.map((label => this.getGraphicBounds(label))), ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), {
47
+ text: ""
48
+ }), ellipsisText = this._createLabelText(ellipsisLabelAttribute), ellipsisTextBounds = this.getGraphicBounds(ellipsisText), ellipsisWidth = ellipsisTextBounds.x2 - ellipsisTextBounds.x1, data = labels.map((label => label.attribute)), arcs = this.layoutArcLabels(this.attribute.position, this.attribute, Array.from(this._idToGraphic.values()), data, textBoundsArray, ellipsisWidth);
49
49
  for (let i = 0; i < data.length; i++) {
50
50
  const textData = data[i], basedArc = arcs.find((arc => {
51
51
  var _a;
52
52
  return (null === (_a = arc.refDatum) || void 0 === _a ? void 0 : _a.id) === textData.id;
53
- })), labelAttribute = {
54
- visible: basedArc.labelVisible,
55
- x: basedArc.labelPosition.x,
56
- y: basedArc.labelPosition.y,
57
- angle: basedArc.angle,
58
- maxLineWidth: basedArc.labelLimit,
59
- points: (null == basedArc ? void 0 : basedArc.pointA) && (null == basedArc ? void 0 : basedArc.pointB) && (null == basedArc ? void 0 : basedArc.pointC) ? [ basedArc.pointA, basedArc.pointB, basedArc.pointC ] : void 0,
60
- line: null == basedArc ? void 0 : basedArc.labelLine
61
- };
62
- labels[i].setAttributes(labelAttribute);
53
+ }));
54
+ if (basedArc) {
55
+ const labelAttribute = {
56
+ visible: basedArc.labelVisible,
57
+ x: basedArc.labelPosition.x,
58
+ y: basedArc.labelPosition.y,
59
+ angle: basedArc.angle,
60
+ maxLineWidth: basedArc.labelLimit,
61
+ points: basedArc.pointA && basedArc.pointB && basedArc.pointC ? [ basedArc.pointA, basedArc.pointB, basedArc.pointC ] : void 0,
62
+ line: basedArc.labelLine
63
+ };
64
+ labels[i].setAttributes(labelAttribute);
65
+ }
63
66
  }
64
67
  return labels;
65
68
  }
@@ -103,7 +106,7 @@ export class ArcLabel extends LabelBase {
103
106
  }
104
107
  _layoutInsideLabels(arcs, attribute, currentMarks) {
105
108
  var _a, _b;
106
- const labelConfig = attribute, spaceWidth = labelConfig.spaceWidth, position = null !== (_a = null == labelConfig ? void 0 : labelConfig.position) && void 0 !== _a ? _a : "inside", offsetRadius = null !== (_b = null == labelConfig ? void 0 : labelConfig.offsetRadius) && void 0 !== _b ? _b : -spaceWidth;
109
+ const labelConfig = attribute, spaceWidth = labelConfig.spaceWidth, position = null !== (_a = labelConfig.position) && void 0 !== _a ? _a : "inside", offsetRadius = null !== (_b = labelConfig.offsetRadius) && void 0 !== _b ? _b : -spaceWidth;
107
110
  return arcs.forEach((arc => {
108
111
  var _a, _b, _c;
109
112
  const {labelSize: labelSize, radian: radian} = arc, innerRadius = arc.innerRadius, outerRadius = arc.outerRadius;
@@ -113,7 +116,7 @@ export class ArcLabel extends LabelBase {
113
116
  minRadius = radian >= Math.PI ? innerRadius : Math.max(innerRadius, labelSize.height / 2 / Math.tan(radian / 2)),
114
117
  limit = outerRadius - minRadius - spaceWidth;
115
118
  }
116
- !0 !== (null == labelConfig ? void 0 : labelConfig.rotate) && (limit = outerRadius - spaceWidth);
119
+ !0 !== labelConfig.rotate && (limit = outerRadius - spaceWidth);
117
120
  const text = this._getFormatLabelText(arc.refDatum, limit);
118
121
  arc.labelText = text;
119
122
  const labelWidth = Math.min(limit, arc.labelSize.width), align = this._computeAlign(arc, attribute);
@@ -122,15 +125,15 @@ export class ArcLabel extends LabelBase {
122
125
  labelRadius = "inside-inner" === position ? innerRadius - offsetRadius + alignOffset : outerRadius + offsetRadius - alignOffset,
123
126
  arc.labelPosition = circlePoint(arc.circleCenter.x, arc.circleCenter.y, labelRadius, arc.middleAngle),
124
127
  arc.labelLimit = labelWidth, isGreater(labelWidth, 0) || (arc.labelVisible = !1),
125
- arc.angle = null !== (_b = null === (_a = null == attribute ? void 0 : attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : arc.middleAngle;
126
- let offsetAngle = null !== (_c = null == labelConfig ? void 0 : labelConfig.offsetAngle) && void 0 !== _c ? _c : 0;
128
+ arc.angle = null !== (_b = null === (_a = attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : arc.middleAngle;
129
+ let offsetAngle = null !== (_c = labelConfig.offsetAngle) && void 0 !== _c ? _c : 0;
127
130
  [ "inside-inner", "inside-outer" ].includes(position) && (offsetAngle += Math.PI / 2),
128
131
  arc.angle += offsetAngle;
129
132
  })), arcs;
130
133
  }
131
134
  _layoutOutsideLabels(arcs, attribute, currentMarks) {
132
- var _a, _b, _c, _d, _e;
133
- const center_x = null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0, height = 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0), line2MinLength = attribute.line.line2MinLength, labelLayout = attribute.layout, spaceWidth = attribute.spaceWidth;
135
+ var _a, _b, _c;
136
+ const center_x = null !== (_a = currentMarks[0].attribute.x) && void 0 !== _a ? _a : 0, height = 2 * (null !== (_b = currentMarks[0].attribute.y) && void 0 !== _b ? _b : 0), line2MinLength = attribute.line.line2MinLength, labelLayout = attribute.layout, spaceWidth = attribute.spaceWidth;
134
137
  if (arcs.forEach((arc => {
135
138
  const direction = isQuadrantLeft(arc.quadrant) ? -1 : 1;
136
139
  arc.labelPosition = {
@@ -150,7 +153,7 @@ export class ArcLabel extends LabelBase {
150
153
  }
151
154
  !1 === attribute.coverEnable && "none" === labelLayout.strategy && this._coverLabels(arcs);
152
155
  } else {
153
- const maxLabels = height / ((null === (_e = attribute.textStyle) || void 0 === _e ? void 0 : _e.fontSize) || 16);
156
+ const maxLabels = height / ((null === (_c = attribute.textStyle) || void 0 === _c ? void 0 : _c.fontSize) || 16);
154
157
  this._adjustY(arcs, maxLabels, attribute, currentMarks);
155
158
  const {minY: minY, maxY: maxY} = arcs.reduce(((yInfo, arc) => {
156
159
  const {y1: y1, y2: y2} = arc.getLabelBounds();
@@ -166,9 +169,8 @@ export class ArcLabel extends LabelBase {
166
169
  return arcs.forEach((arc => {
167
170
  var _a, _b;
168
171
  arc.labelVisible && (isLess(arc.pointB.x, line2MinLength + spaceWidth) || isGreater(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
169
- arc.angle = null !== (_b = null === (_a = null == attribute ? void 0 : attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : 0,
170
- (null == attribute ? void 0 : attribute.offsetAngle) && (arc.angle += attribute.offsetAngle),
171
- arc.labelLine = Object.assign({}, null == attribute ? void 0 : attribute.line);
172
+ arc.angle = null !== (_b = null === (_a = attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : 0,
173
+ attribute.offsetAngle && (arc.angle += attribute.offsetAngle), arc.labelLine = Object.assign({}, attribute.line);
172
174
  })), arcs;
173
175
  }
174
176
  _computeX(arc, attribute, currentMarks) {
@@ -227,9 +229,9 @@ export class ArcLabel extends LabelBase {
227
229
  return null !== (_a = null == value ? void 0 : value.text) && void 0 !== _a ? _a : "";
228
230
  }
229
231
  _adjustY(arcs, maxLabels, attribute, currentMarks) {
230
- var _a, _b, _c, _d;
231
- _b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x;
232
- const plotRect_height = 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0), labelLayout = attribute.layout;
232
+ var _a, _b;
233
+ _a = currentMarks[0].attribute.x;
234
+ const plotRect_height = 2 * (null !== (_b = currentMarks[0].attribute.y) && void 0 !== _b ? _b : 0), labelLayout = attribute.layout;
233
235
  if ("vertical" === labelLayout.strategy) {
234
236
  let delta, lastY = 0;
235
237
  const len = arcs.length;
@@ -407,15 +409,16 @@ export class ArcLabel extends LabelBase {
407
409
  checkBoundsOverlap(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
408
410
  }
409
411
  }
410
- _labelLine(text) {
411
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
412
- return (null === (_a = text.attribute) || void 0 === _a ? void 0 : _a.points) ? graphicCreator.line({
413
- visible: null === (_g = null !== (_e = (null === (_c = null === (_b = text.attribute) || void 0 === _b ? void 0 : _b.line) || void 0 === _c ? void 0 : _c.visible) && (null === (_d = text.attribute) || void 0 === _d ? void 0 : _d.visible)) && void 0 !== _e ? _e : null === (_f = text.attribute) || void 0 === _f ? void 0 : _f.visible) || void 0 === _g || _g,
414
- stroke: null !== (_l = null === (_k = null === (_j = null === (_h = text.attribute) || void 0 === _h ? void 0 : _h.line) || void 0 === _j ? void 0 : _j.style) || void 0 === _k ? void 0 : _k.stroke) && void 0 !== _l ? _l : null === (_m = text.attribute) || void 0 === _m ? void 0 : _m.fill,
415
- lineWidth: null !== (_r = null === (_q = null === (_p = null === (_o = text.attribute) || void 0 === _o ? void 0 : _o.line) || void 0 === _p ? void 0 : _p.style) || void 0 === _q ? void 0 : _q.lineWidth) && void 0 !== _r ? _r : 1,
416
- points: null === (_s = text.attribute) || void 0 === _s ? void 0 : _s.points,
417
- curveType: (null === (_u = null === (_t = text.attribute) || void 0 === _t ? void 0 : _t.line) || void 0 === _u ? void 0 : _u.smooth) ? "basis" : null
412
+ _createLabelLine(text, baseMark) {
413
+ var _a, _b, _c, _d, _e, _f, _g;
414
+ const {points: points, line: line = {}, visible: visible, fill: fill} = text.attribute, labelLine = text.attribute.points ? graphicCreator.line({
415
+ visible: null === (_c = null !== (_a = line.visible && visible) && void 0 !== _a ? _a : null === (_b = text.attribute) || void 0 === _b ? void 0 : _b.visible) || void 0 === _c || _c,
416
+ stroke: null !== (_e = null === (_d = line.style) || void 0 === _d ? void 0 : _d.stroke) && void 0 !== _e ? _e : fill,
417
+ lineWidth: null !== (_g = null === (_f = line.style) || void 0 === _f ? void 0 : _f.lineWidth) && void 0 !== _g ? _g : 1,
418
+ points: points,
419
+ curveType: line.smooth ? "basis" : null
418
420
  }) : void 0;
421
+ return labelLine && this._setStatesOfLabelLine(labelLine), labelLine;
419
422
  }
420
423
  computeRadius(r, width, height, k) {
421
424
  return this.computeLayoutRadius(width || 0, height || 0) * r * (isNil(k) ? 1 : k);