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