2022-03-22 18:37:17 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-23 18:38:16 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-22 18:37:17 +03:00
|
|
|
|
|
|
|
export default class ChartEmailOpenRate extends Component {
|
2022-03-23 18:38:16 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you need to fetch new data from the server. In this component, it will get called
|
|
|
|
* when the days parameter changes and on initialisation.
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
loadCharts() {
|
|
|
|
// The dashboard stats service will take care or reusing and limiting API-requests between charts
|
|
|
|
this.dashboardStats.loadNewsletterSubscribers();
|
|
|
|
this.dashboardStats.loadEmailsSent();
|
|
|
|
this.dashboardStats.loadEmailOpenRateStats();
|
|
|
|
}
|
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
get dataSubscribers() {
|
2022-03-23 18:38:16 +03:00
|
|
|
// @todo: show paid, free, total together
|
2022-03-28 14:19:56 +03:00
|
|
|
return this.dashboardStats.newsletterSubscribers ?? {
|
|
|
|
total: 0,
|
|
|
|
free: 0,
|
|
|
|
paid: 0
|
|
|
|
};
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get dataEmailsSent() {
|
2022-03-23 18:38:16 +03:00
|
|
|
return this.dashboardStats.emailsSent30d ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
return this.dashboardStats.emailOpenRateStats === null;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartType() {
|
|
|
|
return 'bar';
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartData() {
|
2022-03-28 14:49:44 +03:00
|
|
|
const stats = this.dashboardStats.emailOpenRateStats;
|
2022-03-28 15:20:07 +03:00
|
|
|
const labels = stats.map(stat => stat.subject);
|
|
|
|
const data = stats.map(stat => stat.openRate);
|
2022-03-23 18:38:16 +03:00
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
return {
|
2022-03-23 18:38:16 +03:00
|
|
|
labels,
|
2022-03-22 18:37:17 +03:00
|
|
|
datasets: [{
|
2022-03-23 18:38:16 +03:00
|
|
|
data,
|
2022-03-22 18:37:17 +03:00
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#14b8ff',
|
2022-03-29 18:53:50 +03:00
|
|
|
tension: 0.1,
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 10,
|
|
|
|
borderColor: '#14b8ff',
|
|
|
|
borderJoinStyle: 'miter',
|
|
|
|
maxBarThickness: 20,
|
|
|
|
minBarLength: 2
|
2022-03-22 18:37:17 +03:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartOptions() {
|
|
|
|
return {
|
2022-03-29 18:53:50 +03:00
|
|
|
title: {
|
|
|
|
display: false
|
|
|
|
},
|
2022-03-22 18:37:17 +03:00
|
|
|
legend: {
|
|
|
|
display: false
|
2022-03-29 18:53:50 +03:00
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
gridLines: {
|
|
|
|
drawTicks: false,
|
|
|
|
display: false,
|
|
|
|
drawBorder: false
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
fontColor: '#7C8B9A',
|
|
|
|
padding: 8,
|
|
|
|
precision: 0
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
xAxes: [{
|
|
|
|
gridLines: {
|
|
|
|
drawTicks: false,
|
|
|
|
display: false,
|
|
|
|
drawBorder: false
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
autoSkip: true,
|
|
|
|
maxRotation: 0,
|
|
|
|
minRotation: 0
|
|
|
|
}
|
|
|
|
}]
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartHeight() {
|
2022-03-29 18:53:50 +03:00
|
|
|
return 175;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
}
|