blob: d869de79bf5f7aa6cc15f72f1884e2fe6d5ecc6c [file] [log] [blame]
/*global d3, document∆*/
function updateFlow(model) {
model.flows.forEach(function (flow) {
flow.flowId = flow.flowId.value;
flow.installerId = flow.installerId.value;
flow.dstDpid = flow.dataPath.dstPort.dpid.value;
flow.srcDpid = flow.dataPath.srcPort.dpid.value;
flow.dstPort = flow.dataPath.dstPort.port.value;
flow.srcPort = flow.dataPath.srcPort.port.value;
});
}
function sync() {
var d = Date.now();
updateModel(function (newModel) {
// console.log('Update time: ' + (Date.now() - d)/1000 + 's');
if (newModel) {
updateFlow(newModel);
var modelChanged = false;
var newModelString = JSON.stringify(newModel);
if (!modelString || newModelString != modelString) {
modelChanged = true;
model = newModel;
modelString = newModelString;
} else {
// console.log('no change');
}
if (modelChanged) {
updateControllers();
updateSelectedFlows();
updateTopology();
}
updateHeader(newModel);
d3.select('#contents').style('visibility', 'visible');
}
// do it again in 1s
setTimeout(function () {
sync()
}, 1000);
});
}
// workaround for another Chrome v25 bug
// viewbox transform stuff doesn't work in combination with browser zoom
// also works in Chrome v27
function zoomWorkaround() {
var zoom = window.document.body.clientWidth/window.document.width;
// workaround does not seem to be effective for transforming mouse coordinates
// map display does not use the transform stuff, so commenting out
// d3.select('#svg-container').style('zoom', zoom);
}
d3.select(window).on('resize', zoomWorkaround);
appInit(function () {
// workaround for Chrome v25 bug
// if executed immediately, the view box transform logic doesn't work properly
// fixed in Chrome v27
setTimeout(function () {
zoomWorkaround();
sync();
}, 100);
});