Skip to content

Commit

Permalink
improve tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed May 16, 2024
1 parent 499ad88 commit ef13411
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/src/_helpers/charts/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ const customCanvasBackgroundColor = {
}
}

export { customCanvasBackgroundColor }
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}

export { customCanvasBackgroundColor, capitalizeFirstLetter }
21 changes: 21 additions & 0 deletions frontend/src/components/LineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { mdiDownloadBox, mdiFileDelimited, mdiCodeJson, mdiMagnifyMinusOutline }
import { downloadCsv, downloadFeatureJson } from '../_helpers/hydroCron';
import { useDisplay } from 'vuetify'
import zoomPlugin from 'chartjs-plugin-zoom';
import { capitalizeFirstLetter } from '@/_helpers/charts/plugins'
const { lgAndUp } = useDisplay()
Expand Down Expand Up @@ -120,6 +121,26 @@ const options = {
mode: 'xy',
}
},
tooltip: {
// https://www.chartjs.org/docs/latest/configuration/tooltip.html
callbacks: {
label: function (context) {
// var label = context.dataset.label || '';
let selectedVariable = props.chosenVariable
let label = `${capitalizeFirstLetter(selectedVariable.abbreviation)}`
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
// label += new Intl.NumberFormat('en-US', { style: 'decimal', maximumFractionDigits: 5 }).format(context.parsed.y);
label += context.parsed.y
}
label += ` ${selectedVariable.unit}`
return label;
}
},
displayColors: false,
}
},
scales: {
x: {
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/NodeChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { mdiDownloadBox, mdiFileDelimited, mdiCodeJson, mdiMagnifyMinusOutline }
import { downloadMultiNodesCsv, downloadMultiNodesJson } from '../_helpers/hydroCron';
import { useDisplay } from 'vuetify'
import zoomPlugin from 'chartjs-plugin-zoom';
import { capitalizeFirstLetter } from '@/_helpers/charts/plugins'
const { lgAndUp } = useDisplay()
Expand Down Expand Up @@ -110,6 +111,29 @@ const options = {
mode: 'xy',
}
},
tooltip: {
// https://www.chartjs.org/docs/latest/configuration/tooltip.html
callbacks: {
label: function (context) {
// var label = context.dataset.label || '';
let selectedVariable = props.chosenVariable
let label = `${capitalizeFirstLetter(selectedVariable.abbreviation)}`
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
// label += new Intl.NumberFormat('en-US', { style: 'decimal', maximumFractionDigits: 5 }).format(context.parsed.y);
label += context.parsed.y
}
label += ` ${selectedVariable.unit}`
return label;
},
title: function (context) {
return `Distance: ${context[0].parsed.x} m`
},
},
displayColors: false,
},
},
scales: {
x: {
Expand Down

0 comments on commit ef13411

Please sign in to comment.