|
|
|
@ -1,45 +1,58 @@ |
|
|
|
|
// Libraries
|
|
|
|
|
import React, { PureComponent } from 'react'; |
|
|
|
|
|
|
|
|
|
// Services & Utils
|
|
|
|
|
import { config } from 'app/core/config'; |
|
|
|
|
|
|
|
|
|
import { BarGauge, VizRepeater, VizRepeaterRenderValueProps, DataLinksContextMenu } from '@grafana/ui'; |
|
|
|
|
import { BarGaugeOptions } from './types'; |
|
|
|
|
import { |
|
|
|
|
getFieldDisplayValues, |
|
|
|
|
DisplayValueAlignmentFactors, |
|
|
|
|
FieldDisplay, |
|
|
|
|
PanelProps, |
|
|
|
|
getDisplayValueAlignmentFactors, |
|
|
|
|
DisplayValueAlignmentFactors, |
|
|
|
|
getFieldDisplayValues, |
|
|
|
|
PanelProps, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
import { BarGauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui'; |
|
|
|
|
|
|
|
|
|
import { config } from 'app/core/config'; |
|
|
|
|
import { BarGaugeOptions } from './types'; |
|
|
|
|
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu'; |
|
|
|
|
|
|
|
|
|
export class BarGaugePanel extends PureComponent<PanelProps<BarGaugeOptions>> { |
|
|
|
|
renderValue = (valueProps: VizRepeaterRenderValueProps<FieldDisplay, DisplayValueAlignmentFactors>): JSX.Element => { |
|
|
|
|
renderComponent = ( |
|
|
|
|
valueProps: VizRepeaterRenderValueProps<FieldDisplay, DisplayValueAlignmentFactors>, |
|
|
|
|
menuProps: DataLinksContextMenuApi |
|
|
|
|
): JSX.Element => { |
|
|
|
|
const { options } = this.props; |
|
|
|
|
const { value, alignmentFactors, orientation, width, height } = valueProps; |
|
|
|
|
const { field, display, view, colIndex } = value; |
|
|
|
|
const { openMenu, targetClassName } = menuProps; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<BarGauge |
|
|
|
|
value={display} |
|
|
|
|
width={width} |
|
|
|
|
height={height} |
|
|
|
|
orientation={orientation} |
|
|
|
|
field={field} |
|
|
|
|
display={view?.getFieldDisplayProcessor(colIndex)} |
|
|
|
|
theme={config.theme} |
|
|
|
|
itemSpacing={this.getItemSpacing()} |
|
|
|
|
displayMode={options.displayMode} |
|
|
|
|
onClick={openMenu} |
|
|
|
|
className={targetClassName} |
|
|
|
|
alignmentFactors={alignmentFactors} |
|
|
|
|
showUnfilled={options.showUnfilled} |
|
|
|
|
/> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
renderValue = (valueProps: VizRepeaterRenderValueProps<FieldDisplay, DisplayValueAlignmentFactors>): JSX.Element => { |
|
|
|
|
const { value } = valueProps; |
|
|
|
|
const { hasLinks, getLinks } = value; |
|
|
|
|
|
|
|
|
|
if (!hasLinks) { |
|
|
|
|
return this.renderComponent(valueProps, {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<DataLinksContextMenu links={value.getLinks}> |
|
|
|
|
{({ openMenu, targetClassName }) => { |
|
|
|
|
return ( |
|
|
|
|
<BarGauge |
|
|
|
|
value={display} |
|
|
|
|
width={width} |
|
|
|
|
height={height} |
|
|
|
|
orientation={orientation} |
|
|
|
|
field={field} |
|
|
|
|
display={view?.getFieldDisplayProcessor(colIndex)} |
|
|
|
|
theme={config.theme} |
|
|
|
|
itemSpacing={this.getItemSpacing()} |
|
|
|
|
displayMode={options.displayMode} |
|
|
|
|
onClick={openMenu} |
|
|
|
|
className={targetClassName} |
|
|
|
|
alignmentFactors={alignmentFactors} |
|
|
|
|
showUnfilled={options.showUnfilled} |
|
|
|
|
/> |
|
|
|
|
); |
|
|
|
|
<DataLinksContextMenu links={getLinks}> |
|
|
|
|
{api => { |
|
|
|
|
return this.renderComponent(valueProps, api); |
|
|
|
|
}} |
|
|
|
|
</DataLinksContextMenu> |
|
|
|
|
); |
|
|
|
|