diff --git a/packages/plots/CHANGELOG.md b/packages/plots/CHANGELOG.md index 18e698683..cc7c9f259 100644 --- a/packages/plots/CHANGELOG.md +++ b/packages/plots/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.1.3 + +`2023-12-12` + +- 💄 代码逻辑优化 +- 🐞 修复 DualAxes Annotations 配置展示异常 + + ## 2.1.2 `2023-12-12` diff --git a/packages/plots/package.json b/packages/plots/package.json index 0d4d60cf9..1b9ffa41d 100644 --- a/packages/plots/package.json +++ b/packages/plots/package.json @@ -1,6 +1,6 @@ { "name": "@ant-design/plots", - "version": "2.1.2", + "version": "2.1.3", "description": "G2Plot Statistical chart", "bugs": { "url": "https://github.com/ant-design/ant-design-charts/issues" diff --git a/packages/plots/src/core/annotation/controller.ts b/packages/plots/src/core/annotation/controller.ts deleted file mode 100644 index f2199bfbe..000000000 --- a/packages/plots/src/core/annotation/controller.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Chart } from '@antv/g2'; -import { ANNOTATION_LIST } from '../constants'; -import { Annotaion } from '.'; - -export class Controller { - public chart: Chart; - public config: T; - public container: Map = new Map(); - - constructor(chart: Chart, config: T) { - this.chart = chart; - this.config = config; - this.init(); - } - - init() { - ANNOTATION_LIST.forEach((annotation) => { - const { key, shape } = annotation; - const annotationOptions = this.config[key]; - if (annotationOptions) { - const annotationInstance = new Annotaion[shape](this.chart, annotationOptions); - const { canvas } = this.chart.getContext(); - canvas.appendChild(annotationInstance); - this.container.set(key, annotationInstance); - } else { - this.container.get(key)?.clear(); - } - }); - } - /** - * Update annotaions - */ - update() { - if (!this.container.size) return; - ANNOTATION_LIST.forEach((annotation) => { - const { key } = annotation; - const annotationInstance = this.container.get(key); - annotationInstance?.update(); - }); - } -} diff --git a/packages/plots/src/core/annotation/core.ts b/packages/plots/src/core/annotation/core.ts index a438127fa..d3c0ef742 100644 --- a/packages/plots/src/core/annotation/core.ts +++ b/packages/plots/src/core/annotation/core.ts @@ -21,41 +21,42 @@ export abstract class Annotaion> extends CustomEle attributeChangedCallback(name: Key): void {} + public update(attr?: Partial, animate?: GenericAnimation) { + this.attr(mergeWithArrayCoverage({}, this.attributes, attr || {})); + return this.render?.(this.attributes as Required, this, animate); + } + + public clear() { + this.removeChildren(); + } + + public abstract render( + attributes: Required, + container: Group, + animate?: GenericAnimation, + ): void | AnimationResult[]; + public getElementsLayout() { const { canvas } = this.chart.getContext(); const elements = canvas.document.getElementsByClassName('element'); const elementsLayout = []; elements.forEach((element) => { - // @ts-ignore + //@ts-expect-error const bbox = element.getBBox(); const { x, y, width, height } = bbox; + const data = element['__data__']; elementsLayout.push({ bbox, x, y, width, height, - key: element['__data__'].key, - data: element['__data__'], + key: data.key, + data, }); }); return elementsLayout; } - public update(attr?: Partial, animate?: GenericAnimation) { - this.attr(mergeWithArrayCoverage({}, this.attributes, attr || {})); - return this.render?.(this.attributes as Required, this, animate); - } - - public clear() { - this.removeChildren(); - } - - public abstract render( - attributes: Required, - container: Group, - animate?: GenericAnimation, - ): void | AnimationResult[]; - public bindEvents(attributes: T, container: Group): void {} } diff --git a/packages/plots/src/core/annotation/index.ts b/packages/plots/src/core/annotation/index.ts index 21f4df76c..26cbff211 100644 --- a/packages/plots/src/core/annotation/index.ts +++ b/packages/plots/src/core/annotation/index.ts @@ -1,5 +1,44 @@ +import { Chart } from '@antv/g2'; +import { ANNOTATION_LIST } from '../constants'; import { ConversionTag } from './conversion-tag'; import { BidirectionalBarAxisText } from './bidirectional-bar-axis-text'; -export { Controller } from './controller'; -export const Annotaion = { ConversionTag, BidirectionalBarAxisText }; +const Annotaion = { ConversionTag, BidirectionalBarAxisText }; + +export class Controller { + public chart: Chart; + public config: T; + public container: Map = new Map(); + + constructor(chart: Chart, config: T) { + this.chart = chart; + this.config = config; + this.init(); + } + + init() { + ANNOTATION_LIST.forEach((annotation) => { + const { key, shape } = annotation; + const annotationOptions = this.config[key]; + if (annotationOptions) { + const annotationInstance = new Annotaion[shape](this.chart, annotationOptions); + const { canvas } = this.chart.getContext(); + canvas.appendChild(annotationInstance); + this.container.set(key, annotationInstance); + } else { + this.container.get(key)?.clear(); + } + }); + } + /** + * Update annotaions + */ + update() { + if (!this.container.size) return; + ANNOTATION_LIST.forEach((annotation) => { + const { key } = annotation; + const annotationInstance = this.container.get(key); + annotationInstance?.update(); + }); + } +} diff --git a/packages/util/package.json b/packages/util/package.json index 9408a6e17..46d07a7f9 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@ant-design/charts-util", - "version": "0.0.1-alpha.4", + "version": "0.0.1-alpha.5", "description": "charts utils", "bugs": { "url": "https://github.com/ant-design/ant-design-charts/issues"