Change no-series-defined behavior so that it computes the
[dygraphs.git] / tests / labelsKMB.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
5 <title>labelsKMB</title>
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
9 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
10 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
11 <script type="text/javascript" src="../dygraph-canvas.js"></script>
12 <script type="text/javascript" src="../dygraph.js"></script>
13 </head>
14 <body>
15 <p>labelsKMB:</p>
16 <div id="labelsKMB" style="width:600px; height: 300px;"></div>
17
18 <p>labelsKMG2:</p>
19 <div id="labelsKMG2" style="width:600px; height: 300px;"></div>
20
21 <p>labelsKMG2 with yValueFormatter:</p>
22 <div id="labelsKMG2yValueFormatter" style="width:600px; height: 300px;"></div>
23
24 <p>The curves are exponentials. Zooming in should reveal each of the 'K',
25 'M', 'B', etc. labels.</p>
26
27 <script type="text/javascript">
28 function round(num, places) {
29 var shift = Math.pow(10, places);
30 return Math.round(num * shift)/shift;
31 };
32
33 var data = [];
34 for (var i = 0, n = 1; i < 43; i++, n *= 2) {
35 data.push([i, n]);
36 }
37
38 var suffixes = ['', 'k', 'M', 'G', 'T'];
39 function formatValue(v) {
40 if (v < 1000) return v;
41
42 var magnitude = Math.floor(String(Math.floor(v)).length / 3);
43 if (magnitude > suffixes.length - 1)
44 magnitude = suffixes.length - 1;
45 return String(round(v / Math.pow(10, magnitude * 3), 2)) +
46 suffixes[magnitude];
47 }
48
49 new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true });
50 new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true });
51 var g = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data,
52 { labelsKMG2: true, yValueFormatter: formatValue });
53 </script>
54 </body>
55 </html>