Commit 794333de by Berbe Committed by GitHub

Binary-prefixed data rates (#27022)

* Dashboard: Merge Data units categories

Prefixes already allow to distinguish IEC units from SI ones
+ Prefer using binary function over decimal one when equal

* Dashboard: Clarify SI & binary prefixes

* Dashboard: Homogeneise rate units

* Dashboard: Add Binary (IEC) prefix for data rates
parent 4167f9d8
......@@ -53,7 +53,7 @@ export function getOffsetFromSIPrefix(c: string): number {
return 0;
}
export function binarySIPrefix(unit: string, offset = 0): ValueFormatter {
export function binaryPrefix(unit: string, offset = 0): ValueFormatter {
const prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
const units = prefixes.map(p => {
return ' ' + p + unit;
......@@ -61,7 +61,7 @@ export function binarySIPrefix(unit: string, offset = 0): ValueFormatter {
return scaledUnits(1024, units);
}
export function decimalSIPrefix(unit: string, offset = 0): ValueFormatter {
export function SIPrefix(unit: string, offset = 0): ValueFormatter {
let prefixes = ['f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
prefixes = prefixes.slice(5 + (offset || 0));
const units = prefixes.map(p => {
......
import { getCategories } from './categories';
import { DecimalCount } from '../types/displayValue';
import { toDateTimeValueFormatter } from './dateTimeFormatters';
import { getOffsetFromSIPrefix, decimalSIPrefix, currency } from './symbolFormatters';
import { getOffsetFromSIPrefix, SIPrefix, currency } from './symbolFormatters';
import { TimeZone } from '../types';
export interface FormattedValue {
......@@ -213,7 +213,7 @@ export function getValueFormat(id?: string | null): ValueFormatter {
if (key === 'si') {
const offset = getOffsetFromSIPrefix(sub.charAt(0));
const unit = offset === 0 ? sub : sub.substring(1);
return decimalSIPrefix(unit, offset);
return SIPrefix(unit, offset);
}
if (key === 'count') {
......
......@@ -33,7 +33,7 @@ import {
import { getThemeColor } from 'app/core/utils/colors';
import { deduplicateLogRowsById } from 'app/core/utils/explore';
import { decimalSIPrefix } from '@grafana/data/src/valueFormats/symbolFormatters';
import { SIPrefix } from '@grafana/data/src/valueFormats/symbolFormatters';
export const LogLevelColor = {
[LogLevel.critical]: colors[7],
......@@ -437,7 +437,7 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
}
if (totalBytes > 0) {
const { text, suffix } = decimalSIPrefix('B')(totalBytes);
const { text, suffix } = SIPrefix('B')(totalBytes);
meta.push({
label: 'Total bytes processed',
value: `${text} ${suffix}`,
......
......@@ -33,7 +33,7 @@ describe('when rendering table', () => {
{ text: 'Colored' },
{ text: 'Undefined' },
{ text: 'String' },
{ text: 'United', unit: 'bps' },
{ text: 'United', unit: 'decbps' },
{ text: 'Sanitized' },
{ text: 'Link' },
{ text: 'Array' },
......@@ -246,7 +246,7 @@ describe('when rendering table', () => {
it('number column with unit specified should ignore style unit', () => {
const html = renderer.renderCell(5, 0, 1230);
expect(html).toBe('<td>1.23 kbps</td>');
expect(html).toBe('<td>1.23 kb/s</td>');
});
it('number column should be formated', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment