mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 14:42:18 +08: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>
196 lines
4.4 KiB
TypeScript
196 lines
4.4 KiB
TypeScript
import { ArrayVector, createTheme } from '@grafana/data';
|
|
import { makeEdgesDataFrame, makeNodesDataFrame, processNodes } from './utils';
|
|
|
|
describe('processNodes', () => {
|
|
const theme = createTheme();
|
|
|
|
it('handles empty args', async () => {
|
|
expect(processNodes(undefined, undefined, theme)).toEqual({ nodes: [], edges: [] });
|
|
});
|
|
|
|
it('returns proper nodes and edges', async () => {
|
|
const { nodes, edges, legend } = processNodes(
|
|
makeNodesDataFrame(3),
|
|
makeEdgesDataFrame([
|
|
[0, 1],
|
|
[0, 2],
|
|
[1, 2],
|
|
]),
|
|
theme
|
|
);
|
|
|
|
expect(nodes).toEqual([
|
|
{
|
|
arcSections: [
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'green',
|
|
},
|
|
},
|
|
name: 'arc__success',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'red',
|
|
},
|
|
},
|
|
name: 'arc__errors',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
],
|
|
color: 'rgb(226, 192, 61)',
|
|
dataFrameRowIndex: 0,
|
|
id: '0',
|
|
incoming: 0,
|
|
mainStat: {
|
|
config: {},
|
|
index: 3,
|
|
name: 'mainStat',
|
|
type: 'number',
|
|
values: new ArrayVector([0.1, 0.1, 0.1]),
|
|
},
|
|
secondaryStat: {
|
|
config: {},
|
|
index: 4,
|
|
name: 'secondaryStat',
|
|
type: 'number',
|
|
values: new ArrayVector([2, 2, 2]),
|
|
},
|
|
subTitle: 'service',
|
|
title: 'service:0',
|
|
},
|
|
{
|
|
arcSections: [
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'green',
|
|
},
|
|
},
|
|
name: 'arc__success',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'red',
|
|
},
|
|
},
|
|
name: 'arc__errors',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
],
|
|
color: 'rgb(226, 192, 61)',
|
|
dataFrameRowIndex: 1,
|
|
id: '1',
|
|
incoming: 1,
|
|
mainStat: {
|
|
config: {},
|
|
index: 3,
|
|
name: 'mainStat',
|
|
type: 'number',
|
|
values: new ArrayVector([0.1, 0.1, 0.1]),
|
|
},
|
|
secondaryStat: {
|
|
config: {},
|
|
index: 4,
|
|
name: 'secondaryStat',
|
|
type: 'number',
|
|
values: new ArrayVector([2, 2, 2]),
|
|
},
|
|
subTitle: 'service',
|
|
title: 'service:1',
|
|
},
|
|
{
|
|
arcSections: [
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'green',
|
|
},
|
|
},
|
|
name: 'arc__success',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
{
|
|
config: {
|
|
color: {
|
|
fixedColor: 'red',
|
|
},
|
|
},
|
|
name: 'arc__errors',
|
|
type: 'number',
|
|
values: new ArrayVector([0.5, 0.5, 0.5]),
|
|
},
|
|
],
|
|
color: 'rgb(226, 192, 61)',
|
|
dataFrameRowIndex: 2,
|
|
id: '2',
|
|
incoming: 2,
|
|
mainStat: {
|
|
config: {},
|
|
index: 3,
|
|
name: 'mainStat',
|
|
type: 'number',
|
|
values: new ArrayVector([0.1, 0.1, 0.1]),
|
|
},
|
|
secondaryStat: {
|
|
config: {},
|
|
index: 4,
|
|
name: 'secondaryStat',
|
|
type: 'number',
|
|
values: new ArrayVector([2, 2, 2]),
|
|
},
|
|
subTitle: 'service',
|
|
title: 'service:2',
|
|
},
|
|
]);
|
|
|
|
expect(edges).toEqual([
|
|
{
|
|
dataFrameRowIndex: 0,
|
|
id: '0--1',
|
|
mainStat: '',
|
|
secondaryStat: '',
|
|
source: '0',
|
|
target: '1',
|
|
},
|
|
{
|
|
dataFrameRowIndex: 1,
|
|
id: '0--2',
|
|
mainStat: '',
|
|
secondaryStat: '',
|
|
source: '0',
|
|
target: '2',
|
|
},
|
|
{
|
|
dataFrameRowIndex: 2,
|
|
id: '1--2',
|
|
mainStat: '',
|
|
secondaryStat: '',
|
|
source: '1',
|
|
target: '2',
|
|
},
|
|
]);
|
|
|
|
expect(legend).toEqual([
|
|
{
|
|
color: 'green',
|
|
name: 'arc__success',
|
|
},
|
|
{
|
|
color: 'red',
|
|
name: 'arc__errors',
|
|
},
|
|
]);
|
|
});
|
|
});
|