grafana/public/app/plugins/panel/graph2/GraphPanel.tsx
Torkel Ödegaard 28ce2f12ed
Legend/GraphNG: Refactoring legend types and options (#29067)
* Legend/GraphNG: Refactoring legend types and options

* Rename label

* Minor update

* Fixed legend placement crash issue

* remove unused

* Minor tweaks and fixes
2020-11-13 17:08:55 +01:00

72 lines
1.8 KiB
TypeScript

import React from 'react';
import { GraphWithLegend, Chart } from '@grafana/ui';
import { PanelProps } from '@grafana/data';
import { Options } from './types';
import { GraphPanelController } from './GraphPanelController';
interface GraphPanelProps extends PanelProps<Options> {}
export const GraphPanel: React.FunctionComponent<GraphPanelProps> = ({
data,
timeRange,
timeZone,
width,
height,
options,
fieldConfig,
onOptionsChange,
onChangeTimeRange,
}) => {
if (!data) {
return (
<div className="panel-empty">
<p>No data found in response</p>
</div>
);
}
const {
graph: { showLines, showBars, showPoints },
legend: legendOptions,
tooltipOptions,
} = options;
const graphProps = {
showBars,
showLines,
showPoints,
tooltipOptions,
};
return (
<GraphPanelController
data={data}
timeZone={timeZone}
options={options}
fieldConfig={fieldConfig}
onOptionsChange={onOptionsChange}
onChangeTimeRange={onChangeTimeRange}
>
{({ onSeriesToggle, onHorizontalRegionSelected, ...controllerApi }) => {
return (
<GraphWithLegend
timeRange={timeRange}
timeZone={timeZone}
width={width}
height={height}
legendDisplayMode={legendOptions.displayMode}
placement={legendOptions.placement}
sortLegendBy={legendOptions.sortBy}
sortLegendDesc={legendOptions.sortDesc}
onSeriesToggle={onSeriesToggle}
onHorizontalRegionSelected={onHorizontalRegionSelected}
{...graphProps}
{...controllerApi}
>
<Chart.Tooltip mode={tooltipOptions.mode} />
</GraphWithLegend>
);
}}
</GraphPanelController>
);
};