Skip to content

Commit

Permalink
Show hours next to billability percentages in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion committed Nov 8, 2023
1 parent 6036fca commit 0b33d30
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "TimeChimp Billability Chart",
"description": "Adds a billability chart on the TimeChimp hours page.",
"version": "1.3.1",
"version": "1.4.0",
"manifest_version": 3,
"permissions": [
"webRequest"
Expand Down
42 changes: 35 additions & 7 deletions src/content/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ export function createOrUpdateChart(
data: rollingStats.map((s) => s.nonBillableHoursPercentage),
color: '#e6e4e3',
tooltip: {
valueSuffix: '%',
valueDecimals: 0,
pointFormatter: function () {
const hours =
rollingStats.find(
(s) => s.week === Number(this.category),
)?.nonBillableHours ?? 0;

return this.tooltipFormatter(
formatTooltip(
`${Math.round(
this.y ?? 0,
)}% (${hoursToClockNotation(hours)})`,
),
);
},
},
},
{
Expand All @@ -76,8 +88,20 @@ export function createOrUpdateChart(
data: rollingStats.map((s) => s.billableHoursPercentage),
color: '#f36f21',
tooltip: {
valueSuffix: '%',
valueDecimals: 0,
pointFormatter: function () {
const hours =
rollingStats.find(
(s) => s.week === Number(this.category),
)?.billableHours ?? 0;

return this.tooltipFormatter(
formatTooltip(
`${Math.round(
this.y ?? 0,
)}% (${hoursToClockNotation(hours)})`,
),
);
},
},
},
{
Expand All @@ -100,9 +124,9 @@ export function createOrUpdateChart(
opacity: 0,
tooltip: {
pointFormatter: function () {
const hours = hoursToClockNotation(this.y ?? 0);
const format = `<span style='color:{point.color}'>●</span> {series.name}: <b>${hours}</b><br/>`;
return this.tooltipFormatter.call(this, format);
return this.tooltipFormatter(
formatTooltip(hoursToClockNotation(this.y ?? 0)),
);
},
},
},
Expand All @@ -125,3 +149,7 @@ export function createOrUpdateChart(
console.error('No chart container given and no existing chart set.');
}
}

function formatTooltip(value: string) {
return `<span style='color:{point.color}'>●</span> {series.name}: <b>${value}</b><br/>`;
}

0 comments on commit 0b33d30

Please sign in to comment.