@visactor/vrender-components 0.17.0-alpha.2 → 0.17.0-alpha.4

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 (81) hide show
  1. package/cjs/data-zoom/config.d.ts +0 -6
  2. package/cjs/data-zoom/config.js +1 -7
  3. package/cjs/data-zoom/config.js.map +1 -1
  4. package/cjs/data-zoom/data-zoom.d.ts +3 -2
  5. package/cjs/data-zoom/data-zoom.js +19 -15
  6. package/cjs/data-zoom/data-zoom.js.map +1 -1
  7. package/cjs/data-zoom/type.d.ts +6 -0
  8. package/cjs/data-zoom/type.js +6 -1
  9. package/cjs/data-zoom/type.js.map +1 -1
  10. package/cjs/index.d.ts +1 -1
  11. package/cjs/index.js +1 -1
  12. package/cjs/index.js.map +1 -1
  13. package/cjs/label/animate/animate.d.ts +8 -2
  14. package/cjs/label/animate/animate.js +37 -3
  15. package/cjs/label/animate/animate.js.map +1 -1
  16. package/cjs/label/area.d.ts +15 -0
  17. package/cjs/label/area.js +41 -0
  18. package/cjs/label/area.js.map +1 -0
  19. package/cjs/label/base.d.ts +7 -4
  20. package/cjs/label/base.js +37 -42
  21. package/cjs/label/base.js.map +1 -1
  22. package/cjs/label/dataLabel.js +8 -5
  23. package/cjs/label/dataLabel.js.map +1 -1
  24. package/cjs/label/line.d.ts +1 -1
  25. package/cjs/label/line.js +2 -9
  26. package/cjs/label/line.js.map +1 -1
  27. package/cjs/label/type.d.ts +22 -2
  28. package/cjs/label/type.js +1 -2
  29. package/cjs/label/type.js.map +1 -1
  30. package/cjs/label/util.d.ts +4 -0
  31. package/cjs/label/util.js +14 -2
  32. package/cjs/label/util.js.map +1 -1
  33. package/cjs/legend/discrete/discrete.d.ts +3 -0
  34. package/cjs/legend/discrete/discrete.js +45 -38
  35. package/cjs/legend/discrete/discrete.js.map +1 -1
  36. package/cjs/legend/discrete/type.d.ts +1 -0
  37. package/cjs/legend/discrete/type.js.map +1 -1
  38. package/cjs/link-path/type.js +1 -1
  39. package/cjs/scrollbar/scrollbar.js.map +1 -1
  40. package/dist/index.js +699 -562
  41. package/dist/index.min.js +1 -1
  42. package/es/data-zoom/config.d.ts +0 -6
  43. package/es/data-zoom/config.js +0 -7
  44. package/es/data-zoom/config.js.map +1 -1
  45. package/es/data-zoom/data-zoom.d.ts +3 -2
  46. package/es/data-zoom/data-zoom.js +10 -4
  47. package/es/data-zoom/data-zoom.js.map +1 -1
  48. package/es/data-zoom/type.d.ts +6 -0
  49. package/es/data-zoom/type.js +6 -1
  50. package/es/data-zoom/type.js.map +1 -1
  51. package/es/index.d.ts +1 -1
  52. package/es/index.js +1 -1
  53. package/es/index.js.map +1 -1
  54. package/es/label/animate/animate.d.ts +8 -2
  55. package/es/label/animate/animate.js +35 -0
  56. package/es/label/animate/animate.js.map +1 -1
  57. package/es/label/area.d.ts +15 -0
  58. package/es/label/area.js +39 -0
  59. package/es/label/area.js.map +1 -0
  60. package/es/label/base.d.ts +7 -4
  61. package/es/label/base.js +39 -44
  62. package/es/label/base.js.map +1 -1
  63. package/es/label/dataLabel.js +11 -4
  64. package/es/label/dataLabel.js.map +1 -1
  65. package/es/label/line.d.ts +1 -1
  66. package/es/label/line.js +3 -8
  67. package/es/label/line.js.map +1 -1
  68. package/es/label/type.d.ts +22 -2
  69. package/es/label/type.js +1 -2
  70. package/es/label/type.js.map +1 -1
  71. package/es/label/util.d.ts +4 -0
  72. package/es/label/util.js +13 -1
  73. package/es/label/util.js.map +1 -1
  74. package/es/legend/discrete/discrete.d.ts +3 -0
  75. package/es/legend/discrete/discrete.js +44 -36
  76. package/es/legend/discrete/discrete.js.map +1 -1
  77. package/es/legend/discrete/type.d.ts +1 -0
  78. package/es/legend/discrete/type.js.map +1 -1
  79. package/es/link-path/type.js +1 -1
  80. package/es/scrollbar/scrollbar.js.map +1 -1
  81. package/package.json +8 -8
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.DataLabel = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), base_1 = require("../core/base"), overlap_1 = require("./overlap"), rect_1 = require("./rect"), symbol_1 = require("./symbol"), arc_1 = require("./arc"), base_2 = require("./base"), line_data_1 = require("./line-data"), labelComponentMap = {
7
+ const vutils_1 = require("@visactor/vutils"), base_1 = require("../core/base"), overlap_1 = require("./overlap"), rect_1 = require("./rect"), symbol_1 = require("./symbol"), arc_1 = require("./arc"), base_2 = require("./base"), line_data_1 = require("./line-data"), line_1 = require("./line"), area_1 = require("./area"), labelComponentMap = {
8
8
  rect: rect_1.RectLabel,
9
9
  symbol: symbol_1.SymbolLabel,
10
10
  arc: arc_1.ArcLabel,
11
+ line: line_1.LineLabel,
12
+ area: area_1.AreaLabel,
11
13
  "line-data": line_data_1.LineDataLabel
12
14
  };
13
15
 
@@ -17,6 +19,7 @@ class DataLabel extends base_1.AbstractComponent {
17
19
  this.name = "data-label";
18
20
  }
19
21
  render() {
22
+ var _a;
20
23
  const {dataLabels: dataLabels, size: size} = this.attribute;
21
24
  if (!dataLabels || 0 === dataLabels.length) return;
22
25
  const {width: width = 0, height: height = 0} = size || {};
@@ -26,12 +29,12 @@ class DataLabel extends base_1.AbstractComponent {
26
29
  for (let i = 0; i < dataLabels.length; i++) {
27
30
  const dataLabel = dataLabels[i], labelComponent = labelComponentMap[dataLabel.type] || base_2.LabelBase;
28
31
  if (labelComponent) {
29
- const {baseMarkGroupName: baseMarkGroupName} = dataLabel;
30
- let component = this._componentMap.get(baseMarkGroupName);
32
+ const {baseMarkGroupName: baseMarkGroupName, type: type} = dataLabel, id = null !== (_a = dataLabel.id) && void 0 !== _a ? _a : `${baseMarkGroupName}-${type}-${i}`;
33
+ let component = this._componentMap.get(id);
31
34
  component ? (component.setBitmapTool(tool), component.setBitmap(bitmap), component.setAttributes(dataLabel),
32
- currentComponentMap.set(baseMarkGroupName, component)) : (component = new labelComponent(dataLabel),
35
+ currentComponentMap.set(id, component)) : (component = new labelComponent(dataLabel),
33
36
  component.setBitmap(bitmap), component.setBitmapTool(tool), this.add(component),
34
- currentComponentMap.set(baseMarkGroupName, component));
37
+ currentComponentMap.set(id, component));
35
38
  }
36
39
  }
37
40
  prevComponentMap.forEach(((cp, key) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/label/dataLabel.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAExD,uCAAiD;AAEjD,uCAAuC;AACvC,iCAAmC;AACnC,qCAAuC;AACvC,+BAAiC;AAGjC,iCAAiD;AACjD,2CAA4C;AAG5C,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,gBAAS;IACf,MAAM,EAAE,oBAAW;IACnB,GAAG,EAAE,cAAQ;IACb,WAAW,EAAE,yBAAa;CAC3B,CAAC;AAEF,MAAa,SAAU,SAAQ,wBAAiC;IAS9D,YAAY,UAA0B,EAAE,OAA0B;QAChE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAThG,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;YAC1C,OAAO;SACR;QACD,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;QAE7C,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAA,sBAAa,EAAC,MAAM,GAAG,KAAK,CAAC,EAAE;YACvD,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,IAAI,CAAC,aAAa,GAAG,IAAI,GA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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;;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-core';\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';\nimport { LineDataLabel } from './line-data';\nimport type { ComponentOptions } from '../interface';\n\nconst labelComponentMap = {\n rect: RectLabel,\n symbol: SymbolLabel,\n arc: ArcLabel,\n 'line-data': LineDataLabel\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, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : 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":["../src/label/dataLabel.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAExD,uCAAiD;AAEjD,uCAAuC;AACvC,iCAAmC;AACnC,qCAAuC;AACvC,+BAAiC;AAGjC,iCAAiD;AACjD,2CAA4C;AAC5C,iCAAmC;AACnC,iCAAmC;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C;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;;AA/EH,8BAgFC;AA3EgB,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-core';\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';\nimport { LineDataLabel } from './line-data';\nimport { LineLabel } from './line';\nimport { AreaLabel } from './area';\nimport type { ComponentOptions } from '../interface';\n\nconst labelComponentMap = {\n rect: RectLabel,\n symbol: SymbolLabel,\n arc: ArcLabel,\n line: LineLabel,\n area: AreaLabel,\n 'line-data': LineDataLabel\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, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : 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, type } = dataLabel;\n const id = dataLabel.id ?? `${baseMarkGroupName}-${type}-${i}`;\n\n let component = this._componentMap.get(id);\n if (component) {\n component.setBitmapTool(tool);\n component.setBitmap(bitmap);\n component.setAttributes(dataLabel);\n currentComponentMap.set(id, 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(id, 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"]}
@@ -9,7 +9,7 @@ export declare class LineLabel extends LabelBase<LineLabelAttrs> {
9
9
  static defaultAttributes: Partial<LineLabelAttrs>;
10
10
  constructor(attributes: LineLabelAttrs, options?: ComponentOptions);
11
11
  protected getGraphicBounds(graphic: ILine, point?: Partial<PointLocationCfg>): IBoundsLike;
12
- protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: LineLabelAttrs['position'], offset?: number): {
12
+ protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: string, offset?: number): {
13
13
  x: number;
14
14
  y: number;
15
15
  };
package/cjs/label/line.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.LineLabel = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), base_1 = require("./base");
7
+ const vutils_1 = require("@visactor/vutils"), base_1 = require("./base"), util_1 = require("./util");
8
8
 
9
9
  class LineLabel extends base_1.LabelBase {
10
10
  constructor(attributes, options) {
@@ -23,14 +23,7 @@ class LineLabel extends base_1.LabelBase {
23
23
  };
24
24
  }
25
25
  labeling(textBounds, graphicBounds, position = "end", offset = 0) {
26
- if (!textBounds || !graphicBounds) return;
27
- const {x1: x1, x2: x2} = textBounds, width = Math.abs(x2 - x1), anchorX = graphicBounds.x1;
28
- let x = anchorX;
29
- return "end" === position ? x = anchorX + width / 2 + offset : "start" === position && (x = anchorX - width / 2 - offset),
30
- {
31
- x: x,
32
- y: graphicBounds.y1
33
- };
26
+ return (0, util_1.labelingLineOrArea)(textBounds, graphicBounds, position, offset);
34
27
  }
35
28
  }
36
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/label/line.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAIzC,iCAAmC;AAGnC,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,UAA0B,EAAE,OAA0B;QAChE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAhBhG,SAAI,GAAG,YAAY,CAAC;IAiBpB,CAAC;IAES,gBAAgB,CAAC,OAAc,EAAE,QAAmC,EAAE;;QAC9E,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO,KAAK,CA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AE;YAC/B,CAAC,GAAG,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC;SAClC;QAED,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;;AA7DH,8BA8DC;AA3DQ,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":"line.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { ILine } from '@visactor/vrender-core';\nimport type { PointLocationCfg } from '../core/type';\nimport type { LineLabelAttrs } from './type';\nimport { LabelBase } from './base';\nimport type { ComponentOptions } from '../interface';\n\nexport class LineLabel extends LabelBase<LineLabelAttrs> {\n name = 'line-label';\n\n static defaultAttributes: Partial<LineLabelAttrs> = {\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: 'end',\n offset: 6,\n pickable: false\n };\n\n constructor(attributes: LineLabelAttrs, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, LineLabel.defaultAttributes, attributes));\n }\n\n protected getGraphicBounds(graphic: ILine, point: Partial<PointLocationCfg> = {}) {\n if (graphic.type !== 'line') {\n return super.getGraphicBounds(graphic, point);\n }\n const { position = 'end' } = this.attribute;\n const points = graphic?.attribute?.points || [point];\n const index = position === 'start' ? 0 : points.length - 1;\n return {\n x1: points[index].x as number,\n x2: points[index].x as number,\n y1: points[index].y as number,\n y2: points[index].y as number\n };\n }\n\n protected labeling(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position: LineLabelAttrs['position'] = 'end',\n offset = 0\n ) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, x2 } = textBounds;\n const width = Math.abs(x2 - x1);\n\n const anchorX = graphicBounds.x1;\n const anchorY = graphicBounds.y1;\n\n let x = anchorX;\n const y = anchorY;\n\n if (position === 'end') {\n x = anchorX + width / 2 + offset;\n } else if (position === 'start') {\n x = anchorX - width / 2 - offset;\n }\n\n return { x, y };\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/label/line.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAIzC,iCAAmC;AACnC,iCAA4C;AAG5C,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,UAA0B,EAAE,OAA0B;QAChE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAhBhG,SAAI,GAAG,YAAY,CAAC;IAiBpB,CAAC;IAES,gBAAgB,CAAC,OAAc,EAAE,QAAmC,EAAE;;QAC9E,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC/C;QACD,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,MAAM,MAAM,GAAG,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,MAAM,KAAI,CAAC,KAAK,CAAC,CAAC;QACrD,MAAM,KAAK,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3D,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAW;YAC7B,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAW;YAC7B,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAW;YAC7B,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAW;SAC9B,CAAC;IACJ,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,WAAmB,KAAK,EAAE,MAAM,GAAG,CAAC;QAC1G,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzE,CAAC;;AArCH,8BAsCC;AAnCQ,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":"line.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { ILine } from '@visactor/vrender-core';\nimport type { PointLocationCfg } from '../core/type';\nimport type { LineLabelAttrs } from './type';\nimport { LabelBase } from './base';\nimport { labelingLineOrArea } from './util';\nimport type { ComponentOptions } from '../interface';\n\nexport class LineLabel extends LabelBase<LineLabelAttrs> {\n name = 'line-label';\n\n static defaultAttributes: Partial<LineLabelAttrs> = {\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: 'end',\n offset: 6,\n pickable: false\n };\n\n constructor(attributes: LineLabelAttrs, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, LineLabel.defaultAttributes, attributes));\n }\n\n protected getGraphicBounds(graphic: ILine, point: Partial<PointLocationCfg> = {}) {\n if (graphic.type !== 'line') {\n return super.getGraphicBounds(graphic, point);\n }\n const { position = 'end' } = this.attribute;\n const points = graphic?.attribute?.points || [point];\n const index = position === 'start' ? 0 : points.length - 1;\n return {\n x1: points[index].x as number,\n x2: points[index].x as number,\n y1: points[index].y as number,\n y2: points[index].y as number\n };\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position: string = 'end', offset = 0) {\n return labelingLineOrArea(textBounds, graphicBounds, position, offset);\n }\n}\n"]}
@@ -28,10 +28,14 @@ export interface BaseLabelAttrs extends IGroupGraphicAttribute {
28
28
  overlap?: OverlapAttrs | false;
29
29
  smartInvert?: SmartInvertAttrs | false;
30
30
  animation?: ILabelAnimation | false;
31
+ animationEnter?: ILabelUpdateAnimation;
32
+ animationUpdate?: ILabelUpdateAnimation | ILabelUpdateChannelAnimation[];
33
+ animationExit?: ILabelExitAnimation;
31
34
  dataFilter?: (data: LabelItem[]) => LabelItem[];
32
35
  customLayoutFunc?: (data: LabelItem[], getRelatedGraphic: (data: LabelItem) => IGraphic, getRelatedPoint?: (data: LabelItem) => IPointLike) => Text[];
33
36
  customOverlapFunc?: (label: Text[], getRelatedGraphic: (data: LabelItem) => IGraphic, getRelatedPoint?: (data: LabelItem) => IPointLike) => Text[];
34
37
  disableTriggerEvent?: boolean;
38
+ id?: string;
35
39
  }
36
40
  export interface OverlapAttrs {
37
41
  size?: {
@@ -85,6 +89,10 @@ export interface LineLabelAttrs extends BaseLabelAttrs {
85
89
  type: 'line';
86
90
  position?: Functional<'start' | 'end'>;
87
91
  }
92
+ export interface AreaLabelAttrs extends BaseLabelAttrs {
93
+ type: 'area';
94
+ position?: Functional<'start' | 'end'>;
95
+ }
88
96
  export interface LineDataLabelAttrs extends BaseLabelAttrs {
89
97
  type: 'line-data';
90
98
  position?: Functional<'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'>;
@@ -136,13 +144,25 @@ export interface DataLabelAttrs extends IGroupGraphicAttribute {
136
144
  };
137
145
  }
138
146
  export type Functional<T> = T | ((data: any) => T);
139
- export interface ILabelAnimation {
140
- mode?: 'same-time' | 'after' | 'after-all';
147
+ export interface ILabelExitAnimation {
141
148
  duration?: number;
142
149
  delay?: number;
143
150
  easing?: EasingType;
151
+ }
152
+ export interface ILabelEnterAnimation extends ILabelExitAnimation {
153
+ mode?: 'same-time' | 'after' | 'after-all';
154
+ }
155
+ export interface ILabelUpdateAnimation extends ILabelExitAnimation {
144
156
  increaseEffect?: boolean;
145
157
  }
158
+ export interface ILabelUpdateChannelAnimation extends ILabelUpdateAnimation {
159
+ channel?: string[];
160
+ options?: {
161
+ excludeChannels?: string[];
162
+ };
163
+ }
164
+ export interface ILabelAnimation extends ILabelEnterAnimation, ILabelExitAnimation, ILabelUpdateAnimation {
165
+ }
146
166
  export interface IPoint {
147
167
  x: number;
148
168
  y: number;
package/cjs/label/type.js CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- });
6
- //# sourceMappingURL=type.js.map
5
+ });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/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 ILineGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { IPointLike } from '@visactor/vutils';\n\nexport type LabelItemStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n [key: string]: 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 * @hack not recommend to use\n * @returns\n */\n getBaseMarks?: () => IGraphic[];\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 labelLineState?: LabelItemStateStyle<ILineGraphicAttribute>;\n\n syncState?: boolean;\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?: (\n data: LabelItem[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n */\n customOverlapFunc?: (\n label: Text[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n /**\n * 关闭交互效果\n * @default false\n */\n disableTriggerEvent?: boolean;\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(不执行智能反色,保持fill设置的颜色)\n * @default 'invertBase'\n */\n fillStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * strokeStrategy的四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持stroke设置的颜色)\n * @default 'base'\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 * label超出mark范围,也以mark作为背景色进行反色\n */\n outsideEnable?: boolean;\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'\n | 'bottom'\n | 'left'\n | 'right'\n | 'inside'\n | 'inside-top'\n | 'inside-bottom'\n | 'inside-right'\n | 'inside-left'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-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 LineDataLabelAttrs extends BaseLabelAttrs {\n type: 'line-data';\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 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' | 'inside-inner' | 'inside-outer'>;\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 offsetAngle?: number;\n /**\n * 标签相对于 `outerRadius` 的径向偏移,目前仅作用于 inside 标签\n */\n offsetRadius?: 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 * 是否显示引导线\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 * 引导线是否光滑\n * @default false\n */\n smooth?: boolean;\n /**\n * 引导线样式\n */\n style?: Partial<ILineGraphicAttribute>;\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 | LineDataLabelAttrs)[];\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":["../src/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 ILineGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { IPointLike } from '@visactor/vutils';\n\nexport type LabelItemStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n [key: string]: 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 * @hack not recommend to use\n * @returns\n */\n getBaseMarks?: () => IGraphic[];\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 labelLineState?: LabelItemStateStyle<ILineGraphicAttribute>;\n\n syncState?: boolean;\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 animationEnter?: ILabelUpdateAnimation;\n animationUpdate?: ILabelUpdateAnimation | ILabelUpdateChannelAnimation[];\n animationExit?: ILabelExitAnimation;\n\n // 排序 or 删减\n dataFilter?: (data: LabelItem[]) => LabelItem[];\n\n /** 自定义布局函数\n * @description 当配置了 customLayoutFunc 后,默认布局逻辑将不再生效。(position/offset不生效)\n */\n customLayoutFunc?: (\n data: LabelItem[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n */\n customOverlapFunc?: (\n label: Text[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n /**\n * 关闭交互效果\n * @default false\n */\n disableTriggerEvent?: boolean;\n /** 唯一标志符 */\n id?: string;\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(不执行智能反色,保持fill设置的颜色)\n * @default 'invertBase'\n */\n fillStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * strokeStrategy的四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持stroke设置的颜色)\n * @default 'base'\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 * label超出mark范围,也以mark作为背景色进行反色\n */\n outsideEnable?: boolean;\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'\n | 'bottom'\n | 'left'\n | 'right'\n | 'inside'\n | 'inside-top'\n | 'inside-bottom'\n | 'inside-right'\n | 'inside-left'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-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 AreaLabelAttrs extends BaseLabelAttrs {\n type: 'area';\n /**\n * 标签位置\n * @default 'end'\n */\n position?: Functional<'start' | 'end'>;\n}\n\nexport interface LineDataLabelAttrs extends BaseLabelAttrs {\n type: 'line-data';\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 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' | 'inside-inner' | 'inside-outer'>;\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 offsetAngle?: number;\n /**\n * 标签相对于 `outerRadius` 的径向偏移,目前仅作用于 inside 标签\n */\n offsetRadius?: 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 * 是否显示引导线\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 * 引导线是否光滑\n * @default false\n */\n smooth?: boolean;\n /**\n * 引导线样式\n */\n style?: Partial<ILineGraphicAttribute>;\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 | LineDataLabelAttrs)[];\n /**\n * 防重叠的区域大小\n */\n size: { width: number; height: number };\n}\n\nexport type Functional<T> = T | ((data: any) => T);\n\nexport interface ILabelExitAnimation {\n duration?: number;\n delay?: number;\n easing?: EasingType;\n}\n\nexport interface ILabelEnterAnimation extends ILabelExitAnimation {\n mode?: 'same-time' | 'after' | 'after-all';\n}\n\nexport interface ILabelUpdateAnimation extends ILabelExitAnimation {\n /** 是否开启 increaseCount 动画\n * @default true\n */\n increaseEffect?: boolean;\n}\n\nexport interface ILabelUpdateChannelAnimation extends ILabelUpdateAnimation {\n channel?: string[];\n options?: { excludeChannels?: string[] };\n}\n\nexport interface ILabelAnimation extends ILabelEnterAnimation, ILabelExitAnimation, ILabelUpdateAnimation {}\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"]}
@@ -16,3 +16,7 @@ export declare const labelingPoint: (textBounds: IBoundsLike, graphicBounds: IBo
16
16
  y: number;
17
17
  };
18
18
  export declare const getPointsOfLineArea: (graphic: ILine | IArea) => IPointLike[];
19
+ export declare function labelingLineOrArea(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: string, offset?: number): {
20
+ x: number;
21
+ y: number;
22
+ };
package/cjs/label/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.getPointsOfLineArea = exports.labelingPoint = exports.degrees = exports.checkBoundsOverlap = exports.connectLineRadian = exports.lineCirclePoints = exports.isQuadrantRight = exports.isQuadrantLeft = exports.normalizeAngle = exports.computeQuadrant = exports.circlePoint = exports.polarToCartesian = void 0;
5
+ }), exports.labelingLineOrArea = exports.getPointsOfLineArea = exports.labelingPoint = exports.degrees = exports.checkBoundsOverlap = exports.connectLineRadian = exports.lineCirclePoints = exports.isQuadrantRight = exports.isQuadrantLeft = exports.normalizeAngle = exports.computeQuadrant = exports.circlePoint = exports.polarToCartesian = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils");
8
8
 
@@ -171,4 +171,16 @@ const getPointsOfLineArea = graphic => {
171
171
  return points;
172
172
  };
173
173
 
174
- exports.getPointsOfLineArea = getPointsOfLineArea;
174
+ function labelingLineOrArea(textBounds, graphicBounds, position = "end", offset = 0) {
175
+ if (!textBounds || !graphicBounds) return;
176
+ const {x1: x1, x2: x2} = textBounds, width = Math.abs(x2 - x1), anchorX = graphicBounds.x1;
177
+ let x = anchorX;
178
+ return "end" === position ? x = anchorX + width / 2 + offset : "start" === position && (x = anchorX - width / 2 - offset),
179
+ {
180
+ x: x,
181
+ y: graphicBounds.y1
182
+ };
183
+ }
184
+
185
+ exports.getPointsOfLineArea = getPointsOfLineArea, exports.labelingLineOrArea = labelingLineOrArea;
186
+ //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/label/util.ts"],"names":[],"mappings":";;;AAGA,6CAAiE;AAOjE,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACvB;IACD,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;QACvC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AARD,4CAQC;AASD,SAAgB,WAAW,CAAC,EAAU,EAAE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C,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE3E,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC;AA1DW,QAAA,aAAa,iBA0DxB;AAEK,MAAM,mBAAmB,GAAG,CAAC,OAAsB,EAAgB,EAAE;IAC1E,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;QAClC,OAAO,EAAE,CAAC;KACX;IAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAE/C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC/B,MAAM,GAAG,GAAiB,EAAE,CAAC;QAE7B,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACrB,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;YAE7B,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACxB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;KACZ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAtBW,QAAA,mBAAmB,uBAsB9B","file":"util.js","sourcesContent":["import type { IArea, IAreaSegment, ILine, ISegment } from '@visactor/vrender-core';\nimport type { IPolarPoint, IPoint, Quadrant } from './type';\nimport type { IBoundsLike, IPointLike } from '@visactor/vutils';\nimport { radianToDegree, isValidNumber } from '@visactor/vutils';\n\n/**\n * 极坐标系 -> 直角坐标系\n * @param point\n * @returns\n */\nexport function polarToCartesian(point: IPolarPoint): IPoint {\n if (!point.radius) {\n return { x: 0, y: 0 };\n }\n return {\n x: Math.cos(point.angle) * point.radius,\n y: Math.sin(point.angle) * point.radius\n };\n}\n\n/**\n * 计算圆弧上的点坐标\n * @param x0 圆心 x 坐标\n * @param y0 圆心 y 坐标\n * @param radius 圆弧半径\n * @param radian 点所在弧度\n */\nexport function circlePoint(x0: number, y0: number, radius: number, radian: number): IPoint {\n const offset = polarToCartesian({\n radius,\n angle: radian\n });\n return {\n x: x0 + offset.x,\n y: y0 + offset.y\n };\n}\n\n/**\n * 根据角度计算象限\n * 计算角度所在象限\n * @param angle\n * @returns\n */\nexport function computeQuadrant(angle: number): Quadrant {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\n/**\n * 角度标准化处理\n * @param angle 弧度角\n */\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function isQuadrantLeft(quadrant: Quadrant): boolean {\n return quadrant === 3 || quadrant === 4;\n}\n\nexport function isQuadrantRight(quadrant: Quadrant): boolean {\n return quadrant === 1 || quadrant === 2;\n}\n\n/**\n * 计算直线与圆交点\n * 直线方程:ax + by + c = 0\n * 圆方程:(x - x0)^2 + (y - y0)^2 = r^2\n */\nexport function lineCirclePoints(a: number, b: number, c: number, x0: number, y0: number, r: number): IPoint[] {\n if ((a === 0 && b === 0) || r <= 0) {\n return [];\n }\n if (a === 0) {\n const y1 = -c / b;\n const fy = (y1 - y0) ** 2;\n const fd = r ** 2 - fy;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x0, y: y1 }];\n }\n const x1 = Math.sqrt(fd) + x0;\n const x2 = -Math.sqrt(fd) + x0;\n return [\n { x: x1, y: y1 },\n { x: x2, y: y1 }\n ];\n } else if (b === 0) {\n const x1 = -c / a;\n const fx = (x1 - x0) ** 2;\n const fd = r ** 2 - fx;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x1, y: y0 }];\n }\n const y1 = Math.sqrt(fd) + y0;\n const y2 = -Math.sqrt(fd) + y0;\n return [\n { x: x1, y: y1 },\n { x: x1, y: y2 }\n ];\n }\n const fa = (b / a) ** 2 + 1;\n const fb = 2 * ((c / a + x0) * (b / a) - y0);\n const fc = (c / a + x0) ** 2 + y0 ** 2 - r ** 2;\n const fd = fb ** 2 - 4 * fa * fc;\n if (fd < 0) {\n return [];\n }\n const y1 = (-fb + Math.sqrt(fd)) / (2 * fa);\n const y2 = (-fb - Math.sqrt(fd)) / (2 * fa);\n const x1 = -(b * y1 + c) / a;\n const x2 = -(b * y2 + c) / a;\n if (fd === 0) {\n return [{ x: x1, y: y1 }];\n }\n return [\n { x: x1, y: y1 },\n { x: x2, y: y2 }\n ];\n}\n\n/**\n * 根据圆弧两点连接线长度计算弧度\n * @param radius 圆弧半径\n * @param length 连接线长度\n */\nexport function connectLineRadian(radius: number, length: number) {\n if (length > radius * 2) {\n return NaN;\n }\n return Math.asin(length / 2 / radius) * 2;\n}\n\nexport function checkBoundsOverlap(boundsA: IBoundsLike, boundsB: IBoundsLike): boolean {\n const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = boundsA;\n const { x1: bx1, y1: by1, x2: bx2, y2: by2 } = boundsB;\n return !(\n (ax1 <= bx1 && ax2 <= bx1) ||\n (ax1 >= bx2 && ax2 >= bx2) ||\n (ay1 <= by1 && ay2 <= by1) ||\n (ay1 >= by2 && ay2 >= by2)\n );\n}\n\nexport const degrees = (angle?: number) => {\n if (!isValidNumber(angle)) {\n return null;\n }\n return radianToDegree(angle);\n};\n\nexport const labelingPoint = (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\nexport const getPointsOfLineArea = (graphic: ILine | IArea): IPointLike[] => {\n if (!graphic || !graphic.attribute) {\n return [];\n }\n\n const { points, segments } = graphic.attribute;\n\n if (segments && segments.length) {\n const res: IPointLike[] = [];\n\n segments.forEach(seg => {\n const segPoints = seg.points;\n\n segPoints.forEach(point => {\n res.push(point);\n });\n });\n\n return res;\n }\n\n return points;\n};\n"]}
1
+ {"version":3,"sources":["../src/label/util.ts"],"names":[],"mappings":";;;AAGA,6CAAiE;AAOjE,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACvB;IACD,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;QACvC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAA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AM,OAAO,GAAG,aAAa,CAAC,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,CAAC;IAEjC,IAAI,CAAC,GAAG,OAAO,CAAC;IAChB,MAAM,CAAC,GAAG,OAAO,CAAC;IAElB,IAAI,QAAQ,KAAK,KAAK,EAAE;QACtB,CAAC,GAAG,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC;KAClC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE;QAC/B,CAAC,GAAG,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC;KAClC;IAED,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC;AA1BD,gDA0BC","file":"util.js","sourcesContent":["import type { IArea, ILine } from '@visactor/vrender-core';\nimport type { IPolarPoint, IPoint, Quadrant } from './type';\nimport type { IBoundsLike, IPointLike } from '@visactor/vutils';\nimport { radianToDegree, isValidNumber } from '@visactor/vutils';\n\n/**\n * 极坐标系 -> 直角坐标系\n * @param point\n * @returns\n */\nexport function polarToCartesian(point: IPolarPoint): IPoint {\n if (!point.radius) {\n return { x: 0, y: 0 };\n }\n return {\n x: Math.cos(point.angle) * point.radius,\n y: Math.sin(point.angle) * point.radius\n };\n}\n\n/**\n * 计算圆弧上的点坐标\n * @param x0 圆心 x 坐标\n * @param y0 圆心 y 坐标\n * @param radius 圆弧半径\n * @param radian 点所在弧度\n */\nexport function circlePoint(x0: number, y0: number, radius: number, radian: number): IPoint {\n const offset = polarToCartesian({\n radius,\n angle: radian\n });\n return {\n x: x0 + offset.x,\n y: y0 + offset.y\n };\n}\n\n/**\n * 根据角度计算象限\n * 计算角度所在象限\n * @param angle\n * @returns\n */\nexport function computeQuadrant(angle: number): Quadrant {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\n/**\n * 角度标准化处理\n * @param angle 弧度角\n */\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function isQuadrantLeft(quadrant: Quadrant): boolean {\n return quadrant === 3 || quadrant === 4;\n}\n\nexport function isQuadrantRight(quadrant: Quadrant): boolean {\n return quadrant === 1 || quadrant === 2;\n}\n\n/**\n * 计算直线与圆交点\n * 直线方程:ax + by + c = 0\n * 圆方程:(x - x0)^2 + (y - y0)^2 = r^2\n */\nexport function lineCirclePoints(a: number, b: number, c: number, x0: number, y0: number, r: number): IPoint[] {\n if ((a === 0 && b === 0) || r <= 0) {\n return [];\n }\n if (a === 0) {\n const y1 = -c / b;\n const fy = (y1 - y0) ** 2;\n const fd = r ** 2 - fy;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x0, y: y1 }];\n }\n const x1 = Math.sqrt(fd) + x0;\n const x2 = -Math.sqrt(fd) + x0;\n return [\n { x: x1, y: y1 },\n { x: x2, y: y1 }\n ];\n } else if (b === 0) {\n const x1 = -c / a;\n const fx = (x1 - x0) ** 2;\n const fd = r ** 2 - fx;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x1, y: y0 }];\n }\n const y1 = Math.sqrt(fd) + y0;\n const y2 = -Math.sqrt(fd) + y0;\n return [\n { x: x1, y: y1 },\n { x: x1, y: y2 }\n ];\n }\n const fa = (b / a) ** 2 + 1;\n const fb = 2 * ((c / a + x0) * (b / a) - y0);\n const fc = (c / a + x0) ** 2 + y0 ** 2 - r ** 2;\n const fd = fb ** 2 - 4 * fa * fc;\n if (fd < 0) {\n return [];\n }\n const y1 = (-fb + Math.sqrt(fd)) / (2 * fa);\n const y2 = (-fb - Math.sqrt(fd)) / (2 * fa);\n const x1 = -(b * y1 + c) / a;\n const x2 = -(b * y2 + c) / a;\n if (fd === 0) {\n return [{ x: x1, y: y1 }];\n }\n return [\n { x: x1, y: y1 },\n { x: x2, y: y2 }\n ];\n}\n\n/**\n * 根据圆弧两点连接线长度计算弧度\n * @param radius 圆弧半径\n * @param length 连接线长度\n */\nexport function connectLineRadian(radius: number, length: number) {\n if (length > radius * 2) {\n return NaN;\n }\n return Math.asin(length / 2 / radius) * 2;\n}\n\nexport function checkBoundsOverlap(boundsA: IBoundsLike, boundsB: IBoundsLike): boolean {\n const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = boundsA;\n const { x1: bx1, y1: by1, x2: bx2, y2: by2 } = boundsB;\n return !(\n (ax1 <= bx1 && ax2 <= bx1) ||\n (ax1 >= bx2 && ax2 >= bx2) ||\n (ay1 <= by1 && ay2 <= by1) ||\n (ay1 >= by2 && ay2 >= by2)\n );\n}\n\nexport const degrees = (angle?: number) => {\n if (!isValidNumber(angle)) {\n return null;\n }\n return radianToDegree(angle);\n};\n\nexport const labelingPoint = (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\nexport const getPointsOfLineArea = (graphic: ILine | IArea): IPointLike[] => {\n if (!graphic || !graphic.attribute) {\n return [];\n }\n\n const { points, segments } = graphic.attribute;\n\n if (segments && segments.length) {\n const res: IPointLike[] = [];\n\n segments.forEach(seg => {\n const segPoints = seg.points;\n\n segPoints.forEach(point => {\n res.push(point);\n });\n });\n\n return res;\n }\n\n return points;\n};\n\nexport function labelingLineOrArea(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position: string = 'end',\n offset = 0\n) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, x2 } = textBounds;\n const width = Math.abs(x2 - x1);\n\n const anchorX = graphicBounds.x1;\n const anchorY = graphicBounds.y1;\n\n let x = anchorX;\n const y = anchorY;\n\n if (position === 'end') {\n x = anchorX + width / 2 + offset;\n } else if (position === 'start') {\n x = anchorX - width / 2 - offset;\n }\n\n return { x, y };\n}\n"]}
@@ -9,6 +9,7 @@ export declare class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
9
9
  private _itemHeight;
10
10
  private _itemMaxWidth;
11
11
  private _pager;
12
+ private _lastActiveItem;
12
13
  static defaultAttributes: Partial<DiscreteLegendAttrs>;
13
14
  constructor(attributes: DiscreteLegendAttrs, options?: ComponentOptions);
14
15
  setSelected(selectedData: (string | number)[]): void;
@@ -19,6 +20,8 @@ export declare class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
19
20
  private _onHover;
20
21
  private _onUnHover;
21
22
  private _onClick;
23
+ private _hover;
24
+ private _unHover;
22
25
  private _setLegendItemState;
23
26
  private _removeLegendItemState;
24
27
  private _getSelectedLegends;
@@ -31,26 +31,14 @@ class DiscreteLegend extends base_1.LegendBase {
31
31
  const target = e.target;
32
32
  if (null === (_a = null == target ? void 0 : target.name) || void 0 === _a ? void 0 : _a.startsWith(constant_1.LEGEND_ELEMENT_NAME.item)) {
33
33
  const legendItem = target.delegate;
34
- legendItem.hasState(constant_1.LegendStateValue.selected) ? this._setLegendItemState(legendItem, constant_1.LegendStateValue.selectedHover, e) : this._setLegendItemState(legendItem, constant_1.LegendStateValue.unSelectedHover, e);
35
- const focusButton = legendItem.getChildren()[0].find((node => node.name === constant_1.LEGEND_ELEMENT_NAME.focus), !1);
36
- focusButton && focusButton.setAttribute("visible", !0), this._dispatchEvent(constant_1.LegendEvent.legendItemHover, legendItem, e);
37
- }
34
+ if (this._lastActiveItem) {
35
+ if (this._lastActiveItem.id === legendItem.id) return;
36
+ this._unHover(this._lastActiveItem, e);
37
+ }
38
+ this._hover(legendItem, e);
39
+ } else this._lastActiveItem && (this._unHover(this._lastActiveItem, e), this._lastActiveItem = null);
38
40
  }, this._onUnHover = e => {
39
- var _a;
40
- const target = e.target;
41
- if (null === (_a = null == target ? void 0 : target.name) || void 0 === _a ? void 0 : _a.startsWith(constant_1.LEGEND_ELEMENT_NAME.item)) {
42
- const legendItem = target.delegate;
43
- let attributeUpdate = !1;
44
- (legendItem.hasState(constant_1.LegendStateValue.unSelectedHover) || legendItem.hasState(constant_1.LegendStateValue.selectedHover)) && (attributeUpdate = !0),
45
- legendItem.removeState(constant_1.LegendStateValue.unSelectedHover), legendItem.removeState(constant_1.LegendStateValue.selectedHover),
46
- legendItem.getChildren()[0].getChildren().forEach((child => {
47
- attributeUpdate || !child.hasState(constant_1.LegendStateValue.unSelectedHover) && !child.hasState(constant_1.LegendStateValue.selectedHover) || (attributeUpdate = !0),
48
- child.removeState(constant_1.LegendStateValue.unSelectedHover), child.removeState(constant_1.LegendStateValue.selectedHover);
49
- }));
50
- const focusButton = legendItem.getChildren()[0].find((node => node.name === constant_1.LEGEND_ELEMENT_NAME.focus), !1);
51
- focusButton && focusButton.setAttribute("visible", !1), attributeUpdate && this._dispatchEvent(constant_1.LegendEvent.legendItemAttributeUpdate, legendItem, e),
52
- this._dispatchEvent(constant_1.LegendEvent.legendItemUnHover, legendItem, e);
53
- }
41
+ this._lastActiveItem && (this._unHover(this._lastActiveItem, e), this._lastActiveItem = null);
54
42
  }, this._onClick = e => {
55
43
  var _a, _b, _c, _d, _e;
56
44
  const target = e.target;
@@ -137,7 +125,7 @@ class DiscreteLegend extends base_1.LegendBase {
137
125
  if (this.attribute.disableTriggerEvent) return;
138
126
  if (!this._itemsContainer) return;
139
127
  const {hover: hover = !0, select: select = !0} = this.attribute;
140
- hover && (this._itemsContainer.addEventListener("pointermove", this._onHover), this._itemsContainer.addEventListener("pointerout", this._onUnHover)),
128
+ hover && (this._itemsContainer.addEventListener("pointermove", this._onHover), this._itemsContainer.addEventListener("pointerleave", this._onUnHover)),
141
129
  select && this._itemsContainer.addEventListener("pointerdown", this._onClick);
142
130
  }
143
131
  _renderEachItem(item, isSelected, index, items) {
@@ -156,30 +144,31 @@ class DiscreteLegend extends base_1.LegendBase {
156
144
  x: 0,
157
145
  y: 0
158
146
  }, null == background ? void 0 : background.style)), this._appendDataToShape(itemGroup, constant_1.LEGEND_ELEMENT_NAME.item, item, itemGroup, null == background ? void 0 : background.state)),
159
- itemGroup.addState(isSelected ? constant_1.LegendStateValue.selected : constant_1.LegendStateValue.unSelected);
147
+ itemGroup.id = `${null != id ? id : label}-${index}`, itemGroup.addState(isSelected ? constant_1.LegendStateValue.selected : constant_1.LegendStateValue.unSelected);
160
148
  const innerGroup = (0, vrender_core_1.createGroup)({
161
149
  x: 0,
162
150
  y: 0,
163
151
  pickable: !1
164
152
  });
165
153
  itemGroup.add(innerGroup);
166
- let focusStartX = 0;
167
- const shapeSize = (0, vutils_1.get)(shapeAttr, "style.size", constant_1.DEFAULT_SHAPE_SIZE), shapeSpace = (0,
168
- vutils_1.get)(shapeAttr, "space", constant_1.DEFAULT_SHAPE_SPACE), itemShape = (0,
169
- vrender_core_1.createSymbol)(Object.assign(Object.assign({
170
- x: 0,
171
- y: 0,
172
- symbolType: "circle",
173
- strokeBoundsBuffer: 0
174
- }, shape), shapeAttr.style));
175
- let focusShape;
176
- Object.keys(shapeAttr.state || {}).forEach((key => {
177
- const color = shapeAttr.state[key].fill || shapeAttr.state[key].stroke;
178
- shape.fill && (0, vutils_1.isNil)(shapeAttr.state[key].fill) && color && (shapeAttr.state[key].fill = color),
179
- shape.stroke && (0, vutils_1.isNil)(shapeAttr.state[key].stroke) && color && (shapeAttr.state[key].stroke = color);
180
- })), this._appendDataToShape(itemShape, constant_1.LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, null == shapeAttr ? void 0 : shapeAttr.state),
181
- itemShape.addState(isSelected ? constant_1.LegendStateValue.selected : constant_1.LegendStateValue.unSelected),
182
- innerGroup.add(itemShape);
154
+ let focusShape, focusStartX = 0, shapeSize = 0, shapeSpace = 0;
155
+ if (!1 !== (null == shapeAttr ? void 0 : shapeAttr.visible)) {
156
+ shapeSize = (0, vutils_1.get)(shapeAttr, "style.size", constant_1.DEFAULT_SHAPE_SIZE),
157
+ shapeSpace = (0, vutils_1.get)(shapeAttr, "space", constant_1.DEFAULT_SHAPE_SPACE);
158
+ const itemShape = (0, vrender_core_1.createSymbol)(Object.assign(Object.assign({
159
+ x: 0,
160
+ y: 0,
161
+ symbolType: "circle",
162
+ strokeBoundsBuffer: 0
163
+ }, shape), shapeAttr.style));
164
+ Object.keys(shapeAttr.state || {}).forEach((key => {
165
+ const color = shapeAttr.state[key].fill || shapeAttr.state[key].stroke;
166
+ shape.fill && (0, vutils_1.isNil)(shapeAttr.state[key].fill) && color && (shapeAttr.state[key].fill = color),
167
+ shape.stroke && (0, vutils_1.isNil)(shapeAttr.state[key].stroke) && color && (shapeAttr.state[key].stroke = color);
168
+ })), this._appendDataToShape(itemShape, constant_1.LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, null == shapeAttr ? void 0 : shapeAttr.state),
169
+ itemShape.addState(isSelected ? constant_1.LegendStateValue.selected : constant_1.LegendStateValue.unSelected),
170
+ innerGroup.add(itemShape);
171
+ }
183
172
  let focusSpace = 0;
184
173
  if (focus) {
185
174
  const focusSize = (0, vutils_1.get)(focusIconStyle, "size", constant_1.DEFAULT_SHAPE_SIZE);
@@ -310,6 +299,24 @@ class DiscreteLegend extends base_1.LegendBase {
310
299
  return this._pager.addEventListener("toPrev", onPaging), this._pager.addEventListener("toNext", onPaging),
311
300
  !0;
312
301
  }
302
+ _hover(legendItem, e) {
303
+ this._lastActiveItem = legendItem;
304
+ legendItem.hasState(constant_1.LegendStateValue.selected) ? this._setLegendItemState(legendItem, constant_1.LegendStateValue.selectedHover, e) : this._setLegendItemState(legendItem, constant_1.LegendStateValue.unSelectedHover, e);
305
+ const focusButton = legendItem.getChildren()[0].find((node => node.name === constant_1.LEGEND_ELEMENT_NAME.focus), !1);
306
+ focusButton && focusButton.setAttribute("visible", !0), this._dispatchEvent(constant_1.LegendEvent.legendItemHover, legendItem, e);
307
+ }
308
+ _unHover(legendItem, e) {
309
+ let attributeUpdate = !1;
310
+ (legendItem.hasState(constant_1.LegendStateValue.unSelectedHover) || legendItem.hasState(constant_1.LegendStateValue.selectedHover)) && (attributeUpdate = !0),
311
+ legendItem.removeState(constant_1.LegendStateValue.unSelectedHover), legendItem.removeState(constant_1.LegendStateValue.selectedHover),
312
+ legendItem.getChildren()[0].getChildren().forEach((child => {
313
+ attributeUpdate || !child.hasState(constant_1.LegendStateValue.unSelectedHover) && !child.hasState(constant_1.LegendStateValue.selectedHover) || (attributeUpdate = !0),
314
+ child.removeState(constant_1.LegendStateValue.unSelectedHover), child.removeState(constant_1.LegendStateValue.selectedHover);
315
+ }));
316
+ const focusButton = legendItem.getChildren()[0].find((node => node.name === constant_1.LEGEND_ELEMENT_NAME.focus), !1);
317
+ focusButton && focusButton.setAttribute("visible", !1), attributeUpdate && this._dispatchEvent(constant_1.LegendEvent.legendItemAttributeUpdate, legendItem, e),
318
+ this._dispatchEvent(constant_1.LegendEvent.legendItemUnHover, legendItem, e);
319
+ }
313
320
  _setLegendItemState(legendItem, stateName, e) {
314
321
  let attributeUpdate = !1;
315
322
  legendItem.hasState(stateName) || (attributeUpdate = !0), legendItem.addState(stateName, true),