Procházet zdrojové kódy

size x and y axes according to value ranges and make scrollable

Thomas Buck před 5 roky
rodič
revize
d4a56a7ef5
1 změnil soubory, kde provedl 46 přidání a 1 odebrání
  1. 46
    1
      index.html

+ 46
- 1
index.html Zobrazit soubor

@@ -58,6 +58,37 @@
58 58
                 var div = document.createElement('div');
59 59
                 var ctx = document.createElement('canvas');
60 60
 
61
+                var min_date = new Date('3000-01-01T00:00:00');
62
+                var max_date = new Date('1000-01-01T00:00:00');
63
+                var min_kilo = 1000;
64
+                var max_kilo = 0;
65
+                for (var i = 0; i < data.users.length; i++) {
66
+                    for (var j = 0; j < data.users[i].data.length; j++) {
67
+                        temp_date = new Date(data.users[i].data[j].x);
68
+                        temp_kilo = parseInt(data.users[i].data[j].y);
69
+                        if (temp_date < min_date) {
70
+                            min_date = temp_date;
71
+                        }
72
+                        if (temp_date > max_date) {
73
+                            max_date = temp_date;
74
+                        }
75
+                        if (temp_kilo < min_kilo) {
76
+                            min_kilo = temp_kilo;
77
+                        }
78
+                        if (temp_kilo > max_kilo) {
79
+                            max_kilo = temp_kilo;
80
+                        }
81
+                    }
82
+                }
83
+
84
+                var days = (max_date - min_date) / 1000 / 60 / 60 / 24;
85
+                var pixels_per_day = 3000 / 365;
86
+                var width_px = days * pixels_per_day;
87
+
88
+                var kilos = (max_kilo - min_kilo);
89
+                var pixels_per_kilo = 1400 / 100;
90
+                var height_px = kilos * pixels_per_kilo;
91
+
61 92
                 var datasets = [];
62 93
                 for (var i = 0; i < data.users.length; i++) {
63 94
                     var set = createDataset(data.users[i].name,
@@ -71,6 +102,7 @@
71 102
                         datasets: datasets
72 103
                     },
73 104
                     options: {
105
+                        maintainAspectRatio: false,
74 106
                         scales: {
75 107
                             xAxes: [{
76 108
                                 type: 'time',
@@ -92,7 +124,20 @@
92 124
                 });
93 125
 
94 126
                 if (data.users.length > 0) {
95
-                    div.appendChild(ctx);
127
+                    div_wrapper = document.createElement('div');
128
+                    div_wrapper.setAttribute('style', 'width: ' + Math.ceil(width_px) + 'px;');
129
+
130
+                    div_wrapper.style.width = Math.ceil(width_px) + 'px';
131
+                    div_wrapper.style.height = height_px + 'px';
132
+                    div_wrapper.width = Math.ceil(width_px);
133
+                    div_wrapper.height = height_px;
134
+
135
+                    div_wrapper.appendChild(ctx);
136
+                    div_wrapper2 = document.createElement('div');
137
+                    div_wrapper2.setAttribute('style', 'overflow-x: auto; overflow-y: auto;');
138
+                    div_wrapper2.appendChild(div_wrapper);
139
+
140
+                    div.appendChild(div_wrapper2);
96 141
                     div.appendChild(document.createElement('hr'));
97 142
 
98 143
                     var date = new Date();

Loading…
Zrušit
Uložit