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_Geo.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Models\Geo; |
| 6 | class Chart_Geo |
| 7 | { |
| 8 | private $geos; |
| 9 | private $title; |
| 10 | /** |
| 11 | * @param Geo[] $geos |
| 12 | * @param $title |
| 13 | */ |
| 14 | public function __construct(array $geos, $title = null) |
| 15 | { |
| 16 | $this->geos = $geos; |
| 17 | $this->title = $title; |
| 18 | } |
| 19 | public function get_html($unused_visible_datasets = null) |
| 20 | { |
| 21 | $chart_data = \array_map(function ($geo) { |
| 22 | return [$geo->country_code(), $geo->views(), $this->get_tooltip($geo)]; |
| 23 | }, $this->geos); |
| 24 | $dark_mode = \IAWP_SCOPED\iawp()->get_option('iawp_dark_mode', '0'); |
| 25 | \ob_start(); |
| 26 | ?> |
| 27 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
| 28 | <div class="chart-container"> |
| 29 | <div class="chart-inner"> |
| 30 | <div class="legend-container"> |
| 31 | <h2 class="legend-title"><?php |
| 32 | echo $this->title; |
| 33 | ?></h2> |
| 34 | </div> |
| 35 | <div id="myChart" |
| 36 | data-controller="chart-geo" |
| 37 | data-chart-geo-data-value="<?php |
| 38 | \esc_attr_e(\json_encode($chart_data)); |
| 39 | ?>" |
| 40 | data-chart-geo-dark-mode-value="<?php |
| 41 | \esc_attr_e($dark_mode); |
| 42 | ?>"> |
| 43 | <div data-chart-geo-target="chart"></div> |
| 44 | </div> |
| 45 | </div> |
| 46 | </div><?php |
| 47 | $html = \ob_get_contents(); |
| 48 | \ob_end_clean(); |
| 49 | return $html; |
| 50 | } |
| 51 | private function get_tooltip(Models\Geo $geo) : string |
| 52 | { |
| 53 | \ob_start(); |
| 54 | ?> |
| 55 | <div class="iawp-geo-chart-tooltip"> |
| 56 | <?php |
| 57 | echo Icon_Directory_Factory::flags()->find($geo->country_code()); |
| 58 | ?> |
| 59 | <h1><?php |
| 60 | echo $geo->country(); |
| 61 | ?></h1> |
| 62 | <p><span><?php |
| 63 | \_e('Views'); |
| 64 | ?>: </span> <?php |
| 65 | echo \number_format_i18n($geo->views()); |
| 66 | ?></p> |
| 67 | <p><span><?php |
| 68 | \_e('Visitors'); |
| 69 | ?>: </span><?php |
| 70 | echo \number_format_i18n($geo->visitors()); |
| 71 | ?> </p> |
| 72 | <p><span><?php |
| 73 | \_e('Sessions'); |
| 74 | ?>: </span><?php |
| 75 | echo \number_format_i18n($geo->sessions()); |
| 76 | ?> </p> |
| 77 | </div> |
| 78 | <?php |
| 79 | $html = \ob_get_contents(); |
| 80 | \ob_end_clean(); |
| 81 | return $html; |
| 82 | } |
| 83 | } |
| 84 |