Skip to content

Commit

Permalink
* Draft implementation of info diagram
Browse files Browse the repository at this point in the history
* Fix for issue #109
  • Loading branch information
knsv committed Jan 20, 2015
1 parent 4850065 commit 44a2e04
Show file tree
Hide file tree
Showing 12 changed files with 2,244 additions and 44 deletions.
737 changes: 723 additions & 14 deletions dist/mermaid.full.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/mermaid.full.min.js

Large diffs are not rendered by default.

737 changes: 723 additions & 14 deletions dist/mermaid.slim.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ gulp.task('jison', shell.task([
'jison src/diagrams/flowchart/parser/flow.jison -o src/diagrams/flowchart/parser/flow.js',
'jison src/diagrams/flowchart/parser/dot.jison -o src/diagrams/flowchart/parser/dot.js',
'jison src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison -o src/diagrams/sequenceDiagram/parser/sequenceDiagram.js',
'jison src/diagrams/example/parser/example.jison -o src/diagrams/example/parser/example.js',
//'jison src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison -o src/diagrams/sequenceDiagram/parser/sequenceDiagram.js'
]));

Expand Down
25 changes: 25 additions & 0 deletions src/diagrams/example/example.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Created by knut on 14-11-18.
*/
describe('when parsing an info graph it',function() {
var parseError;
beforeEach(function () {
ex = require('./parser/example').parser;
ex.yy = require('./exampleDb');
parseError = function(err, hash) {
console.log('Syntax error:' + err);
};
ex.yy.parseError = parseError;
});

it('should handle an info definition', function () {
var str = 'info\nsay: hello';

ex.parse(str);
});
it('should handle an showMessage statement definition', function () {
var str = 'info\nshowInfo';

ex.parse(str);
});
});
23 changes: 23 additions & 0 deletions src/diagrams/example/exampleDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Created by knut on 15-01-14.
*/

var message = '';
var info = false;

exports.setMessage = function(txt){
message = txt;
};

exports.getMessage = function(){
return message;
};

exports.setInfo = function(inf){
info = inf;
};

exports.getInfo = function(){
return info;
};

44 changes: 44 additions & 0 deletions src/diagrams/example/exampleRenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Created by knut on 14-12-11.
*/
var db = require('./exampleDb');
var exampleParser = require('./parser/example.js');


/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
* @param text
* @param id
*/
exports.draw = function (txt, id, ver) {
var parser;
parser = exampleParser.parser;
parser.yy = db;

// Parse the graph definition
parser.parse(txt);

// Fetch the default direction, use TD if none was found
var svg = d3.select('#'+id);

var textstring = "mermaid!";
var g = svg.append("g");

g.append("text") // text label for the x axis
.attr("x", 100)
.attr("y", 40)
.attr('class','version')
.attr('font-size','32px')
.style("text-anchor", "middle")
.text('mermaid '+ ver);

/*
var box = exports.bounds.getBounds();
var height = box.stopy-box.starty+2*conf.diagramMarginY;
var width = box.stopx-box.startx+2*conf.diagramMarginX;*/

svg.attr("height",100);
svg.attr("width", 400 );
//svg.attr("viewBox", '0 0 300 150');
};
53 changes: 53 additions & 0 deletions src/diagrams/example/parser/example.jison
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/** js sequence diagrams
* http://bramp.github.io/js-sequence-diagrams/
* (c) 2012-2013 Andrew Brampton (bramp.net)
* Simplified BSD license.
*/
%lex

%options case-insensitive

%{
// Pre-lexer code can go here
%}

%%

[\n]+ return 'NL';
"showInfo" return 'showInfo';
"info" return 'info';
"say" return 'say';
":"[^#\n;]+ return 'TXT';
<<EOF>> return 'EOF';
. return 'INVALID';

/lex

%start start

%% /* language grammar */

start
: info document 'EOF' { return yy; }
;

document
: /* empty */
| document line
;

line
: statement { }
| 'NL'
;

statement
: showInfo { yy.setInfo(true); }
| message { yy.setMessage($1); }
;

message
: 'say' TXT { $$ = $1.substring(1).trim().replace(/\\n/gm, "\n"); }
;

%%
Loading

0 comments on commit 44a2e04

Please sign in to comment.