
var _data_list = [];

var partner_data = undefined;
var partner_profile = undefined;
var partner_limit = 5;

function fetchDataAndRenderContent () {
  _data_list.length = 0;
  renderCharts();
  extractDataAndUpdateContent();
}

function extractDataAndUpdateContent () {
  updateFetchProgress(100);

  renderOrUpdateGaugeRowItemsWithAnimation(extractGauageRowData());
  updateCharts(extractChartData());

  updateFetchCounter();
  updateFetchProgress(0);
}

function extractChartData (_limit) {
  _limit = _limit || 100;
  var _raw_list = _data_list.slice(-_limit);
  var _data_set = {};

  $.each(gauge_data, function (index, item) {
    var _list = [];
    $.each(_raw_list, function (index, record) {
      var _record = {};
      _record.date = $.format.date(record[item.id].time, 'yyyy-MM-dd HH:mm:ss');
      _record.value = _formatReadableFloat(record[item.id].value);
      _list.push(_record);
    });
    _data_set[item.id] = _list;
  });

  $.each(partner_data, function (index, item) {
    var _list = [];
    $.each(_raw_list, function (index, record) {
      var _value = [];
      var _base_value = record[item.parent_id].value;
      for (var i = 0; i < partner_limit; i++) {
        _value.push(_base_value * 0.15 * (1 + (Math.random() - 0.35) * (partner_limit - i) / (partner_limit) ));
      };
      var _record = {};
      _record.date = $.format.date(record[item.parent_id].time, 'yyyy-MM-dd HH:mm:ss');
      _record.value = _value;
      _list.push(_record);
    });
    _data_set[item.id] = _list;
  });
  
  return _data_set;
}

function extractGauageRowData () {
  if (!_data_list.length) {
    fetchMockupData();
  }
  var _set = _data_list.slice(-1)[0];
  var _data = $.extend(true, {}, gauge_data);
  $.each(_data, function (index, item) {
    item.time = _set[item.id].time;
    item.value = _set[item.id].value;
  });
  return _data;
}

function initializePartnersForCharts () {
  partner_profile = fetchMockupTopPartnersProfile(partner_limit);

  partner_data = $.extend(true, {}, gauge_data);
  $.each(partner_data, function (index, label_data) {
    label_data.name = "Top Partners - " + label_data.name; 
    label_data.parent_id = label_data.id;
    label_data.id += "-part";
  });
}

function fetchMockupTopPartnersProfile (_limit) {
  _limit = _limit || 5;
  var _list = flattenConfigIntoList(menu_part_data);
  _list.sort(function () { return 0.5 - Math.random() });
  return _list.slice(-_limit);
}

function fetchMockupData () {
  var _set = {};
  var _date = new Date();
  var _last_set = _data_list.length ? _data_list.slice(-1)[0] : undefined;
  $.each(gauge_data, function (index, item) {
    var _item = {};
    _item.time = _date;
    _item.value = _last_set ? _last_set[item.id].value : item.value;
    _item.value *= (1 + (Math.random() - 0.5) * 0.1);
    _set[item.id] = _item;
  });
  _data_list.push(_set);
}

@@ -1075,18 +1075,107 @@
 ar _
-value = %5B%5D
+record = %7B%7D;%0A      _record.date = $.format.date(record%5Bitem.parent_id%5D.time, 'yyyy-MM-dd HH:mm:ss')
 ;%0A  
@@ -1287,19 +1287,30 @@
    _
-value.push(
+record%5B%22value%22 + i%5D = 
 _bas
@@ -1394,17 +1394,16 @@
 _limit) 
-)
 );%0A     
@@ -1410,150 +1410,8 @@
  %7D;%0A
-      var _record = %7B%7D;%0A      _record.date = $.format.date(record%5Bitem.parent_id%5D.time, 'yyyy-MM-dd HH:mm:ss');%0A      _record.value = _value;%0A
     

Use value0/1/2/3/4 instead of value[] for mockup chart data for top 5 partners