UNPKG

@grafana/ui

Version:
65 lines (62 loc) 2.09 kB
import { jsx } from 'react/jsx-runtime'; import { ThresholdsMode, getFieldConfigWithMinMax, VizOrientation } from '@grafana/data'; import { BarGaugeDisplayMode, TableCellDisplayMode, BarGaugeValueMode } from '@grafana/schema'; import { BarGauge } from '../../../BarGauge/BarGauge.mjs'; import { MaybeWrapWithLink } from '../components/MaybeWrapWithLink.mjs'; import { TABLE } from '../constants.mjs'; import { getCellOptions, getAlignmentFactor } from '../utils.mjs'; "use strict"; const defaultScale = { mode: ThresholdsMode.Absolute, steps: [ { color: "blue", value: -Infinity }, { color: "green", value: 20 } ] }; const BarGaugeCell = ({ value, field, theme, height, width, rowIdx }) => { var _a; const displayValue = field.display(value); const cellOptions = getCellOptions(field); const heightOffset = TABLE.CELL_PADDING * 2; let config = getFieldConfigWithMinMax(field, false); if (!config.thresholds) { config = { ...config, thresholds: defaultScale }; } let barGaugeMode = BarGaugeDisplayMode.Gradient; let valueDisplayMode = void 0; if (cellOptions.type === TableCellDisplayMode.Gauge) { barGaugeMode = (_a = cellOptions.mode) != null ? _a : BarGaugeDisplayMode.Gradient; valueDisplayMode = cellOptions.valueDisplayMode !== void 0 ? cellOptions.valueDisplayMode : BarGaugeValueMode.Text; } const alignmentFactors = getAlignmentFactor(field, displayValue, rowIdx); const renderedHeight = Math.min(height - heightOffset, TABLE.MAX_CELL_HEIGHT); return /* @__PURE__ */ jsx(MaybeWrapWithLink, { field, rowIdx, children: /* @__PURE__ */ jsx( BarGauge, { width, height: renderedHeight, field: config, display: field.display, text: { valueSize: 14 }, value: displayValue, orientation: VizOrientation.Horizontal, theme, alignmentFactors, itemSpacing: 1, lcdCellWidth: 8, displayMode: barGaugeMode, valueDisplayMode } ) }); }; export { BarGaugeCell }; //# sourceMappingURL=BarGaugeCell.mjs.map