lookout-ahoy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +99 -0
- data/Rakefile +24 -0
- data/app/assets/images/lookout/apple-touch-icon.png +0 -0
- data/app/assets/images/lookout/favicon-16x16.png +0 -0
- data/app/assets/images/lookout/favicon-32x32.png +0 -0
- data/app/assets/images/lookout/logo.png +0 -0
- data/app/assets/images/lookout/safari-pinned-tab.png +0 -0
- data/app/assets/images/lookout/safari-pinned-tab.svg +199 -0
- data/app/assets/javascript/lookout/application.js +2 -0
- data/app/assets/javascript/lookout/controllers/application.js +9 -0
- data/app/assets/javascript/lookout/controllers/application_controller.js +33 -0
- data/app/assets/javascript/lookout/controllers/combobox_controller.js +371 -0
- data/app/assets/javascript/lookout/controllers/details_modal_controller.js +18 -0
- data/app/assets/javascript/lookout/controllers/dropdown_label_controller.js +39 -0
- data/app/assets/javascript/lookout/controllers/filter/item_controller.js +12 -0
- data/app/assets/javascript/lookout/controllers/filter_form_controller.js +13 -0
- data/app/assets/javascript/lookout/controllers/filter_modal_controller.js +45 -0
- data/app/assets/javascript/lookout/controllers/frame_link_controller.js +20 -0
- data/app/assets/javascript/lookout/controllers/funnel_chart_controller.js +159 -0
- data/app/assets/javascript/lookout/controllers/index.js +4 -0
- data/app/assets/javascript/lookout/controllers/interval_controller.js +15 -0
- data/app/assets/javascript/lookout/controllers/line_chart_controller.js +251 -0
- data/app/assets/javascript/lookout/controllers/predicate_select_controller.js +10 -0
- data/app/assets/javascript/lookout/controllers/properties_controller.js +8 -0
- data/app/assets/javascript/lookout/controllers/property_filter_controller.js +45 -0
- data/app/assets/javascript/lookout/controllers/realtime_controller.js +30 -0
- data/app/assets/javascript/lookout/controllers/sparkline_controller.js +64 -0
- data/app/assets/javascript/lookout/controllers/tile_controller.js +33 -0
- data/app/assets/javascript/lookout/controllers/toggle_controller.js +17 -0
- data/app/assets/javascript/lookout/helpers/chart_utils.js +156 -0
- data/app/assets/javascript/lookout/helpers/countries.js +2261 -0
- data/app/assets/javascript/lookout/helpers/number_formatters.js +55 -0
- data/app/assets/manifest/lookout/manifest.js +2 -0
- data/app/components/lookout/combobox_component.html.erb +33 -0
- data/app/components/lookout/combobox_component.rb +13 -0
- data/app/components/lookout/comparison_link_component.html.erb +17 -0
- data/app/components/lookout/comparison_link_component.rb +44 -0
- data/app/components/lookout/dropdown_button_component.html.erb +16 -0
- data/app/components/lookout/dropdown_button_component.rb +14 -0
- data/app/components/lookout/dropdown_link_component.html.erb +17 -0
- data/app/components/lookout/dropdown_link_component.rb +19 -0
- data/app/components/lookout/filter/dropdown_component.html.erb +50 -0
- data/app/components/lookout/filter/dropdown_component.rb +51 -0
- data/app/components/lookout/filter/modal_component.html.erb +16 -0
- data/app/components/lookout/filter/modal_component.rb +13 -0
- data/app/components/lookout/filter/select_component.html.erb +25 -0
- data/app/components/lookout/filter/select_component.rb +64 -0
- data/app/components/lookout/filter/tag_component.html.erb +13 -0
- data/app/components/lookout/filter/tag_component.rb +14 -0
- data/app/components/lookout/filter/tag_container_component.html.erb +4 -0
- data/app/components/lookout/filter/tag_container_component.rb +6 -0
- data/app/components/lookout/previous_next_component.html.erb +8 -0
- data/app/components/lookout/previous_next_component.rb +11 -0
- data/app/components/lookout/stats/comparable_container_component.html.erb +25 -0
- data/app/components/lookout/stats/comparable_container_component.rb +103 -0
- data/app/components/lookout/stats/container_component.html.erb +23 -0
- data/app/components/lookout/stats/container_component.rb +28 -0
- data/app/components/lookout/sticky_nav_component.html.erb +32 -0
- data/app/components/lookout/sticky_nav_component.rb +24 -0
- data/app/components/lookout/table_component.html.erb +16 -0
- data/app/components/lookout/table_component.rb +48 -0
- data/app/components/lookout/tables/devices_table_component.rb +11 -0
- data/app/components/lookout/tables/dynamic_table.rb +13 -0
- data/app/components/lookout/tables/dynamic_table_component.rb +207 -0
- data/app/components/lookout/tables/goals_table_component.rb +17 -0
- data/app/components/lookout/tables/header_component.html.erb +6 -0
- data/app/components/lookout/tables/header_component.rb +18 -0
- data/app/components/lookout/tables/headers/header_component.html.erb +5 -0
- data/app/components/lookout/tables/headers/header_component.rb +16 -0
- data/app/components/lookout/tables/properties_table_component.rb +27 -0
- data/app/components/lookout/tables/row_component.html.erb +4 -0
- data/app/components/lookout/tables/rows/row_component.html.erb +6 -0
- data/app/components/lookout/tables/rows/row_component.rb +40 -0
- data/app/components/lookout/tile_component.html.erb +24 -0
- data/app/components/lookout/tile_component.rb +24 -0
- data/app/components/lookout/tooltip_component.html.erb +3 -0
- data/app/components/lookout/tooltip_component.rb +18 -0
- data/app/controllers/lookout/application_controller.rb +83 -0
- data/app/controllers/lookout/campaigns_controller.rb +19 -0
- data/app/controllers/lookout/devices_controller.rb +20 -0
- data/app/controllers/lookout/entry_pages_controller.rb +19 -0
- data/app/controllers/lookout/exit_pages_controller.rb +19 -0
- data/app/controllers/lookout/exports_controller.rb +14 -0
- data/app/controllers/lookout/filters/base_controller.rb +15 -0
- data/app/controllers/lookout/filters/goals_controller.rb +9 -0
- data/app/controllers/lookout/filters/locations_controller.rb +11 -0
- data/app/controllers/lookout/filters/operating_systems/names_controller.rb +13 -0
- data/app/controllers/lookout/filters/operating_systems/versions_controller.rb +13 -0
- data/app/controllers/lookout/filters/pages/actions_controller.rb +13 -0
- data/app/controllers/lookout/filters/pages/entry_pages_controller.rb +14 -0
- data/app/controllers/lookout/filters/pages/exit_pages_controller.rb +15 -0
- data/app/controllers/lookout/filters/properties/names_controller.rb +29 -0
- data/app/controllers/lookout/filters/properties/values_controller.rb +15 -0
- data/app/controllers/lookout/filters/screens_controller.rb +11 -0
- data/app/controllers/lookout/filters/sources_controller.rb +11 -0
- data/app/controllers/lookout/filters/utms_controller.rb +10 -0
- data/app/controllers/lookout/funnels_controller.rb +8 -0
- data/app/controllers/lookout/goals_controller.rb +7 -0
- data/app/controllers/lookout/locations/cities_controller.rb +22 -0
- data/app/controllers/lookout/locations/countries_controller.rb +22 -0
- data/app/controllers/lookout/locations/maps_controller.rb +24 -0
- data/app/controllers/lookout/locations/regions_controller.rb +22 -0
- data/app/controllers/lookout/properties_controller.rb +73 -0
- data/app/controllers/lookout/realtimes_controller.rb +7 -0
- data/app/controllers/lookout/roots_controller.rb +6 -0
- data/app/controllers/lookout/sources_controller.rb +21 -0
- data/app/controllers/lookout/stats/base_controller.rb +148 -0
- data/app/controllers/lookout/stats/bounce_rates_controller.rb +12 -0
- data/app/controllers/lookout/stats/total_pageviews_controller.rb +10 -0
- data/app/controllers/lookout/stats/total_visits_controller.rb +10 -0
- data/app/controllers/lookout/stats/unique_visitors_controller.rb +11 -0
- data/app/controllers/lookout/stats/views_per_visits_controller.rb +11 -0
- data/app/controllers/lookout/stats/visit_durations_controller.rb +10 -0
- data/app/controllers/lookout/stats_controller.rb +7 -0
- data/app/controllers/lookout/top_pages_controller.rb +20 -0
- data/app/decorators/lookout/application_decorator.rb +58 -0
- data/app/decorators/lookout/campaign_decorator.rb +27 -0
- data/app/decorators/lookout/city_decorator.rb +24 -0
- data/app/decorators/lookout/country_decorator.rb +38 -0
- data/app/decorators/lookout/device_decorator.rb +27 -0
- data/app/decorators/lookout/entry_page_decorator.rb +7 -0
- data/app/decorators/lookout/exit_page_decorator.rb +7 -0
- data/app/decorators/lookout/page_decorator.rb +27 -0
- data/app/decorators/lookout/region_decorator.rb +28 -0
- data/app/decorators/lookout/source_decorator.rb +27 -0
- data/app/decorators/lookout/top_page_decorator.rb +7 -0
- data/app/helpers/lookout/application_helper.rb +124 -0
- data/app/models/concerns/lookout/compare_mode.rb +19 -0
- data/app/models/concerns/lookout/limitable.rb +17 -0
- data/app/models/concerns/lookout/range_options.rb +8 -0
- data/app/models/lookout/comparison_mode.rb +72 -0
- data/app/models/lookout/export.rb +48 -0
- data/app/models/lookout/filter_parser.rb +82 -0
- data/app/models/lookout/range_from_params.rb +78 -0
- data/app/models/lookout/rangeable.rb +7 -0
- data/app/models/lookout/widget.rb +15 -0
- data/app/presenters/lookout/dashboard_presenter.rb +53 -0
- data/app/presenters/lookout/funnel_presenter.rb +75 -0
- data/app/presenters/lookout/goals_presenter.rb +72 -0
- data/app/queries/concerns/lookout/comparable_queries.rb +25 -0
- data/app/queries/concerns/lookout/comparable_query.rb +152 -0
- data/app/queries/concerns/lookout/lazy_comparable_query.rb +42 -0
- data/app/queries/lookout/application_query.rb +186 -0
- data/app/queries/lookout/campaign_query.rb +14 -0
- data/app/queries/lookout/city_query.rb +14 -0
- data/app/queries/lookout/country_query.rb +10 -0
- data/app/queries/lookout/device_query.rb +10 -0
- data/app/queries/lookout/entry_pages_query.rb +18 -0
- data/app/queries/lookout/event_query.rb +42 -0
- data/app/queries/lookout/exit_pages_query.rb +19 -0
- data/app/queries/lookout/region_query.rb +14 -0
- data/app/queries/lookout/source_query.rb +11 -0
- data/app/queries/lookout/stats/average_views_per_visit_query.rb +20 -0
- data/app/queries/lookout/stats/average_visit_duration_query.rb +34 -0
- data/app/queries/lookout/stats/base_query.rb +18 -0
- data/app/queries/lookout/stats/bounce_rates_query.rb +33 -0
- data/app/queries/lookout/stats/total_pageviews_query.rb +9 -0
- data/app/queries/lookout/stats/total_visitors_query.rb +9 -0
- data/app/queries/lookout/stats/unique_visitors_query.rb +9 -0
- data/app/queries/lookout/stats/views_per_visit_query.rb +17 -0
- data/app/queries/lookout/stats/visit_duration_query.rb +19 -0
- data/app/queries/lookout/top_page_query.rb +13 -0
- data/app/queries/lookout/visit_query.rb +42 -0
- data/app/views/lookout/campaigns/index.html+details.erb +4 -0
- data/app/views/lookout/campaigns/index.html.erb +3 -0
- data/app/views/lookout/devices/_table.html.erb +2 -0
- data/app/views/lookout/devices/index.html+details.erb +4 -0
- data/app/views/lookout/devices/index.html.erb +3 -0
- data/app/views/lookout/entry_pages/index.html+details.erb +4 -0
- data/app/views/lookout/entry_pages/index.html.erb +3 -0
- data/app/views/lookout/exit_pages/index.html+details.erb +4 -0
- data/app/views/lookout/exit_pages/index.html.erb +3 -0
- data/app/views/lookout/funnels/index.html.erb +7 -0
- data/app/views/lookout/funnels/show.html.erb +15 -0
- data/app/views/lookout/goals/index.html.erb +4 -0
- data/app/views/lookout/layouts/application.html.erb +144 -0
- data/app/views/lookout/layouts/shared/_tile_loader.html.erb +5 -0
- data/app/views/lookout/layouts/shared/_widget_disabled.html+details.erb +3 -0
- data/app/views/lookout/layouts/shared/_widget_disabled.html.erb +3 -0
- data/app/views/lookout/locations/cities/index.html+details.erb +4 -0
- data/app/views/lookout/locations/cities/index.html.erb +3 -0
- data/app/views/lookout/locations/countries/index.html+details.erb +5 -0
- data/app/views/lookout/locations/countries/index.html.erb +3 -0
- data/app/views/lookout/locations/maps/_simple_map.html.erb +26 -0
- data/app/views/lookout/locations/maps/show.html.erb +106 -0
- data/app/views/lookout/locations/regions/index.html+details.erb +4 -0
- data/app/views/lookout/locations/regions/index.html.erb +3 -0
- data/app/views/lookout/properties/_form.html.erb +6 -0
- data/app/views/lookout/properties/index.html.erb +3 -0
- data/app/views/lookout/properties/show.html.erb +6 -0
- data/app/views/lookout/realtimes/show.html.erb +9 -0
- data/app/views/lookout/roots/_filters.html.erb +80 -0
- data/app/views/lookout/roots/show.html.erb +191 -0
- data/app/views/lookout/sources/index.html+details.erb +4 -0
- data/app/views/lookout/sources/index.html.erb +3 -0
- data/app/views/lookout/stats/base/index.html.erb +40 -0
- data/app/views/lookout/stats/show.html.erb +15 -0
- data/app/views/lookout/top_pages/index.html+details.erb +4 -0
- data/app/views/lookout/top_pages/index.html.erb +3 -0
- data/config/routes.rb +69 -0
- data/lib/generators/lookout/install_generator.rb +31 -0
- data/lib/generators/lookout/migration_generator.rb +21 -0
- data/lib/generators/lookout/templates/config.rb.tt +185 -0
- data/lib/generators/lookout/templates/migration.rb.tt +7 -0
- data/lib/lookout/active_record.rb +108 -0
- data/lib/lookout/ahoy/event_methods.rb +75 -0
- data/lib/lookout/ahoy/visit_methods.rb +24 -0
- data/lib/lookout/configuration.rb +58 -0
- data/lib/lookout/database_adapter.rb +168 -0
- data/lib/lookout/engine.rb +47 -0
- data/lib/lookout/filter_configuration/filter.rb +16 -0
- data/lib/lookout/filter_configuration/filter_collection.rb +48 -0
- data/lib/lookout/filters_configuration.rb +77 -0
- data/lib/lookout/funnels.rb +44 -0
- data/lib/lookout/goals.rb +51 -0
- data/lib/lookout/period_collection.rb +115 -0
- data/lib/lookout/predicate_label.rb +7 -0
- data/lib/lookout/railtie.rb +9 -0
- data/lib/lookout/version.rb +3 -0
- data/lib/lookout.rb +78 -0
- metadata +673 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
handleChange(event) {
|
|
5
|
+
const url = new URL(event.target.form.action);
|
|
6
|
+
const interval = event.target.value;
|
|
7
|
+
url.searchParams.set('interval', interval);
|
|
8
|
+
event.target.closest('turbo-frame').src = url.href;
|
|
9
|
+
document.querySelectorAll('a[data-turbo-frame="chart"]').forEach(el => {
|
|
10
|
+
const url = new URL(el.href);
|
|
11
|
+
url.searchParams.set('interval', interval);
|
|
12
|
+
el.href = url.href
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
import { getCSS, externalTooltipHandler, dateFormatter, metricFormatter } from 'helpers/chart_utils';
|
|
3
|
+
|
|
4
|
+
const calculatePercentageDifference = function(oldValue, newValue) {
|
|
5
|
+
if(!oldValue) { return false }
|
|
6
|
+
if (oldValue == 0 && newValue > 0) {
|
|
7
|
+
return 100
|
|
8
|
+
} else if (oldValue == 0 && newValue == 0) {
|
|
9
|
+
return 0
|
|
10
|
+
} else {
|
|
11
|
+
return Math.round((newValue - oldValue) / oldValue * 100)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const footer = (tooltipItems) => {
|
|
16
|
+
let sum = 0;
|
|
17
|
+
|
|
18
|
+
tooltipItems.forEach(function(tooltipItem) {
|
|
19
|
+
sum += tooltipItem.parsed.y;
|
|
20
|
+
});
|
|
21
|
+
return 'Sum: ' + sum;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default class extends Controller {
|
|
25
|
+
static values = {
|
|
26
|
+
current: Object,
|
|
27
|
+
comparedTo: Object,
|
|
28
|
+
interval: String,
|
|
29
|
+
label: String,
|
|
30
|
+
metric: String,
|
|
31
|
+
comparison: String
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
connect() {
|
|
35
|
+
const onClick = (e) => {
|
|
36
|
+
if(drag) { return }
|
|
37
|
+
const element = this.chart.getElementsAtEventForMode(e, 'index', { intersect: false })[0];
|
|
38
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
39
|
+
|
|
40
|
+
searchParams.delete('period')
|
|
41
|
+
searchParams.delete('start_date')
|
|
42
|
+
searchParams.delete('end_date')
|
|
43
|
+
searchParams.delete('compare_to_start_date')
|
|
44
|
+
searchParams.delete('compare_to_end_date')
|
|
45
|
+
searchParams.set('date', Object.keys(this.currentValue)[element.index])
|
|
46
|
+
|
|
47
|
+
Turbo.visit(window.location.pathname + "?" + searchParams.toString())
|
|
48
|
+
}
|
|
49
|
+
const datasets = [
|
|
50
|
+
{
|
|
51
|
+
label: Object.keys(this.currentValue),
|
|
52
|
+
data: Object.values(this.currentValue),
|
|
53
|
+
borderColor: getCSS('--a'),
|
|
54
|
+
backgroundColor: getCSS('--a'),
|
|
55
|
+
color: getCSS('--bc'),
|
|
56
|
+
yAxisID: 'y',
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
if(this.hasComparedToValue) {
|
|
61
|
+
datasets.push({
|
|
62
|
+
label: Object.keys(this.comparedToValue),
|
|
63
|
+
data: Object.values(this.comparedToValue),
|
|
64
|
+
borderColor: getCSS('--s', 0.8),
|
|
65
|
+
backgroundColor: getCSS('--s', 0.8),
|
|
66
|
+
color: getCSS('--bc'),
|
|
67
|
+
yAxisID: 'yComparison',
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const calculateMaximumY = function(dataset) {
|
|
72
|
+
if (dataset) {
|
|
73
|
+
return Math.max(Object.values(dataset))
|
|
74
|
+
} else {
|
|
75
|
+
return 1
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const typeForDate = this.comparisonValue === 'year' ? 'long' : "short"
|
|
80
|
+
const options = {
|
|
81
|
+
type: 'line',
|
|
82
|
+
data: {
|
|
83
|
+
labels: Object.keys(this.currentValue),
|
|
84
|
+
datasets: datasets
|
|
85
|
+
},
|
|
86
|
+
options: {
|
|
87
|
+
onClick: onClick,
|
|
88
|
+
responsive: true,
|
|
89
|
+
maintainAspectRatio: false,
|
|
90
|
+
interaction: {
|
|
91
|
+
intersect: false,
|
|
92
|
+
mode: 'index',
|
|
93
|
+
},
|
|
94
|
+
plugins: {
|
|
95
|
+
legend: false,
|
|
96
|
+
tooltip: {
|
|
97
|
+
enabled: false,
|
|
98
|
+
position: 'nearest',
|
|
99
|
+
external: externalTooltipHandler(this)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
scales: {
|
|
103
|
+
y: {
|
|
104
|
+
min: 0,
|
|
105
|
+
suggestedMax: calculateMaximumY(this.currentValue),
|
|
106
|
+
ticks: {
|
|
107
|
+
},
|
|
108
|
+
grid: {
|
|
109
|
+
zeroLineColor: 'transparent',
|
|
110
|
+
drawBorder: false,
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
yComparison: {
|
|
114
|
+
min: 0,
|
|
115
|
+
suggestedMax: calculateMaximumY(this.currentValue),
|
|
116
|
+
display: false,
|
|
117
|
+
grid: { display: false },
|
|
118
|
+
},
|
|
119
|
+
x: {
|
|
120
|
+
ticks: {
|
|
121
|
+
grid: { display: false },
|
|
122
|
+
|
|
123
|
+
color: getCSS('--bc'),
|
|
124
|
+
callback: (val, idx) => {
|
|
125
|
+
if(idx % 2 == 0) {
|
|
126
|
+
const date = Object.keys(this.currentValue)[val];
|
|
127
|
+
return dateFormatter[this.intervalValue](date, typeForDate)
|
|
128
|
+
} else {
|
|
129
|
+
return ""
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
elements: {
|
|
137
|
+
point: {
|
|
138
|
+
radius: 0
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
this.chart = new Chart(this.element, options);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
var canvas = this.element;
|
|
147
|
+
var overlay = document.getElementById('overlay');
|
|
148
|
+
var startIndex = 0;
|
|
149
|
+
overlay.width = canvas.width;
|
|
150
|
+
overlay.height = canvas.height;
|
|
151
|
+
var selectionContext = overlay.getContext('2d');
|
|
152
|
+
var selectionRect = {
|
|
153
|
+
w: 0,
|
|
154
|
+
startX: 0,
|
|
155
|
+
startY: 0
|
|
156
|
+
};
|
|
157
|
+
var drag = false;
|
|
158
|
+
canvas.addEventListener('pointerdown', evt => {
|
|
159
|
+
const points = this.chart.getElementsAtEventForMode(evt, 'index', {
|
|
160
|
+
intersect: false
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
startIndex = points[0].index;
|
|
164
|
+
const rect = canvas.getBoundingClientRect();
|
|
165
|
+
selectionRect.startX = evt.clientX - rect.left;
|
|
166
|
+
selectionRect.startY = this.chart.chartArea.top;
|
|
167
|
+
drag = true;
|
|
168
|
+
});
|
|
169
|
+
canvas.addEventListener('pointermove', evt => {
|
|
170
|
+
const rect = canvas.getBoundingClientRect();
|
|
171
|
+
if (drag) {
|
|
172
|
+
|
|
173
|
+
const rect = canvas.getBoundingClientRect();
|
|
174
|
+
selectionContext.fillStyle = getCSS('--p')
|
|
175
|
+
selectionRect.w = (evt.clientX - rect.left) - selectionRect.startX;
|
|
176
|
+
selectionContext.globalAlpha = 0.5;
|
|
177
|
+
selectionContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
178
|
+
selectionContext.fillRect(selectionRect.startX,
|
|
179
|
+
selectionRect.startY,
|
|
180
|
+
selectionRect.w,
|
|
181
|
+
this.chart.chartArea.bottom - this.chart.chartArea.top);
|
|
182
|
+
} else {
|
|
183
|
+
selectionContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
184
|
+
var x = evt.clientX - rect.left;
|
|
185
|
+
if (x > this.chart.chartArea.left) {
|
|
186
|
+
selectionContext.fillStyle = getCSS('--p')
|
|
187
|
+
selectionContext.fillRect(x,
|
|
188
|
+
this.chart.chartArea.top,
|
|
189
|
+
1,
|
|
190
|
+
this.chart.chartArea.bottom - this.chart.chartArea.top);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
canvas.addEventListener('pointerup', evt => {
|
|
195
|
+
const points = this.chart.getElementsAtEventForMode(evt, 'index', {
|
|
196
|
+
intersect: false
|
|
197
|
+
});
|
|
198
|
+
const dates = [options.data.labels[startIndex], options.data.labels[points[0].index]].sort()
|
|
199
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
200
|
+
searchParams.set('start_date', dates[0])
|
|
201
|
+
searchParams.set('end_date', dates[1])
|
|
202
|
+
searchParams.delete('period')
|
|
203
|
+
searchParams.delete('compare_to_start_date')
|
|
204
|
+
searchParams.delete('compare_to_end_date')
|
|
205
|
+
Turbo.visit(window.location.pathname + "?" + searchParams.toString())
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
formatLabel(label) {
|
|
210
|
+
return dateFormatter[this.intervalValue](label, 'long')
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
formatMetric(value) {
|
|
214
|
+
return metricFormatter[this.metricValue](value)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
resize() { this.chart.resize() };
|
|
218
|
+
|
|
219
|
+
extractTooltipData(tooltip) {
|
|
220
|
+
const data = this.chart.config.data.datasets.find((set) => set.yAxisID == "y")
|
|
221
|
+
const comparisonData = this.chart.config.data.datasets.find((set) => set.yAxisID == "yComparison");
|
|
222
|
+
const dataIndex = this.chart.config.data.datasets.indexOf(data)
|
|
223
|
+
const comparisonDataIndex = this.chart.config.data.datasets.indexOf(comparisonData);
|
|
224
|
+
|
|
225
|
+
const tooltipData = tooltip.dataPoints.find((dataPoint) => dataPoint.datasetIndex == dataIndex)
|
|
226
|
+
const label = data.label[tooltipData.dataIndex];
|
|
227
|
+
let comparisonLabel = false
|
|
228
|
+
let comparisonValue = false
|
|
229
|
+
let comparisonLabelBackgroundColor = false
|
|
230
|
+
if(this.hasComparedToValue) {
|
|
231
|
+
const tooltipComparisonData = tooltip.dataPoints.find((dataPoint) => dataPoint.datasetIndex == comparisonDataIndex);
|
|
232
|
+
comparisonLabel = comparisonData.label[tooltipComparisonData.dataIndex];
|
|
233
|
+
comparisonValue = tooltip.dataPoints.find((dataPoint) => dataPoint.datasetIndex == comparisonDataIndex)?.raw || 0
|
|
234
|
+
comparisonLabelBackgroundColor = comparisonData.backgroundColor
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const value = tooltip.dataPoints.find((dataPoint) => dataPoint.datasetIndex == dataIndex)?.raw || 0
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
comparison: this.hasComparedToValue,
|
|
241
|
+
comparisonDifference: calculatePercentageDifference(comparisonValue, value),
|
|
242
|
+
metric: this.labelValue,
|
|
243
|
+
label: this.formatLabel(label),
|
|
244
|
+
labelBackgroundColor: data.backgroundColor,
|
|
245
|
+
formattedValue: this.formatMetric(value),
|
|
246
|
+
comparisonLabel: this.formatLabel(comparisonLabel),
|
|
247
|
+
comparisonLabelBackgroundColor: comparisonLabelBackgroundColor,
|
|
248
|
+
formattedComparisonValue: this.formatMetric(comparisonValue)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["select"]
|
|
5
|
+
|
|
6
|
+
handleChange(event) {
|
|
7
|
+
this.selectTarget.dataset.predicate = event.target.value
|
|
8
|
+
this.selectTarget.name = event.target.value
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ['name', 'value'];
|
|
5
|
+
|
|
6
|
+
connect() {
|
|
7
|
+
this.init = this.init.bind(this)
|
|
8
|
+
|
|
9
|
+
const interval = setInterval(() => {
|
|
10
|
+
if(window.comboboxConnected === 2) {
|
|
11
|
+
clearInterval(interval);
|
|
12
|
+
this.init()
|
|
13
|
+
}
|
|
14
|
+
}, 100)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init() {
|
|
18
|
+
|
|
19
|
+
if(this.nameTarget.value) {
|
|
20
|
+
this.valueTarget.combobox.element.dataset.comboboxQueryValue = `q[properties.${this.nameTarget.value}_i_cont]`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.nameTarget.addEventListener("change", (event) => {
|
|
24
|
+
if(event.target.value) {
|
|
25
|
+
event.target.dataset.column = event.target.value;
|
|
26
|
+
this.valueTarget.combobox.element.dataset.comboboxQueryValue = `q[properties.${event.target.value}_i_cont]`
|
|
27
|
+
this.valueTarget.combobox.setDisabled(false)
|
|
28
|
+
this.valueTarget.combobox.isOpenValue = false
|
|
29
|
+
} else {
|
|
30
|
+
this.valueTarget.combobox.setSelected([])
|
|
31
|
+
this.valueTarget.combobox.setDisabled(true)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
this.valueTarget.addEventListener("change", (event) => {
|
|
35
|
+
if(event.target.value.length > 0) {
|
|
36
|
+
this.valueTarget.name = `q[properties.${this.nameTarget.dataset.column}_in]`
|
|
37
|
+
} else {
|
|
38
|
+
this.valueTarget.name = null
|
|
39
|
+
this.valueTarget.combobox.element.dataset.comboboxQueryValue = ""
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ['label'];
|
|
5
|
+
static values = {
|
|
6
|
+
interval: Number
|
|
7
|
+
}
|
|
8
|
+
connect() {
|
|
9
|
+
this.reload = this.reload.bind(this);
|
|
10
|
+
this.setLabel = this.setLabel.bind(this);
|
|
11
|
+
this.labelCount = 0;
|
|
12
|
+
this.reloadInterval = setInterval(this.reload, 1000 * this.intervalValue);
|
|
13
|
+
this.labelInterval = setInterval(this.setLabel, 1000);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
reload() {
|
|
17
|
+
this.element.reload();
|
|
18
|
+
this.labelCount = 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setLabel() {
|
|
22
|
+
this.labelTarget.title = `Last updated ${this.labelCount} seconds ago`;
|
|
23
|
+
this.labelCount += 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
disconnect() {
|
|
27
|
+
clearInterval(this.labelInterval);
|
|
28
|
+
clearInterval(this.reloadInterval);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static values = {
|
|
5
|
+
data: Array,
|
|
6
|
+
label: String
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
connect() {
|
|
10
|
+
// Wait for Chart.js to be available
|
|
11
|
+
if (typeof Chart === 'undefined') {
|
|
12
|
+
console.error('Chart.js not loaded for sparkline:', this.labelValue);
|
|
13
|
+
// Try again after a short delay
|
|
14
|
+
setTimeout(() => this.renderChart(), 100);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.renderChart();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
renderChart() {
|
|
22
|
+
if (typeof Chart === 'undefined') {
|
|
23
|
+
console.error('Chart.js still not available for:', this.labelValue);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
// Generate sample trend data (in production, pass real data via data-sparkline-data-value)
|
|
29
|
+
const data = this.hasDataValue ? this.dataValue : Array.from({length: 7}, () => Math.random() * 100);
|
|
30
|
+
|
|
31
|
+
new Chart(this.element.getContext('2d'), {
|
|
32
|
+
type: 'line',
|
|
33
|
+
data: {
|
|
34
|
+
labels: data.map((_, i) => i),
|
|
35
|
+
datasets: [{
|
|
36
|
+
data: data,
|
|
37
|
+
borderColor: 'rgba(99, 102, 241, 0.8)',
|
|
38
|
+
backgroundColor: 'rgba(99, 102, 241, 0.1)',
|
|
39
|
+
borderWidth: 2,
|
|
40
|
+
fill: true,
|
|
41
|
+
tension: 0.4,
|
|
42
|
+
pointRadius: 0
|
|
43
|
+
}]
|
|
44
|
+
},
|
|
45
|
+
options: {
|
|
46
|
+
responsive: true,
|
|
47
|
+
maintainAspectRatio: false,
|
|
48
|
+
plugins: {
|
|
49
|
+
legend: { display: false },
|
|
50
|
+
tooltip: { enabled: false }
|
|
51
|
+
},
|
|
52
|
+
scales: {
|
|
53
|
+
x: { display: false },
|
|
54
|
+
y: { display: false }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
console.log('Sparkline created for:', this.labelValue);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error('Error creating sparkline for', this.labelValue, ':', e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["title"]
|
|
5
|
+
connect() {
|
|
6
|
+
this.frame = this.element.querySelector('turbo-frame');
|
|
7
|
+
const targetNode = this.frame;
|
|
8
|
+
const config = { attributes: true };
|
|
9
|
+
|
|
10
|
+
const callback = (mutationList, observer) => {
|
|
11
|
+
for (const mutation of mutationList) {
|
|
12
|
+
if (mutation.type === "attributes") {
|
|
13
|
+
this.handleFrameLoad(mutation.attributeName)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const observer = new MutationObserver(callback);
|
|
19
|
+
observer.observe(targetNode, config);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
handleFrameLoad(status) {
|
|
23
|
+
if(!this.frame.hasAttribute('skeleton')) {
|
|
24
|
+
if(status === 'busy') {
|
|
25
|
+
this.frame.innerHTML = document.querySelector('#tile-loader-template').innerHTML;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setTitle(event) {
|
|
31
|
+
this.titleTarget.innerHTML = event.target.title || event.target.text
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// Connects to data-controller="toggle"
|
|
4
|
+
export default class extends Controller {
|
|
5
|
+
static targets = ['toggleable'];
|
|
6
|
+
static values = {
|
|
7
|
+
enable: Boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
trigger() {
|
|
11
|
+
if (this.enableValue) {
|
|
12
|
+
this.toggleableTargets.forEach(element => {
|
|
13
|
+
element.classList.toggle('hidden');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { numberFormatter, durationFormatter, percentageFormatter } from "helpers/number_formatters";
|
|
2
|
+
|
|
3
|
+
export const getCSS = (varname, alpha = 1) => {
|
|
4
|
+
const value = getComputedStyle(document.documentElement).getPropertyValue(varname);
|
|
5
|
+
if(value.includes("em") || value.includes("px")) {
|
|
6
|
+
return value
|
|
7
|
+
}
|
|
8
|
+
return `hsl(${getComputedStyle(document.documentElement).getPropertyValue(varname)} / ${alpha})`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const buildTooltipData = (controller, tooltip) => {
|
|
12
|
+
return controller.extractTooltipData(tooltip)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const metricFormatter = {
|
|
16
|
+
"ActiveSupport::Duration": durationFormatter,
|
|
17
|
+
"BigDecimal": numberFormatter,
|
|
18
|
+
"Float": percentageFormatter,
|
|
19
|
+
"Integer": numberFormatter
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const dateFormatter = {
|
|
23
|
+
month: (value, type = 'short') => {
|
|
24
|
+
if(type === 'short') {
|
|
25
|
+
return new Date(value).toLocaleString(
|
|
26
|
+
'en-US',
|
|
27
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
|
28
|
+
)
|
|
29
|
+
} else {
|
|
30
|
+
return new Date(value).toLocaleString(
|
|
31
|
+
'en-US',
|
|
32
|
+
{ year: "numeric", month: 'short', day: 'numeric', hour: 'numeric' }
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
week: (value, type = 'short') => {
|
|
37
|
+
return new Date(value).toLocaleString(
|
|
38
|
+
'en-US',
|
|
39
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
|
40
|
+
)
|
|
41
|
+
},
|
|
42
|
+
day: (value, type = 'short') => {
|
|
43
|
+
return new Date(value).toLocaleString(
|
|
44
|
+
'en-US',
|
|
45
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
|
46
|
+
)
|
|
47
|
+
},
|
|
48
|
+
hour: (value, type = 'short') => {
|
|
49
|
+
if(type == 'long') {
|
|
50
|
+
return new Date(value).toLocaleString(
|
|
51
|
+
'en-US',
|
|
52
|
+
{ year: 'numeric', hour: 'numeric' }
|
|
53
|
+
)
|
|
54
|
+
} else {
|
|
55
|
+
return new Date(value).toLocaleString(
|
|
56
|
+
'en-US',
|
|
57
|
+
{ hour: 'numeric' }
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
minute: (value, type = 'short') => {
|
|
62
|
+
if(type == 'short') {
|
|
63
|
+
return new Date(value).toLocaleString(
|
|
64
|
+
'en-US',
|
|
65
|
+
{ minute: 'numeric', hour: 'numeric' }
|
|
66
|
+
)
|
|
67
|
+
} else {
|
|
68
|
+
return new Date(value).toLocaleString(
|
|
69
|
+
'en-US',
|
|
70
|
+
{ year: 'numeric', minute: 'numeric', hour: 'numeric' }
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const externalTooltipHandler = (controller) => {
|
|
77
|
+
|
|
78
|
+
return ({chart, tooltip}) => {
|
|
79
|
+
const offset = controller.chart.canvas.getBoundingClientRect()
|
|
80
|
+
let tooltipEl = document.getElementById('chartjs-tooltip')
|
|
81
|
+
|
|
82
|
+
if (!tooltipEl) {
|
|
83
|
+
tooltipEl = document.createElement('div')
|
|
84
|
+
tooltipEl.id = 'chartjs-tooltip'
|
|
85
|
+
tooltipEl.style.background = getCSS('--n', );
|
|
86
|
+
tooltipEl.style.borderRadius = getCSS('--rounded-btn');
|
|
87
|
+
tooltipEl.style.opacity = 1;
|
|
88
|
+
tooltipEl.style.pointerEvents = 'none';
|
|
89
|
+
tooltipEl.style.position = 'absolute';
|
|
90
|
+
tooltipEl.style.transform = 'translate(-50%, 50%)';
|
|
91
|
+
tooltipEl.style.transition = 'all .1s ease';
|
|
92
|
+
tooltipEl.style.minWidth = '250px'
|
|
93
|
+
|
|
94
|
+
chart.canvas.parentNode.appendChild(tooltipEl);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (tooltipEl && offset && window.innerWidth < 768) {
|
|
98
|
+
tooltipEl.style.top = offset.y + offset.height + window.scrollY + 15 + 'px'
|
|
99
|
+
tooltipEl.style.left = offset.x + 'px'
|
|
100
|
+
tooltipEl.style.right = null
|
|
101
|
+
tooltipEl.style.opacity = 1
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (tooltip.opacity === 0) {
|
|
105
|
+
tooltipEl.style.display = 'none'
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (tooltip.body) {
|
|
110
|
+
const tooltipData = buildTooltipData(controller, tooltip)
|
|
111
|
+
|
|
112
|
+
tooltipEl.innerHTML = `
|
|
113
|
+
<aside class="flex flex-col text-neutral-content">
|
|
114
|
+
<div class="flex justify-between items-center">
|
|
115
|
+
<span class="text-sm font-bold uppercase whitespace-nowrap flex mr-4">${tooltipData.metric}</span>
|
|
116
|
+
${tooltipData.comparison && tooltipData.comparisonDifference ?
|
|
117
|
+
`<div class="inline-flex items-center space-x-1">
|
|
118
|
+
${tooltipData.comparisonDifference > 0 ? `<span class="font-semibold text-sm text-green-500">↑</span><span>${tooltipData.comparisonDifference}%</span>` : ""}
|
|
119
|
+
${tooltipData.comparisonDifference < 0 ? `<span class="font-semibold text-sm text-red-400">↓</span><span>${tooltipData.comparisonDifference * -1}%</span>` : ""}
|
|
120
|
+
${tooltipData.comparisonDifference == 0 ? `<span class="font-semibold text-sm">〰 0%</span>` : ""}
|
|
121
|
+
</div>` : ''}
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
${tooltipData.label ?
|
|
125
|
+
`<div class="flex flex-col">
|
|
126
|
+
<div class="flex flex-row justify-between items-center">
|
|
127
|
+
<span class="badge relative badge-xs" style="background-color: ${tooltipData.labelBackgroundColor}"></span>
|
|
128
|
+
<span class="flex items-center grow ml-4 mr-4">
|
|
129
|
+
<span>${tooltipData.label}</span>
|
|
130
|
+
</span>
|
|
131
|
+
<span class="font-bold">${tooltipData.formattedValue}</span>
|
|
132
|
+
</div>` : ''}
|
|
133
|
+
|
|
134
|
+
${tooltipData.comparison ?
|
|
135
|
+
`<div class="flex flex-row justify-between items-center">
|
|
136
|
+
<span class="badge relative badge-xs" style="background-color: ${tooltipData.comparisonLabelBackgroundColor}"></span>
|
|
137
|
+
<span class="flex items-center grow ml-4 mr-4">
|
|
138
|
+
<span>${tooltipData.comparisonLabel}</span>
|
|
139
|
+
</span>
|
|
140
|
+
<span class="font-bold">${tooltipData.formattedComparisonValue}</span>
|
|
141
|
+
</div>` : ""}
|
|
142
|
+
</div>
|
|
143
|
+
</aside>
|
|
144
|
+
`
|
|
145
|
+
}
|
|
146
|
+
const {offsetLeft: positionX, offsetTop: positionY} = chart.canvas;
|
|
147
|
+
|
|
148
|
+
// Display, position, and set styles for font
|
|
149
|
+
tooltipEl.style.opacity = 1;
|
|
150
|
+
tooltipEl.style.display = null;
|
|
151
|
+
tooltipEl.style.left = positionX + tooltip._eventPosition.x + 'px';
|
|
152
|
+
tooltipEl.style.top = positionY + tooltip._eventPosition.y + 'px';
|
|
153
|
+
tooltipEl.style.font = tooltip.options.bodyFont.string;
|
|
154
|
+
tooltipEl.style.padding = tooltip.options.padding + 'px ' + tooltip.options.padding + 'px';
|
|
155
|
+
}
|
|
156
|
+
};
|