const meta2d = new Meta2d('meta2d',{
  background: '#1e2430',
  x: 32,
  y: 32,
  width: 1920,
  height: 1080,
  color: '#bdc7db',
});

registerCommonDiagram();

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split('&');
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split('=');
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
}

function _fetch(url, cb) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url, true);
  xhr.send();
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
      cb && cb(xhr.responseText);
    }
  };
}

var id = getQueryVariable('id');
if (!id) {
  id = 'data';
}
_fetch(id + '.json', function(text) {
  var data = JSON.parse(text);
  data.locked = 1;
  meta2d.open(data);
  let fit =
      meta2d.store.data.scaleMode === '3'
      ? 'height'
      : meta2d.store.data.scaleMode === '2'
      ? 'width'
      : true;
  meta2d.fitSizeView(fit, 10);
});

