@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
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.Indicator = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), base_1 = require("../core/base"), util_1 = require("../util"), config_1 = require("./config"), constant_1 = require("../constant"), register_1 = require("./register");
7
+ const vutils_1 = require("@visactor/vutils"), base_1 = require("../core/base"), util_1 = require("../util"), config_1 = require("./config"), register_1 = require("./register");
8
8
 
9
9
  (0, register_1.loadIndicatorComponent)();
10
10
 
@@ -13,7 +13,7 @@ class Indicator extends base_1.AbstractComponent {
13
13
  super(...arguments), this.name = "indicator";
14
14
  }
15
15
  render() {
16
- var _a, _b, _c;
16
+ var _a;
17
17
  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", {
18
18
  x: 0,
19
19
  y: 0,
@@ -22,20 +22,8 @@ class Indicator extends base_1.AbstractComponent {
22
22
  if (!0 !== visible) return void (group && group.hideAll());
23
23
  if ((0, vutils_1.isValid)(title)) if (!1 !== title.visible) {
24
24
  const titleStyle = (0, vutils_1.merge)({}, (0, vutils_1.get)(config_1.DEFAULT_INDICATOR_THEME, "title.style"), title.style);
25
- "rich" === titleStyle.type ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({
26
- textConfig: titleStyle.text
27
- }, titleStyle), {
28
- visible: title.visible,
29
- x: 0,
30
- y: 0,
31
- width: null !== (_a = titleStyle.width) && void 0 !== _a ? _a : 0,
32
- height: null !== (_b = titleStyle.height) && void 0 !== _b ? _b : 0
33
- }), "richtext") : "html" === titleStyle.type ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({
34
- textConfig: [],
35
- html: Object.assign(Object.assign({
36
- dom: titleStyle.text
37
- }, constant_1.DEFAULT_HTML_TEXT_SPEC), titleStyle)
38
- }, titleStyle), {
25
+ (0, util_1.isRichText)(titleStyle) ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, (0,
26
+ util_1.richTextAttributeTransform)(titleStyle)), {
39
27
  visible: title.visible,
40
28
  x: 0,
41
29
  y: 0
@@ -44,67 +32,93 @@ class Indicator extends base_1.AbstractComponent {
44
32
  visible: title.visible,
45
33
  x: 0,
46
34
  y: 0
47
- }), "text"), title.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setAutoFit(limit, this._title, title),
35
+ }), "text"), title.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setLocalAutoFit(limit, this._title, title),
48
36
  title.autoLimit && (0, vutils_1.isValidNumber)(limitRatio) && this._title.setAttribute("maxLineWidth", limit);
49
37
  } else {
50
38
  const titleNode = group.find((node => "indicator-title" === node.name), !1);
51
39
  titleNode && group.removeChild(titleNode), this._title = void 0;
52
40
  }
53
- const titleHeight = this._title ? this._title.AABBBounds.height() : 0;
54
41
  if ((0, vutils_1.isValid)(content)) {
55
- const titleSpace = this._title && title.space ? title.space : 0, contents = (0,
56
- vutils_1.array)(content), contentComponents = [];
57
- let lastContentHeight = 0;
42
+ const contents = (0, vutils_1.array)(content), contentComponents = [];
58
43
  contents.forEach(((contentItem, i) => {
59
- var _a, _b;
60
44
  if (!1 !== contentItem.visible) {
61
45
  const contentStyle = (0, vutils_1.merge)({}, (0, vutils_1.get)(config_1.DEFAULT_INDICATOR_THEME, "content.style"), contentItem.style);
62
46
  let contentComponent;
63
- contentComponent = "rich" === contentStyle.type ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({
64
- textConfig: contentStyle.text
65
- }, contentStyle), {
66
- visible: title.visible,
67
- x: 0,
68
- y: titleHeight + titleSpace + lastContentHeight,
69
- width: null !== (_a = contentStyle.width) && void 0 !== _a ? _a : 0,
70
- height: null !== (_b = contentStyle.height) && void 0 !== _b ? _b : 0
71
- }), "richtext") : "html" === contentStyle.type ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({
72
- textConfig: [],
73
- html: Object.assign(Object.assign({
74
- dom: contentStyle.text
75
- }, constant_1.DEFAULT_HTML_TEXT_SPEC), contentStyle)
76
- }, contentStyle), {
47
+ contentComponent = (0, util_1.isRichText)(contentStyle) ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, (0,
48
+ util_1.richTextAttributeTransform)(contentStyle)), {
77
49
  visible: title.visible,
78
50
  x: 0,
79
- y: titleHeight + titleSpace + lastContentHeight
51
+ y: 0
80
52
  }), "richtext") : group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, contentStyle), {
81
53
  lineHeight: (0, vutils_1.isValid)(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,
82
54
  visible: contentItem.visible,
83
55
  x: 0,
84
- y: titleHeight + titleSpace + lastContentHeight
85
- }), "text"), contentItem.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setAutoFit(limit, contentComponent, contentItem),
56
+ y: 0
57
+ }), "text"), contentItem.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setLocalAutoFit(limit, contentComponent, contentItem),
86
58
  contentItem.autoLimit && (0, vutils_1.isValidNumber)(limitRatio) && contentComponent.setAttribute("maxLineWidth", limit),
87
59
  contentComponents.push(contentComponent);
88
- const contentSpace = contentItem.space ? contentItem.space : 0;
89
- lastContentHeight += contentComponent.AABBBounds.height() + contentSpace;
90
60
  } else {
91
61
  const contentItemNode = group.find((node => node.name === "indicator-content-" + i), !1);
92
62
  contentItemNode && group.removeChild(contentItemNode);
93
63
  }
94
64
  })), this._content = contentComponents;
95
65
  }
96
- 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;
97
68
  group.setAttribute("y", size.height / 2 - totalHeight / 2), group.setAttribute("x", size.width / 2);
98
69
  }
99
- _setAutoFit(limit, indicatorItem, indicatorItemSpec) {
100
- var _a, _b, _c, _d, _e, _f;
101
- const originWidth = (0, util_1.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 = (0, util_1.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;
102
74
  if (originWidth > 0) {
103
- 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);
104
76
  indicatorItem.setAttribute("fontSize", fontSize), indicatorItem.setAttribute("lineHeight", (0,
105
77
  vutils_1.isValid)(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize);
106
78
  }
107
79
  }
80
+ _setGlobalAutoFit(limit) {
81
+ var _a, _b, _c, _d, _e, _f, _g;
82
+ const r = limit / 2, autoFitTexts = [];
83
+ let otherHeight = 0;
84
+ const titleSpec = null !== (_a = this.attribute.title) && void 0 !== _a ? _a : {};
85
+ titleSpec.autoFit && "inscribed" === titleSpec.fitStrategy ? (this._title.setAttribute("fontSize", 12),
86
+ autoFitTexts.push({
87
+ text: this._title,
88
+ spec: null !== (_b = this.attribute.title) && void 0 !== _b ? _b : {}
89
+ })) : 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;
90
+ const titleSpace = null !== (_g = titleSpec.space) && void 0 !== _g ? _g : 0;
91
+ if (otherHeight += titleSpace, (0, vutils_1.array)(this.attribute.content).filter((contentSpec => !1 !== contentSpec.visible)).forEach(((contentSpec, index) => {
92
+ var _a, _b, _c, _d;
93
+ const contentText = this._content[index];
94
+ contentSpec.autoFit && "inscribed" === contentSpec.fitStrategy ? (contentText.setAttribute("fontSize", 12),
95
+ autoFitTexts.push({
96
+ text: contentText,
97
+ spec: contentSpec
98
+ })) : 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;
99
+ const contentSpace = null !== (_d = contentSpec.space) && void 0 !== _d ? _d : 0;
100
+ otherHeight += contentSpace;
101
+ })), autoFitTexts.length <= 0) return;
102
+ 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;
103
+ (0, vutils_1.isValidNumber)(y) && autoFitTexts.forEach((textItem => {
104
+ var _a;
105
+ const specLineHeight = null === (_a = textItem.spec.style) || void 0 === _a ? void 0 : _a.lineHeight;
106
+ textItem.text.setAttribute("fontSize", lineHeight), textItem.text.setAttribute("lineHeight", (0,
107
+ vutils_1.isValid)(specLineHeight) ? specLineHeight : lineHeight);
108
+ }));
109
+ }
110
+ _setYPosition() {
111
+ var _a, _b, _c, _d, _e, _f;
112
+ let lastContentHeight = 0;
113
+ 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;
114
+ (0, vutils_1.array)(this.attribute.content).filter((contentSpec => !1 !== contentSpec.visible)).forEach(((contentSpec, index) => {
115
+ var _a;
116
+ const contentText = this._content[index];
117
+ contentText.setAttribute("y", titleHeight + titleSpace + lastContentHeight);
118
+ const contentSpace = null !== (_a = contentSpec.space) && void 0 !== _a ? _a : 0;
119
+ lastContentHeight += contentText.AABBBounds.height() + contentSpace;
120
+ }));
121
+ }
108
122
  }
109
123
 
110
124
  exports.Indicator = Indicator;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":";;;AAIA,6CAA6E;AAC7E,uCAAiD;AACjD,kCAA0C;AAE1C,qCAAmD;AACnD,0CAAqD;AACrD,yCAAoD;AAEpD,IAAA,iCAAsB,GAAE,CAAC;AACzB,MAAa,SAAU,SAAQ,wBAAgD;IAA/E;;QACE,SAAI,GAAG,WAAW,CAAC;IAgMrB,CAAC;IA3LW,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;QAG5G,IAAI,OAAO,KAAK,IAAI,EAAE;YACpB,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;SACR;QAED,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,EAAE;YAClB,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE;gBAC3B,MAAM,UAAU,GAAG,IAAA,cAAK,EAAC,EAAE,EAAE,IAAA,YAAG,EAAC,gCAAuB,EAAE,aAAa,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvF,IAAI,UAAU,CAAC,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,MAAA,iBAAiB,CAAC,KAAK,mCAAI,EAAE,CAAmC,CAClE,CAAC,KAAK,CAAC;QACR,IAAI,WAAW,GAAG,CAAC,EAAE;YACnB,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,MAAA,iBAAiB,CAAC,UAAU,mCAAI,GAAG,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,IAAA,gBAAO,EAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAC5F,CAAC;SACH;IACH,CAAC;CACF;AAjMD,8BAiMC","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,6CAA6E;AAC7E,uCAAiD;AACjD,kCAAkF;AAElF,qCAAmD;AACnD,yCAAoD;AAEpD,IAAA,iCAAsB,GAAE,CAAC;AACzB,MAAa,SAAU,SAAQ,wBAAgD;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;QAG5G,IAAI,OAAO,KAAK,IAAI,E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AAE,UAAU,CAAC,CAAC;gBACnD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,IAAA,gBAAO,EAAC,cAAc,CAAC,CAAC,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,IAAA,cAAK,EAAC,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;AA7OD,8BA6OC","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"]}
@@ -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/cjs/label/arc.js CHANGED
@@ -44,24 +44,27 @@ class ArcLabel extends base_1.LabelBase {
44
44
  y: 0
45
45
  };
46
46
  }
47
- _layout(data = []) {
48
- const labels = super._layout(data), textBoundsArray = labels.map((label => this.getGraphicBounds(label))), ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), {
49
- text: "..."
50
- }), 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);
47
+ _layout(texts) {
48
+ const labels = super._layout(texts), textBoundsArray = labels.map((label => this.getGraphicBounds(label))), ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), {
49
+ text: ""
50
+ }), 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);
51
51
  for (let i = 0; i < data.length; i++) {
52
52
  const textData = data[i], basedArc = arcs.find((arc => {
53
53
  var _a;
54
54
  return (null === (_a = arc.refDatum) || void 0 === _a ? void 0 : _a.id) === textData.id;
55
- })), 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: (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,
62
- line: null == basedArc ? void 0 : basedArc.labelLine
63
- };
64
- labels[i].setAttributes(labelAttribute);
55
+ }));
56
+ if (basedArc) {
57
+ const labelAttribute = {
58
+ visible: basedArc.labelVisible,
59
+ x: basedArc.labelPosition.x,
60
+ y: basedArc.labelPosition.y,
61
+ angle: basedArc.angle,
62
+ maxLineWidth: basedArc.labelLimit,
63
+ points: basedArc.pointA && basedArc.pointB && basedArc.pointC ? [ basedArc.pointA, basedArc.pointB, basedArc.pointC ] : void 0,
64
+ line: basedArc.labelLine
65
+ };
66
+ labels[i].setAttributes(labelAttribute);
67
+ }
65
68
  }
66
69
  return labels;
67
70
  }
@@ -109,7 +112,7 @@ class ArcLabel extends base_1.LabelBase {
109
112
  }
110
113
  _layoutInsideLabels(arcs, attribute, currentMarks) {
111
114
  var _a, _b;
112
- 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;
115
+ 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;
113
116
  return arcs.forEach((arc => {
114
117
  var _a, _b, _c;
115
118
  const {labelSize: labelSize, radian: radian} = arc, innerRadius = arc.innerRadius, outerRadius = arc.outerRadius;
@@ -119,7 +122,7 @@ class ArcLabel extends base_1.LabelBase {
119
122
  minRadius = radian >= Math.PI ? innerRadius : Math.max(innerRadius, labelSize.height / 2 / Math.tan(radian / 2)),
120
123
  limit = outerRadius - minRadius - spaceWidth;
121
124
  }
122
- !0 !== (null == labelConfig ? void 0 : labelConfig.rotate) && (limit = outerRadius - spaceWidth);
125
+ !0 !== labelConfig.rotate && (limit = outerRadius - spaceWidth);
123
126
  const text = this._getFormatLabelText(arc.refDatum, limit);
124
127
  arc.labelText = text;
125
128
  const labelWidth = Math.min(limit, arc.labelSize.width), align = this._computeAlign(arc, attribute);
@@ -128,15 +131,15 @@ class ArcLabel extends base_1.LabelBase {
128
131
  labelRadius = "inside-inner" === position ? innerRadius - offsetRadius + alignOffset : outerRadius + offsetRadius - alignOffset,
129
132
  arc.labelPosition = (0, util_1.circlePoint)(arc.circleCenter.x, arc.circleCenter.y, labelRadius, arc.middleAngle),
130
133
  arc.labelLimit = labelWidth, (0, vutils_1.isGreater)(labelWidth, 0) || (arc.labelVisible = !1),
131
- 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;
132
- let offsetAngle = null !== (_c = null == labelConfig ? void 0 : labelConfig.offsetAngle) && void 0 !== _c ? _c : 0;
134
+ arc.angle = null !== (_b = null === (_a = attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : arc.middleAngle;
135
+ let offsetAngle = null !== (_c = labelConfig.offsetAngle) && void 0 !== _c ? _c : 0;
133
136
  [ "inside-inner", "inside-outer" ].includes(position) && (offsetAngle += Math.PI / 2),
134
137
  arc.angle += offsetAngle;
135
138
  })), arcs;
136
139
  }
137
140
  _layoutOutsideLabels(arcs, attribute, currentMarks) {
138
- var _a, _b, _c, _d, _e;
139
- 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;
141
+ var _a, _b, _c;
142
+ 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;
140
143
  if (arcs.forEach((arc => {
141
144
  const direction = (0, util_1.isQuadrantLeft)(arc.quadrant) ? -1 : 1;
142
145
  arc.labelPosition = {
@@ -156,7 +159,7 @@ class ArcLabel extends base_1.LabelBase {
156
159
  }
157
160
  !1 === attribute.coverEnable && "none" === labelLayout.strategy && this._coverLabels(arcs);
158
161
  } else {
159
- const maxLabels = height / ((null === (_e = attribute.textStyle) || void 0 === _e ? void 0 : _e.fontSize) || 16);
162
+ const maxLabels = height / ((null === (_c = attribute.textStyle) || void 0 === _c ? void 0 : _c.fontSize) || 16);
160
163
  this._adjustY(arcs, maxLabels, attribute, currentMarks);
161
164
  const {minY: minY, maxY: maxY} = arcs.reduce(((yInfo, arc) => {
162
165
  const {y1: y1, y2: y2} = arc.getLabelBounds();
@@ -173,9 +176,8 @@ class ArcLabel extends base_1.LabelBase {
173
176
  var _a, _b;
174
177
  arc.labelVisible && ((0, vutils_1.isLess)(arc.pointB.x, line2MinLength + spaceWidth) || (0,
175
178
  vutils_1.isGreater)(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
176
- arc.angle = null !== (_b = null === (_a = null == attribute ? void 0 : attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : 0,
177
- (null == attribute ? void 0 : attribute.offsetAngle) && (arc.angle += attribute.offsetAngle),
178
- arc.labelLine = Object.assign({}, null == attribute ? void 0 : attribute.line);
179
+ arc.angle = null !== (_b = null === (_a = attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : 0,
180
+ attribute.offsetAngle && (arc.angle += attribute.offsetAngle), arc.labelLine = Object.assign({}, attribute.line);
179
181
  })), arcs;
180
182
  }
181
183
  _computeX(arc, attribute, currentMarks) {
@@ -237,9 +239,9 @@ class ArcLabel extends base_1.LabelBase {
237
239
  return null !== (_a = null == value ? void 0 : value.text) && void 0 !== _a ? _a : "";
238
240
  }
239
241
  _adjustY(arcs, maxLabels, attribute, currentMarks) {
240
- var _a, _b, _c, _d;
241
- _b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x;
242
- 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;
242
+ var _a, _b;
243
+ _a = currentMarks[0].attribute.x;
244
+ const plotRect_height = 2 * (null !== (_b = currentMarks[0].attribute.y) && void 0 !== _b ? _b : 0), labelLayout = attribute.layout;
243
245
  if ("vertical" === labelLayout.strategy) {
244
246
  let delta, lastY = 0;
245
247
  const len = arcs.length;
@@ -420,15 +422,16 @@ class ArcLabel extends base_1.LabelBase {
420
422
  (0, util_1.checkBoundsOverlap)(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
421
423
  }
422
424
  }
423
- _labelLine(text) {
424
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
425
- return (null === (_a = text.attribute) || void 0 === _a ? void 0 : _a.points) ? vrender_core_1.graphicCreator.line({
426
- 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,
427
- 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,
428
- 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,
429
- points: null === (_s = text.attribute) || void 0 === _s ? void 0 : _s.points,
430
- curveType: (null === (_u = null === (_t = text.attribute) || void 0 === _t ? void 0 : _t.line) || void 0 === _u ? void 0 : _u.smooth) ? "basis" : null
425
+ _createLabelLine(text, baseMark) {
426
+ var _a, _b, _c, _d, _e, _f, _g;
427
+ const {points: points, line: line = {}, visible: visible, fill: fill} = text.attribute, labelLine = text.attribute.points ? vrender_core_1.graphicCreator.line({
428
+ 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,
429
+ stroke: null !== (_e = null === (_d = line.style) || void 0 === _d ? void 0 : _d.stroke) && void 0 !== _e ? _e : fill,
430
+ lineWidth: null !== (_g = null === (_f = line.style) || void 0 === _f ? void 0 : _f.lineWidth) && void 0 !== _g ? _g : 1,
431
+ points: points,
432
+ curveType: line.smooth ? "basis" : null
431
433
  }) : void 0;
434
+ return labelLine && this._setStatesOfLabelLine(labelLine), labelLine;
432
435
  }
433
436
  computeRadius(r, width, height, k) {
434
437
  return this.computeLayoutRadius(width || 0, height || 0) * r * ((0, vutils_1.isNil)(k) ? 1 : k);