AJAX
3 months ago
Admin_Page
3 months ago
Click_Tracking
5 months ago
ColumnOptions
6 months ago
Cron
8 months ago
Custom_WordPress_Columns
8 months ago
Data_Pruning
5 months ago
Date_Picker
3 months ago
Date_Range
5 months ago
Ecommerce
5 months ago
Email_Reports
3 months ago
Examiner
3 months ago
Favicon
5 months ago
Form_Submissions
5 months ago
Integrations
3 months ago
Interval
1 year ago
Journey
5 months ago
Migrations
5 months ago
Models
5 months ago
Overview
3 months ago
Public_API
5 months ago
Rows
3 months ago
Statistics
3 months ago
Tables
3 months ago
Utils
5 months ago
Views
5 months ago
WooCommerceOrderMetaBox
5 months ago
ActivationLifecycle.php
3 months ago
Admin_Bar_Stats.php
3 months ago
Appearance.php
1 year ago
Campaign_Builder.php
3 months ago
Capability_Manager.php
3 months ago
Chart.php
3 months ago
Chart_Data.php
1 year ago
Click_Tracking.php
3 months ago
ComplianzIntegration.php
3 months ago
Cron_Job.php
5 months ago
Cron_Manager.php
5 months ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
6 months ago
Dashboard_Widget.php
2 years ago
Database.php
8 months ago
Database_Manager.php
5 months ago
Empty_Report_Option.php
2 years ago
Env.php
6 months ago
Examiner_Config.php
11 months ago
FetchFaviconsJob.php
5 months ago
Filters.php
3 months ago
Geo_Database_Health_Check_Job.php
8 months ago
Geo_Database_Manager.php
6 months ago
Geoposition.php
1 year ago
Icon_Directory.php
6 months ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
10 months ago
Independent_Analytics.php
5 months ago
Interrupt.php
3 months ago
Known_Referrers.php
6 months ago
MainWP.php
1 year ago
Map.php
8 months ago
Map_Data.php
1 year ago
Migration_Fixer_Job.php
5 months ago
Patch.php
1 year ago
Payload_Validator.php
8 months ago
Plugin_Conflict_Detector.php
6 months ago
Plugin_Group.php
6 months ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
3 months ago
Quick_Stats.php
3 months ago
REST_API.php
3 months ago
Real_Time.php
3 months ago
Report.php
1 year ago
Report_Finder.php
6 months ago
Report_Options_Parser.php
8 months ago
Resource_Identifier.php
8 months ago
Settings.php
3 months ago
Sort_Configuration.php
8 months ago
Tables.php
8 months ago
Track_Resource_Changes.php
1 year ago
View_Counter.php
6 months ago
Views_Over_Time_Finder.php
1 year ago
VisitorSaltRefreshInterval.php
6 months ago
WP_Option_Cache_Bust.php
2 years ago
Chart.php
61 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 $is_preview; |
| 13 | private $is_showing_skeleton_ui; |
| 14 | public function __construct(Statistics $statistics, bool $is_preview = \false, bool $is_showing_skeleton_ui = \false) |
| 15 | { |
| 16 | $this->statistics = $statistics; |
| 17 | $this->is_preview = $is_preview; |
| 18 | $this->is_showing_skeleton_ui = $is_showing_skeleton_ui; |
| 19 | } |
| 20 | public function get_html() : string |
| 21 | { |
| 22 | $options = \IAWP\Dashboard_Options::getInstance(); |
| 23 | $primary_statistic = $this->statistics->get_statistic($options->primary_chart_metric_id()) ?? $this->statistics->get_statistic('visitors'); |
| 24 | $secondary_statistic = \is_string($options->secondary_chart_metric_id()) ? $this->statistics->get_statistic($options->secondary_chart_metric_id()) : null; |
| 25 | // Exception for clicks report |
| 26 | if ($primary_statistic && $primary_statistic->is_invisible()) { |
| 27 | $primary_statistic = $this->statistics->get_statistic('clicks'); |
| 28 | } |
| 29 | // Exception for clicks report |
| 30 | if ($secondary_statistic && $secondary_statistic->is_invisible()) { |
| 31 | $secondary_statistic = null; |
| 32 | } |
| 33 | $labels = \array_map(function ($data_point) { |
| 34 | return Security::json_encode($this->statistics->chart_interval()->get_label_for($data_point[0])); |
| 35 | }, $primary_statistic->statistic_over_time()); |
| 36 | $data = []; |
| 37 | foreach ($this->statistics->get_statistics() as $statistic) { |
| 38 | if ($this->is_showing_skeleton_ui) { |
| 39 | $data[$statistic->id()] = []; |
| 40 | continue; |
| 41 | } |
| 42 | $data[$statistic->id()] = \array_map(function ($data_point) { |
| 43 | return $data_point[1]; |
| 44 | }, $statistic->statistic_over_time()); |
| 45 | } |
| 46 | $total_chart_statistics = 0; |
| 47 | foreach ($this->statistics->get_grouped_statistics() as $group) { |
| 48 | $total_chart_statistics += \count($group['items']); |
| 49 | } |
| 50 | return \IAWPSCOPED\iawp_render('chart', ['chart' => $this, 'intervals' => Intervals::all(), 'current_interval' => $this->statistics->chart_interval(), 'available_datasets' => $this->statistics->get_grouped_statistics(), 'primary_chart_metric_id' => $primary_statistic->id(), 'secondary_chart_metric_id' => \is_null($secondary_statistic) ? null : $secondary_statistic->id(), 'stimulus_values' => ['locale' => \get_bloginfo('language'), 'currency' => \IAWPSCOPED\iawp()->get_currency_code(), 'is-preview' => $this->is_preview() ? '1' : '0', 'disable-dark-mode' => $this->is_preview() ? '1' : '0', 'primary-chart-metric-id' => $primary_statistic->id(), 'primary-chart-metric-name' => $primary_statistic->name(), 'secondary-chart-metric-id' => \is_null($secondary_statistic) ? null : $secondary_statistic->id(), 'secondary-chart-metric-name' => \is_null($secondary_statistic) ? null : $secondary_statistic->name(), 'labels' => $labels, 'data' => $data, 'has-multiple-datasets' => $total_chart_statistics > 1 ? 1 : 0]]); |
| 51 | } |
| 52 | public function is_preview() : bool |
| 53 | { |
| 54 | return $this->is_preview; |
| 55 | } |
| 56 | public function encode_json(array $array) : string |
| 57 | { |
| 58 | return Security::json_encode($array); |
| 59 | } |
| 60 | } |
| 61 |