pbs/src/pert-ui.coffee

40 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2015-03-14 09:42:05 +01:00
$.get 'data', (d) ->
# Serve the server data
2015-03-30 12:47:38 +02:00
buildTimeline d
buildGraph d
toDates = (list, startDay) ->
list.map (i) ->
r = content: ""+i.id, id: i.id
if i.startDay? then r.start = moment(startDay).add(i.startDay, 'days').format 'YYYY-MM-DD'
if i.endDay? then r.end = moment(startDay).add(i.endDay, 'days').format 'YYYY-MM-DD'
return r
buildTimeline = (data) ->
console.log toDates data.activities
timeline = new vis.Timeline (document.getElementById 'timeline'), (toDates data.activities), {}
2015-03-14 09:42:05 +01:00
buildGraph = (data) ->
2015-03-13 21:03:11 +01:00
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
data.activities.forEach (x) ->
connections.push
from: x.startDay, to: x.endDay
label: x.id+" ("+(if x.permittedDelay > 0 then x.duration+"/"+(x.duration+x.permittedDelay) else x.duration)+")"
2015-03-16 11:44:08 +01:00
color: if !x.permittedDelay then 'red'
2015-03-13 21:03:11 +01:00
if x.permittedDelay > 0
2015-03-14 09:42:05 +01:00
connections.push
from: x.endDay
to: x.endDay+x.permittedDelay
color: 'green'
label: x.id+" ("+x.permittedDelay+")"
2015-03-13 21:03:11 +01:00
console.log nodes
console.log connections
2015-03-14 09:42:05 +01:00
if network
network.setData { nodes: nodes, edges: edges }
else
options =
edges:
style: 'arrow'
network = new vis.Network (document.getElementById 'pert'), { nodes: nodes, edges: connections }, options