mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Add exploration option to node layout * Add hidden node count * Add grid layout option * Fix panning bounds calculation * Add legend with sorting * Allow sorting on any stats or arc value * Fix merge * Make sorting better * Reset focused node on layout change * Refactor limit hook a bit * Disable selected layout button * Don't show markers if only 1 node is hidden * Move legend to the bottom * Fix text backgrounds * Add show in graph layout action in grid layout * Center view on the focused node, fix perf issue when expanding big graph * Limit the node counting * Comment and linting fixes * Bit of code cleanup and comments * Add state for computing layout * Prevent computing map with partial data * Add rollup plugin for worker * Add rollup plugin for worker * Enhance data from worker * Fix perf issues with reduce and object creation * Improve comment * Fix tests * Css fixes * Remove worker plugin * Add comments * Fix test * Add test for exploration * Add test switching to grid layout * Apply suggestions from code review Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> * Remove unused plugin * Fix function name * Remove unused rollup plugin * Review fixes * Fix context menu shown on layout change * Make buttons bigger * Moved NodeGraph to core grafana Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
26 lines
984 B
TypeScript
26 lines
984 B
TypeScript
import { useMemo } from 'react';
|
|
import { DataFrame } from '@grafana/data';
|
|
|
|
/**
|
|
* As we need 2 dataframes for the service map, one with nodes and one with edges we have to figure out which is which.
|
|
* Right now we do not have any metadata for it so we just check preferredVisualisationType and then column names.
|
|
* TODO: maybe we could use column labels to have a better way to do this
|
|
*/
|
|
export function useCategorizeFrames(series: DataFrame[]) {
|
|
return useMemo(() => {
|
|
const serviceMapFrames = series.filter((frame) => frame.meta?.preferredVisualisationType === 'nodeGraph');
|
|
return serviceMapFrames.reduce(
|
|
(acc, frame) => {
|
|
const sourceField = frame.fields.filter((f) => f.name === 'source');
|
|
if (sourceField.length) {
|
|
acc.edges.push(frame);
|
|
} else {
|
|
acc.nodes.push(frame);
|
|
}
|
|
return acc;
|
|
},
|
|
{ edges: [], nodes: [] } as { nodes: DataFrame[]; edges: DataFrame[] }
|
|
);
|
|
}, [series]);
|
|
}
|