HeatmapNG: explicitly pass scales for cursor sync config (#51389)

This commit is contained in:
Leon Sorokin 2022-06-24 11:42:39 -05:00 committed by GitHub
parent 0689c5839a
commit 7e1667ce87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 17 deletions

View File

@ -7655,13 +7655,6 @@ exports[`no explicit any`] = {
"public/app/plugins/panel/heatmap/palettes.ts:4110363347": [ "public/app/plugins/panel/heatmap/palettes.ts:4110363347": [
[87, 59, 3, "Unexpected any. Specify a different type.", "193409811"] [87, 59, 3, "Unexpected any. Specify a different type.", "193409811"]
], ],
"public/app/plugins/panel/heatmap/utils.ts:2711553971": [
[64, 27, 3, "Unexpected any. Specify a different type.", "193409811"],
[215, 21, 3, "Unexpected any. Specify a different type.", "193409811"],
[396, 21, 3, "Unexpected any. Specify a different type.", "193409811"],
[495, 10, 3, "Unexpected any. Specify a different type.", "193409811"],
[527, 9, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/plugins/panel/histogram/Histogram.tsx:3993177092": [ "public/app/plugins/panel/histogram/Histogram.tsx:3993177092": [
[130, 31, 3, "Unexpected any. Specify a different type.", "193409811"], [130, 31, 3, "Unexpected any. Specify a different type.", "193409811"],
[223, 32, 3, "Unexpected any. Specify a different type.", "193409811"], [223, 32, 3, "Unexpected any. Specify a different type.", "193409811"],

View File

@ -62,7 +62,7 @@ interface PrepConfigOpts {
theme: GrafanaTheme2; theme: GrafanaTheme2;
eventBus: EventBus; eventBus: EventBus;
onhover?: null | ((evt?: HeatmapHoverEvent | null) => void); onhover?: null | ((evt?: HeatmapHoverEvent | null) => void);
onclick?: null | ((evt?: any) => void); onclick?: null | ((evt?: Object) => void);
onzoom?: null | ((evt: HeatmapZoomEvent) => void); onzoom?: null | ((evt: HeatmapZoomEvent) => void);
isToolTipOpen: MutableRefObject<boolean>; isToolTipOpen: MutableRefObject<boolean>;
timeZone: string; timeZone: string;
@ -113,8 +113,8 @@ export function prepConfig(opts: PrepConfigOpts) {
let rect: DOMRect; let rect: DOMRect;
builder.addHook('init', (u) => { builder.addHook('init', (u) => {
u.root.querySelectorAll('.u-cursor-pt').forEach((el) => { u.root.querySelectorAll<HTMLElement>('.u-cursor-pt').forEach((el) => {
Object.assign((el as HTMLElement).style, { Object.assign(el.style, {
borderRadius: '0', borderRadius: '0',
border: '1px solid white', border: '1px solid white',
background: 'transparent', background: 'transparent',
@ -175,7 +175,7 @@ export function prepConfig(opts: PrepConfigOpts) {
}; };
const hoverEvent = new DataHoverEvent(payload); const hoverEvent = new DataHoverEvent(payload);
let pendingOnleave = 0; let pendingOnleave: ReturnType<typeof setTimeout> | 0;
onhover && onhover &&
builder.addHook('setLegend', (u) => { builder.addHook('setLegend', (u) => {
@ -213,7 +213,7 @@ export function prepConfig(opts: PrepConfigOpts) {
payload.rowIndex = undefined; payload.rowIndex = undefined;
payload.point[xScaleUnit] = null; payload.point[xScaleUnit] = null;
eventBus.publish(hoverEvent); eventBus.publish(hoverEvent);
}, 100) as any; }, 100);
} }
} }
}); });
@ -257,6 +257,7 @@ export function prepConfig(opts: PrepConfigOpts) {
return builder; // early abort (avoids error) return builder; // early abort (avoids error)
} }
// eslint-ignore @typescript-eslint/no-explicit-any
const yFieldConfig = yField.config?.custom as PanelFieldConfig | undefined; const yFieldConfig = yField.config?.custom as PanelFieldConfig | undefined;
const yScale = yFieldConfig?.scaleDistribution ?? { type: ScaleDistribution.Linear }; const yScale = yFieldConfig?.scaleDistribution ?? { type: ScaleDistribution.Linear };
const yAxisReverse = Boolean(yAxisConfig.reverse); const yAxisReverse = Boolean(yAxisConfig.reverse);
@ -394,7 +395,7 @@ export function prepConfig(opts: PrepConfigOpts) {
size: yAxisConfig.axisWidth || null, size: yAxisConfig.axisWidth || null,
label: yAxisConfig.axisLabel, label: yAxisConfig.axisLabel,
theme: theme, theme: theme,
formatValue: (v: any) => formattedValueToString(dispY(v)), formatValue: (v: number) => formattedValueToString(dispY(v)),
splits: isOrdianalY splits: isOrdianalY
? (self: uPlot) => { ? (self: uPlot) => {
const meta = readHeatmapRowsCustomMeta(dataRef.current?.heatmap); const meta = readHeatmapRowsCustomMeta(dataRef.current?.heatmap);
@ -493,7 +494,7 @@ export function prepConfig(opts: PrepConfigOpts) {
index: palette, index: palette,
}, },
}, },
}) as any, }),
theme, theme,
scaleKey: '', // facets' scales used (above) scaleKey: '', // facets' scales used (above)
}); });
@ -525,7 +526,7 @@ export function prepConfig(opts: PrepConfigOpts) {
}, },
}, },
exemplarFillColor exemplarFillColor
) as any, ),
theme, theme,
scaleKey: '', // facets' scales used (above) scaleKey: '', // facets' scales used (above)
}); });
@ -570,6 +571,7 @@ export function prepConfig(opts: PrepConfigOpts) {
if (sync && sync() !== DashboardCursorSync.Off) { if (sync && sync() !== DashboardCursorSync.Off) {
cursor.sync = { cursor.sync = {
key: '__global_', key: '__global_',
scales: [xScaleKey, yScaleKey],
filters: { filters: {
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => { pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
if (x < 0) { if (x < 0) {
@ -705,6 +707,8 @@ export function heatmapPathsDense(opts: PathbuilderOpts) {
return null; return null;
} }
); );
return null;
}; };
} }
@ -765,6 +769,8 @@ export function heatmapPathsPoints(opts: PointsBuilderOpts, exemplarColor: strin
u.ctx.restore(); u.ctx.restore();
} }
); );
return null;
}; };
} }
// accepts xMax, yMin, yMax, count // accepts xMax, yMin, yMax, count
@ -881,10 +887,10 @@ export function heatmapPathsSparse(opts: PathbuilderOpts) {
u.ctx.restore(); u.ctx.restore();
//console.timeEnd('heatmapPathsSparse'); //console.timeEnd('heatmapPathsSparse');
return null;
} }
); );
return null;
}; };
} }