Guest User

Untitled

a guest
Aug 19th, 2017
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script language="Javascript">
  2.  
  3.   var url = "";
  4.  
  5.     //Cross browser method to get an object
  6.     function getObject(id)
  7.     {
  8.         if (document.getElementById)
  9.         //IE 5.x or NS 6.x or above
  10.         return document.getElementById(id);
  11.         else if (document.all)
  12.         //IE 4.x
  13.         return document.all[id];
  14.         else
  15.         //Netscape 4.x
  16.         return document[id];
  17.     }
  18.  
  19.     function setMarket(m) {
  20.         getObject('m').value = m;
  21.         updateChart(1);
  22.     }
  23.  
  24.     var resizeTimeout = false;
  25.  
  26.     jQuery(window).resize( function() {
  27.         clearTimeout(resizeTimeout);
  28.         resizeTimeout = setTimeout("updateChart(0, true)", 100);
  29.     });
  30.  
  31.     //Update the chart according to user selection
  32.     function updateChart(updateURL, noclear)
  33.     {
  34.         resizeTimeout = false;
  35.         var box = jQuery('#content_chart');
  36.     var boxwidth = box.innerWidth() - 40;
  37.         //
  38.         //we encode the values of all form elements as query parameters
  39.         //
  40.         var elements = getObject("chartoptions").elements;
  41.     url = "";
  42.         var hash = new Array();
  43.         var market = "";
  44.         for (var i = 0; i < elements.length; ++i)
  45.         {
  46.             var e = elements[i];
  47.             if (e.type == "checkbox")
  48.             url = url + e.id + "=" + (e.checked ? "1" : "0") + "&";
  49.             else
  50.             url = url + e.id + "=" + escape(e.value) + "&";
  51.  
  52.             if(e.id == "m") {
  53.                 market = e.value;
  54.                 } else if (e.type != "submit") {
  55.         if (e.type == "checkbox") {
  56.           if(e.checked)
  57.                     hash.push(e.id)
  58.         } else if (e.value)
  59.                 hash.push(e.id + "g" + escape(e.value));
  60.             }
  61.         }
  62.  
  63.     if(updateURL > 0) {
  64.       urlhash = hash.join("z");
  65.       new_url = location.href.replace(/\/[^/]+$/, "/") + market + '#' + urlhash;
  66.       jQuery('#permalink').val(new_url);
  67.         if (typeof history.pushState == 'function')  {
  68.             if(updateURL == 2)
  69.                 history.replaceState("m=" + market + "," + urlhash, document.title, market + '#' + urlhash);
  70.             else
  71.                 history.pushState("m=" + market + "," + urlhash, document.title, market + '#' + urlhash);
  72.         }
  73.     }
  74.  
  75.         //Now we update the URL of the image to update the chart
  76.         var d = new Date;
  77.  
  78.         var img = getObject("ChartImage");
  79.         img.src = "chart.png?width=" + boxwidth + "&" + url;
  80.  
  81.         img.onload = function() {
  82.             return;
  83.             var img = jQuery(this);
  84.             var o = jQuery('#ChartOverlay');
  85.             o.width(this.width);
  86.             o.height(this.height);
  87.  
  88.             o.css('position', 'absolute');
  89.             o.css('left', img.offset()['left']);
  90.             o.css('top', img.offset()['top']);
  91.         };
  92.  
  93.     if (!noclear) clear_table();
  94.  
  95.     if (updateURL == 1)
  96.       ga('send', 'pageview', location.pathname);
  97.   }
  98.  
  99.   function load_table() {
  100.     var table = jQuery("#chart_table");
  101.     table.show();
  102.  
  103.     update_table('chart.json?' + url);
  104.  
  105.     return false;
  106.   }
  107.  
  108.   function clear_table() {
  109.     var table = jQuery("#chart_table");
  110.     table.children("tbody tr").remove();
  111.     table.hide();
  112.  
  113.   }
  114.  
  115.   function update_table(url) {
  116.     var table = jQuery("#chart_table tbody");
  117.     table.children().remove();
  118.     table.append("<tr><td colspan=8>Loading...</td></tr>");
  119.  
  120.     jQuery.getJSON(url, null, function (data) {
  121.       table.children().remove();
  122.  
  123.       if (!data) {
  124.         table.append("<tr><td colspan=8>No data returned.</td></tr>");
  125.         return;
  126.       }
  127.  
  128.       function round(a, n) {
  129.         if (a == "—")
  130.           return a;
  131.  
  132.         return Math.round(a * Math.pow(10,  n)) / Math.pow(10, n);
  133.       }
  134.  
  135.       function ISODateString(d) {
  136.           function pad(n){
  137.               return n<10 ? '0'+n : n
  138.           }
  139.           return d.getUTCFullYear()+'-'
  140.           + pad(d.getUTCMonth()+1)+'-'
  141.           + pad(d.getUTCDate())+' '
  142.           + pad(d.getUTCHours())+':'
  143.           + pad(d.getUTCMinutes())+':'
  144.           + pad(d.getUTCSeconds());
  145.       }
  146.  
  147.       for (var i = 0; i < data.length; i++){
  148.         var timestamp = new Date();
  149.         timestamp.setTime(data[i][0] * 1000);
  150.  
  151.         for (var j = 1; j < 8; j++) {
  152.           if (data[i][j] == 1.7e308)
  153.             data[i][j] = "—";
  154.         }
  155.  
  156.         var o = data[i][1];
  157.         var h = data[i][2];
  158.         var l = data[i][3];
  159.         var c = data[i][4];
  160.         var v = data[i][5];
  161.         var cv = data[i][6];
  162.         var avg = data[i][7];
  163.  
  164.         if (v == 0) continue;
  165.  
  166.         row = [ISODateString(timestamp), o, h, l, c, round(v, 2), round(cv, 2), round(avg, 2)];
  167.  
  168.  
  169.         table.append("<tr><td>" + row.join("</td><td>") + "</td></tr>");
  170.       }
  171.  
  172.     });
  173.   }
  174.  
  175.     function customTime() {
  176.         var c = document.getElementById("c").checked;
  177.         if(c) {
  178.             var d = parseInt(document.getElementById("r").value);
  179.             if(d == 0) {
  180.                 d = 29;
  181.             }
  182.             var x = "-" + (d-1) + "d";
  183.             jQuery("#s").datepicker("setDate", x);
  184.             jQuery("#e").datepicker("setDate", "1d");
  185.             jQuery("#CustomTimeBox").show();
  186.             jQuery("#r").hide();
  187.         } else {
  188.       jQuery("#s").val("");
  189.       jQuery("#e").val("");
  190.             jQuery("#CustomTimeBox").hide();
  191.             jQuery("#r").show();
  192.     }
  193.     }
  194.  
  195.     window.onpopstate = function(e) {
  196.         if(e.state.length > 0)
  197.             parseHash(e.state);
  198.  
  199.         updateChart(0);
  200.     };
  201.  
  202.     jQuery(document).ready(function(){
  203.         jQuery("#CustomTimeBox").hide();
  204.         var hash = location.hash.substring(1);
  205.  
  206.         if(hash.length > 0)
  207.             parseHash(hash);
  208.  
  209.         customTime();
  210.  
  211.         jQuery("#s").datepicker({ dateFormat: 'yy-mm-dd' });
  212.         jQuery("#e").datepicker({ dateFormat: 'yy-mm-dd' });
  213.  
  214.         updateChart(2);
  215.         jQuery("#chartoptions").change( function() {
  216.             updateChart(1);
  217.         });
  218.  
  219.         jQuery("#c").change( function() {
  220.             customTime();
  221.         });
  222.  
  223.         jQuery("#r").change( function() {
  224.             document.getElementById("c").checked = false;
  225.         });
  226.  
  227.         jQuery("#Prev").click( function() {
  228.             if(document.getElementById("c").checked == false) {
  229.                 jQuery("#c").click();
  230.             }
  231.             s = document.getElementById("s");
  232.             e = document.getElementById("e");
  233.             s.value = Date.parse(s.value).add(-1).days().toString("yyyy-MM-dd");
  234.             e.value = Date.parse(e.value).add(-1).days().toString("yyyy-MM-dd");
  235.         });
  236.         jQuery("#Next").click( function() {
  237.             if(document.getElementById("c").checked == false) {
  238.                 jQuery("#c").click();
  239.             }
  240.             s = document.getElementById("s");
  241.             e = document.getElementById("e");
  242.             s.value = Date.parse(s.value).add(1).days().toString("yyyy-MM-dd");
  243.             e.value = Date.parse(e.value).add(1).days().toString("yyyy-MM-dd");
  244.         });
  245.  
  246.         jQuery("#getPermalink").fancybox({'transitionIn': 'none', 'transitionOut': 'none', 'scrolling': 'no', 'titleShow': false, 'overlayShow': false});
  247.     });
  248.  
  249.  
  250.   var old_width = "";
  251.  
  252.   function fullWidth() {
  253.     if (old_width == "")
  254.       old_width = jQuery("#content_chart").css("width");
  255.  
  256.     var w = jQuery("#content_chart").css("width");
  257.  
  258.     if (w != old_width) {
  259.       jQuery("#content_chart").css("width", old_width);
  260.     } else {
  261.       jQuery("#content_chart").css("width", "auto");
  262.     }
  263.  
  264.         updateChart(0);
  265.  
  266.     return false;
  267.   }
  268.  
  269.  
  270.     function parseHash(hash) {
  271.         /* Reset timerange, volume and chart type if hash is supplied.
  272.             They expect different 0/none as defaults    */
  273.         getObject("v").checked = false;
  274.         getObject("t").value = "";
  275.         getObject("r").value = "";
  276.  
  277.         var data = hash.split('z');
  278.         for (var i = 0; i < data.length; ++i) {
  279.             var x = data[i].split('g');
  280.             if(e = getObject(x.shift())) {
  281.                 if (e.type == "checkbox")
  282.                 e.checked = true;
  283.                 else
  284.                 e.value = x.join('g');
  285.             }
  286.         }
  287.     }
  288.  
  289. </script>
Advertisement
Add Comment
Please, Sign In to add comment