-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforest.js
49 lines (48 loc) · 1.77 KB
/
forest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//This file is a nightmare and is in desperate need of refactoring
var forest = module.exports = {}
var loadClasses = require('./loadClasses.js')
var SvgTree = require('svg-tree')
forest.build = function buildForest(opts,cb) {
opts.treeOpts = opts.treeOpts || {}
opts.onClick = opts.onClick || function(){}
opts.onHover = opts.onHover || function(){}
var result = {}
loadClasses(function(e,tracks) {
if(e) return console.log(e)
Object.keys(tracks).forEach(function(trackName) {
result[trackName] = {}
var track = tracks[trackName]
result[trackName] = {
button : {
title:trackName,
rune:track.rune
},
courseTree: new SvgTree(opts.treeOpts),
track: track
} //end result[trackName].button
var courses = []
Object.keys(track.track).forEach(function(courseName) {
var course = track.track[courseName]
var courseSvg = track.svgTree[courseName]
courses[courseName] = result[trackName].courseTree.CreateCell({
"x":courseSvg.x,"y":courseSvg.y,"rune":courseSvg.rune
})
.on('click',function() {
opts.onClick(track.track[courseName])
})
.on('hover',function() {
opts.onHover(track.track[courseName])
})
.index
}) // end Object.keys(track.track).forEach
Object.keys(track.track).forEach(function(courseName) {
var course = track.track[courseName]
if(!course.deps) return
course.deps.forEach(function(dep) {
result[trackName].courseTree.addEdge(courses[courseName],courses[dep])
}) // end course.deps.forEach
}) //end Object.keys(track.track).forEach
}) //end Object.keys(tracks).forEach
cb(result)
}) //end loadClasses
} //end forest.build