Skip to content

Commit

Permalink
Merge pull request #420 from UmakanthKaspa/fix/tooltip-filter-sort
Browse files Browse the repository at this point in the history
fix: filter and sort tooltip values
  • Loading branch information
nextchamp-saqib authored Jan 10, 2025
2 parents ca8f920 + 622db31 commit e5c7545
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/src/widgets/AxisChart/getAxisChartOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,18 @@ function makeOptions(chartType, labels, datasets, options) {
trigger: 'axis',
confine: true,
appendToBody: false,
valueFormatter: (value) => (isNaN(value) ? value : formatNumber(value)),
formatter: (params) => {
const filteredParams = params
.filter((p) => p.value !== 0 && p.value !== null)
.sort((a, b) => b.value - a.value);

if (!filteredParams.length) return '';
return filteredParams
.map((p) => `${p.marker} ${p.seriesName}: ${formatNumber(p.value)}`)
.join('<br/>');
},
},

}
}

Expand Down
6 changes: 6 additions & 0 deletions frontend/src2/charts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ function getTooltip(options: any = {}) {
confine: true,
appendToBody: false,
formatter: (params: Object | Array<Object>) => {
if (Array.isArray(params)) {
params = params
.filter((p) => p.value?.[1] !== 0)
.sort((a, b) => b.value?.[1] - a.value?.[1]);
}

if (!Array.isArray(params)) {
const p = params as any
const value = options.xySwapped ? p.value[0] : p.value[1]
Expand Down

0 comments on commit e5c7545

Please sign in to comment.