-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be27e2a
commit 51bf7d6
Showing
7 changed files
with
99 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
import * as Layout from './layout' | ||
import * as Registy from './registy' | ||
|
||
export { Layout, Registy } | ||
export * from './layout' | ||
export * from './registy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
export * from './base' | ||
export * from './grid' | ||
export * from './random' | ||
export * from './g-force' | ||
export * from './force' | ||
export * from './circular' | ||
export * from './dagre' | ||
export * from './radial' | ||
export * from './types' | ||
export * from './layout' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Base } from './base' | ||
import { Model } from './types' | ||
import { GridLayout } from './grid' | ||
import { RandomLayout } from './random' | ||
import { GForceLayout } from './g-force' | ||
import { ForceLayout } from './force' | ||
import { CircularLayout } from './circular' | ||
import { DagreLayout } from './dagre' | ||
import { RadialLayout } from './radial' | ||
import { registLayout, getLayoutByName } from '../registy' | ||
|
||
export class Layout { | ||
public readonly layoutInstance: Base | ||
|
||
constructor(options: Layout.LayoutOptions) { | ||
const layoutClass = getLayoutByName(options.type) | ||
this.layoutInstance = new layoutClass(options) | ||
} | ||
|
||
layout(data: Model) { | ||
return this.layoutInstance.layout(data) | ||
} | ||
|
||
updateCfg(cfg: Layout.LayoutOptions) { | ||
this.layoutInstance.updateCfg(cfg) | ||
} | ||
|
||
init(data: Model) { | ||
this.layoutInstance.init(data) | ||
} | ||
|
||
execute() { | ||
this.layoutInstance.execute() | ||
} | ||
|
||
getDefaultCfg() { | ||
return this.layoutInstance.getDefaultCfg() | ||
} | ||
|
||
destroy() { | ||
return this.layoutInstance.destroy() | ||
} | ||
} | ||
|
||
export namespace Layout { | ||
registLayout('grid', GridLayout) | ||
registLayout('random', RandomLayout) | ||
registLayout('gForce', GForceLayout) | ||
registLayout('force', ForceLayout) | ||
registLayout('circular', CircularLayout) | ||
registLayout('dagre', DagreLayout) | ||
registLayout('radial', RadialLayout) | ||
|
||
export type LayoutTypes = | ||
| 'grid' | ||
| 'random' | ||
| 'gForce' | ||
| 'force' | ||
| 'circular' | ||
| 'dagre' | ||
| 'radial' | ||
|
||
export type LayoutOptions = | ||
| GridLayout.GridLayoutOptions | ||
| RandomLayout.RandomLayoutOptions | ||
| GForceLayout.GForceLayoutOptions | ||
| ForceLayout.ForceLayoutOptions | ||
| CircularLayout.CircularLayoutOptions | ||
| DagreLayout.DagreLayoutOptions | ||
| RadialLayout.RadialLayoutOptions | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const map: Map<string, any> = new Map() | ||
|
||
export const registLayout = (name: string, customClass: any) => { | ||
if (map.get(name)) { | ||
throw new Error('already have a layout with the same name') | ||
} | ||
map.set(name, customClass) | ||
} | ||
|
||
export const unRegistLayout = (name: string) => { | ||
if (map.has(name)) { | ||
map.delete(name) | ||
} | ||
} | ||
|
||
export const getLayoutByName = (name: string) => { | ||
if (map.has(name)) { | ||
return map.get(name) | ||
} | ||
return null | ||
} |