mirror of https://github.com/grafana/grafana
NodeGraph: Support icons for nodes (#60989)
parent
fa35ed8141
commit
78b39bb282
@ -1,12 +1,28 @@ |
||||
export enum NodeGraphDataFrameFieldNames { |
||||
// Unique identifier [required] [nodes + edges]
|
||||
id = 'id', |
||||
// Text to show under the node [nodes]
|
||||
title = 'title', |
||||
// Text to show under the node as second line [nodes]
|
||||
subTitle = 'subtitle', |
||||
// Main value to be shown inside the node [nodes]
|
||||
mainStat = 'mainstat', |
||||
// Second value to be shown inside the node under the mainStat [nodes]
|
||||
secondaryStat = 'secondarystat', |
||||
// Prefix for fields which value will represent part of the color circle around the node, values should add up to 1 [nodes]
|
||||
arc = 'arc__', |
||||
// Will show a named icon inside the node circle if defined. Can be used only with icons already available in
|
||||
// grafana/ui [nodes]
|
||||
icon = 'icon', |
||||
// Defines a single color if string (hex or html named value) or color mode config can be used as threshold or
|
||||
// gradient. arc__ fields must not be defined if used [nodes]
|
||||
color = 'color', |
||||
|
||||
// Id of the source node [required] [edges]
|
||||
source = 'source', |
||||
// Id of the target node [required] [edges]
|
||||
target = 'target', |
||||
|
||||
// Prefix for fields which will be shown in a context menu [nodes + edges]
|
||||
detail = 'detail__', |
||||
arc = 'arc__', |
||||
color = 'color', |
||||
} |
||||
|
@ -0,0 +1,56 @@ |
||||
import { render, screen } from '@testing-library/react'; |
||||
import React from 'react'; |
||||
|
||||
import { ArrayVector, FieldType } from '@grafana/data/src'; |
||||
|
||||
import { Node } from './Node'; |
||||
|
||||
describe('Node', () => { |
||||
it('renders correct data', async () => { |
||||
render( |
||||
<svg> |
||||
<Node |
||||
node={nodeDatum} |
||||
onMouseEnter={() => {}} |
||||
onMouseLeave={() => {}} |
||||
onClick={() => {}} |
||||
hovering={'default'} |
||||
/> |
||||
</svg> |
||||
); |
||||
|
||||
expect(screen.getByText('node title')).toBeInTheDocument(); |
||||
expect(screen.getByText('node subtitle')).toBeInTheDocument(); |
||||
expect(screen.getByText('1234.00')).toBeInTheDocument(); |
||||
expect(screen.getByText('9876.00')).toBeInTheDocument(); |
||||
}); |
||||
|
||||
it('renders icon', async () => { |
||||
render( |
||||
<svg> |
||||
<Node |
||||
node={{ ...nodeDatum, icon: 'database' }} |
||||
onMouseEnter={() => {}} |
||||
onMouseLeave={() => {}} |
||||
onClick={() => {}} |
||||
hovering={'default'} |
||||
/> |
||||
</svg> |
||||
); |
||||
|
||||
expect(screen.getByTestId('node-icon-database')).toBeInTheDocument(); |
||||
}); |
||||
}); |
||||
|
||||
const nodeDatum = { |
||||
x: 0, |
||||
y: 0, |
||||
id: '1', |
||||
title: 'node title', |
||||
subTitle: 'node subtitle', |
||||
dataFrameRowIndex: 0, |
||||
incoming: 0, |
||||
mainStat: { name: 'stat', values: new ArrayVector([1234]), type: FieldType.number, config: {} }, |
||||
secondaryStat: { name: 'stat2', values: new ArrayVector([9876]), type: FieldType.number, config: {} }, |
||||
arcSections: [], |
||||
}; |
Loading…
Reference in new issue