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