Skip to content

Two pages json.html and objects.html #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://flowchart.js.org/flowchart-latest.js"></script>
<!--<script src="../release/flowchart.min.js"></script>-->
<!--<script src="http://flowchart.js.org/flowchart-latest.js"></script>-->
<script src="../release/flowchart.js"></script>
<script>

window.onload = function () {
Expand Down
251 changes: 251 additions & 0 deletions example/json.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>flowchart.js · Playground</title>
<style type="text/css">
.end-element { background-color : #FFCCFF; }
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!--<script src="http://flowchart.js.org/flowchart-latest.js"></script>-->
<script src="../release/flowchart.js"></script>
<script>

window.onload = function () {
var btn = document.getElementById("run"),
cd = document.getElementById("code"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're already putting these on their own lines just declare the "var" for each. Makes your intentions a little clearer.

chart;

(btn.onclick = function () {
var code = cd.value;

if (chart) {
chart.clean();
}



var data = JSON.parse(code);

var symbols=data.symbols;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing/formatting

var directions=data.directions;


var symbolsArray ={};
for(var key in symbols)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going with this C style curly braces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad idea in JavaScript. Every newLine triggers a “Should a ; be auto inserted. In compiled languages like C and Java the position of the { is a question of taste (and a source of religious wars second only to tabs vs spaces). In JavaScript it matters. Keep them at line end.

var symbol=symbols[key];
symbolsArray[symbol.key]=symbol;
}


var directionsArray = {};

for(var key in directions)
{
var direction=directions[key];
directionsArray[direction.key+"_"+direction.nextKey+"_"+direction.next]=direction;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a note of these extra spaces and formatting between expressions.


chart = flowchart.parseObject(symbolsArray, directionsArray);


chart.drawSVG('canvas', {
// 'x': 30,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dead code

// 'y': 50,
'line-width': 3,
'line-length': 50,
'text-margin': 10,
'font-size': 14,
'font': 'normal',
'font-family': 'Helvetica',
'font-weight': 'normal',
'font-color': 'black',
'line-color': 'black',
'element-color': 'black',
'fill': 'white',
'yes-text': 'yes',
'no-text': 'no',
'arrow-end': 'block',
'scale': 1,
'symbols': {
'start': {
'font-color': 'red',
'element-color': 'green',
'fill': 'yellow'
},
'end':{
'class': 'end-element'
}
},
'flowstate' : {
'past' : { 'fill' : '#CCCCCC', 'font-size' : 12},
'current' : {'fill' : 'yellow', 'font-color' : 'red', 'font-weight' : 'bold'},
'future' : { 'fill' : '#FFFF99'},
'request' : { 'fill' : 'blue'},
'invalid': {'fill' : '#444444'},
'approved' : { 'fill' : '#58C4A3', 'font-size' : 12, 'yes-text' : 'APPROVED', 'no-text' : 'n/a' },
'rejected' : { 'fill' : '#C45879', 'font-size' : 12, 'yes-text' : 'n/a', 'no-text' : 'REJECTED' }
}
});

$('[id^=sub1]').click(function(){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is this supposed to do?

alert('info here');
});
})();

};
</script>
</head>
<body>
<div><textarea id="code" style="width: 100%;" rows="11">
{
"symbols":[
{
"key":"st",
"symbolType":"start",
"text":"Start",
"link":"http://www.google.com",
"target":"blank",
"flowstate":"past"
},
{
"key":"e",
"symbolType":"end",
"text":"End",
"link":"http://www.google.com",
"target":null,
"flowstate":null
},
{
"key":"op1",
"symbolType":"operation",
"text":"My Operation",
"link":null,
"target":null,
"flowstate":"past"
},
{
"key":"op2",
"symbolType":"operation",
"text":"Stuff",
"link":null,
"target":null,
"flowstate":"current"
},
{
"key":"sub1",
"symbolType":"subroutine",
"text":"My Subroutine",
"link":null,
"target":null,
"flowstate":"invalid"
},
{
"key":"cond",
"symbolType":"condition",
"text":"Yes or No?",
"link":"http://www.google.com",
"target":null,
"flowstate":"approved"
},
{
"key":"c2",
"symbolType":"condition",
"text":"Good idea",
"link":null,
"target":null,
"flowstate":"rejected"
},
{
"key":"io",
"symbolType":"inputoutput",
"text":"catch something...",
"link":null,
"target":null,
"flowstate":"request"
}
],
"directions":[
{
"key":"st",
"symbolType":"start",
"nextKey":"op1",
"nextSymbolType":"operation",
"next":"next",
"direction":null
},
{
"key":"op1",
"symbolType":"operation",
"nextKey":"cond",
"nextSymbolType":"condition",
"next":"next",
"direction":"right"
},
{
"key":"cond",
"symbolType":"condition",
"nextKey":"c2",
"nextSymbolType":"condition",
"next":"yes",
"direction":"right"
},
{
"key":"cond",
"symbolType":"condition",
"nextKey":"sub1",
"nextSymbolType":"subroutine",
"next":"no",
"direction":null
},
{
"key":"sub1",
"symbolType":"subroutine",
"nextKey":"op1",
"nextSymbolType":"operation",
"next":"next",
"direction":"left"
},
{
"key":"c2",
"symbolType":"condition",
"nextKey":"io",
"nextSymbolType":"inputoutput",
"next":"yes",
"direction":null
},
{
"key":"io",
"symbolType":"inputoutput",
"nextKey":"e",
"nextSymbolType":"end",
"next":"next",
"direction":null
},
{
"key":"c2",
"symbolType":"condition",
"nextKey":"op2",
"nextSymbolType":"operation",
"next":"no",
"direction":null
},
{
"key":"op2",
"symbolType":"operation",
"nextKey":"e",
"nextSymbolType":"end",
"next":"next",
"direction":null
}
]
}
</textarea></div>
<div><button id="run" type="button">Run</button></div>
<div id="canvas"></div>
</body>
</html>

Loading