Skip to content

Commit

Permalink
feat: add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed Dec 13, 2024
1 parent 5261d39 commit dc86e62
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/oversight/charts/cwvperf.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ export default class CWVPerfChart extends AbstractChart {
customCanvasBackgroundColor: {
color: 'white',
},
tooltip: {
callbacks: {
label: (context) => {
const value = context.parsed.y;

const { datasets } = context.chart.data;
const i = context.dataIndex;
const cwvmetric = context.dataset.label.split(' ').pop();
const total = datasets
.filter((dataset) => dataset.label.indexOf('Fake') === -1)
.filter(({ label }) => label.indexOf(cwvmetric) > -1)
.reduce((pv, cv) => (pv || 0) + (cv.data[i] || 0), 0);

if (value === 0 || total === 0) return '';
return (`${context.dataset.label}: ${Math.round((value / total) * 1000) / 10}%`);
},
},
},
},
interaction: {
mode: 'x',
Expand Down Expand Up @@ -205,6 +223,7 @@ export default class CWVPerfChart extends AbstractChart {
goodCWV, niCWV, poorCWV, noCWV,
}) => {
const valueCount = goodCWV.count + niCWV.count + poorCWV.count;
console.log('addInterpolation valueCount', valueCount);

Check warning on line 226 in tools/oversight/charts/cwvperf.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
if (valueCount < INTERPOLATION_THRESHOLD) {
// not enough data to interpolate the other values, so
// we report as if there are no CWV at all
Expand Down

0 comments on commit dc86e62

Please sign in to comment.