Skip to content

Commit

Permalink
RAP-896: Added missing docs/tests (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
chill117 committed May 31, 2016
1 parent fc836f2 commit f3c192d
Show file tree
Hide file tree
Showing 107 changed files with 2,062 additions and 921 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "5"
- "6"
- "4"
- "0.12"
- "0.10"
Expand All @@ -10,3 +10,6 @@ before_install:
- npm install -g bower

install: npm install

before_script:
- grunt install
58 changes: 33 additions & 25 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
TBD (v0.10.0)

TBD (v0.9.8)
* Changed the link tool event signature (e.g. `link:options`) to be the same as the rest of the cell events.
* Added paper.drawGrid(opt) - draws grid lines on the paper's DOM element.
* Added paper.setGridSize(gridSize) - changes the grid size of the paper.
* Added point.scale(), rect.scale() - scale point/rect with given origin.
* Added point.toJSON(), rect.toJSON() - converts point/rect into JSON object.
* Added dia.Element scale(), dia.Link scale() for transforming cells by providing a scale ratio and origin.
* Added dia.Graph resize(), resizeCells() for a group resizing
* Added dia.Graph getCellsBBox() for getting a group bounding box
* Added blank:mousewheel and cell:mousewheel events to paper
* Added env namespace with env.test(name) and env.addTest(name, fn) methods
* Added highlighters namespace with two highlighters (stroke and opacity). Highlighting now done automatically when: embedding an element, connecting a link to a port or element.
* Added Vectorizer transform() method to apply SVG matrix to SVG element
* Added Vectorizer empty(), before() method
* Vectorizer prepend() method accepts single or multiple nodes
* Vectorizer createSVGTrasform() accepts optionally an SVG matrix
* Added dia.Cell.isElement()
* Added dia.Graph.removeCells()
* Can now use dia.Graph.addCells(), dia.Graph.removeCells(), and dia.Graph.resetCells() with the same method signature. For example: dia.Graph.addCells(cell, cell) dia.Graph.addCells(cell, cell, opt) dia.Graph.addCells([cell, cell]) dia.Graph.addCells([cell, cell], opt) are all valid usage.
* Added layout.DirectedGraph.layout() `align` option for rank nodes alignment.
* Added paper.setInteractivity() for changing interactivity.
* Added link:connect, link:disconnect paper events for easier link source/target change detection
* Added leftMiddle(), rightMiddle(), topMiddle(), bottomMiddle() to geometry for finding middle points of rect sides.
* Added ellipse.fromRect(), rect.fromEllipse() to geometry for rect-ellipse interchangeability.
* JointJS:
* Added env namespace with env.test(name) and env.addTest(name, fn) methods
* Added highlighters namespace with two highlighters (stroke and opacity). Highlighting now done automatically when: embedding an element, connecting a link to a port or element.
* dia.Paper:
* Added paper.drawGrid(opt) - draws grid lines on the paper's DOM element.
* Added paper.setGridSize(gridSize) - changes the grid size of the paper.
* Added paper.setInteractivity() for changing interactivity.
* Added blank:mousewheel and cell:mousewheel events to paper
* Added link:connect, link:disconnect paper events for easier link source/target change detection
* Changed the link tool event signature (e.g. `link:options`) to be the same as the rest of the cell events.
* dia.Cell:
* Added isElement() and isLink() methods
* dia.Element:
* Added scale() for transforming element by providing a scale ratio and origin.
* dia.Link:
* Added scale() for transforming link by providing a scale ratio and origin.
* dia.Graph:
* Added resize(), resizeCells() for a group resizing
* Added getCellsBBox() for getting a group bounding box
* Added removeCells()
* Can now use addCells(), removeCells(), and resetCells() with the same method signature. For example: addCells(cell, cell) addCells(cell, cell, opt) addCells([cell, cell]) addCells([cell, cell], opt) are all valid usage.
* layout.DirectedGraph:
* Added layout() `align` option for rank nodes alignment.
* Vectorizer:
* Added transform() method to apply SVG matrix to SVG element
* Added empty(), before() method
* prepend() method now accepts single or multiple nodes
* createSVGTransform() now accepts optionally an SVG matrix
* Geometry:
* Added point.scale(), rect.scale() - scale point/rect with given origin.
* Added point.toJSON(), rect.toJSON() - converts point/rect into JSON object.
* Added leftMiddle(), rightMiddle(), topMiddle(), bottomMiddle() for finding middle points of rect sides.
* Added ellipse.fromRect(), rect.fromEllipse() for rect-ellipse interchangeability.

19-12-2015 (v0.9.6/v0.9.7)
* dia.Graph introduces new functions for traversing graphs: dfs(), bfs(), search(), isSuccessor(), isPredecessor(), getPredecessors(), getSuccessors(), isNeighbor(), isSource(), isSink(), getSources(), getSinks(), getSubgraph(), getFirstCell(), getLastCell() and getCells()
Expand Down
43 changes: 43 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ module.exports = function(grunt) {
cwd: 'build/',
src: [
'*',
'!docs',
'!min'
],
dest: 'dist/'
Expand All @@ -306,11 +307,47 @@ module.exports = function(grunt) {
cwd: 'docs/',
src: [
'css/**/*',
'demo/**/*',
'js/**/*',
'images/**/*'
],
dest: 'build/docs/'
},
{
nonull: true,
src: 'node_modules/backbone/backbone-min.js',
dest: 'build/docs/js/lib/backbone.min.js'
},
{
nonull: true,
src: 'node_modules/dagre/dist/dagre.min.js',
dest: 'build/docs/js/lib/dagre.min.js'
},
{
nonull: true,
src: 'node_modules/graphlib/dist/graphlib.min.js',
dest: 'build/docs/js/lib/graphlib.min.js'
},
{
nonull: true,
src: 'node_modules/jquery/dist/jquery.min.js',
dest: 'build/docs/js/lib/jquery.min.js'
},
{
nonull: true,
src: 'build/min/lodash.min.js',
dest: 'build/docs/js/lib/lodash.min.js'
},
{
nonull: true,
src: 'build/joint.min.js',
dest: 'build/docs/js/lib/joint.min.js'
},
{
nonull: true,
src: 'build/joint.min.css',
dest: 'build/docs/css/lib/joint.min.css'
},
{
expand: true,
flatten: true,
Expand Down Expand Up @@ -415,6 +452,11 @@ module.exports = function(grunt) {
options: {
ASCIIOnly: true
},
deps: {
files: {
'build/min/lodash.min.js': 'node_modules/lodash/index.js'
}
},
geometry: {
src: js.geometry,
dest: 'build/min/geometry.min.js'
Expand Down Expand Up @@ -652,6 +694,7 @@ module.exports = function(grunt) {

grunt.registerTask('build:joint', [
'build:plugins',
'newer:uglify:deps',
'newer:uglify:geometry',
'newer:uglify:vectorizer',
'newer:uglify:joint',
Expand Down
28 changes: 28 additions & 0 deletions docs/demo/layout/DirectedGraph/clusters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=Edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Rappid - Demo - layout.DirectedGraph - Clusters</title>
<link rel="stylesheet" type="text/css" href="../../../css/lib/joint.min.css">
</head>
<body>

<div id="paper"></div>

<!-- JointJS/Rappid dependencies: -->
<script src="../../../js/lib/jquery.min.js"></script>
<script src="../../../js/lib/lodash.min.js"></script>
<script src="../../../js/lib/backbone.min.js"></script>

<!-- DirectedGraph dependencies: -->
<script src="../../../js/lib/graphlib.min.js"></script>
<script src="../../../js/lib/dagre.min.js"></script>

<script src="../../../js/lib/joint.min.js"></script>

<script src="js/clusters.js"></script>

</body>
</html>
44 changes: 44 additions & 0 deletions docs/demo/layout/DirectedGraph/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=Edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Rappid - Demo - layout.DirectedGraph</title>
<link rel="stylesheet" type="text/css" href="../../../css/lib/joint.min.css">
</head>
<body>

<div>
<textarea id="adjacency-list" cols="50" rows="10">{
"My element": ["b", "c"],
"b": ["f"],
"c": ["e", "d"],
"d": [],
"e": [],
"f": ["g"],
"g": []
}</textarea>
<br>
<br>
<button id="btn-layout">layout</button>
<br>
<br>
<div id="paper"></div>
</div>

<!-- JointJS/Rappid dependencies: -->
<script src="../../../js/lib/jquery.min.js"></script>
<script src="../../../js/lib/lodash.min.js"></script>
<script src="../../../js/lib/backbone.min.js"></script>

<!-- DirectedGraph dependencies: -->
<script src="../../../js/lib/graphlib.min.js"></script>
<script src="../../../js/lib/dagre.min.js"></script>

<script src="../../../js/lib/joint.min.js"></script>

<script src="js/index.js"></script>

</body>
</html>
69 changes: 69 additions & 0 deletions docs/demo/layout/DirectedGraph/js/clusters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

(function() {

var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
el: $('#paper'),
width: 600,
height: 400,
gridSize: 1,
model: graph
});

function makeLink(el1, el2) {
var l = new joint.dia.Link({
source: { id: el1.id },
target: { id: el2.id },
attrs: {
'.connection': { stroke: 'gray' }
}
});
return l;
}

function makeElement(attrs) {
var el = new joint.shapes.basic.Rect({
size: { width: 30, height: 30 },
attrs: { rect: { rx: 2, ry: 2, fill: '#31D0C6', stroke: '#4B4A67', 'stroke-width': 2 }, text: { text: 'rect', fill: 'white' } }
});
el.attr(attrs);
return el;
}

var topGroup = makeElement({ text: { text: 'TopGroup', 'ref-y': 15 }});
var bottomGroup = makeElement({ text: { text: 'Bottom Group', 'ref-y': 15 }});
var group = makeElement({ text: { text: 'Group', 'ref-y': 15 }});

var ea = makeElement({ text: { text: 'a' }, rect: { fill: '#FE854F' }});
var eb = makeElement({ text: { text: 'b' }, rect: { fill: '#FE854F' }});
var ec = makeElement({ text: { text: 'c' }, rect: { fill: '#FE854F' }});
var ed = makeElement({ text: { text: 'd' }, rect: { fill: '#FE854F' }});
var ee = makeElement({ text: { text: 'e' }, rect: { fill: '#FE854F' }});
var ef = makeElement({ text: { text: 'f' }, rect: { fill: '#FE854F' }});
var eg = makeElement({ text: { text: 'g' }, rect: { fill: '#FE854F' }});
var eh = makeElement({ text: { text: 'h' }, rect: { fill: '#FE854F' }});

var lab = makeLink(ea, eb);
var lbc = makeLink(eb, ec);
var lbd = makeLink(eb, ed);
var lbe = makeLink(eb, ee);
var lbf = makeLink(eb, ef);
var lbg = makeLink(eb, eg);
var lhg = makeLink(eh, eg);

group.embed(topGroup).embed(bottomGroup);
topGroup.embed(eb).embed(eh);
bottomGroup.embed(ec).embed(ed).embed(ee).embed(ef);

graph.addCell([group, topGroup, bottomGroup, ea, eb, ec, ed, ed, ee, ef, eg, eh, lab, lbc, lbd, lbe, lbf, lbg, lhg]);

joint.layout.DirectedGraph.layout(graph, {
setLinkVertices: false,
rankDir: 'TB',
marginX: 50,
marginY: 50,
clusterPadding: { top: 30, left: 10, right: 10, bottom: 10 }
});

})();
101 changes: 101 additions & 0 deletions docs/demo/layout/DirectedGraph/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

(function() {

var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
el: $('#paper'),
width: 400,
height: 400,
gridSize: 1,
model: graph
});

$('#btn-layout').on('click', layout);

function layout() {

try {
var adjacencyList = JSON.parse($('#adjacency-list').val());
} catch (error) {
console.log(error);
}

var cells = adjacencyListToCells(adjacencyList);

graph.resetCells(cells);

joint.layout.DirectedGraph.layout(graph, {
setLinkVertices: false
});
}

// Helpers.
// --------

function adjacencyListToCells(adjacencyList) {

var elements = [];
var links = [];

_.each(adjacencyList, function(edges, parentElementLabel) {
elements.push(makeElement(parentElementLabel));

_.each(edges, function(childElementLabel) {
links.push(makeLink(parentElementLabel, childElementLabel));
});
});

// Links must be added after all the elements. This is because when the links
// are added to the graph, link source/target
// elements must be in the graph already.
var cells = elements.concat(links);

return cells;
}

function makeLink(parentElementLabel, childElementLabel) {

return new joint.dia.Link({
source: { id: parentElementLabel },
target: { id: childElementLabel },
attrs: {
'.marker-target': { d: 'M 4 0 L 0 2 L 4 4 z' }
},
smooth: true
});
}

function makeElement(label) {

var maxLineLength = _.max(label.split('\n'), function(l) {
return l.length;
}).length;

// Compute width/height of the rectangle based on the number
// of lines in the label and the letter size. 0.6 * letterSize is
// an approximation of the monospace font letter width.
var letterSize = 10;
var width = 2 * (letterSize * (0.6 * maxLineLength + 1));
var height = 2 * ((label.split('\n').length + 1) * letterSize);

return new joint.shapes.basic.Rect({
id: label,
size: { width: width, height: height },
attrs: {
text: { text: label, 'font-size': letterSize, 'font-family': 'monospace', fill: 'white' },
rect: {
fill: '#FE854F',
width: width,
height: height,
rx: 5,
ry: 5,
stroke: 'none'
}
}
});
}

layout();

})();
Loading

0 comments on commit f3c192d

Please sign in to comment.