-
Notifications
You must be signed in to change notification settings - Fork 263
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
dd279a5
commit 04ad02c
Showing
8 changed files
with
178 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/graph/elk-layout.js | ||
cd .. | ||
cd .. | ||
npm run dev |
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,100 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import GraphPlugin from '../../plugins/graph-plugin.js'; | ||
import RandomPlacePlugin from '../../plugins/randomplace-plugin.js'; | ||
import MoveToPlugin from '../../plugins/moveto-plugin.js'; | ||
|
||
const COLOR_MAIN = 0x7986cb; | ||
const COLOR_LIGHT = 0xaab6fe; | ||
const COLOR_DARK = 0x49599a; | ||
|
||
const GetRandomItem = Phaser.Utils.Array.GetRandom; | ||
const DistanceBetween = Phaser.Math.Distance.Between; | ||
const RemoveItem = Phaser.Utils.Array.Remove; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { } | ||
|
||
create() { | ||
var nodeA = CreateNode(this); | ||
var nodeB = CreateNode(this); | ||
var nodeC = CreateNode(this); | ||
var nodeD = CreateNode(this); | ||
var edgeAB = CreateEdge(this); | ||
var edgeAC = CreateEdge(this); | ||
var edgeBD = CreateEdge(this); | ||
var edgeCD = CreateEdge(this); | ||
|
||
var graph = this.rexGraph.add.graph() | ||
.addNodes([nodeA, nodeB, nodeC, nodeD]) | ||
.addEdge(edgeAB, nodeA, nodeB) | ||
.addEdge(edgeAC, nodeA, nodeC) | ||
.addEdge(edgeBD, nodeB, nodeD) | ||
.addEdge(edgeCD, nodeC, nodeD) | ||
|
||
graph.on('layout.edge', function (edgeGameObject, path) { | ||
var startPoint = path[0]; | ||
var endPoint = path[path.length - 1]; | ||
edgeGameObject | ||
.setPosition(startPoint.x, startPoint.y) | ||
.setTo(0, 0, endPoint.x - startPoint.x, endPoint.y - startPoint.y) | ||
}); | ||
|
||
this.rexGraph.ELKLayout(graph) | ||
.once('layout.complete', function () { | ||
console.log('layout.complete') | ||
}) | ||
|
||
} | ||
|
||
update() { | ||
} | ||
} | ||
|
||
var CreateNode = function (scene) { | ||
return scene.add.rectangle(0, 0, 100, 100).setStrokeStyle(3, 0x00ffff) | ||
} | ||
|
||
var CreateEdge = function (scene) { | ||
return scene.add.line(0, 0, 0, 0, 0, 0, 0xff0000).setLineWidth(2).setOrigin(0) | ||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: Demo, | ||
plugins: { | ||
global: [ | ||
{ | ||
key: 'rexRandomPlace', | ||
plugin: RandomPlacePlugin, | ||
start: true | ||
}, | ||
{ | ||
key: 'rexMoveTo', | ||
plugin: MoveToPlugin, | ||
start: true | ||
} | ||
], | ||
scene: [ | ||
{ | ||
key: 'rexGraph', | ||
plugin: GraphPlugin, | ||
mapping: 'rexGraph' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
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,7 @@ | ||
import Graph from './graph/graph/Graph.js'; | ||
import ELKLayout from './graph/layout/elkjs/Layout.js'; | ||
|
||
export { | ||
Graph, | ||
ELKLayout | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var GetPath = function (edgeData) { | ||
var result = []; | ||
|
||
var pathData = edgeData.sections[0]; | ||
|
||
result.push(pathData.startPoint); | ||
|
||
if (pathData.bendPoints) { | ||
pathData.bendPoints.forEach(function (point) { | ||
result.push(point); | ||
}) | ||
} | ||
|
||
result.push(pathData.endPoint); | ||
|
||
return result; | ||
} | ||
|
||
export default GetPath; |
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,13 +1,18 @@ | ||
import AlignIn from '../../../utils/actions/AlignIn.js'; | ||
import GetPath from './GetPath.js'; | ||
|
||
const ALIGN_CENTER = Phaser.Display.Align.CENTER; | ||
|
||
var PlaceGameObjects = function (graphData, graph) { | ||
var PlaceGameObjects = function (graph, graphData, config) { | ||
graphData.children.forEach(function (nodeData) { | ||
AlignIn(nodeData.gameObject, nodeData.x, nodeData.y, nodeData.width, nodeData.height, ALIGN_CENTER); | ||
graph.emit('layout.node', nodeData.gameObject); | ||
}) | ||
|
||
// TODO: edge? | ||
graphData.edges.forEach(function (edgeData) { | ||
var path = GetPath(edgeData); | ||
graph.emit('layout.edge', edgeData.gameObject, path, edgeData.sourceGameObject, edgeData.targetGameObject); | ||
}) | ||
} | ||
|
||
export default PlaceGameObjects; |