Developing lightweight computation at the DSG edge

Commit c0905f79 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[assign-view] De-hardcode variables



Adjust the graph size to the window size and other automations.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 36f68768
...@@ -22,49 +22,66 @@ function posItemInArray(theItem, theArray) { ...@@ -22,49 +22,66 @@ function posItemInArray(theItem, theArray) {
return -1 return -1
} }
var drawing = SVG("assign").size(1000,1000) var wwidth = window.innerWidth -15;
if (wwidth < 400) {
wwidth = 400
}
var rwidth = 150
var rheight = 32
var rspace = 3
var rdist = rheight+rspace
var monX = wwidth-rwidth
var wheight = rdist*data.devices.length
var drawing = SVG("assign").size(wwidth,wheight)
var devsRects = new Array() var devsRects = new Array()
var devsTexts = new Array() var devsTexts = new Array()
var monsRects = new Array() var monsRects = new Array()
var monsTexts = new Array() var monsTexts = new Array()
var assignsLines = new Array() var assignsLines = new Array()
if (data.devices !== null ) { if (data.devices !== null ) {
for (i = 0; i < data.devices.length; i++) { for (i = 0; i < data.devices.length; i++) {
var rect = drawing.rect(200, 45).attr({ var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6ffe6", 'fill':"#e6ffe6",
'stroke':"gray", 'stroke':"gray",
'stroke-width':"2px" 'stroke-width':"2px"
}) })
rect.y(50*i) rect.y(rdist*i)
devsRects.push(rect) devsRects.push(rect)
var text = drawing.text(data.devices[i]).font({ var text = drawing.text(data.devices[i]).font({
'anchor':"middle" 'anchor':"middle"
}) })
text.x(100) text.x(rwidth/2)
text.y(10+50*i) text.y(rdist/4+rdist*i)
devsTexts.push(text) devsTexts.push(text)
} }
} }
if (data.monitors !== null ) { if (data.monitors !== null ) {
for (i = 0; i < data.monitors.length; i++) { for (i = 0; i < data.monitors.length; i++) {
var rect = drawing.rect(200, 45).attr({ var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6f2ff", 'fill':"#e6f2ff",
'stroke':"gray", 'stroke':"gray",
'stroke-width':"2px" 'stroke-width':"2px"
}) })
rect.x(500) rect.x(monX)
rect.y(50*i) rect.y(rdist*i)
monsRects.push(rect) monsRects.push(rect)
var text = drawing.text(data.monitors[i]).font({ var text = drawing.text(data.monitors[i]).font({
'anchor':"middle" 'anchor':"middle"
}) })
text.x(600) text.x(monX+rwidth/2)
text.y(10+50*i) text.y(10+rdist*i)
monsTexts.push(text) monsTexts.push(text)
} }
} }
...@@ -75,24 +92,14 @@ if (data.assignations !== null) { ...@@ -75,24 +92,14 @@ if (data.assignations !== null) {
for (j = 0; j < data.assignations[i].monitors.length; j++) { for (j = 0; j < data.assignations[i].monitors.length; j++) {
var devPos = posItemInArray(data.assignations[i].device, data.devices) var devPos = posItemInArray(data.assignations[i].device, data.devices)
var monPos = posItemInArray(data.assignations[i].monitors[j], data.monitors) var monPos = posItemInArray(data.assignations[i].monitors[j], data.monitors)
var line = drawing.line(200, 25+devPos*50, 500, 25+monPos*50).stroke({ width: 1 }) var line = drawing.line(rwidth, rdist/2+devPos*rdist, monX, 25+monPos*50).stroke({ width: 1.5 })
assignsLines.push(line) assignsLines.push(line)
} }
} }
} }
} }
// console.log(i) setTimeout(function(){
// if (data.assignations[i].monitors !== null && data.assignations[i].monitors.length > 0) { window.location.reload(true);
// for (j = 0; j < data.assignations[i].monitors.length; j++) { }, 2000);
// console.log("BBBBBBBB")
// console.log(data.assignations[i].monitors[j])
// var devPos = posItemInArray(data.assignations[i].device, data.devices)
// //var line = drawing.line(200, 25+devPos*50, 500, 25+monPos*50).stroke({ width: 1 })
// }
// }
//
//
// // assignsLines.push(line)
</script> </script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment