campaign_builder_controller.js
2 years ago
chart_controller.js
1 year ago
chart_geo_controller.js
2 years ago
chart_interval_controller.js
2 years ago
clipboard_controller.js
2 years ago
copy_report_controller.js
2 years ago
create_report_controller.js
2 years ago
delete_data_controller.js
2 years ago
delete_report_controller.js
2 years ago
easepick_controller.js
2 years 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
migration_redirect_controller.js
2 years ago
modal_controller.js
2 years ago
plugin_group_options_controller.js
1 year ago
pruner_controller.js
1 year ago
quick_stats_controller.js
2 years ago
real_time_controller.js
2 years ago
rename_report_controller.js
2 years ago
report_controller.js
1 year ago
reset_analytics_controller.js
2 years 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
chart_geo_controller.js
65 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static targets = ["chart"] |
| 5 | static values = { |
| 6 | data: Array, |
| 7 | darkMode: Boolean |
| 8 | } |
| 9 | |
| 10 | connect() { |
| 11 | google.charts.load('current', { |
| 12 | 'packages': ['geochart'], |
| 13 | }) |
| 14 | google.charts.setOnLoadCallback(() => { |
| 15 | this.drawChart() |
| 16 | }) |
| 17 | window.addEventListener('resize', this.drawChart) |
| 18 | } |
| 19 | |
| 20 | disconnect() { |
| 21 | window.removeEventListener('resize', this.drawChart) |
| 22 | } |
| 23 | |
| 24 | drawChart = () => { |
| 25 | // Empty the element to fix glitch where chart height wouldn't be resized |
| 26 | this.chartTarget.innerHTML = ''; |
| 27 | |
| 28 | let dataTable = new google.visualization.DataTable(); |
| 29 | |
| 30 | dataTable.addColumn('string', 'country'); |
| 31 | dataTable.addColumn('number', 'views'); |
| 32 | dataTable.addColumn({ |
| 33 | 'type': 'string', |
| 34 | 'role': 'tooltip', |
| 35 | 'p': {'html': true} |
| 36 | }) |
| 37 | |
| 38 | dataTable.addRows(this.dataValue); |
| 39 | |
| 40 | const options = { |
| 41 | displayMode: 'regions', |
| 42 | tooltip: { |
| 43 | isHtml: true, |
| 44 | showTitle: false |
| 45 | }, |
| 46 | backgroundColor: this.darkModeValue ? '#373040' : '#FFFFFF', |
| 47 | datalessRegionColor: this.darkModeValue ? '#695C7A' : undefined, |
| 48 | colorAxis: { |
| 49 | colors: this.darkModeValue ? ['#AC9CC9', '#9E66FF'] : ['#C4ABED', '#5223A0'] |
| 50 | }, |
| 51 | legend: { |
| 52 | numberFormat: `${iawpText.views}: #`, |
| 53 | textStyle: { |
| 54 | color: this.darkModeValue ? '#FFFFFF' : '#000000', |
| 55 | strokeWidth: 0 |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | const chart = new google.visualization.GeoChart(this.chartTarget) |
| 61 | |
| 62 | chart.draw(dataTable, options) |
| 63 | window.iawp_geo_chart = chart |
| 64 | } |
| 65 | } |