2022-04-20 15:43:11 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import moment from 'moment';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
const DATE_FORMAT = 'D MMM';
|
|
|
|
|
|
|
|
export default class PaidBreakdown extends Component {
|
|
|
|
@service dashboardStats;
|
|
|
|
@service feature;
|
|
|
|
|
|
|
|
@action
|
|
|
|
loadCharts() {
|
|
|
|
// todo: load the new data here
|
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
return this.dashboardStats.memberCountStats === null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartTitle() {
|
|
|
|
return 'Paid subscribers';
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartType() {
|
|
|
|
return 'bar';
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartData() {
|
|
|
|
const stats = this.dashboardStats.filledMemberCountStats;
|
|
|
|
const labels = stats.map(stat => stat.date);
|
|
|
|
const newData = stats.map(stat => stat.paidSubscribed);
|
|
|
|
const canceledData = stats.map(stat => -stat.paidCanceled);
|
|
|
|
const netData = stats.map(stat => stat.paidSubscribed - stat.paidCanceled);
|
2022-04-22 16:04:58 +03:00
|
|
|
const barThickness = 5;
|
2022-04-20 15:43:11 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
type: 'line',
|
|
|
|
data: netData,
|
|
|
|
tension: 0,
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
fill: false,
|
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 10,
|
|
|
|
pointBorderColor: '#14B8FF',
|
|
|
|
pointBackgroundColor: '#14B8FF',
|
|
|
|
pointHoverBackgroundColor: '#14B8FF',
|
|
|
|
pointHoverBorderColor: '#14B8FF',
|
|
|
|
pointHoverRadius: 0,
|
|
|
|
borderColor: 'rgba(189, 197, 204, 0.5)',
|
|
|
|
borderJoinStyle: 'miter',
|
|
|
|
borderWidth: 3
|
|
|
|
}, {
|
|
|
|
data: newData,
|
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#8E42FF',
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
barThickness: barThickness,
|
|
|
|
minBarLength: 3
|
|
|
|
}, {
|
|
|
|
data: canceledData,
|
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#FB76B4',
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
barThickness: barThickness,
|
|
|
|
minBarLength: 3
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartOptions() {
|
2022-04-26 20:54:52 +03:00
|
|
|
const barColor = this.feature.nightShift ? 'rgba(200, 204, 217, 0.25)' : 'rgba(200, 204, 217, 0.65)';
|
2022-04-20 15:43:11 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
title: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
2022-04-22 16:49:03 +03:00
|
|
|
layout: {
|
|
|
|
padding: {
|
2022-04-27 16:40:38 +03:00
|
|
|
top: 24,
|
2022-04-22 16:49:03 +03:00
|
|
|
bottom: 0,
|
2022-04-27 16:40:38 +03:00
|
|
|
left: 0,
|
|
|
|
right: 0
|
2022-04-22 16:49:03 +03:00
|
|
|
}
|
|
|
|
},
|
2022-04-20 15:43:11 +03:00
|
|
|
hover: {
|
|
|
|
onHover: function (e) {
|
|
|
|
e.target.style.cursor = 'pointer';
|
|
|
|
}
|
|
|
|
},
|
2022-04-26 16:52:46 +03:00
|
|
|
animation: {
|
|
|
|
duration: 0
|
|
|
|
},
|
|
|
|
responsiveAnimationDuration: 0,
|
2022-04-20 15:43:11 +03:00
|
|
|
tooltips: {
|
2022-04-26 20:54:52 +03:00
|
|
|
enabled: false,
|
2022-04-20 15:43:11 +03:00
|
|
|
intersect: false,
|
|
|
|
mode: 'index',
|
2022-04-26 20:54:52 +03:00
|
|
|
custom: function (tooltip) {
|
|
|
|
// get tooltip element
|
|
|
|
const tooltipEl = document.getElementById('gh-dashboard5-breakdown-tooltip');
|
2022-04-20 15:43:11 +03:00
|
|
|
|
2022-04-26 20:54:52 +03:00
|
|
|
// only show tooltip when active
|
|
|
|
if (tooltip.opacity === 0) {
|
|
|
|
tooltipEl.style.display = 'none';
|
|
|
|
tooltipEl.style.opacity = 0;
|
|
|
|
return;
|
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
|
2022-04-26 20:54:52 +03:00
|
|
|
// update tooltip styles
|
|
|
|
tooltipEl.style.display = 'block';
|
|
|
|
tooltipEl.style.opacity = 1;
|
|
|
|
tooltipEl.style.position = 'absolute';
|
|
|
|
tooltipEl.style.left = tooltip.x + 'px';
|
|
|
|
tooltipEl.style.top = tooltip.y + 'px';
|
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
label: (tooltipItems, data) => {
|
|
|
|
let newValue = data.datasets[1].data[tooltipItems.index].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
|
|
document.querySelector('#gh-dashboard5-breakdown-tooltip .gh-dashboard5-tooltip-value-2').innerHTML = `New ${newValue}`;
|
2022-04-20 15:43:11 +03:00
|
|
|
|
2022-04-26 20:54:52 +03:00
|
|
|
let canceldValue = data.datasets[2].data[tooltipItems.index].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
|
|
document.querySelector('#gh-dashboard5-breakdown-tooltip .gh-dashboard5-tooltip-value-3').innerHTML = `Canceled ${canceldValue}`;
|
2022-04-20 15:43:11 +03:00
|
|
|
},
|
|
|
|
title: (tooltipItems) => {
|
2022-04-26 20:54:52 +03:00
|
|
|
const value = moment(tooltipItems[0].xLabel).format(DATE_FORMAT);
|
|
|
|
document.querySelector('#gh-dashboard5-breakdown-tooltip .gh-dashboard5-tooltip-label').innerHTML = value;
|
2022-04-20 15:43:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
offset: false,
|
|
|
|
gridLines: {
|
|
|
|
drawTicks: false,
|
|
|
|
display: true,
|
|
|
|
drawBorder: false,
|
|
|
|
color: 'rgba(255, 255, 255, 0.1)',
|
|
|
|
lineWidth: 0,
|
|
|
|
zeroLineColor: barColor,
|
|
|
|
zeroLineWidth: 1
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
fontColor: '#7C8B9A',
|
|
|
|
padding: 8,
|
|
|
|
precision: 0
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
xAxes: [{
|
|
|
|
offset: true,
|
|
|
|
stacked: true,
|
|
|
|
gridLines: {
|
|
|
|
color: barColor,
|
|
|
|
borderDash: [4,4],
|
|
|
|
display: false,
|
|
|
|
drawBorder: false,
|
|
|
|
drawTicks: false,
|
|
|
|
zeroLineWidth: 1,
|
|
|
|
zeroLineColor: barColor,
|
|
|
|
zeroLineBorderDash: [4,4]
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|