ajax
3 years ago
databases
3 years ago
migrations
3 years ago
models
3 years ago
queries
3 years ago
utils
3 years ago
chart.php
3 years ago
chart_geo.php
3 years ago
dashboard_widget.php
3 years ago
db.php
3 years ago
filters.php
3 years ago
freemius.php
3 years ago
independent_analytics.php
3 years ago
known_referrers.php
3 years ago
quick_stats.php
3 years ago
rest_api.php
3 years ago
settings.php
3 years ago
table.php
3 years ago
table_geo.php
3 years ago
table_referrers.php
3 years ago
table_views.php
3 years ago
track_resource_changes.php
3 years ago
view_counter.php
3 years ago
chart.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Chart |
| 6 | { |
| 7 | private $views; |
| 8 | private $title; |
| 9 | |
| 10 | public function __construct($views, $title = null) |
| 11 | { |
| 12 | $this->views = $views; |
| 13 | $this->title = $title; |
| 14 | } |
| 15 | |
| 16 | public function get_html() |
| 17 | { |
| 18 | if (is_null($this->title)) { |
| 19 | $title = esc_html__('Last 30 Days', 'iawp'); |
| 20 | } else { |
| 21 | $title = $this->title; |
| 22 | } |
| 23 | |
| 24 | $labels = array_map(function ($data_point) { |
| 25 | return $data_point[0]->format('M j - l'); |
| 26 | }, $this->views->daily_views()); |
| 27 | |
| 28 | $views_data = array_map(function ($data_point) { |
| 29 | return $data_point[1]; |
| 30 | }, $this->views->daily_views()); |
| 31 | |
| 32 | $visitors_data = array_map(function ($data_point) { |
| 33 | return $data_point[1]; |
| 34 | }, $this->views->daily_visitors()); |
| 35 | |
| 36 | return $this->chart_html($labels, $views_data, $visitors_data, $title); |
| 37 | } |
| 38 | |
| 39 | private function chart_html(array $labels, array $views, array $visitors, $title) |
| 40 | { |
| 41 | // Todo - Bring tick color into the stimulus controller below |
| 42 | $tick_color = get_option('iawp_dark_mode') ? '#ffffff' : '#555555'; |
| 43 | ob_start(); ?> |
| 44 | <div class="chart-container"> |
| 45 | <div class="chart-inner"> |
| 46 | <div class="legend-container"> |
| 47 | <h2 class="legend-title"><?php echo $title ?></h2> |
| 48 | <div id="legend-container"></div> |
| 49 | </div> |
| 50 | <canvas id="myChart" |
| 51 | width="800" |
| 52 | height="200" |
| 53 | data-controller="chart" |
| 54 | data-chart-mode-value='<?php echo get_option('iawp_dark_mode') ? 'dark' : 'light' ?>' |
| 55 | data-chart-labels-value='<?php echo Security::json_encode($labels) ?>' |
| 56 | data-chart-views-value='<?php echo Security::json_encode($views) ?>' |
| 57 | data-chart-visitors-value='<?php echo Security::json_encode($visitors) ?>' |
| 58 | > |
| 59 | </canvas> |
| 60 | </div> |
| 61 | </div><?php |
| 62 | |
| 63 | $html = ob_get_contents(); |
| 64 | ob_end_clean(); |
| 65 | |
| 66 | return $html; |
| 67 | } |
| 68 | } |
| 69 |