Merge pull request #303 from danvk/fix-hidpi
[dygraphs.git] / gallery / edge-padding.js
CommitLineData
e88a95b4 1/*global Gallery,Dygraph,data */
fa460473
KW
2Gallery.register(
3 'edge-padding',
4 {
5 name: 'Edge Padding',
6 title: 'Graph edge padding and axis position',
7 setup: function(parent) {
8 parent.innerHTML = (
9 "<p>" +
10 " <b>Mode:</b>" +
11 " <input type='radio' name='mode'>use {x,y}RangePad</input>" +
12 " <input type='radio' name='mode'>original</input>" +
13 " <br /><b>Settings:</b>" +
14 " <input type='checkbox' id='yrange'>valueRange=[-2,2]</input>" +
15 "</p>" +
16 "<div id='demodiv'></div>"
17 );
18 },
19 run: function() {
20 var parent = document.getElementById("demodiv");
21
22 var graphs = [];
23 var nrows = 50;
24
25 for (var oy = -2; oy <= 2; ++oy) {
26 for (var ox = -1; ox <= 1; ++ox) {
27 var gdiv = document.createElement('div');
28 gdiv.style.display = 'inline-block';
29 gdiv.style.margin = '2px';
30 parent.appendChild(gdiv);
31
32 var data = [];
33 for (var row = 0; row < nrows; ++row) {
34 var x = row * 5 / (nrows - 1);
35 data.push([ox * 2.5 + x - 2.5,
36 oy + Math.sin(x),
37 oy + Math.round(Math.cos(x))]);
38 }
39
40 var g = new Dygraph(gdiv, data, {
41 labels: ['x', 'A', 'B'],
42 labelDivWidth: 100,
43 gridLineColor: '#ccc',
44 includeZero: true,
45 width: 250,
46 height: 130
47 });
48 graphs.push(g);
49 }
50 parent.appendChild(document.createElement('br'));
51 }
52
53 var updateGraphOpts = function(opts) {
54 for (var i = 0; i < graphs.length; ++i) {
55 graphs[i].updateOptions(opts);
56 }
57 };
58
59 var mode = document.getElementsByName('mode');
60 mode[0].onchange = function() {
61 updateGraphOpts({
62 avoidMinZero: false,
63 xRangePad: 3,
64 yRangePad: 10,
e1e80cce
DV
65 drawAxesAtZero: true});
66 };
fa460473
KW
67 mode[1].onchange = function() {
68 updateGraphOpts({
69 avoidMinZero: true,
70 xRangePad: 0,
71 yRangePad: null,
e1e80cce
DV
72 drawAxesAtZero: false});
73 };
fa460473
KW
74 mode[0].checked = true;
75 mode[0].onchange();
76
77 var yrange = document.getElementById('yrange');
78 yrange.onchange = function(ev) {
79 updateGraphOpts({
80 valueRange: ev.target.checked ? [-2, 2] : null});
81 };
82
83 }
84 });