grafana/public/app/plugins/panel/nodeGraph/ViewControls.tsx
Andrej Ocenas fdd6620d0a
NodeGraph: Exploration mode (#33623)
* 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>
2021-05-12 16:04:21 +02:00

91 lines
2.6 KiB
TypeScript

import React, { useState } from 'react';
import { Button, HorizontalGroup, VerticalGroup } from '@grafana/ui';
interface Props<Config> {
config: Config;
onConfigChange: (config: Config) => void;
onPlus: () => void;
onMinus: () => void;
scale: number;
disableZoomOut?: boolean;
disableZoomIn?: boolean;
}
/**
* Control buttons for zoom but also some layout config inputs mainly for debugging.
*/
export function ViewControls<Config extends Record<string, any>>(props: Props<Config>) {
const { config, onConfigChange, onPlus, onMinus, disableZoomOut, disableZoomIn } = props;
const [showConfig, setShowConfig] = useState(false);
// For debugging the layout, should be removed here and maybe moved to panel config later on
const allowConfiguration = false;
return (
<div>
<VerticalGroup spacing="sm">
<HorizontalGroup spacing="xs">
<Button
icon={'plus-circle'}
onClick={onPlus}
size={'md'}
title={'Zoom in'}
variant="secondary"
disabled={disableZoomIn}
/>
<Button
icon={'minus-circle'}
onClick={onMinus}
size={'md'}
title={'Zoom out'}
variant="secondary"
disabled={disableZoomOut}
/>
</HorizontalGroup>
<HorizontalGroup spacing="xs">
<Button
icon={'code-branch'}
onClick={() => onConfigChange({ ...config, gridLayout: false })}
size={'md'}
title={'Default layout'}
variant="secondary"
disabled={!config.gridLayout}
/>
<Button
icon={'apps'}
onClick={() => onConfigChange({ ...config, gridLayout: true })}
size={'md'}
title={'Grid layout'}
variant="secondary"
disabled={config.gridLayout}
/>
</HorizontalGroup>
</VerticalGroup>
{allowConfiguration && (
<Button size={'xs'} variant={'link'} onClick={() => setShowConfig((showConfig) => !showConfig)}>
{showConfig ? 'Hide config' : 'Show config'}
</Button>
)}
{allowConfiguration &&
showConfig &&
Object.keys(config)
.filter((k) => k !== 'show')
.map((k) => (
<div key={k}>
{k}
<input
style={{ width: 50 }}
type={'number'}
value={config[k]}
onChange={(e) => {
onConfigChange({ ...config, [k]: parseFloat(e.target.value) });
}}
/>
</div>
))}
</div>
);
}