fix: resolve conflict

This commit is contained in:
baizn 2020-03-31 10:34:43 +08:00 committed by Yanyan Wang
parent 17e8c1c96d
commit da86834fc9
11 changed files with 32 additions and 47 deletions

View File

@ -1,4 +1,4 @@
import { IG6GraphEvent, Item, G6Event } from '../types'; import { IG6GraphEvent, Item, G6Event, NodeConfig } from '../types';
/* /*
* @Author: moyee * @Author: moyee
@ -167,7 +167,7 @@ export default {
const { graph } = this; const { graph } = this;
const { item } = evt; const { item } = evt;
const model = item.getModel(); const model = item.getModel() as NodeConfig;
// 节点所在的GroupId // 节点所在的GroupId
const { groupId, id } = model; const { groupId, id } = model;

View File

@ -11,7 +11,7 @@ import ShapeBase from '@antv/g-canvas/lib/shape/base';
import { Point } from '@antv/g-canvas/lib/types'; import { Point } from '@antv/g-canvas/lib/types';
import deepMix from '@antv/util/lib/deep-mix'; import deepMix from '@antv/util/lib/deep-mix';
import isString from '@antv/util/lib/is-string'; import isString from '@antv/util/lib/is-string';
import { GraphData, IG6GraphEvent, Item } from '../../types'; import { GraphData, IG6GraphEvent, Item, NodeConfig } from '../../types';
import { IGraph } from '../../interface/graph'; import { IGraph } from '../../interface/graph';
import { IEdge, INode } from '../../interface/item'; import { IEdge, INode } from '../../interface/item';
import { traverseTree } from '../../util/graphic'; import { traverseTree } from '../../util/graphic';
@ -634,7 +634,7 @@ export default class CustomGroup {
// 隐藏群组中的所有节点 // 隐藏群组中的所有节点
nodesInGroup.forEach(nodeId => { nodesInGroup.forEach(nodeId => {
const node = graph.findById(nodeId); const node = graph.findById(nodeId);
const model = node.getModel(); const model = node.getModel() as NodeConfig;
const { groupId } = model; const { groupId } = model;
if (groupId && groupId !== id) { if (groupId && groupId !== id) {
// 存在群组,则隐藏 // 存在群组,则隐藏
@ -812,7 +812,7 @@ export default class CustomGroup {
setTimeout(() => { setTimeout(() => {
nodesInGroup.forEach(nodeId => { nodesInGroup.forEach(nodeId => {
const node = graph.findById(nodeId); const node = graph.findById(nodeId);
const model = node.getModel(); const model = node.getModel() as NodeConfig;
const { groupId } = model; const { groupId } = model;
if (groupId && groupId !== id) { if (groupId && groupId !== id) {
// 存在群组,则显示 // 存在群组,则显示
@ -1224,7 +1224,7 @@ export default class CustomGroup {
public dynamicChangeGroupSize(evt: IG6GraphEvent, currentGroup: IGroup, keyShape: ShapeBase) { public dynamicChangeGroupSize(evt: IG6GraphEvent, currentGroup: IGroup, keyShape: ShapeBase) {
const { item } = evt; const { item } = evt;
const model = item.getModel(); const model = item.getModel() as NodeConfig;
// 节点所在的GroupId // 节点所在的GroupId
const { groupId } = model; const { groupId } = model;

View File

@ -12,9 +12,6 @@ import Combo from '../../item/combo';
import { EdgeConfig, Item, ITEM_TYPE, ModelConfig, NodeConfig, NodeMap, ComboTree, ComboConfig } from '../../types'; import { EdgeConfig, Item, ITEM_TYPE, ModelConfig, NodeConfig, NodeMap, ComboTree, ComboConfig } from '../../types';
import Graph from '../graph'; import Graph from '../graph';
import { mix } from '@antv/util';
import { IGraph } from '../../interface/graph';
import { IGroup } from '@antv/g-base';
import { IEdge, INode, ICombo } from '../../interface/item'; import { IEdge, INode, ICombo } from '../../interface/item';
import { traverseTreeUp, traverseTree, getComboBBox } from '../../util/graphic'; import { traverseTreeUp, traverseTree, getComboBBox } from '../../util/graphic';

View File

@ -345,7 +345,7 @@ export default class TreeGraph extends Graph implements ITreeGraph {
return; return;
} }
const parentModel = self.findById(parent).getModel(); const parentModel = self.findById(parent).getModel() as NodeConfig;
const current = self.findById(data.id); const current = self.findById(data.id);

View File

@ -173,7 +173,7 @@ const singleEdge: ShapeOptions = {
if (cfg.startPoint!.x === cfg.endPoint!.x && cfg.startPoint!.y === cfg.endPoint!.y) { if (cfg.startPoint!.x === cfg.endPoint!.x && cfg.startPoint!.y === cfg.endPoint!.y) {
style.x = cfg.startPoint!.x + offsetX; style.x = cfg.startPoint!.x + offsetX;
style.y = cfg.startPoint!.y + offsetY; style.y = cfg.startPoint!.y + offsetY;
style.text = cfg.label; style.text = cfg.label as string;
return style; return style;
} }
@ -189,7 +189,7 @@ const singleEdge: ShapeOptions = {
style.y = offsetStyle.y; style.y = offsetStyle.y;
style.rotate = offsetStyle.rotate; style.rotate = offsetStyle.rotate;
style.textAlign = this._getTextAlign!(labelPosition as string, offsetStyle.angle as number); style.textAlign = this._getTextAlign!(labelPosition as string, offsetStyle.angle as number);
style.text = cfg.label; style.text = cfg.label as string;
return style; return style;
}, },
getLabelBgStyleByPosition( getLabelBgStyleByPosition(

View File

@ -1,7 +1,7 @@
import { Point } from '@antv/g-base/lib/types'; import { Point } from '@antv/g-base/lib/types';
import Group from '@antv/g-canvas/lib/group'; import Group from '@antv/g-canvas/lib/group';
import { mix, each, isNumber, isArray, isString } from '@antv/util'; import { mix, each, isArray, isString } from '@antv/util';
import { ModelConfig, ShapeStyle } from '../../types'; import { ShapeStyle, EdgeConfig } from '../../types';
import { pointsToPolygon } from '../../util/path'; import { pointsToPolygon } from '../../util/path';
import Global from '../../global'; import Global from '../../global';
import Shape from '../shape'; import Shape from '../shape';
@ -33,7 +33,7 @@ Shape.registerEdge(
shapeType: 'polyline', shapeType: 'polyline',
// 文本位置 // 文本位置
labelPosition: 'center', labelPosition: 'center',
drawShape(cfg: ModelConfig, group: Group) { drawShape(cfg: EdgeConfig, group: Group) {
const shapeStyle = (this as any).getShapeStyle(cfg); const shapeStyle = (this as any).getShapeStyle(cfg);
const keyShape = group.addShape('path', { const keyShape = group.addShape('path', {
className: 'edge-shape', className: 'edge-shape',
@ -42,8 +42,8 @@ Shape.registerEdge(
}); });
return keyShape; return keyShape;
}, },
getShapeStyle(cfg: ModelConfig): ShapeStyle { getShapeStyle(cfg: EdgeConfig): ShapeStyle {
const { style: defaultStyle } = this.options as ModelConfig; const { style: defaultStyle } = this.options as EdgeConfig;
const strokeStyle: ShapeStyle = { const strokeStyle: ShapeStyle = {
stroke: cfg.color, stroke: cfg.color,
@ -71,7 +71,7 @@ Shape.registerEdge(
routeCfg = { source, target, offset: style.offset, radius: style.radius }; routeCfg = { source, target, offset: style.offset, radius: style.radius };
} }
let path = (this as any).getPath(points, routeCfg); let path = (this as any).getPath(points, routeCfg);
if ((isArray(path) && path.length <=1) || (isString(path) && path.indexOf('L') === -1)) { if ((isArray(path) && path.length <= 1) || (isString(path) && path.indexOf('L') === -1)) {
path = 'M0 0, L0 0'; path = 'M0 0, L0 0';
} }
if (isNaN(startPoint.x) || isNaN(startPoint.y) || isNaN(endPoint.x) || isNaN(endPoint.y)) { if (isNaN(startPoint.x) || isNaN(startPoint.y) || isNaN(endPoint.x) || isNaN(endPoint.y)) {

View File

@ -53,7 +53,7 @@ const singleNode: ShapeOptions = {
// 默认的位置(最可能的情形),所以放在最上面 // 默认的位置(最可能的情形),所以放在最上面
if (labelPosition === 'center') { if (labelPosition === 'center') {
return { x: 0, y: 0, text: cfg!.label }; return { x: 0, y: 0, text: cfg!.label as string };
} }
let { offset } = labelCfg; let { offset } = labelCfg;
@ -330,9 +330,9 @@ const singleNode: ShapeOptions = {
(this as any).updateIcon(cfg, item); (this as any).updateIcon(cfg, item);
} }
}, },
updateIcon(cfg: ModelConfig, item: Item) { updateIcon(cfg: NodeConfig, item: Item) {
const group = item.getContainer(); const group = item.getContainer();
const { icon: defaultIcon } = this.options as ModelConfig; const { icon: defaultIcon } = this.options as NodeConfig;
const icon = mix({}, defaultIcon, cfg.icon); const icon = mix({}, defaultIcon, cfg.icon);
const { show } = cfg.icon ? cfg.icon : { show: undefined }; const { show } = cfg.icon ? cfg.icon : { show: undefined };
const iconShape = group.find(element => element.get('className') === `${this.type}-icon`); const iconShape = group.find(element => element.get('className') === `${this.type}-icon`);

View File

@ -5,10 +5,10 @@
import GGroup from '@antv/g-canvas/lib/group'; import GGroup from '@antv/g-canvas/lib/group';
import { IShape, IElement } from '@antv/g-canvas/lib/interfaces'; import { IShape, IElement } from '@antv/g-canvas/lib/interfaces';
import { ShapeOptions, ILabelConfig } from '../interface/shape'; import { ShapeOptions, ILabelConfig } from '../interface/shape';
import { IPoint, Item, LabelStyle, ShapeStyle, ModelConfig } from '../types'; import { IPoint, Item, LabelStyle, ShapeStyle, ModelConfig, EdgeConfig } from '../types';
import Global from '../global'; import Global from '../global';
import { mat3, transform } from '@antv/matrix-util'; import { mat3, transform } from '@antv/matrix-util';
import { deepMix, each, mix, isString, isBoolean, isPlainObject, clone, indexOf } from '@antv/util'; import { deepMix, each, mix, isBoolean, isPlainObject, clone } from '@antv/util';
const CLS_SHAPE_SUFFIX = '-shape'; const CLS_SHAPE_SUFFIX = '-shape';
const CLS_LABEL_SUFFIX = '-label'; const CLS_LABEL_SUFFIX = '-label';
@ -125,7 +125,7 @@ export const shapeBase: ShapeOptions = {
return rect; return rect;
}, },
getLabelStyleByPosition(cfg: ModelConfig, labelCfg?: ILabelConfig, group?: GGroup): LabelStyle { getLabelStyleByPosition(cfg: ModelConfig, labelCfg?: ILabelConfig, group?: GGroup): LabelStyle {
return { text: cfg.label }; return { text: cfg.label as string };
}, },
getLabelBgStyleByPosition( getLabelBgStyleByPosition(
label: IElement, label: IElement,
@ -415,7 +415,7 @@ export const shapeBase: ShapeOptions = {
* @param {Object} cfg * @param {Object} cfg
* @return {Array|null} , null * @return {Array|null} , null
*/ */
getControlPoints(cfg: ModelConfig): IPoint[] | undefined { getControlPoints(cfg: EdgeConfig): IPoint[] | undefined {
return cfg.controlPoints; return cfg.controlPoints;
}, },
/** /**

View File

@ -334,6 +334,7 @@ export interface ModelConfig extends ModelStyle {
export interface NodeConfig extends ModelConfig { export interface NodeConfig extends ModelConfig {
id: string; id: string;
groupId?: string; groupId?: string;
comboId?: string;
children?: TreeGraphData[]; children?: TreeGraphData[];
description?: string; description?: string;
descriptionCfg?: { descriptionCfg?: {
@ -416,21 +417,6 @@ export interface ComboConfig extends ModelConfig {
}> }>
} }
export interface ComboConfig {
id: string;
parentId?: string;
// Combo 类型,默认 rect值为定义的 combo 的名称
type: string;
// Combo 标题
title: string | LabelStyle;
style: ShapeStyle;
stateStyles: {
[key: string]: ShapeStyle | {
[key: string]: ShapeStyle
}
};
}
export interface EdgeConfig extends ModelConfig { export interface EdgeConfig extends ModelConfig {
id?: string; id?: string;
source?: string; source?: string;
@ -442,8 +428,8 @@ export interface EdgeConfig extends ModelConfig {
controlPoints?: IPoint[]; controlPoints?: IPoint[];
curveOffset?: number; curveOffset?: number;
// loop edge config // loop edge config
loopCfg: LoopConfig; loopCfg?: LoopConfig;
labelCfg: ILabelConfig; labelCfg?: ILabelConfig;
} }
export type EdgeData = EdgeConfig & { export type EdgeData = EdgeConfig & {
@ -506,7 +492,7 @@ export interface TreeGraphData {
export interface ComboTree { export interface ComboTree {
id: string; id: string;
label?: string; label?: string | LabelStyle;
children?: ComboTree[]; children?: ComboTree[];
depth?: number; depth?: number;
parentId?: string; parentId?: string;

View File

@ -1,13 +1,14 @@
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import G6 from '../../../src'; import G6 from '../../../src';
import { IGraph } from '../../../src/interface/graph'; import { IGraph } from '../../../src/interface/graph';
import { NodeConfig, EdgeConfig } from '../../../src/types';
let graph: IGraph = null; let graph: IGraph = null;
G6.registerNode( G6.registerNode(
'file-node', 'file-node',
{ {
draw(cfg, group) { draw(cfg: NodeConfig, group) {
const keyShape = group.addShape('rect', { const keyShape = group.addShape('rect', {
attrs: { attrs: {
x: cfg.x - 4, x: cfg.x - 4,
@ -69,7 +70,7 @@ G6.registerNode(
G6.registerEdge( G6.registerEdge(
'step-line', 'step-line',
{ {
getControlPoints: function getControlPoints(cfg) { getControlPoints: function getControlPoints(cfg: EdgeConfig) {
const startPoint = cfg.startPoint; const startPoint = cfg.startPoint;
const endPoint = cfg.endPoint; const endPoint = cfg.endPoint;
return [ return [

View File

@ -1,6 +1,7 @@
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import G6 from '../../../src'; import G6 from '../../../src';
import { IGraph } from '../../../src/interface/graph'; import { IGraph } from '../../../src/interface/graph';
import { NodeConfig, EdgeConfig } from '../../../src/types';
let graph: IGraph = null; let graph: IGraph = null;
@ -9,7 +10,7 @@ const MoveViewPort = () => {
useEffect(() => { useEffect(() => {
if (!graph) { if (!graph) {
G6.registerNode('file-node', { G6.registerNode('file-node', {
draw: function draw(cfg, group) { draw: function draw(cfg: NodeConfig, group) {
const keyShape = group.addShape('rect', { const keyShape = group.addShape('rect', {
attrs: { attrs: {
x: cfg.x - 4, x: cfg.x - 4,
@ -60,7 +61,7 @@ const MoveViewPort = () => {
G6.registerEdge( G6.registerEdge(
'step-line', 'step-line',
{ {
getControlPoints: function getControlPoints(cfg) { getControlPoints: function getControlPoints(cfg: EdgeConfig) {
const startPoint = cfg.startPoint; const startPoint = cfg.startPoint;
const endPoint = cfg.endPoint; const endPoint = cfg.endPoint;
return [ return [