mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
Fix code style issues
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ test/tmp_*
|
|||||||
test/fixtures/samples/*.actual*
|
test/fixtures/samples/*.actual*
|
||||||
|
|
||||||
dist/*.js
|
dist/*.js
|
||||||
|
todo.md
|
||||||
|
@@ -172,7 +172,7 @@ var setClickFun = function (id, functionName) {
|
|||||||
var elem = d3.select(element).select('#' + id)
|
var elem = d3.select(element).select('#' + id)
|
||||||
if (elem !== null) {
|
if (elem !== null) {
|
||||||
elem.on('click', function () {
|
elem.on('click', function () {
|
||||||
eval(functionName + '(\'' + id + '\')') // jshint ignore:line
|
window[functionName](id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -314,7 +314,8 @@ exports.defaultStyle = function () {
|
|||||||
*/
|
*/
|
||||||
exports.addSubGraph = function (list, title) {
|
exports.addSubGraph = function (list, title) {
|
||||||
function uniq (a) {
|
function uniq (a) {
|
||||||
var prims = {'boolean': {}, 'number': {}, 'string': {}}, objs = []
|
var prims = {'boolean': {}, 'number': {}, 'string': {}}
|
||||||
|
var objs = []
|
||||||
|
|
||||||
return a.filter(function (item) {
|
return a.filter(function (item) {
|
||||||
var type = typeof item
|
var type = typeof item
|
||||||
|
@@ -70,7 +70,7 @@ var getStartDate = function (prevTime, dateFormat, str) {
|
|||||||
str = str.trim()
|
str = str.trim()
|
||||||
|
|
||||||
// Test for after
|
// Test for after
|
||||||
var re = /^after\s+([\d\w\-]+)/
|
var re = /^after\s+([\d\w-]+)/
|
||||||
var afterStatement = re.exec(str.trim())
|
var afterStatement = re.exec(str.trim())
|
||||||
|
|
||||||
if (afterStatement !== null) {
|
if (afterStatement !== null) {
|
||||||
|
@@ -41,15 +41,15 @@ module.exports.draw = function (text, id) {
|
|||||||
|
|
||||||
var taskArray = gantt.yy.getTasks()
|
var taskArray = gantt.yy.getTasks()
|
||||||
|
|
||||||
// Set height based on number of tasks
|
// Set height based on number of tasks
|
||||||
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding
|
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding
|
||||||
|
|
||||||
elem.setAttribute('height', '100%')
|
elem.setAttribute('height', '100%')
|
||||||
// Set viewBox
|
// Set viewBox
|
||||||
elem.setAttribute('viewBox', '0 0 ' + w + ' ' + h)
|
elem.setAttribute('viewBox', '0 0 ' + w + ' ' + h)
|
||||||
var svg = d3.select('#' + id)
|
var svg = d3.select('#' + id)
|
||||||
|
|
||||||
// var dateFormat = d3.time.format('%Y-%m-%d');
|
// var dateFormat = d3.time.format('%Y-%m-%d');
|
||||||
|
|
||||||
var startDate = d3.min(taskArray, function (d) {
|
var startDate = d3.min(taskArray, function (d) {
|
||||||
return d.startTime
|
return d.startTime
|
||||||
@@ -58,16 +58,16 @@ module.exports.draw = function (text, id) {
|
|||||||
return d.endTime
|
return d.endTime
|
||||||
})
|
})
|
||||||
|
|
||||||
// Set timescale
|
// Set timescale
|
||||||
var timeScale = d3.time.scale()
|
var timeScale = d3.time.scale()
|
||||||
.domain([d3.min(taskArray, function (d) {
|
.domain([d3.min(taskArray, function (d) {
|
||||||
return d.startTime
|
return d.startTime
|
||||||
}),
|
}),
|
||||||
d3.max(taskArray, function (d) {
|
d3.max(taskArray, function (d) {
|
||||||
return d.endTime
|
return d.endTime
|
||||||
})])
|
})])
|
||||||
.rangeRound([0, w - conf.leftPadding - conf.rightPadding])
|
.rangeRound([0, w - conf.leftPadding - conf.rightPadding])
|
||||||
// .nice(d3.time.monday);
|
// .nice(d3.time.monday);
|
||||||
|
|
||||||
var categories = []
|
var categories = []
|
||||||
|
|
||||||
@@ -87,10 +87,10 @@ module.exports.draw = function (text, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
svg.append('text')
|
svg.append('text')
|
||||||
.text(gantt.yy.getTitle())
|
.text(gantt.yy.getTitle())
|
||||||
.attr('x', w / 2)
|
.attr('x', w / 2)
|
||||||
.attr('y', conf.titleTopMargin)
|
.attr('y', conf.titleTopMargin)
|
||||||
.attr('class', 'titleText')
|
.attr('class', 'titleText')
|
||||||
|
|
||||||
function makeGant (tasks, pageWidth, pageHeight) {
|
function makeGant (tasks, pageWidth, pageHeight) {
|
||||||
var barHeight = conf.barHeight
|
var barHeight = conf.barHeight
|
||||||
@@ -99,9 +99,9 @@ module.exports.draw = function (text, id) {
|
|||||||
var leftPadding = conf.leftPadding
|
var leftPadding = conf.leftPadding
|
||||||
|
|
||||||
var colorScale = d3.scale.linear()
|
var colorScale = d3.scale.linear()
|
||||||
.domain([0, categories.length])
|
.domain([0, categories.length])
|
||||||
.range(['#00B9FA', '#F95002'])
|
.range(['#00B9FA', '#F95002'])
|
||||||
.interpolate(d3.interpolateHcl)
|
.interpolate(d3.interpolateHcl)
|
||||||
|
|
||||||
makeGrid(leftPadding, topPadding, pageWidth, pageHeight)
|
makeGrid(leftPadding, topPadding, pageWidth, pageHeight)
|
||||||
drawRects(tasks, gap, topPadding, leftPadding, barHeight, colorScale, pageWidth, pageHeight)
|
drawRects(tasks, gap, topPadding, leftPadding, barHeight, colorScale, pageWidth, pageHeight)
|
||||||
@@ -111,148 +111,148 @@ module.exports.draw = function (text, id) {
|
|||||||
|
|
||||||
function drawRects (theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) { // eslint-disable-line no-unused-vars
|
function drawRects (theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) { // eslint-disable-line no-unused-vars
|
||||||
svg.append('g')
|
svg.append('g')
|
||||||
.selectAll('rect')
|
.selectAll('rect')
|
||||||
.data(theArray)
|
.data(theArray)
|
||||||
.enter()
|
.enter()
|
||||||
.append('rect')
|
.append('rect')
|
||||||
.attr('x', 0)
|
.attr('x', 0)
|
||||||
.attr('y', function (d, i) {
|
.attr('y', function (d, i) {
|
||||||
return i * theGap + theTopPad - 2
|
return i * theGap + theTopPad - 2
|
||||||
})
|
})
|
||||||
.attr('width', function () {
|
.attr('width', function () {
|
||||||
return w - conf.rightPadding / 2
|
return w - conf.rightPadding / 2
|
||||||
})
|
})
|
||||||
.attr('height', theGap)
|
.attr('height', theGap)
|
||||||
.attr('class', function (d) { // eslint-disable-line no-unused-vars
|
.attr('class', function (d) { // eslint-disable-line no-unused-vars
|
||||||
for (var i = 0; i < categories.length; i++) {
|
for (var i = 0; i < categories.length; i++) {
|
||||||
if (d.type === categories[i]) {
|
if (d.type === categories[i]) {
|
||||||
return 'section section' + (i % conf.numberSectionStyles)
|
return 'section section' + (i % conf.numberSectionStyles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'section section0'
|
return 'section section0'
|
||||||
})
|
})
|
||||||
|
|
||||||
var rectangles = svg.append('g')
|
var rectangles = svg.append('g')
|
||||||
.selectAll('rect')
|
.selectAll('rect')
|
||||||
.data(theArray)
|
.data(theArray)
|
||||||
.enter()
|
.enter()
|
||||||
|
|
||||||
rectangles.append('rect')
|
rectangles.append('rect')
|
||||||
.attr('rx', 3)
|
.attr('rx', 3)
|
||||||
.attr('ry', 3)
|
.attr('ry', 3)
|
||||||
.attr('x', function (d) {
|
.attr('x', function (d) {
|
||||||
return timeScale(d.startTime) + theSidePad
|
return timeScale(d.startTime) + theSidePad
|
||||||
})
|
})
|
||||||
.attr('y', function (d, i) {
|
.attr('y', function (d, i) {
|
||||||
return i * theGap + theTopPad
|
return i * theGap + theTopPad
|
||||||
})
|
})
|
||||||
.attr('width', function (d) {
|
.attr('width', function (d) {
|
||||||
return (timeScale(d.endTime) - timeScale(d.startTime))
|
return (timeScale(d.endTime) - timeScale(d.startTime))
|
||||||
})
|
})
|
||||||
.attr('height', theBarHeight)
|
.attr('height', theBarHeight)
|
||||||
.attr('class', function (d) {
|
.attr('class', function (d) {
|
||||||
var res = 'task '
|
var res = 'task '
|
||||||
|
|
||||||
var secNum = 0
|
var secNum = 0
|
||||||
for (var i = 0; i < categories.length; i++) {
|
for (var i = 0; i < categories.length; i++) {
|
||||||
if (d.type === categories[i]) {
|
if (d.type === categories[i]) {
|
||||||
secNum = (i % conf.numberSectionStyles)
|
secNum = (i % conf.numberSectionStyles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.active) {
|
if (d.active) {
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
return res + ' activeCrit' + secNum
|
return res + ' activeCrit' + secNum
|
||||||
} else {
|
} else {
|
||||||
return res + ' active' + secNum
|
return res + ' active' + secNum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.done) {
|
if (d.done) {
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
return res + ' doneCrit' + secNum
|
return res + ' doneCrit' + secNum
|
||||||
} else {
|
} else {
|
||||||
return res + ' done' + secNum
|
return res + ' done' + secNum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
return res + ' crit' + secNum
|
return res + ' crit' + secNum
|
||||||
}
|
}
|
||||||
|
|
||||||
return res + ' task' + secNum
|
return res + ' task' + secNum
|
||||||
})
|
})
|
||||||
|
|
||||||
rectangles.append('text')
|
rectangles.append('text')
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
return d.task
|
return d.task
|
||||||
})
|
})
|
||||||
.attr('font-size', conf.fontSize)
|
.attr('font-size', conf.fontSize)
|
||||||
// .attr('font-family',conf.fontFamily)
|
// .attr('font-family',conf.fontFamily)
|
||||||
.attr('x', function (d) {
|
.attr('x', function (d) {
|
||||||
var startX = timeScale(d.startTime),
|
var startX = timeScale(d.startTime)
|
||||||
endX = timeScale(d.endTime),
|
var endX = timeScale(d.endTime)
|
||||||
textWidth = this.getBBox().width
|
var textWidth = this.getBBox().width
|
||||||
|
|
||||||
// Check id text width > width of rectangle
|
// Check id text width > width of rectangle
|
||||||
if (textWidth > (endX - startX)) {
|
if (textWidth > (endX - startX)) {
|
||||||
if (endX + textWidth + 1.5 * conf.leftPadding > w) {
|
if (endX + textWidth + 1.5 * conf.leftPadding > w) {
|
||||||
return startX + theSidePad - 5
|
return startX + theSidePad - 5
|
||||||
} else {
|
} else {
|
||||||
return endX + theSidePad + 5
|
return endX + theSidePad + 5
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return (endX - startX) / 2 + startX + theSidePad
|
return (endX - startX) / 2 + startX + theSidePad
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.attr('y', function (d, i) {
|
.attr('y', function (d, i) {
|
||||||
return i * theGap + (conf.barHeight / 2) + (conf.fontSize / 2 - 2) + theTopPad
|
return i * theGap + (conf.barHeight / 2) + (conf.fontSize / 2 - 2) + theTopPad
|
||||||
})
|
})
|
||||||
// .attr('text-anchor', 'middle')
|
// .attr('text-anchor', 'middle')
|
||||||
.attr('text-height', theBarHeight)
|
.attr('text-height', theBarHeight)
|
||||||
.attr('class', function (d) {
|
.attr('class', function (d) {
|
||||||
var startX = timeScale(d.startTime),
|
var startX = timeScale(d.startTime)
|
||||||
endX = timeScale(d.endTime),
|
var endX = timeScale(d.endTime)
|
||||||
textWidth = this.getBBox().width
|
var textWidth = this.getBBox().width
|
||||||
var secNum = 0
|
var secNum = 0
|
||||||
for (var i = 0; i < categories.length; i++) {
|
for (var i = 0; i < categories.length; i++) {
|
||||||
if (d.type === categories[i]) {
|
if (d.type === categories[i]) {
|
||||||
secNum = (i % conf.numberSectionStyles)
|
secNum = (i % conf.numberSectionStyles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskType = ''
|
var taskType = ''
|
||||||
if (d.active) {
|
if (d.active) {
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
taskType = 'activeCritText' + secNum
|
taskType = 'activeCritText' + secNum
|
||||||
} else {
|
} else {
|
||||||
taskType = 'activeText' + secNum
|
taskType = 'activeText' + secNum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.done) {
|
if (d.done) {
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
taskType = taskType + ' doneCritText' + secNum
|
taskType = taskType + ' doneCritText' + secNum
|
||||||
} else {
|
} else {
|
||||||
taskType = taskType + ' doneText' + secNum
|
taskType = taskType + ' doneText' + secNum
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (d.crit) {
|
if (d.crit) {
|
||||||
taskType = taskType + ' critText' + secNum
|
taskType = taskType + ' critText' + secNum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check id text width > width of rectangle
|
// Check id text width > width of rectangle
|
||||||
if (textWidth > (endX - startX)) {
|
if (textWidth > (endX - startX)) {
|
||||||
if (endX + textWidth + 1.5 * conf.leftPadding > w) {
|
if (endX + textWidth + 1.5 * conf.leftPadding > w) {
|
||||||
return 'taskTextOutsideLeft taskTextOutside' + secNum + ' ' + taskType
|
return 'taskTextOutsideLeft taskTextOutside' + secNum + ' ' + taskType
|
||||||
} else {
|
} else {
|
||||||
return 'taskTextOutsideRight taskTextOutside' + secNum + ' ' + taskType
|
return 'taskTextOutsideRight taskTextOutside' + secNum + ' ' + taskType
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 'taskText taskText' + secNum + ' ' + taskType
|
return 'taskText taskText' + secNum + ' ' + taskType
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeGrid (theSidePad, theTopPad, w, h) {
|
function makeGrid (theSidePad, theTopPad, w, h) {
|
||||||
@@ -263,7 +263,7 @@ module.exports.draw = function (text, id) {
|
|||||||
[':%S', function (d) {
|
[':%S', function (d) {
|
||||||
return d.getSeconds()
|
return d.getSeconds()
|
||||||
}],
|
}],
|
||||||
// Within a hour
|
// Within a hour
|
||||||
['h1 %I:%M', function (d) {
|
['h1 %I:%M', function (d) {
|
||||||
return d.getMinutes()
|
return d.getMinutes()
|
||||||
}]]
|
}]]
|
||||||
@@ -273,20 +273,20 @@ module.exports.draw = function (text, id) {
|
|||||||
}]]
|
}]]
|
||||||
|
|
||||||
var mid = [
|
var mid = [
|
||||||
// Within a day
|
// Within a day
|
||||||
['%I:%M', function (d) {
|
['%I:%M', function (d) {
|
||||||
return d.getHours()
|
return d.getHours()
|
||||||
}],
|
}],
|
||||||
// Day within a week (not monday)
|
// Day within a week (not monday)
|
||||||
['%a %d', function (d) {
|
['%a %d', function (d) {
|
||||||
// return d.getDay() ==1;
|
// return d.getDay() ==1;
|
||||||
return d.getDay() && d.getDate() != 1
|
return d.getDay() && d.getDate() !== 1
|
||||||
}],
|
}],
|
||||||
// within a month
|
// within a month
|
||||||
['%b %d', function (d) {
|
['%b %d', function (d) {
|
||||||
return d.getDate() != 1
|
return d.getDate() !== 1
|
||||||
}],
|
}],
|
||||||
// Month
|
// Month
|
||||||
['%B', function (d) {
|
['%B', function (d) {
|
||||||
return d.getMonth()
|
return d.getMonth()
|
||||||
}]
|
}]
|
||||||
@@ -304,25 +304,25 @@ module.exports.draw = function (text, id) {
|
|||||||
formatter = pre.concat(mid).concat(post)
|
formatter = pre.concat(mid).concat(post)
|
||||||
|
|
||||||
var xAxis = d3.svg.axis()
|
var xAxis = d3.svg.axis()
|
||||||
.scale(timeScale)
|
.scale(timeScale)
|
||||||
.orient('bottom')
|
.orient('bottom')
|
||||||
.tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0)
|
.tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0)
|
||||||
.tickFormat(d3.time.format.multi(formatter))
|
.tickFormat(d3.time.format.multi(formatter))
|
||||||
|
|
||||||
if (daysInChart > 7 && daysInChart < 230) {
|
if (daysInChart > 7 && daysInChart < 230) {
|
||||||
xAxis = xAxis.ticks(d3.time.monday.range)
|
xAxis = xAxis.ticks(d3.time.monday.range)
|
||||||
}
|
}
|
||||||
|
|
||||||
svg.append('g')
|
svg.append('g')
|
||||||
.attr('class', 'grid')
|
.attr('class', 'grid')
|
||||||
.attr('transform', 'translate(' + theSidePad + ', ' + (h - 50) + ')')
|
.attr('transform', 'translate(' + theSidePad + ', ' + (h - 50) + ')')
|
||||||
.call(xAxis)
|
.call(xAxis)
|
||||||
.selectAll('text')
|
.selectAll('text')
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.attr('fill', '#000')
|
.attr('fill', '#000')
|
||||||
.attr('stroke', 'none')
|
.attr('stroke', 'none')
|
||||||
.attr('font-size', 10)
|
.attr('font-size', 10)
|
||||||
.attr('dy', '1em')
|
.attr('dy', '1em')
|
||||||
}
|
}
|
||||||
|
|
||||||
function vertLabels (theGap, theTopPad) {
|
function vertLabels (theGap, theTopPad) {
|
||||||
@@ -334,52 +334,53 @@ module.exports.draw = function (text, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
svg.append('g') // without doing this, impossible to put grid lines behind text
|
svg.append('g') // without doing this, impossible to put grid lines behind text
|
||||||
.selectAll('text')
|
.selectAll('text')
|
||||||
.data(numOccurances)
|
.data(numOccurances)
|
||||||
.enter()
|
.enter()
|
||||||
.append('text')
|
.append('text')
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
return d[0]
|
return d[0]
|
||||||
})
|
})
|
||||||
.attr('x', 10)
|
.attr('x', 10)
|
||||||
.attr('y', function (d, i) {
|
.attr('y', function (d, i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
for (var j = 0; j < i; j++) {
|
for (var j = 0; j < i; j++) {
|
||||||
prevGap += numOccurances[i - 1][1]
|
prevGap += numOccurances[i - 1][1]
|
||||||
// log.debug(prevGap);
|
// log.debug(prevGap);
|
||||||
return d[1] * theGap / 2 + prevGap * theGap + theTopPad
|
return d[1] * theGap / 2 + prevGap * theGap + theTopPad
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return d[1] * theGap / 2 + theTopPad
|
return d[1] * theGap / 2 + theTopPad
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.attr('class', function (d) {
|
.attr('class', function (d) {
|
||||||
for (var i = 0; i < categories.length; i++) {
|
for (var i = 0; i < categories.length; i++) {
|
||||||
if (d[0] === categories[i]) {
|
if (d[0] === categories[i]) {
|
||||||
return 'sectionTitle sectionTitle' + (i % conf.numberSectionStyles)
|
return 'sectionTitle sectionTitle' + (i % conf.numberSectionStyles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'sectionTitle'
|
return 'sectionTitle'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawToday (theSidePad, theTopPad, w, h) {
|
function drawToday (theSidePad, theTopPad, w, h) {
|
||||||
var todayG = svg.append('g')
|
var todayG = svg.append('g')
|
||||||
.attr('class', 'today')
|
.attr('class', 'today')
|
||||||
|
|
||||||
var today = new Date()
|
var today = new Date()
|
||||||
|
|
||||||
todayG.append('line')
|
todayG.append('line')
|
||||||
.attr('x1', timeScale(today) + theSidePad)
|
.attr('x1', timeScale(today) + theSidePad)
|
||||||
.attr('x2', timeScale(today) + theSidePad)
|
.attr('x2', timeScale(today) + theSidePad)
|
||||||
.attr('y1', conf.titleTopMargin)
|
.attr('y1', conf.titleTopMargin)
|
||||||
.attr('y2', h - conf.titleTopMargin)
|
.attr('y2', h - conf.titleTopMargin)
|
||||||
.attr('class', 'today')
|
.attr('class', 'today')
|
||||||
}
|
}
|
||||||
|
|
||||||
// from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
|
// from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
|
||||||
function checkUnique (arr) {
|
function checkUnique (arr) {
|
||||||
var hash = {}, result = []
|
var hash = {}
|
||||||
|
var result = []
|
||||||
for (var i = 0, l = arr.length; i < l; ++i) {
|
for (var i = 0, l = arr.length; i < l; ++i) {
|
||||||
if (!hash.hasOwnProperty(arr[i])) { // it works with objects! in FF, at least
|
if (!hash.hasOwnProperty(arr[i])) { // it works with objects! in FF, at least
|
||||||
hash[arr[i]] = true
|
hash[arr[i]] = true
|
||||||
@@ -389,17 +390,17 @@ module.exports.draw = function (text, id) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
|
// from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
|
||||||
function getCounts (arr) {
|
function getCounts (arr) {
|
||||||
var i = arr.length, // var to loop over
|
var i = arr.length // var to loop over
|
||||||
obj = {} // obj to store results
|
var obj = {} // obj to store results
|
||||||
while (i) {
|
while (i) {
|
||||||
obj[arr[--i]] = (obj[arr[i]] || 0) + 1 // count occurrences
|
obj[arr[--i]] = (obj[arr[i]] || 0) + 1 // count occurrences
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
// get specific from everything
|
// get specific from everything
|
||||||
function getCount (word, arr) {
|
function getCount (word, arr) {
|
||||||
return getCounts(arr)[word] || 0
|
return getCounts(arr)[word] || 0
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ function getId () {
|
|||||||
|
|
||||||
function isfastforwardable (currentCommit, otherCommit) {
|
function isfastforwardable (currentCommit, otherCommit) {
|
||||||
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id)
|
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id)
|
||||||
while (currentCommit.seq <= otherCommit.seq && currentCommit != otherCommit) {
|
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit) {
|
||||||
// only if other branch has more commits
|
// only if other branch has more commits
|
||||||
if (otherCommit.parent == null) break
|
if (otherCommit.parent == null) break
|
||||||
if (Array.isArray(otherCommit.parent)) {
|
if (Array.isArray(otherCommit.parent)) {
|
||||||
@@ -36,7 +36,7 @@ function isfastforwardable (currentCommit, otherCommit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug(currentCommit.id, otherCommit.id)
|
log.debug(currentCommit.id, otherCommit.id)
|
||||||
return currentCommit.id == otherCommit.id
|
return currentCommit.id === otherCommit.id
|
||||||
}
|
}
|
||||||
|
|
||||||
function isReachableFrom (currentCommit, otherCommit) {
|
function isReachableFrom (currentCommit, otherCommit) {
|
||||||
@@ -118,7 +118,7 @@ exports.reset = function (commitRef) {
|
|||||||
log.debug('in reset', commitRef)
|
log.debug('in reset', commitRef)
|
||||||
var ref = commitRef.split(':')[0]
|
var ref = commitRef.split(':')[0]
|
||||||
var parentCount = parseInt(commitRef.split(':')[1])
|
var parentCount = parseInt(commitRef.split(':')[1])
|
||||||
var commit = ref == 'HEAD' ? head : commits[branches[ref]]
|
var commit = ref === 'HEAD' ? head : commits[branches[ref]]
|
||||||
log.debug(commit, parentCount)
|
log.debug(commit, parentCount)
|
||||||
while (parentCount > 0) {
|
while (parentCount > 0) {
|
||||||
commit = commits[commit.parent]
|
commit = commits[commit.parent]
|
||||||
@@ -148,7 +148,7 @@ function prettyPrintCommitHistory (commitArr) {
|
|||||||
var commit = _.maxBy(commitArr, 'seq')
|
var commit = _.maxBy(commitArr, 'seq')
|
||||||
var line = ''
|
var line = ''
|
||||||
_.each(commitArr, function (c) {
|
_.each(commitArr, function (c) {
|
||||||
if (c == commit) {
|
if (c === commit) {
|
||||||
line += '\t*'
|
line += '\t*'
|
||||||
} else {
|
} else {
|
||||||
line += '\t|'
|
line += '\t|'
|
||||||
@@ -156,7 +156,7 @@ function prettyPrintCommitHistory (commitArr) {
|
|||||||
})
|
})
|
||||||
var label = [line, commit.id, commit.seq]
|
var label = [line, commit.id, commit.seq]
|
||||||
_.each(branches, function (v, k) {
|
_.each(branches, function (v, k) {
|
||||||
if (v == commit.id) label.push(k)
|
if (v === commit.id) label.push(k)
|
||||||
})
|
})
|
||||||
log.debug(label.join(' '))
|
log.debug(label.join(' '))
|
||||||
if (Array.isArray(commit.parent)) {
|
if (Array.isArray(commit.parent)) {
|
||||||
|
@@ -73,9 +73,9 @@ function svgDrawLine (svg, points, colorIdx, interpolate) {
|
|||||||
// Pass in the element and its pre-transform coords
|
// Pass in the element and its pre-transform coords
|
||||||
function getElementCoords (element, coords) {
|
function getElementCoords (element, coords) {
|
||||||
coords = coords || element.node().getBBox()
|
coords = coords || element.node().getBBox()
|
||||||
var ctm = element.node().getCTM(),
|
var ctm = element.node().getCTM()
|
||||||
xn = ctm.e + coords.x * ctm.a,
|
var xn = ctm.e + coords.x * ctm.a
|
||||||
yn = ctm.f + coords.y * ctm.d
|
var yn = ctm.f + coords.y * ctm.d
|
||||||
// log.debug(ctm, coords);
|
// log.debug(ctm, coords);
|
||||||
return {
|
return {
|
||||||
left: xn,
|
left: xn,
|
||||||
@@ -96,7 +96,7 @@ function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
|
|||||||
// +--------
|
// +--------
|
||||||
// + (fromBbox)
|
// + (fromBbox)
|
||||||
if (fromBbox.left - toBbox.left > config.nodeSpacing) {
|
if (fromBbox.left - toBbox.left > config.nodeSpacing) {
|
||||||
var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2}
|
var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2 }
|
||||||
var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 }
|
var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 }
|
||||||
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
|
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
|
||||||
svgDrawLine(svg, [
|
svgDrawLine(svg, [
|
||||||
@@ -126,7 +126,7 @@ function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
|
|||||||
// |
|
// |
|
||||||
// + (toBbox)
|
// + (toBbox)
|
||||||
if (toBbox.top - fromBbox.top > config.nodeSpacing) {
|
if (toBbox.top - fromBbox.top > config.nodeSpacing) {
|
||||||
lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing}
|
lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing }
|
||||||
lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top }
|
lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top }
|
||||||
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
|
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
|
||||||
svgDrawLine(svg, [
|
svgDrawLine(svg, [
|
||||||
|
@@ -7,14 +7,14 @@ var proxyquire = require('proxyquire')
|
|||||||
// var log = require('../../logger').create();
|
// var log = require('../../logger').create();
|
||||||
|
|
||||||
var sq = require('./parser/sequenceDiagram').parser
|
var sq = require('./parser/sequenceDiagram').parser
|
||||||
var newD3
|
var NewD3
|
||||||
|
|
||||||
var d3 = {
|
var d3 = {
|
||||||
select: function () {
|
select: function () {
|
||||||
return new newD3()
|
return new NewD3()
|
||||||
},
|
},
|
||||||
selectAll: function () {
|
selectAll: function () {
|
||||||
return new newD3()
|
return new NewD3()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
|
// var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
|
||||||
@@ -773,10 +773,10 @@ describe('when rendering a sequenceDiagram', function () {
|
|||||||
// };
|
// };
|
||||||
// sq.yy.parseError = parseError;
|
// sq.yy.parseError = parseError;
|
||||||
|
|
||||||
newD3 = function () {
|
NewD3 = function () {
|
||||||
var o = {
|
var o = {
|
||||||
append: function () {
|
append: function () {
|
||||||
return newD3()
|
return NewD3()
|
||||||
},
|
},
|
||||||
attr: function () {
|
attr: function () {
|
||||||
return this
|
return this
|
||||||
@@ -998,10 +998,10 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio
|
|||||||
// };
|
// };
|
||||||
// sq.yy.parseError = parseError;
|
// sq.yy.parseError = parseError;
|
||||||
|
|
||||||
newD3 = function () {
|
NewD3 = function () {
|
||||||
var o = {
|
var o = {
|
||||||
append: function () {
|
append: function () {
|
||||||
return newD3()
|
return NewD3()
|
||||||
},
|
},
|
||||||
attr: function () {
|
attr: function () {
|
||||||
return this
|
return this
|
||||||
|
@@ -82,7 +82,7 @@ exports.bounds = {
|
|||||||
_self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
|
_self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||||
_self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
_self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||||
|
|
||||||
if (!(type == 'activation')) {
|
if (!(type === 'activation')) {
|
||||||
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
|
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||||
_self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
_self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ module.exports.setConf = function (cnf) {
|
|||||||
|
|
||||||
var actorActivations = function (actor) {
|
var actorActivations = function (actor) {
|
||||||
return module.exports.bounds.activations.filter(function (activation) {
|
return module.exports.bounds.activations.filter(function (activation) {
|
||||||
return activation.actor == actor
|
return activation.actor === actor
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ module.exports.draw = function (text, id) {
|
|||||||
exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
|
exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastMsg
|
// var lastMsg
|
||||||
|
|
||||||
// Draw the messages/signals
|
// Draw the messages/signals
|
||||||
messages.forEach(function (msg) {
|
messages.forEach(function (msg) {
|
||||||
@@ -448,7 +448,7 @@ module.exports.draw = function (text, id) {
|
|||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
lastMsg = msg
|
// lastMsg = msg
|
||||||
exports.bounds.bumpVerticalPos(conf.messageMargin)
|
exports.bounds.bumpVerticalPos(conf.messageMargin)
|
||||||
var fromBounds = actorFlowVerticaBounds(msg.from)
|
var fromBounds = actorFlowVerticaBounds(msg.from)
|
||||||
var toBounds = actorFlowVerticaBounds(msg.to)
|
var toBounds = actorFlowVerticaBounds(msg.to)
|
||||||
|
Reference in New Issue
Block a user