@visactor/vrender-components 0.14.6-alpha.8 → 0.15.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/cjs/axis/animate/group-transition.d.ts +2 -1
  2. package/cjs/axis/animate/group-transition.js +3 -3
  3. package/cjs/axis/animate/group-transition.js.map +1 -1
  4. package/cjs/axis/base.d.ts +5 -8
  5. package/cjs/axis/base.js +16 -32
  6. package/cjs/axis/base.js.map +1 -1
  7. package/cjs/axis/circle.d.ts +3 -23
  8. package/cjs/axis/circle.js +3 -84
  9. package/cjs/axis/circle.js.map +1 -1
  10. package/cjs/axis/config.d.ts +0 -17
  11. package/cjs/axis/config.js +0 -17
  12. package/cjs/axis/config.js.map +1 -1
  13. package/cjs/axis/grid/base.d.ts +24 -0
  14. package/cjs/axis/{grid.js → grid/base.js} +67 -20
  15. package/cjs/axis/grid/base.js.map +1 -0
  16. package/cjs/axis/grid/circle.d.ts +9 -0
  17. package/cjs/axis/grid/circle.js +92 -0
  18. package/cjs/axis/grid/circle.js.map +1 -0
  19. package/cjs/axis/grid/index.d.ts +3 -0
  20. package/cjs/axis/grid/index.js +22 -0
  21. package/cjs/axis/grid/index.js.map +1 -0
  22. package/cjs/axis/grid/line.d.ts +10 -0
  23. package/cjs/axis/grid/line.js +103 -0
  24. package/cjs/axis/grid/line.js.map +1 -0
  25. package/cjs/axis/grid/type.d.ts +63 -0
  26. package/cjs/axis/grid/type.js +6 -0
  27. package/cjs/axis/grid/type.js.map +1 -0
  28. package/cjs/axis/index.d.ts +0 -1
  29. package/cjs/axis/index.js +3 -3
  30. package/cjs/axis/index.js.map +1 -1
  31. package/cjs/axis/line.d.ts +3 -24
  32. package/cjs/axis/line.js +17 -167
  33. package/cjs/axis/line.js.map +1 -1
  34. package/cjs/axis/mixin/circle.d.ts +17 -0
  35. package/cjs/axis/mixin/circle.js +30 -0
  36. package/cjs/axis/mixin/circle.js.map +1 -0
  37. package/cjs/axis/mixin/line.d.ts +14 -0
  38. package/cjs/axis/mixin/line.js +32 -0
  39. package/cjs/axis/mixin/line.js.map +1 -0
  40. package/cjs/axis/overlap/auto-rotate.js +2 -2
  41. package/cjs/axis/overlap/auto-rotate.js.map +1 -1
  42. package/cjs/axis/type.d.ts +0 -56
  43. package/cjs/axis/type.js.map +1 -1
  44. package/cjs/brush/brush.d.ts +0 -1
  45. package/cjs/brush/brush.js +0 -5
  46. package/cjs/brush/brush.js.map +1 -1
  47. package/cjs/core/type.js +2 -1
  48. package/cjs/crosshair/base.js +1 -2
  49. package/cjs/index.d.ts +3 -1
  50. package/cjs/index.js +9 -8
  51. package/cjs/index.js.map +1 -1
  52. package/cjs/indicator/type.js +2 -1
  53. package/cjs/jsx/component-type.d.ts +4 -0
  54. package/cjs/jsx/component-type.js +13 -0
  55. package/cjs/jsx/component-type.js.map +1 -0
  56. package/cjs/jsx/index.d.ts +1 -0
  57. package/cjs/jsx/index.js +21 -0
  58. package/cjs/jsx/index.js.map +1 -0
  59. package/cjs/label/arc.d.ts +3 -6
  60. package/cjs/label/arc.js +1 -31
  61. package/cjs/label/arc.js.map +1 -1
  62. package/cjs/label/base.d.ts +9 -12
  63. package/cjs/label/base.js +134 -117
  64. package/cjs/label/base.js.map +1 -1
  65. package/cjs/label/dataLabel.js +4 -4
  66. package/cjs/label/dataLabel.js.map +1 -1
  67. package/cjs/label/overlap/place.d.ts +2 -2
  68. package/cjs/label/overlap/place.js +8 -15
  69. package/cjs/label/overlap/place.js.map +1 -1
  70. package/cjs/label/rect.js.map +1 -1
  71. package/cjs/label/symbol.js.map +1 -1
  72. package/cjs/label/type.d.ts +2 -5
  73. package/cjs/label/type.js.map +1 -1
  74. package/cjs/util/labelSmartInvert.d.ts +0 -1
  75. package/cjs/util/labelSmartInvert.js +2 -20
  76. package/cjs/util/labelSmartInvert.js.map +1 -1
  77. package/cjs/util/matrix.d.ts +1 -1
  78. package/cjs/util/matrix.js.map +1 -1
  79. package/dist/index.js +734 -814
  80. package/dist/index.min.js +1 -1
  81. package/es/axis/animate/group-transition.d.ts +2 -1
  82. package/es/axis/animate/group-transition.js +3 -3
  83. package/es/axis/animate/group-transition.js.map +1 -1
  84. package/es/axis/base.d.ts +5 -8
  85. package/es/axis/base.js +15 -33
  86. package/es/axis/base.js.map +1 -1
  87. package/es/axis/circle.d.ts +3 -23
  88. package/es/axis/circle.js +4 -85
  89. package/es/axis/circle.js.map +1 -1
  90. package/es/axis/config.d.ts +0 -17
  91. package/es/axis/config.js +0 -17
  92. package/es/axis/config.js.map +1 -1
  93. package/es/axis/grid/base.d.ts +24 -0
  94. package/es/axis/{grid.js → grid/base.js} +69 -21
  95. package/es/axis/grid/base.js.map +1 -0
  96. package/es/axis/grid/circle.d.ts +9 -0
  97. package/es/axis/grid/circle.js +92 -0
  98. package/es/axis/grid/circle.js.map +1 -0
  99. package/es/axis/grid/index.d.ts +3 -0
  100. package/es/axis/grid/index.js +6 -0
  101. package/es/axis/grid/index.js.map +1 -0
  102. package/es/axis/grid/line.d.ts +10 -0
  103. package/es/axis/grid/line.js +102 -0
  104. package/es/axis/grid/line.js.map +1 -0
  105. package/es/axis/grid/type.d.ts +63 -0
  106. package/es/axis/grid/type.js +2 -0
  107. package/es/axis/grid/type.js.map +1 -0
  108. package/es/axis/index.d.ts +0 -1
  109. package/es/axis/index.js +0 -2
  110. package/es/axis/index.js.map +1 -1
  111. package/es/axis/line.d.ts +3 -24
  112. package/es/axis/line.js +9 -158
  113. package/es/axis/line.js.map +1 -1
  114. package/es/axis/mixin/circle.d.ts +17 -0
  115. package/es/axis/mixin/circle.js +25 -0
  116. package/es/axis/mixin/circle.js.map +1 -0
  117. package/es/axis/mixin/line.d.ts +14 -0
  118. package/es/axis/mixin/line.js +23 -0
  119. package/es/axis/mixin/line.js.map +1 -0
  120. package/es/axis/overlap/auto-rotate.js +2 -2
  121. package/es/axis/overlap/auto-rotate.js.map +1 -1
  122. package/es/axis/type.d.ts +0 -56
  123. package/es/axis/type.js.map +1 -1
  124. package/es/brush/brush.d.ts +0 -1
  125. package/es/brush/brush.js +0 -5
  126. package/es/brush/brush.js.map +1 -1
  127. package/es/core/type.js +2 -1
  128. package/es/crosshair/base.js +1 -2
  129. package/es/index.d.ts +3 -1
  130. package/es/index.js +5 -1
  131. package/es/index.js.map +1 -1
  132. package/es/indicator/type.js +2 -1
  133. package/es/jsx/component-type.d.ts +4 -0
  134. package/es/jsx/component-type.js +5 -0
  135. package/es/jsx/component-type.js.map +1 -0
  136. package/es/jsx/index.d.ts +1 -0
  137. package/es/jsx/index.js +2 -0
  138. package/es/jsx/index.js.map +1 -0
  139. package/es/label/arc.d.ts +3 -6
  140. package/es/label/arc.js +0 -31
  141. package/es/label/arc.js.map +1 -1
  142. package/es/label/base.d.ts +9 -12
  143. package/es/label/base.js +132 -118
  144. package/es/label/base.js.map +1 -1
  145. package/es/label/dataLabel.js +3 -5
  146. package/es/label/dataLabel.js.map +1 -1
  147. package/es/label/overlap/place.d.ts +2 -2
  148. package/es/label/overlap/place.js +8 -15
  149. package/es/label/overlap/place.js.map +1 -1
  150. package/es/label/rect.js.map +1 -1
  151. package/es/label/symbol.js.map +1 -1
  152. package/es/label/type.d.ts +2 -5
  153. package/es/label/type.js.map +1 -1
  154. package/es/util/labelSmartInvert.d.ts +0 -1
  155. package/es/util/labelSmartInvert.js +0 -17
  156. package/es/util/labelSmartInvert.js.map +1 -1
  157. package/es/util/matrix.d.ts +1 -1
  158. package/es/util/matrix.js.map +1 -1
  159. package/package.json +4 -4
  160. package/cjs/axis/grid.d.ts +0 -9
  161. package/cjs/axis/grid.js.map +0 -1
  162. package/cjs/label/polygon.d.ts +0 -12
  163. package/cjs/label/polygon.js +0 -35
  164. package/cjs/label/polygon.js.map +0 -1
  165. package/es/axis/grid.d.ts +0 -9
  166. package/es/axis/grid.js.map +0 -1
  167. package/es/label/polygon.d.ts +0 -12
  168. package/es/label/polygon.js +0 -31
  169. package/es/label/polygon.js.map +0 -1
@@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EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;QACd,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACrC,SAAS,CAAC,gBAAgB,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe;QACb,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACrC,SAAS,CAAC,eAAe,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;;AA7EH,8BA8EC;AAzEgB,2BAAiB,GAA4B;IAC1D,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"dataLabel.js","sourcesContent":["import { isValidNumber, merge } from '@visactor/vutils';\nimport type { IGraphic, INode } from '@visactor/vrender';\nimport { AbstractComponent } from '../core/base';\nimport type { PointLocationCfg } from '../core/type';\nimport { bitmapTool } from './overlap';\nimport { RectLabel } from './rect';\nimport { SymbolLabel } from './symbol';\nimport { ArcLabel } from './arc';\nimport type { DataLabelAttrs } from './type';\nimport type { LabelBase } from './base';\nimport { LabelBase as PointLabel } from './base';\n\nconst labelComponentMap = {\n rect: RectLabel,\n symbol: SymbolLabel,\n arc: ArcLabel\n};\n\nexport class DataLabel extends AbstractComponent<DataLabelAttrs> {\n name = 'data-label';\n\n private _componentMap: Map<string, LabelBase<any>>;\n\n private static defaultAttributes: Partial<DataLabelAttrs> = {\n pickable: false\n };\n\n constructor(attributes: DataLabelAttrs) {\n super(merge({}, DataLabel.defaultAttributes, attributes));\n }\n\n protected render(): void {\n const { dataLabels, size } = this.attribute;\n if (!dataLabels || dataLabels.length === 0) {\n return;\n }\n const { width = 0, height = 0 } = size || {};\n\n if (!width || !height || !isValidNumber(height * width)) {\n return;\n }\n\n if (!this._componentMap) {\n this._componentMap = new Map();\n }\n const tool = bitmapTool(width, height);\n const bitmap = tool.bitmap();\n\n const currentComponentMap = new Map();\n const prevComponentMap = this._componentMap;\n\n for (let i = 0; i < dataLabels.length; i++) {\n const dataLabel = dataLabels[i];\n const labelComponent = labelComponentMap[dataLabel.type] || PointLabel;\n if (labelComponent) {\n const { baseMarkGroupName } = dataLabel;\n let component = this._componentMap.get(baseMarkGroupName);\n if (component) {\n component.setBitmapTool(tool);\n component.setBitmap(bitmap);\n component.setAttributes(dataLabel);\n currentComponentMap.set(baseMarkGroupName, component);\n } else {\n component = new labelComponent(dataLabel as any);\n component.setBitmap(bitmap);\n component.setBitmapTool(tool);\n this.add(component as unknown as INode);\n currentComponentMap.set(baseMarkGroupName, component);\n }\n }\n }\n\n prevComponentMap.forEach((cp, key) => {\n if (!currentComponentMap.get(key)) {\n this.removeChild(cp as unknown as IGraphic);\n }\n });\n\n this._componentMap = currentComponentMap;\n }\n\n setLocation(point: PointLocationCfg) {\n this.translateTo(point.x, point.y);\n }\n\n disableAnimation() {\n this._componentMap.forEach(component => {\n component.disableAnimation();\n });\n }\n\n enableAnimation() {\n this._componentMap.forEach(component => {\n component.enableAnimation();\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["label/dataLabel.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAExD,uCAAiD;AAEjD,uCAAuC;AACvC,iCAAmC;AACnC,qCAAuC;AACvC,+BAAiC;AAIjC,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,gBAAS;IACf,MAAM,EAAE,oBAAW;IACnB,GAAG,EAAE,cAAQ;CACd,CAAC;AAEF,MAAa,SAAU,SAAQ,wBAAiC;IAS9D,YAAY,UAA0B;QACpC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAT5D,SAAI,GAAG,YAAY,CAAC;IAUpB,CAAC;IAES,MAAM;QACd,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;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SAAgB,CAAC,CAAC;oBACpE,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;oBAC5B,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;oBAC9B,IAAI,CAAC,GAAG,CAAC,SAA6B,CAAC,CAAC;oBACxC,mBAAmB,CAAC,GAAG,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;iBACvD;aACF;SACF;QAED,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE;YACnC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACjC,IAAI,CAAC,WAAW,CAAC,EAAyB,CAAC,CAAC;aAC7C;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;IAC3C,CAAC;IAED,WAAW,CAAC,KAAuB;QACjC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;QACd,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACrC,SAAS,CAAC,gBAAgB,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe;QACb,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACrC,SAAS,CAAC,eAAe,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;;AA5EH,8BA6EC;AAxEgB,2BAAiB,GAA4B;IAC1D,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"dataLabel.js","sourcesContent":["import { isValidNumber, merge } from '@visactor/vutils';\nimport type { IGraphic, INode } from '@visactor/vrender';\nimport { AbstractComponent } from '../core/base';\nimport type { PointLocationCfg } from '../core/type';\nimport { bitmapTool } from './overlap';\nimport { RectLabel } from './rect';\nimport { SymbolLabel } from './symbol';\nimport { ArcLabel } from './arc';\nimport type { DataLabelAttrs } from './type';\nimport type { LabelBase } from './base';\n\nconst labelComponentMap = {\n rect: RectLabel,\n symbol: SymbolLabel,\n arc: ArcLabel\n};\n\nexport class DataLabel extends AbstractComponent<DataLabelAttrs> {\n name = 'data-label';\n\n private _componentMap: Map<string, LabelBase<any>>;\n\n private static defaultAttributes: Partial<DataLabelAttrs> = {\n pickable: false\n };\n\n constructor(attributes: DataLabelAttrs) {\n super(merge({}, DataLabel.defaultAttributes, attributes));\n }\n\n protected render(): void {\n const { dataLabels, size } = this.attribute;\n if (!dataLabels || dataLabels.length === 0) {\n return;\n }\n const { width = 0, height = 0 } = size || {};\n\n if (!width || !height || !isValidNumber(height * width)) {\n return;\n }\n\n if (!this._componentMap) {\n this._componentMap = new Map();\n }\n const tool = bitmapTool(width, height);\n const bitmap = tool.bitmap();\n\n const currentComponentMap = new Map();\n const prevComponentMap = this._componentMap;\n\n for (let i = 0; i < dataLabels.length; i++) {\n const dataLabel = dataLabels[i];\n if (labelComponentMap[dataLabel.type]) {\n const { baseMarkGroupName } = dataLabel;\n let component = this._componentMap.get(baseMarkGroupName);\n if (component) {\n component.setBitmapTool(tool);\n component.setBitmap(bitmap);\n component.setAttributes(dataLabel);\n currentComponentMap.set(baseMarkGroupName, component);\n } else {\n component = new labelComponentMap[dataLabel.type](dataLabel as any);\n component.setBitmap(bitmap);\n component.setBitmapTool(tool);\n this.add(component as unknown as INode);\n currentComponentMap.set(baseMarkGroupName, component);\n }\n }\n }\n\n prevComponentMap.forEach((cp, key) => {\n if (!currentComponentMap.get(key)) {\n this.removeChild(cp as unknown as IGraphic);\n }\n });\n\n this._componentMap = currentComponentMap;\n }\n\n setLocation(point: PointLocationCfg) {\n this.translateTo(point.x, point.y);\n }\n\n disableAnimation() {\n this._componentMap.forEach(component => {\n component.disableAnimation();\n });\n }\n\n enableAnimation() {\n this._componentMap.forEach(component => {\n component.enableAnimation();\n });\n }\n}\n"]}
@@ -5,9 +5,9 @@ import type { LabelBase } from '../base';
5
5
  import type { BaseLabelAttrs, Strategy } from '../type';
6
6
  import type { Bitmap } from './bitmap';
7
7
  import type { BitmapTool } from './scaler';
8
- export declare function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound?: boolean, pad?: number): boolean;
8
+ export declare function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound?: boolean): boolean;
9
9
  export declare function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds): boolean;
10
- export declare function placeToCandidates($: BitmapTool, bitmap: Bitmap, text: Text, candidates?: PointLocationCfg[], clampForce?: boolean, pad?: number): PointLocationCfg | false;
10
+ export declare function placeToCandidates($: BitmapTool, bitmap: Bitmap, text: Text, candidates?: PointLocationCfg[], clampForce?: boolean): PointLocationCfg | false;
11
11
  export declare function place<T extends BaseLabelAttrs>($: BitmapTool, bitmap: Bitmap, s: Strategy, attrs: T, text: Text, bounds: IBoundsLike, labeling?: LabelBase<T>['labeling']): PointLocationCfg | false;
12
12
  export declare const DefaultPositions: string[];
13
13
  export declare const DefaultRectPositions: string[];
@@ -6,14 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils"), scaler_1 = require("./scaler");
8
8
 
9
- function canPlace($, bitmap, bound, checkBound = !0, pad = 0) {
10
- let range = bound;
11
- pad > 0 && (range = {
12
- x1: bound.x1 - pad,
13
- x2: bound.x2 + pad,
14
- y1: bound.y1 - pad,
15
- y2: bound.y2 + pad
16
- }), range = (0, scaler_1.boundToRange)($, range);
9
+ function canPlace($, bitmap, bound, checkBound = !0) {
10
+ const range = (0, scaler_1.boundToRange)($, bound);
17
11
  return !(checkBound && bitmap.outOfBounds(range)) && !bitmap.getRange(range);
18
12
  }
19
13
 
@@ -21,23 +15,22 @@ function canPlaceInside(textBound, shapeBound) {
21
15
  return !(!textBound || !shapeBound) && shapeBound.encloses(textBound);
22
16
  }
23
17
 
24
- function placeToCandidates($, bitmap, text, candidates = [], clampForce = !0, pad = 0) {
18
+ function placeToCandidates($, bitmap, text, candidates = [], clampForce = !0) {
25
19
  for (let i = 0; i < candidates.length; i++) {
26
20
  const tempText = text.clone();
27
21
  if (tempText.setAttributes(candidates[i]), tempText.update(), canPlace($, bitmap, (0,
28
- scaler_1.boundToRange)($, tempText.AABBBounds), clampForce, pad)) return bitmap.setRange((0,
22
+ scaler_1.boundToRange)($, tempText.AABBBounds), clampForce)) return bitmap.setRange((0,
29
23
  scaler_1.boundToRange)($, tempText.AABBBounds, !0)), candidates[i];
30
24
  }
31
25
  return !1;
32
26
  }
33
27
 
34
28
  function place($, bitmap, s, attrs, text, bounds, labeling) {
35
- var _a, _b;
36
- const clampForce = null === (_a = attrs.overlap) || void 0 === _a ? void 0 : _a.clampForce, overlapPadding = null === (_b = attrs.overlap) || void 0 === _b ? void 0 : _b.overlapPadding;
29
+ var _a, _b, _c;
37
30
  if ("bound" === s.type || "position" === s.type) {
38
31
  if ((0, vutils_1.isFunction)(labeling)) {
39
32
  const candidates = (((0, vutils_1.isFunction)(s.position) ? s.position(text.attribute) : s.position) || defaultLabelPosition(attrs.type)).map((p => labeling(text.AABBBounds, bounds, p, attrs.offset)));
40
- return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);
33
+ return placeToCandidates($, bitmap, text, candidates, null === (_a = attrs.overlap) || void 0 === _a ? void 0 : _a.clampForce);
41
34
  }
42
35
  return !1;
43
36
  }
@@ -46,14 +39,14 @@ function place($, bitmap, s, attrs, text, bounds, labeling) {
46
39
  x: text.attribute.x,
47
40
  y: text.attribute.y + dy
48
41
  })));
49
- return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);
42
+ return placeToCandidates($, bitmap, text, candidates, null === (_b = attrs.overlap) || void 0 === _b ? void 0 : _b.clampForce);
50
43
  }
51
44
  if ("moveX" === s.type) {
52
45
  const candidates = (s.offset ? (0, vutils_1.isFunction)(s.offset) ? s.offset(text.attribute) : s.offset : []).map((dx => ({
53
46
  x: text.attribute.x + dx,
54
47
  y: text.attribute.y
55
48
  })));
56
- return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);
49
+ return placeToCandidates($, bitmap, text, candidates, null === (_c = attrs.overlap) || void 0 === _c ? void 0 : _c.clampForce);
57
50
  }
58
51
  return !1;
59
52
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["label/overlap/place.ts"],"names":[],"mappings":";;;AAEA,6CAA8C;AAM9C,qCAAwC;AAiCxC,SAAgB,QAAQ,CAAC,CAAa,EAAE,MAAc,EAAE,KAAkB,EAAE,UAAU,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;IACpG,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,GAAG,GAAG,CAAC,EAAE;QACX,KAAK,GAAG;YACN,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG;YAClB,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG;YAClB,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG;YAClB,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG;SACnB,CAAC;KACH;IACD,KAAK,GAAG,IAAA,qBAAY,EAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAE/B,MAAM,WAAW,GAAG,UAAU,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE;QACf,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAnBD,4BAmBC;AAQD,SAAgB,cAAc,CAAC,SAAsB,EAAE,UAAuB;IAC5E,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AALD,wCAKC;AAED,SAAgB,iBAAiB,CAC/B,CAAa,EACb,MAAc,EACd,IAAU,EACV,aAAiC,E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9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE9B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IAGX,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,EAAE;QACpC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE;QACrD,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;KACnB;IAGD,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,EAAE;QACrC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE;QACvD,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;KACpB;IAED,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACpB,CAAC;AA1BD,8BA0BC","file":"place.js","sourcesContent":["import type { IText, Text } from '@visactor/vrender';\nimport type { IAABBBounds, IBoundsLike } from '@visactor/vutils';\nimport { isFunction } from '@visactor/vutils';\nimport type { PointLocationCfg } from '../../core/type';\nimport type { LabelBase } from '../base';\nimport type { BaseLabelAttrs, OverlapAttrs, Strategy } from '../type';\nimport type { Bitmap } from './bitmap';\nimport type { BitmapTool } from './scaler';\nimport { boundToRange } from './scaler';\n\n/**\n * 防重叠逻辑参考 https://github.com/vega/vega/\n * Copyright (c) 2015-2023, University of Washington Interactive Data Lab\n All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n 3. Neither the name of the copyright holder nor the names of its contributors\n may be used to endorse or promote products derived from this software\n without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nexport function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound = true, pad = 0) {\n let range = bound;\n if (pad > 0) {\n range = {\n x1: bound.x1 - pad,\n x2: bound.x2 + pad,\n y1: bound.y1 - pad,\n y2: bound.y2 + pad\n };\n }\n range = boundToRange($, range);\n\n const outOfBounds = checkBound && bitmap.outOfBounds(range);\n\n if (outOfBounds) {\n return false;\n }\n\n return !bitmap.getRange(range);\n}\n\n/**\n * 是否在图形内部\n * @param textBound\n * @param shapeBound\n * @returns\n */\nexport function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds) {\n if (!textBound || !shapeBound) {\n return false;\n }\n return shapeBound.encloses(textBound);\n}\n\nexport function placeToCandidates(\n $: BitmapTool,\n bitmap: Bitmap,\n text: Text,\n candidates: PointLocationCfg[] = [],\n clampForce = true,\n pad = 0\n): PointLocationCfg | false {\n for (let i = 0; i < candidates.length; i++) {\n const tempText = text.clone();\n tempText.setAttributes(candidates[i]);\n tempText.update();\n\n if (canPlace($, bitmap, boundToRange($, tempText.AABBBounds), clampForce, pad)) {\n bitmap.setRange(boundToRange($, tempText.AABBBounds, true));\n return candidates[i];\n }\n }\n return false;\n}\n\nexport function place<T extends BaseLabelAttrs>(\n $: BitmapTool,\n bitmap: Bitmap,\n s: Strategy,\n attrs: T,\n text: Text,\n bounds: IBoundsLike,\n labeling?: LabelBase<T>['labeling']\n): PointLocationCfg | false {\n const clampForce = (attrs.overlap as OverlapAttrs)?.clampForce;\n const overlapPadding = (attrs.overlap as OverlapAttrs)?.overlapPadding;\n if (s.type === 'bound' || s.type === 'position') {\n if (isFunction(labeling)) {\n // TODO:这里可以 filter 掉初始位置,提升一部分性能\n const userPosition = isFunction(s.position) ? s.position(text.attribute) : s.position;\n const positions = (userPosition || defaultLabelPosition(attrs.type)) as string[];\n const candidates = positions.map(p => labeling(text.AABBBounds, bounds, p, attrs.offset) as PointLocationCfg);\n return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);\n }\n return false;\n }\n\n if (s.type === 'moveY') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dy => {\n return { x: text.attribute.x as number, y: (text.attribute.y as number) + dy };\n });\n return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);\n }\n\n if (s.type === 'moveX') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dx => {\n return { x: (text.attribute.x as number) + dx, y: text.attribute.y as number };\n });\n return placeToCandidates($, bitmap, text, candidates, clampForce, overlapPadding);\n }\n return false;\n}\n\nexport const DefaultPositions = [\n 'top',\n 'bottom',\n 'right',\n 'left',\n 'top-right',\n 'bottom-right',\n 'top-left',\n 'bottom-left'\n];\nexport const DefaultRectPositions = ['top', 'inside-top', 'inside'];\n\nexport function defaultLabelPosition(type?: string) {\n switch (type) {\n case 'rect':\n return DefaultRectPositions;\n default:\n return DefaultPositions;\n }\n}\n\nexport function clampText(text: IText, width: number, height: number) {\n const { x1, x2, y1, y2 } = text.AABBBounds;\n const minX = Math.min(x1, x2);\n const maxX = Math.max(x1, x2);\n\n const minY = Math.min(y1, y2);\n const maxY = Math.max(y1, y2);\n\n let dx = 0;\n let dy = 0;\n\n // x 方向\n if (minX < 0 && maxX - minX <= width) {\n dx = -minX;\n } else if (maxX > width && minX - (maxX - width) >= 0) {\n dx = width - maxX;\n }\n\n // y 方向\n if (minY < 0 && maxY - minY <= height) {\n dy = -minY;\n } else if (maxY > height && minY - (maxY - height) >= 0) {\n dy = height - maxY;\n }\n\n return { dx, dy };\n}\n"]}
1
+ {"version":3,"sources":["label/overlap/place.ts"],"names":[],"mappings":";;;AAEA,6CAA8C;AAM9C,qCAAwC;AAiCxC,SAAgB,QAAQ,CAAC,CAAa,EAAE,MAAc,EAAE,KAAkB,EAAE,UAAU,GAAG,IAAI;IAC3F,MAAM,KAAK,GAAG,IAAA,qBAAY,EAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,UAAU,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE;QACf,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AATD,4BASC;AAQD,SAAgB,cAAc,CAAC,SAAsB,EAAE,UAAuB;IAC5E,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AALD,wCAKC;AAED,SAAgB,iBAAiB,CAC/B,CAA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AE9B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IAGX,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,EAAE;QACpC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE;QACrD,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;KACnB;IAGD,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,EAAE;QACrC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE;QACvD,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;KACpB;IAED,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACpB,CAAC;AA1BD,8BA0BC","file":"place.js","sourcesContent":["import type { IText, Text } from '@visactor/vrender';\nimport type { IAABBBounds, IBoundsLike } from '@visactor/vutils';\nimport { isFunction } from '@visactor/vutils';\nimport type { PointLocationCfg } from '../../core/type';\nimport type { LabelBase } from '../base';\nimport type { BaseLabelAttrs, OverlapAttrs, Strategy } from '../type';\nimport type { Bitmap } from './bitmap';\nimport type { BitmapTool } from './scaler';\nimport { boundToRange } from './scaler';\n\n/**\n * 防重叠逻辑参考 https://github.com/vega/vega/\n * Copyright (c) 2015-2023, University of Washington Interactive Data Lab\n All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n 3. Neither the name of the copyright holder nor the names of its contributors\n may be used to endorse or promote products derived from this software\n without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nexport function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound = true) {\n const range = boundToRange($, bound);\n const outOfBounds = checkBound && bitmap.outOfBounds(range);\n\n if (outOfBounds) {\n return false;\n }\n\n return !bitmap.getRange(range);\n}\n\n/**\n * 是否在图形内部\n * @param textBound\n * @param shapeBound\n * @returns\n */\nexport function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds) {\n if (!textBound || !shapeBound) {\n return false;\n }\n return shapeBound.encloses(textBound);\n}\n\nexport function placeToCandidates(\n $: BitmapTool,\n bitmap: Bitmap,\n text: Text,\n candidates: PointLocationCfg[] = [],\n clampForce = true\n): PointLocationCfg | false {\n for (let i = 0; i < candidates.length; i++) {\n const tempText = text.clone();\n tempText.setAttributes(candidates[i]);\n tempText.update();\n\n if (canPlace($, bitmap, boundToRange($, tempText.AABBBounds), clampForce)) {\n bitmap.setRange(boundToRange($, tempText.AABBBounds, true));\n return candidates[i];\n }\n }\n return false;\n}\n\nexport function place<T extends BaseLabelAttrs>(\n $: BitmapTool,\n bitmap: Bitmap,\n s: Strategy,\n attrs: T,\n text: Text,\n bounds: IBoundsLike,\n labeling?: LabelBase<T>['labeling']\n): PointLocationCfg | false {\n if (s.type === 'bound' || s.type === 'position') {\n if (isFunction(labeling)) {\n // TODO:这里可以 filter 掉初始位置,提升一部分性能\n const userPosition = isFunction(s.position) ? s.position(text.attribute) : s.position;\n const positions = (userPosition || defaultLabelPosition(attrs.type)) as string[];\n const candidates = positions.map(p => labeling(text.AABBBounds, bounds, p, attrs.offset) as PointLocationCfg);\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n }\n\n if (s.type === 'moveY') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dy => {\n return { x: text.attribute.x as number, y: (text.attribute.y as number) + dy };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n\n if (s.type === 'moveX') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dx => {\n return { x: (text.attribute.x as number) + dx, y: text.attribute.y as number };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n}\n\nexport const DefaultPositions = [\n 'top',\n 'bottom',\n 'right',\n 'left',\n 'top-right',\n 'bottom-right',\n 'top-left',\n 'bottom-left'\n];\nexport const DefaultRectPositions = ['top', 'inside-top', 'inside'];\n\nexport function defaultLabelPosition(type?: string) {\n switch (type) {\n case 'rect':\n return DefaultRectPositions;\n default:\n return DefaultPositions;\n }\n}\n\nexport function clampText(text: IText, width: number, height: number) {\n const { x1, x2, y1, y2 } = text.AABBBounds;\n const minX = Math.min(x1, x2);\n const maxX = Math.max(x1, x2);\n\n const minY = Math.min(y1, y2);\n const maxY = Math.max(y1, y2);\n\n let dx = 0;\n let dy = 0;\n\n // x 方向\n if (minX < 0 && maxX - minX <= width) {\n dx = -minX;\n } else if (maxX > width && minX - (maxX - width) >= 0) {\n dx = width - maxX;\n }\n\n // y 方向\n if (minY < 0 && maxY - minY <= height) {\n dy = -minY;\n } else if (maxY > height && minY - (maxY - height) >= 0) {\n dy = height - maxY;\n }\n\n return { dx, dy };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["label/rect.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAEzC,iCAAmC;AAEnC,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,UAA0B;QACpC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,CAAC;QAClG,IAAI,CAAC,UAAU,IAAI,CAAC,aAAa,EAAE;YACjC,OAAO;SACR;QAED,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QAChE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QACjE,IAAI,OAAO,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CA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AC;SACxB;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YACrC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACxB;QAED,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAEpD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;;AA9EH,8BA+EC;AA9EQ,aAAG,GAAG,YAAY,CAAC;AAEnB,2BAAiB,GAA4B;IAClD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,QAAQ;QACtB,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9B;IACD,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"rect.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { RectLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class RectLabel extends LabelBase<RectLabelAttrs> {\n static tag = 'rect-label';\n\n static defaultAttributes: Partial<RectLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: RectLabelAttrs) {\n super(merge({}, RectLabel.defaultAttributes, attributes));\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const rectWidth = Math.abs(graphicBounds.x2 - graphicBounds.x1);\n const rectHeight = Math.abs(graphicBounds.y2 - graphicBounds.y1);\n let anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n let anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (position) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n let vx = 0;\n let vy = 0;\n\n const isInside = position.includes('inside');\n\n if (position.includes('top')) {\n vy = isInside ? 1 : -1;\n } else if (position.includes('bottom')) {\n vy = isInside ? -1 : 1;\n } else if (position.includes('left')) {\n vx = isInside ? 1 : -1;\n } else if (position.includes('right')) {\n vx = isInside ? -1 : 1;\n }\n\n const x = anchorX + vx * offset + (vx * width) / 2;\n const y = anchorY + vy * offset + (vy * height) / 2;\n\n return { x, y };\n }\n}\n"]}
1
+ {"version":3,"sources":["label/rect.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAGzC,iCAAmC;AAEnC,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,UAA0B;QACpC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,CAAC;QAClG,IAAI,CAAC,UAAU,IAAI,CAAC,aAAa,EAAE;YACjC,OAAO;SACR;QAED,M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,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"rect.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { ITextGraphicAttribute } from '@visactor/vrender';\nimport type { RectLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class RectLabel extends LabelBase<RectLabelAttrs> {\n static tag = 'rect-label';\n\n static defaultAttributes: Partial<RectLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: RectLabelAttrs) {\n super(merge({}, RectLabel.defaultAttributes, attributes));\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const rectWidth = Math.abs(graphicBounds.x2 - graphicBounds.x1);\n const rectHeight = Math.abs(graphicBounds.y2 - graphicBounds.y1);\n let anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n let anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (position) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n let vx = 0;\n let vy = 0;\n\n const isInside = position.includes('inside');\n\n if (position.includes('top')) {\n vy = isInside ? 1 : -1;\n } else if (position.includes('bottom')) {\n vy = isInside ? -1 : 1;\n } else if (position.includes('left')) {\n vx = isInside ? 1 : -1;\n } else if (position.includes('right')) {\n vx = isInside ? -1 : 1;\n }\n\n const x = anchorX + vx * offset + (vx * width) / 2;\n const y = anchorY + vy * offset + (vy * height) / 2;\n\n return { x, y };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["label/symbol.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAEzC,iCAAmC;AAEnC,MAAa,WAAY,SAAQ,gBAA2B;IAgB1D,YAAY,UAA4B;QACtC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,WAAW,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAhB9D,SAAI,GAAG,cAAc,CAAC;IAiBtB,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,CAAC;QAClG,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QAED,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAEjC,MAAM,OAAO,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QAE1D,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,aAAa,EAAE;YACjB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE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AAG,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE3E,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;;AA9EH,kCA+EC;AA5EQ,6BAAiB,GAA8B;IACpD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,QAAQ;QACtB,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9B;IACD,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"symbol.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { SymbolLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class SymbolLabel extends LabelBase<SymbolLabelAttrs> {\n name = 'symbol-label';\n\n static defaultAttributes: Partial<SymbolLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: SymbolLabelAttrs) {\n super(merge({}, SymbolLabel.defaultAttributes, attributes));\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) {\n if (!textBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n const anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n let offsetX = 0;\n let offsetY = 0;\n if (graphicBounds) {\n offsetX = Math.abs(graphicBounds.x1 - graphicBounds.x2) / 2;\n offsetY = Math.abs(graphicBounds.y1 - graphicBounds.y2) / 2;\n }\n\n const angle = {\n 'top-right': -235,\n 'top-left': 235,\n 'bottom-right': 45,\n 'bottom-left': -45\n };\n\n switch (position) {\n case 'top':\n sy = -1;\n break;\n case 'bottom':\n sy = 1;\n break;\n case 'left':\n sx = -1;\n break;\n case 'right':\n sx = 1;\n break;\n case 'bottom-left':\n case 'bottom-right':\n case 'top-left':\n case 'top-right':\n sx = Math.sin(angle[position] * (Math.PI / 180));\n sy = Math.cos(angle[position] * (Math.PI / 180));\n break;\n case 'center':\n sx = 0;\n sy = 0;\n break;\n }\n\n const x = anchorX + sx * (offset + offsetX) + Math.sign(sx) * (width / 2);\n const y = anchorY + sy * (offset + offsetY) + Math.sign(sy) * (height / 2);\n\n return { x, y };\n }\n}\n"]}
1
+ {"version":3,"sources":["label/symbol.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAGzC,iCAAmC;AAEnC,MAAa,WAAY,SAAQ,gBAA2B;IAgB1D,YAAY,UAA4B;QACtC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,WAAW,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAhB9D,SAAI,GAAG,cAAc,CAAC;IAiBtB,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,CAAC;QAClG,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QAED,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAEjC,MAAM,OAAO,GAA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AAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,QAAQ;gBACX,EAAE,GAAG,CAAC,CAAC;gBACP,EAAE,GAAG,CAAC,CAAC;gBACP,MAAM;SACT;QAED,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1E,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE3E,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;;AA9EH,kCA+EC;AA5EQ,6BAAiB,GAA8B;IACpD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,QAAQ;QACtB,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9B;IACD,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"symbol.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { ITextGraphicAttribute } from '@visactor/vrender';\nimport type { SymbolLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class SymbolLabel extends LabelBase<SymbolLabelAttrs> {\n name = 'symbol-label';\n\n static defaultAttributes: Partial<SymbolLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: SymbolLabelAttrs) {\n super(merge({}, SymbolLabel.defaultAttributes, attributes));\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) {\n if (!textBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n const anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n let offsetX = 0;\n let offsetY = 0;\n if (graphicBounds) {\n offsetX = Math.abs(graphicBounds.x1 - graphicBounds.x2) / 2;\n offsetY = Math.abs(graphicBounds.y1 - graphicBounds.y2) / 2;\n }\n\n const angle = {\n 'top-right': -235,\n 'top-left': 235,\n 'bottom-right': 45,\n 'bottom-left': -45\n };\n\n switch (position) {\n case 'top':\n sy = -1;\n break;\n case 'bottom':\n sy = 1;\n break;\n case 'left':\n sx = -1;\n break;\n case 'right':\n sx = 1;\n break;\n case 'bottom-left':\n case 'bottom-right':\n case 'top-left':\n case 'top-right':\n sx = Math.sin(angle[position] * (Math.PI / 180));\n sy = Math.cos(angle[position] * (Math.PI / 180));\n break;\n case 'center':\n sx = 0;\n sy = 0;\n break;\n }\n\n const x = anchorX + sx * (offset + offsetX) + Math.sign(sx) * (width / 2);\n const y = anchorY + sy * (offset + offsetY) + Math.sign(sy) * (height / 2);\n\n return { x, y };\n }\n}\n"]}
@@ -37,7 +37,6 @@ export interface OverlapAttrs {
37
37
  avoidBaseMark?: boolean;
38
38
  avoidMarks?: string[] | IGraphic[];
39
39
  strategy?: Strategy[];
40
- overlapPadding?: number;
41
40
  }
42
41
  export interface SmartInvertAttrs {
43
42
  textType?: string;
@@ -72,16 +71,14 @@ export interface SymbolLabelAttrs extends BaseLabelAttrs {
72
71
  }
73
72
  export interface RectLabelAttrs extends BaseLabelAttrs {
74
73
  type: 'rect';
74
+ baseMarkGroupName: string;
75
75
  position?: Functional<'top' | 'bottom' | 'left' | 'right' | 'inside' | 'inside-top' | 'inside-bottom' | 'inside-right' | 'inside-left'>;
76
76
  }
77
77
  export interface LineLabelAttrs extends BaseLabelAttrs {
78
78
  type: 'line';
79
+ baseMarkGroupName: string;
79
80
  position?: Functional<'start' | 'end'>;
80
81
  }
81
- export interface PolygonLabelAttrs extends BaseLabelAttrs {
82
- type: 'polygon';
83
- position?: Functional<'center'>;
84
- }
85
82
  export interface ArcLabelAttrs extends BaseLabelAttrs {
86
83
  type: 'arc';
87
84
  baseMarkGroupName: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["label/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n EasingType,\n IGraphic,\n IGroupGraphicAttribute,\n ITextGraphicAttribute,\n Text,\n TextAlignType,\n TextBaselineType\n} from '@visactor/vrender';\n\nexport type LabelItemStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n};\n\nexport type LabelItem = {\n // 用于动画\n id?: string;\n // 原始数据\n data?: any;\n [key: string]: any;\n} & ITextGraphicAttribute;\n\nexport interface BaseLabelAttrs extends IGroupGraphicAttribute {\n type: string;\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n /**\n * 是否开启选中交互\n * @default false\n */\n select?: boolean;\n /**\n * 是否开启 hover 交互\n * @default false\n */\n hover?: boolean;\n /**\n * 标签数据\n */\n data: LabelItem[];\n\n /** 文本样式,优先级低于 data */\n textStyle?: Partial<ITextGraphicAttribute>;\n\n /** 文本交互样式 */\n state?: LabelItemStateStyle<ITextGraphicAttribute>;\n\n /** 标签默认位置 */\n position?: Functional<string>;\n\n /** 偏移量 */\n offset?: number;\n\n /** 是否开启防重叠\n * @default true\n */\n overlap?: OverlapAttrs | false;\n\n /** 智能反色 */\n smartInvert?: SmartInvertAttrs | false;\n\n /** 动画配置 */\n animation?: ILabelAnimation | false;\n\n // 排序 or 删减\n dataFilter?: (data: LabelItem[]) => LabelItem[];\n\n /** 自定义布局函数\n * @description 当配置了 customLayoutFunc 后,默认布局逻辑将不再生效。(position/offset不生效)\n */\n customLayoutFunc?: (data: LabelItem[], getRelatedGraphic: (data: LabelItem) => IGraphic) => Text[];\n\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n */\n customOverlapFunc?: (label: Text[], getRelatedGraphic: (data: LabelItem) => IGraphic) => Text[];\n}\n\nexport interface OverlapAttrs {\n /**\n * 防重叠的区域大小\n */\n size?: { width: number; height: number };\n\n /**\n * 发生重叠后,是否隐藏标签\n * @default true\n */\n hideOnHit?: boolean;\n\n /**\n * 是否约束标签在指定 size 的范围内。开启后若标签被区域裁剪,会向内收缩。\n * @default true\n */\n clampForce?: boolean;\n\n /**\n * 是否躲避基础图元\n * @default false\n */\n avoidBaseMark?: boolean;\n\n /**\n * 躲避指定图元\n * @default []\n */\n avoidMarks?: string[] | IGraphic[];\n\n /**\n * 发生重叠后的躲避策略\n */\n strategy?: Strategy[];\n\n /**\n * 文字在防重叠计算中预留的边距。\n * @default 0\n */\n overlapPadding?: number;\n}\n\nexport interface SmartInvertAttrs {\n /**\n * 文本类型\n * 包含普通文本和大文本,对应不同的对比度标准,label默认为普通文本\n * 'normalText' | 'largeText'\n * @default 'normalText'\n */\n textType?: string;\n /**\n * 自定义对比度阈值\n */\n contrastRatiosThreshold?: number;\n /**\n * 自定义备选label颜色\n */\n alternativeColors?: string | string[];\n /**\n * fillStrategy四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持stroke设置的颜色)\n * @default 'invertSeries'\n */\n fillStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * strokeStrategy的四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持fill设置的颜色)\n * @default 'series'\n */\n strokeStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * 前景色与亮色具有对比度时,similarSeries使用该色\n * @default '#ffffff'\n */\n brightColor?: string;\n /**\n * 前景色与暗色具有对比度时,similarSeries使用该色\n * @default '#000000'\n */\n darkColor?: string;\n}\n\nexport type PositionStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则考虑 position 内的备选位置。\n */\n type: 'position';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type BoundStrategy = {\n /**\n * 标签配置在图形内部时使用。\n * 当图形大小不足以放下标签,则考虑 position 内的备选位置。\n */\n type: 'bound';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type MoveYStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在Y方向上寻找位置。\n */\n type: 'moveY';\n /**\n * Y方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type MoveXStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在X方向上寻找位置。\n */\n type: 'moveX';\n /**\n * X方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type Strategy = PositionStrategy | BoundStrategy | MoveYStrategy | MoveXStrategy;\n\nexport type LabelPosition = SymbolLabelAttrs['position'] | RectLabelAttrs['position'];\n\nexport interface SymbolLabelAttrs extends BaseLabelAttrs {\n type: 'symbol';\n\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'\n >;\n}\n\nexport interface RectLabelAttrs extends BaseLabelAttrs {\n type: 'rect';\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'inside' | 'inside-top' | 'inside-bottom' | 'inside-right' | 'inside-left'\n >;\n}\n\nexport interface LineLabelAttrs extends BaseLabelAttrs {\n type: 'line';\n /**\n * 标签位置\n * @default 'end'\n */\n position?: Functional<'start' | 'end'>;\n}\n\nexport interface PolygonLabelAttrs extends BaseLabelAttrs {\n type: 'polygon';\n /**\n * 标签位置\n * @default 'center'\n */\n position?: Functional<'center'>;\n}\n\nexport interface ArcLabelAttrs extends BaseLabelAttrs {\n type: 'arc';\n\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n\n /**\n * 标签位置\n * @default 'outside'\n */\n position?: Functional<'inside' | 'outside'>;\n\n // 画布宽度\n width?: number;\n // 画布高度\n height?: number;\n\n /**\n * 是否允许标签重叠\n * @default false\n */\n coverEnable?: boolean;\n /**\n * 是否允许标签旋转\n * @default true\n */\n rotate?: boolean;\n\n /**\n * 文字与引导线间隔宽度\n * @default 5\n */\n spaceWidth?: number;\n /**\n * 标签旋转角度\n */\n angle?: number;\n /**\n * 标签横向点对齐\n */\n textAlign?: TextAlignType;\n /**\n * 标签纵向点对齐\n */\n textBaseline?: TextBaselineType;\n /**\n * 扇区间标签的间隔\n * @default 6\n */\n layoutArcGap?: number;\n /** 标签引导线样式 */\n line?: IArcLabelLineSpec;\n /** 标签布局配置 */\n layout?: IArcLabelLayoutSpec;\n /** 标签引导线点集 */\n points?: IPoint[];\n /** 饼图扇区中心偏移 */\n centerOffset?: number;\n}\n\nexport interface IArcLabelLineSpec {\n /** 引导线线宽 */\n lineWidth?: number;\n /** 引导线颜色 */\n stroke?: string;\n /**\n * 是否显示引导线\n * @default true\n */\n visible?: boolean;\n /**\n * 引导线 line1 部分最小长度\n * @default 20\n */\n line1MinLength?: number;\n /**\n * 引导线 line2 部分最小长度\n * @default 10\n */\n line2MinLength?: number;\n}\n\nexport type ArcLabelAlignType = 'arc' | 'labelLine' | 'edge';\n\nexport type ArcLabelStrategyType = 'priority' | 'vertical' | 'none';\n\nexport interface IArcLabelLayoutSpec {\n /**\n * 标签对齐方式\n * @default 'arc'\n */\n textAlign?: ArcLabelAlignType;\n /** @deprecate 建议统一使用textAlign,后续将废除 */\n align?: ArcLabelAlignType;\n /**\n * 标签布局策略\n * @default 'priority'\n */\n strategy?: ArcLabelStrategyType;\n /**\n * 是否启用切线约束\n * @default true\n */\n tangentConstraint?: boolean;\n}\n\nexport interface DataLabelAttrs extends IGroupGraphicAttribute {\n dataLabels: (RectLabelAttrs | SymbolLabelAttrs | ArcLabelAttrs)[];\n /**\n * 防重叠的区域大小\n */\n size: { width: number; height: number };\n}\n\nexport type Functional<T> = T | ((data: any) => T);\n\nexport interface ILabelAnimation {\n mode?: 'same-time' | 'after' | 'after-all';\n duration?: number;\n delay?: number;\n easing?: EasingType;\n /** 是否开启 increaseCount 动画\n * @default true\n */\n increaseEffect?: boolean;\n}\n\nexport interface IPoint {\n x: number;\n y: number;\n}\n\nexport interface IPolarPoint {\n radius: number;\n angle: number;\n}\n\nexport type Quadrant = 1 | 2 | 3 | 4;\n\nexport type TextAlign = 'left' | 'right' | 'center';\n"]}
1
+ {"version":3,"sources":["label/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n EasingType,\n IGraphic,\n IGroupGraphicAttribute,\n ITextGraphicAttribute,\n Text,\n TextAlignType,\n TextBaselineType\n} from '@visactor/vrender';\n\nexport type LabelItemStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n};\n\nexport type LabelItem = {\n // 用于动画\n id?: string;\n // 原始数据\n data?: any;\n [key: string]: any;\n} & ITextGraphicAttribute;\n\nexport interface BaseLabelAttrs extends IGroupGraphicAttribute {\n type: string;\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n /**\n * 是否开启选中交互\n * @default false\n */\n select?: boolean;\n /**\n * 是否开启 hover 交互\n * @default false\n */\n hover?: boolean;\n /**\n * 标签数据\n */\n data: LabelItem[];\n\n /** 文本样式,优先级低于 data */\n textStyle?: Partial<ITextGraphicAttribute>;\n\n /** 文本交互样式 */\n state?: LabelItemStateStyle<ITextGraphicAttribute>;\n\n /** 标签默认位置 */\n position?: Functional<string>;\n\n /** 偏移量 */\n offset?: number;\n\n /** 是否开启防重叠\n * @default true\n */\n overlap?: OverlapAttrs | false;\n\n /** 智能反色 */\n smartInvert?: SmartInvertAttrs | false;\n\n /** 动画配置 */\n animation?: ILabelAnimation | false;\n\n // 排序 or 删减\n dataFilter?: (data: LabelItem[]) => LabelItem[];\n\n /** 自定义布局函数\n * @description 当配置了 customLayoutFunc 后,默认布局和防重叠逻辑将不再生效。(overlap/position/offset不生效)\n */\n customLayoutFunc?: (data: LabelItem[], getRelatedGraphic: (data: LabelItem) => IGraphic) => Text[];\n\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n */\n customOverlapFunc?: (label: Text[], getRelatedGraphic: (data: LabelItem) => IGraphic) => Text[];\n}\n\nexport interface OverlapAttrs {\n /**\n * 防重叠的区域大小\n */\n size?: { width: number; height: number };\n\n /**\n * 发生重叠后,是否隐藏标签\n * @default true\n */\n hideOnHit?: boolean;\n\n /**\n * 是否约束标签在指定 size 的范围内。开启后若标签被区域裁剪,会向内收缩。\n * @default true\n */\n clampForce?: boolean;\n\n /**\n * 是否躲避基础图元\n * @default false\n */\n avoidBaseMark?: boolean;\n\n /**\n * 躲避指定图元\n * @default []\n */\n avoidMarks?: string[] | IGraphic[];\n\n /**\n * 发生重叠后的躲避策略\n */\n strategy?: Strategy[];\n}\n\nexport interface SmartInvertAttrs {\n /**\n * 文本类型\n * 包含普通文本和大文本,对应不同的对比度标准,label默认为普通文本\n * 'normalText' | 'largeText'\n * @default 'normalText'\n */\n textType?: string;\n /**\n * 自定义对比度阈值\n */\n contrastRatiosThreshold?: number;\n /**\n * 自定义备选label颜色\n */\n alternativeColors?: string | string[];\n /**\n * fillStrategy四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持stroke设置的颜色)\n * @default 'invertSeries'\n */\n fillStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * strokeStrategy的四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持fill设置的颜色)\n * @default 'series'\n */\n strokeStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * 前景色与亮色具有对比度时,similarSeries使用该色\n * @default '#ffffff'\n */\n brightColor?: string;\n /**\n * 前景色与暗色具有对比度时,similarSeries使用该色\n * @default '#000000'\n */\n darkColor?: string;\n}\n\nexport type PositionStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则考虑 position 内的备选位置。\n */\n type: 'position';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type BoundStrategy = {\n /**\n * 标签配置在图形内部时使用。\n * 当图形大小不足以放下标签,则考虑 position 内的备选位置。\n */\n type: 'bound';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type MoveYStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在Y方向上寻找位置。\n */\n type: 'moveY';\n /**\n * Y方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type MoveXStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在X方向上寻找位置。\n */\n type: 'moveX';\n /**\n * X方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type Strategy = PositionStrategy | BoundStrategy | MoveYStrategy | MoveXStrategy;\n\nexport type LabelPosition = SymbolLabelAttrs['position'] | RectLabelAttrs['position'];\n\nexport interface SymbolLabelAttrs extends BaseLabelAttrs {\n type: 'symbol';\n\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'\n >;\n}\n\nexport interface RectLabelAttrs extends BaseLabelAttrs {\n type: 'rect';\n\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'inside' | 'inside-top' | 'inside-bottom' | 'inside-right' | 'inside-left'\n >;\n}\n\nexport interface LineLabelAttrs extends BaseLabelAttrs {\n type: 'line';\n\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n\n /**\n * 标签位置\n * @default 'end'\n */\n position?: Functional<'start' | 'end'>;\n}\n\nexport interface ArcLabelAttrs extends BaseLabelAttrs {\n type: 'arc';\n\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n\n /**\n * 标签位置\n * @default 'outside'\n */\n position?: Functional<'inside' | 'outside'>;\n\n // 画布宽度\n width?: number;\n // 画布高度\n height?: number;\n\n /**\n * 是否允许标签重叠\n * @default false\n */\n coverEnable?: boolean;\n /**\n * 是否允许标签旋转\n * @default true\n */\n rotate?: boolean;\n\n /**\n * 文字与引导线间隔宽度\n * @default 5\n */\n spaceWidth?: number;\n /**\n * 标签旋转角度\n */\n angle?: number;\n /**\n * 标签横向点对齐\n */\n textAlign?: TextAlignType;\n /**\n * 标签纵向点对齐\n */\n textBaseline?: TextBaselineType;\n /**\n * 扇区间标签的间隔\n * @default 6\n */\n layoutArcGap?: number;\n /** 标签引导线样式 */\n line?: IArcLabelLineSpec;\n /** 标签布局配置 */\n layout?: IArcLabelLayoutSpec;\n /** 标签引导线点集 */\n points?: IPoint[];\n /** 饼图扇区中心偏移 */\n centerOffset?: number;\n}\n\nexport interface IArcLabelLineSpec {\n /** 引导线线宽 */\n lineWidth?: number;\n /** 引导线颜色 */\n stroke?: string;\n /**\n * 是否显示引导线\n * @default true\n */\n visible?: boolean;\n /**\n * 引导线 line1 部分最小长度\n * @default 20\n */\n line1MinLength?: number;\n /**\n * 引导线 line2 部分最小长度\n * @default 10\n */\n line2MinLength?: number;\n}\n\nexport type ArcLabelAlignType = 'arc' | 'labelLine' | 'edge';\n\nexport type ArcLabelStrategyType = 'priority' | 'vertical' | 'none';\n\nexport interface IArcLabelLayoutSpec {\n /**\n * 标签对齐方式\n * @default 'arc'\n */\n textAlign?: ArcLabelAlignType;\n /** @deprecate 建议统一使用textAlign,后续将废除 */\n align?: ArcLabelAlignType;\n /**\n * 标签布局策略\n * @default 'priority'\n */\n strategy?: ArcLabelStrategyType;\n /**\n * 是否启用切线约束\n * @default true\n */\n tangentConstraint?: boolean;\n}\n\nexport interface DataLabelAttrs extends IGroupGraphicAttribute {\n dataLabels: (RectLabelAttrs | SymbolLabelAttrs | ArcLabelAttrs)[];\n /**\n * 防重叠的区域大小\n */\n size: { width: number; height: number };\n}\n\nexport type Functional<T> = T | ((data: any) => T);\n\nexport interface ILabelAnimation {\n mode?: 'same-time' | 'after' | 'after-all';\n duration?: number;\n delay?: number;\n easing?: EasingType;\n /** 是否开启 increaseCount 动画\n * @default true\n */\n increaseEffect?: boolean;\n}\n\nexport interface IPoint {\n x: number;\n y: number;\n}\n\nexport interface IPolarPoint {\n radius: number;\n angle: number;\n}\n\nexport type Quadrant = 1 | 2 | 3 | 4;\n\nexport type TextAlign = 'left' | 'right' | 'center';\n"]}
@@ -1,4 +1,3 @@
1
1
  import type { IColor } from '@visactor/vrender';
2
2
  export declare function labelSmartInvert(foregroundColorOrigin: IColor | undefined, backgroundColorOrogin: IColor | undefined, textType?: string | undefined, contrastRatiosThreshold?: number, alternativeColors?: string | string[]): IColor | undefined;
3
3
  export declare function contrastAccessibilityChecker(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined, textType?: IColor | undefined, contrastRatiosThreshold?: number): boolean;
4
- export declare function smartInvertStrategy(fillStrategy: string, baseColor: IColor, invertColor: IColor, similarColor: IColor): IColor;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.smartInvertStrategy = exports.contrastAccessibilityChecker = exports.labelSmartInvert = void 0;
5
+ }), exports.contrastAccessibilityChecker = exports.labelSmartInvert = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils"), defaultAlternativeColors = [ "#ffffff", "#000000" ];
8
8
 
@@ -41,23 +41,5 @@ function formatColorToHex(originColor) {
41
41
  return "#" + vutils_1.ColorUtil.rgbToHex(r, g, b);
42
42
  }
43
43
 
44
- function smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor) {
45
- let result;
46
- switch (fillStrategy) {
47
- case "base":
48
- result = baseColor;
49
- break;
50
-
51
- case "invertBase":
52
- result = invertColor;
53
- break;
54
-
55
- case "similarBase":
56
- result = similarColor;
57
- }
58
- return result;
59
- }
60
-
61
- exports.labelSmartInvert = labelSmartInvert, exports.contrastAccessibilityChecker = contrastAccessibilityChecker,
62
- exports.smartInvertStrategy = smartInvertStrategy;
44
+ exports.labelSmartInvert = labelSmartInvert, exports.contrastAccessibilityChecker = contrastAccessibilityChecker;
63
45
  //# sourceMappingURL=labelSmartInvert.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["util/labelSmartInvert.ts"],"names":[],"mappings":";;;AACA,6CAA6C;AAE7C,MAAM,wBAAwB,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAQlE,SAAgB,gBAAgB,CAC9B,qBAAyC,EACzC,qBAAyC,EACzC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC;IAErC,MAAM,eAAe,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAChE,MAAM,eAAe,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAChE,IAAI,CAAC,4BAA4B,CAAC,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,uBAAuB,CAAC,EAAE;QACtG,OAAO,sBAAsB,CAC3B,eAAe,EACf,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,CAClB,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAnBD,4CAmBC;AASD,SAAS,sBAAs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ACD,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;KACnB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAQD,SAAS,gBAAgB,CAAC,WAA+B;IACvD,IAAK,WAAsB,aAAtB,WAAW,uBAAX,WAAW,CAAa,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,CAAC,GAAG,IAAI,kBAAS,CAAC,KAAK,CAAC,WAAqB,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IAC5B,OAAO,GAAG,GAAG,kBAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,SAAgB,mBAAmB,CACjC,YAAoB,EACpB,SAAiB,EACjB,WAAmB,EACnB,YAAoB;IAEpB,IAAI,MAAM,CAAC;IACX,QAAQ,YAAY,EAAE;QACpB,KAAK,MAAM;YACT,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM;QACR,KAAK,YAAY;YACf,MAAM,GAAG,WAAW,CAAC;YACrB,MAAM;QACR,KAAK,aAAa;YAChB,MAAM,GAAG,YAAY,CAAC;QACxB;YACE,MAAM;KACT;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,kDAoBC","file":"labelSmartInvert.js","sourcesContent":["import type { IColor } from '@visactor/vrender';\nimport { ColorUtil } from '@visactor/vutils';\n\nconst defaultAlternativeColors: string[] = ['#ffffff', '#000000'];\n\n/**\n * 标签智能反色\n * @param foregroundColorOrigin\n * @param backgroundColorOrogin\n * @returns\n */\nexport function labelSmartInvert(\n foregroundColorOrigin: IColor | undefined,\n backgroundColorOrogin: IColor | undefined,\n textType?: string | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n): IColor | undefined {\n const foregroundColor = formatColorToHex(foregroundColorOrigin);\n const backgroundColor = formatColorToHex(backgroundColorOrogin);\n if (!contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return improveContrastReverse(\n foregroundColor,\n backgroundColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors\n );\n }\n return foregroundColor;\n}\n\n/**\n * 提升对比度\n * 对于对比度不足阈值的情况,推荐备选颜色色板中的颜色提升对比\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction improveContrastReverse(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n) {\n const alternativeColorPalletes: string[] = [];\n if (alternativeColors) {\n if (alternativeColors instanceof Array) {\n alternativeColorPalletes.push(...alternativeColors);\n } else {\n alternativeColorPalletes.push(alternativeColors);\n }\n }\n alternativeColorPalletes.push(...defaultAlternativeColors);\n for (const alternativeColor of alternativeColorPalletes) {\n if (foregroundColor === alternativeColor) {\n continue;\n }\n if (contrastAccessibilityChecker(alternativeColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return alternativeColor;\n }\n }\n return undefined;\n}\n\n/**\n * 颜色对比度可行性检查 https://webaim.org/articles/contrast/\n * - WCAG 2.0 AA 级要求普通文本的对比度至少为 4.5:1,大文本的对比度至少为 3:1。(目前按照此标准)\n * - WCAG 2.1 要求图形和用户界面组件(例如表单输入边框)的对比度至少为 3:1。\n * - WCAG AAA 级要求普通文本的对比度至少为 7:1,大文本的对比度至少为 4.5:1。\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nexport function contrastAccessibilityChecker(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number\n): boolean {\n //Contrast ratios can range from 1 to 21\n if (contrastRatiosThreshold) {\n if (contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold) {\n return true;\n }\n return false;\n } else if (textType === 'largeText') {\n if (contrastRatios(foregroundColor, backgroundColor) > 3) {\n return true;\n }\n return false;\n }\n if (contrastRatios(foregroundColor, backgroundColor) > 4.5) {\n return true;\n }\n return false;\n}\n\n/**\n * 计算颜色对比度 https://webaim.org/articles/contrast/\n * Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).\n * (L1 + 0.05) / (L2 + 0.05), whereby:\n * L1 is the relative luminance of the lighter of the colors, and\n * L2 is the relative luminance of the darker of the colors.\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction contrastRatios(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined): number {\n const foregroundColorLuminance = getColorLuminance(foregroundColor as string);\n const backgroundColorLuminance = getColorLuminance(backgroundColor as string);\n const L1 = foregroundColorLuminance > backgroundColorLuminance ? foregroundColorLuminance : backgroundColorLuminance;\n const L2 = foregroundColorLuminance > backgroundColorLuminance ? backgroundColorLuminance : foregroundColorLuminance;\n const contrastRatios = (L1 + 0.05) / (L2 + 0.05);\n return contrastRatios;\n}\n\n/**\n * 计算相对亮度 https://webaim.org/articles/contrast/\n * the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white\n * Note 1: For the sRGB colorspace, the relative luminance of a color is defined as\n * L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:\n * if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4\n * if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4\n * if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4\n * and RsRGB, GsRGB, and BsRGB are defined as:\n * RsRGB = R8bit/255\n * GsRGB = G8bit/255\n * BsRGB = B8bit/255\n * @param color\n * @returns\n */\nfunction getColorLuminance(color: string): number {\n const rgb8bit = ColorUtil.hexToRgb(color);\n const RsRGB = rgb8bit[0] / 255;\n const GsRGB = rgb8bit[1] / 255;\n const BsRGB = rgb8bit[2] / 255;\n let R;\n let G;\n let B;\n if (RsRGB <= 0.03928) {\n R = RsRGB / 12.92;\n } else {\n R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);\n }\n if (GsRGB <= 0.03928) {\n G = GsRGB / 12.92;\n } else {\n G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);\n }\n if (BsRGB <= 0.03928) {\n B = BsRGB / 12.92;\n } else {\n B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);\n }\n const L = 0.2126 * R + 0.7152 * G + 0.0722 * B;\n return L;\n}\n\n/**\n * 规范化color格式为hex\n * 当color为颜色名称或rgb时,对其进行规范化处理\n * @param originColor\n * @returns\n */\nfunction formatColorToHex(originColor: IColor | undefined) {\n if ((originColor as string)?.includes('#')) {\n return originColor;\n }\n const c = new ColorUtil.Color(originColor as string);\n const { r, g, b } = c.color;\n return '#' + ColorUtil.rgbToHex(r, g, b);\n}\n\nexport function smartInvertStrategy(\n fillStrategy: string,\n baseColor: IColor,\n invertColor: IColor,\n similarColor: IColor\n) {\n let result;\n switch (fillStrategy) {\n case 'base':\n result = baseColor;\n break;\n case 'invertBase':\n result = invertColor;\n break;\n case 'similarBase':\n result = similarColor;\n default:\n break;\n }\n return result;\n}\n"]}
1
+ {"version":3,"sources":["util/labelSmartInvert.ts"],"names":[],"mappings":";;;AACA,6CAA6C;AAE7C,MAAM,wBAAwB,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAQlE,SAAgB,gBAAgB,CAC9B,qBAAyC,EACzC,qBAAyC,EACzC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC;IAErC,MAAM,eAAe,GAAG,gB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,GAAG,KAAK,CAAC;KACnB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;KACnB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;KACnB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAQD,SAAS,gBAAgB,CAAC,WAA+B;IACvD,IAAK,WAAsB,aAAtB,WAAW,uBAAX,WAAW,CAAa,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,CAAC,GAAG,IAAI,kBAAS,CAAC,KAAK,CAAC,WAAqB,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IAC5B,OAAO,GAAG,GAAG,kBAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","file":"labelSmartInvert.js","sourcesContent":["import type { IColor } from '@visactor/vrender';\nimport { ColorUtil } from '@visactor/vutils';\n\nconst defaultAlternativeColors: string[] = ['#ffffff', '#000000'];\n\n/**\n * 标签智能反色\n * @param foregroundColorOrigin\n * @param backgroundColorOrogin\n * @returns\n */\nexport function labelSmartInvert(\n foregroundColorOrigin: IColor | undefined,\n backgroundColorOrogin: IColor | undefined,\n textType?: string | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n): IColor | undefined {\n const foregroundColor = formatColorToHex(foregroundColorOrigin);\n const backgroundColor = formatColorToHex(backgroundColorOrogin);\n if (!contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return improveContrastReverse(\n foregroundColor,\n backgroundColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors\n );\n }\n return foregroundColor;\n}\n\n/**\n * 提升对比度\n * 对于对比度不足阈值的情况,推荐备选颜色色板中的颜色提升对比\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction improveContrastReverse(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n) {\n const alternativeColorPalletes: string[] = [];\n if (alternativeColors) {\n if (alternativeColors instanceof Array) {\n alternativeColorPalletes.push(...alternativeColors);\n } else {\n alternativeColorPalletes.push(alternativeColors);\n }\n }\n alternativeColorPalletes.push(...defaultAlternativeColors);\n for (const alternativeColor of alternativeColorPalletes) {\n if (foregroundColor === alternativeColor) {\n continue;\n }\n if (contrastAccessibilityChecker(alternativeColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return alternativeColor;\n }\n }\n return undefined;\n}\n\n/**\n * 颜色对比度可行性检查 https://webaim.org/articles/contrast/\n * - WCAG 2.0 AA 级要求普通文本的对比度至少为 4.5:1,大文本的对比度至少为 3:1。(目前按照此标准)\n * - WCAG 2.1 要求图形和用户界面组件(例如表单输入边框)的对比度至少为 3:1。\n * - WCAG AAA 级要求普通文本的对比度至少为 7:1,大文本的对比度至少为 4.5:1。\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nexport function contrastAccessibilityChecker(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number\n): boolean {\n //Contrast ratios can range from 1 to 21\n if (contrastRatiosThreshold) {\n if (contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold) {\n return true;\n }\n return false;\n } else if (textType === 'largeText') {\n if (contrastRatios(foregroundColor, backgroundColor) > 3) {\n return true;\n }\n return false;\n }\n if (contrastRatios(foregroundColor, backgroundColor) > 4.5) {\n return true;\n }\n return false;\n}\n\n/**\n * 计算颜色对比度 https://webaim.org/articles/contrast/\n * Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).\n * (L1 + 0.05) / (L2 + 0.05), whereby:\n * L1 is the relative luminance of the lighter of the colors, and\n * L2 is the relative luminance of the darker of the colors.\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction contrastRatios(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined): number {\n const foregroundColorLuminance = getColorLuminance(foregroundColor as string);\n const backgroundColorLuminance = getColorLuminance(backgroundColor as string);\n const L1 = foregroundColorLuminance > backgroundColorLuminance ? foregroundColorLuminance : backgroundColorLuminance;\n const L2 = foregroundColorLuminance > backgroundColorLuminance ? backgroundColorLuminance : foregroundColorLuminance;\n const contrastRatios = (L1 + 0.05) / (L2 + 0.05);\n return contrastRatios;\n}\n\n/**\n * 计算相对亮度 https://webaim.org/articles/contrast/\n * the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white\n * Note 1: For the sRGB colorspace, the relative luminance of a color is defined as\n * L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:\n * if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4\n * if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4\n * if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4\n * and RsRGB, GsRGB, and BsRGB are defined as:\n * RsRGB = R8bit/255\n * GsRGB = G8bit/255\n * BsRGB = B8bit/255\n * @param color\n * @returns\n */\nfunction getColorLuminance(color: string): number {\n const rgb8bit = ColorUtil.hexToRgb(color);\n const RsRGB = rgb8bit[0] / 255;\n const GsRGB = rgb8bit[1] / 255;\n const BsRGB = rgb8bit[2] / 255;\n let R;\n let G;\n let B;\n if (RsRGB <= 0.03928) {\n R = RsRGB / 12.92;\n } else {\n R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);\n }\n if (GsRGB <= 0.03928) {\n G = GsRGB / 12.92;\n } else {\n G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);\n }\n if (BsRGB <= 0.03928) {\n B = BsRGB / 12.92;\n } else {\n B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);\n }\n const L = 0.2126 * R + 0.7152 * G + 0.0722 * B;\n return L;\n}\n\n/**\n * 规范化color格式为hex\n * 当color为颜色名称或rgb时,对其进行规范化处理\n * @param originColor\n * @returns\n */\nfunction formatColorToHex(originColor: IColor | undefined) {\n if ((originColor as string)?.includes('#')) {\n return originColor;\n }\n const c = new ColorUtil.Color(originColor as string);\n const { r, g, b } = c.color;\n return '#' + ColorUtil.rgbToHex(r, g, b);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  export type Vector2 = [number, number];
2
- export declare function scale(vector: Vector2, scale: number): number[];
2
+ export declare function scale(vector: Vector2, scale: number): [number, number];
3
3
  export declare function length(vector: Vector2): number;
4
4
  export declare function normalize(vector: Vector2): number[];
5
5
  export declare function angle(vector1: Vector2, vector2: Vector2): number;
@@ -1 +1 @@
1
- {"version":3,"sources":["util/matrix.ts"],"names":[],"mappings":";;;AAKA,SAAgB,KAAK,CAAC,MAAe,EAAE,KAAa;IAClD,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AAChD,CAAC;AAFD,sBAEC;AAKD,SAAgB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AgB,SAAS,CAAC,EAAY,EAAE,EAAY;IAClD,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,8BAEC;AAQD,SAAgB,OAAO,CAAC,EAAoB,EAAE,EAAoB,EAAE,MAAe;IACjF,MAAM,GAAG,GAAG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1B,MAAM,gBAAgB,GAAG,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,MAAM,EAAE;QACV,IAAI,gBAAgB,EAAE;YACpB,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;SAC1B;QACD,OAAO,GAAG,CAAC;KACZ;IAED,IAAI,gBAAgB,EAAE;QACpB,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3B,CAAC;AAdD,0BAcC","file":"matrix.js","sourcesContent":["export type Vector2 = [number, number];\n\n/**\n * Scales a vec2 by a scalar number\n */\nexport function scale(vector: Vector2, scale: number) {\n return [vector[0] * scale, vector[1] * scale];\n}\n\n/**\n * Calculates the length of a vec2\n */\nexport function length(vector: Vector2) {\n const [x, y] = vector;\n return Math.sqrt(x * x + y * y);\n}\n\n/**\n * Normalize a vec2\n */\nexport function normalize(vector: Vector2) {\n const [x, y] = vector;\n let len = x * x + y * y;\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n }\n return [vector[0] * len, vector[1] * len];\n}\n\n/**\n * Get the angle between two 2D vectors\n */\nexport function angle(vector1: Vector2, vector2: Vector2) {\n const [x1, y1] = vector1;\n const [x2, y2] = vector2;\n const mag = Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2));\n const cosine = mag && (x1 * x2 + y1 * y2) / mag;\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n\n/**\n * 向量 v1 到 向量 v2 夹角的方向\n * @param {Array} v1 向量\n * @param {Array} v2 向量\n * @return {Boolean} >= 0 顺时针 < 0 逆时针\n */\nexport function direction(v1: number[], v2: number[]): number {\n return v1[0] * v2[1] - v2[0] * v1[1];\n}\n\n/**\n * 二维向量 v1 到 v2 的夹角\n * @param v1\n * @param v2\n * @param direct\n */\nexport function angleTo(v1: [number, number], v2: [number, number], direct: boolean): number {\n const ang = angle(v1, v2);\n const angleLargeThanPI = direction(v1, v2) >= 0;\n if (direct) {\n if (angleLargeThanPI) {\n return Math.PI * 2 - ang;\n }\n return ang;\n }\n\n if (angleLargeThanPI) {\n return ang;\n }\n return Math.PI * 2 - ang;\n}\n"]}
1
+ {"version":3,"sources":["util/matrix.ts"],"names":[],"mappings":";;;AAKA,SAAgB,KAAK,CAAC,MAAe,EAAE,KAAa;IAClD,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AAChD,CAAC;AAFD,sBAEC;AAKD,SAAgB,MAAM,CAAC,MAAe;IACpC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;IACtB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAClC,CAAC;AAHD,wBAGC;AAKD,SAAgB,SAAS,CAAC,MAAe;IACvC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;IACtB,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,GAAG,GAAG,CAAC,EAAE;QACX,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GA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ACD,OAAO,GAAG,CAAC;KACZ;IAED,IAAI,gBAAgB,EAAE;QACpB,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3B,CAAC;AAdD,0BAcC","file":"matrix.js","sourcesContent":["export type Vector2 = [number, number];\n\n/**\n * Scales a vec2 by a scalar number\n */\nexport function scale(vector: Vector2, scale: number): [number, number] {\n return [vector[0] * scale, vector[1] * scale];\n}\n\n/**\n * Calculates the length of a vec2\n */\nexport function length(vector: Vector2) {\n const [x, y] = vector;\n return Math.sqrt(x * x + y * y);\n}\n\n/**\n * Normalize a vec2\n */\nexport function normalize(vector: Vector2) {\n const [x, y] = vector;\n let len = x * x + y * y;\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n }\n return [vector[0] * len, vector[1] * len];\n}\n\n/**\n * Get the angle between two 2D vectors\n */\nexport function angle(vector1: Vector2, vector2: Vector2) {\n const [x1, y1] = vector1;\n const [x2, y2] = vector2;\n const mag = Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2));\n const cosine = mag && (x1 * x2 + y1 * y2) / mag;\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n\n/**\n * 向量 v1 到 向量 v2 夹角的方向\n * @param {Array} v1 向量\n * @param {Array} v2 向量\n * @return {Boolean} >= 0 顺时针 < 0 逆时针\n */\nexport function direction(v1: number[], v2: number[]): number {\n return v1[0] * v2[1] - v2[0] * v1[1];\n}\n\n/**\n * 二维向量 v1 到 v2 的夹角\n * @param v1\n * @param v2\n * @param direct\n */\nexport function angleTo(v1: [number, number], v2: [number, number], direct: boolean): number {\n const ang = angle(v1, v2);\n const angleLargeThanPI = direction(v1, v2) >= 0;\n if (direct) {\n if (angleLargeThanPI) {\n return Math.PI * 2 - ang;\n }\n return ang;\n }\n\n if (angleLargeThanPI) {\n return ang;\n }\n return Math.PI * 2 - ang;\n}\n"]}