mermaid/src/diagrams/gitGraph/gitGraphRenderer.js

75 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-03-29 08:33:38 +05:30
var db = require('./gitGraphAst');
var gitGraphParser = require('./parser/gitGraph');
2016-03-29 08:33:38 +05:30
var d3 = require('../../d3');
var Logger = require('../../logger');
var log = new Logger.Log();
exports.setConf = function(config) {
}
2016-03-29 08:33:38 +05:30
exports.draw = function (txt, id, ver) {
try{
var parser;
parser = gitGraphParser.parser;
parser.yy = db;
2016-03-29 08:33:38 +05:30
log.debug('in gitgraph renderer', txt, id, ver);
// Parse the graph definition
parser.parse(txt + "\n");
2016-03-29 20:55:22 +05:30
var commits = db.getCommitsArray();
log.debug("# of commits: " + commits.length);
//log.debug("id: " + commits[0].id);
//log.debug(db.getCommits());
//log.debug("length:", commits.length);
//log.debug("length:", Object.keys(db.getCommits()).length);
// Fetch the default direction, use TD if none was found
var svg = d3.select('#'+id);
2016-03-29 08:33:38 +05:30
var nodes = svg
.selectAll("g")
.data(commits)
.enter()
.append("g")
.attr("class", "commit")
.attr("id", function(d){return d.id;})
.attr("transform", function(d,i){
return "translate(" + (50 + i*100) + ", 50)";
});
2016-03-29 08:33:38 +05:30
2016-03-29 20:55:22 +05:30
//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 raghu'+ ver);
2016-03-29 08:33:38 +05:30
var circles = svg.selectAll("g.commit")
2016-03-29 20:55:22 +05:30
.append("circle")
.attr("r", 15)
.attr("fill", "yellow")
.attr("stroke", "grey");
var textContainer = svg.selectAll("g.commit")
.append("g")
.attr("transform", "translate(-40, 35)")
.attr("class", "commit-label");
textContainer
.append("text")
.text(function(c){ return c.id; });
/*
var box = exports.bounds.getBounds();
2016-03-29 08:33:38 +05:30
var height = box.stopy-box.starty+2*conf.diagramMarginY;
var width = box.stopx-box.startx+2*conf.diagramMarginX;*/
2016-03-29 08:33:38 +05:30
svg.attr('height',100);
svg.attr('width', 400);
//svg.attr('viewBox', '0 0 300 150');
}catch(e) {
log.error("Error while rendering gitgraph");
log.error(e.message);
}
2016-03-29 08:33:38 +05:30
};