Browse Source

Uninline chart JS

spaghetti 8 years ago
parent
commit
c5bfdcef37
4 changed files with 98 additions and 113 deletions
  1. 27
    33
      sections/stats/torrents.php
  2. 47
    59
      sections/stats/users.php
  3. 17
    20
      sections/tools/data/user_flow.php
  4. 7
    1
      static/functions/chart.js

+ 27
- 33
sections/stats/torrents.php View File

@@ -46,42 +46,36 @@ View::show_header('Detailed torrent statistics', 'chart');
46 46
 
47 47
 <h3 id="Upload_Flow"><a href="#Upload_Flow">Uploads by month</a></h3>
48 48
 <div class="box pad center">
49
-  <canvas class="chart" id="chart_torrents_timeline"></canvas>
50
-  <script>
51
-    new Chart($('#chart_torrents_timeline').raw().getContext('2d'), {
52
-      type: 'line',
53
-      data: {
54
-        labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
55
-        datasets: [ {
56
-          label: "New Torrents",
57
-          backgroundColor: "rgba(0,0,255,0.2)",
58
-          borderColor: "rgba(0,0,255,0.8)",
59
-          data: <? print "[".implode(",",$InFlow)."]"; ?>
60
-        }, {
61
-          label: "Deleted Torrents",
62
-          backgroundColor: "rgba(255,0,0,0.2)",
63
-          borderColor: "rgba(255,0,0,0.8)",
64
-          data: <? print "[".implode(",",$OutFlow)."]"; ?>
65
-        }]
66
-      }
67
-    })
68
-  </script>
49
+  <canvas class="chart" id="chart_torrents_timeline" data-chart='{
50
+    "type": "line",
51
+    "data": {
52
+      "labels": <? print '["'.implode('","',$Labels).'"]'; ?>,
53
+      "datasets": [ {
54
+        "label": "New Torrents",
55
+        "backgroundColor": "rgba(0,0,255,0.2)",
56
+        "borderColor": "rgba(0,0,255,0.8)",
57
+        "data": <? print "[".implode(",",$InFlow)."]"; ?>
58
+      }, {
59
+        "label": "Deleted Torrents",
60
+        "backgroundColor": "rgba(255,0,0,0.2)",
61
+        "borderColor": "rgba(255,0,0,0.8)",
62
+        "data": <? print "[".implode(",",$OutFlow)."]"; ?>
63
+      }]
64
+    }
65
+  }'></canvas>
69 66
 </div>
70 67
 <h3 id="Torrent_Categories"><a href="#Torrent_Categories">Torrents by category</a></h3>
71 68
 <div class="box pad center">
72
-  <canvas class="chart" id="chart_torrent_categories"></canvas>
73
-  <script>
74
-    new Chart($('#chart_torrent_categories').raw().getContext('2d'), {
75
-      type: 'pie',
76
-      data: {
77
-        labels: <? print '["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?>,
78
-        datasets: [ {
79
-          data: <? print "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>,
80
-          backgroundColor: ['#8a00b8','#a944cb','#be71d8','#e8ccf1', '#f3e3f9', '#fbf6fd', '#ffffff']
81
-        }]
82
-      }
83
-    })
84
-  </script>
69
+  <canvas class="chart" id="chart_torrent_categories" data-chart='{
70
+    "type": "pie",
71
+    "data": {
72
+      "labels": <? print '["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?>,
73
+      "datasets": [ {
74
+        "data": <? print "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>,
75
+        "backgroundColor": ["#8a00b8","#a944cb","#be71d8","#e8ccf1","#f3e3f9","#fbf6fd","#ffffff"]
76
+      }]
77
+    }
78
+  }'></canvas>
85 79
 </div>
86 80
 <?
87 81
 View::show_footer();

+ 47
- 59
sections/stats/users.php View File

@@ -98,48 +98,41 @@ View::show_header('Detailed User Statistics', 'chart');
98 98
 ?>
99 99
 <h3 id="User_Flow"><a href="#User_Flow">User Flow</a></h3>
100 100
 <div class="box pad center">
101
-  <canvas class="chart" id="chart_user_timeline"></canvas>
102
-  <script>
103
-    new Chart($('#chart_user_timeline').raw().getContext('2d'), {
104
-      type: 'line',
105
-      data: {
106
-        labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
107
-        datasets: [ {
108
-          label: "New Registrations",
109
-          backgroundColor: "rgba(0,0,255,0.2)",
110
-          borderColor: "rgba(0,0,255,0.8)",
111
-          data: <? print "[".implode(",",$InFlow)."]"; ?>
112
-        }, {
113
-          label: "Disabled Users",
114
-          backgroundColor: "rgba(255,0,0,0.2)",
115
-          borderColor: "rgba(255,0,0,0.8)",
116
-          data: <? print "[".implode(",",$OutFlow)."]"; ?>
117
-        }]
118
-      }
119
-    })
120
-  </script>
101
+  <canvas class="chart" id="chart_user_timeline" data-chart='{
102
+    "type": "line",
103
+    "data": {
104
+      "labels": <? print '["'.implode('","',$Labels).'"]'; ?>,
105
+      "datasets": [ {
106
+        "label": "New Registrations",
107
+        "backgroundColor": "rgba(0,0,255,0.2)",
108
+        "borderColor": "rgba(0,0,255,0.8)",
109
+        "data": <? print "[".implode(",",$InFlow)."]"; ?>
110
+      }, {
111
+        "label": "Disabled Users",
112
+        "backgroundColor": "rgba(255,0,0,0.2)",
113
+        "borderColor": "rgba(255,0,0,0.8)",
114
+        "data": <? print "[".implode(",",$OutFlow)."]"; ?>
115
+      }]
116
+    }
117
+  }'></canvas>
121 118
 </div>
122 119
 <br />
123 120
 <h3 id="User_Classes"><a href="#User_Classes">User Classes</a></h3>
124 121
 <div class="box pad center">
125
-  <canvas class="chart" id="chart_user_classes"></canvas>
126
-  <script>
127
-    new Chart($('#chart_user_classes').raw().getContext('2d'), {
128
-      type: 'pie',
129
-      data: {
130
-        labels: <? print '["'.implode('","', array_column($ClassDistribution, 'Name')).'"]'; ?>,
131
-        datasets: [ {
132
-          data: <? print "[".implode(",", array_column($ClassDistribution, 'Users'))."]"; ?>,
133
-          backgroundColor: ['#8a00b8','#a944cb','#be71d8','#e8ccf1', '#f3e3f9', '#fbf6fd', '#ffffff']
134
-        }]
135
-      }
136
-    })
137
-  </script>
122
+  <canvas class="chart" id="chart_user_classes" data-chart='{
123
+    "type": "pie",
124
+    "data": {
125
+      "labels": <? print '["'.implode('","', array_column($ClassDistribution, 'Name')).'"]'; ?>,
126
+      "datasets": [ {
127
+        "data": <? print "[".implode(",", array_column($ClassDistribution, 'Users'))."]"; ?>,
128
+        "backgroundColor": ["#8a00b8","#a944cb","#be71d8","#e8ccf1","#f3e3f9","#fbf6fd","#ffffff"]
129
+      }]
130
+    }
131
+  }'></canvas>
138 132
 </div>
139 133
 <br />
140 134
 <h3 id="User_Platforms"><a href="#User_Platforms">User Platforms</a></h3>
141 135
 <div class="box pad center">
142
-  <canvas class="chart" id="chart_user_platforms"></canvas>
143 136
   <?
144 137
     $AllPlatforms = array_column($PlatformDistribution, 'OperatingSystem');
145 138
     $SlicedPlatforms = (count($AllPlatforms) > 14) ? array_slice($AllPlatforms,0,13)+[13=>'Other'] : $AllPlatforms;
@@ -164,23 +157,20 @@ View::show_header('Detailed User Statistics', 'chart');
164 157
       }
165 158
     }
166 159
   ?>
167
-  <script>
168
-    new Chart($('#chart_user_platforms').raw().getContext('2d'), {
169
-      type: 'pie',
170
-      data: {
171
-        labels: ["<?=implode('","', $SlicedPlatforms)?>"],
172
-        datasets: [ {
173
-          data: [<?=implode(",", $SlicedUsers)?>],
174
-            backgroundColor: ["<?=implode('","', $Colors)?>"]
175
-        }]
176
-      }
177
-    })
178
-  </script>
160
+  <canvas class="chart" id="chart_user_platforms" data-chart='{
161
+    "type": "pie",
162
+    "data": {
163
+      "labels": ["<?=implode('","', $SlicedPlatforms)?>"],
164
+      "datasets": [ {
165
+        "data": [<?=implode(",", $SlicedUsers)?>],
166
+          "backgroundColor": ["<?=implode('","', $Colors)?>"]
167
+      }]
168
+    }
169
+  }'></canvas>
179 170
 </div>
180 171
 <br />
181 172
 <h3 id="User_Browsers"><a href="#User_Browsers">User Browsers</a></h3>
182 173
 <div class="box pad center">
183
-  <canvas class="chart" id="chart_user_browsers"></canvas>
184 174
   <?
185 175
     $AllBrowsers = array_column($BrowserDistribution, 'Browser');
186 176
     $SlicedBrowsers = (count($AllBrowsers) > 7) ? array_slice($AllBrowsers,0,6)+[6=>'Other'] : $AllBrowsers;
@@ -205,18 +195,16 @@ View::show_header('Detailed User Statistics', 'chart');
205 195
       }
206 196
     }
207 197
   ?>
208
-  <script>
209
-    new Chart($('#chart_user_browsers').raw().getContext('2d'), {
210
-      type: 'pie',
211
-      data: {
212
-        labels: ["<?=implode('","', $SlicedBrowsers)?>"],
213
-        datasets: [ {
214
-          data: [<?=implode(",", $SlicedUsers)?>],
215
-          backgroundColor: ["<?=implode('","', $Colors)?>"],
216
-        }]
217
-      }
218
-    })
219
-  </script>
198
+  <canvas class="chart" id="chart_user_browsers" data-chart='{
199
+    "type": "pie",
200
+    "data": {
201
+      "labels": ["<?=implode('","', $SlicedBrowsers)?>"],
202
+      "datasets": [{
203
+        "data": [<?=implode(",", $SlicedUsers)?>],
204
+        "backgroundColor": ["<?=implode('","', $Colors)?>"]
205
+      }]
206
+    }
207
+  }'></canvas>
220 208
 </div>
221 209
 <br />
222 210
 <h3 id="Geo_Dist_Map"><a href="#Geo_Dist_Map">Geographical Distribution Map</a></h3>

+ 17
- 20
sections/tools/data/user_flow.php View File

@@ -105,26 +105,23 @@ $DB->set_query_id($RS);
105 105
 <div class="thin">
106 106
 <?  if (!isset($_GET['page'])) { ?>
107 107
   <div class="box pad center">
108
-    <canvas class="chart" id="chart_user_timeline"></canvas>
109
-    <script>
110
-      new Chart($('#chart_user_timeline').raw().getContext('2d'), {
111
-        type: 'line',
112
-        data: {
113
-          labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
114
-          datasets: [ {
115
-            label: "New Registrations",
116
-            backgroundColor: "rgba(0,0,255,0.2)",
117
-            borderColor: "rgba(0,0,255,0.8)",
118
-            data: <? print "[".implode(",",$InFlow)."]"; ?>
119
-          }, {
120
-            label: "Disabled Users",
121
-            backgroundColor: "rgba(255,0,0,0.2)",
122
-            borderColor: "rgba(255,0,0,0.8)",
123
-            data: <? print "[".implode(",",$OutFlow)."]"; ?>
124
-          }]
125
-        }
126
-      })
127
-    </script>
108
+    <canvas class="chart" id="chart_user_timeline" data-chart='{
109
+      "type": "line",
110
+      "data": {
111
+        "labels": <? print '["'.implode('","',$Labels).'"]'; ?>,
112
+        "datasets": [ {
113
+          "label": "New Registrations",
114
+          "backgroundColor": "rgba(0,0,255,0.2)",
115
+          "borderColor": "rgba(0,0,255,0.8)",
116
+          "data": <? print "[".implode(",",$InFlow)."]"; ?>
117
+        }, {
118
+          "label": "Disabled Users",
119
+          "backgroundColor": "rgba(255,0,0,0.2)",
120
+          "borderColor": "rgba(255,0,0,0.8)",
121
+          "data": <? print "[".implode(",",$OutFlow)."]"; ?>
122
+        }]
123
+      }
124
+    }'></canvas>
128 125
   </div>
129 126
 <?  } ?>
130 127
   <div class="linkbox">

+ 7
- 1
static/functions/chart.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save