1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: tooltip and legend

This commit is contained in:
Steven Tang 2021-09-05 14:28:00 +10:00
parent d1577fc6be
commit fa4512f79b
No known key found for this signature in database
GPG Key ID: AA0C5A4496B7ADF5

View File

@ -66,10 +66,9 @@ String.prototype.toHHMM = function () {
function draw(subselection) { function draw(subselection) {
function getTooltipOptions(key) { function getTooltipOptions(key) {
return { return {
mode: 'single',
callbacks: { callbacks: {
label: (item) => { label: (item) => {
let d = wakapiData[key][item.index] const d = wakapiData[key][item.dataIndex]
return `${d.key}: ${d.total.toString().toHHMMSS()}` return `${d.key}: ${d.total.toString().toHHMMSS()}`
}, },
title: () => 'Total Time' title: () => 'Total Time'
@ -114,9 +113,6 @@ function draw(subselection) {
}, },
options: { options: {
indexAxis: 'y', indexAxis: 'y',
legend: {
display: false
},
scales: { scales: {
xAxes: [{ xAxes: [{
scaleLabel: { scaleLabel: {
@ -128,7 +124,12 @@ function draw(subselection) {
} }
}] }]
}, },
tooltips: getTooltipOptions('projects'), plugins: {
legend: {
display: false
},
tooltip: getTooltipOptions('projects'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -161,7 +162,9 @@ function draw(subselection) {
.map(p => p.key) .map(p => p.key)
}, },
options: { options: {
tooltips: getTooltipOptions('operatingSystems'), plugins: {
tooltip: getTooltipOptions('operatingSystems'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -194,7 +197,9 @@ function draw(subselection) {
.map(p => p.key) .map(p => p.key)
}, },
options: { options: {
tooltips: getTooltipOptions('editors'), plugins: {
tooltip: getTooltipOptions('editors'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -227,7 +232,9 @@ function draw(subselection) {
.map(p => p.key) .map(p => p.key)
}, },
options: { options: {
tooltips: getTooltipOptions('languages'), plugins: {
tooltip: getTooltipOptions('languages'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -260,7 +267,9 @@ function draw(subselection) {
.map(p => p.key) .map(p => p.key)
}, },
options: { options: {
tooltips: getTooltipOptions('machines'), plugins: {
tooltip: getTooltipOptions('machines'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -293,7 +302,9 @@ function draw(subselection) {
.map(p => p.key) .map(p => p.key)
}, },
options: { options: {
tooltips: getTooltipOptions('labels'), plugins: {
tooltip: getTooltipOptions('labels'),
},
maintainAspectRatio: false, maintainAspectRatio: false,
onResize: onChartResize onResize: onChartResize
} }
@ -305,7 +316,7 @@ function draw(subselection) {
charts = [projectChart, osChart, editorChart, languageChart, machineChart, labelChart].filter(c => !!c) charts = [projectChart, osChart, editorChart, languageChart, machineChart, labelChart].filter(c => !!c)
if (!subselection) { if (!subselection) {
charts.forEach(c => c.options.onResize(c.chart)) charts.forEach(c => c.options.onResize(c))
equalizeHeights() equalizeHeights()
} }
} }