NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@antv/g2/esm/geometry/base.d.ts

707 lines
22 KiB
TypeScript
Raw Normal View History

2023-09-14 14:47:11 +08:00
import { Adjust } from '@antv/adjust';
import { Attribute } from '@antv/attr';
import Base from '../base';
import { BBox, Coordinate, IGroup, IShape, Scale } from '../dependents';
import { AdjustOption, AnimateOption, AttributeOption, ColorAttrCallback, Data, Datum, GeometryLabelCfg, GeometryTooltipOption, LabelCallback, LabelOption, LooseObject, MappingDatum, ScaleOption, ShapeAttrCallback, ShapeFactory, ShapeInfo, ShapeMarkerCfg, ShapePoint, SizeAttrCallback, StateOption, StyleCallback, StyleOption, TooltipCallback } from '../interface';
import Element from './element';
/** geometry.init() 传入参数 */
export interface InitCfg {
/** 坐标系 */
coordinate?: Coordinate;
/** 数据 */
data?: Data;
/** 主题对象 */
theme?: LooseObject;
/** 列定义 */
scaleDefs?: Record<string, ScaleOption>;
/** 因为数据使用的引用,所以需要有一个标识位标识数据是否发生了更新 */
isDataChanged?: boolean;
isCoordinateChanged?: boolean;
}
/** Geometry 构造函数参数 */
export interface GeometryCfg {
/** Geometry shape 的容器。 */
container: IGroup;
/** 绘制的坐标系对象。 */
coordinate?: Coordinate;
/** 绘制数据。 */
data?: Data;
/** 需要的 scales。 */
scales?: Record<string, Scale>;
/** 列定义 */
scaleDefs?: Record<string, ScaleOption>;
/** Geometry labels 的容器 */
labelsContainer?: IGroup;
/** 是否对数据进行排序 */
sortable?: boolean;
/** 是否可见 */
visible?: boolean;
/** 主题配置 */
theme?: LooseObject;
}
/**
* Geometry
*/
export default class Geometry extends Base {
/** Geometry 几何标记类型。 */
readonly type: string;
/** ShapeFactory 对应的类型。 */
readonly shapeType: string;
/** Coordinate 坐标系实例。 */
coordinate: Coordinate;
/** 用户绘制数据。 */
data: Data;
/** 图形绘制容器。 */
readonly container: IGroup;
/** label 绘制容器。 */
readonly labelsContainer: IGroup;
/** 是否对数据进行排序,默认为 false。 */
sortable: boolean;
/** 当前 Geometry 实例主题。 */
theme: LooseObject;
/** 存储 geometry 需要的 scales需要外部传入。 */
scales: Record<string, Scale>;
/** scale 定义,需要外部传入。 */
scaleDefs: Record<string, ScaleOption>;
/** 画布区域,用于 label 布局。 */
canvasRegion: BBox;
/** Attribute map */
attributes: Record<string, Attribute>;
/** Element map */
elements: Element[];
/**
*
* + init() updateData() , Data[]
* + paint() MappingDatum[][]
*/
dataArray: MappingDatum[][];
/** 存储 tooltip 配置信息。 */
tooltipOption: GeometryTooltipOption | boolean;
/** 存储 label 配置信息。 */
labelOption: LabelOption | false;
/** 状态量相关的配置项 */
stateOption: StateOption;
/** 使用 key-value 结构存储 Elementkey 为每个 Element 实例对应的唯一 ID */
elementsMap: Record<string, Element>;
/** animate 配置项 */
animateOption: AnimateOption | boolean;
/** 图形属性映射配置 */
protected attributeOption: Record<string, AttributeOption>;
/** adjust 配置项 */
protected adjustOption: AdjustOption[];
/** style 配置项 */
protected styleOption: StyleOption;
/** 每个 Geometry 对应的 Shape 工厂实例,用于创建各个 Shape */
protected shapeFactory: ShapeFactory;
/** 存储上一次渲染时的 element 映射表,用于更新逻辑 */
protected lastElementsMap: Record<string, Element>;
/** 是否生成多个点来绘制图形。 */
protected generatePoints: boolean;
/** 存储发生图形属性映射前的数据 */
protected beforeMappingData: Data[];
/** 存储每个 shape 的默认 size用于 Interval、Schema 几何标记 */
protected defaultSize: number;
private userTheme;
private adjusts;
private lastAttributeOption;
private idFields;
private geometryLabel;
/** 虚拟 Group用于图形更新 */
private offscreenGroup;
private groupScales;
private hasSorted;
protected isCoordinateChanged: boolean;
/**
* Geometry
* @param cfg
*/
constructor(cfg: GeometryCfg);
/**
* position
*
* @example
* ```typescript
* // 数据结构: [{ x: 'A', y: 10, color: 'red' }]
* geometry.position('x*y');
* geometry.position([ 'x', 'y' ]);
* geometry.position({
* fields: [ 'x', 'y' ],
* });
* ```
*
* @param cfg
* @returns
*/
position(cfg: string | string[] | AttributeOption): Geometry;
/**
* color
*
* @example
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
* geometry.color({
* fields: [ 'x' ],
* values: [ '#1890ff', '#5AD8A6' ],
* });
* ```
*
* @param field
* @returns
*/
color(field: AttributeOption): Geometry;
/**
* @example
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
*
* // 使用 '#1890ff' 颜色渲染图形
* geometry.color('#1890ff');
*
* // 根据 x 字段的数据值进行颜色的映射,这时候 G2 会在内部调用默认的回调函数,读取默认提供的颜色进行数据值到颜色值的映射。
* geometry.color('x');
*
* // 将 'x' 字段的数据值映射至指定的颜色值 colors可以是字符串也可以是数组此时用于通常映射分类数据
* geometry.color('x', [ '#1890ff', '#5AD8A6' ]);
*
* // 使用回调函数进行颜色值的自定义;可以使用多个字段使用、*号连接
* geometry.color('x', (xVal) => {
* if (xVal === 'a') {
* return 'red';
* }
* return 'blue';
* });
*
* // 指定颜色的渐变路径,用于映射连续的数据
* geometry.color('x', '#BAE7FF-#1890FF-#0050B3');
* ```
*
* @param field 使 '*'
* @param cfg Optional, color
* @returns
*/
color(field: string, cfg?: string | string[] | ColorAttrCallback): Geometry;
/**
* shape
*
* @example
*
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
* geometry.shape({
* fields: [ 'x' ],
* });
* ```
*
* @param field
* @returns
*/
shape(field: AttributeOption): Geometry;
/**
*
* @example
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
*
* // 指定常量,将所有数据值映射到固定的 shape
* geometry.shape('circle');
*
* // 将指定的字段映射到内置的 shapes 数组中
* geometry.shape('x');
*
* // 将指定的字段映射到指定的 shapes 数组中
* geometry.shape('x', [ 'circle', 'diamond', 'square' ]);
*
* // 使用回调函数获取 shape用于个性化的 shape 定制,可以根据单个或者多个字段确定
* geometry.shape('x', (xVal) => {
* if (xVal === 'a') {
* return 'circle';
* }
* return 'diamond';
* });
* ```
*
* @param field shape 使 '*'
* @param cfg Optional, shape
* @returns
*/
shape(field: string, cfg?: string[] | ShapeAttrCallback): Geometry;
/**
* size
*
* @example
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
* geometry.size({
* values: [ 10 ],
* })
* ```
*
* @param field
* @returns
*/
size(field: AttributeOption): Geometry;
/**
*
* @example
* ```typescript
* // data: [{ x: 'A', y: 10, color: 'red' }, { x: 'B', y: 30, color: 'yellow' }]
*
* // 直接指定像素大小
* geometry.size(10);
*
* // 指定映射到 size 的字段,使用内置的默认大小范围为 [1, 10]
* geometry.size('x');
*
* // 指定映射到 size 字段外,还提供了 size 的最大值和最小值范围
* geometry.size('x', [ 5, 30 ]);
*
* // 使用回调函数映射 size用于个性化的 size 定制,可以使用多个字段进行映射
* geometry.size('x', (xVal) => {
* if (xVal === 'a') {
* return 10;
* }
* return 5;
* });
* ```
*
* @param field size 使 '*'
* @param cfg Optional, size
* @returns
*/
size(field: number | string, cfg?: [number, number] | SizeAttrCallback): Geometry;
/**
* G2
* 1. dodge
* 2. stack
* 3. symmetric
* 4. jitter
*
*
* **Tip**
* + 'dodge' :
* ```typescript
* geometry.adjust('dodge', {
* marginRatio: 0, // 取 0 到 1 范围的值(相对于每个柱子宽度),用于控制一个分组中柱子之间的间距
* dodgeBy: 'x', // 该属性只对 'dodge' 类型生效,声明以哪个数据字段为分组依据
* });
* ```
*
* + 'stack' :
* ```typescript
* geometry.adjust('stack', {
* reverseOrder: false, // 用于控制是否对数据进行反序操作
* });
* ```
*
* @example
* ```typescript
* geometry.adjust('stack');
*
* geometry.adjust({
* type: 'stack',
* reverseOrder: false,
* });
*
* // 组合使用 adjust
* geometry.adjust([ 'stack', 'dodge' ]);
*
* geometry.adjust([
* { type: 'stack' },
* { type: 'dodge', dodgeBy: 'x' },
* ]);
* ```
*
* @param adjustCfg
* @returns
*/
adjust(adjustCfg: string | string[] | AdjustOption | AdjustOption[]): Geometry;
/**
*
*
* @example
* ```typescript
* // 配置图形样式
* style({
* lineWidth: 2,
* stroke: '#1890ff',
* });
*
* // 根据具体的数据进行详细配置
* style({
* fields: [ 'x', 'y' ], // 数据字段
* callback: (xVal, yVal) => {
* const style = { lineWidth: 2, stroke: '#1890ff' };
* if (xVal === 'a') {
* style.lineDash = [ 2, 2 ];
* }
* return style;
* },
* });
* ```
*
* @param field
* @returns
*/
style(field: StyleOption | LooseObject): Geometry;
/**
* @example
* ```typescript
* style('x*y', (xVal, yVal) => {
* const style = { lineWidth: 2, stroke: '#1890ff' };
* if (xVal === 'a') {
* style.lineDash = [ 2, 2 ];
* }
* return style;
* });
* ```
*
* @param field
* @param styleFunc Optional,
* @returns
*/
style(field: string, styleFunc: StyleCallback): Geometry;
/**
* Geometry tooltip
*
* `tooltip(false)` tooltip
* `tooltip(true)` tooltip
*
* Geometry tooltip 使 tooltip
*
* @example
* ```typescript
* // data: [{x: 'a', y: 10}]
* tooltip({
* fields: [ 'x' ],
* });
* ```
* ![](https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*268uQ50if60AAAAAAAAAAABkARQnAQ)
*
* ```typescript
* tooltip({
* fields: [ 'x', 'y' ],
* });
* ```
* ![](https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*A_ujSa8QhtcAAAAAAAAAAABkARQnAQ)
*
* tooltip()
*
* @example
* ```typescript
* chart.tooltip({
* itemTpl: '<li>{x}: {y}</li>',
* });
*
* chart.line()
* .position('x*y')
* .tooltip({
* fields: [ 'x', 'y' ],
* callback: (x, y) => {
* return {
* x,
* y,
* };
* },
* });
* ```
*
* chart.tooltip() itemTpl itemTpl
*
* @param field tooltip
* @returns
*/
tooltip(field: GeometryTooltipOption | boolean): Geometry;
/**
* @example
* ```typescript
* // data: [{x: 'a', y: 10}]
*
* // 等同于 tooltip({ fields: [ 'x' ] })
* tooltip('x');
*
* // 等同于 tooltip({ fields: [ 'x', 'y' ] })
* tooltip('x*y');
*
* // 等同于 tooltip({ fields: [ 'x', 'y' ], callback: (x, y) => { x, y } })
* tooltip('x*y', (x, y) => {
* return {
* x,
* y,
* };
* });
* ```
*
* @param field
* @param cfg Optional,
* @returns
*/
tooltip(field: string, cfg?: TooltipCallback): Geometry;
/**
* Geometry
*
* + `animate(false)`
* + `animate(true)`
*
*
* 1. appear: 图表第一次加载时的入场动画
* 2. enter: 图表绘制完成
* 3. update: 图表绘制完成
* 4. leave: 图表绘制完成
*
* @example
* ```typescript
* animate({
* enter: {
* duration: 1000, // enter 动画执行时间
* },
* leave: false, // 关闭 leave 销毁动画
* });
* ```
*
* @param cfg
* @returns
*/
animate(cfg: AnimateOption | boolean): Geometry;
/**
* Geometry label
*
* @example
* ```ts
* // data: [ {x: 1, y: 2, z: 'a'}, {x: 2, y: 2, z: 'b'} ]
* // 在每个图形上显示 z 字段对应的数值
* label({
* fields: [ 'z' ]
* });
*
* label(false); // 不展示 label
*
* // 在每个图形上显示 x 字段对应的数值,同时配置文本颜色为红色
* label('x', {
* style: {
* fill: 'red',
* },
* })
*
* // 以 type 类型的 label 渲染每个图形上显示 x 字段对应的数值,同时格式化文本内容
* label('x', (xValue) => {
* return {
* content: xValue + '%',
* };
* }, {
* type: 'base' // 声明 label 类型
* })
* ```
*
* @param field
* @returns label
*/
label(field: LabelOption | false | string): Geometry;
label(field: string, secondParam: GeometryLabelCfg | LabelCallback): Geometry;
label(field: string, secondParam: LabelCallback, thirdParam: GeometryLabelCfg): Geometry;
/**
*
*
* @example
* ```ts
* chart.interval().state({
* selected: {
* animate: { duration: 100, easing: 'easeLinear' },
* style: {
* lineWidth: 2,
* stroke: '#000',
* },
* },
* });
* ```
*
* shape shape G.Group group shape使
* group shape 'name' (shape.set('name', 'xx')) 'name' key shape key
*
* ```ts
* chart.interval().shape('groupShape').state({
* selected: {
* style: {
* 0: { lineWidth: 2 },
* 1: { fillOpacity: 1 },
* }
* }
* });
* ```
*
* @param cfg
*/
state(cfg: StateOption): this;
/**
* Geomtry
* [[Attribute]] and [[Scale]]
*/
init(cfg?: InitCfg): void;
/**
* Geometry
* @param [cfg]
*/
update(cfg?: InitCfg): void;
/**
*
*/
paint(isUpdate?: boolean): void;
/**
* Geometry
* @override
*/
clear(): void;
/**
* Geometry
*/
destroy(): void;
/**
* scale
* @returns
*/
getGroupScales(): Scale[];
/**
*
*/
getAttribute(name: string): Attribute;
/** 获取 x 轴对应的 scale 实例。 */
getXScale(): Scale;
/** 获取 y 轴对应的 scale 实例。 */
getYScale(): Scale;
/**
*
*/
getGroupAttributes(): Attribute[];
/** 获取图形属性默认的映射值。 */
getDefaultValue(attrName: string): any;
/**
* Attribute
* @param attr Attribute
* @param obj
* @returns
*/
getAttributeValues(attr: Attribute, obj: Datum): any[];
getAdjust(adjustType: string): Adjust;
/**
* shape marker
* @param shapeName shape
* @param cfg marker
* @returns
*/
getShapeMarker(shapeName: string, cfg: ShapeMarkerCfg): import("../interface").ShapeMarkerAttrs;
/**
* Geometry Elements
*
* ```typescript
* getElementsBy((element) => {
* const data = element.getData();
*
* return data.a === 'a';
* });
* ```
*
* @param condition
* @returns
*/
getElementsBy(condition: (element: Element) => boolean): Element[];
/**
* id
* @param data Element
* @returns
*/
getElementId(data: MappingDatum | MappingDatum[]): any;
/**
* scale
*/
getScaleFields(): string[];
/**
* geometry
* @param visible
*/
changeVisible(visible: boolean): void;
/**
* &
* @return fields string[]
*/
getGroupFields(): string[];
/**
* x y
*/
getXYFields(): string[];
/**
* Geometry shapes
* @returns shapes
*/
getShapes(): Array<IShape | IGroup>;
/**
* Group
* @returns
*/
getOffscreenGroup(): IGroup;
sort(mappingArray: Data[]): void;
/**
* Geometry Interval Y 0
*/
protected adjustScale(): void;
/**
* Geometry Shape
*/
protected getShapeFactory(): ShapeFactory;
/**
* Shape
* @param obj -> -> adjust
* @returns
*/
protected createShapePointsCfg(obj: Datum): ShapePoint;
/**
* Element
* @param mappingDatum Element
* @param [isUpdate]
* @returns element Element
*/
protected createElement(mappingDatum: MappingDatum, isUpdate?: boolean): Element;
/**
*
* @param mappingDatum
* @returns draw cfg
*/
protected getDrawCfg(mappingDatum: MappingDatum): ShapeInfo;
/**
* Elements
* @param mappingData
* @param [isUpdate]
* @returns elements
*/
protected createElements(mappingData: MappingDatum[], index: number, isUpdate?: boolean): Element[];
/**
* label
*/
protected getLabelType(): string;
/**
* Y
*/
protected getYMinValue(): number;
private createAttrOption;
private initAttributes;
private processData;
private adjustData;
private groupData;
private updateStackRange;
private beforeMapping;
private generateShapePoints;
private normalizeValues;
private mapping;
private convertPoint;
private getStyleCfg;
private setCfg;
private renderLabels;
/**
*
*
* 1.
* 2. geometry
* 3. appear
* 4. appear.animation
*/
private canDoGroupAnimation;
}