Ghost/ghost/admin/app/components/dashboard/v5/chart-paid-members.js
James Morris 560d862d91 The big cleanup (#2328)
* Trying out a tooltip alternative for combined graph in new dashboard

refs: https://github.com/TryGhost/Team/issues/1467

* Trying out a different type of interaction with the combined graph for the new dashboard that includes different style

refs: https://github.com/TryGhost/Team/issues/1467

* Working through the interface and code to majorly clean up for the new Dashboard

refs: https://github.com/TryGhost/Team/issues/1462

- lots of moving around css
- trying out some different layouts
- refactoring lots of code
- known bug: paid graphs don't work
- known bug: without newsletters, layout breaks

* Finishing up the basic styling of the new dashboard to be more presentable

refs: https://github.com/TryGhost/Team/issues/1462

- add an animation between the top metrics on combined graph
- ensure all graphs are responsive to parent container
- refactor many of the components and tidy up the styles
- tighten up spacing, headers, chart heights and more
- make the tooltip hovers a little more presentable
- balance the colors to be more muted, for the moment
- a million other tiny tweaks
2022-04-06 18:11:46 +01:00

139 lines
4.1 KiB
JavaScript

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 YYYY';
export default class ChartPaidMembers extends Component {
@service dashboardStats;
/**
* Call this method when you need to fetch new data from the server.
*/
@action
loadCharts() {
// The dashboard stats service will take care or reusing and limiting API-requests between charts
this.dashboardStats.loadMemberCountStats();
}
get loading() {
return this.dashboardStats.memberCountStats === null;
}
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);
return {
labels: labels,
datasets: [
{
data: newData,
fill: true,
backgroundColor: '#7BA4F3',
barThickness: 10
},{
data: canceledData,
fill: true,
backgroundColor: '#E5E5E5',
barThickness: 10
}]
};
}
get chartOptions() {
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
},
ticks: {
display: false,
maxTicksLimit: 5,
fontColor: '#7C8B9A',
padding: 8,
precision: 0
}
}],
xAxes: [{
offset: true,
stacked: true,
gridLines: {
drawTicks: true,
display: false,
drawBorder: false
},
ticks: {
display: false,
maxTicksLimit: 5,
autoSkip: true
},
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'
}
}
}]
}
};
}
get chartHeight() {
return 125;
}
}