PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.7
Independent Analytics – WordPress Analytics Plugin v1.7
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / inc / chart.php
independent-analytics / inc Last commit date
models 4 years ago queries 4 years ago utils 4 years ago chart.php 4 years ago db.php 4 years ago delete_data_ajax.php 4 years ago filters.php 4 years ago filters_ajax.php 4 years ago rest_api.php 4 years ago settings.php 4 years ago settings_ajax.php 4 years ago super_secret_content_generator.php 4 years ago table.php 4 years ago table_referrers.php 4 years ago table_views.php 4 years ago track_resource_changes.php 4 years ago
chart.php
94 lines
1 <?php
2
3 namespace IAWP;
4
5 class Chart
6 {
7 public function output_chart(Views $views, string $title = null)
8 {
9 if (is_null($title)) {
10 $title = esc_html__('Last 30 Days', 'iawp');
11 }
12 $labels = array_map(function ($data_point) {
13 return $data_point[0]->format('M j - l');
14 }, $views->daily_views());
15
16 $views_data = array_map(function ($data_point) {
17 return $data_point[1];
18 }, $views->daily_views());
19
20 $visitors_data = array_map(function ($data_point) {
21 return $data_point[1];
22 }, $views->daily_visitors());
23
24 return $this->chart_html($labels, $views_data, $visitors_data, $title);
25 }
26
27 public function chart_html(array $labels, array $views, array $visitors, $title)
28 {
29 // Todo - Bring tick color into the stimulus controller below
30 $tick_color = get_option('iawp_dark_mode') ? '#ffffff' : '#555555';
31 ob_start(); ?>
32 <div class="chart-container">
33 <div class="chart-inner">
34 <div class="legend-container">
35 <h2 class="legend-title"><?php echo $title ?></h2>
36 <div id="legend-container"></div>
37 </div>
38 <canvas id="myChart"
39 width="800"
40 height="200"
41 data-controller="chart"
42 data-chart-mode-value='<?php echo get_option('iawp_dark_mode') ? 'dark' : 'light' ?>'
43 data-chart-labels-value='<?php echo Security::json_encode($labels) ?>'
44 data-chart-views-value='<?php echo Security::json_encode($views) ?>'
45 data-chart-visitors-value='<?php echo Security::json_encode($visitors) ?>'
46 >
47 </canvas>
48 </div>
49 </div><?php
50
51 $html = ob_get_contents();
52 ob_end_clean();
53
54 return $html;
55 }
56
57 public function quick_stats(Views $views, Views $unfiltered_views = null)
58 {
59 $filtered = !is_null($unfiltered_views) ? true : false;
60
61 $stats = [[
62 'title' => __('Views', 'iawp'),
63 'class' => 'views',
64 'count' => $views->views(),
65 'growth' => $views->views_percentage_growth(),
66 ], [
67 'title' => __('Visitors', 'iawp'),
68 'class' => 'visitors',
69 'count' => $views->visitors(),
70 'growth' => $views->visitors_percentage_growth(),
71 ]];
72
73 if ($filtered) {
74 $stats[] = [
75 'title' => __('Total Views', 'iawp'),
76 'class' => 'views unfiltered',
77 'count' => $unfiltered_views->views(),
78 'growth' => $unfiltered_views->views_percentage_growth(),
79 ];
80 $stats[] = [
81 'title' => __('Total Visitors', 'iawp'),
82 'class' => 'visitors unfiltered',
83 'count' => $unfiltered_views->visitors(),
84 'growth' => $unfiltered_views->visitors_percentage_growth(),
85 ];
86 }
87
88 return IAWP()->templates()->render('stats/index', [
89 'is_filtered' => $filtered,
90 'stats' => $stats,
91 ]);
92 }
93 }
94