add back Dygraph.floatFormat
[dygraphs.git] / tests / labelsKMB.html
CommitLineData
54425b14 1<!DOCTYPE html>
02ecfa7a
DV
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
02ecfa7a
DV
5 <title>labelsKMB</title>
6 <!--[if IE]>
a2b2c3a1 7 <script type="text/javascript" src="../excanvas.js"></script>
02ecfa7a 8 <![endif]-->
d37dca40
DV
9 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
10 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
02ecfa7a
DV
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
d160cc3b 18 <p>labelsKMG2:</p>
02ecfa7a
DV
19 <div id="labelsKMG2" style="width:600px; height: 300px;"></div>
20
d160cc3b
NK
21 <p>labelsKMG2 with yValueFormatter:</p>
22 <div id="labelsKMG2yValueFormatter" style="width:600px; height: 300px;"></div>
23
02ecfa7a
DV
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">
029da4b6
DV
28 function round(num, places) {
29 var shift = Math.pow(10, places);
30 return Math.round(num * shift)/shift;
31 };
32
02ecfa7a
DV
33 var data = [];
34 for (var i = 0, n = 1; i < 43; i++, n *= 2) {
35 data.push([i, n]);
36 }
37
d160cc3b
NK
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;
029da4b6 45 return String(round(v / Math.pow(10, magnitude * 3), 2)) +
d160cc3b
NK
46 suffixes[magnitude];
47 }
48
02ecfa7a
DV
49 new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true });
50 new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true });
d160cc3b
NK
51 var g = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data,
52 { labelsKMG2: true, yValueFormatter: formatValue });
02ecfa7a
DV
53 </script>
54 </body>
55</html>