mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 03:38:20 +08:00
refactor: remove CallableValue type (#5903)
This commit is contained in:
parent
79bb790299
commit
760c98150c
@ -190,7 +190,6 @@ export type { CustomPluginOption } from './spec/plugin';
|
|||||||
export type { BaseTransformOptions } from './transforms';
|
export type { BaseTransformOptions } from './transforms';
|
||||||
export type {
|
export type {
|
||||||
BaseElementStyleProps,
|
BaseElementStyleProps,
|
||||||
CallableValue,
|
|
||||||
CardinalPlacement,
|
CardinalPlacement,
|
||||||
CollapsedMarkerStyleProps,
|
CollapsedMarkerStyleProps,
|
||||||
Combo,
|
Combo,
|
||||||
|
@ -7,7 +7,7 @@ import type { ContourStyleProps } from '../elements/shapes';
|
|||||||
import { Contour } from '../elements/shapes';
|
import { Contour } from '../elements/shapes';
|
||||||
import type { Graph } from '../runtime/graph';
|
import type { Graph } from '../runtime/graph';
|
||||||
import type { RuntimeContext } from '../runtime/types';
|
import type { RuntimeContext } from '../runtime/types';
|
||||||
import type { CallableValue, ID } from '../types';
|
import type { ID } from '../types';
|
||||||
import { getBBoxHeight, getBBoxWidth } from '../utils/bbox';
|
import { getBBoxHeight, getBBoxWidth } from '../utils/bbox';
|
||||||
import { arrayDiff } from '../utils/diff';
|
import { arrayDiff } from '../utils/diff';
|
||||||
import type { ElementLifeCycleEvent } from '../utils/event';
|
import type { ElementLifeCycleEvent } from '../utils/event';
|
||||||
@ -225,7 +225,7 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|||||||
* <en/> Update member elements
|
* <en/> Update member elements
|
||||||
* @param members - <zh/> 值或者回调函数 | <en/> value or callback function
|
* @param members - <zh/> 值或者回调函数 | <en/> value or callback function
|
||||||
*/
|
*/
|
||||||
public updateMember(members: CallableValue<ID[]>) {
|
public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
|
||||||
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
||||||
this.drawBubbleSets();
|
this.drawBubbleSets();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { GraphEvent } from '../../constants';
|
|||||||
import type { ContourStyleProps } from '../../elements/shapes';
|
import type { ContourStyleProps } from '../../elements/shapes';
|
||||||
import { Contour } from '../../elements/shapes';
|
import { Contour } from '../../elements/shapes';
|
||||||
import type { RuntimeContext } from '../../runtime/types';
|
import type { RuntimeContext } from '../../runtime/types';
|
||||||
import type { CallableValue, ID, Point } from '../../types';
|
import type { ID, Point } from '../../types';
|
||||||
import type { ElementLifeCycleEvent } from '../../utils/event';
|
import type { ElementLifeCycleEvent } from '../../utils/event';
|
||||||
import { idOf } from '../../utils/id';
|
import { idOf } from '../../utils/id';
|
||||||
import { positionOf } from '../../utils/position';
|
import { positionOf } from '../../utils/position';
|
||||||
@ -185,7 +185,7 @@ export class Hull extends BasePlugin<HullOptions> {
|
|||||||
* <en/> Update Hull member
|
* <en/> Update Hull member
|
||||||
* @param members - <zh/> 元素 Ids | <en/> Element Ids
|
* @param members - <zh/> 元素 Ids | <en/> Element Ids
|
||||||
*/
|
*/
|
||||||
public updateMember(members: CallableValue<ID[]>) {
|
public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
|
||||||
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
||||||
this.shape.update(this.getHullStyle(true));
|
this.shape.update(this.getHullStyle(true));
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import type { UpdateBehaviorOption } from '../spec/behavior';
|
|||||||
import type { UpdatePluginOption } from '../spec/plugin';
|
import type { UpdatePluginOption } from '../spec/plugin';
|
||||||
import type { UpdateTransformOption } from '../spec/transform';
|
import type { UpdateTransformOption } from '../spec/transform';
|
||||||
import type {
|
import type {
|
||||||
CallableValue,
|
|
||||||
DataID,
|
DataID,
|
||||||
EdgeDirection,
|
EdgeDirection,
|
||||||
ElementDatum,
|
ElementDatum,
|
||||||
@ -262,7 +261,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param theme - <zh/> 主题配置 | <en/> theme configuration
|
* @param theme - <zh/> 主题配置 | <en/> theme configuration
|
||||||
* @apiCategory theme
|
* @apiCategory theme
|
||||||
*/
|
*/
|
||||||
public setTheme(theme: CallableValue<ThemeOptions>): void {
|
public setTheme(theme: ThemeOptions | ((prev: ThemeOptions) => ThemeOptions)): void {
|
||||||
this.options.theme = isFunction(theme) ? theme(this.getTheme()) : theme;
|
this.options.theme = isFunction(theme) ? theme(this.getTheme()) : theme;
|
||||||
|
|
||||||
const { background } = getExtension('theme', this.options.theme) || {};
|
const { background } = getExtension('theme', this.options.theme) || {};
|
||||||
@ -278,7 +277,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param layout - <zh/> 布局配置 | <en/> layout configuration
|
* @param layout - <zh/> 布局配置 | <en/> layout configuration
|
||||||
* @apiCategory layout
|
* @apiCategory layout
|
||||||
*/
|
*/
|
||||||
public setLayout(layout: CallableValue<LayoutOptions>): void {
|
public setLayout(layout: LayoutOptions | ((prev: LayoutOptions) => LayoutOptions)): void {
|
||||||
this.options.layout = isFunction(layout) ? layout(this.getLayout()) : layout;
|
this.options.layout = isFunction(layout) ? layout(this.getLayout()) : layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +299,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param behaviors - <zh/> 交互配置 | <en/> behavior configuration
|
* @param behaviors - <zh/> 交互配置 | <en/> behavior configuration
|
||||||
* @apiCategory behavior
|
* @apiCategory behavior
|
||||||
*/
|
*/
|
||||||
public setBehaviors(behaviors: CallableValue<BehaviorOptions>): void {
|
public setBehaviors(behaviors: BehaviorOptions | ((prev: BehaviorOptions) => BehaviorOptions)): void {
|
||||||
this.options.behaviors = isFunction(behaviors) ? behaviors(this.getBehaviors()) : behaviors;
|
this.options.behaviors = isFunction(behaviors) ? behaviors(this.getBehaviors()) : behaviors;
|
||||||
this.context.behavior?.setBehaviors(this.options.behaviors);
|
this.context.behavior?.setBehaviors(this.options.behaviors);
|
||||||
}
|
}
|
||||||
@ -341,7 +340,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param plugins - <zh/> 插件配置 | <en/> plugin configuration
|
* @param plugins - <zh/> 插件配置 | <en/> plugin configuration
|
||||||
* @apiCategory plugin
|
* @apiCategory plugin
|
||||||
*/
|
*/
|
||||||
public setPlugins(plugins: CallableValue<PluginOptions>): void {
|
public setPlugins(plugins: PluginOptions | ((prev: PluginOptions) => PluginOptions)): void {
|
||||||
this.options.plugins = isFunction(plugins) ? plugins(this.getPlugins()) : plugins;
|
this.options.plugins = isFunction(plugins) ? plugins(this.getPlugins()) : plugins;
|
||||||
this.context.plugin?.setPlugins(this.options.plugins);
|
this.context.plugin?.setPlugins(this.options.plugins);
|
||||||
}
|
}
|
||||||
@ -394,7 +393,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param transforms - <zh/> 数据转换配置 | <en/> data transform configuration
|
* @param transforms - <zh/> 数据转换配置 | <en/> data transform configuration
|
||||||
* @apiCategory transform
|
* @apiCategory transform
|
||||||
*/
|
*/
|
||||||
public setTransforms(transforms: CallableValue<TransformOptions>): void {
|
public setTransforms(transforms: TransformOptions | ((prev: TransformOptions) => TransformOptions)): void {
|
||||||
this.options.transforms = isFunction(transforms) ? transforms(this.getTransforms()) : transforms;
|
this.options.transforms = isFunction(transforms) ? transforms(this.getTransforms()) : transforms;
|
||||||
this.context.transform?.setTransforms(this.options.transforms);
|
this.context.transform?.setTransforms(this.options.transforms);
|
||||||
}
|
}
|
||||||
@ -565,7 +564,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 数据 | <en/> data
|
* @param data - <zh/> 数据 | <en/> data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public setData(data: CallableValue<GraphData>): void {
|
public setData(data: GraphData | ((prev: GraphData) => GraphData)): void {
|
||||||
this.context.model.setData(isFunction(data) ? data(this.getData()) : data);
|
this.context.model.setData(isFunction(data) ? data(this.getData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +575,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 元素数据 | <en/> element data
|
* @param data - <zh/> 元素数据 | <en/> element data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public addData(data: CallableValue<GraphData>): void {
|
public addData(data: GraphData | ((prev: GraphData) => GraphData)): void {
|
||||||
this.context.model.addData(isFunction(data) ? data(this.getData()) : data);
|
this.context.model.addData(isFunction(data) ? data(this.getData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,7 +586,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 节点数据 | <en/> node data
|
* @param data - <zh/> 节点数据 | <en/> node data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public addNodeData(data: CallableValue<NodeData[]>): void {
|
public addNodeData(data: NodeData[] | ((prev: NodeData[]) => NodeData[])): void {
|
||||||
this.context.model.addNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
this.context.model.addNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,7 +597,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 边数据 | <en/> edge data
|
* @param data - <zh/> 边数据 | <en/> edge data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public addEdgeData(data: CallableValue<EdgeData[]>): void {
|
public addEdgeData(data: EdgeData[] | ((prev: EdgeData[]) => EdgeData[])): void {
|
||||||
this.context.model.addEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
this.context.model.addEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,7 +608,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 组合数据 | <en/> combo data
|
* @param data - <zh/> 组合数据 | <en/> combo data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public addComboData(data: CallableValue<ComboData[]>): void {
|
public addComboData(data: ComboData[] | ((prev: ComboData[]) => ComboData[])): void {
|
||||||
this.context.model.addComboData(isFunction(data) ? data(this.getComboData()) : data);
|
this.context.model.addComboData(isFunction(data) ? data(this.getComboData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +619,7 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 元素数据 | <en/> element data
|
* @param data - <zh/> 元素数据 | <en/> element data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public updateData(data: CallableValue<PartialGraphData>): void {
|
public updateData(data: PartialGraphData | ((prev: PartialGraphData) => PartialGraphData)): void {
|
||||||
this.context.model.updateData(isFunction(data) ? data(this.getData()) : data);
|
this.context.model.updateData(isFunction(data) ? data(this.getData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +630,11 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 节点数据 | <en/> node data
|
* @param data - <zh/> 节点数据 | <en/> node data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public updateNodeData(data: CallableValue<PartialNodeLikeData<NodeData>[]>): void {
|
public updateNodeData(
|
||||||
|
data:
|
||||||
|
| PartialNodeLikeData<NodeData>[]
|
||||||
|
| ((prev: PartialNodeLikeData<NodeData>[]) => PartialNodeLikeData<NodeData>[]),
|
||||||
|
): void {
|
||||||
this.context.model.updateNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
this.context.model.updateNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +645,9 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 边数据 | <en/> edge data
|
* @param data - <zh/> 边数据 | <en/> edge data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public updateEdgeData(data: CallableValue<PartialEdgeData<EdgeData>[]>): void {
|
public updateEdgeData(
|
||||||
|
data: PartialEdgeData<EdgeData>[] | ((prev: PartialEdgeData<EdgeData>[]) => PartialEdgeData<EdgeData>[]),
|
||||||
|
): void {
|
||||||
this.context.model.updateEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
this.context.model.updateEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,7 +658,11 @@ export class Graph extends EventEmitter {
|
|||||||
* @param data - <zh/> 组合数据 | <en/> combo data
|
* @param data - <zh/> 组合数据 | <en/> combo data
|
||||||
* @apiCategory data
|
* @apiCategory data
|
||||||
*/
|
*/
|
||||||
public updateComboData(data: CallableValue<PartialNodeLikeData<ComboData>[]>): void {
|
public updateComboData(
|
||||||
|
data:
|
||||||
|
| PartialNodeLikeData<ComboData>[]
|
||||||
|
| ((prev: PartialNodeLikeData<ComboData>[]) => PartialNodeLikeData<ComboData>[]),
|
||||||
|
): void {
|
||||||
this.context.model.updateComboData(isFunction(data) ? data(this.getComboData()) : data);
|
this.context.model.updateComboData(isFunction(data) ? data(this.getComboData()) : data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import type { PathStyleProps } from '@antv/g';
|
|||||||
import { isBoolean, isEmpty, isEqual, isFunction } from '@antv/util';
|
import { isBoolean, isEmpty, isEqual, isFunction } from '@antv/util';
|
||||||
import type { RuntimeContext } from '../runtime/types';
|
import type { RuntimeContext } from '../runtime/types';
|
||||||
import type { EdgeData } from '../spec';
|
import type { EdgeData } from '../spec';
|
||||||
import type { CallableValue, ID, LoopPlacement, NodeLikeData } from '../types';
|
import type { ID, LoopPlacement, NodeLikeData } from '../types';
|
||||||
import { groupByChangeType, reduceDataChanges } from '../utils/change';
|
import { groupByChangeType, reduceDataChanges } from '../utils/change';
|
||||||
import { idOf } from '../utils/id';
|
import { idOf } from '../utils/id';
|
||||||
import { reassignTo } from '../utils/transform';
|
import { reassignTo } from '../utils/transform';
|
||||||
@ -55,7 +55,7 @@ export interface ProcessParallelEdgesOptions extends BaseTransformOptions {
|
|||||||
*
|
*
|
||||||
* <en/> The style of the merged edge, only valid for merging mode
|
* <en/> The style of the merged edge, only valid for merging mode
|
||||||
*/
|
*/
|
||||||
style?: CallableValue<PathStyleProps, EdgeData[]>;
|
style?: PathStyleProps | ((prev: EdgeData[]) => PathStyleProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,15 +1,3 @@
|
|||||||
/**
|
|
||||||
* <zh/> 可回调值
|
|
||||||
*
|
|
||||||
* <en/> Callable value
|
|
||||||
* @example
|
|
||||||
* type Prop = number;
|
|
||||||
* type CallableProp = Callable<Prop>;
|
|
||||||
* const prop1: CallableProp = 1;
|
|
||||||
* const prop2: CallableProp = (value) => value;
|
|
||||||
*/
|
|
||||||
export type CallableValue<Returns, Param = Returns> = Returns | ((args: Param) => Returns);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <zh/> 可回调对象
|
* <zh/> 可回调对象
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user