signoz/frontend/src/lib/uPlotLib/plugins/onClickPlugin.ts
SagarRajput-7 0320285a25
feat: added context redirection from panels to explorer pages (#7141)
* feat: added context redirection from panels to explorer pages

* feat: added graph coordinate - context redirection

* feat: fixed tooltip overlapping the button

* feat: code fix

* feat: removed unneccesary comment

* feat: added logic to resolve variables

* feat: added better logic to handle specific and panel redirection using query

* feat: added multi query support by datasource to panels redirction

* feat: fixing createbutton display logic

* feat: added logic and ui for specific line redirection

* feat: added logic to compute query with groupby

* feat: code fix and added aysnc await

* feat: added context redirection to fullview and edit view panels (#7252)

* feat: added context redirection to fullview and edit view panels

* feat: restricted redirection query to have only one query

* feat: added is buttonEnabled logic of graphs

* feat: code cleanup

* feat: for one query removed the queryname from onclick button

* feat: removed redirection option from action menu

* feat: redesign the format api flow to avoid delay in clickbutton appearance

* feat: updated the create filter logic for groupBys

* feat: handled the error on format api
2025-03-20 11:29:31 +05:30

72 lines
1.9 KiB
TypeScript

import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
export interface OnClickPluginOpts {
onClick: (
xValue: number,
yValue: number,
mouseX: number,
mouseY: number,
data?: {
[key: string]: string;
},
queryData?: {
queryName: string;
inFocusOrNot: boolean;
},
) => void;
apiResponse?: MetricRangePayloadProps;
}
function onClickPlugin(opts: OnClickPluginOpts): uPlot.Plugin {
let handleClick: (event: MouseEvent) => void;
const hooks: uPlot.Plugin['hooks'] = {
init: (u: uPlot) => {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
handleClick = function (event: MouseEvent) {
const mouseX = event.offsetX + 40;
const mouseY = event.offsetY + 40;
// Convert pixel positions to data values
// do not use mouseX and mouseY here as it offsets the timestamp as well
const xValue = u.posToVal(event.offsetX, 'x');
const yValue = u.posToVal(event.offsetY, 'y');
let metric = {};
const { series } = u;
const apiResult = opts.apiResponse?.data?.result || [];
const outputMetric = {
queryName: '',
inFocusOrNot: false,
};
// this is to get the metric value of the focused series
if (Array.isArray(series) && series.length > 0) {
series.forEach((item, index) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (item?.show && item?._focus) {
const { metric: focusedMetric, queryName } = apiResult[index - 1] || [];
metric = focusedMetric;
outputMetric.queryName = queryName;
outputMetric.inFocusOrNot = true;
}
});
}
opts.onClick(xValue, yValue, mouseX, mouseY, metric, outputMetric);
};
u.over.addEventListener('click', handleClick);
},
destroy: (u: uPlot) => {
u.over.removeEventListener('click', handleClick);
},
};
return {
hooks,
};
}
export default onClickPlugin;