]> arthur.barton.de Git - netdata.git/commitdiff
the new dashboard is now the default, the old one moved to the old/ directory and...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 20 Dec 2015 03:05:38 +0000 (05:05 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 20 Dec 2015 03:05:38 +0000 (05:05 +0200)
13 files changed:
web/Makefile.am
web/dashboard.js
web/dashboard_full.html [deleted file]
web/datasource.html [deleted file]
web/index.html [changed mode: 0644->0755]
web/index.js [deleted file]
web/netdata.js [deleted file]
web/old/datasource.html [new file with mode: 0644]
web/old/index.html [new file with mode: 0644]
web/old/index.js [new file with mode: 0755]
web/old/netdata.js [new file with mode: 0755]
web/old/theme.css [new file with mode: 0644]
web/theme.css [deleted file]

index 1cd764829c6facfede0a3e0b0d124552cd578360..ffb9769941d8025e3ea42282fd536a0425ab7c29 100644 (file)
@@ -4,19 +4,22 @@
 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
 
 dist_web_DATA = \
-        datasource.html \
-        index.html \
-        index.js \
-        netdata.js \
         robots.txt \
-        theme.css \
-        dashboard_full.html \
+        index.html \
         dashboard.html \
         dashboard.js \
         dashboard.css \
        favicon.ico \
         $(NULL)
 
+webolddir=$(webdir)/old
+dist_webold_DATA = \
+        old/datasource.html \
+        old/index.html \
+        old/index.js \
+        old/netdata.js \
+        old/theme.css \
+        $(NULL)
 
 weblibdir=$(webdir)/lib
 dist_weblib_DATA = \
index 65009ee0db6917413bafa5d159149d3a8e254473..1a02fbb19d5d602e108f8cbf387838143adfdd01 100755 (executable)
                        focus:                          false,
                        visibility:             false,
                        chart_data_url:         false,
-                       chart_errors:           true,
+                       chart_errors:           false,
                        chart_timing:           false,
                        chart_calls:            false,
                        libraries:                      false,
diff --git a/web/dashboard_full.html b/web/dashboard_full.html
deleted file mode 100755 (executable)
index ea9e3f0..0000000
+++ /dev/null
@@ -1,859 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-       <title>netdata dashboard</title>
-
-       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-       <meta charset="utf-8">
-       <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-       <meta name="viewport" content="width=device-width, initial-scale=1">
-       <meta name="apple-mobile-web-app-capable" content="yes">
-       <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
-       <meta name="author" content="costa@tsaousis.gr">
-
-       <link rel="shortcut icon" href="images/seo-performance-multi-size.ico">
-       
-       <link rel="apple-touch-icon" href="images/seo-performance-72.png">
-       <link rel="apple-touch-icon" sizes="72x72" href="images/seo-performance-72.png">
-       <link rel="apple-touch-icon" sizes="114x114" href="images/seo-performance-114.png">
-
-       <link rel="icon" type="image/png" sizes="512x512" href="images/seo-performance-512.png">
-       <link rel="icon" type="image/png" sizes="256x256" href="images/seo-performance-256.png">
-       <link rel="icon" type="image/png" sizes="128x128" href="images/seo-performance-128.png">
-       <link rel="icon" type="image/png" sizes="64x64" href="images/seo-performance-64.png">
-       <link rel="icon" type="image/png" sizes="48x48" href="images/seo-performance-48.png">
-       <link rel="icon" type="image/png" sizes="32x32" href="images/seo-performance-32.png">
-       <link rel="icon" type="image/png" sizes="24x24" href="images/seo-performance-24.png">
-       <link rel="icon" type="image/png" sizes="16x16" href="images/seo-performance-16.png">
-
-       <style>
-
-       /* prevent body from hidding under the navbar */
-       body {
-               padding-top: 50px;
-       }
-
-       /* fix # anchors scrolling under the navbar
-          https://github.com/twbs/bootstrap/issues/1768#issuecomment-46519033
-        */
-       h1 {
-               position: relative;
-               z-index: -1;
-       }
-       h2 {
-               position: relative;
-               z-index: -2;
-       }
-       h1:before, h2:before { 
-               display: block; 
-               content: " "; 
-               margin-top: -70px;
-               height: 70px;
-               visibility: hidden; 
-       }
-
-       .p {
-               display: block;
-               margin-top: 15px;
-       }
-
-       .chart-message {
-               display: block; 
-               margin-top: 10px;
-       }
-
-       .container {
-               width: 90% !important;
-       }
-
-       #masthead h1 {
-               /*font-size: 30px;*/
-               line-height: 1;
-               padding-top: 30px;
-       }
-
-       #masthead .well {
-               margin-top:4%;
-       }
-
-
-       /*
-        * Side navigation
-        *
-        * Scrollspy and affixed enhanced navigation to highlight sections and secondary
-        * sections of docs content.
-        */
-
-       .dashboard-sidebar {
-               max-height: calc(100% - 70px) !important;
-               overflow-y: auto;
-               width: 170px !important;
-       }
-
-       /* By default it's not affixed in mobile views, so undo that */
-       .dashboard-sidebar.affix {
-               position: static;
-       }
-       @media (min-width: 768px) {
-               .dashboard-sidebar {
-                       padding-left: 20px;
-               }
-       }
-
-       .affix {
-               position: static;
-               top: 70px !important;
-               width: 170px;
-       }
-       .affix-top {
-               width: 170px;
-       }
-
-       /* First level of nav */
-       .dashboard-sidenav {
-               margin-top: 20px;
-               margin-bottom: 20px;
-       }
-
-       /* All levels of nav */
-       .dashboard-sidebar .nav > li > a {
-               display: block;
-               padding: 4px 20px;
-               font-size: 13px;
-               font-weight: 500;
-               color: #767676;
-       }
-       .dashboard-sidebar .nav > li > a:hover,
-       .dashboard-sidebar .nav > li > a:focus {
-               padding-left: 19px;
-               color: #563d7c;
-               text-decoration: none;
-               background-color: transparent;
-               border-left: 1px solid #563d7c;
-       }
-       .dashboard-sidebar .nav > .active > a,
-       .dashboard-sidebar .nav > .active:hover > a,
-       .dashboard-sidebar .nav > .active:focus > a {
-               padding-left: 18px;
-               font-weight: bold;
-               color: #563d7c;
-               background-color: transparent;
-               border-left: 2px solid #563d7c;
-       }
-
-       /* Nav: second level (shown on .active) */
-       .dashboard-sidebar .nav .nav {
-               display: none; /* Hide by default, but at >768px, show it */
-               padding-bottom: 10px;
-       }
-       .dashboard-sidebar .nav .nav > li > a {
-               padding-top: 1px;
-               padding-bottom: 1px;
-               padding-left: 30px;
-               font-size: 12px;
-               font-weight: normal;
-       }
-       .dashboard-sidebar .nav .nav > li > a:hover,
-       .dashboard-sidebar .nav .nav > li > a:focus {
-               padding-left: 29px;
-       }
-       .dashboard-sidebar .nav .nav > .active > a,
-       .dashboard-sidebar .nav .nav > .active:hover > a,
-       .dashboard-sidebar .nav .nav > .active:focus > a {
-               padding-left: 28px;
-               font-weight: 500;
-       }
-
-       /* Back to top (hidden on mobile) */
-       .back-to-top,
-       .dashboard-theme-toggle {
-               display: none;
-               padding: 4px 10px;
-               margin-top: 10px;
-               margin-left: 10px;
-               font-size: 12px;
-               font-weight: 500;
-               color: #999;
-       }
-       .back-to-top:hover,
-       .dashboard-theme-toggle:hover {
-               color: #563d7c;
-               text-decoration: none;
-       }
-       .dashboard-theme-toggle {
-               margin-top: 0;
-       }
-
-       @media (min-width: 768px) {
-               .back-to-top,
-               .dashboard-theme-toggle {
-                       display: block;
-               }
-       }
-
-       /* Show and affix the side nav when space allows it */
-       @media (min-width: 992px) {
-               .dashboard-sidebar .nav > .active > ul {
-                       display: block;
-               }
-               /* Widen the fixed sidebar */
-               .dashboard-sidebar.affix,
-               .dashboard-sidebar.affix-bottom {
-                       width: 213px;
-               }
-               .dashboard-sidebar.affix {
-                       position: fixed; /* Undo the static from mobile first approach */
-                       top: 20px;
-               }
-               .dashboard-sidebar.affix-bottom {
-                       position: absolute; /* Undo the static from mobile first approach */
-               }
-               .dashboard-sidebar.affix-bottom .dashboard-sidenav,
-               .dashboard-sidebar.affix .dashboard-sidenav {
-                       margin-top: 0;
-                       margin-bottom: 0;
-               }
-       }
-       @media (min-width: 1200px) {
-               /* Widen the fixed sidebar again */
-               .dashboard-sidebar.affix-bottom,
-               .dashboard-sidebar.affix {
-                       width: 263px;
-               }
-       }
-       </style>
-       
-       <!-- you can set your netdata server globally, by ucommenting this -->
-       <!-- you can also give a different server per chart, with the attribute: data-host="http://netdata.server:19999" -->
-       <!-- <script> netdataServer = "http://box:19999"; </script> -->
-
-       <!-- load the dashboard manager - it will do the rest -->
-       <script type="text/javascript" src="dashboard.js"></script>
-</head>
-<body data-spy="scroll">
-       <nav class="navbar navbar-default navbar-fixed-top" role="banner">
-               <div class="container">
-                       <div class="navbar-header">
-                               <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
-                                       <span class="sr-only">Toggle navigation</span>
-                                       <span class="icon-bar"></span>
-                                       <span class="icon-bar"></span>
-                                       <span class="icon-bar"></span>
-                               </button>
-                               <a href="/" class="navbar-brand" id="hostname">netdata</a>
-                       </div>
-<!--                   <nav class="collapse navbar-collapse" role="navigation">
-                               <ul class="nav navbar-nav">
-                                       <li><a href="#sec">Get Started</a></li>
-                                       <li><a href="#sec">Edit</a></li>
-                                       <li><a href="#sec">Visualize</a></li>
-                                       <li><a href="#sec">Prototype</a></li>
-                               </ul>
-                       </nav>
--->            </div>
-       </nav>
-
-       <div id="masthead" style="display: none;">
-               <div class="container">
-                       <div class="row">
-                               <div class="col-md-7">
-                                       <h1>Netdata Dashboard
-                                               <p class="lead">Real time data collection and graphs...</p>
-                                       </h1>
-                               </div>
-                               <div class="col-md-5">
-                                       <div class="well well-lg">
-                                               <div class="row">
-                                               <div class="col-md-6">
-                                                       <b>Drag</b> charts to pan.
-                                                       <b>Shift + wheel</b> on them, to zoom in and out.
-                                                       <b>Double-click</b> on them, to reset.
-                                                       <b>Hover</b> on them too!
-                                                       </div>
-                                               <div class="col-md-6">
-                                                       <div data-netdata="system.intr" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-dygraph-type="line" data-dygraph-strokewidth="3" data-dygraph-smooth="true" data-dygraph-highlightcirclesize="6" data-after="-90" data-height="60px" data-colors="#C66"></div>
-                                                       </div>
-                                               </div>
-                                       </div>
-                               </div>
-                       </div>
-               </div>
-       </div>
-
-       <div class="container">
-               <div class="row">
-                       <div class="col-md-10" role="main">
-                               <div id="charts_div"></div>
-                       </div>
-                       <div class="col-md-2" role="complementary">
-                               <nav class="dashboard-sidebar hidden-print hidden-xs hidden-sm" data-spy="affix" id="sidebar" role="menu"></nav>
-                       </div>
-               </div>
-       </div>
-
-<div class="modal fade" id="welcomeModal" tabindex="-1" role="dialog" aria-labelledby="welcomeModalLabel">
-       <div class="modal-dialog modal-lg" role="document">
-               <div class="modal-content">
-                       <div class="modal-header">
-                               <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
-                               <h4 class="modal-title" id="welcomeModalLabel">Welcome to netdata!</h4>
-                       </div>
-                       <div class="modal-body">
-                                       <div class="p">
-                                       <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> is the fastest way to visualize data. It is a resource efficient, highly optimized system for collecting and visualizing any type of realtime timeseries data, from CPU usage, disk activity, SQL queries, to web site visitors, e-shop orders, revenue and profits.
-                                       </div>
-                                       <div class="p">
-                                       To make a chart in <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b>, you just need a <b>number</b>. Just a number you can read somehow. <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> will turn this number to a real time web chart. For collecting these numbers, it supports <a href="https://github.com/firehol/netdata/tree/master/plugins.d" target="_blank">external plugins</a>, even <a href="https://github.com/firehol/netdata/tree/master/charts.d" target="_blank">bash shell plugins</a>. Any computer program, in any language, that can print a few lines of text on its standard output, can be a netdata data collector.
-                                       </div>
-                                       <div class="p">
-                                       <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> can embed charts everywhere, like this one <div data-netdata="system.cpu" data-dimensions="system" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-show-value-of-system-at="system.cpu.system.modal.1"></div> (my CPU system usage which is <span id="system.cpu.system.modal.1" style="display: inline-block; width: 40px; text-align: right;"></span>%),
-                                       or this one <div data-netdata="ipv4.tcppackets" data-dimensions="received" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-show-value-of-received-at="ipv4.tcppackets.received.modal.1"></div> (my IPv4 received TCP packets, which are <span id="ipv4.tcppackets.received.modal.1" style="display: inline-block; width: 60px; text-align: right;"></span>/second).
-                                       </div>
-                                       <div class="p">
-                                       You can have <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> charts on your site too. Just give it a <code>div</code> and a real time chart, zoomable and draggable will appear (try it even on these tiny ones - <b>drag</b> them to pan horizontally, <b>shift + drag</b> to zoom in, on <b>chrome shift + mouse wheel</b> to zoom in/out, <b>double click</b> on them to reset them - don't be afraid of <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> performance - <a href="https://github.com/firehol/netdata/issues/36" target="_blank">a raspberry pi 2 can sustain 300 charts updates per second</a>!).
-                                       </div>
-                                       <div class="p">
-                                       If you like this project, <b>we need help writing documentation, coding plugins, testing new features, supporting end users.</b>
-                                       </div>
-                                       <div class="p">
-                                       We will be glad to have you on board...
-                                       </div>
-                       </div>
-                       <div class="modal-footer">
-                               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
-                       </div>
-               </div>
-       </div>
-</div>
-
-</body>
-</html>
-<script>
-
-
-var demo_hostname = 'netdata.firehol.org';
-// var demo_hostname = 'box';
-
-//if(document.location.hostname === demo_hostname) {
-       document.getElementById('masthead').style.display = 'block';
-//}
-
-var options = {
-       sparklines_registry: {},
-       data: null,
-       hostname: 'netdata_server', // will be overwritten by the netdata server
-       categories: new Array(),
-       categories_idx: {},
-       families: new Array(),
-       families_idx: {},
-
-       chartsPerRow: 0,
-       chartsMinWidth: 1450,
-       chartsHeight: 180,
-       sparklinesHeight: 60
-};
-
-// generate a sparkline
-// used in the documentation
-function sparkline(chart, dimension, units) {
-       var key = chart + '.' + dimension;
-
-       if(typeof units === 'undefined')
-               units = '';
-
-       if(typeof options.sparklines_registry[key] === 'undefined')
-               options.sparklines_registry[key] = { count: 1 };
-       else
-               options.sparklines_registry[key].count++;
-
-       key = key + '.' + options.sparklines_registry[key].count;
-
-       var h = '<div data-netdata="' + chart + '" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-dimensions="' + dimension + '" data-show-value-of-' + dimension + '-at="' + key + '"></div> (<span id="' + key + '" style="display: inline-block; min-width: 50px; text-align: right;">X</span>' + units + ')';
-
-       return h;
-}
-
-// documentation for each category and chart
-var messages = {
-
-       // categories / sections
-       'system': 'Overview of the key system metrices.',
-       'tc': 'Netdata collects and visualizes tc class utilization using its <a href="https://github.com/firehol/netdata/blob/master/plugins.d/tc-qos-helper.sh" target="_blank">tc-helper plugin</a>. If you also use <a href="http://firehol.org/#fireqos" target="_blank">FireQOS</a> for setting up QoS, netdata automatically collects interface and class names.',
-       'net': 'Per network interface statistics collected from <code>/proc/net/dev</code>.',
-       'apps': 'Per application statistics are collected using netdata\'s <code>apps.plugin</code>. This plugin walks through the entire <code>/proc</code> filesystem and aggregates statistics for applications of interest, defined in <code>/etc/netdata/apps_groups.conf</code> (the default is <a href="https://github.com/firehol/netdata/blob/master/conf.d/apps_groups.conf" target="_blank">here</a>). The plugin internaly builds a process tree (much like <code>ps fax</code> does), and groups processes together (evaluating both child and parent processes) so that the result is always a chart with a predefined set of dimensions (of course, only application groups found running are reported).<br/><b>IMPORTANT</b>: The values shown here are not 100% accurate. They only include values for the processes running. If an application is spawning childs continiously, which are terminated in just a few milliseconds (like shell scripts do), the values reported will be inaccurate. Linux does report the values for the exited childs of a process. However, these values are reported to the parent process <b>only when the child exits</b>. If these values, of the exited child processes, were also aggregated in the charts below, the charts would have been full of spikes, presenting unrealisting utilization for each process group. So, we decided to ignore these values and present only the utilization of <b>the currently running processes</b>.',
-
-       // charts
-       'system.cpu': 'Total CPU utilization (all cores). 100% here means there is no CPU idle time at all. You can get per core usage at the <a href="#cpu">CPUs</a> section and per application usage at the <a href="#apps">Applications Monitoring</a> section.<br/>Keep an eye on <b>iowait</b> ' + sparkline('system.cpu', 'iowait', '%') + '. If it is constantly high, your disks are a bottleneck and they slow your system down.<br/>Another important metric worth monitoring, is <b>softirq</b> ' + sparkline('system.cpu', 'softirq', '%') + '. A constantly high percentage of softirq may indicate network drivers issues.',
-       'system.io': 'Total Disk I/O, for all disks, read from <code>/proc/vmstat</code>. You can get detailed information about each disk at the <a href="#disk">Disks</a> section and per application Disk usage at the <a href="#apps">Applications Monitoring</a> section.',
-       'system.swapio': 'Total Swap I/O, read from <code>/proc/vmstat</code>. (netdata measures both <code>in</code> and <code>out</code>. If either of them is not shown in the chart, it is because it is zero - you can change the page settings to always render all the available dimensions on all charts).',
-       'system.pgfaults': 'Total page faults, read from <code>/proc/vmstat</code>. <b>Major page faults</b> indicates that the system is using its swap. You can find which applications use the swap at the <a href="#apps">Applications Monitoring</a> section.',
-       'system.entropy': '<a href="https://en.wikipedia.org/wiki/Entropy_(computing)" target="_blank">Entropy</a>, read from <code>/proc/sys/kernel/random/entropy_avail</code>, is like a pool of random numbers that are mainly used in cryptography. It is advised that the pool remains always <a href="https://blog.cloudflare.com/ensuring-randomness-with-linuxs-random-number-generator/" target="_blank">above 200</a>. If the pool of entropy gets empty, you risk your security to be predictable and you should install a user-space random numbers generating daemon, like <a href="http://www.issihosts.com/haveged/" target="_blank">haveged</a>, to keep the pool in healthy levels.',
-       'system.forks': 'The number of new processes created per second, read from <code>/proc/stat</code>.',
-       'system.intr': 'Total number of CPU interrupts, read from <code>/proc/stat</code>. Check <code>system.interrupts</code> that gives more detail about each interrupt and also the <a href="#cpu">CPUs</a> section where interrupts are analyzed per CPU core.',
-       'system.interrupts': 'CPU interrupts in detail, read from <code>/proc/interrupts</code>. At the <a href="#cpu">CPUs</a> section, interrupts are analyzed per CPU core.',
-       'system.softirqs': 'CPU softirqs in detail, read from <code>/proc/softirqs</code>. At the <a href="#cpu">CPUs</a> section, softirqs are analyzed per CPU core.',
-       'system.processes': 'System processes, read from <code>/proc/stat</code>. <b>Blocked</b> are processes that are willing to execute but they cannot, e.g. because they wait for disk activity.',
-       'system.ctxt': '<a href="https://en.wikipedia.org/wiki/Context_switch" target="_blank">Context Switches</a>, read from <code>/proc/stat</code>, is the switching of the CPU from one process, task or thread to another. If there are many processes or threads willing to execute and very few CPU cores available to handle them, the system is making more context switching to balance the CPU resources among them. The whole process is computationally intensive. The more the context switches, the slower the system gets.',
-       'system.idlejitter': 'Idle jitter is calculated by netdata. A thread is spawned that requests to sleep for a few microseconds. When the system wakes it up, it measures how many microseconds have passed. The different between the requested and the actual duration of the sleep, is the <b>idle jitter</b>. This number is useful in realtime environments, where CPU jitter can affect the quality of the service (like VoIP media gateways).',
-       'system.ipv4': 'Total IPv4 Traffic, read from <code>/proc/net/netstat</code>. This includes <code>lo</code> device traffic.',
-       'system.ram': 'System memory, read from <code>/proc/meminfo</code>.',
-       'system.swap': 'System swap memory, read from <code>/proc/meminfo</code>.',
-
-       // just a line to allow ending all entries above with comma
-       'end': 'end'
-};
-
-function screenWidth() {
-       return (($(window).width() * 0.95) - 50);
-}
-
-function chartsPerRow(total) {
-       if(options.chartsPerRow === 0) {
-               width = Math.floor(total / options.chartsMinWidth);
-               if(width === 0) width = 1;
-               return width;
-       }
-       else return options.chartsPerRow;
-}
-
-function chartsPrioritySort(a, b) {
-       if(a.priority === b.priority) {
-               if(a.name < b.name) return -1;
-       }
-       else if(a.priority < b.priority) return -1;
-       return 1;
-}
-
-function uniq(array, find_key, get_result) {
-       if(typeof get_result === 'undefined' || get_result === null)
-               get_result = find_key;
-
-       var idx = {};
-       var result = new Array();
-
-       $.each(array, function(i, c) {
-               key = find_key(c);
-               if(typeof idx[key] === 'undefined') {
-                       idx[key] = true;
-                       result.push(get_result(c));
-               }
-       });
-       return result;
-}
-
-function uniq_with_list(array, find_key_function) {
-       var idx = {};
-       var result = new Array();
-
-       $.each(array, function(i, c) {
-               key = find_key_function(c);
-               if(typeof idx[key] === 'undefined') {
-                       idx[key] = new Array();
-                       result.push( { name: key, values: idx[key] } );
-               }
-               idx[key].push(c);
-       });
-       result.sort(function(a, b) {
-               if(a.name < b.name) return -1;
-               return 1;
-       });
-       return result;
-}
-
-function prepareScreen(data) {
-       // console.log('NETDATA is paused - ready to prepare the screen');
-       // console.log(data);
-
-       options.data = data;
-       options.hostname = data.hostname;
-       document.getElementById('hostname').innerHTML = options.hostname;
-       document.title = options.hostname + ' dashboard';
-       var charts = data.charts;
-
-       $.each(charts, function(i, c) {
-               if(c.enabled === true) {
-
-                       // find the category of the chart
-                       c.category = c.type.split('.')[0];
-
-                       var tmp = c.category.split('_')[0];
-                       if(tmp === 'net' || tmp === 'disk')
-                               c.category = tmp;
-
-                       if(c.category === 'cpu') {
-                               if(c.id.match(/^cpu\.cpu[0-9]+$/)) {
-                                       c.family = 'Utilization';
-                               }
-                               else if(c.id.match(/^cpu\.cpu[0-9]+_interrupts$/)) {
-                                       c.family = 'Interrupts';
-                               }
-                               else if(c.id.match(/^cpu\.cpu[0-9]+_softirqs$/)) {
-                                       c.family = 'SoftIRQs';
-                               }
-                       }
-
-                       switch(c.category) {
-                               case 'system':
-                                       c.category_priority = 10;
-                                       c.category_title = 'System Summary';
-                                       c.glyphicon = "glyphicon-dashboard";
-                                       break;
-
-                               case 'tc':
-                                       c.category_priority = 20;
-                                       c.category_title = 'Quality Of Service';
-                                       c.glyphicon = "glyphicon-random";
-                                       break;
-
-                               case 'net':
-                                       c.category_priority = 30;
-                                       c.category_title = 'Network Interfaces';
-                                       c.glyphicon = "glyphicon-transfer";
-                                       break;
-
-                               case 'apps':
-                                       c.category_priority = 40;
-                                       c.category_title = 'Applications Monitoring';
-                                       c.glyphicon = "glyphicon-tasks";
-                                       break;
-
-                               case 'ipvs':
-                                       c.category_priority = 50;
-                                       c.category_title = 'IP Virtual Server';
-                                       c.glyphicon = "glyphicon-transfer";
-                                       break;
-
-                               case 'netfilter':
-                                       c.category_priority = 60;
-                                       c.category_title = 'Netfilter / IPTables';
-                                       c.glyphicon = "glyphicon-cloud";
-                                       break;
-
-                               case 'ipv4':
-                                       c.category_priority = 70;
-                                       c.category_title = 'IPv4 Summary';
-                                       c.glyphicon = "glyphicon-globe";
-                                       break;
-
-                               case 'mem':
-                                       c.category_priority = 80;
-                                       c.category_title = 'Memory';
-                                       c.glyphicon = "glyphicon-dashboard";
-                                       break;
-
-                               case 'cpu':
-                                       c.category_priority = 90;
-                                       c.category_title = 'CPU Cores';
-                                       c.glyphicon = "glyphicon-dashboard";
-                                       break;
-
-                               case 'disk':
-                                       c.category_priority = 100;
-                                       c.category_title = 'Disks';
-                                       c.glyphicon = "glyphicon-hdd";
-                                       break;
-
-                               case 'nfsd':
-                                       c.category_priority = 110;
-                                       c.category_title = 'NFS Server';
-                                       c.glyphicon = "glyphicon-hdd";
-                                       break;
-
-                               case 'squid':
-                                       c.category_priority = 140;
-                                       c.category_title = 'Proxy Server';
-                                       c.glyphicon = "glyphicon-link";
-                                       break;
-
-                               case 'netdata':
-                                       c.category_priority = 150;
-                                       c.category_title = 'Netdata Monitoring';
-                                       c.glyphicon = "glyphicon-thumbs-up";
-                                       break;
-
-                               case 'sensors':
-                                       c.category_priority = 160;
-                                       c.category_title = 'Hardware Sensors';
-                                       c.glyphicon = "glyphicon-thumbs-up";
-                                       break;
-
-                               case 'postfix':
-                                       c.category_priority = 170;
-                                       c.category_title = 'Mail Server';
-                                       c.glyphicon = "glyphicon-thumbs-up";
-                                       break;
-
-                               case 'example':
-                                       c.category_priority = 100000;
-                                       c.category_title = 'Example Plugins';
-                                       c.glyphicon = "glyphicon-search";
-                                       break;
-
-                               default:
-                                       c.category_priority = 150;
-                                       c.category_title = c.type;
-                                       c.glyphicon = "glyphicon-dashboard";
-                                       break;
-                       }
-
-                       // find the unique categories
-                       if(typeof options.categories_idx[c.category] === 'undefined') {
-                               options.categories_idx[c.category] = {
-                                       charts: new Array()
-                               }
-                               options.categories.push({
-                                       name: c.category,
-                                       title: c.category_title,
-                                       priority: c.category_priority,
-                                       glyphicon: c.glyphicon,
-                                       charts: options.categories_idx[c.category].charts
-                               });
-                       }
-                       options.categories_idx[c.category].charts.push(c);
-
-                       // find the unique families
-                       if(typeof options.families_idx[c.family] === 'undefined') {
-                               options.families_idx[c.family] = {
-                                       charts: new Array()
-                               };
-                               options.families.push({
-                                       name: c.family,
-                                       title: c.family,
-                                       priority: c.category_priority,
-                                       glyphicon: c.glyphicon,
-                                       charts: options.categories_idx[c.category].charts
-                               });
-                       }
-                       options.families_idx[c.family].charts.push(c);
-               }
-       });
-
-       function prioritySort(a, b) {
-               if(a.priority < b.priority) return -1;
-               if(a.priority > b.priority) return 1;
-               if(a.name < b.name) return -1;
-               return 1;
-       }
-
-       // sort all of them
-       options.categories.sort(prioritySort);
-       options.families.sort(prioritySort);
-       $.each(options.families,   function(i, c) { c.charts.sort(prioritySort); });
-
-       var div = document.getElementById('charts_div');
-       var pcent_width = Math.floor(100 / chartsPerRow($(div).width()));
-
-       // find the proper duration for per-second updates
-       var duration = Math.round(($(div).width() * pcent_width / 100 * data.update_every / 3) / 60) * 60;
-       var html = '';
-       var sidebar = '<ul class="nav dashboard-sidenav" id="sidebar_ul">';
-
-       function getMessage(id) {
-               if(typeof messages[id] !== 'undefined')
-                       return '<div class="chart-message" role="document">' + messages[id] + '</div>';
-               else
-                       return '';
-       }
-
-       // render the charts
-       $.each(options.categories, function(i, t) {
-               t.charts.sort(prioritySort);
-
-               sidebar += '<li class="' + ((i === 0)?'active':'').toString() + '"><a href="#' + t.name + '">' + t.title + '</a>';
-               html += '<div role="section"><div role="sectionhead"><h1 id="' + t.name + '" role="heading">' + t.title + '</h1>' + getMessage(t.name) + '</div><div id="' + t.name + '" role="document">';
-
-               if(t.name === 'cpu') {
-                       var families = uniq_with_list(t.charts, function(c) { return c.family; });
-
-                       sidebar += '<ul class="nav">';
-                       $.each(families, function(j, c) {
-                               sidebar += '<li class><a href="#' + t.name + '_' + c.name + '">' + c.name + '</a></li>';
-                               html += '<div class="netdata-group-container" id="family_' + t.name + '_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + t.name + '_' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
-                               $.each(c.values, function(x, f) {
-                                       var c = null;
-                                       var h = options.chartsHeight;
-
-                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
-                                               + ' data-width="100%"'
-                                               + ' data-height="' + h.toString() + 'px"'
-                                               + ' data-before="0"'
-                                               + ' data-after="-' + duration.toString() + '"'
-                                               + ' data-colors="' + c + '"'
-                                               + ' role="application"></div>';
-                               });
-                               html += '</div>'; // netdata-group-container
-                       });
-                       sidebar += '</ul>';
-               }
-               else if(t.name === 'net' || t.name === 'tc') {
-                       var interfaces = uniq_with_list(t.charts, function(c) { return c.family; });
-
-                       sidebar += '<ul class="nav">';
-                       $.each(interfaces, function(j, c) {
-                               sidebar += '<li class><a href="#' + t.name + '_' + c.name + '">' + c.name + '</a></li>';
-                               html += '<div class="netdata-group-container" id="interface_' + t.name + '_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + t.name + '_' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
-                               $.each(c.values, function(x, f) {
-                                       var c = null;
-                                       var h = options.chartsHeight / 2;
-                                       switch(f.type) {
-                                               case 'net'        : h = options.chartsHeight; break;
-                                               case 'tc'         : h = options.chartsHeight; break;
-                                       }
-
-                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
-                                               + ' data-width="100%"'
-                                               + ' data-height="' + h.toString() + 'px"'
-                                               + ' data-before="0"'
-                                               + ' data-after="-' + duration.toString() + '"'
-                                               + ' data-colors="' + c + '"'
-                                               + ' role="application"></div>';
-                               });
-                               html += '</div>'; // netdata-group-container
-                       });
-                       sidebar += '</ul>';
-               }
-               else if(t.name === 'disk') {
-                       var disks = uniq_with_list(t.charts, function(c) { return c.family; });
-
-                       sidebar += '<ul class="nav">';
-                       $.each(disks, function(j, c) {
-                               sidebar += '<li class><a href="#' + c.name + '">' + c.name + '</a></li>';
-                               html += '<div class="netdata-group-container" id="disk_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
-                               $.each(c.values, function(x, f) {
-                                       var c = null;
-                                       var h = options.chartsHeight / 2;
-                                       switch(f.type) {
-                                               case 'disk'        : h = options.chartsHeight; break;
-                                               case 'disk_backlog': c = '#DD4477'; break;
-                                               case 'disk_util'   : c = '#109618'; break;
-                                               case 'disk_qops'   : c = '#E67300'; break;
-                                       }
-
-                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
-                                               + ' data-width="100%"'
-                                               + ' data-height="' + h.toString() + 'px"'
-                                               + ' data-before="0"'
-                                               + ' data-after="-' + duration.toString() + '"'
-                                               + ' data-colors="' + c + '"'
-                                               + ' role="application"></div>';
-                               });
-                               html += '</div>'; // netdata-group-container
-                       });
-                       sidebar += '</ul>';
-               }
-               else if(t.name === 'apps') {
-                       $.each(t.charts, function(x, f) {
-                               var c = null;
-                               var h = options.chartsHeight / 2;
-                               switch(f.id) {
-                                       case 'apps.cpu'         : h = options.chartsHeight; break;
-                                       case 'apps.preads'      : h = options.chartsHeight; break;
-                                       case 'apps.pwrites'     : h = options.chartsHeight; break;
-                                       case 'apps.mem'         : h = options.chartsHeight; break;
-                                       case 'apps.major_faults': h = options.chartsHeight; break;
-                               }
-
-                               html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
-                                       + ' data-width="100%"'
-                                       + ' data-height="' + h.toString() + 'px"'
-                                       + ' data-before="0"'
-                                       + ' data-after="-' + duration.toString() + '"'
-                                       + ' data-colors="' + c + '"'
-                                       + ' role="application"></div>';
-                       });
-               }
-               else {
-                       $.each(t.charts, function(x, c) {
-                               html += getMessage(c.id) + '<div data-netdata="' + c.id + '"'
-                                       + ' data-width="' + pcent_width.toString() + '%"'
-                                       + ' data-height="' + options.chartsHeight.toString() + 'px"'
-                                       + ' data-before="0"'
-                                       + ' data-after="-' + duration.toString() + '"'
-                                       + ' role="application"></div>';
-                       });
-               }
-
-               sidebar += '</li>';
-               html += '</div>'; // document
-               html += '</div>'; // section
-               html += '<hr role="separator"/>';
-       });
-       sidebar += '</ul>';
-/*
-       // show the colors
-       html += '<br/><div class="row">'
-       $.each(NETDATA.colors, function(i, c){
-               html += '<div style="display: inline-block;"><div style="display: inline-block; width: 100px; height: 100px; background: ' + c + ';"></div><br/>' + c + '</div>';
-       });
-       html += '</div>'
-*/
-       div.innerHTML = html;
-       document.getElementById('sidebar').innerHTML = sidebar;
-
-       // resize all charts - without starting the background thread
-       // this has to be done while NETDATA is paused
-       // if we ommit this, the affix menu will be wrong, since all
-       // the Dom elements are initially zero-sized
-       NETDATA.parseDom();
-
-       // let it run (update the charts)
-       NETDATA.unpause();
-
-       // check if we have to jump to a specific section
-       var hash = location.hash.replace('#','');
-       if(hash != '') {
-               // Clear the hash in the URL
-               // location.hash = '';   // delete front "//" if you want to change the address bar
-               var offset = $(location.hash).offset();
-               if(typeof offset !== 'undefined')
-                       $('html, body').animate({ scrollTop: offset.top }, 0);
-       }
-
-       /* activate bootstrap scrollspy (needed for sidebar) */
-       $(document.body).scrollspy({
-               target: '#sidebar',
-               offset: $(window).height() / 3 // controls the diff of the <hX> element to the top, to select it
-       });
-
-       /* activate bootstrap sidebar (affix) */
-       $('#sidebar').affix({
-               offset: {
-                       top: 200,
-                       bottom: 0
-               }
-       });
-
-       /* fix scrolling of very long affix lists
-          http://stackoverflow.com/questions/21691585/bootstrap-3-1-0-affix-too-long
-        */
-       $('#sidebar').on('affixed.bs.affix', function() {
-               $(this).removeAttr('style');
-       });
-}
-
-NETDATA.ready(function() {
-
-       $('#welcomeModal').on('hidden.bs.modal', function (e) {
-               NETDATA.updatedDom();
-       });
-       $('#welcomeModal').on('shown.bs.modal', function (e) {
-               NETDATA.updatedDom();
-       });
-
-       // download all the charts the server knows
-       NETDATA.chartRegistry.downloadAll(NETDATA.serverDefault, function(data) {
-
-               // pause the NETDATA thread that updates the charts
-               NETDATA.pause(function() {
-
-                       if(document.location.hostname === demo_hostname)
-                               $('#welcomeModal').modal();
-
-                       // prepare our DOM
-                       // this will be called when NETDATA is paused
-                       prepareScreen(data);
-               });
-       });
-});
-
-</script>
diff --git a/web/datasource.html b/web/datasource.html
deleted file mode 100644 (file)
index f61db4f..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<html>
-       <style>
-               * {font-family:Arial}
-               div {float: left; margin: 0 0 0 0; }
-       </style>
-       <head>
-       <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
-       <title>NetData Datasource Example</title>
-       <script type="text/javascript" src="http://www.google.com/jsapi"></script>
-       <script type="text/javascript">
-
-       google.load('visualization', '1', {packages: ['charteditor']});
-       // google.load('visualization', '1.0');  // Note: No need to specify chart libraries.
-
-       google.setOnLoadCallback(drawVisualization);
-
-       var wrapper;
-       function drawVisualization() {
-               wrapper = new google.visualization.ChartWrapper({
-                       containerId: 'graph_div',
-                       chartType: 'AreaChart',
-                       dataSourceUrl: 'http:/datasource/system.cpu/60/1/max', // it needs a protocol to work, even in relative URLs
-                       refreshInterval: 1,
-                       options: {
-                               isStacked: true,
-                               areaOpacity: 0.85,
-                               lineWidth: 1,
-                               title: 'CPU utilization',
-                               width: window.innerWidth - 50,
-                               height: window.innerHeight - 50,
-                               hAxis: {title: "Time of Day", viewWindowMode: 'maximized', format:'HH:mm:ss'},
-                               vAxis: {title: "percent", viewWindowMode: 'pretty', minValue: 0, maxValue: 100},
-                               focusTarget: 'category',
-                               annotation: {'1': {style: 'line'}},
-                       },
-               });
-               wrapper.draw();
-       }
-
-       function openEditor() {
-               var editor = new google.visualization.ChartEditor();
-               google.visualization.events.addListener(editor, 'ok', function() {
-                       wrapper = editor.getChartWrapper();
-                       wrapper.draw(document.getElementById('graph_div'));
-               });
-               editor.openDialog(wrapper);
-       }
-
-       </script>
-       </head>
-       <body>
-               <input type='button' onclick='openEditor()' value='Open Editor'>
-               <br/>
-               <div><div id="graph_div"/></div>
-       </body>
-</html>
old mode 100644 (file)
new mode 100755 (executable)
index 1175151..ec7f2a6
 <!DOCTYPE html>
 <html lang="en">
 <head>
+       <title>netdata dashboard</title>
+
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
-    <meta name="apple-mobile-web-app-capable" content="yes">
-    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
-    <meta name="description" content="">
-    <meta name="author" content="costa@tsaousis.gr">
-
-       <title>NetData</title>
-
-       <!-- Bootstrap CSS -->
-       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
-       <link href="/file/theme.css" rel="stylesheet">
-</head>
+       <meta charset="utf-8">
+       <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+       <meta name="viewport" content="width=device-width, initial-scale=1">
+       <meta name="apple-mobile-web-app-capable" content="yes">
+       <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
+       <meta name="author" content="costa@tsaousis.gr">
+
+       <link rel="shortcut icon" href="images/seo-performance-multi-size.ico">
+       
+       <link rel="apple-touch-icon" href="images/seo-performance-72.png">
+       <link rel="apple-touch-icon" sizes="72x72" href="images/seo-performance-72.png">
+       <link rel="apple-touch-icon" sizes="114x114" href="images/seo-performance-114.png">
+
+       <link rel="icon" type="image/png" sizes="512x512" href="images/seo-performance-512.png">
+       <link rel="icon" type="image/png" sizes="256x256" href="images/seo-performance-256.png">
+       <link rel="icon" type="image/png" sizes="128x128" href="images/seo-performance-128.png">
+       <link rel="icon" type="image/png" sizes="64x64" href="images/seo-performance-64.png">
+       <link rel="icon" type="image/png" sizes="48x48" href="images/seo-performance-48.png">
+       <link rel="icon" type="image/png" sizes="32x32" href="images/seo-performance-32.png">
+       <link rel="icon" type="image/png" sizes="24x24" href="images/seo-performance-24.png">
+       <link rel="icon" type="image/png" sizes="16x16" href="images/seo-performance-16.png">
+
+       <style>
+
+       /* prevent body from hidding under the navbar */
+       body {
+               padding-top: 50px;
+       }
+
+       /* fix # anchors scrolling under the navbar
+          https://github.com/twbs/bootstrap/issues/1768#issuecomment-46519033
+        */
+       h1 {
+               position: relative;
+               z-index: -1;
+       }
+       h2 {
+               position: relative;
+               z-index: -2;
+       }
+       h1:before, h2:before { 
+               display: block; 
+               content: " "; 
+               margin-top: -70px;
+               height: 70px;
+               visibility: hidden; 
+       }
+
+       .p {
+               display: block;
+               margin-top: 15px;
+       }
+
+       .chart-message {
+               display: block; 
+               margin-top: 10px;
+       }
+
+       .container {
+               width: 90% !important;
+       }
+
+       #masthead h1 {
+               /*font-size: 30px;*/
+               line-height: 1;
+               padding-top: 30px;
+       }
+
+       #masthead .well {
+               margin-top:4%;
+       }
+
+
+       /*
+        * Side navigation
+        *
+        * Scrollspy and affixed enhanced navigation to highlight sections and secondary
+        * sections of docs content.
+        */
+
+       .dashboard-sidebar {
+               max-height: calc(100% - 70px) !important;
+               overflow-y: auto;
+               width: 170px !important;
+       }
 
-<body role="document" data-spy="scroll" data-target="#main_menu_div">
-    <nav id="mynav" class="navbar navbar-default navbar-fixed-top" role="navigation">
-      <div class="container" style="width: 98%;">
-        <div class="navbar-header">
-          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main_menu_div">
-            <span class="sr-only">Toggle navigation</span>
-            <span class="icon-bar"></span>
-            <span class="icon-bar"></span>
-            <span class="icon-bar"></span>
-          </button>
-          <a class="navbar-brand" href="/" id="hostname_id">NetData</a>
-        </div>
-               <form class="navbar-form navbar-right">
-                       <!-- <div class="form-group">
-                               <input type="text" class="form-control" placeholder="Search">
-                       </div> -->
-                               <button type="button" class="btn btn-primary global_play_button" onClick="buttonGlobalPlayPause('toggle');" data-play-text="<span class='glyphicon glyphicon-pause'></span> Pause" data-pause-text="<span class='glyphicon glyphicon-play'></span> Play" data-toggle="tooltip" data-placement="bottom" title=" click <span class='glyphicon glyphicon-play'></span> to have the graphs auto-refresh, or click <span class='glyphicon glyphicon-pause'></span> to pause the graphs.">
-                               <span class="glyphicon glyphicon-pause"></span> Pause
+       /* By default it's not affixed in mobile views, so undo that */
+       .dashboard-sidebar.affix {
+               position: static;
+       }
+       @media (min-width: 768px) {
+               .dashboard-sidebar {
+                       padding-left: 20px;
+               }
+       }
+
+       .affix {
+               position: static;
+               top: 70px !important;
+               width: 170px;
+       }
+       .affix-top {
+               width: 170px;
+       }
+
+       /* First level of nav */
+       .dashboard-sidenav {
+               margin-top: 20px;
+               margin-bottom: 20px;
+       }
+
+       /* All levels of nav */
+       .dashboard-sidebar .nav > li > a {
+               display: block;
+               padding: 4px 20px;
+               font-size: 13px;
+               font-weight: 500;
+               color: #767676;
+       }
+       .dashboard-sidebar .nav > li > a:hover,
+       .dashboard-sidebar .nav > li > a:focus {
+               padding-left: 19px;
+               color: #563d7c;
+               text-decoration: none;
+               background-color: transparent;
+               border-left: 1px solid #563d7c;
+       }
+       .dashboard-sidebar .nav > .active > a,
+       .dashboard-sidebar .nav > .active:hover > a,
+       .dashboard-sidebar .nav > .active:focus > a {
+               padding-left: 18px;
+               font-weight: bold;
+               color: #563d7c;
+               background-color: transparent;
+               border-left: 2px solid #563d7c;
+       }
+
+       /* Nav: second level (shown on .active) */
+       .dashboard-sidebar .nav .nav {
+               display: none; /* Hide by default, but at >768px, show it */
+               padding-bottom: 10px;
+       }
+       .dashboard-sidebar .nav .nav > li > a {
+               padding-top: 1px;
+               padding-bottom: 1px;
+               padding-left: 30px;
+               font-size: 12px;
+               font-weight: normal;
+       }
+       .dashboard-sidebar .nav .nav > li > a:hover,
+       .dashboard-sidebar .nav .nav > li > a:focus {
+               padding-left: 29px;
+       }
+       .dashboard-sidebar .nav .nav > .active > a,
+       .dashboard-sidebar .nav .nav > .active:hover > a,
+       .dashboard-sidebar .nav .nav > .active:focus > a {
+               padding-left: 28px;
+               font-weight: 500;
+       }
+
+       /* Back to top (hidden on mobile) */
+       .back-to-top,
+       .dashboard-theme-toggle {
+               display: none;
+               padding: 4px 10px;
+               margin-top: 10px;
+               margin-left: 10px;
+               font-size: 12px;
+               font-weight: 500;
+               color: #999;
+       }
+       .back-to-top:hover,
+       .dashboard-theme-toggle:hover {
+               color: #563d7c;
+               text-decoration: none;
+       }
+       .dashboard-theme-toggle {
+               margin-top: 0;
+       }
+
+       @media (min-width: 768px) {
+               .back-to-top,
+               .dashboard-theme-toggle {
+                       display: block;
+               }
+       }
+
+       /* Show and affix the side nav when space allows it */
+       @media (min-width: 992px) {
+               .dashboard-sidebar .nav > .active > ul {
+                       display: block;
+               }
+               /* Widen the fixed sidebar */
+               .dashboard-sidebar.affix,
+               .dashboard-sidebar.affix-bottom {
+                       width: 213px;
+               }
+               .dashboard-sidebar.affix {
+                       position: fixed; /* Undo the static from mobile first approach */
+                       top: 20px;
+               }
+               .dashboard-sidebar.affix-bottom {
+                       position: absolute; /* Undo the static from mobile first approach */
+               }
+               .dashboard-sidebar.affix-bottom .dashboard-sidenav,
+               .dashboard-sidebar.affix .dashboard-sidenav {
+                       margin-top: 0;
+                       margin-bottom: 0;
+               }
+       }
+       @media (min-width: 1200px) {
+               /* Widen the fixed sidebar again */
+               .dashboard-sidebar.affix-bottom,
+               .dashboard-sidebar.affix {
+                       width: 263px;
+               }
+       }
+       </style>
+       
+       <!-- you can set your netdata server globally, by ucommenting this -->
+       <!-- you can also give a different server per chart, with the attribute: data-host="http://netdata.server:19999" -->
+       <!-- <script> netdataServer = "http://box:19999"; </script> -->
+
+       <!-- load the dashboard manager - it will do the rest -->
+       <script type="text/javascript" src="dashboard.js"></script>
+</head>
+<body data-spy="scroll">
+       <nav class="navbar navbar-default navbar-fixed-top" role="banner">
+               <div class="container">
+                       <div class="navbar-header">
+                               <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
+                                       <span class="sr-only">Toggle navigation</span>
+                                       <span class="icon-bar"></span>
+                                       <span class="icon-bar"></span>
+                                       <span class="icon-bar"></span>
                                </button>
-                       <div class="btn-group btn-group" data-toggle="buttons" role="group">
-                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Show less detail to speed up the browser. Use this if your machine is old and slow.">
-                                       <input type="radio" name="presentation" id="presentation_speedy" onChange="setPresentationSpeedy(0);">Speedy
-                               </label>
-                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Balance graphs detail with browser speed. Use this on modern computers.">
-                                       <input type="radio" name="presentation" id="presentation_normal" onChange="setPresentationNormal(0);">Normal
-                               </label>
-                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Show all the detail there is. This may slow down your browser.">
-                                       <input type="radio" name="presentation" id="presentation_detailed" onChange="setPresentationDetailed(0);">Detailed
-                               </label>
+                               <a href="/" class="navbar-brand" id="hostname">netdata</a>
                        </div>
-               </form>
-        <div class="collapse navbar-collapse" id="main_menu_div">
-          <ul class="nav navbar-nav">
-            <li><a href="#">preparing charts...</a></li>
-          </ul>
-        </div><!--/.nav-collapse -->
-      </div>
-    </nav>
-
-    <div class="container graphs" id="maingraph_container" style="display: none;">
-               <table>
-                       <tr><td>
-                       <div class="maingraph">
-                                       <table>
-                                               <tr><td>
-                                               <div class="maingraph" id="maingraph"></div>
-                                               <div id="maingraph_dashboard">
-                                                       <div class="maingraph" id="maingraph_hidden" style="display: none"></div>
-                                                       <div class="maingraph" id="maingraph_control"></div>
-                                               </div>
-                                               </td></tr>
-                                               <tr><td align="center">
-                                                       <div class="btn-group">
-                                                               <form id="mainchartform">
-                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title=" click <span class='glyphicon glyphicon-play'></span> to have the graph auto-refresh, or click <span class='glyphicon glyphicon-pause'></span> to pause the graph. When paused the graph can be zoomed and panned horizontally." >
-                                                                               <button type="button" class="btn btn-primary mainchart_play_button" data-play-text="<span class='glyphicon glyphicon-pause'></span>" data-pause-text="<span class='glyphicon glyphicon-play'></span>" onClick="setMainChartPlay('toggle');">
-                                                                                       <span class="glyphicon glyphicon-pause"></span>
-                                                                               </button>
-                                                                       </div>
-                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title="use the maximum ( <span class='glyphicon glyphicon-signal'></span> ) or the average ( <span class='glyphicon glyphicon-align-justify'></span> ) value of grouped points" >
-                                                                               <button type="button" class="btn btn-primary mainchart_avg_button" data-max-text="<span class='glyphicon glyphicon-signal'></span>" data-average-text="<span class='glyphicon glyphicon-align-justify'></span>" onClick="setMainChartGroupMethod('toggle');">
-                                                                                       <span class="glyphicon glyphicon-signal"></span>
-                                                                               </button>
-                                                                       </div>
-                                                                       <div class="btn-group btn-group" data-toggle="buttons" >
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="do not group points, show the raw data">
-                                                                                       <input type="radio" name="group" id="group1" onChange="setMainChartGroup(1);">1
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group in half, show 1 every 2 points of data">
-                                                                                       <input type="radio" name="group" id="group2" onChange="setMainChartGroup(2);">2
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 3 points of data">
-                                                                                       <input type="radio" name="group" id="group3" onChange="setMainChartGroup(3);">3
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 4 points of data">
-                                                                                       <input type="radio" name="group" id="group4" onChange="setMainChartGroup(4);">4
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 5 points of data">
-                                                                                       <input type="radio" name="group" id="group5" onChange="setMainChartGroup(5);">5
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 10 points of data">
-                                                                                       <input type="radio" name="group" id="group10" onChange="setMainChartGroup(10);">10
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 15 points of data">
-                                                                                       <input type="radio" name="group" id="group15" onChange="setMainChartGroup(15);">15
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 20 points of data">
-                                                                                       <input type="radio" name="group" id="group20" onChange="setMainChartGroup(20);">20
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 30 points of data">
-                                                                                       <input type="radio" name="group" id="group30" onChange="setMainChartGroup(30);">30
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 45 points of data">
-                                                                                       <input type="radio" name="group" id="group45" onChange="setMainChartGroup(45);">45
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 60 points of data">
-                                                                                       <input type="radio" name="group" id="group60" onChange="setMainChartGroup(60);">60
-                                                                               </label>
-                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 90 points of data">
-                                                                                       <input type="radio" name="group" id="group90" onChange="setMainChartGroup(90);">90
-                                                                               </label>
-                                                                       </div>
-                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title="maximized ( <span class='glyphicon glyphicon-fullscreen'></span> ) or normal ( <span class='glyphicon glyphicon-resize-small'></span> ) view of the graph" >
-                                                                               <button type="button" class="btn btn-primary mainchart_max_button" data-maximized-text="<span class='glyphicon glyphicon-resize-small'></span>" data-normal-text="<span class='glyphicon glyphicon-fullscreen'></span>" onClick="setMainChartMax('toggle');">
-                                                                                       <span class="glyphicon glyphicon-fullscreen"></span>
-                                                                               </button>
-                                                                       </div>
-                                                               </form>
+                       <nav class="collapse navbar-collapse navbar-right" role="navigation">
+                               <ul class="nav navbar-nav">
+                                       <li><a href="old/">Looking for the old Dashboard?</a></li>
+<!--                                   <li><a href="#sec">Edit</a></li>
+                                       <li><a href="#sec">Visualize</a></li>
+                                       <li><a href="#sec">Prototype</a></li>
+-->                            </ul>
+                       </nav>
+               </div>
+       </nav>
+
+       <div id="masthead" style="display: none;">
+               <div class="container">
+                       <div class="row">
+                               <div class="col-md-7">
+                                       <h1>Netdata Dashboard
+                                               <p class="lead">Real time data collection and graphs...</p>
+                                       </h1>
+                               </div>
+                               <div class="col-md-5">
+                                       <div class="well well-lg">
+                                               <div class="row">
+                                               <div class="col-md-6">
+                                                       <b>Drag</b> charts to pan.
+                                                       <b>Shift + wheel</b> on them, to zoom in and out.
+                                                       <b>Double-click</b> on them, to reset.
+                                                       <b>Hover</b> on them too!
+                                                       </div>
+                                               <div class="col-md-6">
+                                                       <div data-netdata="system.intr" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-dygraph-type="line" data-dygraph-strokewidth="3" data-dygraph-smooth="true" data-dygraph-highlightcirclesize="6" data-after="-90" data-height="60px" data-colors="#C66"></div>
                                                        </div>
-                                                       </td></tr>
-                                       </table>
-                          </div><!-- /.maingraph -->
-                       </td></tr>
-               </table>
+                                               </div>
+                                       </div>
+                               </div>
+                       </div>
+               </div>
        </div>
 
-    <div class="container graphs" id="thumbgraphs_container" style="display: none;">
-       <div id="thumbgraphs">
-       </div>
+       <div class="container">
+               <div class="row">
+                       <div class="col-md-10" role="main">
+                               <div id="charts_div"></div>
+                       </div>
+                       <div class="col-md-2" role="complementary">
+                               <nav class="dashboard-sidebar hidden-print hidden-xs hidden-sm" data-spy="affix" id="sidebar" role="menu"></nav>
+                       </div>
+               </div>
        </div>
 
-    <div class="container graphs" id="groupgraphs_container" style="display: none;">
-       <div class="allgraphs" id="groupgraphs">
-       </div>
+<div class="modal fade" id="welcomeModal" tabindex="-1" role="dialog" aria-labelledby="welcomeModalLabel">
+       <div class="modal-dialog modal-lg" role="document">
+               <div class="modal-content">
+                       <div class="modal-header">
+                               <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                               <h4 class="modal-title" id="welcomeModalLabel">Welcome to netdata!</h4>
+                       </div>
+                       <div class="modal-body">
+                                       <div class="p">
+                                       <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> is the fastest way to visualize data. It is a resource efficient, highly optimized system for collecting and visualizing any type of realtime timeseries data, from CPU usage, disk activity, SQL queries, to web site visitors, e-shop orders, revenue and profits.
+                                       </div>
+                                       <div class="p">
+                                       To make a chart in <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b>, you just need a <b>number</b>. Just a number you can read somehow. <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> will turn this number to a real time web chart. For collecting these numbers, it supports <a href="https://github.com/firehol/netdata/tree/master/plugins.d" target="_blank">external plugins</a>, even <a href="https://github.com/firehol/netdata/tree/master/charts.d" target="_blank">bash shell plugins</a>. Any computer program, in any language, that can print a few lines of text on its standard output, can be a netdata data collector.
+                                       </div>
+                                       <div class="p">
+                                       <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> can embed charts everywhere, like this one <div data-netdata="system.cpu" data-dimensions="system" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-show-value-of-system-at="system.cpu.system.modal.1"></div> (my CPU system usage which is <span id="system.cpu.system.modal.1" style="display: inline-block; width: 40px; text-align: right;"></span>%),
+                                       or this one <div data-netdata="ipv4.tcppackets" data-dimensions="received" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-show-value-of-received-at="ipv4.tcppackets.received.modal.1"></div> (my IPv4 received TCP packets, which are <span id="ipv4.tcppackets.received.modal.1" style="display: inline-block; width: 60px; text-align: right;"></span>/second).
+                                       </div>
+                                       <div class="p">
+                                       You can have <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> charts on your site too. Just give it a <code>div</code> and a real time chart, zoomable and draggable will appear (try it even on these tiny ones - <b>drag</b> them to pan horizontally, <b>shift + drag</b> to zoom in, on <b>chrome shift + mouse wheel</b> to zoom in/out, <b>double click</b> on them to reset them - don't be afraid of <b><a href="https://github.com/firehol/netdata/" target="_blank">netdata</a></b> performance - <a href="https://github.com/firehol/netdata/issues/36" target="_blank">a raspberry pi 2 can sustain 300 charts updates per second</a>!).
+                                       </div>
+                                       <div class="p">
+                                       If you like this project, <b>we need help writing documentation, coding plugins, testing new features, supporting end users.</b>
+                                       </div>
+                                       <div class="p">
+                                       We will be glad to have you on board...
+                                       </div>
+                       </div>
+                       <div class="modal-footer">
+                               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+                       </div>
+               </div>
        </div>
+</div>
 
-    <div class="container" id="splash_container">
-               <table width="100%">
-                       <tr><td id="splash" align="center" style="vertical-align: middle; height: 400px; overflow: auto;">
-                               <h2>
-                               Welcome to <b>NetData</b>!
-                               <br/><br/>
-                               <span class="glyphicon glyphicon-off"></span>
-                               <br/><br/>
-                               loading cosmos
-                               <br/><br/>
-                               <span class="label label-default">Please wait...</span>
-                               </h2>
-                       </td></tr>
-               </table>
-       </div>
+</body>
+</html>
+<script>
+
+
+var demo_hostname = 'netdata.firehol.org';
+// var demo_hostname = 'box';
+
+//if(document.location.hostname === demo_hostname) {
+       document.getElementById('masthead').style.display = 'block';
+//}
+
+var options = {
+       sparklines_registry: {},
+       data: null,
+       hostname: 'netdata_server', // will be overwritten by the netdata server
+       categories: new Array(),
+       categories_idx: {},
+       families: new Array(),
+       families_idx: {},
+
+       chartsPerRow: 0,
+       chartsMinWidth: 1450,
+       chartsHeight: 180,
+       sparklinesHeight: 60
+};
+
+// generate a sparkline
+// used in the documentation
+function sparkline(chart, dimension, units) {
+       var key = chart + '.' + dimension;
+
+       if(typeof units === 'undefined')
+               units = '';
+
+       if(typeof options.sparklines_registry[key] === 'undefined')
+               options.sparklines_registry[key] = { count: 1 };
+       else
+               options.sparklines_registry[key].count++;
+
+       key = key + '.' + options.sparklines_registry[key].count;
+
+       var h = '<div data-netdata="' + chart + '" data-after="-120" data-width="25%" data-height="15px" data-chart-library="dygraph" data-dygraph-theme="sparkline" data-dimensions="' + dimension + '" data-show-value-of-' + dimension + '-at="' + key + '"></div> (<span id="' + key + '" style="display: inline-block; min-width: 50px; text-align: right;">X</span>' + units + ')';
+
+       return h;
+}
+
+// documentation for each category and chart
+var messages = {
+
+       // categories / sections
+       'system': 'Overview of the key system metrices.',
+       'tc': 'Netdata collects and visualizes tc class utilization using its <a href="https://github.com/firehol/netdata/blob/master/plugins.d/tc-qos-helper.sh" target="_blank">tc-helper plugin</a>. If you also use <a href="http://firehol.org/#fireqos" target="_blank">FireQOS</a> for setting up QoS, netdata automatically collects interface and class names.',
+       'net': 'Per network interface statistics collected from <code>/proc/net/dev</code>.',
+       'apps': 'Per application statistics are collected using netdata\'s <code>apps.plugin</code>. This plugin walks through the entire <code>/proc</code> filesystem and aggregates statistics for applications of interest, defined in <code>/etc/netdata/apps_groups.conf</code> (the default is <a href="https://github.com/firehol/netdata/blob/master/conf.d/apps_groups.conf" target="_blank">here</a>). The plugin internaly builds a process tree (much like <code>ps fax</code> does), and groups processes together (evaluating both child and parent processes) so that the result is always a chart with a predefined set of dimensions (of course, only application groups found running are reported).<br/><b>IMPORTANT</b>: The values shown here are not 100% accurate. They only include values for the processes running. If an application is spawning childs continiously, which are terminated in just a few milliseconds (like shell scripts do), the values reported will be inaccurate. Linux does report the values for the exited childs of a process. However, these values are reported to the parent process <b>only when the child exits</b>. If these values, of the exited child processes, were also aggregated in the charts below, the charts would have been full of spikes, presenting unrealisting utilization for each process group. So, we decided to ignore these values and present only the utilization of <b>the currently running processes</b>.',
+
+       // charts
+       'system.cpu': 'Total CPU utilization (all cores). 100% here means there is no CPU idle time at all. You can get per core usage at the <a href="#cpu">CPUs</a> section and per application usage at the <a href="#apps">Applications Monitoring</a> section.<br/>Keep an eye on <b>iowait</b> ' + sparkline('system.cpu', 'iowait', '%') + '. If it is constantly high, your disks are a bottleneck and they slow your system down.<br/>Another important metric worth monitoring, is <b>softirq</b> ' + sparkline('system.cpu', 'softirq', '%') + '. A constantly high percentage of softirq may indicate network drivers issues.',
+       'system.io': 'Total Disk I/O, for all disks, read from <code>/proc/vmstat</code>. You can get detailed information about each disk at the <a href="#disk">Disks</a> section and per application Disk usage at the <a href="#apps">Applications Monitoring</a> section.',
+       'system.swapio': 'Total Swap I/O, read from <code>/proc/vmstat</code>. (netdata measures both <code>in</code> and <code>out</code>. If either of them is not shown in the chart, it is because it is zero - you can change the page settings to always render all the available dimensions on all charts).',
+       'system.pgfaults': 'Total page faults, read from <code>/proc/vmstat</code>. <b>Major page faults</b> indicates that the system is using its swap. You can find which applications use the swap at the <a href="#apps">Applications Monitoring</a> section.',
+       'system.entropy': '<a href="https://en.wikipedia.org/wiki/Entropy_(computing)" target="_blank">Entropy</a>, read from <code>/proc/sys/kernel/random/entropy_avail</code>, is like a pool of random numbers that are mainly used in cryptography. It is advised that the pool remains always <a href="https://blog.cloudflare.com/ensuring-randomness-with-linuxs-random-number-generator/" target="_blank">above 200</a>. If the pool of entropy gets empty, you risk your security to be predictable and you should install a user-space random numbers generating daemon, like <a href="http://www.issihosts.com/haveged/" target="_blank">haveged</a>, to keep the pool in healthy levels.',
+       'system.forks': 'The number of new processes created per second, read from <code>/proc/stat</code>.',
+       'system.intr': 'Total number of CPU interrupts, read from <code>/proc/stat</code>. Check <code>system.interrupts</code> that gives more detail about each interrupt and also the <a href="#cpu">CPUs</a> section where interrupts are analyzed per CPU core.',
+       'system.interrupts': 'CPU interrupts in detail, read from <code>/proc/interrupts</code>. At the <a href="#cpu">CPUs</a> section, interrupts are analyzed per CPU core.',
+       'system.softirqs': 'CPU softirqs in detail, read from <code>/proc/softirqs</code>. At the <a href="#cpu">CPUs</a> section, softirqs are analyzed per CPU core.',
+       'system.processes': 'System processes, read from <code>/proc/stat</code>. <b>Blocked</b> are processes that are willing to execute but they cannot, e.g. because they wait for disk activity.',
+       'system.ctxt': '<a href="https://en.wikipedia.org/wiki/Context_switch" target="_blank">Context Switches</a>, read from <code>/proc/stat</code>, is the switching of the CPU from one process, task or thread to another. If there are many processes or threads willing to execute and very few CPU cores available to handle them, the system is making more context switching to balance the CPU resources among them. The whole process is computationally intensive. The more the context switches, the slower the system gets.',
+       'system.idlejitter': 'Idle jitter is calculated by netdata. A thread is spawned that requests to sleep for a few microseconds. When the system wakes it up, it measures how many microseconds have passed. The different between the requested and the actual duration of the sleep, is the <b>idle jitter</b>. This number is useful in realtime environments, where CPU jitter can affect the quality of the service (like VoIP media gateways).',
+       'system.ipv4': 'Total IPv4 Traffic, read from <code>/proc/net/netstat</code>. This includes <code>lo</code> device traffic.',
+       'system.ram': 'System memory, read from <code>/proc/meminfo</code>.',
+       'system.swap': 'System swap memory, read from <code>/proc/meminfo</code>.',
+
+       // just a line to allow ending all entries above with comma
+       'end': 'end'
+};
+
+function screenWidth() {
+       return (($(window).width() * 0.95) - 50);
+}
+
+function chartsPerRow(total) {
+       if(options.chartsPerRow === 0) {
+               width = Math.floor(total / options.chartsMinWidth);
+               if(width === 0) width = 1;
+               return width;
+       }
+       else return options.chartsPerRow;
+}
+
+function chartsPrioritySort(a, b) {
+       if(a.priority === b.priority) {
+               if(a.name < b.name) return -1;
+       }
+       else if(a.priority < b.priority) return -1;
+       return 1;
+}
+
+function uniq(array, find_key, get_result) {
+       if(typeof get_result === 'undefined' || get_result === null)
+               get_result = find_key;
+
+       var idx = {};
+       var result = new Array();
+
+       $.each(array, function(i, c) {
+               key = find_key(c);
+               if(typeof idx[key] === 'undefined') {
+                       idx[key] = true;
+                       result.push(get_result(c));
+               }
+       });
+       return result;
+}
+
+function uniq_with_list(array, find_key_function) {
+       var idx = {};
+       var result = new Array();
+
+       $.each(array, function(i, c) {
+               key = find_key_function(c);
+               if(typeof idx[key] === 'undefined') {
+                       idx[key] = new Array();
+                       result.push( { name: key, values: idx[key] } );
+               }
+               idx[key].push(c);
+       });
+       result.sort(function(a, b) {
+               if(a.name < b.name) return -1;
+               return 1;
+       });
+       return result;
+}
+
+function prepareScreen(data) {
+       // console.log('NETDATA is paused - ready to prepare the screen');
+       // console.log(data);
 
-    <div class="container graphs" id="footer_container">
-               &nbsp;<p/>
-               <hr/>
-       <h4>NetData</h4>
-       Realtime System Information over the web for all linux systems.
-       <p/>
-       Distributed under GPL v2.
-       <p/>
-       (c) 2015 Costa Tsaousis <a href="mailto:costa@tsaousis.gr">costa@tsaousis.gr</a>
-       <p/>
-       <div id="server_summary_id"></div>
-    </div>
-
-       <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
-       <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
-       <script type='text/javascript'>
-               document.getElementById('splash').height = $(window).height();
-       </script>
-
-       <!-- Google AJAX API -->
-       <script type="text/javascript" src="https://www.google.com/jsapi"></script>
-
-       <!-- NetData -->
-       <script type="text/javascript" src="/file/netdata.js"></script>
-       <script type="text/javascript" src="/file/index.js"></script>
-
-       <script type='text/javascript'>
-               google.load('visualization', '1.1', {packages: ['controls']});
-
-               $(document).ready(function(){
-
-                       $(document).on('click','.navbar-collapse.in',function(e) {
-                               if( $(e.target).is('a') ) {
-                                       $(this).collapse('hide');
+       options.data = data;
+       options.hostname = data.hostname;
+       document.getElementById('hostname').innerHTML = options.hostname;
+       document.title = options.hostname + ' dashboard';
+       var charts = data.charts;
+
+       $.each(charts, function(i, c) {
+               if(c.enabled === true) {
+
+                       // find the category of the chart
+                       c.category = c.type.split('.')[0];
+
+                       var tmp = c.category.split('_')[0];
+                       if(tmp === 'net' || tmp === 'disk')
+                               c.category = tmp;
+
+                       if(c.category === 'cpu') {
+                               if(c.id.match(/^cpu\.cpu[0-9]+$/)) {
+                                       c.family = 'Utilization';
+                               }
+                               else if(c.id.match(/^cpu\.cpu[0-9]+_interrupts$/)) {
+                                       c.family = 'Interrupts';
+                               }
+                               else if(c.id.match(/^cpu\.cpu[0-9]+_softirqs$/)) {
+                                       c.family = 'SoftIRQs';
+                               }
+                       }
+
+                       switch(c.category) {
+                               case 'system':
+                                       c.category_priority = 10;
+                                       c.category_title = 'System Summary';
+                                       c.glyphicon = "glyphicon-dashboard";
+                                       break;
+
+                               case 'tc':
+                                       c.category_priority = 20;
+                                       c.category_title = 'Quality Of Service';
+                                       c.glyphicon = "glyphicon-random";
+                                       break;
+
+                               case 'net':
+                                       c.category_priority = 30;
+                                       c.category_title = 'Network Interfaces';
+                                       c.glyphicon = "glyphicon-transfer";
+                                       break;
+
+                               case 'apps':
+                                       c.category_priority = 40;
+                                       c.category_title = 'Applications Monitoring';
+                                       c.glyphicon = "glyphicon-tasks";
+                                       break;
+
+                               case 'ipvs':
+                                       c.category_priority = 50;
+                                       c.category_title = 'IP Virtual Server';
+                                       c.glyphicon = "glyphicon-transfer";
+                                       break;
+
+                               case 'netfilter':
+                                       c.category_priority = 60;
+                                       c.category_title = 'Netfilter / IPTables';
+                                       c.glyphicon = "glyphicon-cloud";
+                                       break;
+
+                               case 'ipv4':
+                                       c.category_priority = 70;
+                                       c.category_title = 'IPv4 Summary';
+                                       c.glyphicon = "glyphicon-globe";
+                                       break;
+
+                               case 'mem':
+                                       c.category_priority = 80;
+                                       c.category_title = 'Memory';
+                                       c.glyphicon = "glyphicon-dashboard";
+                                       break;
+
+                               case 'cpu':
+                                       c.category_priority = 90;
+                                       c.category_title = 'CPU Cores';
+                                       c.glyphicon = "glyphicon-dashboard";
+                                       break;
+
+                               case 'disk':
+                                       c.category_priority = 100;
+                                       c.category_title = 'Disks';
+                                       c.glyphicon = "glyphicon-hdd";
+                                       break;
+
+                               case 'nfsd':
+                                       c.category_priority = 110;
+                                       c.category_title = 'NFS Server';
+                                       c.glyphicon = "glyphicon-hdd";
+                                       break;
+
+                               case 'squid':
+                                       c.category_priority = 140;
+                                       c.category_title = 'Proxy Server';
+                                       c.glyphicon = "glyphicon-link";
+                                       break;
+
+                               case 'netdata':
+                                       c.category_priority = 150;
+                                       c.category_title = 'Netdata Monitoring';
+                                       c.glyphicon = "glyphicon-thumbs-up";
+                                       break;
+
+                               case 'sensors':
+                                       c.category_priority = 160;
+                                       c.category_title = 'Hardware Sensors';
+                                       c.glyphicon = "glyphicon-thumbs-up";
+                                       break;
+
+                               case 'postfix':
+                                       c.category_priority = 170;
+                                       c.category_title = 'Mail Server';
+                                       c.glyphicon = "glyphicon-thumbs-up";
+                                       break;
+
+                               case 'example':
+                                       c.category_priority = 100000;
+                                       c.category_title = 'Example Plugins';
+                                       c.glyphicon = "glyphicon-search";
+                                       break;
+
+                               default:
+                                       c.category_priority = 150;
+                                       c.category_title = c.type;
+                                       c.glyphicon = "glyphicon-dashboard";
+                                       break;
+                       }
+
+                       // find the unique categories
+                       if(typeof options.categories_idx[c.category] === 'undefined') {
+                               options.categories_idx[c.category] = {
+                                       charts: new Array()
+                               }
+                               options.categories.push({
+                                       name: c.category,
+                                       title: c.category_title,
+                                       priority: c.category_priority,
+                                       glyphicon: c.glyphicon,
+                                       charts: options.categories_idx[c.category].charts
+                               });
+                       }
+                       options.categories_idx[c.category].charts.push(c);
+
+                       // find the unique families
+                       if(typeof options.families_idx[c.family] === 'undefined') {
+                               options.families_idx[c.family] = {
+                                       charts: new Array()
+                               };
+                               options.families.push({
+                                       name: c.family,
+                                       title: c.family,
+                                       priority: c.category_priority,
+                                       glyphicon: c.glyphicon,
+                                       charts: options.categories_idx[c.category].charts
+                               });
+                       }
+                       options.families_idx[c.family].charts.push(c);
+               }
+       });
+
+       function prioritySort(a, b) {
+               if(a.priority < b.priority) return -1;
+               if(a.priority > b.priority) return 1;
+               if(a.name < b.name) return -1;
+               return 1;
+       }
+
+       // sort all of them
+       options.categories.sort(prioritySort);
+       options.families.sort(prioritySort);
+       $.each(options.families,   function(i, c) { c.charts.sort(prioritySort); });
+
+       var div = document.getElementById('charts_div');
+       var pcent_width = Math.floor(100 / chartsPerRow($(div).width()));
+
+       // find the proper duration for per-second updates
+       var duration = Math.round(($(div).width() * pcent_width / 100 * data.update_every / 3) / 60) * 60;
+       var html = '';
+       var sidebar = '<ul class="nav dashboard-sidenav" id="sidebar_ul">';
+
+       function getMessage(id) {
+               if(typeof messages[id] !== 'undefined')
+                       return '<div class="chart-message" role="document">' + messages[id] + '</div>';
+               else
+                       return '';
+       }
+
+       // render the charts
+       $.each(options.categories, function(i, t) {
+               t.charts.sort(prioritySort);
+
+               sidebar += '<li class="' + ((i === 0)?'active':'').toString() + '"><a href="#' + t.name + '">' + t.title + '</a>';
+               html += '<div role="section"><div role="sectionhead"><h1 id="' + t.name + '" role="heading">' + t.title + '</h1>' + getMessage(t.name) + '</div><div id="' + t.name + '" role="document">';
+
+               if(t.name === 'cpu') {
+                       var families = uniq_with_list(t.charts, function(c) { return c.family; });
+
+                       sidebar += '<ul class="nav">';
+                       $.each(families, function(j, c) {
+                               sidebar += '<li class><a href="#' + t.name + '_' + c.name + '">' + c.name + '</a></li>';
+                               html += '<div class="netdata-group-container" id="family_' + t.name + '_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + t.name + '_' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
+                               $.each(c.values, function(x, f) {
+                                       var c = null;
+                                       var h = options.chartsHeight;
+
+                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
+                                               + ' data-width="100%"'
+                                               + ' data-height="' + h.toString() + 'px"'
+                                               + ' data-before="0"'
+                                               + ' data-after="-' + duration.toString() + '"'
+                                               + ' data-colors="' + c + '"'
+                                               + ' role="application"></div>';
+                               });
+                               html += '</div>'; // netdata-group-container
+                       });
+                       sidebar += '</ul>';
+               }
+               else if(t.name === 'net' || t.name === 'tc') {
+                       var interfaces = uniq_with_list(t.charts, function(c) { return c.family; });
+
+                       sidebar += '<ul class="nav">';
+                       $.each(interfaces, function(j, c) {
+                               sidebar += '<li class><a href="#' + t.name + '_' + c.name + '">' + c.name + '</a></li>';
+                               html += '<div class="netdata-group-container" id="interface_' + t.name + '_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + t.name + '_' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
+                               $.each(c.values, function(x, f) {
+                                       var c = null;
+                                       var h = options.chartsHeight / 2;
+                                       switch(f.type) {
+                                               case 'net'        : h = options.chartsHeight; break;
+                                               case 'tc'         : h = options.chartsHeight; break;
+                                       }
+
+                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
+                                               + ' data-width="100%"'
+                                               + ' data-height="' + h.toString() + 'px"'
+                                               + ' data-before="0"'
+                                               + ' data-after="-' + duration.toString() + '"'
+                                               + ' data-colors="' + c + '"'
+                                               + ' role="application"></div>';
+                               });
+                               html += '</div>'; // netdata-group-container
+                       });
+                       sidebar += '</ul>';
+               }
+               else if(t.name === 'disk') {
+                       var disks = uniq_with_list(t.charts, function(c) { return c.family; });
+
+                       sidebar += '<ul class="nav">';
+                       $.each(disks, function(j, c) {
+                               sidebar += '<li class><a href="#' + c.name + '">' + c.name + '</a></li>';
+                               html += '<div class="netdata-group-container" id="disk_' + c.name + '" style="display: inline-block; width: ' + pcent_width.toString() + '%"><h2 id="' + c.name + '" class="netdata-chart-alignment" role="heading">' + c.name + '</h2>';
+                               $.each(c.values, function(x, f) {
+                                       var c = null;
+                                       var h = options.chartsHeight / 2;
+                                       switch(f.type) {
+                                               case 'disk'        : h = options.chartsHeight; break;
+                                               case 'disk_backlog': c = '#DD4477'; break;
+                                               case 'disk_util'   : c = '#109618'; break;
+                                               case 'disk_qops'   : c = '#E67300'; break;
+                                       }
+
+                                       html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
+                                               + ' data-width="100%"'
+                                               + ' data-height="' + h.toString() + 'px"'
+                                               + ' data-before="0"'
+                                               + ' data-after="-' + duration.toString() + '"'
+                                               + ' data-colors="' + c + '"'
+                                               + ' role="application"></div>';
+                               });
+                               html += '</div>'; // netdata-group-container
+                       });
+                       sidebar += '</ul>';
+               }
+               else if(t.name === 'apps') {
+                       $.each(t.charts, function(x, f) {
+                               var c = null;
+                               var h = options.chartsHeight / 2;
+                               switch(f.id) {
+                                       case 'apps.cpu'         : h = options.chartsHeight; break;
+                                       case 'apps.preads'      : h = options.chartsHeight; break;
+                                       case 'apps.pwrites'     : h = options.chartsHeight; break;
+                                       case 'apps.mem'         : h = options.chartsHeight; break;
+                                       case 'apps.major_faults': h = options.chartsHeight; break;
                                }
+
+                               html += getMessage(f.id) + '<div data-netdata="' + f.id + '"'
+                                       + ' data-width="100%"'
+                                       + ' data-height="' + h.toString() + 'px"'
+                                       + ' data-before="0"'
+                                       + ' data-after="-' + duration.toString() + '"'
+                                       + ' data-colors="' + c + '"'
+                                       + ' role="application"></div>';
                        });
+               }
+               else {
+                       $.each(t.charts, function(x, c) {
+                               html += getMessage(c.id) + '<div data-netdata="' + c.id + '"'
+                                       + ' data-width="' + pcent_width.toString() + '%"'
+                                       + ' data-height="' + options.chartsHeight.toString() + 'px"'
+                                       + ' data-before="0"'
+                                       + ' data-after="-' + duration.toString() + '"'
+                                       + ' role="application"></div>';
+                       });
+               }
+
+               sidebar += '</li>';
+               html += '</div>'; // document
+               html += '</div>'; // section
+               html += '<hr role="separator"/>';
+       });
+       sidebar += '</ul>';
+/*
+       // show the colors
+       html += '<br/><div class="row">'
+       $.each(NETDATA.colors, function(i, c){
+               html += '<div style="display: inline-block;"><div style="display: inline-block; width: 100px; height: 100px; background: ' + c + ';"></div><br/>' + c + '</div>';
+       });
+       html += '</div>'
+*/
+       div.innerHTML = html;
+       document.getElementById('sidebar').innerHTML = sidebar;
+
+       // resize all charts - without starting the background thread
+       // this has to be done while NETDATA is paused
+       // if we ommit this, the affix menu will be wrong, since all
+       // the Dom elements are initially zero-sized
+       NETDATA.parseDom();
+
+       // let it run (update the charts)
+       NETDATA.unpause();
+
+       // check if we have to jump to a specific section
+       var hash = location.hash.replace('#','');
+       if(hash != '') {
+               // Clear the hash in the URL
+               // location.hash = '';   // delete front "//" if you want to change the address bar
+               var offset = $(location.hash).offset();
+               if(typeof offset !== 'undefined')
+                       $('html, body').animate({ scrollTop: offset.top }, 0);
+       }
+
+       /* activate bootstrap scrollspy (needed for sidebar) */
+       $(document.body).scrollspy({
+               target: '#sidebar',
+               offset: $(window).height() / 3 // controls the diff of the <hX> element to the top, to select it
+       });
+
+       /* activate bootstrap sidebar (affix) */
+       $('#sidebar').affix({
+               offset: {
+                       top: 200,
+                       bottom: 0
+               }
+       });
+
+       /* fix scrolling of very long affix lists
+          http://stackoverflow.com/questions/21691585/bootstrap-3-1-0-affix-too-long
+        */
+       $('#sidebar').on('affixed.bs.affix', function() {
+               $(this).removeAttr('style');
+       });
+}
 
-                       $('body').scrollspy({ target: '#main_menu_div' })
+NETDATA.ready(function() {
+
+       $('#welcomeModal').on('hidden.bs.modal', function (e) {
+               NETDATA.updatedDom();
+       });
+       $('#welcomeModal').on('shown.bs.modal', function (e) {
+               NETDATA.updatedDom();
+       });
+
+       // download all the charts the server knows
+       NETDATA.chartRegistry.downloadAll(NETDATA.serverDefault, function(data) {
+
+               // pause the NETDATA thread that updates the charts
+               NETDATA.pause(function() {
+
+                       if(document.location.hostname === demo_hostname)
+                               $('#welcomeModal').modal();
+
+                       // prepare our DOM
+                       // this will be called when NETDATA is paused
+                       prepareScreen(data);
                });
-       </script>
-</html>
+       });
+});
+
+</script>
diff --git a/web/index.js b/web/index.js
deleted file mode 100755 (executable)
index 3a28daf..0000000
+++ /dev/null
@@ -1,1174 +0,0 @@
-var page_is_visible = 1;
-
-var TARGET_THUMB_GRAPH_WIDTH = 500;            // thumb charts width will range from 0.5 to 1.5 of that
-var MINIMUM_THUMB_GRAPH_WIDTH = 400;   // thumb chart will generally try to be wider than that
-var TARGET_THUMB_GRAPH_HEIGHT = 160;   // the height of the thumb charts
-var TARGET_GROUP_GRAPH_HEIGHT = 160;
-
-var THUMBS_MAX_TIME_TO_SHOW = 240;             // how much time the thumb charts will present?
-var THUMBS_POINTS_DIVISOR = 3;
-var THUMBS_STACKED_POINTS_DIVISOR = 4;
-
-var GROUPS_MAX_TIME_TO_SHOW = 600;             // how much time the group charts will present?
-var GROUPS_POINTS_DIVISOR = 2;
-var GROUPS_STACKED_POINTS_DIVISOR = 3;
-
-var MAINCHART_MIN_TIME_TO_SHOW = 1200; // how much time the main chart will present by default?
-var MAINCHART_POINTS_DIVISOR = 2;              // how much detailed will the main chart be by default? 1 = finest, higher is faster
-var MAINCHART_STACKED_POINTS_DIVISOR = 3;              // how much detailed will the main chart be by default? 1 = finest, higher is faster
-
-var MAINCHART_CONTROL_HEIGHT = 75;             // how tall the control chart will be
-var MAINCHART_CONTROL_DIVISOR = 5;             // how much detailed will the control chart be? 1 = finest, higher is faster
-var MAINCHART_INITIAL_SELECTOR= 20;            // 1/20th of the width, this overrides MAINCHART_MIN_TIME_TO_SHOW
-
-var CHARTS_REFRESH_LOOP = 50;                  // delay between chart refreshes
-var CHARTS_REFRESH_IDLE = 500;                 // delay between chart refreshes when no chart was ready for refresh the last time
-var CHARTS_CHECK_NO_FOCUS = 500;               // delay to check for visibility when the page has no focus
-var CHARTS_SCROLL_IDLE = 100;                  // delay to wait after a page scroll
-
-var ENABLE_CURVE = 1;
-
-var resize_request = false;
-
-function setPresentationNormal(ui) {
-       THUMBS_POINTS_DIVISOR                           = 3;
-       THUMBS_STACKED_POINTS_DIVISOR           = Math.round(THUMBS_POINTS_DIVISOR * 1.5);
-       GROUPS_POINTS_DIVISOR                           = 2;
-       GROUPS_STACKED_POINTS_DIVISOR           = Math.round(GROUPS_POINTS_DIVISOR * 1.5);
-       MAINCHART_POINTS_DIVISOR                        = 2;
-       MAINCHART_STACKED_POINTS_DIVISOR        = Math.round(MAINCHART_POINTS_DIVISOR * 1.5);
-       ENABLE_CURVE = 1;
-       CHARTS_REFRESH_LOOP = 50;
-       CHARTS_SCROLL_IDLE = 50;
-       resize_request = true;
-       if(ui) $('#presentation_normal').trigger('click');
-       playGraphs();
-}
-function setPresentationSpeedy(ui) {
-       THUMBS_POINTS_DIVISOR                           = 10;
-       THUMBS_STACKED_POINTS_DIVISOR           = Math.round(THUMBS_POINTS_DIVISOR * 1.5);
-       GROUPS_POINTS_DIVISOR                           = 8;
-       GROUPS_STACKED_POINTS_DIVISOR           = Math.round(GROUPS_POINTS_DIVISOR * 1.5);
-       MAINCHART_POINTS_DIVISOR                        = 5;
-       MAINCHART_STACKED_POINTS_DIVISOR        = Math.round(MAINCHART_POINTS_DIVISOR * 1.5);
-       ENABLE_CURVE = 0;
-       CHARTS_REFRESH_LOOP = 50;
-       CHARTS_SCROLL_IDLE = 100;
-       resize_request = true;
-       if(ui) $('#presentation_speedy').trigger('click');
-       playGraphs();
-}
-function setPresentationDetailed(ui) {
-       THUMBS_POINTS_DIVISOR                           = 1;
-       THUMBS_STACKED_POINTS_DIVISOR           = 1;
-       GROUPS_POINTS_DIVISOR                           = 1;
-       GROUPS_STACKED_POINTS_DIVISOR           = 1;
-       MAINCHART_POINTS_DIVISOR                        = 1;
-       MAINCHART_STACKED_POINTS_DIVISOR        = 1;
-       ENABLE_CURVE = 1;
-       CHARTS_REFRESH_LOOP = 50;
-       CHARTS_SCROLL_IDLE = 50;
-       resize_request = true;
-       if(ui) $('#presentation_detailed').trigger('click');
-       playGraphs();
-}
-
-function isIE() {
-  userAgent = navigator.userAgent;
-  return userAgent.indexOf("MSIE ") > -1 || userAgent.indexOf("Trident/") > -1;
-}
-
-if(isIE()){
-       // do stuff with ie-users
-       CHARTS_REFRESH_LOOP=250;
-       CHARTS_SCROLL_IDLE=500;
-}
-
-var MODE_THUMBS = 1;
-var MODE_MAIN = 2;
-var MODE_GROUP_THUMBS = 3;
-var mode; // one of the MODE_* values
-
-var allCharts = new Array();
-var mainchart;
-
-// html for the main menu
-var mainmenu = "";
-var categoriesmainmenu = "";
-var familiesmainmenu = "";
-var chartsmainmenu = "";
-
-
-// ------------------------------------------------------------------------
-// common HTML generation
-
-function thumbChartActions(i, c, nogroup) {
-       var name = c.name;
-       if(!nogroup) name = c.family;
-
-       var refinfo = "the chart is drawing ";
-       if(c.group == 1) refinfo += "every single point collected (" + c.update_every + "s each).";
-       else refinfo += ((c.group_method == "average")?"the average":"the max") + " value for every " + (c.group * c.update_every) + " seconds of data";
-
-       var html = "<div class=\"btn-group btn-group\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"" + refinfo + "\">"
-       +               "<button type=\"button\" class=\"btn btn-default\" onclick=\"javascript: return;\"><span class=\"glyphicon glyphicon-info-sign\"></span></button>"
-       +       "</div>"
-       +       "<div class=\"btn-group btn-group\"><button type=\"button\" class=\"btn btn-default disabled\"><small>&nbsp;&nbsp; " + name + "</small></button>";
-
-       if(!nogroup) {
-               var ingroup = 0;
-               var ingroup_detail = 0;
-
-               $.each(allCharts, function(i, d) {
-                       if(d.family == c.family) {
-                               ingroup++;
-                               if(d.isdetail) ingroup_detail++;
-                       }
-               });
-
-               var hidden = "";
-               if(ingroup_detail) hidden = ", including " + ingroup_detail + " charts not shown now";
-
-               html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Show all " + ingroup + " charts in group '" + c.family + "'" + hidden + "\" class=\"btn btn-default\" onclick=\"initGroupGraphs('" + c.family +"');\"><span class=\"glyphicon glyphicon-th-large\"></span></button>";
-       }
-
-       html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"show chart '" + c.name + "' in fullscreen\" class=\"btn btn-default\" onclick=\"initMainChartIndex(" + i +");\"><span class=\"glyphicon glyphicon-resize-full\"></span></button>"
-       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"set options for chart '" + c.name + "'\" class=\"btn btn-default disabled\" onclick=\"alert('Not implemented yet!');\"><span class=\"glyphicon glyphicon-cog\"></span></button>"
-       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"ignore chart '" + c.name + "'\" class=\"btn btn-default\" onclick=\"disableChart(" + i + ");\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
-       +       "</div>";
-
-       return html;
-}
-
-function groupChartActions(i, c) {
-       var name = c.name;
-
-       var refinfo = "the chart is drawing ";
-       if(c.group == 1) refinfo += "every single point collected (" + c.update_every + "s each).";
-       else refinfo += ((c.group_method == "average")?"the average":"the max") + " value for every " + (c.group * c.update_every) + " seconds of data";
-
-       var html = "<div class=\"btn-group btn-group\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"" + refinfo + "\">"
-       +               "<button type=\"button\" class=\"btn btn-default\" onclick=\"javascript: return;\"><span class=\"glyphicon glyphicon-info-sign\"></span></button>"
-       +       "</div>";
-
-       html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"show chart '" + c.name + "' in fullscreen\" class=\"btn btn-default\" onclick=\"initMainChartIndex(" + i +");\"><span class=\"glyphicon glyphicon-resize-full\"></span></button>"
-       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"ignore chart '" + c.name + "'\" class=\"btn btn-default\" onclick=\"disableChart(" + i + ");\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
-       +       "</div>";
-
-       return html;
-}
-
-function mylog(txt) {
-       console.log(txt);
-       $('#logline').html(txt);
-}
-
-function chartssort(a, b) {
-       if(a.priority == b.priority) {
-               if(a.name < b.name) return -1;
-       }
-       else if(a.priority < b.priority) return -1;
-
-       return 1;
-}
-
-
-// ------------------------------------------------------------------------
-// MAINGRAPH = fullscreen view of 1 graph
-
-// copy the chart c to mainchart
-// switch to main graphs screen
-function initMainChart(c) {
-       if(mainchart) cleanThisChart(mainchart);
-
-       mainchart = $.extend(true, {}, c);
-       mainchart.enabled = true;
-       mainchart.refreshCount = 0;
-       mainchart.last_updated = 0;
-       mainchart.chartOptions.explorer = null;
-       mainchart.chart = null;
-
-       mainchart.before = 0;
-       mainchart.after = 0;
-
-       mainchart.chartOptions.width = screenWidth();
-       mainchart.chartOptions.height = $(window).height() - 150 - MAINCHART_CONTROL_HEIGHT;
-       if(mainchart.chartOptions.height < 300) mainchart.chartOptions.height = 300;
-
-       mainchart.div = 'maingraph';
-       mainchart.max_time_to_show = (mainchart.last_entry_t - mainchart.first_entry_t) / ( MAINCHART_INITIAL_SELECTOR * mainchart.update_every );
-       if(mainchart.max_time_to_show < MAINCHART_MIN_TIME_TO_SHOW) mainchart.max_time_to_show = MAINCHART_MIN_TIME_TO_SHOW;
-       calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, 0, ENABLE_CURVE);
-
-       // copy it to the hidden chart
-       mainchart.hiddenchart = $.extend(true, {}, mainchart);
-       mainchart.hiddenchart.chartOptions.height = MAINCHART_CONTROL_HEIGHT;
-       mainchart.hiddenchart.div = 'maingraph_control';
-       mainchart.hiddenchart.non_zero = 0;
-
-       // initialize the div
-       showChartIsLoading(mainchart.div, mainchart.name, mainchart.chartOptions.width, mainchart.chartOptions.height);
-       document.getElementById(mainchart.hiddenchart.div).innerHTML = "<table><tr><td align=\"center\" width=\"" + mainchart.hiddenchart.chartOptions.width + "\" height=\"" + mainchart.hiddenchart.chartOptions.height + "\" style=\"vertical-align:middle\"><h4><span class=\"label label-default\">Please wait...</span></h4></td></tr></table>";
-       //showChartIsLoading(mainchart.hiddenchart.div, mainchart.hiddenchart.name, mainchart.hiddenchart.chartOptions.width, mainchart.hiddenchart.chartOptions.height);
-
-       // set the radio buttons
-       setMainChartGroupMethod(mainchart.group_method, 'no-refresh');
-       setMainChartMax('normal');
-
-       $('#group' + mainchart.group).trigger('click');
-       setMainChartGroup(mainchart.group, 'no-refresh');
-
-       switchToMainGraph();
-}
-
-function refreshHiddenChart(doNext) {
-       if(refresh_mode == REFRESH_PAUSED && mainchart.hiddenchart.last_updated != 0) {
-               if(typeof doNext == "function") doNext();
-               return;
-       }
-
-       // is it too soon for a refresh?
-       var now = new Date().getTime();
-       if((now - mainchart.hiddenchart.last_updated) < (mainchart.update_every * 10 * 1000) || (now - mainchart.hiddenchart.last_updated) < (mainchart.hiddenchart.group * mainchart.hiddenchart.update_every * 1000)) {
-               if(typeof doNext == "function") doNext();
-               return;
-       }
-
-       if(mainchart.dashboard && mainchart.hiddenchart.refreshCount > 50) {
-               mainchart.dashboard.clear();
-               mainchart.control_wrapper.clear();
-               mainchart.hidden_wrapper.clear();
-
-               mainchart.dashboard = null;
-               mainchart.control_wrapper = null;
-               mainchart.hidden_wrapper = null;
-               mainchart.hiddenchart.last_updated = 0;
-       }
-
-       if(!mainchart.dashboard) {
-               var controlopts = $.extend(true, {}, mainchart.chartOptions, {
-                       lineWidth: 1,
-                       height: mainchart.hiddenchart.chartOptions.height,
-                       chartArea: {'width': '98%'},
-                       hAxis: {'baselineColor': 'none', viewWindowMode: 'maximized', gridlines: { count: 0 } },
-                       vAxis: {'title': null, gridlines: { count: 0 } },
-               });
-
-               mainchart.dashboard = new google.visualization.Dashboard(document.getElementById('maingraph_dashboard'));
-               mainchart.control_wrapper = new google.visualization.ControlWrapper({
-                       controlType: 'ChartRangeFilter',
-                       containerId: 'maingraph_control',
-                       options: {
-                               filterColumnIndex: 0,
-                               ui: {
-                                       chartType: mainchart.chartType,
-                                       chartOptions: controlopts,
-                                       minRangeSize: (mainchart.max_time_to_show * 1000) / MAINCHART_POINTS_DIVISOR,
-                               }
-                       },
-               });
-               mainchart.hidden_wrapper = new google.visualization.ChartWrapper({
-                       chartType: mainchart.chartType,
-                       containerId: 'maingraph_hidden',
-                       options: {
-                               isStacked: mainchart.chartOptions.isStacked,
-                               width: mainchart.hiddenchart.chartOptions.width,
-                               height: mainchart.hiddenchart.chartOptions.height,
-                               //chartArea: {'height': '80%', 'width': '100%'},
-                               //hAxis: {'slantedText': false},
-                               //legend: {'position': 'none'}
-                       },
-               });
-
-               mainchart.hiddenchart.refreshCount = 0;
-       }
-
-       // load the data for the control and the hidden wrappers
-       // calculate the group and points to show for the control chart
-       calculateChartPointsToShow(mainchart.hiddenchart, MAINCHART_CONTROL_DIVISOR, 0, -1, ENABLE_CURVE);
-
-       $.ajax({
-               url: generateChartURL(mainchart.hiddenchart),
-               dataType:"json",
-               cache: false
-       })
-       .done(function(jsondata) {
-               if(!jsondata || jsondata.length == 0) return;
-
-               mainchart.control_data = new google.visualization.DataTable(jsondata);
-
-               if(mainchart.hiddenchart.last_updated == 0) {
-                       google.visualization.events.addListener(mainchart.control_wrapper, 'ready', mainchartControlReadyEvent);
-                       mainchart.dashboard.bind(mainchart.control_wrapper, mainchart.hidden_wrapper);
-               }
-               if(refresh_mode != REFRESH_PAUSED) {
-                       // console.log('mainchart.points_to_show: ' + mainchart.points_to_show + ', mainchart.group: ' + mainchart.group + ', mainchart.update_every: ' + mainchart.update_every);
-
-                       var start = now - (mainchart.points_to_show * mainchart.group * mainchart.update_every * 1000);
-                       var end = now;
-                       var min = MAINCHART_MIN_TIME_TO_SHOW * 1000;
-                       if(end - start < min) start = end - min;
-
-                       mainchart.control_wrapper.setState({range: {
-                               start: new Date(start),
-                               end: new Date(end)
-                       },
-                       ui: {
-                               minRangeSize: min
-                       }});
-               }
-
-               mainchart.dashboard.draw(mainchart.control_data);
-               mainchart.hiddenchart.last_updated = new Date().getTime();
-               mainchart.hiddenchart.refreshCount++;
-       })
-       .always(function() {
-               if(typeof doNext == "function") doNext();
-       });
-}
-
-function mainchartControlReadyEvent() {
-       google.visualization.events.addListener(mainchart.control_wrapper, 'statechange', mainchartControlStateHandler);
-       //mylog(mainchart);
-}
-
-function mainchartControlStateHandler() {
-       // setMainChartPlay('pause');
-
-       var state = mainchart.control_wrapper.getState();
-       mainchart.after = Math.round(state.range.start.getTime() / 1000);
-       mainchart.before = Math.round(state.range.end.getTime() / 1000);
-
-       calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.before - mainchart.after, 0, ENABLE_CURVE);
-       //mylog('group = ' + mainchart.group + ', points_to_show = ' + mainchart.points_to_show + ', dt = ' + (mainchart.before - mainchart.after));
-
-       $('#group' + mainchart.group).trigger('click');
-       mainchart.last_updated = 0;
-
-       if(refresh_mode != REFRESH_PAUSED) pauseGraphs();
-}
-
-function initMainChartIndex(i) {
-       if(mode == MODE_GROUP_THUMBS)
-               initMainChart(groupCharts[i]);
-
-       else if(mode == MODE_THUMBS)
-               initMainChart(allCharts[i]);
-
-       else
-               initMainChart(allCharts[i]);
-}
-
-function initMainChartIndexOfMyCharts(i) {
-       initMainChart(allCharts[i]);
-}
-
-var last_main_chart_max='normal';
-function setMainChartMax(m) {
-       if(!mainchart) return;
-
-       if(m == 'toggle') {
-               if(last_main_chart_max == 'maximized') m = 'normal';
-               else m = 'maximized';
-       }
-
-       if(m == "maximized") {
-               mainchart.chartOptions.theme = 'maximized';
-               //mainchart.chartOptions.axisTitlesPosition = 'in';
-               //mainchart.chartOptions.legend = {position: 'none'};
-               mainchart.chartOptions.hAxis.title = null;
-               mainchart.chartOptions.hAxis.viewWindowMode = 'maximized';
-               mainchart.chartOptions.vAxis.viewWindowMode = 'maximized';
-               mainchart.chartOptions.chartArea = {'width': '98%', 'height': '100%'};
-       }
-       else {
-               mainchart.chartOptions.hAxis.title = null;
-               mainchart.chartOptions.theme = null;
-               mainchart.chartOptions.hAxis.viewWindowMode = null;
-               mainchart.chartOptions.vAxis.viewWindowMode = null;
-               mainchart.chartOptions.chartArea = {'width': '80%', 'height': '90%'};
-       }
-       $('.mainchart_max_button').button(m);
-       last_main_chart_max = m;
-       mainchart.last_updated = 0;
-}
-
-function setMainChartGroup(g, norefresh) {
-       if(!mainchart) return;
-
-       mainchart.group = g;
-
-       if(!mainchart.before && !mainchart.after)
-               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, mainchart.group, ENABLE_CURVE);
-       else
-               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, 0, mainchart.group, ENABLE_CURVE);
-
-       if(!norefresh) {
-               mainchart.last_updated = 0;
-       }
-}
-
-var last_main_chart_avg = null;
-function setMainChartGroupMethod(g, norefresh) {
-       if(!mainchart) return;
-
-       if(g == 'toggle') {
-               if(last_main_chart_avg == 'max') g = 'average';
-               else g = 'max';
-       }
-
-       mainchart.group_method = g;
-
-       $('.mainchart_avg_button').button(g);
-
-       if(!norefresh) {
-               mainchart.last_updated = 0;
-       }
-
-       last_main_chart_avg = g;
-}
-
-function setMainChartPlay(p) {
-       if(!mainchart) return;
-
-       if(p == 'toggle') {
-               if(refresh_mode != REFRESH_ALWAYS) p = 'play';
-               else p = 'pause';
-       }
-
-       if(p == 'play') {
-               //mainchart.chartOptions.explorer = null;
-               mainchart.after = 0;
-               mainchart.before = 0;
-               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, 0, ENABLE_CURVE);
-               $('#group' + mainchart.group).trigger('click');
-               mainchart.last_updated = 0;
-               mainchart.hiddenchart.last_updated = 0;
-               playGraphs();
-       }
-       else {
-               //mainchart.chartOptions.explorer = {
-               //      'axis': 'horizontal',
-               //      'maxZoomOut': 1,
-               //};
-               //mainchart.last_updated = 0;
-
-               //if(!renderChart(mainchart, pauseGraphs))
-               pauseGraphs();
-       }
-}
-
-function buttonGlobalPlayPause(p) {
-       if(mode == MODE_MAIN) {
-               setMainChartPlay(p);
-               return;
-       }
-
-       if(p == 'toggle') {
-               if(refresh_mode != REFRESH_ALWAYS) p = 'play';
-               else p = 'pause';
-       }
-
-       if(p == 'play') playGraphs();
-       else pauseGraphs();
-}
-
-
-// ------------------------------------------------------------------------
-// Chart resizing
-
-function screenWidth() {
-       return (($(window).width() * 0.95) - 50);
-}
-
-// calculate the proper width for the thumb charts
-function thumbWidth() {
-       var cwidth = screenWidth();
-       var items = Math.round(cwidth / TARGET_THUMB_GRAPH_WIDTH);
-       if(items < 1) items = 1;
-
-       if(items > 1 && (cwidth / items) < MINIMUM_THUMB_GRAPH_WIDTH) items--;
-
-       return Math.round(cwidth / items) - 1;
-}
-
-function groupChartSizes() {
-       var s = { width: screenWidth(), height: TARGET_GROUP_GRAPH_HEIGHT };
-
-       var count = 0;
-       if(groupCharts) $.each(groupCharts, function(i, c) {
-               if(c.enabled) count++;
-       });
-
-       if(count == 0) {
-               s.width = TARGET_GROUP_GRAPH_HEIGHT;
-               s.height = TARGET_GROUP_GRAPH_HEIGHT;
-       }
-       else {
-               if(s.width < MINIMUM_THUMB_GRAPH_WIDTH) s.width = screenWidth();
-               s.height = ($(window).height() - 130) / count - 10;
-       }
-
-       if(s.height < TARGET_GROUP_GRAPH_HEIGHT)
-               s.height = TARGET_GROUP_GRAPH_HEIGHT;
-
-       return s;
-}
-
-// resize all charts
-// if the thumb charts need resize in their width, reset them
-function resizeCharts() {
-       var width = screenWidth();
-
-       if(mainchart) {
-               mainchart.chartOptions.width = width;
-               mainchart.chartOptions.height = $(window).height() - 150 - MAINCHART_CONTROL_HEIGHT;
-               mainchart.last_updated = 0;
-
-               mainchart.hidden_wrapper.setOption('width', width);
-               mainchart.control_wrapper.setOption('ui.chartOptions.width', width);
-               mainchart.hiddenchart.chartOptions.width = width;
-               mainchart.hiddenchart.last_updated = 0;
-       }
-
-       width = thumbWidth();
-       $.each(allCharts, function(i, c) {
-               if(c.enabled) {
-                       cleanThisChart(c);
-                       c.chartOptions.width = width;
-                       calculateChartPointsToShow(c, c.chartOptions.isStacked?THUMBS_STACKED_POINTS_DIVISOR:THUMBS_POINTS_DIVISOR, THUMBS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
-                       showChartIsLoading(c.div, c.name, c.chartOptions.width, c.chartOptions.height);
-                       document.getElementById(c.id + '_thumb_actions_div').innerHTML = thumbChartActions(i, c);
-                       c.last_updated = 0;
-               }
-       });
-
-       if(groupCharts) $.each(groupCharts, function(i, c) {
-               var sizes = groupChartSizes();
-
-               if(c.enabled) {
-                       cleanThisChart(c);
-                       c.chartOptions.width = sizes.width;
-                       c.chartOptions.height = sizes.height;
-                       calculateChartPointsToShow(c, c.chartOptions.isStacked?GROUPS_STACKED_POINTS_DIVISOR:GROUPS_POINTS_DIVISOR, GROUPS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
-                       showChartIsLoading(c.div, c.name, c.chartOptions.width, c.chartOptions.height);
-                       document.getElementById(c.id + '_group_actions_div').innerHTML = groupChartActions(i, c);
-                       c.last_updated = 0;
-               }
-       });
-
-       updateUI();
-}
-
-window.onresize = function(event) {
-       resize_request = true;
-};
-
-
-// ------------------------------------------------------------------------
-// Core of the thread refreshing the charts
-
-var REFRESH_PAUSED = 0;
-var REFRESH_ALWAYS = 1;
-
-var refresh_mode = REFRESH_PAUSED;
-var last_refresh = 0;
-function playGraphs() {
-       mylog('playGraphs()');
-       if(refresh_mode == REFRESH_ALWAYS) return;
-
-       //mylog('PlayGraphs()');
-       refresh_mode = REFRESH_ALWAYS;
-       $('.mainchart_play_button').button('play');
-       $('.global_play_button').button('play');
-
-       // check if the thread died due to a javascript error
-       var now = new Date().getTime();
-       if((now - last_refresh) > 60000) {
-               // it died or never started
-               //mylog('It seems the refresh thread died. Restarting it.');
-               renderChartCallback();
-       }
-}
-
-function pauseGraphs() {
-       mylog('pauseGraphs()');
-       if(refresh_mode == REFRESH_PAUSED) return;
-
-       refresh_mode = REFRESH_PAUSED;
-       $('.mainchart_play_button').button('pause');
-       $('.global_play_button').button('pause');
-}
-
-var interval = null;
-function checkRefreshThread() {
-       if(interval == null) {
-               interval = setInterval(checkRefreshThread, 2000);
-               return;
-       }
-
-       var now = new Date().getTime();
-       if(now - last_refresh > 60000) {
-               mylog('Refresh thread died. Restarting it.');
-               renderChartCallback();
-       }
-}
-
-// refresh the proper chart
-// this is an internal function.
-// never call it directly, or new javascript threads will be spawn
-var timeout = null;
-function renderChartCallback() {
-       last_refresh = new Date().getTime();
-
-       if(!page_is_visible) {
-               timeout = setTimeout(triggerRefresh, CHARTS_CHECK_NO_FOCUS);
-               return;
-       }
-
-       if(resize_request) {
-               mylog('renderChartCallback() resize_request is set');
-               cleanupCharts();
-               resizeCharts();
-               resize_request = false;
-               // refresh_mode = REFRESH_ALWAYS;
-       }
-
-       if(last_user_scroll) {
-               var now = new Date().getTime();
-               if((now - last_user_scroll) >= CHARTS_SCROLL_IDLE) {
-                       last_user_scroll = 0;
-                       mylog('Scrolling: resuming refresh...');
-               }
-               else {
-                       mylog('Scrolling: pausing refresh for ' + (CHARTS_SCROLL_IDLE - (now - last_user_scroll)) + ' ms...');
-                       timeout = setTimeout(triggerRefresh, CHARTS_SCROLL_IDLE - (now - last_user_scroll));
-                       return;
-               }
-       }
-
-       if(refresh_mode == REFRESH_PAUSED) {
-               if(mode == MODE_MAIN && mainchart.last_updated == 0) {
-                       mainChartRefresh();
-                       return;
-               }
-
-               if(mode != MODE_MAIN) {
-                       timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
-                       return;
-               }
-       }
-
-            if(mode == MODE_THUMBS)            timeout = setTimeout(thumbChartsRefreshNext, CHARTS_REFRESH_LOOP);
-       else if(mode == MODE_GROUP_THUMBS)  timeout = setTimeout(groupChartsRefreshNext, CHARTS_REFRESH_LOOP);
-       else if(mode == MODE_MAIN)              timeout = setTimeout(mainChartRefresh, CHARTS_REFRESH_LOOP);
-       else                                    timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
-}
-
-// callback for refreshing the charts later
-// this is an internal function.
-// never call it directly, or new javascript threads will be spawn
-function triggerRefresh() {
-       //mylog('triggerRefresh()');
-
-       if(!page_is_visible || (refresh_mode == REFRESH_PAUSED && mode != MODE_MAIN)) {
-               last_refresh = new Date().getTime();
-               timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
-               return;
-       }
-
-            if(mode == MODE_THUMBS)            timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
-       else if(mode == MODE_GROUP_THUMBS)      timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
-       else if(mode == MODE_MAIN)              timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
-       else                                    timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
-}
-
-// refresh the main chart
-// make sure we don't loose the refreshing thread
-function mainChartRefresh() {
-       //mylog('mainChartRefresh()');
-
-       if(mode != MODE_MAIN || !mainchart) {
-               triggerRefresh();
-               return;
-       }
-
-       if(refresh_mode == REFRESH_PAUSED && mainchart.last_updated != 0) {
-               hiddenChartRefresh();
-               return;
-       }
-
-       if(!renderChart(mainchart, hiddenChartRefresh))
-               hiddenChartRefresh();
-}
-
-function hiddenChartRefresh() {
-       refreshHiddenChart(triggerRefresh);
-}
-
-function roundRobinRenderChart(charts, startat) {
-       var refreshed = false;
-
-       // find a chart to refresh
-       var all = charts.length;
-       var cur = startat + 1;
-       var count = 0;
-
-       for(count = 0; count < all ; count++, cur++) {
-               if(cur >= all) cur = 0;
-
-               if(charts[cur].enabled) {
-                       refreshed = renderChart(charts[cur], renderChartCallback);
-                       if(refreshed) {
-                               mylog('Refreshed: ' + charts[cur].name);
-                               break;
-                       }
-               }
-       }
-
-       if(!refreshed) triggerRefresh();
-       return cur;
-}
-
-// refresh the thumb charts
-// make sure we don't loose the refreshing thread
-var last_thumb_updated = 0;
-function thumbChartsRefreshNext() {
-       //mylog('thumbChartsRefreshNext()');
-
-       if(allCharts.length == 0 || mode != MODE_THUMBS) {
-               triggerRefresh();
-               return;
-       }
-
-       last_thumb_updated = roundRobinRenderChart(allCharts, last_thumb_updated);
-}
-
-// refresh the group charts
-// make sure we don't loose the refreshing thread
-var last_group_updated = 0;
-function groupChartsRefreshNext() {
-       //mylog('groupChartsRefreshNext()');
-
-       if(!groupCharts || groupCharts.length == 0 || mode != MODE_GROUP_THUMBS) {
-               //mylog('cannot refresh charts');
-               triggerRefresh();
-               return;
-       }
-
-       last_group_updated = roundRobinRenderChart(groupCharts, last_group_updated);
-}
-
-
-// ------------------------------------------------------------------------
-// switch the screen between views
-// these should be called only from initXXXX()
-
-function disableChart(i) {
-       mylog('disableChart(' + i + ')');
-
-       var chart = null;
-
-       var count = 0;
-       if(mode == MODE_GROUP_THUMBS && groupCharts) {
-               $.each(groupCharts, function(i, c) {
-                       if(c.enabled) count++;
-               });
-
-               if(i < groupCharts.length) chart = groupCharts[i];
-       }
-       else if(mode == MODE_THUMBS) {
-               $.each(allCharts, function(i, c) {
-                       if(c.enabled) count++;
-               });
-
-               if(i < allCharts.length) chart = allCharts[i];
-       }
-
-       if(!chart) return;
-
-       if(count <= 1) {
-               alert('Cannot close the last chart shown.');
-               return;
-       }
-
-       if(chart) {
-               mylog("request to disable chart " + chart.name);
-               chart.disablethisplease = true;
-               resize_request = true;
-       }
-       else
-               mylog("no chart to disable");
-}
-
-function cleanThisChart(chart, emptydivs) {
-       //mylog('cleanThisChart(' + chart.name + ', ' + emptydivs +')');
-
-       if(chart.dashboard) {
-               chart.dashboard.clear();
-               chart.dashboard = null;
-
-               if(chart.control_wrapper) {
-                       chart.control_wrapper.clear();
-                       chart.control_wrapper = null;
-               }
-
-               if(chart.hidden_wrapper) {
-                       chart.hidden_wrapper.clear();
-                       chart.hidden_wrapper = null;
-               }
-
-               chart.control_data = null;
-       }
-
-       if(chart.chart) chart.chart.clearChart();
-       chart.chart = null;
-
-       if(emptydivs) {
-               var div = document.getElementById(chart.div);
-               if(div) {
-                       div.style.display = 'none';
-                       div.innerHTML = "";
-               }
-
-               div = document.getElementById(chart.div + "_parent");
-               if(div) {
-                       div.style.display = 'none';
-                       div.innerHTML = "";
-               }
-       }
-
-       //mylog("chart " + chart.name + " cleaned with option " + emptydivs);
-}
-
-// cleanup the previously shown charts
-function cleanupCharts() {
-       // mylog('cleanupCharts()');
-
-       if(mode != MODE_MAIN && mainchart) {
-               if(mainchart.chart) cleanThisChart(mainchart);
-               mainchart = null;
-       }
-
-       if(mode != MODE_GROUP_THUMBS && groupCharts) {
-               clearGroupGraphs();
-       }
-
-       // cleanup the disabled charts
-       $.each(allCharts, function(i, c) {
-               if(c.disablethisplease && c.enabled) {
-                       cleanThisChart(c, 'emptydivs');
-                       c.disablethisplease = false;
-                       c.enabled = false;
-                       resize_request = true;
-                       mylog("removed thumb chart " + c.name + " removed");
-               }
-       });
-
-       if(groupCharts) $.each(groupCharts, function(i, c) {
-               if(c.disablethisplease && c.enabled) {
-                       cleanThisChart(c, 'emptydivs');
-                       c.disablethisplease = false;
-                       c.enabled = false;
-                       resize_request = true;
-                       mylog("removed group chart " + c.name + " removed");
-               }
-       });
-
-       // we never cleanup the main chart
-}
-
-function updateUI() {
-       $('[data-toggle="tooltip"]').tooltip({'container': 'body', 'html': true});
-
-       $('[data-spy="scroll"]').each(function () {
-               var $spy = $(this).scrollspy('refresh')
-       })
-}
-
-var thumbsScrollPosition = null;
-function switchToMainGraph() {
-       //mylog('switchToMainGraph()');
-
-       if(!mainchart) return;
-
-       if(!groupCharts) thumbsScrollPosition = window.pageYOffset;
-
-       document.getElementById('maingraph_container').style.display = 'block';
-       document.getElementById('thumbgraphs_container').style.display = 'none';
-       document.getElementById('groupgraphs_container').style.display = 'none';
-       document.getElementById('splash_container').style.display = 'none';
-
-       document.getElementById("main_menu_div").innerHTML = "<ul class=\"nav navbar-nav\"><li><a href=\"javascript:switchToThumbGraphs();\"><span class=\"glyphicon glyphicon-circle-arrow-left\"></span> Back to Dashboard</a></li><li class=\"active\"><a href=\"#\">" + mainchart.name + "</a></li>" + familiesmainmenu + chartsmainmenu + "</ul>" ;
-
-       window.scrollTo(0, 0);
-
-       mode = MODE_MAIN;
-       playGraphs();
-       updateUI();
-}
-
-function switchToThumbGraphs() {
-       //mylog('switchToThumbGraphs()');
-
-       document.getElementById('maingraph_container').style.display = 'none';
-       document.getElementById('thumbgraphs_container').style.display = 'block';
-       document.getElementById('groupgraphs_container').style.display = 'none';
-       document.getElementById('splash_container').style.display = 'none';
-
-       document.getElementById("main_menu_div").innerHTML = mainmenu;
-
-       if(thumbsScrollPosition) window.scrollTo(0, thumbsScrollPosition);
-
-       // switch mode
-       mode = MODE_THUMBS;
-       playGraphs();
-       updateUI();
-}
-
-function switchToGroupGraphs() {
-       //mylog('switchToGroupGraphs()');
-
-       if(!groupCharts) return;
-
-       if(!mainchart) thumbsScrollPosition = window.pageYOffset;
-
-       document.getElementById('maingraph_container').style.display = 'none';
-       document.getElementById('thumbgraphs_container').style.display = 'none';
-       document.getElementById('groupgraphs_container').style.display = 'block';
-       document.getElementById('splash_container').style.display = 'none';
-
-       document.getElementById("main_menu_div").innerHTML = "<ul class=\"nav navbar-nav\"><li><a href=\"javascript:switchToThumbGraphs();\"><span class=\"glyphicon glyphicon-circle-arrow-left\"></span> Back to Dashboard</a></li><li class=\"active\"><a href=\"#\">" + groupCharts[0].family + "</a></li>" + familiesmainmenu + chartsmainmenu + "</ul>";
-
-       window.scrollTo(0, 0);
-
-       mode = MODE_GROUP_THUMBS;
-       playGraphs();
-       updateUI();
-}
-
-
-// ------------------------------------------------------------------------
-// Group Charts
-
-var groupCharts = null;
-function initGroupGraphs(group) {
-       var count = 0;
-
-       if(groupCharts) clearGroupGraphs();
-       groupCharts = new Array();
-
-       var groupbody = "";
-       $.each(allCharts, function(i, c) {
-               if(c.family == group) {
-                       groupCharts[count] = [];
-                       groupCharts[count] = $.extend(true, {}, c);
-                       groupCharts[count].div += "_group";
-                       groupCharts[count].enabled = true;
-                       groupCharts[count].chart = null;
-                       groupCharts[count].last_updated = 0;
-                       count++;
-               }
-       });
-       groupCharts.sort(chartssort);
-
-       var sizes = groupChartSizes();
-
-       var groupbody = "";
-       $.each(groupCharts, function(i, c) {
-               c.chartOptions.width = sizes.width;
-               c.chartOptions.height = sizes.height;
-               c.chartOptions.chartArea.width = '85%';
-               c.chartOptions.chartArea.height = '90%';
-               c.chartOptions.hAxis.textPosition = 'in';
-               c.chartOptions.hAxis.viewWindowMode = 'maximized';
-               c.chartOptions.hAxis.textStyle = { "fontSize": 9 };
-               c.chartOptions.vAxis.textStyle = { "fontSize": 9 };
-               c.chartOptions.fontSize = 11;
-               c.chartOptions.titlePosition = 'in';
-               c.chartOptions.tooltip = { "textStyle": { "fontSize": 9 } };
-               c.chartOptions.legend = { "textStyle": { "fontSize": 9 } };
-
-               calculateChartPointsToShow(c, c.chartOptions.isStacked?GROUPS_STACKED_POINTS_DIVISOR:GROUPS_POINTS_DIVISOR, GROUPS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
-
-               groupbody += "<div class=\"thumbgraph\" id=\"" + c.div + "_parent\"><table><tr><td width='" + sizes.width + "'><div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div></td><td id=\"" + c.id + "_group_actions_div\" align=\"center\">" + groupChartActions(i, c) + "</td></tr><tr><td width='15'></td></tr></table></div>";
-               //groupbody += "<div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div>";
-       });
-       groupbody += "";
-
-       document.getElementById("groupgraphs").innerHTML = groupbody;
-       switchToGroupGraphs();
-}
-
-function clearGroupGraphs() {
-       if(groupCharts && groupCharts.length) {
-               $.each(groupCharts, function(i, c) {
-                       cleanThisChart(c, 'emptydivs');
-               });
-
-               groupCharts = null;
-       }
-
-       document.getElementById("groupgraphs").innerHTML = "";
-}
-
-
-// ------------------------------------------------------------------------
-// Global entry point
-// initialize the thumb charts
-
-var last_user_scroll = 0;
-
-// load the charts from the server
-// generate html for the thumbgraphs to support them
-function initCharts() {
-       setPresentationNormal(1);
-
-       var width = thumbWidth();
-       var height = TARGET_THUMB_GRAPH_HEIGHT;
-
-       window.onscroll = function (e) {
-               last_user_scroll = new Date().getTime();
-               mylog('Scrolling: detected');
-       }
-
-       loadCharts(null, function(all) {
-               allCharts = all.charts;
-
-               if(allCharts == null || allCharts.length == 0) {
-                       alert("Cannot load data from server.");
-                       return;
-               }
-
-               var thumbsContainer = document.getElementById("thumbgraphs");
-               if(!thumbsContainer) {
-                       alert("Cannot find the thumbsContainer");
-                       return;
-               }
-
-               allCharts.sort(chartssort);
-
-               document.getElementById('hostname_id').innerHTML = all.hostname;
-               document.title = all.hostname;
-
-               // create an array for grouping all same-type graphs together
-               var dimensions = 0;
-               var categories = new Array();
-               var families = new Array();
-               var chartslist = new Array();
-               $.each(allCharts, function(i, c) {
-                       var j;
-
-                       chartslist.push({name: c.name, type: c.type, id: i});
-
-                       dimensions += c.dimensions.length;
-                       c.chartOptions.width = width;
-                       c.chartOptions.height = height;
-
-                       // calculate how many point to show for each chart
-                       //c.points_to_show = Math.round(c.entries / c.group) - 1;
-                       // show max 10 mins of data
-                       //if(c.points_to_show * c.group > THUMBS_MAX_TIME_TO_SHOW) c.points_to_show = THUMBS_MAX_TIME_TO_SHOW / c.group;
-                       calculateChartPointsToShow(c, c.chartOptions.isStacked?THUMBS_STACKED_POINTS_DIVISOR:THUMBS_POINTS_DIVISOR, THUMBS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
-
-                       if(c.enabled) {
-                               var h = "<div class=\"thumbgraph\" id=\"" + c.div + "_parent\"><table><tr><td><div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div></td></tr><tr><td id=\"" + c.id + "_thumb_actions_div\" align=\"center\">"
-                               + thumbChartActions(i, c)
-                               +       "</td></tr><tr><td height='15'></td></tr></table></div>";
-
-                               // find the categories object for this type
-                               for(j = 0; j < categories.length ;j++) {
-                                       if(categories[j].name == c.type) {
-                                               categories[j].html += h;
-                                               categories[j].count++;
-                                               break;
-                                       }
-                               }
-
-                               if(j == categories.length)
-                                       categories.push({name: c.type, title: c.category, description: '', priority: c.categoryPriority, count: 1, glyphicon: c.glyphicon, html: h});
-                       }
-
-                       // find the families object for this type
-                       for(j = 0; j < families.length ;j++) {
-                               if(families[j].name == c.family) {
-                                       families[j].count++;
-                                       break;
-                               }
-                       }
-
-                       if(j == families.length)
-                               families.push({name: c.family, count: 1});
-               });
-
-               document.getElementById('server_summary_id').innerHTML = "<small>NetData server at <b>" + all.hostname + "</b> is maintaining <b>" + allCharts.length + "</b> charts, having <b>" + dimensions + "</b> dimensions (by default with <b>" + all.history + "</b> entries each), which are updated every <b>" + all.update_every + "s</b>, using a total of <b>" + (Math.round(all.memory * 10 / 1024 / 1024) / 10) + " MB</b> for the round robin database.</small>";
-
-               $.each(categories, function(i, a) {
-                       a.html = "<tr><td id=\"" + a.name + "\"><ol class=\"breadcrumb graphs\"><li class=\"active\"><span class=\"glyphicon " + a.glyphicon + "\"></span> &nbsp; <a id=\"" + a.name + "\" href=\"#" + a.name + "\"><b>" + a.title + "</b> " + a.description + " </a></li></ol></td></tr><tr><td><div class=\"thumbgraphs\">" + a.html + "</td></tr>";
-               });
-
-               function categoriessort(a, b) {
-                       if(a.priority < b.priority) return -1;
-                       return 1;
-               }
-               categories.sort(categoriessort);
-
-               function familiessort(a, b) {
-                       if(a.name < b.name) return -1;
-                       return 1;
-               }
-               families.sort(familiessort);
-
-               function chartslistsort(a, b) {
-                       if(a.name < b.name) return -1;
-                       return 1;
-               }
-               chartslist.sort(chartslistsort);
-
-               // combine all the htmls into one
-               var allcategories = "<table width=\"100%\">";
-               mainmenu = '<ul class="nav navbar-nav">';
-
-               categoriesmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-fire\"></span> Dashboard Sections <b class="caret"></b></a><ul class="dropdown-menu">';
-               $.each(categories, function(i, a) {
-                       allcategories += a.html;
-                       categoriesmainmenu += "<li><a href=\"#" + a.name + "\">" + a.title + "</a></li>";
-               });
-               categoriesmainmenu += "</ul></li>";
-               allcategories += "</table>";
-
-               familiesmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-th-large\"></span> Chart Families <b class="caret"></b></a><ul class="dropdown-menu">';
-               $.each(families, function(i, a) {
-                       familiesmainmenu += "<li><a href=\"javascript:initGroupGraphs('" + a.name + "');\">" + a.name + " <span class=\"badge pull-right\">" + a.count + "</span></a></li>";
-               });
-               familiesmainmenu += "</ul></li>";
-
-               chartsmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-resize-full\"></span> All Charts <b class="caret"></b></a><ul class="dropdown-menu">';
-               $.each(chartslist, function(i, a) {
-                       chartsmainmenu += "<li><a href=\"javascript:initMainChartIndexOfMyCharts('" + a.id + "');\">" + a.name + "</a></li>";
-               });
-               chartsmainmenu += "</ul></li>";
-
-               mainmenu += categoriesmainmenu;
-               mainmenu += familiesmainmenu;
-               mainmenu += chartsmainmenu;
-               mainmenu += '<li role="presentation" class="disabled" style="display: none;"><a href="#" id="logline"></a></li></ul>';
-
-               thumbsContainer.innerHTML = allcategories;
-               switchToThumbGraphs();
-               checkRefreshThread();
-       });
-}
-
-$(window).blur(function() {
-       page_is_visible = 0;
-       mylog('Lost Focus!');
-});
-
-$(window).focus(function() {
-       page_is_visible = 1;
-       mylog('Focus restored!');
-});
-
-// Set a callback to run when the Google Visualization API is loaded.
-google.setOnLoadCallback(initCharts);
diff --git a/web/netdata.js b/web/netdata.js
deleted file mode 100755 (executable)
index f1af0a6..0000000
+++ /dev/null
@@ -1,502 +0,0 @@
-// fix old IE bug with console
-if(!window.console){ window.console = {log: function(){} }; }
-
-// Load the Visualization API and the piechart package.
-google.load('visualization', '1.1', {'packages':['corechart']});
-//google.load('visualization', '1.1', {'packages':['controls']});
-
-function canChartBeRefreshed(chart) {
-       // is it enabled?
-       if(!chart.enabled) return false;
-
-       // is there something selected on the chart?
-       if(chart.chart && chart.chart.getSelection()[0]) return false;
-
-       // is it too soon for a refresh?
-       var now = new Date().getTime();
-       if((now - chart.last_updated) < (chart.group * chart.update_every * 1000)) return false;
-
-       // is the chart in the visible area?
-       //console.log(chart.div);
-       if($('#' + chart.div).visible(true) == false) return false;
-
-       // ok, do it
-       return true;
-}
-
-function generateChartURL(chart) {
-       // build the data URL
-       var url = chart.url;
-       url += chart.points_to_show?chart.points_to_show.toString():"all";
-       url += "/";
-       url += chart.group?chart.group.toString():"1";
-       url += "/";
-       url += chart.group_method?chart.group_method:"average";
-       url += "/";
-       url += chart.after?chart.after.toString():"0";
-       url += "/";
-       url += chart.before?chart.before.toString():"0";
-       url += "/";
-       url += chart.non_zero?"nonzero":"all";
-       url += "/";
-
-       return url;
-}
-
-function renderChart(chart, doNext) {
-       if(canChartBeRefreshed(chart) == false) return false;
-
-       $.ajax({
-               url: generateChartURL(chart),
-               dataType:"json",
-               cache: false
-       })
-       .done(function(jsondata) {
-               if(!jsondata || jsondata.length == 0) return;
-               chart.jsondata = jsondata;
-
-               // Create our data table out of JSON data loaded from server.
-               chart.datatable = new google.visualization.DataTable(chart.jsondata);
-               //console.log(chart.datatable);
-
-               // cleanup once every 50 updates
-               // we don't cleanup on every single, to avoid firefox flashing effect
-               if(chart.chart && chart.refreshCount > 50) {
-                       chart.chart.clearChart();
-                       chart.chart = null;
-                       chart.refreshCount = 0;
-               }
-
-               // Instantiate and draw our chart, passing in some options.
-               if(!chart.chart) {
-                       // console.log('Creating new chart for ' + chart.url);
-                       if(chart.chartType == "LineChart")
-                               chart.chart = new google.visualization.LineChart(document.getElementById(chart.div));
-                       else
-                               chart.chart = new google.visualization.AreaChart(document.getElementById(chart.div));
-               }
-
-               if(chart.chart) {
-                       chart.chart.draw(chart.datatable, chart.chartOptions);
-                       chart.refreshCount++;
-                       chart.last_updated = new Date().getTime();
-               }
-               else console.log('Cannot create chart for ' + chart.url);
-       })
-       .fail(function() {
-               // to avoid an infinite loop, let's assume it was refreshed
-               if(chart.chart) chart.chart.clearChart();
-               chart.chart = null;
-               chart.refreshCount = 0;
-               showChartIsLoading(chart.div, chart.name, chart.chartOptions.width, chart.chartOptions.height, "failed to refresh");
-               chart.last_updated = new Date().getTime();
-       })
-       .always(function() {
-               if(typeof doNext == "function") doNext();
-       });
-
-       return true;
-}
-
-function chartIsLoadingHTML(name, width, height, message)
-{
-       return "<table><tr><td align=\"center\" width=\"" + width + "\" height=\"" + height + "\" style=\"vertical-align:middle\"><h4><span class=\"glyphicon glyphicon-refresh\"></span><br/><br/>" + name + "<br/><br/><span class=\"label label-default\">" + (message?message:"loading chart...") + "</span></h4></td></tr></table>";
-}
-
-function showChartIsLoading(id, name, width, height, message) {
-       document.getElementById(id).innerHTML = chartIsLoadingHTML(name, width, height, message);
-}
-
-// calculateChartPointsToShow
-// calculate the chart group and point to show properties.
-// This uses the chartOptions.width and the supplied divisor
-// to calculate the propers values so that the chart will
-// be visually correct (not too much or too less points shown).
-//
-// c = the chart
-// divisor = when calculating screen points, divide width with this
-//           if all screen points are used the chart will be overcrowded
-//           the default is 2
-// maxtime = the maxtime to show
-//           the default is to render all the server data
-// group   = the required grouping on points
-//           if undefined or negative, any calculated value will be used
-//           if zero, one of 1,2,5,10,15,20,30,45,60 will be used
-
-function calculateChartPointsToShow(c, divisor, maxtime, group, enable_curve) {
-       // console.log('calculateChartPointsToShow( c = ' + c.id + ',  divisor = ' + divisor + ', maxtime = ' + maxtime + ', group = ' + group + ' )');
-
-       if(!divisor) divisor = 2;
-
-       var before = c.before?c.before:new Date().getTime() / 1000;
-       var after = c.after?c.after:c.first_entry_t;
-
-       var dt = before - after;
-       if(dt > c.entries * c.update_every) dt = c.entries * c.update_every;
-
-       // console.log('chart ' + c.id + ' internal duration is ' + dt + ' secs, requested maxtime is ' + maxtime + ' secs');
-
-       if(!maxtime) maxtime = c.entries * c.update_every;
-       dt = maxtime;
-
-       var data_points = Math.round(dt / c.update_every);
-       if(!data_points) data_points = 100;
-
-       var screen_points = Math.round(c.chartOptions.width / divisor);
-       if(!screen_points) screen_points = 100;
-
-       // console.log('screen_points = ' + screen_points + ', data_points = ' + data_points + ', divisor = ' + divisor);
-
-       if(group == undefined || group <= 0) {
-               if(screen_points > data_points) {
-                       c.group = 1;
-                       c.points_to_show = data_points;
-                       // console.log("rendering at full detail (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
-               }
-               else {
-                       c.group = Math.round(data_points / screen_points);
-
-                            if(c.group > 60) c.group = 90;
-                       else if(c.group > 45) c.group = 60;
-                       else if(c.group > 30) c.group = 45;
-                       else if(c.group > 20) c.group = 30;
-                       else if(c.group > 15) c.group = 20;
-                       else if(c.group > 10) c.group = 15;
-                       else if(c.group > 5) c.group = 10;
-                       else if(c.group > 4) c.group = 5;
-                       else if(c.group > 3) c.group = 4;
-                       else if(c.group > 2) c.group = 3;
-                       else if(c.group > 1) c.group = 2;
-                       else c.group = 1;
-
-                       c.points_to_show = Math.round(data_points / c.group);
-                       // console.log("rendering adaptive (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
-               }
-       }
-       else {
-               c.group = group;
-               c.points_to_show = Math.round(data_points / group);
-               // console.log("rendering with supplied group (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
-       }
-
-       // console.log("final configuration (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
-
-       // make sure the line width is not congesting the chart
-       if(c.chartType == 'LineChart') {
-               if(c.points_to_show > c.chartOptions.width / 3) {
-                       c.chartOptions.lineWidth = 1;
-               }
-
-               else {
-                       c.chartOptions.lineWidth = 2;
-               }
-       }
-       else if(c.chartType == 'AreaChart') {
-               if(c.points_to_show > c.chartOptions.width / 2)
-                       c.chartOptions.lineWidth = 0;
-               else
-                       c.chartOptions.lineWidth = 1;
-       }
-
-       // do not render curves when we don't have at
-       // least 2 twice the space per point
-       if(!enable_curve || c.points_to_show > (c.chartOptions.width * c.chartOptions.lineWidth / 2) )
-               c.chartOptions.curveType = 'none';
-       else
-               c.chartOptions.curveType = c.default_curveType;
-
-       var hpoints = Math.round(maxtime / 30);
-       if(hpoints > 10) hpoints = 10;
-       c.chartOptions.hAxis.gridlines.count = hpoints;
-}
-
-
-// loadCharts()
-// fetches all the charts from the server
-// returns an array of objects, containing all the server metadata
-// (not the values of the graphs - just the info about the graphs)
-
-function loadCharts(base_url, doNext) {
-       $.ajax({
-               url: ((base_url)?base_url:'') + '/all.json',
-               dataType: 'json',
-               cache: false
-       })
-       .done(function(json) {
-               $.each(json.charts, function(i, value) {
-                       json.charts[i].div = json.charts[i].name.replace(/\./g,"_");
-                       json.charts[i].div = json.charts[i].div.replace(/\-/g,"_");
-                       json.charts[i].div = json.charts[i].div + "_div";
-
-                       // make sure we have the proper values
-                       if(!json.charts[i].update_every) chart.update_every = 1;
-                       if(base_url) json.charts[i].url = base_url + json.charts[i].url;
-
-                       json.charts[i].last_updated = 0;
-                       json.charts[i].thumbnail = false;
-                       json.charts[i].refreshCount = 0;
-                       json.charts[i].group = 1;
-                       json.charts[i].points_to_show = 0;      // all
-                       json.charts[i].group_method = "max";
-
-                       json.charts[i].chart = null;
-                       json.charts[i].jsondata = null;
-                       json.charts[i].datatable = null;
-                       json.charts[i].before = 0;
-                       json.charts[i].after = 0;
-
-                       // if it is detail, disable it by default
-                       if(json.charts[i].isdetail) json.charts[i].enabled = false;
-
-                       // set default chart options
-                       json.charts[i].chartOptions = {
-                               width: 400,
-                               height: 200,
-                               lineWidth: 1,
-                               title: json.charts[i].title,
-                               fontSize: 11,
-                               hAxis: {
-                               //      title: "Time of Day",
-                               //      format:'HH:mm:ss',
-                                       viewWindowMode: 'maximized',
-                                       slantedText: false,
-                                       format:'HH:mm:ss',
-                                       textStyle: {
-                                               fontSize: 9
-                                       },
-                                       gridlines: {
-                                               color: '#EEE'
-                                       }
-                               },
-                               vAxis: {
-                                       title: json.charts[i].units,
-                                       viewWindowMode: 'pretty',
-                                       minValue: -0.1,
-                                       maxValue: 0.1,
-                                       direction: 1,
-                                       textStyle: {
-                                               fontSize: 9
-                                       },
-                                       gridlines: {
-                                               color: '#EEE'
-                                       }
-                               },
-                               chartArea: {
-                                       width: '65%',
-                                       height: '80%'
-                               },
-                               focusTarget: 'category',
-                               annotation: {
-                                       '1': {
-                                               style: 'line'
-                                       }
-                               },
-                               pointsVisible: 0,
-                               titlePosition: 'out',
-                               titleTextStyle: {
-                                       fontSize: 11
-                               },
-                               tooltip: {
-                                       isHtml: true,
-                                       ignoreBounds: true,
-                                       textStyle: {
-                                               fontSize: 9
-                                       }
-                               }
-                       };
-
-                       json.charts[i].default_curveType = 'none';
-
-                       // set the chart type
-                       switch(json.charts[i].chart_type) {
-                               case "area":
-                                       json.charts[i].chartType = "AreaChart";
-                                       json.charts[i].chartOptions.isStacked = false;
-                                       json.charts[i].chartOptions.areaOpacity = 0.3;
-
-                                       json.charts[i].chartOptions.vAxis.viewWindowMode = 'maximized';
-                                       json.charts[i].non_zero = 0;
-
-                                       json.charts[i].group = 3;
-                                       break;
-
-                               case "stacked":
-                                       json.charts[i].chartType = "AreaChart";
-                                       json.charts[i].chartOptions.isStacked = true;
-                                       json.charts[i].chartOptions.areaOpacity = 0.85;
-                                       json.charts[i].chartOptions.lineWidth = 1;
-                                       json.charts[i].group_method = "average";
-                                       json.charts[i].non_zero = 1;
-
-                                       json.charts[i].chartOptions.vAxis.viewWindowMode = 'maximized';
-                                       json.charts[i].chartOptions.vAxis.minValue = null;
-                                       json.charts[i].chartOptions.vAxis.maxValue = null;
-
-                                       json.charts[i].group = 10;
-                                       break;
-
-                               default:
-                               case "line":
-                                       json.charts[i].chartType = "LineChart";
-                                       json.charts[i].chartOptions.lineWidth = 2;
-                                       json.charts[i].non_zero = 0;
-
-                                       json.charts[i].default_curveType = 'function';
-
-                                       json.charts[i].group = 3;
-                                       break;
-                       }
-
-                       // the category name, and other options, per type
-                       switch(json.charts[i].type) {
-                               case "system":
-                                       json.charts[i].category = "System";
-                                       json.charts[i].categoryPriority = 10;
-                                       json.charts[i].glyphicon = "glyphicon-dashboard";
-
-                                       if(json.charts[i].id == "system.cpu" || json.charts[i].id == "system.ram") {
-                                               json.charts[i].chartOptions.vAxis.minValue = 0;
-                                               json.charts[i].chartOptions.vAxis.maxValue = 100;
-                                       }
-                                       else {
-                                               json.charts[i].chartOptions.vAxis.minValue = -0.1;
-                                               json.charts[i].chartOptions.vAxis.maxValue =  0.1;
-                                       }
-                                       break;
-
-                               case "net":
-                                       json.charts[i].category = "Network";
-                                       json.charts[i].categoryPriority = 20;
-                                       json.charts[i].glyphicon = "glyphicon-transfer";
-
-                                       // disable IFB and net.lo devices by default
-                                       if((json.charts[i].id.substring(json.charts[i].id.length - 4, json.charts[i].id.length) == "-ifb")
-                                               || json.charts[i].id == "net.lo")
-                                               json.charts[i].enabled = false;
-                                       break;
-
-                               case "tc":
-                                       json.charts[i].category = "Quality of Service";
-                                       json.charts[i].categoryPriority = 30;
-                                       json.charts[i].glyphicon = "glyphicon-random";
-                                       break;
-
-                               case "ipvs":
-                                       json.charts[i].category = "IP Virtual Server";
-                                       json.charts[i].categoryPriority = 40;
-                                       json.charts[i].glyphicon = "glyphicon-sort";
-                                       break;
-
-                               case "netfilter":
-                                       json.charts[i].category = "Netfilter";
-                                       json.charts[i].categoryPriority = 50;
-                                       json.charts[i].glyphicon = "glyphicon-cloud";
-                                       break;
-
-                               case "ipv4":
-                                       json.charts[i].category = "IPv4";
-                                       json.charts[i].categoryPriority = 60;
-                                       json.charts[i].glyphicon = "glyphicon-globe";
-                                       break;
-
-                               case "mem":
-                                       json.charts[i].category = "Memory";
-                                       json.charts[i].categoryPriority = 70;
-                                       json.charts[i].glyphicon = "glyphicon-dashboard";
-                                       break;
-
-                               case "cpu":
-                                       json.charts[i].category = "CPU";
-                                       json.charts[i].categoryPriority = 80;
-                                       json.charts[i].glyphicon = "glyphicon-dashboard";
-
-                                       if(json.charts[i].id.substring(0, 7) == "cpu.cpu") {
-                                               json.charts[i].chartOptions.vAxis.minValue = 0;
-                                               json.charts[i].chartOptions.vAxis.maxValue = 100;
-                                       }
-                                       break;
-
-                               case "disk":
-                                       json.charts[i].category = "Disks";
-                                       json.charts[i].categoryPriority = 90;
-                                       json.charts[i].glyphicon = "glyphicon-hdd";
-                                       break;
-
-                               case "nfsd":
-                                       json.charts[i].category = "NFS Server";
-                                       json.charts[i].categoryPriority = 100;
-                                       json.charts[i].glyphicon = "glyphicon-hdd";
-                                       break;
-
-                               case "nut":
-                                       json.charts[i].category = "UPS";
-                                       json.charts[i].categoryPriority = 110;
-                                       json.charts[i].glyphicon = "glyphicon-dashboard";
-                                       break;
-
-                               case "netdata":
-                                       json.charts[i].category = "NetData";
-                                       json.charts[i].categoryPriority = 3000;
-                                       json.charts[i].glyphicon = "glyphicon-thumbs-up";
-                                       break;
-
-                               case "apps":
-                                       json.charts[i].category = "Apps";
-                                       json.charts[i].categoryPriority = 4000;
-                                       json.charts[i].glyphicon = "glyphicon-tasks";
-                                       break;
-
-                               case "squid":
-                                       json.charts[i].category = "Squid";
-                                       json.charts[i].categoryPriority = 5000;
-                                       json.charts[i].glyphicon = "glyphicon-link";
-                                       break;
-
-                               case "example":
-                                       json.charts[i].category = "Examples";
-                                       json.charts[i].categoryPriority = 9000;
-                                       json.charts[i].glyphicon = "glyphicon-search";
-                                       break;
-
-                               default:
-                                       json.charts[i].category = json.charts[i].type;
-                                       json.charts[i].categoryPriority = 1000;
-                                       json.charts[i].glyphicon = "glyphicon-search";
-                                       break;
-                       }
-               });
-
-               if(typeof doNext == "function") doNext(json);
-       })
-       .fail(function() {
-               if(typeof doNext == "function") doNext();
-       });
-};
-
-// jquery visible plugin
-(function($){
-
-       /**
-        * Copyright 2012, Digital Fusion
-        * Licensed under the MIT license.
-        * http://teamdf.com/jquery-plugins/license/
-        *
-        * @author Sam Sehnert
-        * @desc A small plugin that checks whether elements are within
-        *               the user visible viewport of a web browser.
-        *               only accounts for vertical position, not horizontal.
-        */
-       $.fn.visible = function(partial){
-
-           var $t                              = $(this),
-               $w                              = $(window),
-               viewTop                 = $w.scrollTop(),
-               viewBottom              = viewTop + $w.height(),
-               _top                    = $t.offset().top,
-               _bottom                 = _top + $t.height(),
-               compareTop              = partial === true ? _bottom : _top,
-               compareBottom   = partial === true ? _top : _bottom;
-
-               return ((compareBottom <= viewBottom) && (compareTop >= viewTop));
-    };
-})(jQuery);
diff --git a/web/old/datasource.html b/web/old/datasource.html
new file mode 100644 (file)
index 0000000..f61db4f
--- /dev/null
@@ -0,0 +1,56 @@
+<html>
+       <style>
+               * {font-family:Arial}
+               div {float: left; margin: 0 0 0 0; }
+       </style>
+       <head>
+       <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+       <title>NetData Datasource Example</title>
+       <script type="text/javascript" src="http://www.google.com/jsapi"></script>
+       <script type="text/javascript">
+
+       google.load('visualization', '1', {packages: ['charteditor']});
+       // google.load('visualization', '1.0');  // Note: No need to specify chart libraries.
+
+       google.setOnLoadCallback(drawVisualization);
+
+       var wrapper;
+       function drawVisualization() {
+               wrapper = new google.visualization.ChartWrapper({
+                       containerId: 'graph_div',
+                       chartType: 'AreaChart',
+                       dataSourceUrl: 'http:/datasource/system.cpu/60/1/max', // it needs a protocol to work, even in relative URLs
+                       refreshInterval: 1,
+                       options: {
+                               isStacked: true,
+                               areaOpacity: 0.85,
+                               lineWidth: 1,
+                               title: 'CPU utilization',
+                               width: window.innerWidth - 50,
+                               height: window.innerHeight - 50,
+                               hAxis: {title: "Time of Day", viewWindowMode: 'maximized', format:'HH:mm:ss'},
+                               vAxis: {title: "percent", viewWindowMode: 'pretty', minValue: 0, maxValue: 100},
+                               focusTarget: 'category',
+                               annotation: {'1': {style: 'line'}},
+                       },
+               });
+               wrapper.draw();
+       }
+
+       function openEditor() {
+               var editor = new google.visualization.ChartEditor();
+               google.visualization.events.addListener(editor, 'ok', function() {
+                       wrapper = editor.getChartWrapper();
+                       wrapper.draw(document.getElementById('graph_div'));
+               });
+               editor.openDialog(wrapper);
+       }
+
+       </script>
+       </head>
+       <body>
+               <input type='button' onclick='openEditor()' value='Open Editor'>
+               <br/>
+               <div><div id="graph_div"/></div>
+       </body>
+</html>
diff --git a/web/old/index.html b/web/old/index.html
new file mode 100644 (file)
index 0000000..ff26bfa
--- /dev/null
@@ -0,0 +1,207 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="apple-mobile-web-app-capable" content="yes">
+    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
+    <meta name="description" content="">
+    <meta name="author" content="costa@tsaousis.gr">
+
+       <title>NetData</title>
+
+       <!-- Bootstrap CSS -->
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
+       <link href="theme.css" rel="stylesheet">
+</head>
+
+<body role="document" data-spy="scroll" data-target="#main_menu_div">
+    <nav id="mynav" class="navbar navbar-default navbar-fixed-top" role="navigation">
+      <div class="container" style="width: 98%;">
+        <div class="navbar-header">
+          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main_menu_div">
+            <span class="sr-only">Toggle navigation</span>
+            <span class="icon-bar"></span>
+            <span class="icon-bar"></span>
+            <span class="icon-bar"></span>
+          </button>
+          <a class="navbar-brand" href="/" id="hostname_id">NetData</a>
+        </div>
+        <div class="navbar-header navbar-right">
+               <ul class="nav navbar-nav">
+               <li><a href="/">Looking for the new Dashboard?</a></li>
+               </ul>
+        </div>
+               <form class="navbar-form navbar-right">
+                       <!-- <div class="form-group">
+                               <input type="text" class="form-control" placeholder="Search">
+                       </div> -->
+                               <button type="button" class="btn btn-primary global_play_button" onClick="buttonGlobalPlayPause('toggle');" data-play-text="<span class='glyphicon glyphicon-pause'></span> Pause" data-pause-text="<span class='glyphicon glyphicon-play'></span> Play" data-toggle="tooltip" data-placement="bottom" title=" click <span class='glyphicon glyphicon-play'></span> to have the graphs auto-refresh, or click <span class='glyphicon glyphicon-pause'></span> to pause the graphs.">
+                               <span class="glyphicon glyphicon-pause"></span> Pause
+                               </button>
+                       <div class="btn-group btn-group" data-toggle="buttons" role="group">
+                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Show less detail to speed up the browser. Use this if your machine is old and slow.">
+                                       <input type="radio" name="presentation" id="presentation_speedy" onChange="setPresentationSpeedy(0);">Speedy
+                               </label>
+                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Balance graphs detail with browser speed. Use this on modern computers.">
+                                       <input type="radio" name="presentation" id="presentation_normal" onChange="setPresentationNormal(0);">Normal
+                               </label>
+                               <label class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Show all the detail there is. This may slow down your browser.">
+                                       <input type="radio" name="presentation" id="presentation_detailed" onChange="setPresentationDetailed(0);">Detailed
+                               </label>
+                       </div>
+               </form>
+        <div class="collapse navbar-collapse" id="main_menu_div">
+          <ul class="nav navbar-nav">
+            <li><a href="#">preparing charts...</a></li>
+          </ul>
+        </div><!--/.nav-collapse -->
+      </div>
+    </nav>
+
+    <div class="container graphs" id="maingraph_container" style="display: none;">
+               <table>
+                       <tr><td>
+                       <div class="maingraph">
+                                       <table>
+                                               <tr><td>
+                                               <div class="maingraph" id="maingraph"></div>
+                                               <div id="maingraph_dashboard">
+                                                       <div class="maingraph" id="maingraph_hidden" style="display: none"></div>
+                                                       <div class="maingraph" id="maingraph_control"></div>
+                                               </div>
+                                               </td></tr>
+                                               <tr><td align="center">
+                                                       <div class="btn-group">
+                                                               <form id="mainchartform">
+                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title=" click <span class='glyphicon glyphicon-play'></span> to have the graph auto-refresh, or click <span class='glyphicon glyphicon-pause'></span> to pause the graph. When paused the graph can be zoomed and panned horizontally." >
+                                                                               <button type="button" class="btn btn-primary mainchart_play_button" data-play-text="<span class='glyphicon glyphicon-pause'></span>" data-pause-text="<span class='glyphicon glyphicon-play'></span>" onClick="setMainChartPlay('toggle');">
+                                                                                       <span class="glyphicon glyphicon-pause"></span>
+                                                                               </button>
+                                                                       </div>
+                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title="use the maximum ( <span class='glyphicon glyphicon-signal'></span> ) or the average ( <span class='glyphicon glyphicon-align-justify'></span> ) value of grouped points" >
+                                                                               <button type="button" class="btn btn-primary mainchart_avg_button" data-max-text="<span class='glyphicon glyphicon-signal'></span>" data-average-text="<span class='glyphicon glyphicon-align-justify'></span>" onClick="setMainChartGroupMethod('toggle');">
+                                                                                       <span class="glyphicon glyphicon-signal"></span>
+                                                                               </button>
+                                                                       </div>
+                                                                       <div class="btn-group btn-group" data-toggle="buttons" >
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="do not group points, show the raw data">
+                                                                                       <input type="radio" name="group" id="group1" onChange="setMainChartGroup(1);">1
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group in half, show 1 every 2 points of data">
+                                                                                       <input type="radio" name="group" id="group2" onChange="setMainChartGroup(2);">2
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 3 points of data">
+                                                                                       <input type="radio" name="group" id="group3" onChange="setMainChartGroup(3);">3
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 4 points of data">
+                                                                                       <input type="radio" name="group" id="group4" onChange="setMainChartGroup(4);">4
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 5 points of data">
+                                                                                       <input type="radio" name="group" id="group5" onChange="setMainChartGroup(5);">5
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 10 points of data">
+                                                                                       <input type="radio" name="group" id="group10" onChange="setMainChartGroup(10);">10
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 15 points of data">
+                                                                                       <input type="radio" name="group" id="group15" onChange="setMainChartGroup(15);">15
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 20 points of data">
+                                                                                       <input type="radio" name="group" id="group20" onChange="setMainChartGroup(20);">20
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 30 points of data">
+                                                                                       <input type="radio" name="group" id="group30" onChange="setMainChartGroup(30);">30
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 45 points of data">
+                                                                                       <input type="radio" name="group" id="group45" onChange="setMainChartGroup(45);">45
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 60 points of data">
+                                                                                       <input type="radio" name="group" id="group60" onChange="setMainChartGroup(60);">60
+                                                                               </label>
+                                                                               <label class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="group every 90 points of data">
+                                                                                       <input type="radio" name="group" id="group90" onChange="setMainChartGroup(90);">90
+                                                                               </label>
+                                                                       </div>
+                                                                       <div class="btn-group btn-group" data-toggle="tooltip" data-placement="top" title="maximized ( <span class='glyphicon glyphicon-fullscreen'></span> ) or normal ( <span class='glyphicon glyphicon-resize-small'></span> ) view of the graph" >
+                                                                               <button type="button" class="btn btn-primary mainchart_max_button" data-maximized-text="<span class='glyphicon glyphicon-resize-small'></span>" data-normal-text="<span class='glyphicon glyphicon-fullscreen'></span>" onClick="setMainChartMax('toggle');">
+                                                                                       <span class="glyphicon glyphicon-fullscreen"></span>
+                                                                               </button>
+                                                                       </div>
+                                                               </form>
+                                                       </div>
+                                                       </td></tr>
+                                       </table>
+                          </div><!-- /.maingraph -->
+                       </td></tr>
+               </table>
+       </div>
+
+    <div class="container graphs" id="thumbgraphs_container" style="display: none;">
+       <div id="thumbgraphs">
+       </div>
+       </div>
+
+    <div class="container graphs" id="groupgraphs_container" style="display: none;">
+       <div class="allgraphs" id="groupgraphs">
+       </div>
+       </div>
+
+    <div class="container" id="splash_container">
+               <table width="100%">
+                       <tr><td id="splash" align="center" style="vertical-align: middle; height: 400px; overflow: auto;">
+                               <h2>
+                               Welcome to <b>NetData</b>!
+                               <br/><br/>
+                               <span class="glyphicon glyphicon-off"></span>
+                               <br/><br/>
+                               loading cosmos
+                               <br/><br/>
+                               <span class="label label-default">Please wait...</span>
+                               </h2>
+                       </td></tr>
+               </table>
+       </div>
+
+    <div class="container graphs" id="footer_container">
+               &nbsp;<p/>
+               <hr/>
+       <h4>NetData</h4>
+       Realtime System Information over the web for all linux systems.
+       <p/>
+       Distributed under GPL v2.
+       <p/>
+       (c) 2015 Costa Tsaousis <a href="mailto:costa@tsaousis.gr">costa@tsaousis.gr</a>
+       <p/>
+       <div id="server_summary_id"></div>
+    </div>
+
+       <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
+       <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
+       <script type='text/javascript'>
+               document.getElementById('splash').height = $(window).height();
+       </script>
+
+       <!-- Google AJAX API -->
+       <script type="text/javascript" src="https://www.google.com/jsapi"></script>
+
+       <!-- NetData -->
+       <script type="text/javascript" src="netdata.js"></script>
+       <script type="text/javascript" src="index.js"></script>
+
+       <script type='text/javascript'>
+               google.load('visualization', '1.1', {packages: ['controls']});
+
+               $(document).ready(function(){
+
+                       $(document).on('click','.navbar-collapse.in',function(e) {
+                               if( $(e.target).is('a') ) {
+                                       $(this).collapse('hide');
+                               }
+                       });
+
+                       $('body').scrollspy({ target: '#main_menu_div' })
+               });
+       </script>
+</html>
diff --git a/web/old/index.js b/web/old/index.js
new file mode 100755 (executable)
index 0000000..3a28daf
--- /dev/null
@@ -0,0 +1,1174 @@
+var page_is_visible = 1;
+
+var TARGET_THUMB_GRAPH_WIDTH = 500;            // thumb charts width will range from 0.5 to 1.5 of that
+var MINIMUM_THUMB_GRAPH_WIDTH = 400;   // thumb chart will generally try to be wider than that
+var TARGET_THUMB_GRAPH_HEIGHT = 160;   // the height of the thumb charts
+var TARGET_GROUP_GRAPH_HEIGHT = 160;
+
+var THUMBS_MAX_TIME_TO_SHOW = 240;             // how much time the thumb charts will present?
+var THUMBS_POINTS_DIVISOR = 3;
+var THUMBS_STACKED_POINTS_DIVISOR = 4;
+
+var GROUPS_MAX_TIME_TO_SHOW = 600;             // how much time the group charts will present?
+var GROUPS_POINTS_DIVISOR = 2;
+var GROUPS_STACKED_POINTS_DIVISOR = 3;
+
+var MAINCHART_MIN_TIME_TO_SHOW = 1200; // how much time the main chart will present by default?
+var MAINCHART_POINTS_DIVISOR = 2;              // how much detailed will the main chart be by default? 1 = finest, higher is faster
+var MAINCHART_STACKED_POINTS_DIVISOR = 3;              // how much detailed will the main chart be by default? 1 = finest, higher is faster
+
+var MAINCHART_CONTROL_HEIGHT = 75;             // how tall the control chart will be
+var MAINCHART_CONTROL_DIVISOR = 5;             // how much detailed will the control chart be? 1 = finest, higher is faster
+var MAINCHART_INITIAL_SELECTOR= 20;            // 1/20th of the width, this overrides MAINCHART_MIN_TIME_TO_SHOW
+
+var CHARTS_REFRESH_LOOP = 50;                  // delay between chart refreshes
+var CHARTS_REFRESH_IDLE = 500;                 // delay between chart refreshes when no chart was ready for refresh the last time
+var CHARTS_CHECK_NO_FOCUS = 500;               // delay to check for visibility when the page has no focus
+var CHARTS_SCROLL_IDLE = 100;                  // delay to wait after a page scroll
+
+var ENABLE_CURVE = 1;
+
+var resize_request = false;
+
+function setPresentationNormal(ui) {
+       THUMBS_POINTS_DIVISOR                           = 3;
+       THUMBS_STACKED_POINTS_DIVISOR           = Math.round(THUMBS_POINTS_DIVISOR * 1.5);
+       GROUPS_POINTS_DIVISOR                           = 2;
+       GROUPS_STACKED_POINTS_DIVISOR           = Math.round(GROUPS_POINTS_DIVISOR * 1.5);
+       MAINCHART_POINTS_DIVISOR                        = 2;
+       MAINCHART_STACKED_POINTS_DIVISOR        = Math.round(MAINCHART_POINTS_DIVISOR * 1.5);
+       ENABLE_CURVE = 1;
+       CHARTS_REFRESH_LOOP = 50;
+       CHARTS_SCROLL_IDLE = 50;
+       resize_request = true;
+       if(ui) $('#presentation_normal').trigger('click');
+       playGraphs();
+}
+function setPresentationSpeedy(ui) {
+       THUMBS_POINTS_DIVISOR                           = 10;
+       THUMBS_STACKED_POINTS_DIVISOR           = Math.round(THUMBS_POINTS_DIVISOR * 1.5);
+       GROUPS_POINTS_DIVISOR                           = 8;
+       GROUPS_STACKED_POINTS_DIVISOR           = Math.round(GROUPS_POINTS_DIVISOR * 1.5);
+       MAINCHART_POINTS_DIVISOR                        = 5;
+       MAINCHART_STACKED_POINTS_DIVISOR        = Math.round(MAINCHART_POINTS_DIVISOR * 1.5);
+       ENABLE_CURVE = 0;
+       CHARTS_REFRESH_LOOP = 50;
+       CHARTS_SCROLL_IDLE = 100;
+       resize_request = true;
+       if(ui) $('#presentation_speedy').trigger('click');
+       playGraphs();
+}
+function setPresentationDetailed(ui) {
+       THUMBS_POINTS_DIVISOR                           = 1;
+       THUMBS_STACKED_POINTS_DIVISOR           = 1;
+       GROUPS_POINTS_DIVISOR                           = 1;
+       GROUPS_STACKED_POINTS_DIVISOR           = 1;
+       MAINCHART_POINTS_DIVISOR                        = 1;
+       MAINCHART_STACKED_POINTS_DIVISOR        = 1;
+       ENABLE_CURVE = 1;
+       CHARTS_REFRESH_LOOP = 50;
+       CHARTS_SCROLL_IDLE = 50;
+       resize_request = true;
+       if(ui) $('#presentation_detailed').trigger('click');
+       playGraphs();
+}
+
+function isIE() {
+  userAgent = navigator.userAgent;
+  return userAgent.indexOf("MSIE ") > -1 || userAgent.indexOf("Trident/") > -1;
+}
+
+if(isIE()){
+       // do stuff with ie-users
+       CHARTS_REFRESH_LOOP=250;
+       CHARTS_SCROLL_IDLE=500;
+}
+
+var MODE_THUMBS = 1;
+var MODE_MAIN = 2;
+var MODE_GROUP_THUMBS = 3;
+var mode; // one of the MODE_* values
+
+var allCharts = new Array();
+var mainchart;
+
+// html for the main menu
+var mainmenu = "";
+var categoriesmainmenu = "";
+var familiesmainmenu = "";
+var chartsmainmenu = "";
+
+
+// ------------------------------------------------------------------------
+// common HTML generation
+
+function thumbChartActions(i, c, nogroup) {
+       var name = c.name;
+       if(!nogroup) name = c.family;
+
+       var refinfo = "the chart is drawing ";
+       if(c.group == 1) refinfo += "every single point collected (" + c.update_every + "s each).";
+       else refinfo += ((c.group_method == "average")?"the average":"the max") + " value for every " + (c.group * c.update_every) + " seconds of data";
+
+       var html = "<div class=\"btn-group btn-group\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"" + refinfo + "\">"
+       +               "<button type=\"button\" class=\"btn btn-default\" onclick=\"javascript: return;\"><span class=\"glyphicon glyphicon-info-sign\"></span></button>"
+       +       "</div>"
+       +       "<div class=\"btn-group btn-group\"><button type=\"button\" class=\"btn btn-default disabled\"><small>&nbsp;&nbsp; " + name + "</small></button>";
+
+       if(!nogroup) {
+               var ingroup = 0;
+               var ingroup_detail = 0;
+
+               $.each(allCharts, function(i, d) {
+                       if(d.family == c.family) {
+                               ingroup++;
+                               if(d.isdetail) ingroup_detail++;
+                       }
+               });
+
+               var hidden = "";
+               if(ingroup_detail) hidden = ", including " + ingroup_detail + " charts not shown now";
+
+               html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Show all " + ingroup + " charts in group '" + c.family + "'" + hidden + "\" class=\"btn btn-default\" onclick=\"initGroupGraphs('" + c.family +"');\"><span class=\"glyphicon glyphicon-th-large\"></span></button>";
+       }
+
+       html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"show chart '" + c.name + "' in fullscreen\" class=\"btn btn-default\" onclick=\"initMainChartIndex(" + i +");\"><span class=\"glyphicon glyphicon-resize-full\"></span></button>"
+       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"set options for chart '" + c.name + "'\" class=\"btn btn-default disabled\" onclick=\"alert('Not implemented yet!');\"><span class=\"glyphicon glyphicon-cog\"></span></button>"
+       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"ignore chart '" + c.name + "'\" class=\"btn btn-default\" onclick=\"disableChart(" + i + ");\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
+       +       "</div>";
+
+       return html;
+}
+
+function groupChartActions(i, c) {
+       var name = c.name;
+
+       var refinfo = "the chart is drawing ";
+       if(c.group == 1) refinfo += "every single point collected (" + c.update_every + "s each).";
+       else refinfo += ((c.group_method == "average")?"the average":"the max") + " value for every " + (c.group * c.update_every) + " seconds of data";
+
+       var html = "<div class=\"btn-group btn-group\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"" + refinfo + "\">"
+       +               "<button type=\"button\" class=\"btn btn-default\" onclick=\"javascript: return;\"><span class=\"glyphicon glyphicon-info-sign\"></span></button>"
+       +       "</div>";
+
+       html += "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"show chart '" + c.name + "' in fullscreen\" class=\"btn btn-default\" onclick=\"initMainChartIndex(" + i +");\"><span class=\"glyphicon glyphicon-resize-full\"></span></button>"
+       +               "<button type=\"button\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"ignore chart '" + c.name + "'\" class=\"btn btn-default\" onclick=\"disableChart(" + i + ");\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
+       +       "</div>";
+
+       return html;
+}
+
+function mylog(txt) {
+       console.log(txt);
+       $('#logline').html(txt);
+}
+
+function chartssort(a, b) {
+       if(a.priority == b.priority) {
+               if(a.name < b.name) return -1;
+       }
+       else if(a.priority < b.priority) return -1;
+
+       return 1;
+}
+
+
+// ------------------------------------------------------------------------
+// MAINGRAPH = fullscreen view of 1 graph
+
+// copy the chart c to mainchart
+// switch to main graphs screen
+function initMainChart(c) {
+       if(mainchart) cleanThisChart(mainchart);
+
+       mainchart = $.extend(true, {}, c);
+       mainchart.enabled = true;
+       mainchart.refreshCount = 0;
+       mainchart.last_updated = 0;
+       mainchart.chartOptions.explorer = null;
+       mainchart.chart = null;
+
+       mainchart.before = 0;
+       mainchart.after = 0;
+
+       mainchart.chartOptions.width = screenWidth();
+       mainchart.chartOptions.height = $(window).height() - 150 - MAINCHART_CONTROL_HEIGHT;
+       if(mainchart.chartOptions.height < 300) mainchart.chartOptions.height = 300;
+
+       mainchart.div = 'maingraph';
+       mainchart.max_time_to_show = (mainchart.last_entry_t - mainchart.first_entry_t) / ( MAINCHART_INITIAL_SELECTOR * mainchart.update_every );
+       if(mainchart.max_time_to_show < MAINCHART_MIN_TIME_TO_SHOW) mainchart.max_time_to_show = MAINCHART_MIN_TIME_TO_SHOW;
+       calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, 0, ENABLE_CURVE);
+
+       // copy it to the hidden chart
+       mainchart.hiddenchart = $.extend(true, {}, mainchart);
+       mainchart.hiddenchart.chartOptions.height = MAINCHART_CONTROL_HEIGHT;
+       mainchart.hiddenchart.div = 'maingraph_control';
+       mainchart.hiddenchart.non_zero = 0;
+
+       // initialize the div
+       showChartIsLoading(mainchart.div, mainchart.name, mainchart.chartOptions.width, mainchart.chartOptions.height);
+       document.getElementById(mainchart.hiddenchart.div).innerHTML = "<table><tr><td align=\"center\" width=\"" + mainchart.hiddenchart.chartOptions.width + "\" height=\"" + mainchart.hiddenchart.chartOptions.height + "\" style=\"vertical-align:middle\"><h4><span class=\"label label-default\">Please wait...</span></h4></td></tr></table>";
+       //showChartIsLoading(mainchart.hiddenchart.div, mainchart.hiddenchart.name, mainchart.hiddenchart.chartOptions.width, mainchart.hiddenchart.chartOptions.height);
+
+       // set the radio buttons
+       setMainChartGroupMethod(mainchart.group_method, 'no-refresh');
+       setMainChartMax('normal');
+
+       $('#group' + mainchart.group).trigger('click');
+       setMainChartGroup(mainchart.group, 'no-refresh');
+
+       switchToMainGraph();
+}
+
+function refreshHiddenChart(doNext) {
+       if(refresh_mode == REFRESH_PAUSED && mainchart.hiddenchart.last_updated != 0) {
+               if(typeof doNext == "function") doNext();
+               return;
+       }
+
+       // is it too soon for a refresh?
+       var now = new Date().getTime();
+       if((now - mainchart.hiddenchart.last_updated) < (mainchart.update_every * 10 * 1000) || (now - mainchart.hiddenchart.last_updated) < (mainchart.hiddenchart.group * mainchart.hiddenchart.update_every * 1000)) {
+               if(typeof doNext == "function") doNext();
+               return;
+       }
+
+       if(mainchart.dashboard && mainchart.hiddenchart.refreshCount > 50) {
+               mainchart.dashboard.clear();
+               mainchart.control_wrapper.clear();
+               mainchart.hidden_wrapper.clear();
+
+               mainchart.dashboard = null;
+               mainchart.control_wrapper = null;
+               mainchart.hidden_wrapper = null;
+               mainchart.hiddenchart.last_updated = 0;
+       }
+
+       if(!mainchart.dashboard) {
+               var controlopts = $.extend(true, {}, mainchart.chartOptions, {
+                       lineWidth: 1,
+                       height: mainchart.hiddenchart.chartOptions.height,
+                       chartArea: {'width': '98%'},
+                       hAxis: {'baselineColor': 'none', viewWindowMode: 'maximized', gridlines: { count: 0 } },
+                       vAxis: {'title': null, gridlines: { count: 0 } },
+               });
+
+               mainchart.dashboard = new google.visualization.Dashboard(document.getElementById('maingraph_dashboard'));
+               mainchart.control_wrapper = new google.visualization.ControlWrapper({
+                       controlType: 'ChartRangeFilter',
+                       containerId: 'maingraph_control',
+                       options: {
+                               filterColumnIndex: 0,
+                               ui: {
+                                       chartType: mainchart.chartType,
+                                       chartOptions: controlopts,
+                                       minRangeSize: (mainchart.max_time_to_show * 1000) / MAINCHART_POINTS_DIVISOR,
+                               }
+                       },
+               });
+               mainchart.hidden_wrapper = new google.visualization.ChartWrapper({
+                       chartType: mainchart.chartType,
+                       containerId: 'maingraph_hidden',
+                       options: {
+                               isStacked: mainchart.chartOptions.isStacked,
+                               width: mainchart.hiddenchart.chartOptions.width,
+                               height: mainchart.hiddenchart.chartOptions.height,
+                               //chartArea: {'height': '80%', 'width': '100%'},
+                               //hAxis: {'slantedText': false},
+                               //legend: {'position': 'none'}
+                       },
+               });
+
+               mainchart.hiddenchart.refreshCount = 0;
+       }
+
+       // load the data for the control and the hidden wrappers
+       // calculate the group and points to show for the control chart
+       calculateChartPointsToShow(mainchart.hiddenchart, MAINCHART_CONTROL_DIVISOR, 0, -1, ENABLE_CURVE);
+
+       $.ajax({
+               url: generateChartURL(mainchart.hiddenchart),
+               dataType:"json",
+               cache: false
+       })
+       .done(function(jsondata) {
+               if(!jsondata || jsondata.length == 0) return;
+
+               mainchart.control_data = new google.visualization.DataTable(jsondata);
+
+               if(mainchart.hiddenchart.last_updated == 0) {
+                       google.visualization.events.addListener(mainchart.control_wrapper, 'ready', mainchartControlReadyEvent);
+                       mainchart.dashboard.bind(mainchart.control_wrapper, mainchart.hidden_wrapper);
+               }
+               if(refresh_mode != REFRESH_PAUSED) {
+                       // console.log('mainchart.points_to_show: ' + mainchart.points_to_show + ', mainchart.group: ' + mainchart.group + ', mainchart.update_every: ' + mainchart.update_every);
+
+                       var start = now - (mainchart.points_to_show * mainchart.group * mainchart.update_every * 1000);
+                       var end = now;
+                       var min = MAINCHART_MIN_TIME_TO_SHOW * 1000;
+                       if(end - start < min) start = end - min;
+
+                       mainchart.control_wrapper.setState({range: {
+                               start: new Date(start),
+                               end: new Date(end)
+                       },
+                       ui: {
+                               minRangeSize: min
+                       }});
+               }
+
+               mainchart.dashboard.draw(mainchart.control_data);
+               mainchart.hiddenchart.last_updated = new Date().getTime();
+               mainchart.hiddenchart.refreshCount++;
+       })
+       .always(function() {
+               if(typeof doNext == "function") doNext();
+       });
+}
+
+function mainchartControlReadyEvent() {
+       google.visualization.events.addListener(mainchart.control_wrapper, 'statechange', mainchartControlStateHandler);
+       //mylog(mainchart);
+}
+
+function mainchartControlStateHandler() {
+       // setMainChartPlay('pause');
+
+       var state = mainchart.control_wrapper.getState();
+       mainchart.after = Math.round(state.range.start.getTime() / 1000);
+       mainchart.before = Math.round(state.range.end.getTime() / 1000);
+
+       calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.before - mainchart.after, 0, ENABLE_CURVE);
+       //mylog('group = ' + mainchart.group + ', points_to_show = ' + mainchart.points_to_show + ', dt = ' + (mainchart.before - mainchart.after));
+
+       $('#group' + mainchart.group).trigger('click');
+       mainchart.last_updated = 0;
+
+       if(refresh_mode != REFRESH_PAUSED) pauseGraphs();
+}
+
+function initMainChartIndex(i) {
+       if(mode == MODE_GROUP_THUMBS)
+               initMainChart(groupCharts[i]);
+
+       else if(mode == MODE_THUMBS)
+               initMainChart(allCharts[i]);
+
+       else
+               initMainChart(allCharts[i]);
+}
+
+function initMainChartIndexOfMyCharts(i) {
+       initMainChart(allCharts[i]);
+}
+
+var last_main_chart_max='normal';
+function setMainChartMax(m) {
+       if(!mainchart) return;
+
+       if(m == 'toggle') {
+               if(last_main_chart_max == 'maximized') m = 'normal';
+               else m = 'maximized';
+       }
+
+       if(m == "maximized") {
+               mainchart.chartOptions.theme = 'maximized';
+               //mainchart.chartOptions.axisTitlesPosition = 'in';
+               //mainchart.chartOptions.legend = {position: 'none'};
+               mainchart.chartOptions.hAxis.title = null;
+               mainchart.chartOptions.hAxis.viewWindowMode = 'maximized';
+               mainchart.chartOptions.vAxis.viewWindowMode = 'maximized';
+               mainchart.chartOptions.chartArea = {'width': '98%', 'height': '100%'};
+       }
+       else {
+               mainchart.chartOptions.hAxis.title = null;
+               mainchart.chartOptions.theme = null;
+               mainchart.chartOptions.hAxis.viewWindowMode = null;
+               mainchart.chartOptions.vAxis.viewWindowMode = null;
+               mainchart.chartOptions.chartArea = {'width': '80%', 'height': '90%'};
+       }
+       $('.mainchart_max_button').button(m);
+       last_main_chart_max = m;
+       mainchart.last_updated = 0;
+}
+
+function setMainChartGroup(g, norefresh) {
+       if(!mainchart) return;
+
+       mainchart.group = g;
+
+       if(!mainchart.before && !mainchart.after)
+               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, mainchart.group, ENABLE_CURVE);
+       else
+               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, 0, mainchart.group, ENABLE_CURVE);
+
+       if(!norefresh) {
+               mainchart.last_updated = 0;
+       }
+}
+
+var last_main_chart_avg = null;
+function setMainChartGroupMethod(g, norefresh) {
+       if(!mainchart) return;
+
+       if(g == 'toggle') {
+               if(last_main_chart_avg == 'max') g = 'average';
+               else g = 'max';
+       }
+
+       mainchart.group_method = g;
+
+       $('.mainchart_avg_button').button(g);
+
+       if(!norefresh) {
+               mainchart.last_updated = 0;
+       }
+
+       last_main_chart_avg = g;
+}
+
+function setMainChartPlay(p) {
+       if(!mainchart) return;
+
+       if(p == 'toggle') {
+               if(refresh_mode != REFRESH_ALWAYS) p = 'play';
+               else p = 'pause';
+       }
+
+       if(p == 'play') {
+               //mainchart.chartOptions.explorer = null;
+               mainchart.after = 0;
+               mainchart.before = 0;
+               calculateChartPointsToShow(mainchart, mainchart.chartOptions.isStacked?MAINCHART_STACKED_POINTS_DIVISOR:MAINCHART_POINTS_DIVISOR, mainchart.max_time_to_show, 0, ENABLE_CURVE);
+               $('#group' + mainchart.group).trigger('click');
+               mainchart.last_updated = 0;
+               mainchart.hiddenchart.last_updated = 0;
+               playGraphs();
+       }
+       else {
+               //mainchart.chartOptions.explorer = {
+               //      'axis': 'horizontal',
+               //      'maxZoomOut': 1,
+               //};
+               //mainchart.last_updated = 0;
+
+               //if(!renderChart(mainchart, pauseGraphs))
+               pauseGraphs();
+       }
+}
+
+function buttonGlobalPlayPause(p) {
+       if(mode == MODE_MAIN) {
+               setMainChartPlay(p);
+               return;
+       }
+
+       if(p == 'toggle') {
+               if(refresh_mode != REFRESH_ALWAYS) p = 'play';
+               else p = 'pause';
+       }
+
+       if(p == 'play') playGraphs();
+       else pauseGraphs();
+}
+
+
+// ------------------------------------------------------------------------
+// Chart resizing
+
+function screenWidth() {
+       return (($(window).width() * 0.95) - 50);
+}
+
+// calculate the proper width for the thumb charts
+function thumbWidth() {
+       var cwidth = screenWidth();
+       var items = Math.round(cwidth / TARGET_THUMB_GRAPH_WIDTH);
+       if(items < 1) items = 1;
+
+       if(items > 1 && (cwidth / items) < MINIMUM_THUMB_GRAPH_WIDTH) items--;
+
+       return Math.round(cwidth / items) - 1;
+}
+
+function groupChartSizes() {
+       var s = { width: screenWidth(), height: TARGET_GROUP_GRAPH_HEIGHT };
+
+       var count = 0;
+       if(groupCharts) $.each(groupCharts, function(i, c) {
+               if(c.enabled) count++;
+       });
+
+       if(count == 0) {
+               s.width = TARGET_GROUP_GRAPH_HEIGHT;
+               s.height = TARGET_GROUP_GRAPH_HEIGHT;
+       }
+       else {
+               if(s.width < MINIMUM_THUMB_GRAPH_WIDTH) s.width = screenWidth();
+               s.height = ($(window).height() - 130) / count - 10;
+       }
+
+       if(s.height < TARGET_GROUP_GRAPH_HEIGHT)
+               s.height = TARGET_GROUP_GRAPH_HEIGHT;
+
+       return s;
+}
+
+// resize all charts
+// if the thumb charts need resize in their width, reset them
+function resizeCharts() {
+       var width = screenWidth();
+
+       if(mainchart) {
+               mainchart.chartOptions.width = width;
+               mainchart.chartOptions.height = $(window).height() - 150 - MAINCHART_CONTROL_HEIGHT;
+               mainchart.last_updated = 0;
+
+               mainchart.hidden_wrapper.setOption('width', width);
+               mainchart.control_wrapper.setOption('ui.chartOptions.width', width);
+               mainchart.hiddenchart.chartOptions.width = width;
+               mainchart.hiddenchart.last_updated = 0;
+       }
+
+       width = thumbWidth();
+       $.each(allCharts, function(i, c) {
+               if(c.enabled) {
+                       cleanThisChart(c);
+                       c.chartOptions.width = width;
+                       calculateChartPointsToShow(c, c.chartOptions.isStacked?THUMBS_STACKED_POINTS_DIVISOR:THUMBS_POINTS_DIVISOR, THUMBS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
+                       showChartIsLoading(c.div, c.name, c.chartOptions.width, c.chartOptions.height);
+                       document.getElementById(c.id + '_thumb_actions_div').innerHTML = thumbChartActions(i, c);
+                       c.last_updated = 0;
+               }
+       });
+
+       if(groupCharts) $.each(groupCharts, function(i, c) {
+               var sizes = groupChartSizes();
+
+               if(c.enabled) {
+                       cleanThisChart(c);
+                       c.chartOptions.width = sizes.width;
+                       c.chartOptions.height = sizes.height;
+                       calculateChartPointsToShow(c, c.chartOptions.isStacked?GROUPS_STACKED_POINTS_DIVISOR:GROUPS_POINTS_DIVISOR, GROUPS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
+                       showChartIsLoading(c.div, c.name, c.chartOptions.width, c.chartOptions.height);
+                       document.getElementById(c.id + '_group_actions_div').innerHTML = groupChartActions(i, c);
+                       c.last_updated = 0;
+               }
+       });
+
+       updateUI();
+}
+
+window.onresize = function(event) {
+       resize_request = true;
+};
+
+
+// ------------------------------------------------------------------------
+// Core of the thread refreshing the charts
+
+var REFRESH_PAUSED = 0;
+var REFRESH_ALWAYS = 1;
+
+var refresh_mode = REFRESH_PAUSED;
+var last_refresh = 0;
+function playGraphs() {
+       mylog('playGraphs()');
+       if(refresh_mode == REFRESH_ALWAYS) return;
+
+       //mylog('PlayGraphs()');
+       refresh_mode = REFRESH_ALWAYS;
+       $('.mainchart_play_button').button('play');
+       $('.global_play_button').button('play');
+
+       // check if the thread died due to a javascript error
+       var now = new Date().getTime();
+       if((now - last_refresh) > 60000) {
+               // it died or never started
+               //mylog('It seems the refresh thread died. Restarting it.');
+               renderChartCallback();
+       }
+}
+
+function pauseGraphs() {
+       mylog('pauseGraphs()');
+       if(refresh_mode == REFRESH_PAUSED) return;
+
+       refresh_mode = REFRESH_PAUSED;
+       $('.mainchart_play_button').button('pause');
+       $('.global_play_button').button('pause');
+}
+
+var interval = null;
+function checkRefreshThread() {
+       if(interval == null) {
+               interval = setInterval(checkRefreshThread, 2000);
+               return;
+       }
+
+       var now = new Date().getTime();
+       if(now - last_refresh > 60000) {
+               mylog('Refresh thread died. Restarting it.');
+               renderChartCallback();
+       }
+}
+
+// refresh the proper chart
+// this is an internal function.
+// never call it directly, or new javascript threads will be spawn
+var timeout = null;
+function renderChartCallback() {
+       last_refresh = new Date().getTime();
+
+       if(!page_is_visible) {
+               timeout = setTimeout(triggerRefresh, CHARTS_CHECK_NO_FOCUS);
+               return;
+       }
+
+       if(resize_request) {
+               mylog('renderChartCallback() resize_request is set');
+               cleanupCharts();
+               resizeCharts();
+               resize_request = false;
+               // refresh_mode = REFRESH_ALWAYS;
+       }
+
+       if(last_user_scroll) {
+               var now = new Date().getTime();
+               if((now - last_user_scroll) >= CHARTS_SCROLL_IDLE) {
+                       last_user_scroll = 0;
+                       mylog('Scrolling: resuming refresh...');
+               }
+               else {
+                       mylog('Scrolling: pausing refresh for ' + (CHARTS_SCROLL_IDLE - (now - last_user_scroll)) + ' ms...');
+                       timeout = setTimeout(triggerRefresh, CHARTS_SCROLL_IDLE - (now - last_user_scroll));
+                       return;
+               }
+       }
+
+       if(refresh_mode == REFRESH_PAUSED) {
+               if(mode == MODE_MAIN && mainchart.last_updated == 0) {
+                       mainChartRefresh();
+                       return;
+               }
+
+               if(mode != MODE_MAIN) {
+                       timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
+                       return;
+               }
+       }
+
+            if(mode == MODE_THUMBS)            timeout = setTimeout(thumbChartsRefreshNext, CHARTS_REFRESH_LOOP);
+       else if(mode == MODE_GROUP_THUMBS)  timeout = setTimeout(groupChartsRefreshNext, CHARTS_REFRESH_LOOP);
+       else if(mode == MODE_MAIN)              timeout = setTimeout(mainChartRefresh, CHARTS_REFRESH_LOOP);
+       else                                    timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
+}
+
+// callback for refreshing the charts later
+// this is an internal function.
+// never call it directly, or new javascript threads will be spawn
+function triggerRefresh() {
+       //mylog('triggerRefresh()');
+
+       if(!page_is_visible || (refresh_mode == REFRESH_PAUSED && mode != MODE_MAIN)) {
+               last_refresh = new Date().getTime();
+               timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
+               return;
+       }
+
+            if(mode == MODE_THUMBS)            timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
+       else if(mode == MODE_GROUP_THUMBS)      timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
+       else if(mode == MODE_MAIN)              timeout = setTimeout(renderChartCallback, CHARTS_REFRESH_IDLE);
+       else                                    timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
+}
+
+// refresh the main chart
+// make sure we don't loose the refreshing thread
+function mainChartRefresh() {
+       //mylog('mainChartRefresh()');
+
+       if(mode != MODE_MAIN || !mainchart) {
+               triggerRefresh();
+               return;
+       }
+
+       if(refresh_mode == REFRESH_PAUSED && mainchart.last_updated != 0) {
+               hiddenChartRefresh();
+               return;
+       }
+
+       if(!renderChart(mainchart, hiddenChartRefresh))
+               hiddenChartRefresh();
+}
+
+function hiddenChartRefresh() {
+       refreshHiddenChart(triggerRefresh);
+}
+
+function roundRobinRenderChart(charts, startat) {
+       var refreshed = false;
+
+       // find a chart to refresh
+       var all = charts.length;
+       var cur = startat + 1;
+       var count = 0;
+
+       for(count = 0; count < all ; count++, cur++) {
+               if(cur >= all) cur = 0;
+
+               if(charts[cur].enabled) {
+                       refreshed = renderChart(charts[cur], renderChartCallback);
+                       if(refreshed) {
+                               mylog('Refreshed: ' + charts[cur].name);
+                               break;
+                       }
+               }
+       }
+
+       if(!refreshed) triggerRefresh();
+       return cur;
+}
+
+// refresh the thumb charts
+// make sure we don't loose the refreshing thread
+var last_thumb_updated = 0;
+function thumbChartsRefreshNext() {
+       //mylog('thumbChartsRefreshNext()');
+
+       if(allCharts.length == 0 || mode != MODE_THUMBS) {
+               triggerRefresh();
+               return;
+       }
+
+       last_thumb_updated = roundRobinRenderChart(allCharts, last_thumb_updated);
+}
+
+// refresh the group charts
+// make sure we don't loose the refreshing thread
+var last_group_updated = 0;
+function groupChartsRefreshNext() {
+       //mylog('groupChartsRefreshNext()');
+
+       if(!groupCharts || groupCharts.length == 0 || mode != MODE_GROUP_THUMBS) {
+               //mylog('cannot refresh charts');
+               triggerRefresh();
+               return;
+       }
+
+       last_group_updated = roundRobinRenderChart(groupCharts, last_group_updated);
+}
+
+
+// ------------------------------------------------------------------------
+// switch the screen between views
+// these should be called only from initXXXX()
+
+function disableChart(i) {
+       mylog('disableChart(' + i + ')');
+
+       var chart = null;
+
+       var count = 0;
+       if(mode == MODE_GROUP_THUMBS && groupCharts) {
+               $.each(groupCharts, function(i, c) {
+                       if(c.enabled) count++;
+               });
+
+               if(i < groupCharts.length) chart = groupCharts[i];
+       }
+       else if(mode == MODE_THUMBS) {
+               $.each(allCharts, function(i, c) {
+                       if(c.enabled) count++;
+               });
+
+               if(i < allCharts.length) chart = allCharts[i];
+       }
+
+       if(!chart) return;
+
+       if(count <= 1) {
+               alert('Cannot close the last chart shown.');
+               return;
+       }
+
+       if(chart) {
+               mylog("request to disable chart " + chart.name);
+               chart.disablethisplease = true;
+               resize_request = true;
+       }
+       else
+               mylog("no chart to disable");
+}
+
+function cleanThisChart(chart, emptydivs) {
+       //mylog('cleanThisChart(' + chart.name + ', ' + emptydivs +')');
+
+       if(chart.dashboard) {
+               chart.dashboard.clear();
+               chart.dashboard = null;
+
+               if(chart.control_wrapper) {
+                       chart.control_wrapper.clear();
+                       chart.control_wrapper = null;
+               }
+
+               if(chart.hidden_wrapper) {
+                       chart.hidden_wrapper.clear();
+                       chart.hidden_wrapper = null;
+               }
+
+               chart.control_data = null;
+       }
+
+       if(chart.chart) chart.chart.clearChart();
+       chart.chart = null;
+
+       if(emptydivs) {
+               var div = document.getElementById(chart.div);
+               if(div) {
+                       div.style.display = 'none';
+                       div.innerHTML = "";
+               }
+
+               div = document.getElementById(chart.div + "_parent");
+               if(div) {
+                       div.style.display = 'none';
+                       div.innerHTML = "";
+               }
+       }
+
+       //mylog("chart " + chart.name + " cleaned with option " + emptydivs);
+}
+
+// cleanup the previously shown charts
+function cleanupCharts() {
+       // mylog('cleanupCharts()');
+
+       if(mode != MODE_MAIN && mainchart) {
+               if(mainchart.chart) cleanThisChart(mainchart);
+               mainchart = null;
+       }
+
+       if(mode != MODE_GROUP_THUMBS && groupCharts) {
+               clearGroupGraphs();
+       }
+
+       // cleanup the disabled charts
+       $.each(allCharts, function(i, c) {
+               if(c.disablethisplease && c.enabled) {
+                       cleanThisChart(c, 'emptydivs');
+                       c.disablethisplease = false;
+                       c.enabled = false;
+                       resize_request = true;
+                       mylog("removed thumb chart " + c.name + " removed");
+               }
+       });
+
+       if(groupCharts) $.each(groupCharts, function(i, c) {
+               if(c.disablethisplease && c.enabled) {
+                       cleanThisChart(c, 'emptydivs');
+                       c.disablethisplease = false;
+                       c.enabled = false;
+                       resize_request = true;
+                       mylog("removed group chart " + c.name + " removed");
+               }
+       });
+
+       // we never cleanup the main chart
+}
+
+function updateUI() {
+       $('[data-toggle="tooltip"]').tooltip({'container': 'body', 'html': true});
+
+       $('[data-spy="scroll"]').each(function () {
+               var $spy = $(this).scrollspy('refresh')
+       })
+}
+
+var thumbsScrollPosition = null;
+function switchToMainGraph() {
+       //mylog('switchToMainGraph()');
+
+       if(!mainchart) return;
+
+       if(!groupCharts) thumbsScrollPosition = window.pageYOffset;
+
+       document.getElementById('maingraph_container').style.display = 'block';
+       document.getElementById('thumbgraphs_container').style.display = 'none';
+       document.getElementById('groupgraphs_container').style.display = 'none';
+       document.getElementById('splash_container').style.display = 'none';
+
+       document.getElementById("main_menu_div").innerHTML = "<ul class=\"nav navbar-nav\"><li><a href=\"javascript:switchToThumbGraphs();\"><span class=\"glyphicon glyphicon-circle-arrow-left\"></span> Back to Dashboard</a></li><li class=\"active\"><a href=\"#\">" + mainchart.name + "</a></li>" + familiesmainmenu + chartsmainmenu + "</ul>" ;
+
+       window.scrollTo(0, 0);
+
+       mode = MODE_MAIN;
+       playGraphs();
+       updateUI();
+}
+
+function switchToThumbGraphs() {
+       //mylog('switchToThumbGraphs()');
+
+       document.getElementById('maingraph_container').style.display = 'none';
+       document.getElementById('thumbgraphs_container').style.display = 'block';
+       document.getElementById('groupgraphs_container').style.display = 'none';
+       document.getElementById('splash_container').style.display = 'none';
+
+       document.getElementById("main_menu_div").innerHTML = mainmenu;
+
+       if(thumbsScrollPosition) window.scrollTo(0, thumbsScrollPosition);
+
+       // switch mode
+       mode = MODE_THUMBS;
+       playGraphs();
+       updateUI();
+}
+
+function switchToGroupGraphs() {
+       //mylog('switchToGroupGraphs()');
+
+       if(!groupCharts) return;
+
+       if(!mainchart) thumbsScrollPosition = window.pageYOffset;
+
+       document.getElementById('maingraph_container').style.display = 'none';
+       document.getElementById('thumbgraphs_container').style.display = 'none';
+       document.getElementById('groupgraphs_container').style.display = 'block';
+       document.getElementById('splash_container').style.display = 'none';
+
+       document.getElementById("main_menu_div").innerHTML = "<ul class=\"nav navbar-nav\"><li><a href=\"javascript:switchToThumbGraphs();\"><span class=\"glyphicon glyphicon-circle-arrow-left\"></span> Back to Dashboard</a></li><li class=\"active\"><a href=\"#\">" + groupCharts[0].family + "</a></li>" + familiesmainmenu + chartsmainmenu + "</ul>";
+
+       window.scrollTo(0, 0);
+
+       mode = MODE_GROUP_THUMBS;
+       playGraphs();
+       updateUI();
+}
+
+
+// ------------------------------------------------------------------------
+// Group Charts
+
+var groupCharts = null;
+function initGroupGraphs(group) {
+       var count = 0;
+
+       if(groupCharts) clearGroupGraphs();
+       groupCharts = new Array();
+
+       var groupbody = "";
+       $.each(allCharts, function(i, c) {
+               if(c.family == group) {
+                       groupCharts[count] = [];
+                       groupCharts[count] = $.extend(true, {}, c);
+                       groupCharts[count].div += "_group";
+                       groupCharts[count].enabled = true;
+                       groupCharts[count].chart = null;
+                       groupCharts[count].last_updated = 0;
+                       count++;
+               }
+       });
+       groupCharts.sort(chartssort);
+
+       var sizes = groupChartSizes();
+
+       var groupbody = "";
+       $.each(groupCharts, function(i, c) {
+               c.chartOptions.width = sizes.width;
+               c.chartOptions.height = sizes.height;
+               c.chartOptions.chartArea.width = '85%';
+               c.chartOptions.chartArea.height = '90%';
+               c.chartOptions.hAxis.textPosition = 'in';
+               c.chartOptions.hAxis.viewWindowMode = 'maximized';
+               c.chartOptions.hAxis.textStyle = { "fontSize": 9 };
+               c.chartOptions.vAxis.textStyle = { "fontSize": 9 };
+               c.chartOptions.fontSize = 11;
+               c.chartOptions.titlePosition = 'in';
+               c.chartOptions.tooltip = { "textStyle": { "fontSize": 9 } };
+               c.chartOptions.legend = { "textStyle": { "fontSize": 9 } };
+
+               calculateChartPointsToShow(c, c.chartOptions.isStacked?GROUPS_STACKED_POINTS_DIVISOR:GROUPS_POINTS_DIVISOR, GROUPS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
+
+               groupbody += "<div class=\"thumbgraph\" id=\"" + c.div + "_parent\"><table><tr><td width='" + sizes.width + "'><div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div></td><td id=\"" + c.id + "_group_actions_div\" align=\"center\">" + groupChartActions(i, c) + "</td></tr><tr><td width='15'></td></tr></table></div>";
+               //groupbody += "<div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div>";
+       });
+       groupbody += "";
+
+       document.getElementById("groupgraphs").innerHTML = groupbody;
+       switchToGroupGraphs();
+}
+
+function clearGroupGraphs() {
+       if(groupCharts && groupCharts.length) {
+               $.each(groupCharts, function(i, c) {
+                       cleanThisChart(c, 'emptydivs');
+               });
+
+               groupCharts = null;
+       }
+
+       document.getElementById("groupgraphs").innerHTML = "";
+}
+
+
+// ------------------------------------------------------------------------
+// Global entry point
+// initialize the thumb charts
+
+var last_user_scroll = 0;
+
+// load the charts from the server
+// generate html for the thumbgraphs to support them
+function initCharts() {
+       setPresentationNormal(1);
+
+       var width = thumbWidth();
+       var height = TARGET_THUMB_GRAPH_HEIGHT;
+
+       window.onscroll = function (e) {
+               last_user_scroll = new Date().getTime();
+               mylog('Scrolling: detected');
+       }
+
+       loadCharts(null, function(all) {
+               allCharts = all.charts;
+
+               if(allCharts == null || allCharts.length == 0) {
+                       alert("Cannot load data from server.");
+                       return;
+               }
+
+               var thumbsContainer = document.getElementById("thumbgraphs");
+               if(!thumbsContainer) {
+                       alert("Cannot find the thumbsContainer");
+                       return;
+               }
+
+               allCharts.sort(chartssort);
+
+               document.getElementById('hostname_id').innerHTML = all.hostname;
+               document.title = all.hostname;
+
+               // create an array for grouping all same-type graphs together
+               var dimensions = 0;
+               var categories = new Array();
+               var families = new Array();
+               var chartslist = new Array();
+               $.each(allCharts, function(i, c) {
+                       var j;
+
+                       chartslist.push({name: c.name, type: c.type, id: i});
+
+                       dimensions += c.dimensions.length;
+                       c.chartOptions.width = width;
+                       c.chartOptions.height = height;
+
+                       // calculate how many point to show for each chart
+                       //c.points_to_show = Math.round(c.entries / c.group) - 1;
+                       // show max 10 mins of data
+                       //if(c.points_to_show * c.group > THUMBS_MAX_TIME_TO_SHOW) c.points_to_show = THUMBS_MAX_TIME_TO_SHOW / c.group;
+                       calculateChartPointsToShow(c, c.chartOptions.isStacked?THUMBS_STACKED_POINTS_DIVISOR:THUMBS_POINTS_DIVISOR, THUMBS_MAX_TIME_TO_SHOW, -1, ENABLE_CURVE);
+
+                       if(c.enabled) {
+                               var h = "<div class=\"thumbgraph\" id=\"" + c.div + "_parent\"><table><tr><td><div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.name, c.chartOptions.width, c.chartOptions.height) + "</div></td></tr><tr><td id=\"" + c.id + "_thumb_actions_div\" align=\"center\">"
+                               + thumbChartActions(i, c)
+                               +       "</td></tr><tr><td height='15'></td></tr></table></div>";
+
+                               // find the categories object for this type
+                               for(j = 0; j < categories.length ;j++) {
+                                       if(categories[j].name == c.type) {
+                                               categories[j].html += h;
+                                               categories[j].count++;
+                                               break;
+                                       }
+                               }
+
+                               if(j == categories.length)
+                                       categories.push({name: c.type, title: c.category, description: '', priority: c.categoryPriority, count: 1, glyphicon: c.glyphicon, html: h});
+                       }
+
+                       // find the families object for this type
+                       for(j = 0; j < families.length ;j++) {
+                               if(families[j].name == c.family) {
+                                       families[j].count++;
+                                       break;
+                               }
+                       }
+
+                       if(j == families.length)
+                               families.push({name: c.family, count: 1});
+               });
+
+               document.getElementById('server_summary_id').innerHTML = "<small>NetData server at <b>" + all.hostname + "</b> is maintaining <b>" + allCharts.length + "</b> charts, having <b>" + dimensions + "</b> dimensions (by default with <b>" + all.history + "</b> entries each), which are updated every <b>" + all.update_every + "s</b>, using a total of <b>" + (Math.round(all.memory * 10 / 1024 / 1024) / 10) + " MB</b> for the round robin database.</small>";
+
+               $.each(categories, function(i, a) {
+                       a.html = "<tr><td id=\"" + a.name + "\"><ol class=\"breadcrumb graphs\"><li class=\"active\"><span class=\"glyphicon " + a.glyphicon + "\"></span> &nbsp; <a id=\"" + a.name + "\" href=\"#" + a.name + "\"><b>" + a.title + "</b> " + a.description + " </a></li></ol></td></tr><tr><td><div class=\"thumbgraphs\">" + a.html + "</td></tr>";
+               });
+
+               function categoriessort(a, b) {
+                       if(a.priority < b.priority) return -1;
+                       return 1;
+               }
+               categories.sort(categoriessort);
+
+               function familiessort(a, b) {
+                       if(a.name < b.name) return -1;
+                       return 1;
+               }
+               families.sort(familiessort);
+
+               function chartslistsort(a, b) {
+                       if(a.name < b.name) return -1;
+                       return 1;
+               }
+               chartslist.sort(chartslistsort);
+
+               // combine all the htmls into one
+               var allcategories = "<table width=\"100%\">";
+               mainmenu = '<ul class="nav navbar-nav">';
+
+               categoriesmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-fire\"></span> Dashboard Sections <b class="caret"></b></a><ul class="dropdown-menu">';
+               $.each(categories, function(i, a) {
+                       allcategories += a.html;
+                       categoriesmainmenu += "<li><a href=\"#" + a.name + "\">" + a.title + "</a></li>";
+               });
+               categoriesmainmenu += "</ul></li>";
+               allcategories += "</table>";
+
+               familiesmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-th-large\"></span> Chart Families <b class="caret"></b></a><ul class="dropdown-menu">';
+               $.each(families, function(i, a) {
+                       familiesmainmenu += "<li><a href=\"javascript:initGroupGraphs('" + a.name + "');\">" + a.name + " <span class=\"badge pull-right\">" + a.count + "</span></a></li>";
+               });
+               familiesmainmenu += "</ul></li>";
+
+               chartsmainmenu = '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class=\"glyphicon glyphicon-resize-full\"></span> All Charts <b class="caret"></b></a><ul class="dropdown-menu">';
+               $.each(chartslist, function(i, a) {
+                       chartsmainmenu += "<li><a href=\"javascript:initMainChartIndexOfMyCharts('" + a.id + "');\">" + a.name + "</a></li>";
+               });
+               chartsmainmenu += "</ul></li>";
+
+               mainmenu += categoriesmainmenu;
+               mainmenu += familiesmainmenu;
+               mainmenu += chartsmainmenu;
+               mainmenu += '<li role="presentation" class="disabled" style="display: none;"><a href="#" id="logline"></a></li></ul>';
+
+               thumbsContainer.innerHTML = allcategories;
+               switchToThumbGraphs();
+               checkRefreshThread();
+       });
+}
+
+$(window).blur(function() {
+       page_is_visible = 0;
+       mylog('Lost Focus!');
+});
+
+$(window).focus(function() {
+       page_is_visible = 1;
+       mylog('Focus restored!');
+});
+
+// Set a callback to run when the Google Visualization API is loaded.
+google.setOnLoadCallback(initCharts);
diff --git a/web/old/netdata.js b/web/old/netdata.js
new file mode 100755 (executable)
index 0000000..f1af0a6
--- /dev/null
@@ -0,0 +1,502 @@
+// fix old IE bug with console
+if(!window.console){ window.console = {log: function(){} }; }
+
+// Load the Visualization API and the piechart package.
+google.load('visualization', '1.1', {'packages':['corechart']});
+//google.load('visualization', '1.1', {'packages':['controls']});
+
+function canChartBeRefreshed(chart) {
+       // is it enabled?
+       if(!chart.enabled) return false;
+
+       // is there something selected on the chart?
+       if(chart.chart && chart.chart.getSelection()[0]) return false;
+
+       // is it too soon for a refresh?
+       var now = new Date().getTime();
+       if((now - chart.last_updated) < (chart.group * chart.update_every * 1000)) return false;
+
+       // is the chart in the visible area?
+       //console.log(chart.div);
+       if($('#' + chart.div).visible(true) == false) return false;
+
+       // ok, do it
+       return true;
+}
+
+function generateChartURL(chart) {
+       // build the data URL
+       var url = chart.url;
+       url += chart.points_to_show?chart.points_to_show.toString():"all";
+       url += "/";
+       url += chart.group?chart.group.toString():"1";
+       url += "/";
+       url += chart.group_method?chart.group_method:"average";
+       url += "/";
+       url += chart.after?chart.after.toString():"0";
+       url += "/";
+       url += chart.before?chart.before.toString():"0";
+       url += "/";
+       url += chart.non_zero?"nonzero":"all";
+       url += "/";
+
+       return url;
+}
+
+function renderChart(chart, doNext) {
+       if(canChartBeRefreshed(chart) == false) return false;
+
+       $.ajax({
+               url: generateChartURL(chart),
+               dataType:"json",
+               cache: false
+       })
+       .done(function(jsondata) {
+               if(!jsondata || jsondata.length == 0) return;
+               chart.jsondata = jsondata;
+
+               // Create our data table out of JSON data loaded from server.
+               chart.datatable = new google.visualization.DataTable(chart.jsondata);
+               //console.log(chart.datatable);
+
+               // cleanup once every 50 updates
+               // we don't cleanup on every single, to avoid firefox flashing effect
+               if(chart.chart && chart.refreshCount > 50) {
+                       chart.chart.clearChart();
+                       chart.chart = null;
+                       chart.refreshCount = 0;
+               }
+
+               // Instantiate and draw our chart, passing in some options.
+               if(!chart.chart) {
+                       // console.log('Creating new chart for ' + chart.url);
+                       if(chart.chartType == "LineChart")
+                               chart.chart = new google.visualization.LineChart(document.getElementById(chart.div));
+                       else
+                               chart.chart = new google.visualization.AreaChart(document.getElementById(chart.div));
+               }
+
+               if(chart.chart) {
+                       chart.chart.draw(chart.datatable, chart.chartOptions);
+                       chart.refreshCount++;
+                       chart.last_updated = new Date().getTime();
+               }
+               else console.log('Cannot create chart for ' + chart.url);
+       })
+       .fail(function() {
+               // to avoid an infinite loop, let's assume it was refreshed
+               if(chart.chart) chart.chart.clearChart();
+               chart.chart = null;
+               chart.refreshCount = 0;
+               showChartIsLoading(chart.div, chart.name, chart.chartOptions.width, chart.chartOptions.height, "failed to refresh");
+               chart.last_updated = new Date().getTime();
+       })
+       .always(function() {
+               if(typeof doNext == "function") doNext();
+       });
+
+       return true;
+}
+
+function chartIsLoadingHTML(name, width, height, message)
+{
+       return "<table><tr><td align=\"center\" width=\"" + width + "\" height=\"" + height + "\" style=\"vertical-align:middle\"><h4><span class=\"glyphicon glyphicon-refresh\"></span><br/><br/>" + name + "<br/><br/><span class=\"label label-default\">" + (message?message:"loading chart...") + "</span></h4></td></tr></table>";
+}
+
+function showChartIsLoading(id, name, width, height, message) {
+       document.getElementById(id).innerHTML = chartIsLoadingHTML(name, width, height, message);
+}
+
+// calculateChartPointsToShow
+// calculate the chart group and point to show properties.
+// This uses the chartOptions.width and the supplied divisor
+// to calculate the propers values so that the chart will
+// be visually correct (not too much or too less points shown).
+//
+// c = the chart
+// divisor = when calculating screen points, divide width with this
+//           if all screen points are used the chart will be overcrowded
+//           the default is 2
+// maxtime = the maxtime to show
+//           the default is to render all the server data
+// group   = the required grouping on points
+//           if undefined or negative, any calculated value will be used
+//           if zero, one of 1,2,5,10,15,20,30,45,60 will be used
+
+function calculateChartPointsToShow(c, divisor, maxtime, group, enable_curve) {
+       // console.log('calculateChartPointsToShow( c = ' + c.id + ',  divisor = ' + divisor + ', maxtime = ' + maxtime + ', group = ' + group + ' )');
+
+       if(!divisor) divisor = 2;
+
+       var before = c.before?c.before:new Date().getTime() / 1000;
+       var after = c.after?c.after:c.first_entry_t;
+
+       var dt = before - after;
+       if(dt > c.entries * c.update_every) dt = c.entries * c.update_every;
+
+       // console.log('chart ' + c.id + ' internal duration is ' + dt + ' secs, requested maxtime is ' + maxtime + ' secs');
+
+       if(!maxtime) maxtime = c.entries * c.update_every;
+       dt = maxtime;
+
+       var data_points = Math.round(dt / c.update_every);
+       if(!data_points) data_points = 100;
+
+       var screen_points = Math.round(c.chartOptions.width / divisor);
+       if(!screen_points) screen_points = 100;
+
+       // console.log('screen_points = ' + screen_points + ', data_points = ' + data_points + ', divisor = ' + divisor);
+
+       if(group == undefined || group <= 0) {
+               if(screen_points > data_points) {
+                       c.group = 1;
+                       c.points_to_show = data_points;
+                       // console.log("rendering at full detail (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
+               }
+               else {
+                       c.group = Math.round(data_points / screen_points);
+
+                            if(c.group > 60) c.group = 90;
+                       else if(c.group > 45) c.group = 60;
+                       else if(c.group > 30) c.group = 45;
+                       else if(c.group > 20) c.group = 30;
+                       else if(c.group > 15) c.group = 20;
+                       else if(c.group > 10) c.group = 15;
+                       else if(c.group > 5) c.group = 10;
+                       else if(c.group > 4) c.group = 5;
+                       else if(c.group > 3) c.group = 4;
+                       else if(c.group > 2) c.group = 3;
+                       else if(c.group > 1) c.group = 2;
+                       else c.group = 1;
+
+                       c.points_to_show = Math.round(data_points / c.group);
+                       // console.log("rendering adaptive (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
+               }
+       }
+       else {
+               c.group = group;
+               c.points_to_show = Math.round(data_points / group);
+               // console.log("rendering with supplied group (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
+       }
+
+       // console.log("final configuration (group = " + c.group + ", points_to_show = " + c.points_to_show + ')');
+
+       // make sure the line width is not congesting the chart
+       if(c.chartType == 'LineChart') {
+               if(c.points_to_show > c.chartOptions.width / 3) {
+                       c.chartOptions.lineWidth = 1;
+               }
+
+               else {
+                       c.chartOptions.lineWidth = 2;
+               }
+       }
+       else if(c.chartType == 'AreaChart') {
+               if(c.points_to_show > c.chartOptions.width / 2)
+                       c.chartOptions.lineWidth = 0;
+               else
+                       c.chartOptions.lineWidth = 1;
+       }
+
+       // do not render curves when we don't have at
+       // least 2 twice the space per point
+       if(!enable_curve || c.points_to_show > (c.chartOptions.width * c.chartOptions.lineWidth / 2) )
+               c.chartOptions.curveType = 'none';
+       else
+               c.chartOptions.curveType = c.default_curveType;
+
+       var hpoints = Math.round(maxtime / 30);
+       if(hpoints > 10) hpoints = 10;
+       c.chartOptions.hAxis.gridlines.count = hpoints;
+}
+
+
+// loadCharts()
+// fetches all the charts from the server
+// returns an array of objects, containing all the server metadata
+// (not the values of the graphs - just the info about the graphs)
+
+function loadCharts(base_url, doNext) {
+       $.ajax({
+               url: ((base_url)?base_url:'') + '/all.json',
+               dataType: 'json',
+               cache: false
+       })
+       .done(function(json) {
+               $.each(json.charts, function(i, value) {
+                       json.charts[i].div = json.charts[i].name.replace(/\./g,"_");
+                       json.charts[i].div = json.charts[i].div.replace(/\-/g,"_");
+                       json.charts[i].div = json.charts[i].div + "_div";
+
+                       // make sure we have the proper values
+                       if(!json.charts[i].update_every) chart.update_every = 1;
+                       if(base_url) json.charts[i].url = base_url + json.charts[i].url;
+
+                       json.charts[i].last_updated = 0;
+                       json.charts[i].thumbnail = false;
+                       json.charts[i].refreshCount = 0;
+                       json.charts[i].group = 1;
+                       json.charts[i].points_to_show = 0;      // all
+                       json.charts[i].group_method = "max";
+
+                       json.charts[i].chart = null;
+                       json.charts[i].jsondata = null;
+                       json.charts[i].datatable = null;
+                       json.charts[i].before = 0;
+                       json.charts[i].after = 0;
+
+                       // if it is detail, disable it by default
+                       if(json.charts[i].isdetail) json.charts[i].enabled = false;
+
+                       // set default chart options
+                       json.charts[i].chartOptions = {
+                               width: 400,
+                               height: 200,
+                               lineWidth: 1,
+                               title: json.charts[i].title,
+                               fontSize: 11,
+                               hAxis: {
+                               //      title: "Time of Day",
+                               //      format:'HH:mm:ss',
+                                       viewWindowMode: 'maximized',
+                                       slantedText: false,
+                                       format:'HH:mm:ss',
+                                       textStyle: {
+                                               fontSize: 9
+                                       },
+                                       gridlines: {
+                                               color: '#EEE'
+                                       }
+                               },
+                               vAxis: {
+                                       title: json.charts[i].units,
+                                       viewWindowMode: 'pretty',
+                                       minValue: -0.1,
+                                       maxValue: 0.1,
+                                       direction: 1,
+                                       textStyle: {
+                                               fontSize: 9
+                                       },
+                                       gridlines: {
+                                               color: '#EEE'
+                                       }
+                               },
+                               chartArea: {
+                                       width: '65%',
+                                       height: '80%'
+                               },
+                               focusTarget: 'category',
+                               annotation: {
+                                       '1': {
+                                               style: 'line'
+                                       }
+                               },
+                               pointsVisible: 0,
+                               titlePosition: 'out',
+                               titleTextStyle: {
+                                       fontSize: 11
+                               },
+                               tooltip: {
+                                       isHtml: true,
+                                       ignoreBounds: true,
+                                       textStyle: {
+                                               fontSize: 9
+                                       }
+                               }
+                       };
+
+                       json.charts[i].default_curveType = 'none';
+
+                       // set the chart type
+                       switch(json.charts[i].chart_type) {
+                               case "area":
+                                       json.charts[i].chartType = "AreaChart";
+                                       json.charts[i].chartOptions.isStacked = false;
+                                       json.charts[i].chartOptions.areaOpacity = 0.3;
+
+                                       json.charts[i].chartOptions.vAxis.viewWindowMode = 'maximized';
+                                       json.charts[i].non_zero = 0;
+
+                                       json.charts[i].group = 3;
+                                       break;
+
+                               case "stacked":
+                                       json.charts[i].chartType = "AreaChart";
+                                       json.charts[i].chartOptions.isStacked = true;
+                                       json.charts[i].chartOptions.areaOpacity = 0.85;
+                                       json.charts[i].chartOptions.lineWidth = 1;
+                                       json.charts[i].group_method = "average";
+                                       json.charts[i].non_zero = 1;
+
+                                       json.charts[i].chartOptions.vAxis.viewWindowMode = 'maximized';
+                                       json.charts[i].chartOptions.vAxis.minValue = null;
+                                       json.charts[i].chartOptions.vAxis.maxValue = null;
+
+                                       json.charts[i].group = 10;
+                                       break;
+
+                               default:
+                               case "line":
+                                       json.charts[i].chartType = "LineChart";
+                                       json.charts[i].chartOptions.lineWidth = 2;
+                                       json.charts[i].non_zero = 0;
+
+                                       json.charts[i].default_curveType = 'function';
+
+                                       json.charts[i].group = 3;
+                                       break;
+                       }
+
+                       // the category name, and other options, per type
+                       switch(json.charts[i].type) {
+                               case "system":
+                                       json.charts[i].category = "System";
+                                       json.charts[i].categoryPriority = 10;
+                                       json.charts[i].glyphicon = "glyphicon-dashboard";
+
+                                       if(json.charts[i].id == "system.cpu" || json.charts[i].id == "system.ram") {
+                                               json.charts[i].chartOptions.vAxis.minValue = 0;
+                                               json.charts[i].chartOptions.vAxis.maxValue = 100;
+                                       }
+                                       else {
+                                               json.charts[i].chartOptions.vAxis.minValue = -0.1;
+                                               json.charts[i].chartOptions.vAxis.maxValue =  0.1;
+                                       }
+                                       break;
+
+                               case "net":
+                                       json.charts[i].category = "Network";
+                                       json.charts[i].categoryPriority = 20;
+                                       json.charts[i].glyphicon = "glyphicon-transfer";
+
+                                       // disable IFB and net.lo devices by default
+                                       if((json.charts[i].id.substring(json.charts[i].id.length - 4, json.charts[i].id.length) == "-ifb")
+                                               || json.charts[i].id == "net.lo")
+                                               json.charts[i].enabled = false;
+                                       break;
+
+                               case "tc":
+                                       json.charts[i].category = "Quality of Service";
+                                       json.charts[i].categoryPriority = 30;
+                                       json.charts[i].glyphicon = "glyphicon-random";
+                                       break;
+
+                               case "ipvs":
+                                       json.charts[i].category = "IP Virtual Server";
+                                       json.charts[i].categoryPriority = 40;
+                                       json.charts[i].glyphicon = "glyphicon-sort";
+                                       break;
+
+                               case "netfilter":
+                                       json.charts[i].category = "Netfilter";
+                                       json.charts[i].categoryPriority = 50;
+                                       json.charts[i].glyphicon = "glyphicon-cloud";
+                                       break;
+
+                               case "ipv4":
+                                       json.charts[i].category = "IPv4";
+                                       json.charts[i].categoryPriority = 60;
+                                       json.charts[i].glyphicon = "glyphicon-globe";
+                                       break;
+
+                               case "mem":
+                                       json.charts[i].category = "Memory";
+                                       json.charts[i].categoryPriority = 70;
+                                       json.charts[i].glyphicon = "glyphicon-dashboard";
+                                       break;
+
+                               case "cpu":
+                                       json.charts[i].category = "CPU";
+                                       json.charts[i].categoryPriority = 80;
+                                       json.charts[i].glyphicon = "glyphicon-dashboard";
+
+                                       if(json.charts[i].id.substring(0, 7) == "cpu.cpu") {
+                                               json.charts[i].chartOptions.vAxis.minValue = 0;
+                                               json.charts[i].chartOptions.vAxis.maxValue = 100;
+                                       }
+                                       break;
+
+                               case "disk":
+                                       json.charts[i].category = "Disks";
+                                       json.charts[i].categoryPriority = 90;
+                                       json.charts[i].glyphicon = "glyphicon-hdd";
+                                       break;
+
+                               case "nfsd":
+                                       json.charts[i].category = "NFS Server";
+                                       json.charts[i].categoryPriority = 100;
+                                       json.charts[i].glyphicon = "glyphicon-hdd";
+                                       break;
+
+                               case "nut":
+                                       json.charts[i].category = "UPS";
+                                       json.charts[i].categoryPriority = 110;
+                                       json.charts[i].glyphicon = "glyphicon-dashboard";
+                                       break;
+
+                               case "netdata":
+                                       json.charts[i].category = "NetData";
+                                       json.charts[i].categoryPriority = 3000;
+                                       json.charts[i].glyphicon = "glyphicon-thumbs-up";
+                                       break;
+
+                               case "apps":
+                                       json.charts[i].category = "Apps";
+                                       json.charts[i].categoryPriority = 4000;
+                                       json.charts[i].glyphicon = "glyphicon-tasks";
+                                       break;
+
+                               case "squid":
+                                       json.charts[i].category = "Squid";
+                                       json.charts[i].categoryPriority = 5000;
+                                       json.charts[i].glyphicon = "glyphicon-link";
+                                       break;
+
+                               case "example":
+                                       json.charts[i].category = "Examples";
+                                       json.charts[i].categoryPriority = 9000;
+                                       json.charts[i].glyphicon = "glyphicon-search";
+                                       break;
+
+                               default:
+                                       json.charts[i].category = json.charts[i].type;
+                                       json.charts[i].categoryPriority = 1000;
+                                       json.charts[i].glyphicon = "glyphicon-search";
+                                       break;
+                       }
+               });
+
+               if(typeof doNext == "function") doNext(json);
+       })
+       .fail(function() {
+               if(typeof doNext == "function") doNext();
+       });
+};
+
+// jquery visible plugin
+(function($){
+
+       /**
+        * Copyright 2012, Digital Fusion
+        * Licensed under the MIT license.
+        * http://teamdf.com/jquery-plugins/license/
+        *
+        * @author Sam Sehnert
+        * @desc A small plugin that checks whether elements are within
+        *               the user visible viewport of a web browser.
+        *               only accounts for vertical position, not horizontal.
+        */
+       $.fn.visible = function(partial){
+
+           var $t                              = $(this),
+               $w                              = $(window),
+               viewTop                 = $w.scrollTop(),
+               viewBottom              = viewTop + $w.height(),
+               _top                    = $t.offset().top,
+               _bottom                 = _top + $t.height(),
+               compareTop              = partial === true ? _bottom : _top,
+               compareBottom   = partial === true ? _top : _bottom;
+
+               return ((compareBottom <= viewBottom) && (compareTop >= viewTop));
+    };
+})(jQuery);
diff --git a/web/old/theme.css b/web/old/theme.css
new file mode 100644 (file)
index 0000000..0252533
--- /dev/null
@@ -0,0 +1,87 @@
+/* http://stackoverflow.com/questions/17005500/bootstrap-css-responsive-left-with-a-white-space-on-the-right */
+
+html {
+  width: auto !important;
+  overflow-x: hidden !important;
+}
+
+body {
+  width: auto !important;
+  overflow-x: hidden !important;
+  padding-top: 70px;
+  padding-bottom: 30px;
+}
+
+.theme-dropdown .dropdown-menu {
+  position: static;
+  display: block;
+  margin-bottom: 20px;
+}
+
+.theme-showcase > p > .btn {
+  margin: 5px 0;
+}
+
+.thumbgraph {
+       float: left;
+}
+
+.thumbgraphs {
+       width: 100%;
+}
+
+.thumbtitle {
+       float: none;
+       width: 100%;
+}
+
+.thumbgroup {
+       float: none;
+       width: 100%;
+}
+
+.container.graphs {
+       width: 98%;
+}
+
+.breadcrumb.graphs {
+    margin-top: 10px;
+    margin-bottom: 10px;
+}
+
+.dropdown-menu {
+    max-height: 500px;
+    overflow-y: auto;
+    overflow-x: hidden;
+}
+
+.google-visualization-tooltip-action: hover {
+  background-color: #eeeeee;
+}
+.google-visualization-tooltip {
+  border: solid 1px #bdbdbd;
+  border-radius: 2px;
+  background-color: white;
+  box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
+  font-size: 9px;
+  -moz-box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
+  -webkit-box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
+  position: absolute;
+  line-height: 90% !important;
+  margin: 0 0 0 0 !important;
+  padding: 0.5em 0.1em 0.5em 0.1em !important;
+  width: 180px !important;
+  z-index: 1000 !important;
+}
+.google-visualization-tooltip-item-list {
+  list-style-type: none;
+  margin: 0 0 0 0 !important;
+  padding: 0 0 0 0 !important;
+}
+.google-visualization-tooltip-item {
+  margin: 0 0 0 0 !important;
+}
+.google-visualization-tooltip-item-list
+.google-visualization-tooltip-item:first-child {
+  margin: 0 0 0 0 !important;
+}
diff --git a/web/theme.css b/web/theme.css
deleted file mode 100644 (file)
index 0252533..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* http://stackoverflow.com/questions/17005500/bootstrap-css-responsive-left-with-a-white-space-on-the-right */
-
-html {
-  width: auto !important;
-  overflow-x: hidden !important;
-}
-
-body {
-  width: auto !important;
-  overflow-x: hidden !important;
-  padding-top: 70px;
-  padding-bottom: 30px;
-}
-
-.theme-dropdown .dropdown-menu {
-  position: static;
-  display: block;
-  margin-bottom: 20px;
-}
-
-.theme-showcase > p > .btn {
-  margin: 5px 0;
-}
-
-.thumbgraph {
-       float: left;
-}
-
-.thumbgraphs {
-       width: 100%;
-}
-
-.thumbtitle {
-       float: none;
-       width: 100%;
-}
-
-.thumbgroup {
-       float: none;
-       width: 100%;
-}
-
-.container.graphs {
-       width: 98%;
-}
-
-.breadcrumb.graphs {
-    margin-top: 10px;
-    margin-bottom: 10px;
-}
-
-.dropdown-menu {
-    max-height: 500px;
-    overflow-y: auto;
-    overflow-x: hidden;
-}
-
-.google-visualization-tooltip-action: hover {
-  background-color: #eeeeee;
-}
-.google-visualization-tooltip {
-  border: solid 1px #bdbdbd;
-  border-radius: 2px;
-  background-color: white;
-  box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
-  font-size: 9px;
-  -moz-box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
-  -webkit-box-shadow: 0px 2px 2px 0px rgba(204, 204, 204, 0.6);
-  position: absolute;
-  line-height: 90% !important;
-  margin: 0 0 0 0 !important;
-  padding: 0.5em 0.1em 0.5em 0.1em !important;
-  width: 180px !important;
-  z-index: 1000 !important;
-}
-.google-visualization-tooltip-item-list {
-  list-style-type: none;
-  margin: 0 0 0 0 !important;
-  padding: 0 0 0 0 !important;
-}
-.google-visualization-tooltip-item {
-  margin: 0 0 0 0 !important;
-}
-.google-visualization-tooltip-item-list
-.google-visualization-tooltip-item:first-child {
-  margin: 0 0 0 0 !important;
-}