2022-05-11 20:52:28 +03:00
|
|
|
/* globals Chart */
|
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
const MODE_OPTIONS = [{
|
|
|
|
name: 'Cadence',
|
|
|
|
value: 'cadence'
|
|
|
|
}, {
|
|
|
|
name: 'Tiers',
|
|
|
|
value: 'tiers'
|
|
|
|
}];
|
|
|
|
|
2022-05-11 20:52:28 +03:00
|
|
|
// Custom ChartJS rounded rectangle
|
|
|
|
Chart.elements.Rectangle.prototype.draw = function () {
|
|
|
|
var ctx = this._chart.ctx;
|
|
|
|
var vm = this._view;
|
|
|
|
var left, right, top, bottom, borderSkipped, radius;
|
|
|
|
|
|
|
|
// If radius is less than 0 or is large enough to cause drawing errors a max
|
|
|
|
// radius is imposed. If cornerRadius is not defined set it to 0.
|
|
|
|
var cornerRadius = this._chart.config.options.cornerRadius;
|
|
|
|
var fullCornerRadius = this._chart.config.options.fullCornerRadius;
|
|
|
|
var stackedRounded = this._chart.config.options.stackedRounded;
|
|
|
|
var typeOfChart = this._chart.config.type;
|
|
|
|
|
|
|
|
if (cornerRadius < 0) {
|
|
|
|
cornerRadius = 0;
|
|
|
|
}
|
|
|
|
if (typeof cornerRadius === 'undefined') {
|
|
|
|
cornerRadius = 0;
|
|
|
|
}
|
|
|
|
if (typeof fullCornerRadius === 'undefined') {
|
|
|
|
fullCornerRadius = true;
|
|
|
|
}
|
|
|
|
if (typeof stackedRounded === 'undefined') {
|
|
|
|
stackedRounded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vm.horizontal) {
|
|
|
|
// bar
|
|
|
|
left = vm.x - vm.width / 2;
|
|
|
|
right = vm.x + vm.width / 2;
|
|
|
|
top = vm.y;
|
|
|
|
bottom = vm.base;
|
|
|
|
borderSkipped = vm.borderSkipped || 'bottom';
|
|
|
|
} else {
|
|
|
|
// horizontal bar
|
|
|
|
left = vm.base;
|
|
|
|
right = vm.x;
|
|
|
|
top = vm.y - vm.height / 2;
|
|
|
|
bottom = vm.y + vm.height / 2;
|
|
|
|
borderSkipped = vm.borderSkipped || 'left';
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = vm.backgroundColor;
|
|
|
|
ctx.strokeStyle = vm.borderColor;
|
|
|
|
|
|
|
|
// Corner points, from bottom-left to bottom-right clockwise
|
|
|
|
// | 1 2 |
|
|
|
|
// | 0 3 |
|
|
|
|
var corners = [
|
|
|
|
[left, bottom],
|
|
|
|
[left, top],
|
|
|
|
[right, top],
|
|
|
|
[right, bottom]
|
|
|
|
];
|
|
|
|
|
|
|
|
// Find first (starting) corner with fallback to 'bottom'
|
|
|
|
var borders = ['bottom', 'left', 'top', 'right'];
|
|
|
|
var startCorner = borders.indexOf(borderSkipped, 0);
|
|
|
|
if (startCorner === -1) {
|
|
|
|
startCorner = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cornerAt(index) {
|
|
|
|
return corners[(startCorner + index) % 4];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw rectangle from 'startCorner'
|
|
|
|
var corner = cornerAt(0);
|
|
|
|
ctx.moveTo(corner[0], corner[1]);
|
|
|
|
|
|
|
|
var nextCornerId, width, height, x, y;
|
|
|
|
for (var i = 1; i < 4; i++) {
|
|
|
|
corner = cornerAt(i);
|
|
|
|
nextCornerId = i + 1;
|
|
|
|
if (nextCornerId === 4) {
|
|
|
|
nextCornerId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = corners[2][0] - corners[1][0];
|
|
|
|
height = corners[0][1] - corners[1][1];
|
|
|
|
x = corners[1][0];
|
|
|
|
y = corners[1][1];
|
|
|
|
|
|
|
|
radius = cornerRadius;
|
|
|
|
// Fix radius being too large
|
|
|
|
if (radius > Math.abs(height) / 2) {
|
|
|
|
radius = Math.floor(Math.abs(height) / 2);
|
|
|
|
}
|
|
|
|
if (radius > Math.abs(width) / 2) {
|
|
|
|
radius = Math.floor(Math.abs(width) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var xTL, xTR, yTL, yTR, xBL, xBR, yBL, yBR;
|
|
|
|
if (width < 0) {
|
|
|
|
// Negative values in a horizontal bar chart
|
|
|
|
xTL = x + width;
|
|
|
|
xTR = x;
|
|
|
|
yTL = y;
|
|
|
|
yTR = y;
|
|
|
|
|
|
|
|
xBL = x + width;
|
|
|
|
xBR = x;
|
|
|
|
yBL = y + height;
|
|
|
|
yBR = y + height;
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
ctx.moveTo(xBL + radius, yBL);
|
|
|
|
ctx.lineTo(xBR - radius, yBR);
|
|
|
|
|
|
|
|
// Bottom right corner
|
|
|
|
fullCornerRadius ? ctx.quadraticCurveTo(xBR, yBR, xBR, yBR - radius) : ctx.lineTo(xBR, yBR, xBR, yBR - radius);
|
|
|
|
ctx.lineTo(xTR, yTR + radius);
|
|
|
|
|
|
|
|
// top right Corner
|
|
|
|
fullCornerRadius ? ctx.quadraticCurveTo(xTR, yTR, xTR - radius, yTR) : ctx.lineTo(xTR, yTR, xTR - radius, yTR);
|
|
|
|
ctx.lineTo(xTL + radius, yTL);
|
|
|
|
|
|
|
|
// top left corner
|
|
|
|
ctx.quadraticCurveTo(xTL, yTL, xTL, yTL + radius);
|
|
|
|
ctx.lineTo(xBL, yBL - radius);
|
|
|
|
|
|
|
|
// bttom left corner
|
|
|
|
ctx.quadraticCurveTo(xBL, yBL, xBL + radius, yBL);
|
|
|
|
} else {
|
|
|
|
var lastVisible = 0;
|
|
|
|
for (var findLast = 0, findLastTo = this._chart.data.datasets.length; findLast < findLastTo; findLast++) {
|
|
|
|
if (!this._chart.getDatasetMeta(findLast).hidden) {
|
|
|
|
lastVisible = findLast;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var rounded = this._datasetIndex === lastVisible;
|
|
|
|
|
|
|
|
if (rounded) {
|
|
|
|
//Positive Value
|
|
|
|
ctx.moveTo(x + radius, y);
|
|
|
|
ctx.lineTo(x + width - radius, y);
|
|
|
|
|
|
|
|
// top right
|
|
|
|
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
|
|
ctx.lineTo(x + width, y + height - radius);
|
|
|
|
|
|
|
|
// bottom right
|
|
|
|
if (fullCornerRadius || typeOfChart === 'horizontalBar') {
|
|
|
|
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
|
|
} else {
|
|
|
|
ctx.lineTo(x + width, y + height, x + width - radius, y + height);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.lineTo(x + radius, y + height);
|
|
|
|
|
|
|
|
// bottom left
|
|
|
|
if (fullCornerRadius) {
|
|
|
|
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
|
|
} else {
|
|
|
|
ctx.lineTo(x, y + height, x, y + height - radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.lineTo(x, y + radius);
|
|
|
|
|
|
|
|
// top left
|
|
|
|
if (fullCornerRadius || typeOfChart === 'bar') {
|
|
|
|
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
|
|
} else {
|
|
|
|
ctx.lineTo(x, y, x + radius, y);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx.moveTo(x, y);
|
|
|
|
ctx.lineTo(x + width, y);
|
|
|
|
ctx.lineTo(x + width, y + height);
|
|
|
|
ctx.lineTo(x, y + height);
|
|
|
|
ctx.lineTo(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.fill();
|
|
|
|
};
|
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
export default class PaidMix extends Component {
|
|
|
|
@service dashboardStats;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you need to fetch new data from the server.
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
loadCharts() {
|
2022-05-12 16:09:19 +03:00
|
|
|
this.dashboardStats.loadMemberCountStats();
|
2022-04-20 15:43:11 +03:00
|
|
|
// The dashboard stats service will take care or reusing and limiting API-requests between charts
|
|
|
|
if (this.mode === 'cadence') {
|
|
|
|
this.dashboardStats.loadPaidMembersByCadence();
|
|
|
|
} else {
|
|
|
|
this.dashboardStats.loadPaidMembersByTier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@tracked mode = 'cadence';
|
|
|
|
modeOptions = MODE_OPTIONS;
|
|
|
|
|
|
|
|
get selectedModeOption() {
|
|
|
|
return this.modeOptions.find(option => option.value === this.mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasMultipleTiers() {
|
|
|
|
return this.dashboardStats.siteStatus?.hasMultipleTiers;
|
2022-05-06 19:33:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get totalMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.total ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isTotalMembersZero() {
|
2022-05-12 16:09:19 +03:00
|
|
|
return this.dashboardStats.memberCounts?.total === 0;
|
2022-05-06 19:33:19 +03:00
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
onSwitchMode(selected) {
|
|
|
|
this.mode = selected.value;
|
|
|
|
|
|
|
|
if (this.loading) {
|
|
|
|
// We don't have the data yet for the newly selected mode
|
|
|
|
this.loadCharts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
if (this.mode === 'cadence') {
|
|
|
|
return this.dashboardStats.paidMembersByCadence === null;
|
|
|
|
}
|
|
|
|
return this.dashboardStats.paidMembersByTier === null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartType() {
|
|
|
|
return 'horizontalBar';
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:09:19 +03:00
|
|
|
get areTiersAllZero() {
|
2022-05-12 20:05:20 +03:00
|
|
|
if (this.dashboardStats.paidMembersByTier === null || this.dashboardStats.paidMembersByTier.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-05-12 16:09:19 +03:00
|
|
|
const data = this.dashboardStats.paidMembersByTier.map(stat => stat.members);
|
|
|
|
let areAllTiersZero = true;
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
if (data[i] > 0) {
|
|
|
|
areAllTiersZero = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return areAllTiersZero;
|
2022-05-10 20:40:20 +03:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
get chartData() {
|
2022-04-27 17:11:01 +03:00
|
|
|
const totalCadence = this.dashboardStats.paidMembersByCadence.month + this.dashboardStats.paidMembersByCadence.year;
|
|
|
|
const monthlyPercentage = Math.round(this.dashboardStats.paidMembersByCadence.month / totalCadence * 100);
|
|
|
|
const annualPercentage = Math.round(this.dashboardStats.paidMembersByCadence.year / totalCadence * 100);
|
2022-04-27 16:40:38 +03:00
|
|
|
const barThickness = 5;
|
2022-04-22 16:04:58 +03:00
|
|
|
|
2022-05-12 16:09:19 +03:00
|
|
|
if (this.mode === 'cadence') {
|
|
|
|
// there has to be negative values to make rounded corners work
|
|
|
|
// empty chart render when there is no data
|
|
|
|
if (totalCadence === 0 && !this.isTotalMembersZero) {
|
|
|
|
return {
|
|
|
|
labels: ['Cadence'],
|
|
|
|
datasets: [{
|
|
|
|
label: 'Monthly',
|
|
|
|
data: [-50],
|
|
|
|
backgroundColor: '#F3F6F8',
|
|
|
|
barThickness
|
|
|
|
},{
|
|
|
|
label: 'Annual',
|
|
|
|
data: [50],
|
|
|
|
backgroundColor: '#EBEEF0',
|
|
|
|
barThickness
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
// fake colorful data for underneath empty state
|
|
|
|
} else if (this.isTotalMembersZero) {
|
|
|
|
return {
|
|
|
|
labels: ['Cadence'],
|
|
|
|
datasets: [{
|
|
|
|
label: 'Monthly',
|
|
|
|
data: [-40],
|
|
|
|
backgroundColor: '#8E42FF',
|
|
|
|
barThickness
|
|
|
|
},{
|
|
|
|
label: 'Annual',
|
|
|
|
data: [60],
|
|
|
|
backgroundColor: '#FB76B4',
|
|
|
|
barThickness
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
2022-05-06 19:33:19 +03:00
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
return {
|
2022-04-27 17:11:01 +03:00
|
|
|
labels: ['Cadence'],
|
2022-04-20 15:43:11 +03:00
|
|
|
datasets: [{
|
2022-04-22 16:04:58 +03:00
|
|
|
label: 'Monthly',
|
2022-05-11 20:52:28 +03:00
|
|
|
data: [-monthlyPercentage],
|
2022-04-22 16:04:58 +03:00
|
|
|
backgroundColor: '#8E42FF',
|
2022-04-27 16:40:38 +03:00
|
|
|
barThickness
|
2022-04-22 16:04:58 +03:00
|
|
|
}, {
|
|
|
|
label: 'Annual',
|
|
|
|
data: [annualPercentage],
|
|
|
|
backgroundColor: '#FB76B4',
|
2022-04-27 16:40:38 +03:00
|
|
|
barThickness
|
2022-04-20 15:43:11 +03:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:09:19 +03:00
|
|
|
// if it's for tiers...
|
2022-04-20 15:43:11 +03:00
|
|
|
const labels = this.dashboardStats.paidMembersByTier.map(stat => stat.tier.name);
|
|
|
|
const data = this.dashboardStats.paidMembersByTier.map(stat => stat.members);
|
2022-04-22 16:13:33 +03:00
|
|
|
const colors = ['#853EED', '#CA3FED', '#E993CC', '#DB7777', '#EE9696', '#FEC7C0', '#853EED', '#CA3FED', '#E993CC', '#DB7777', '#EE9696', '#FEC7C0'];
|
2022-05-12 16:09:19 +03:00
|
|
|
const zeroColors = ['#E6E9EB', '#EEF1F2', '#F6F8FA', '#EEF1F2', '#E6E9EB', '#EEF1F2', '#F6F8FA', '#EEF1F2', '#E6E9EB', '#EEF1F2', '#F6F8FA', '#EEF1F2'];
|
|
|
|
let datasets = [];
|
|
|
|
let totalTiersAmount;
|
2022-04-22 16:04:58 +03:00
|
|
|
|
2022-05-12 16:09:19 +03:00
|
|
|
// tiers all have 0 data
|
|
|
|
if (this.areTiersAllZero) {
|
|
|
|
totalTiersAmount = 100;
|
2022-05-13 17:17:25 +03:00
|
|
|
let equalPercentageData = Math.round(100 / data.length);
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
data[i] = equalPercentageData;
|
2022-05-12 16:09:19 +03:00
|
|
|
}
|
|
|
|
// tiers have good data
|
|
|
|
} else {
|
|
|
|
totalTiersAmount = 0;
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
totalTiersAmount += data[i];
|
|
|
|
}
|
2022-04-22 16:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
2022-05-19 12:41:54 +03:00
|
|
|
if (!this.areTiersAllZero && data[i] === 0) {
|
|
|
|
// If not all tiers are zero, hide tiers with 0 members, because
|
|
|
|
// they are not visible in the graph and can break rounded corners
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-22 16:04:58 +03:00
|
|
|
let tierPercentage = Math.round(data[i] / totalTiersAmount * 100);
|
2022-05-11 20:52:28 +03:00
|
|
|
|
|
|
|
// The first value has to be negative to make rounded corners work
|
|
|
|
if (i === 0) {
|
|
|
|
tierPercentage = -tierPercentage;
|
|
|
|
}
|
2022-04-22 16:04:58 +03:00
|
|
|
datasets.push({
|
|
|
|
data: [tierPercentage],
|
|
|
|
label: labels[i],
|
2022-05-12 16:09:19 +03:00
|
|
|
backgroundColor: this.areTiersAllZero ? zeroColors[i] : colors[i],
|
2022-04-27 16:40:38 +03:00
|
|
|
barThickness
|
2022-04-22 16:04:58 +03:00
|
|
|
});
|
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
|
|
|
|
return {
|
2022-04-22 16:04:58 +03:00
|
|
|
labels: ['Tiers'],
|
|
|
|
datasets
|
2022-04-20 15:43:11 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartOptions() {
|
2022-05-12 16:09:19 +03:00
|
|
|
let that = this;
|
2022-05-12 16:35:30 +03:00
|
|
|
let ticksY = {display: false};
|
2022-05-12 16:09:19 +03:00
|
|
|
let totalCadence = this.dashboardStats.paidMembersByCadence.month + this.dashboardStats.paidMembersByCadence.year;
|
|
|
|
let minTickValue = -(Math.round(this.dashboardStats.paidMembersByCadence.month / totalCadence * 100));
|
|
|
|
let maxTickValue = Math.round(this.dashboardStats.paidMembersByCadence.year / totalCadence * 100);
|
2022-05-11 20:52:28 +03:00
|
|
|
|
2022-05-12 16:35:30 +03:00
|
|
|
// this is for cadence...
|
2022-05-11 20:52:28 +03:00
|
|
|
if (this.mode === 'cadence') {
|
2022-05-12 16:09:19 +03:00
|
|
|
// for when it's empty
|
|
|
|
if (totalCadence === 0) {
|
|
|
|
minTickValue = -50;
|
|
|
|
maxTickValue = 50;
|
|
|
|
}
|
2022-05-12 16:35:30 +03:00
|
|
|
|
|
|
|
ticksY = {
|
|
|
|
display: false,
|
|
|
|
min: minTickValue,
|
|
|
|
max: maxTickValue
|
|
|
|
};
|
|
|
|
|
|
|
|
// this is for tiers...
|
2022-05-11 20:52:28 +03:00
|
|
|
} else {
|
2022-05-12 16:57:33 +03:00
|
|
|
if (!this.areTiersAllZero) {
|
|
|
|
let data = this.dashboardStats.paidMembersByTier.map(stat => stat.members);
|
|
|
|
let totalTiersAmount = 0;
|
2022-05-12 16:35:30 +03:00
|
|
|
|
2022-05-12 16:57:33 +03:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
totalTiersAmount += data[i];
|
2022-05-12 16:35:30 +03:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:57:33 +03:00
|
|
|
let negativeTierPercentage = Math.round(data[0] / totalTiersAmount * 100);
|
2022-05-12 16:35:30 +03:00
|
|
|
|
2022-05-12 16:57:33 +03:00
|
|
|
ticksY = {
|
|
|
|
display: false,
|
|
|
|
min: -negativeTierPercentage,
|
|
|
|
max: 100 - negativeTierPercentage // take the negative away from 100 to create a full width bar
|
|
|
|
};
|
|
|
|
}
|
2022-05-11 20:52:28 +03:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
2022-05-11 20:52:28 +03:00
|
|
|
cornerRadius: 50,
|
|
|
|
fullCornerRadius: false,
|
2022-04-20 15:43:11 +03:00
|
|
|
legend: {
|
2022-04-26 16:52:46 +03:00
|
|
|
display: false
|
2022-04-22 16:04:58 +03:00
|
|
|
},
|
|
|
|
layout: {
|
2022-04-27 16:40:38 +03:00
|
|
|
padding: {
|
2022-05-06 13:59:45 +03:00
|
|
|
top: 72,
|
2022-04-27 16:40:38 +03:00
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
2022-04-28 18:40:19 +03:00
|
|
|
right: 4
|
2022-04-27 16:40:38 +03:00
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
},
|
2022-05-12 15:04:24 +03:00
|
|
|
animation: false,
|
|
|
|
responsiveAnimationDuration: 1,
|
2022-04-20 15:43:11 +03:00
|
|
|
hover: {
|
|
|
|
onHover: function (e) {
|
|
|
|
e.target.style.cursor = 'pointer';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tooltips: {
|
2022-04-26 20:54:52 +03:00
|
|
|
enabled: false,
|
2022-04-20 15:43:11 +03:00
|
|
|
intersect: false,
|
2022-04-22 16:04:58 +03:00
|
|
|
mode: 'single',
|
2022-04-26 20:54:52 +03:00
|
|
|
custom: function (tooltip) {
|
|
|
|
// get tooltip element
|
2022-05-17 10:34:34 +03:00
|
|
|
const tooltipEl = document.getElementById('gh-dashboard-mix-tooltip');
|
2022-05-11 11:51:32 +03:00
|
|
|
const chartContainerEl = tooltipEl.parentElement;
|
|
|
|
const chartWidth = chartContainerEl.offsetWidth;
|
|
|
|
const tooltipWidth = tooltipEl.offsetWidth;
|
2022-04-26 20:54:52 +03:00
|
|
|
|
|
|
|
// only show tooltip when active
|
|
|
|
if (tooltip.opacity === 0) {
|
|
|
|
tooltipEl.style.opacity = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-11 11:51:32 +03:00
|
|
|
let offsetX = 0;
|
2022-05-17 14:50:56 +03:00
|
|
|
|
|
|
|
if (that.mode === 'cadence') {
|
|
|
|
// these adjustments should match the special width and margin values in css
|
|
|
|
if (tooltip.x > (chartWidth * 0.69) - tooltipWidth) {
|
|
|
|
offsetX = tooltipWidth - 10;
|
|
|
|
}
|
|
|
|
offsetX -= (chartWidth * 0.30);
|
|
|
|
} else {
|
|
|
|
if (tooltip.x > chartWidth - tooltipWidth) {
|
|
|
|
offsetX = tooltipWidth - 10;
|
|
|
|
}
|
2022-05-11 11:51:32 +03:00
|
|
|
}
|
|
|
|
|
2022-04-26 20:54:52 +03:00
|
|
|
// update tooltip styles
|
|
|
|
tooltipEl.style.opacity = 1;
|
|
|
|
tooltipEl.style.position = 'absolute';
|
2022-05-11 11:51:32 +03:00
|
|
|
tooltipEl.style.left = tooltip.x - offsetX + 'px';
|
2022-05-11 13:50:05 +03:00
|
|
|
tooltipEl.style.top = '30px';
|
2022-04-26 20:54:52 +03:00
|
|
|
},
|
2022-04-22 16:04:58 +03:00
|
|
|
callbacks: {
|
2022-04-26 20:54:52 +03:00
|
|
|
label: (tooltipItems, data) => {
|
2022-05-17 10:34:34 +03:00
|
|
|
const tooltipTextEl = document.querySelector('#gh-dashboard-mix-tooltip .gh-dashboard-tooltip-value');
|
2022-05-12 16:09:19 +03:00
|
|
|
const label = data.datasets[tooltipItems.datasetIndex].label || '';
|
|
|
|
var value = data.datasets[tooltipItems.datasetIndex].data[tooltipItems.index] || 0;
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
}
|
|
|
|
if (that.isTotalMembersZero || totalCadence === 0) {
|
|
|
|
value = 0;
|
2022-05-10 20:40:20 +03:00
|
|
|
} else {
|
2022-05-12 16:09:19 +03:00
|
|
|
value += '%';
|
2022-05-10 20:40:20 +03:00
|
|
|
}
|
2022-05-12 16:09:19 +03:00
|
|
|
tooltipTextEl.innerHTML = `<span class="indicator solid" style="background-color: ${data.datasets[tooltipItems.datasetIndex].backgroundColor}"></span><span class="value">${value}</span><span class="metric">${label}</span>`;
|
2022-04-22 16:04:58 +03:00
|
|
|
},
|
|
|
|
title: () => {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
2022-04-22 16:04:58 +03:00
|
|
|
stacked: true,
|
2022-04-20 15:43:11 +03:00
|
|
|
gridLines: {
|
2022-04-22 16:13:33 +03:00
|
|
|
display: false
|
2022-04-20 15:43:11 +03:00
|
|
|
},
|
|
|
|
ticks: {
|
2022-04-22 16:04:58 +03:00
|
|
|
display: false
|
2022-04-20 15:43:11 +03:00
|
|
|
}
|
|
|
|
}],
|
|
|
|
xAxes: [{
|
|
|
|
stacked: true,
|
|
|
|
gridLines: {
|
2022-04-22 16:13:33 +03:00
|
|
|
display: false
|
2022-04-20 15:43:11 +03:00
|
|
|
},
|
2022-05-11 20:52:28 +03:00
|
|
|
ticks: ticksY
|
2022-04-22 16:13:33 +03:00
|
|
|
}]
|
2022-04-20 15:43:11 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-26 16:52:46 +03:00
|
|
|
get isChartCadence() {
|
|
|
|
return (this.mode === 'cadence');
|
|
|
|
}
|
|
|
|
|
|
|
|
get isChartTiers() {
|
|
|
|
return (this.mode === 'tiers');
|
2022-04-20 15:43:11 +03:00
|
|
|
}
|
2022-04-27 17:11:01 +03:00
|
|
|
}
|