2022-04-01 16:53:55 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-04-06 20:11:46 +03:00
|
|
|
import moment from 'moment';
|
2022-04-01 16:53:55 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
2022-04-06 20:11:46 +03:00
|
|
|
const DATE_FORMAT = 'D MMM YYYY';
|
|
|
|
|
2022-04-12 12:18:10 +03:00
|
|
|
const PAID_OPTIONS = [{
|
|
|
|
name: 'Paid total',
|
|
|
|
value: 'paid'
|
|
|
|
}, {
|
|
|
|
name: 'Paid breakdown',
|
|
|
|
value: 'breakdown'
|
|
|
|
}];
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
export default class ChartAnchor extends Component {
|
|
|
|
@service dashboardStats;
|
|
|
|
@tracked chartDisplay = 'total';
|
2022-04-12 12:18:10 +03:00
|
|
|
@tracked paidOptionSelected = 'paid';
|
|
|
|
|
|
|
|
paidOptions = PAID_OPTIONS;
|
2022-04-01 16:53:55 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
loadCharts() {
|
|
|
|
this.dashboardStats.loadMemberCountStats();
|
|
|
|
this.dashboardStats.loadMrrStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
changeChartDisplay(type) {
|
|
|
|
this.chartDisplay = type;
|
2022-04-11 19:17:31 +03:00
|
|
|
this.loadCharts();
|
2022-04-01 16:53:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-12 12:18:10 +03:00
|
|
|
@action
|
|
|
|
paidOptionsChange(selected) {
|
|
|
|
this.paidOptionSelected = selected.value;
|
|
|
|
this.changeChartDisplay(selected.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get selectedPaidOption() {
|
|
|
|
return this.paidOptions.find(d => d.value === this.paidOptionSelected);
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
get chartShowingTotal() {
|
|
|
|
return (this.chartDisplay === 'total');
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartShowingPaid() {
|
2022-04-12 12:18:10 +03:00
|
|
|
return (this.chartDisplay === 'paid' || this.chartDisplay === 'breakdown');
|
2022-04-01 16:53:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-11 19:17:31 +03:00
|
|
|
get chartShowingBreakdown() {
|
|
|
|
return (this.chartDisplay === 'breakdown');
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
get chartShowingMonthly() {
|
|
|
|
return (this.chartDisplay === 'monthly');
|
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
if (this.chartDisplay === 'total') {
|
|
|
|
return this.dashboardStats.memberCountStats === null;
|
|
|
|
} else if (this.chartDisplay === 'paid') {
|
|
|
|
return this.dashboardStats.memberCountStats === null;
|
2022-04-11 19:17:31 +03:00
|
|
|
} else if (this.chartDisplay === 'breakdown') {
|
|
|
|
return this.dashboardStats.memberCountStats === null;
|
2022-04-01 16:53:55 +03:00
|
|
|
} else if (this.chartDisplay === 'monthly') {
|
|
|
|
return this.dashboardStats.mrrStats === null;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
get totalMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.total ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get paidMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.paid ?? 0;
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:17:31 +03:00
|
|
|
get paidBreakdown() {
|
|
|
|
return this.dashboardStats.memberCounts?.breakdown ?? 0;
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
get freeMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.free ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentMRR() {
|
|
|
|
return this.dashboardStats.currentMRR ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasTrends() {
|
|
|
|
return this.dashboardStats.memberCounts !== null && this.dashboardStats.memberCountsTrend !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get totalMembersTrend() {
|
|
|
|
return this.calculatePercentage(this.dashboardStats.memberCountsTrend.total, this.dashboardStats.memberCounts.total);
|
|
|
|
}
|
|
|
|
|
|
|
|
get paidMembersTrend() {
|
|
|
|
return this.calculatePercentage(this.dashboardStats.memberCountsTrend.paid, this.dashboardStats.memberCounts.paid);
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:17:31 +03:00
|
|
|
get paidBreakdownTrend() {
|
|
|
|
return '40%';
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
get freeMembersTrend() {
|
|
|
|
return this.calculatePercentage(this.dashboardStats.memberCountsTrend.free, this.dashboardStats.memberCounts.free);
|
|
|
|
}
|
|
|
|
|
|
|
|
get mrrTrend() {
|
|
|
|
return this.calculatePercentage(this.dashboardStats.currentMRRTrend, this.dashboardStats.currentMRR);
|
|
|
|
}
|
|
|
|
|
2022-04-01 19:02:30 +03:00
|
|
|
get hasPaidTiers() {
|
|
|
|
return this.dashboardStats.siteStatus?.hasPaidTiers;
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
get chartType() {
|
2022-04-11 19:17:31 +03:00
|
|
|
if (this.chartDisplay === 'breakdown') {
|
2022-04-08 19:49:11 +03:00
|
|
|
return 'bar';
|
|
|
|
}
|
2022-04-11 19:17:31 +03:00
|
|
|
|
|
|
|
return 'line';
|
2022-04-01 16:53:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartData() {
|
|
|
|
let stats = [];
|
|
|
|
let labels = [];
|
|
|
|
let data = [];
|
2022-04-11 19:17:31 +03:00
|
|
|
let newData;
|
|
|
|
let canceledData;
|
|
|
|
|
|
|
|
if (this.chartDisplay === 'breakdown') {
|
|
|
|
stats = this.dashboardStats.filledMemberCountStats;
|
|
|
|
labels = stats.map(stat => stat.date);
|
|
|
|
newData = stats.map(stat => stat.paidSubscribed);
|
|
|
|
canceledData = stats.map(stat => -stat.paidCanceled);
|
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
data: newData,
|
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#BD96F6',
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
barThickness: 18
|
|
|
|
},{
|
|
|
|
data: canceledData,
|
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#FB76B4',
|
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
barThickness: 18
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
2022-04-01 16:53:55 +03:00
|
|
|
|
|
|
|
if (this.chartDisplay === 'total') {
|
|
|
|
stats = this.dashboardStats.filledMemberCountStats;
|
|
|
|
labels = stats.map(stat => stat.date);
|
|
|
|
data = stats.map(stat => stat.paid + stat.free + stat.comped);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.chartDisplay === 'paid') {
|
|
|
|
stats = this.dashboardStats.filledMemberCountStats;
|
|
|
|
labels = stats.map(stat => stat.date);
|
|
|
|
data = stats.map(stat => stat.paid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.chartDisplay === 'monthly') {
|
|
|
|
stats = this.dashboardStats.filledMrrStats;
|
|
|
|
labels = stats.map(stat => stat.date);
|
|
|
|
data = stats.map(stat => stat.mrr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
|
|
|
data: data,
|
2022-04-06 20:11:46 +03:00
|
|
|
tension: 0,
|
2022-04-01 16:53:55 +03:00
|
|
|
cubicInterpolationMode: 'monotone',
|
|
|
|
fill: true,
|
2022-04-08 19:49:11 +03:00
|
|
|
fillColor: 'rgba(20, 184, 255, 0.07)',
|
|
|
|
backgroundColor: 'rgba(20, 184, 255, 0.07)',
|
2022-04-01 16:53:55 +03:00
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 10,
|
2022-04-08 19:49:11 +03:00
|
|
|
pointBorderColor: '#14B8FF',
|
|
|
|
pointBackgroundColor: '#14B8FF',
|
|
|
|
pointHoverBackgroundColor: '#14B8FF',
|
|
|
|
pointHoverBorderColor: '#14B8FF',
|
2022-04-06 20:11:46 +03:00
|
|
|
pointHoverRadius: 0,
|
2022-04-08 19:49:11 +03:00
|
|
|
borderColor: '#14B8FF',
|
2022-04-06 20:11:46 +03:00
|
|
|
borderJoinStyle: 'miter'
|
2022-04-01 16:53:55 +03:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartOptions() {
|
2022-04-11 19:17:31 +03:00
|
|
|
if (this.chartDisplay === 'breakdown') {
|
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
title: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
hover: {
|
|
|
|
onHover: function (e) {
|
|
|
|
e.target.style.cursor = 'pointer';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tooltips: {
|
|
|
|
intersect: false,
|
|
|
|
mode: 'index',
|
|
|
|
displayColors: false,
|
|
|
|
backgroundColor: '#15171A',
|
|
|
|
xPadding: 7,
|
|
|
|
yPadding: 7,
|
|
|
|
cornerRadius: 5,
|
|
|
|
caretSize: 7,
|
|
|
|
caretPadding: 5,
|
|
|
|
bodyFontSize: 12.5,
|
|
|
|
titleFontSize: 12,
|
|
|
|
titleFontStyle: 'normal',
|
|
|
|
titleFontColor: 'rgba(255, 255, 255, 0.7)',
|
|
|
|
titleMarginBottom: 3,
|
|
|
|
callbacks: {
|
|
|
|
title: (tooltipItems) => {
|
|
|
|
return moment(tooltipItems[0].xLabel).format(DATE_FORMAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
offset: true,
|
|
|
|
gridLines: {
|
|
|
|
drawTicks: false,
|
|
|
|
display: true,
|
|
|
|
drawBorder: false,
|
|
|
|
color: 'rgba(255, 255, 255, 0.1)',
|
|
|
|
lineWidth: 0,
|
|
|
|
zeroLineColor: 'rgba(200, 204, 217, 0.75)',
|
|
|
|
zeroLineWidth: 1
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: true,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
fontColor: '#7C8B9A',
|
|
|
|
padding: 8,
|
|
|
|
precision: 0
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
xAxes: [{
|
|
|
|
offset: true,
|
|
|
|
stacked: true,
|
|
|
|
gridLines: {
|
|
|
|
color: 'rgba(200, 204, 217, 0.75)',
|
|
|
|
borderDash: [4,4],
|
|
|
|
display: true,
|
|
|
|
drawBorder: true,
|
|
|
|
drawTicks: false,
|
|
|
|
zeroLineWidth: 1,
|
|
|
|
zeroLineColor: 'rgba(200, 204, 217, 0.75)',
|
|
|
|
zeroLineBorderDash: [4,4]
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: true,
|
|
|
|
maxRotation: 0,
|
|
|
|
minRotation: 0,
|
|
|
|
padding: 8,
|
|
|
|
autoSkip: true,
|
|
|
|
maxTicksLimit: 7
|
|
|
|
},
|
|
|
|
type: 'time',
|
|
|
|
time: {
|
|
|
|
displayFormats: {
|
|
|
|
millisecond: 'MMM DD',
|
|
|
|
second: 'MMM DD',
|
|
|
|
minute: 'MMM DD',
|
|
|
|
hour: 'MMM DD',
|
|
|
|
day: 'MMM DD',
|
|
|
|
week: 'MMM DD',
|
|
|
|
month: 'MMM DD',
|
|
|
|
quarter: 'MMM DD',
|
|
|
|
year: 'MMM DD'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
title: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
padding: {
|
2022-04-06 20:11:46 +03:00
|
|
|
top: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hover: {
|
|
|
|
onHover: function (e) {
|
|
|
|
e.target.style.cursor = 'pointer';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tooltips: {
|
|
|
|
intersect: false,
|
|
|
|
mode: 'index',
|
|
|
|
displayColors: false,
|
|
|
|
backgroundColor: '#15171A',
|
|
|
|
xPadding: 7,
|
|
|
|
yPadding: 7,
|
|
|
|
cornerRadius: 5,
|
|
|
|
caretSize: 7,
|
|
|
|
caretPadding: 5,
|
|
|
|
bodyFontSize: 12.5,
|
|
|
|
titleFontSize: 12,
|
|
|
|
titleFontStyle: 'normal',
|
|
|
|
titleFontColor: 'rgba(255, 255, 255, 0.7)',
|
|
|
|
titleMarginBottom: 3,
|
|
|
|
callbacks: {
|
|
|
|
label: (tooltipItems, data) => {
|
|
|
|
let valueText = data.datasets[tooltipItems.datasetIndex].data[tooltipItems.index].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
|
|
|
|
|
|
if (this.chartDisplay === 'total') {
|
|
|
|
return `Total members: ${valueText}`;
|
|
|
|
}
|
|
|
|
if (this.chartDisplay === 'paid') {
|
|
|
|
return `Paid members: ${valueText}`;
|
|
|
|
}
|
|
|
|
if (this.chartDisplay === 'monthly') {
|
|
|
|
return `Monthly revenue (MRR): ${valueText}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: (tooltipItems) => {
|
|
|
|
return moment(tooltipItems[0].xLabel).format(DATE_FORMAT);
|
|
|
|
}
|
2022-04-01 16:53:55 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
gridLines: {
|
|
|
|
drawTicks: false,
|
2022-04-11 19:17:31 +03:00
|
|
|
display: true,
|
|
|
|
drawBorder: false,
|
|
|
|
color: 'transparent',
|
|
|
|
zeroLineColor: 'rgba(200, 204, 217, 0.75)',
|
|
|
|
zeroLineWidth: 1
|
2022-04-01 16:53:55 +03:00
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
fontColor: '#7C8B9A',
|
|
|
|
padding: 8,
|
2022-04-06 20:11:46 +03:00
|
|
|
precision: 0,
|
2022-04-11 19:17:31 +03:00
|
|
|
stepSize: 1
|
2022-04-06 20:11:46 +03:00
|
|
|
},
|
|
|
|
display: true
|
2022-04-01 16:53:55 +03:00
|
|
|
}],
|
|
|
|
xAxes: [{
|
|
|
|
gridLines: {
|
2022-04-11 19:17:31 +03:00
|
|
|
color: 'rgba(200, 204, 217, 0.75)',
|
2022-04-08 19:49:11 +03:00
|
|
|
borderDash: [4,4],
|
|
|
|
display: true,
|
|
|
|
drawBorder: true,
|
2022-04-01 16:53:55 +03:00
|
|
|
drawTicks: false,
|
2022-04-08 19:49:11 +03:00
|
|
|
zeroLineWidth: 1,
|
2022-04-11 19:17:31 +03:00
|
|
|
zeroLineColor: 'rgba(200, 204, 217, 0.75)',
|
2022-04-08 19:49:11 +03:00
|
|
|
zeroLineBorderDash: [4,4]
|
2022-04-01 16:53:55 +03:00
|
|
|
},
|
|
|
|
ticks: {
|
2022-04-11 19:17:31 +03:00
|
|
|
display: true,
|
2022-04-01 16:53:55 +03:00
|
|
|
maxRotation: 0,
|
2022-04-06 20:11:46 +03:00
|
|
|
minRotation: 0,
|
2022-04-11 19:17:31 +03:00
|
|
|
padding: 14,
|
|
|
|
autoSkip: true,
|
|
|
|
maxTicksLimit: 8,
|
|
|
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Droid Sans", "Helvetica Neue", sans-serif',
|
|
|
|
fontSize: 11,
|
|
|
|
fontColor: '#7c8b9a'
|
2022-04-01 16:53:55 +03:00
|
|
|
},
|
|
|
|
type: 'time',
|
|
|
|
time: {
|
|
|
|
displayFormats: {
|
|
|
|
millisecond: 'MMM DD',
|
|
|
|
second: 'MMM DD',
|
|
|
|
minute: 'MMM DD',
|
|
|
|
hour: 'MMM DD',
|
|
|
|
day: 'MMM DD',
|
|
|
|
week: 'MMM DD',
|
|
|
|
month: 'MMM DD',
|
|
|
|
quarter: 'MMM DD',
|
|
|
|
year: 'MMM DD'
|
|
|
|
}
|
2022-04-06 20:11:46 +03:00
|
|
|
},
|
|
|
|
display: true
|
2022-04-01 16:53:55 +03:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-06 20:11:46 +03:00
|
|
|
get chartHeight() {
|
2022-04-12 12:18:10 +03:00
|
|
|
return 325;
|
2022-04-06 20:11:46 +03:00
|
|
|
}
|
|
|
|
|
2022-04-01 16:53:55 +03:00
|
|
|
calculatePercentage(from, to) {
|
|
|
|
if (from === 0) {
|
|
|
|
if (to > 0) {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.round((to - from) / from * 100);
|
|
|
|
}
|
|
|
|
}
|