mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Heatmap: Add datalink support (#71016)
This commit is contained in:
parent
443b4b0327
commit
4ef5c33af9
@ -8,6 +8,9 @@ import {
|
||||
getFieldDisplayName,
|
||||
LinkModel,
|
||||
TimeRange,
|
||||
getLinksSupplier,
|
||||
InterpolateFunction,
|
||||
ScopedVars,
|
||||
} from '@grafana/data';
|
||||
import { HeatmapCellLayout } from '@grafana/schema';
|
||||
import { LinkButton, VerticalGroup } from '@grafana/ui';
|
||||
@ -23,6 +26,8 @@ type Props = {
|
||||
hover: HeatmapHoverEvent;
|
||||
showHistogram?: boolean;
|
||||
timeRange: TimeRange;
|
||||
replaceVars: InterpolateFunction;
|
||||
scopedVars: ScopedVars[];
|
||||
};
|
||||
|
||||
export const HeatmapHoverView = (props: Props) => {
|
||||
@ -32,7 +37,7 @@ export const HeatmapHoverView = (props: Props) => {
|
||||
return <HeatmapHoverCell {...props} />;
|
||||
};
|
||||
|
||||
const HeatmapHoverCell = ({ data, hover, showHistogram }: Props) => {
|
||||
const HeatmapHoverCell = ({ data, hover, showHistogram, scopedVars, replaceVars }: Props) => {
|
||||
const index = hover.dataIdx;
|
||||
const xField = data.heatmap?.fields[0];
|
||||
const yField = data.heatmap?.fields[1];
|
||||
@ -119,7 +124,14 @@ const HeatmapHoverCell = ({ data, hover, showHistogram }: Props) => {
|
||||
const linkLookup = new Set<string>();
|
||||
|
||||
for (const field of visibleFields ?? []) {
|
||||
// TODO: Currently always undefined? (getLinks)
|
||||
const hasLinks = field.config.links && field.config.links.length > 0;
|
||||
if (hasLinks && data.heatmap) {
|
||||
let appropriateScopedVars = scopedVars.filter(
|
||||
(sv) => sv && sv.__dataContext && sv.__dataContext.value.field.name === nonNumericOrdinalDisplay
|
||||
)[0];
|
||||
field.getLinks = getLinksSupplier(data.heatmap, field, appropriateScopedVars ?? {}, replaceVars);
|
||||
}
|
||||
|
||||
if (field.getLinks) {
|
||||
const v = field.values[index];
|
||||
const disp = field.display ? field.display(v) : { text: `${v}`, numeric: +v };
|
||||
|
@ -43,6 +43,16 @@ export const HeatmapPanel = ({
|
||||
const styles = useStyles2(getStyles);
|
||||
const { sync } = usePanelContext();
|
||||
|
||||
// necessary for enabling datalinks in hover view
|
||||
let scopedVarsFromRawData = [];
|
||||
for (const series of data.series) {
|
||||
for (const field of series.fields) {
|
||||
if (field.state?.scopedVars) {
|
||||
scopedVarsFromRawData.push(field.state?.scopedVars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ugh
|
||||
let timeRangeRef = useRef<TimeRange>(timeRange);
|
||||
timeRangeRef.current = timeRange;
|
||||
@ -210,6 +220,8 @@ export const HeatmapPanel = ({
|
||||
data={info}
|
||||
hover={hover}
|
||||
showHistogram={options.tooltip.yHistogram}
|
||||
replaceVars={replaceVariables}
|
||||
scopedVars={scopedVarsFromRawData}
|
||||
/>
|
||||
</VizTooltipContainer>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user