Skip to content

Commit 1474815

Browse files
committed
support map state (#30)
1 parent 3c213b0 commit 1474815

File tree

18 files changed

+299
-168
lines changed

18 files changed

+299
-168
lines changed

.eslintrc.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"globals": {
1212
"mxscript": false,
1313
"Draw": false,
14-
"ui": false,
15-
"graph": false,
14+
"Graph": false,
1615
"Editor": false,
16+
"EditDataDialog": true,
1717
"mxUtils": false,
1818
"mxEvent": false,
1919
"mxCellState": false,
@@ -32,10 +32,11 @@
3232
"mxMorphing": false,
3333
"mxForm": false,
3434
"mxCodecRegistry": false,
35-
"EditDataDialog": true,
3635
"mxCodec": false,
3736
"mxClient": false,
3837
"mxCompactTreeLayout": false,
38+
"mxCellRenderer": false,
39+
"mxSwimlane": false,
3940
"AWS": false,
4041
"__listStateMachines": false,
4142
"__describeStateMachine": false,

dist/aws-step-functions.js

Lines changed: 36 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/awssf.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare let WaitState
2020
declare let SucceedState
2121
declare let FailState
2222
declare let ParallelState
23+
declare let MapState
2324

2425
declare let StartAtEdge
2526
declare let NextEdge

src/@types/draw-io.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare module Editor {
66
const helpImage: string
77
}
88

9+
declare let Graph
910
declare let EditDataDialog
1011

1112
declare namespace ui {

src/@types/mxgraph.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ declare namespace mxUtils {
1717
function findNode( node, attr, value)
1818
function getPrettyXml(node)
1919
function extend(ctor, superCtor)
20-
20+
function getValue(array, key, defaultValue)
2121
}
22+
2223
declare namespace mxEvent {
2324
function addGestureListeners( node, startListener, moveListener?, endListener? )
2425
function getClientX( e )
@@ -134,4 +135,11 @@ declare class mxMorphing extends mxAnimation{
134135
declare class mxAnimation {
135136
startAnimation()
136137
addListener(event, listener)
137-
}
138+
}
139+
declare class mxSwimlane {
140+
isHorizontal: boolean | Function
141+
paintVertexShape: Function
142+
}
143+
declare module mxCellRenderer {
144+
function registerShape(key, shape)
145+
}

src/extend.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ mxConnectionHandler.prototype.insertEdge = function (parent, id, value, source,
3030
if (awssfUtils.isParallelChild(source) || awssfUtils.isParallelChild(target)) {
3131
if (source.parent != target.parent) return null;
3232
}
33-
if ((source == target) && (awssfUtils.isTask(source) || awssfUtils.isParallel(source))) {
33+
if (awssfUtils.isMapChild(source) || awssfUtils.isMapChild(target)) {
34+
if (source.parent != target.parent) return null;
35+
}
36+
if ((source == target) && (awssfUtils.isTask(source) || awssfUtils.isParallel(source) || awssfUtils.isMap(source))) {
3437
edge = RetryEdge.prototype.create();
3538
} else if (this.edgeState) {
3639
edge = this.edgeState.cell;

src/form/dialog.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as awssfUtils from "../utils";
22

33
export const awssfImportDialog = function (editorUi, title) {
4-
var graph = editorUi.editor.graph;
4+
const graph = editorUi.editor.graph;
55

66
function recurseStates (states) {
7-
var res = {hash: {}, list: []};
8-
var cell;
9-
for (var name in states) {
10-
var body = states[name];
7+
const res = {hash: {}, list: []};
8+
let cell;
9+
for (const name in states) {
10+
const body = states[name];
1111
if (body.Type === "Pass") {
1212
cell = PassState.prototype.create(name, body);
1313
} else if (body.Type === "Task") {
@@ -23,10 +23,15 @@ export const awssfImportDialog = function (editorUi, title) {
2323
} else if (body.Type === "Parallel") {
2424
cell = ParallelState.prototype.create(name, body);
2525
for(const branch in body.Branches) {
26-
var _sub = recurseStates(body.Branches[branch].States);
26+
const _sub = recurseStates(body.Branches[branch].States);
2727
for(const _cell of _sub.list) cell.insert(_cell);
2828
Object.assign(res.hash, _sub.hash);
2929
}
30+
} else if (body.Type === "Map") {
31+
cell = MapState.prototype.create(name, body);
32+
const _sub = recurseStates(body.Iterator.States);
33+
for(const _cell of _sub.list) cell.insert(_cell);
34+
Object.assign(res.hash, _sub.hash);
3035
}
3136
res.hash[name] = cell;
3237
res.list.push(cell);
@@ -79,11 +84,16 @@ export const awssfImportDialog = function (editorUi, title) {
7984
}
8085
if (body.Type === "Parallel") {
8186
for(const branch of body.Branches) {
82-
var _sp = vertexes[name].getChildAt(0);
83-
var tmp = recurseEdges(branch, vertexes, _sp);
87+
const _sp = vertexes[name].getChildAt(0);
88+
const tmp = recurseEdges(branch, vertexes, _sp);
8489
tmp.map(v => vertexes[name].insert(v));
8590
}
8691
}
92+
if (body.Type === "Map") {
93+
const _sp = vertexes[name].getChildAt(0);
94+
const tmp = recurseEdges(body.Iterator, vertexes, _sp);
95+
tmp.map(v => vertexes[name].insert(v));
96+
}
8797
}
8898
return res;
8999
}
@@ -122,7 +132,7 @@ export const awssfImportDialog = function (editorUi, title) {
122132
graph.setSelectionCells(cells);
123133
graph.getModel().beginUpdate();
124134
try {
125-
var parallels = cells.filter(function (v) { return v.awssf.type === "Parallel"; });
135+
var parallels = cells.filter(function (v) { return v.awssf.type.match(/Parallel|Map/); });
126136
var parallelLayout = new mxCompactTreeLayout(graph, false);
127137
parallelLayout.edgeRouting = false;
128138
parallelLayout.levelDistance = 30;

src/form/editData.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ export function setupEditData () {
9696
const datalist = document.createElement('datalist');
9797
datalist.id = "errors";
9898
var errors = [
99-
"States.ALL", "States.Timeout", "States.TaskFailed", "States.Permissions",
100-
"States.ResultPathMatchFailure", "States.BranchFailed", "States.NoChoiceMatched"
99+
"States.ALL",
100+
"States.Timeout",
101+
"States.TaskFailed",
102+
"States.Permissions",
103+
"States.ResultPathMatchFailure",
104+
"States.ParameterPathFailure",
105+
"States.BranchFailed",
106+
"States.NoChoiceMatched"
101107
];
102108
for (const error of errors) {
103109
const opt = document.createElement('option');

src/shapes/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LayeredShape } from "./layered";
2+
3+
export function init () {
4+
const mapShape = LayeredShape;
5+
}

src/shapes/layered.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export const LayeredShape = function () {};
2+
LayeredShape.prototype = new mxSwimlane(); //mxActor();
3+
LayeredShape.prototype.constructor = LayeredShape;
4+
LayeredShape.prototype.isHorizontal = function () {return false;};
5+
LayeredShape.prototype.paintVertexShape = function (c, x, y, w, h) {
6+
c.translate(x, y);
7+
var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
8+
dx = Math.min(w * 0.5, h * 0.5, dx);
9+
10+
c.begin();
11+
c.moveTo(w - dx * 0.5, dx);
12+
c.lineTo(w, dx);
13+
c.lineTo(w, h);
14+
c.lineTo(dx, h);
15+
c.lineTo(dx, h - dx * 0.5);
16+
c.lineTo(w - dx * 0.5, h - dx * 0.5);
17+
c.close();
18+
c.fillAndStroke();
19+
20+
c.begin();
21+
c.moveTo(w - dx, dx * 0.5);
22+
c.lineTo(w - dx * 0.5, dx * 0.5);
23+
c.lineTo(w - dx * 0.5, h - dx * 0.5);
24+
c.lineTo(dx * 0.5, h - dx * 0.5);
25+
c.lineTo(dx * 0.5, h - dx);
26+
c.lineTo(w - dx, h - dx);
27+
c.close();
28+
c.fillAndStroke();
29+
30+
c.begin();
31+
c.moveTo(0, 0);
32+
c.lineTo(w - dx, 0);
33+
c.lineTo(w - dx, h - dx);
34+
c.lineTo(0, h - dx);
35+
c.close();
36+
c.stroke();
37+
38+
c.begin();
39+
c.moveTo(0, this.startSize);
40+
c.lineTo(w - dx, this.startSize);
41+
c.stroke();
42+
};
43+
44+
mxCellRenderer.registerShape('awssf.layered', LayeredShape);
45+
Graph.handleFactory['awssf.layered'] = function (state) {
46+
var handles = [];
47+
handles.push(...Graph.handleFactory['swimlane'](state));
48+
// handles.push(...Graph.handleFactory['mxgraph.basic.layered_rect'](state));
49+
return handles;
50+
};

0 commit comments

Comments
 (0)