Skip to content

Commit

Permalink
refactor: IsMdata
Browse files Browse the repository at this point in the history
  • Loading branch information
hellowuxin committed May 14, 2021
1 parent bd59bd7 commit 01312a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Mindmap/attribute/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const attrG = (g: SelectionG, tran?: Transition): void => {
g2.attr('transform', getGTransform)
}

export const attrText = (text: d3.Selection<SVGTextElement, Mdata, SVGGElement, Mdata | null>, tran?: Transition): void => {
export const attrText = (text: d3.Selection<SVGTextElement, Mdata, SVGGElement, IsMdata>, tran?: Transition): void => {
const t1 = tran ? text.transition(tran) : text
t1.attr('transform', (d) => `translate(${d.left ? -d.width : 0},0)`)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ export const attrTrigger = (rect: SelectionRect, padding: number): void => {
}

export const attrPath = (
p: d3.Selection<SVGPathElement, Mdata, SVGGElement, Mdata | null>,
p: d3.Selection<SVGPathElement, Mdata, SVGGElement, IsMdata>,
tran?: Transition
): void => {
const p1 = p.attr('stroke', (d) => d.color).attr('stroke-width', branch)
Expand Down
6 changes: 3 additions & 3 deletions src/components/Mindmap/draw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const updateTspan = (
return update
}

export const appendAddBtn = (g: SelectionG): d3.Selection<SVGGElement, Mdata, SVGGElement, Mdata | null> => {
export const appendAddBtn = (g: SelectionG): d3.Selection<SVGGElement, Mdata, SVGGElement, IsMdata> => {
const gAddBtn = g.append('g')
attrAddBtnRect(gAddBtn.append('rect'))
gAddBtn.append('path').attr('d', getAddPath(2, addBtnRect.side))
Expand All @@ -35,7 +35,7 @@ const appendAndBindAddBtn = (g: SelectionG) => {
return gAddBtn
}

export const appendExpandBtn = (g: SelectionG): d3.Selection<SVGGElement, Mdata, SVGGElement, Mdata | null> => {
export const appendExpandBtn = (g: SelectionG): d3.Selection<SVGGElement, Mdata, SVGGElement, IsMdata> => {
const expandBtn = g.append('g')
attrExpandBtnRect(expandBtn.append('rect'))
attrExpandBtnCircle(expandBtn.append('circle'), -4)
Expand All @@ -60,7 +60,7 @@ const bindEvent = (g: SelectionG, isRoot: boolean) => {
}
}

const appendNode = (enter: d3.Selection<d3.EnterElement, Mdata, SVGGElement, Mdata | null>) => {
const appendNode = (enter: d3.Selection<d3.EnterElement, Mdata, SVGGElement, IsMdata>) => {
const isRoot = !enter.data()[0]?.depth
const enterG = enter.append('g')
attrG(enterG)
Expand Down
8 changes: 4 additions & 4 deletions src/components/Mindmap/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface TreeData {
export interface Mdata {
rawData: Data
name: string
parent: Mdata | null
parent: IsMdata
children: Array<Mdata>
_children: Array<Mdata> // 当折叠时保存children数据
left: boolean
Expand All @@ -48,8 +48,8 @@ export interface TspanData {
}

export type Transition = d3.Transition<d3.BaseType, Mdata, d3.BaseType, unknown>
export type SelectionG = d3.Selection<SVGGElement, Mdata, SVGGElement, Mdata | null>
export type SelectionRect = d3.Selection<SVGRectElement, Mdata, SVGGElement, Mdata | null>
export type SelectionCircle = d3.Selection<SVGCircleElement, Mdata, SVGGElement, Mdata | null>
export type SelectionG = d3.Selection<SVGGElement, Mdata, SVGGElement, IsMdata>
export type SelectionRect = d3.Selection<SVGRectElement, Mdata, SVGGElement, IsMdata>
export type SelectionCircle = d3.Selection<SVGCircleElement, Mdata, SVGGElement, IsMdata>
export type TwoNumber = [number, number]
export type IsMdata = Mdata | null

0 comments on commit 01312a9

Please sign in to comment.