PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.30.0
Independent Analytics – WordPress Analytics Plugin v1.30.0
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 / IAWP / Chart.php
independent-analytics / IAWP Last commit date
AJAX 2 years ago Date_Range 2 years ago Interval 3 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Queries 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 2 years ago Chart_SVG.php 3 years ago City_To_Country_Converter.php 3 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 3 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Downloader.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 3 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 3 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Reset_Database.php 3 years ago Resource_Identifier.php 3 years ago Settings.php 2 years ago Sort_Configuration.php 3 years ago Track_Resource_Changes.php 3 years ago View.php 2 years ago View_Counter.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago
Chart.php
155 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\Statistics\Intervals\Intervals;
6 use IAWP_SCOPED\IAWP\Statistics\Statistics;
7 use IAWP_SCOPED\IAWP\Utils\Security;
8 class Chart
9 {
10 private $statistics;
11 private $title;
12 private $preview;
13 public function __construct(Statistics $statistics, ?string $title, bool $preview = \false)
14 {
15 $this->preview = $preview;
16 $this->statistics = $statistics;
17 $this->title = $title;
18 }
19 /**
20 * @param string[] $visible_datasets
21 *
22 * @return false|string
23 */
24 public function get_html(array $visible_datasets = ['visitors', 'views'])
25 {
26 $labels = \array_map(function ($data_point) {
27 return Security::json_encode($this->statistics->chart_interval()->get_label_for($data_point[0]));
28 }, $this->statistics->views()->daily_summary());
29 $views_data = \array_map(function ($data_point) {
30 return $data_point[1];
31 }, $this->statistics->views()->daily_summary());
32 $visitors_data = \array_map(function ($data_point) {
33 return $data_point[1];
34 }, $this->statistics->visitors()->daily_summary());
35 $sessions_data = \array_map(function ($data_point) {
36 return $data_point[1];
37 }, $this->statistics->sessions()->daily_summary());
38 $woocommerce_orders_data = \array_map(function ($data_point) {
39 return $data_point[1];
40 }, $this->statistics->woocommerce_orders()->daily_summary());
41 $woocommerce_net_sales_data = \array_map(function ($data_point) {
42 return $data_point[1];
43 }, $this->statistics->woocommerce_net_sales()->daily_summary());
44 return $this->chart_html($labels, $views_data, $visitors_data, $sessions_data, $woocommerce_orders_data, $woocommerce_net_sales_data, $visible_datasets);
45 }
46 private function chart_html(array $labels, array $views, array $visitors, array $sessions, array $woocommerce_orders_data, array $woocommerce_net_sales_data, array $visible_datasets)
47 {
48 \ob_start();
49 ?>
50 <div class="chart-container">
51 <div class="chart-inner">
52 <div class="legend-container">
53 <h2 class="legend-title"><?php
54 \esc_html_e($this->title);
55 ?></h2>
56 <div class="legend"></div>
57 <?php
58 if ($this->is_full_view()) {
59 ?>
60 <select class="chart-interval-select" data-controller="chart-interval" data-action="chart-interval#setChartInterval">
61 <?php
62 foreach (Intervals::all() as $interval) {
63 ?>
64 <option
65 value="<?php
66 \esc_attr_e($interval->id());
67 ?>"
68 <?php
69 \selected($interval->equals($this->statistics->chart_interval()));
70 ?>
71 ><?php
72 \esc_html_e($interval->label());
73 ?></option>
74 <?php
75 }
76 ?>
77 </select>
78 <?php
79 }
80 ?>
81 </div>
82 <canvas id="myChart"
83 data-testid="chart"
84 width="800"
85 height="200"
86 data-controller="chart"
87 data-chart-locale-value="<?php
88 echo \get_bloginfo('language');
89 ?>"
90 data-chart-preview-value='<?php
91 echo $this->is_preview() ? '1' : '0';
92 ?>'
93 data-chart-using-woo-commerce-value='<?php
94 echo \IAWP_SCOPED\iawp_using_woocommerce() ? '1' : '0';
95 ?>'
96 data-chart-labels-value='<?php
97 echo Security::json_encode($labels);
98 ?>'
99 data-chart-views-value='<?php
100 echo Security::json_encode($views);
101 ?>'
102 data-chart-visitors-value='<?php
103 echo Security::json_encode($visitors);
104 ?>'
105 data-chart-visible-datasets-value='<?php
106 echo Security::json_encode($visible_datasets);
107 ?>'
108 <?php
109 if ($this->is_full_view()) {
110 ?>
111 data-chart-sessions-value='<?php
112 echo Security::json_encode($sessions);
113 ?>'
114 <?php
115 }
116 ?>
117 <?php
118 if ($this->is_full_view() && \IAWP_SCOPED\iawp_using_woocommerce()) {
119 ?>
120 data-chart-currency-value="<?php
121 echo get_woocommerce_currency();
122 ?>"
123 data-chart-woocommerce-orders-value='<?php
124 echo Security::json_encode($woocommerce_orders_data);
125 ?>'
126 data-chart-woocommerce-net-sales-value='<?php
127 echo Security::json_encode($woocommerce_net_sales_data);
128 ?>'
129 <?php
130 }
131 ?>
132 >
133 </canvas>
134 </div>
135 </div><?php
136 $html = \ob_get_contents();
137 \ob_end_clean();
138 return $html;
139 }
140 /**
141 * @return bool
142 */
143 private function is_preview() : bool
144 {
145 return $this->preview;
146 }
147 /**
148 * @return bool
149 */
150 private function is_full_view() : bool
151 {
152 return !$this->is_preview();
153 }
154 }
155