PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.11.4
Independent Analytics – WordPress Analytics Plugin v2.11.4
2.15.5 2.15.4 2.15.3 2.15.2 2.15.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 / javascript-source / controllers / map_controller.js
independent-analytics / javascript-source / controllers Last commit date
overview 1 year ago campaign_builder_controller.js 1 year ago chart_controller.js 1 year ago chart_interval_controller.js 2 years ago clipboard_controller.js 1 year ago copy_report_controller.js 2 years ago create_report_controller.js 1 year ago delete_data_controller.js 1 year ago delete_report_controller.js 2 years ago easepick_controller.js 2 years ago export_overview_controller.js 1 year ago export_reports_controller.js 2 years ago filters_controller.js 1 year ago group_controller.js 2 years ago import_reports_controller.js 2 years ago map_controller.js 1 year ago migration_redirect_controller.js 2 years ago modal_controller.js 2 years ago pie_chart_controller.js 1 year ago plugin_group_options_controller.js 1 year ago pruner_controller.js 1 year ago quick_stats_controller.js 1 year ago real_time_controller.js 1 year ago refresh_overview_controller.js 1 year ago rename_report_controller.js 2 years ago report_controller.js 1 year ago reset_analytics_controller.js 1 year ago reset_overview_controller.js 1 year ago save_report_controller.js 2 years ago select_input_controller.js 2 years ago set_favorite_report_controller.js 2 years ago sort_controller.js 2 years ago sortable_reports_controller.js 2 years ago table_columns_controller.js 2 years ago woocommerce_settings_controller.js 1 year ago
map_controller.js
129 lines
1 import {Controller} from "@hotwired/stimulus"
2 import {isDarkMode} from "../utils/appearance";
3
4 export default class extends Controller {
5 static targets = ["chart"]
6 static values = {
7 data: Array,
8 flagsUrl: String,
9 locale: String
10 }
11
12 mapInstance = null
13
14 connect() {
15 this.resizeObserver = new ResizeObserver(() => {
16 this.drawChart()
17 });
18
19 google.charts.load('current', {
20 'packages': ['geochart'],
21 })
22
23 google.charts.setOnLoadCallback(() => {
24 this.drawChart()
25 this.resizeObserver.observe(this.element);
26 })
27 }
28
29 disconnect() {
30 this.resizeObserver.disconnect();
31 window.mapInstances = window.mapInstances.filter(mapInstance => {
32 return mapInstance !== this.mapInstance
33 })
34 }
35
36 drawChart = () => {
37 // Empty the element to fix glitch where chart height wouldn't be resized
38 this.chartTarget.innerHTML = '';
39
40 // Remove the map
41 if(this.mapInstance) {
42 const index = window.mapInstances.indexOf(this.mapInstance);
43
44 if(index > -1) {
45 window.mapInstances.splice(index, 1)
46 }
47 }
48
49 let dataTable = new google.visualization.DataTable();
50
51 dataTable.addColumn('string', 'country');
52 dataTable.addColumn('number', 'views');
53 dataTable.addColumn({
54 'type': 'string',
55 'role': 'tooltip',
56 'p': {'html': true}
57 })
58
59 dataTable.addRows(
60 this.convertCountryDataToRows(this.dataValue)
61 );
62
63 const options = {
64 displayMode: 'regions',
65 tooltip: {
66 isHtml: true,
67 showTitle: false
68 },
69 backgroundColor: isDarkMode() ? '#373040' : '#FFFFFF',
70 datalessRegionColor: isDarkMode() ? '#695C7A' : undefined,
71 colorAxis: {
72 colors: isDarkMode() ? ['#AC9CC9', '#9E66FF'] : ['#C4ABED', '#5223A0']
73 },
74 legend: {
75 numberFormat: `${iawpText.views}: #`,
76 textStyle: {
77 color: isDarkMode() ? '#FFFFFF' : '#000000',
78 strokeWidth: 0
79 }
80 },
81 }
82
83 const map = new google.visualization.GeoChart(this.chartTarget)
84
85 map.draw(dataTable, options)
86
87 if(!window.mapInstances) {
88 window.mapInstances = []
89 }
90
91 this.mapInstance = map
92 window.mapInstances.push(map)
93 }
94
95 convertCountryDataToRows(countryData) {
96 return countryData.map(country => {
97 return [
98 country.country_code,
99 country.views,
100 this.getTooltipMarkup(country)
101 ]
102 })
103 }
104
105 getTooltipMarkup(country) {
106 const formatted_views = this.formatNumber(country['views'])
107 const formatted_visitors = this.formatNumber(country['visitors'])
108 const formatted_sessions = this.formatNumber(country['sessions'])
109 const flagUrl = this.flagsUrlValue + '/' + country['country_code'].toLowerCase() + '.svg'
110
111 return `
112 <div class="iawp-geo-chart-tooltip">
113 <img src="${flagUrl}" alt="Country flag"/>
114 <h1>${country['country']}</h1>
115 <p><span>${iawpText.views}: </span>${formatted_views}</p>
116 <p><span>${iawpText.visitors}: </span>${formatted_visitors}</p>
117 <p><span>${iawpText.sessions}: </span>${formatted_sessions}</p>
118 </div>
119 `;
120
121 return title.outerHTML
122 }
123
124 formatNumber(number) {
125 return new Intl.NumberFormat(this.localeValue, {
126 maximumFractionDigits: 0
127 }).format(number);
128 }
129 }