| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // Libraries
- import React, { PureComponent } from 'react';
- // Utils & Services
- import { config } from 'app/core/config';
- // Types
- import { SingleStatOptions } from './types';
- import {
- PanelProps,
- getFieldDisplayValues,
- VizRepeater,
- FieldDisplay,
- BigValue,
- DataLinksContextMenu,
- } from '@grafana/ui';
- import { BigValueSparkline } from '@grafana/ui/src/components/BigValue/BigValue';
- import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
- export class SingleStatPanel extends PureComponent<PanelProps<SingleStatOptions>> {
- renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
- let sparkline: BigValueSparkline;
- if (value.sparkline) {
- const { timeRange, options } = this.props;
- sparkline = {
- ...options.sparkline,
- data: value.sparkline,
- minX: timeRange.from.valueOf(),
- maxX: timeRange.to.valueOf(),
- };
- }
- return (
- <DataLinksContextMenu links={getFieldLinksSupplier(value)}>
- {({ openMenu, targetClassName }) => {
- return (
- <BigValue
- value={value.display}
- sparkline={sparkline}
- width={width}
- height={height}
- theme={config.theme}
- onClick={openMenu}
- className={targetClassName}
- />
- );
- }}
- </DataLinksContextMenu>
- );
- };
- getValues = (): FieldDisplay[] => {
- const { data, options, replaceVariables } = this.props;
- return getFieldDisplayValues({
- ...options,
- replaceVariables,
- theme: config.theme,
- data: data.series,
- sparkline: options.sparkline.show,
- });
- };
- render() {
- const { height, width, options, data, renderCounter } = this.props;
- return (
- <VizRepeater
- getValues={this.getValues}
- renderValue={this.renderValue}
- width={width}
- height={height}
- source={data}
- renderCounter={renderCounter}
- orientation={options.orientation}
- />
- );
- }
- }
|