Developing lightweight computation at the DSG edge

Commit 7c81ec6a authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[assign-view] Distribute monitors evenly



Clean debris.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent c0905f79
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Record Mapper</title>
<meta name="description" content="A diagram for displaying and editing the N to M relationships from one set of objects to another set of objects." />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Copyright 1998-2019 by Northwoods Software Corporation. -->
<script src="gojs/go.js"></script>
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
validCycle: go.Diagram.CycleNotDirected, // don't allow loops
// For this sample, automatically show the state of the diagram's model on the page
"ModelChanged": function(e) {
if (e.isTransactionFinished) showModel();
},
"undoManager.isEnabled": true
});
// This template is a Panel that is used to represent each item in a Panel.itemArray.
// The Panel is data bound to the item object.
var fieldTemplate =
$(go.Panel, "TableRow", // this Panel is a row in the containing Table
new go.Binding("portId", "name"), // this Panel is a "port"
{
background: "transparent", // so this port's background can be picked by the mouse
fromSpot: go.Spot.Right, // links only go from the right side to the left side
toSpot: go.Spot.Left,
// allow drawing links from or to this port:
fromLinkable: true, toLinkable: true
},
$(go.Shape,
{
width: 12, height: 12, column: 0, strokeWidth: 2, margin: 4,
// but disallow drawing links from or to this shape:
fromLinkable: false, toLinkable: false
},
new go.Binding("figure", "figure"),
new go.Binding("fill", "color")),
$(go.TextBlock,
{
margin: new go.Margin(0, 5), column: 1, font: "bold 13px sans-serif",
alignment: go.Spot.Left,
// and disallow drawing links from or to this text:
fromLinkable: false, toLinkable: false
},
new go.Binding("text", "name")),
$(go.TextBlock,
{ margin: new go.Margin(0, 5), column: 2, font: "13px sans-serif", alignment: go.Spot.Left },
new go.Binding("text", "info"))
);
// This template represents a whole "record".
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{ copyable: false, deletable: false },
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
// this rectangular shape surrounds the content of the node
$(go.Shape,
{ fill: "#EEEEEE" }),
// the content consists of a header and a list of items
$(go.Panel, "Vertical",
// this is the header for the whole node
$(go.Panel, "Auto",
{ stretch: go.GraphObject.Horizontal }, // as wide as the whole node
$(go.Shape,
{ fill: "#1570A6", stroke: null }),
$(go.TextBlock,
{
alignment: go.Spot.Center,
margin: 3,
stroke: "white",
textAlign: "center",
font: "bold 12pt sans-serif"
},
new go.Binding("text", "key"))),
// this Panel holds a Panel for each item object in the itemArray;
// each item Panel is defined by the itemTemplate to be a TableRow in this Table
$(go.Panel, "Table",
{
padding: 2,
minSize: new go.Size(100, 10),
defaultStretch: go.GraphObject.Horizontal,
itemTemplate: fieldTemplate
},
new go.Binding("itemArray", "fields")
) // end Table Panel of items
) // end Vertical Panel
); // end Node
myDiagram.linkTemplate =
$(go.Link,
{
relinkableFrom: true, relinkableTo: true, // let user reconnect links
toShortLength: 4, fromShortLength: 2
},
$(go.Shape, { strokeWidth: 1.5 }),
$(go.Shape, { toArrow: "Standard", stroke: null })
);
myDiagram.model =
$(go.GraphLinksModel,
{
copiesArrays: true,
copiesArrayObjects: true,
linkFromPortIdProperty: "fromPort",
linkToPortIdProperty: "toPort",
nodeDataArray: [
{
key: "Record1",
fields: [
{ name: "field1", info: "", color: "#F7B84B", figure: "Ellipse" },
{ name: "field2", info: "the second one", color: "#F25022", figure: "Ellipse" },
{ name: "fieldThree", info: "3rd", color: "#00BCF2" }
],
loc: "0 0"
},
{
key: "Record2",
fields: [
{ name: "fieldA", info: "", color: "#FFB900", figure: "Diamond" },
{ name: "fieldB", info: "", color: "#F25022", figure: "Rectangle" },
{ name: "fieldC", info: "", color: "#7FBA00", figure: "Diamond" },
{ name: "fieldD", info: "fourth", color: "#00BCF2", figure: "Rectangle" }
],
loc: "280 0"
}
],
linkDataArray: [
{ from: "Record1", fromPort: "field1", to: "Record2", toPort: "fieldA" },
{ from: "Record1", fromPort: "field2", to: "Record2", toPort: "fieldA" },
{ from: "Record1", fromPort: "field2", to: "Record2", toPort: "fieldD" },
{ from: "Record1", fromPort: "fieldThree", to: "Record2", toPort: "fieldB" }
]
});
showModel(); // show the diagram's initial model
function showModel() {
document.getElementById("mySavedModel").textContent = myDiagram.model.toJson();
<div id="assign"></div>
<script src="./svg.min.js"></script>
<script src="/tmp/out.json"></script>
<script>
// data={"devices":["35578","35580","41236","52800","53410","55625","58266","66287","67954","69514","74780","74943","75036","75038","75651","92844"],"monitors":["1","2","3","444"],"assignations":[{"device":"35578","monitors":["2"]},{"device":"35580","monitors":["1"]},{"device":"41236","monitors":["1"]},{"device":"52800","monitors":["1","2"]},{"device":"53410","monitors":["2"]},{"device":"55625","monitors":["1","2"]},{"device":"58266","monitors":["2"]},{"device":"66287","monitors":null},{"device":"67954","monitors":["1","2"]},{"device":"69514","monitors":["1","2"]},{"device":"74780","monitors":["1"]},{"device":"74943","monitors":["1","2"]},{"device":"75036","monitors":["1","2"]},{"device":"75038","monitors":null},{"device":"75651","monitors":["2"]},{"device":"92844","monitors":["1"]}]}
//
// dsata={"devices":["35578","35580","41236","52800","53410","55625","58266","66287","67954","69514","74780","74943","75036","75038","75651","92844"],"monitors":["1","2"],"assignations":[{"device":"35578","monitors":["2"]},{"device":"35580","monitors":["1"]},{"device":"92844","monitors":["1"]}]}
function posItemInArray(theItem, theArray) {
console.log("theItem " + theItem)
console.log("theArray " + theArray)
if (theItem !== null && theArray !== null && theArray.length > 0) {
for (k=0; k<theArray.length; k++) {
if (theItem == theArray[k]) {
return k
}
}
</script>
</head>
<body onload="init()">
<div id="sample">
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:300px"></div>
<!-- <p>This record mapper shows a number of "fields" for each "record" and how they are mapped between each other.</p> -->
<!-- <p>
Draw new links by dragging from the background of any field.
Reconnect a selected link by dragging its diamond-shaped handle.
The "record" Nodes use a <a>Panel,Table</a> to place the various fields into rows.
Records are not movable or copyable or deletable.
</p> -->
<!-- <p>For a variation on this sample with selectable fields in the record nodes, see the <a href="selectableFields.html">selectable fields</a> sample.</p> -->
<div>
Diagram Model saved in JSON format, automatically updated after each change or undo or redo:
<textarea id="mySavedModel" style="width:100%;height:250px"></textarea>
</div>
</div>
</body>
</html>
}
return -1
}
var wwidth = window.innerWidth -15;
if (wwidth < 400) {
wwidth = 400
}
var wheight = window.innerHeight -15;
if (wheight < 400) {
wheight = 400
}
var rwidth = 150
var rheight = 32
var rspace = 3
var rdist = rheight+rspace
var monX = wwidth-rwidth
var fontsize ="12px"
var dheight = rdist*data.devices.length
var drawing = SVG("assign").size(wwidth,dheight)
var devsRects = new Array()
var devsTexts = new Array()
var monsRects = new Array()
var monsTexts = new Array()
var assignsLines = new Array()
if (data.devices !== null ) {
for (i = 0; i < data.devices.length; i++) {
var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6ffe6",
'stroke':"gray",
'stroke-width':"2px"
})
rect.y(rdist*i)
devsRects.push(rect)
var text = drawing.text(data.devices[i]).font({
'anchor':"middle",
'size':fontsize
})
text.x(rwidth/2)
text.y(rdist/4+rdist*i)
devsTexts.push(text)
}
}
if (data.monitors !== null ) {
for (i = 0; i < data.monitors.length; i++) {
var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6f2ff",
'stroke':"gray",
'stroke-width':"2px"
})
rect.x(monX)
rect.y((dheight/data.monitors.length)*i+rdist*i/2)
monsRects.push(rect)
var text = drawing.text(data.monitors[i]).font({
'anchor':"middle",
'size':fontsize
})
text.x(monX+rwidth/2)
text.y((dheight/data.monitors.length)*i+rdist*i/2+rdist/4)
monsTexts.push(text)
}
}
if (data.assignations !== null) {
for (i = 0; i < data.assignations.length; i++) {
if (data.assignations[i].monitors !== null) {
for (j = 0; j < data.assignations[i].monitors.length; j++) {
var devPos = posItemInArray(data.assignations[i].device, data.devices)
var monPos = posItemInArray(data.assignations[i].monitors[j], data.monitors)
var line = drawing.line(rwidth, rdist/2+devPos*rdist, monX, (dheight/Math.max(1,data.monitors.length))*monPos+rdist*monPos/2+rdist/2).stroke({ width: 1.5 })
assignsLines.push(line)
}
}
}
}
setTimeout(function(){
window.location.reload(true);
}, 2000);
</script>
<div id="assign"></div>
<script src="./svg.min.js"></script>
<script src="/tmp/out.json"></script>
<script>
// data={"devices":["35578","35580","41236","52800","53410","55625","58266","66287","67954","69514","74780","74943","75036","75038","75651","92844"],"monitors":["1","2","3","444"],"assignations":[{"device":"35578","monitors":["2"]},{"device":"35580","monitors":["1"]},{"device":"41236","monitors":["1"]},{"device":"52800","monitors":["1","2"]},{"device":"53410","monitors":["2"]},{"device":"55625","monitors":["1","2"]},{"device":"58266","monitors":["2"]},{"device":"66287","monitors":null},{"device":"67954","monitors":["1","2"]},{"device":"69514","monitors":["1","2"]},{"device":"74780","monitors":["1"]},{"device":"74943","monitors":["1","2"]},{"device":"75036","monitors":["1","2"]},{"device":"75038","monitors":null},{"device":"75651","monitors":["2"]},{"device":"92844","monitors":["1"]}]}
//
// dsata={"devices":["35578","35580","41236","52800","53410","55625","58266","66287","67954","69514","74780","74943","75036","75038","75651","92844"],"monitors":["1","2"],"assignations":[{"device":"35578","monitors":["2"]},{"device":"35580","monitors":["1"]},{"device":"92844","monitors":["1"]}]}
function posItemInArray(theItem, theArray) {
console.log("theItem " + theItem)
console.log("theArray " + theArray)
if (theItem !== null && theArray !== null && theArray.length > 0) {
for (k=0; k<theArray.length; k++) {
if (theItem == theArray[k]) {
return k
}
}
}
return -1
}
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 devsTexts = new Array()
var monsRects = new Array()
var monsTexts = new Array()
var assignsLines = new Array()
if (data.devices !== null ) {
for (i = 0; i < data.devices.length; i++) {
var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6ffe6",
'stroke':"gray",
'stroke-width':"2px"
})
rect.y(rdist*i)
devsRects.push(rect)
var text = drawing.text(data.devices[i]).font({
'anchor':"middle"
})
text.x(rwidth/2)
text.y(rdist/4+rdist*i)
devsTexts.push(text)
}
}
if (data.monitors !== null ) {
for (i = 0; i < data.monitors.length; i++) {
var rect = drawing.rect(rwidth, rheight).attr({
'fill':"#e6f2ff",
'stroke':"gray",
'stroke-width':"2px"
})
rect.x(monX)
rect.y(rdist*i)
monsRects.push(rect)
var text = drawing.text(data.monitors[i]).font({
'anchor':"middle"
})
text.x(monX+rwidth/2)
text.y(10+rdist*i)
monsTexts.push(text)
}
}
if (data.assignations !== null) {
for (i = 0; i < data.assignations.length; i++) {
if (data.assignations[i].monitors !== null) {
for (j = 0; j < data.assignations[i].monitors.length; j++) {
var devPos = posItemInArray(data.assignations[i].device, data.devices)
var monPos = posItemInArray(data.assignations[i].monitors[j], data.monitors)
var line = drawing.line(rwidth, rdist/2+devPos*rdist, monX, 25+monPos*50).stroke({ width: 1.5 })
assignsLines.push(line)
}
}
}
}
setTimeout(function(){
window.location.reload(true);
}, 2000);
</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