From 794333de3ddb7bbe186a4a861143ceee24c7e992 Mon Sep 17 00:00:00 2001 From: Berbe <4251220+Berbe@users.noreply.github.com> Date: Fri, 11 Sep 2020 10:42:54 +0200 Subject: [PATCH] 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 --- .../src/valueFormats/categories.ts | 241 +++++++++--------- .../src/valueFormats/symbolFormatters.ts | 4 +- .../src/valueFormats/valueFormats.ts | 4 +- public/app/core/logs_model.ts | 4 +- .../panel/table-old/specs/renderer.test.ts | 4 +- 5 files changed, 132 insertions(+), 125 deletions(-) diff --git a/packages/grafana-data/src/valueFormats/categories.ts b/packages/grafana-data/src/valueFormats/categories.ts index 3c0eb550c5e..79ffe7cf328 100644 --- a/packages/grafana-data/src/valueFormats/categories.ts +++ b/packages/grafana-data/src/valueFormats/categories.ts @@ -22,7 +22,7 @@ import { toTimeTicks, } from './dateTimeFormatters'; import { toHex, sci, toHex0x, toPercent, toPercentUnit } from './arithmeticFormatters'; -import { binarySIPrefix, currency, decimalSIPrefix } from './symbolFormatters'; +import { binaryPrefix, currency, SIPrefix } from './symbolFormatters'; export const getCategories = (): ValueFormatCategory[] => [ { @@ -75,14 +75,14 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Computation', formats: [ - { name: 'FLOP/s', id: 'flops', fn: decimalSIPrefix('FLOP/s') }, - { name: 'MFLOP/s', id: 'mflops', fn: decimalSIPrefix('FLOP/s', 2) }, - { name: 'GFLOP/s', id: 'gflops', fn: decimalSIPrefix('FLOP/s', 3) }, - { name: 'TFLOP/s', id: 'tflops', fn: decimalSIPrefix('FLOP/s', 4) }, - { name: 'PFLOP/s', id: 'pflops', fn: decimalSIPrefix('FLOP/s', 5) }, - { name: 'EFLOP/s', id: 'eflops', fn: decimalSIPrefix('FLOP/s', 6) }, - { name: 'ZFLOP/s', id: 'zflops', fn: decimalSIPrefix('FLOP/s', 7) }, - { name: 'YFLOP/s', id: 'yflops', fn: decimalSIPrefix('FLOP/s', 8) }, + { name: 'FLOP/s', id: 'flops', fn: SIPrefix('FLOP/s') }, + { name: 'MFLOP/s', id: 'mflops', fn: SIPrefix('FLOP/s', 2) }, + { name: 'GFLOP/s', id: 'gflops', fn: SIPrefix('FLOP/s', 3) }, + { name: 'TFLOP/s', id: 'tflops', fn: SIPrefix('FLOP/s', 4) }, + { name: 'PFLOP/s', id: 'pflops', fn: SIPrefix('FLOP/s', 5) }, + { name: 'EFLOP/s', id: 'eflops', fn: SIPrefix('FLOP/s', 6) }, + { name: 'ZFLOP/s', id: 'zflops', fn: SIPrefix('FLOP/s', 7) }, + { name: 'YFLOP/s', id: 'yflops', fn: SIPrefix('FLOP/s', 8) }, ], }, { @@ -128,45 +128,52 @@ export const getCategories = (): ValueFormatCategory[] => [ ], }, { - name: 'Data (IEC)', + name: 'Data', formats: [ - { name: 'bits(IEC)', id: 'bits', fn: binarySIPrefix('b') }, - { name: 'bytes(IEC)', id: 'bytes', fn: binarySIPrefix('B') }, - { name: 'kibibytes', id: 'kbytes', fn: binarySIPrefix('B', 1) }, - { name: 'mebibytes', id: 'mbytes', fn: binarySIPrefix('B', 2) }, - { name: 'gibibytes', id: 'gbytes', fn: binarySIPrefix('B', 3) }, - { name: 'tebibytes', id: 'tbytes', fn: binarySIPrefix('B', 4) }, - { name: 'pebibytes', id: 'pbytes', fn: binarySIPrefix('B', 5) }, - ], - }, - { - name: 'Data (metric)', - formats: [ - { name: 'bits(Metric)', id: 'decbits', fn: decimalSIPrefix('b') }, - { name: 'bytes(Metric)', id: 'decbytes', fn: decimalSIPrefix('B') }, - { name: 'kilobytes', id: 'deckbytes', fn: decimalSIPrefix('B', 1) }, - { name: 'megabytes', id: 'decmbytes', fn: decimalSIPrefix('B', 2) }, - { name: 'gigabytes', id: 'decgbytes', fn: decimalSIPrefix('B', 3) }, - { name: 'terabytes', id: 'dectbytes', fn: decimalSIPrefix('B', 4) }, - { name: 'petabytes', id: 'decpbytes', fn: decimalSIPrefix('B', 5) }, + { name: 'bytes(IEC)', id: 'bytes', fn: binaryPrefix('B') }, + { name: 'bytes(SI)', id: 'decbytes', fn: SIPrefix('B') }, + { name: 'bits(IEC)', id: 'bits', fn: binaryPrefix('b') }, + { name: 'bits(SI)', id: 'decbits', fn: SIPrefix('b') }, + { name: 'kibibytes', id: 'kbytes', fn: binaryPrefix('B', 1) }, + { name: 'kilobytes', id: 'deckbytes', fn: SIPrefix('B', 1) }, + { name: 'mebibytes', id: 'mbytes', fn: binaryPrefix('B', 2) }, + { name: 'megabytes', id: 'decmbytes', fn: SIPrefix('B', 2) }, + { name: 'gibibytes', id: 'gbytes', fn: binaryPrefix('B', 3) }, + { name: 'gigabytes', id: 'decgbytes', fn: SIPrefix('B', 3) }, + { name: 'tebibytes', id: 'tbytes', fn: binaryPrefix('B', 4) }, + { name: 'terabytes', id: 'dectbytes', fn: SIPrefix('B', 4) }, + { name: 'pebibytes', id: 'pbytes', fn: binaryPrefix('B', 5) }, + { name: 'petabytes', id: 'decpbytes', fn: SIPrefix('B', 5) }, ], }, { name: 'Data rate', formats: [ - { name: 'packets/sec', id: 'pps', fn: decimalSIPrefix('pps') }, - { name: 'bits/sec', id: 'bps', fn: decimalSIPrefix('bps') }, - { name: 'bytes/sec', id: 'Bps', fn: decimalSIPrefix('B/s') }, - { name: 'kilobytes/sec', id: 'KBs', fn: decimalSIPrefix('B/s', 1) }, - { name: 'kilobits/sec', id: 'Kbits', fn: decimalSIPrefix('bps', 1) }, - { name: 'megabytes/sec', id: 'MBs', fn: decimalSIPrefix('B/s', 2) }, - { name: 'megabits/sec', id: 'Mbits', fn: decimalSIPrefix('bps', 2) }, - { name: 'gigabytes/sec', id: 'GBs', fn: decimalSIPrefix('B/s', 3) }, - { name: 'gigabits/sec', id: 'Gbits', fn: decimalSIPrefix('bps', 3) }, - { name: 'terabytes/sec', id: 'TBs', fn: decimalSIPrefix('B/s', 4) }, - { name: 'terabits/sec', id: 'Tbits', fn: decimalSIPrefix('bps', 4) }, - { name: 'petabytes/sec', id: 'PBs', fn: decimalSIPrefix('B/s', 5) }, - { name: 'petabits/sec', id: 'Pbits', fn: decimalSIPrefix('bps', 5) }, + { name: 'packets/sec', id: 'pps', fn: SIPrefix('p/s') }, + { name: 'bytes/sec(IEC)', id: 'Bps', fn: binaryPrefix('B/s') }, + { name: 'bytes/sec(SI)', id: 'decBps', fn: SIPrefix('B/s') }, + { name: 'bits/sec(IEC)', id: 'bps', fn: binaryPrefix('b/s') }, + { name: 'bits/sec(SI)', id: 'decbps', fn: SIPrefix('b/s') }, + { name: 'kibibytes/sec', id: 'KiBs', fn: binaryPrefix('B/s', 1) }, + { name: 'kibibits/sec', id: 'Kibits', fn: binaryPrefix('b/s', 1) }, + { name: 'kilobytes/sec', id: 'KBs', fn: SIPrefix('B/s', 1) }, + { name: 'kilobits/sec', id: 'Kbits', fn: SIPrefix('b/s', 1) }, + { name: 'mibibytes/sec', id: 'MiBs', fn: binaryPrefix('B/s', 2) }, + { name: 'mibibits/sec', id: 'Mibits', fn: binaryPrefix('b/s', 2) }, + { name: 'megabytes/sec', id: 'MBs', fn: SIPrefix('B/s', 2) }, + { name: 'megabits/sec', id: 'Mbits', fn: SIPrefix('b/s', 2) }, + { name: 'gibibytes/sec', id: 'GiBs', fn: binaryPrefix('B/s', 3) }, + { name: 'gibibits/sec', id: 'Gibits', fn: binaryPrefix('b/s', 3) }, + { name: 'gigabytes/sec', id: 'GBs', fn: SIPrefix('B/s', 3) }, + { name: 'gigabits/sec', id: 'Gbits', fn: SIPrefix('b/s', 3) }, + { name: 'tebibytes/sec', id: 'TiBs', fn: binaryPrefix('B/s', 4) }, + { name: 'tebibits/sec', id: 'Tibits', fn: binaryPrefix('b/s', 4) }, + { name: 'terabytes/sec', id: 'TBs', fn: SIPrefix('B/s', 4) }, + { name: 'terabits/sec', id: 'Tbits', fn: SIPrefix('b/s', 4) }, + { name: 'petibytes/sec', id: 'PiBs', fn: binaryPrefix('B/s', 5) }, + { name: 'petibits/sec', id: 'Pibits', fn: binaryPrefix('b/s', 5) }, + { name: 'petabytes/sec', id: 'PBs', fn: SIPrefix('B/s', 5) }, + { name: 'petabits/sec', id: 'Pbits', fn: SIPrefix('b/s', 5) }, ], }, { @@ -183,44 +190,44 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Energy', formats: [ - { name: 'Watt (W)', id: 'watt', fn: decimalSIPrefix('W') }, - { name: 'Kilowatt (kW)', id: 'kwatt', fn: decimalSIPrefix('W', 1) }, - { name: 'Megawatt (MW)', id: 'megwatt', fn: decimalSIPrefix('W', 2) }, - { name: 'Gigawatt (GW)', id: 'gwatt', fn: decimalSIPrefix('W', 3) }, - { name: 'Milliwatt (mW)', id: 'mwatt', fn: decimalSIPrefix('W', -1) }, + { name: 'Watt (W)', id: 'watt', fn: SIPrefix('W') }, + { name: 'Kilowatt (kW)', id: 'kwatt', fn: SIPrefix('W', 1) }, + { name: 'Megawatt (MW)', id: 'megwatt', fn: SIPrefix('W', 2) }, + { name: 'Gigawatt (GW)', id: 'gwatt', fn: SIPrefix('W', 3) }, + { name: 'Milliwatt (mW)', id: 'mwatt', fn: SIPrefix('W', -1) }, { name: 'Watt per square meter (W/m²)', id: 'Wm2', fn: toFixedUnit('W/m²') }, - { name: 'Volt-ampere (VA)', id: 'voltamp', fn: decimalSIPrefix('VA') }, - { name: 'Kilovolt-ampere (kVA)', id: 'kvoltamp', fn: decimalSIPrefix('VA', 1) }, - { name: 'Volt-ampere reactive (var)', id: 'voltampreact', fn: decimalSIPrefix('var') }, - { name: 'Kilovolt-ampere reactive (kvar)', id: 'kvoltampreact', fn: decimalSIPrefix('var', 1) }, - { name: 'Watt-hour (Wh)', id: 'watth', fn: decimalSIPrefix('Wh') }, - { name: 'Watt-hour per Kilogram (Wh/kg)', id: 'watthperkg', fn: decimalSIPrefix('Wh/kg') }, - { name: 'Kilowatt-hour (kWh)', id: 'kwatth', fn: decimalSIPrefix('Wh', 1) }, - { name: 'Kilowatt-min (kWm)', id: 'kwattm', fn: decimalSIPrefix('W-Min', 1) }, - { name: 'Ampere-hour (Ah)', id: 'amph', fn: decimalSIPrefix('Ah') }, - { name: 'Kiloampere-hour (kAh)', id: 'kamph', fn: decimalSIPrefix('Ah', 1) }, - { name: 'Milliampere-hour (mAh)', id: 'mamph', fn: decimalSIPrefix('Ah', -1) }, - { name: 'Joule (J)', id: 'joule', fn: decimalSIPrefix('J') }, - { name: 'Electron volt (eV)', id: 'ev', fn: decimalSIPrefix('eV') }, - { name: 'Ampere (A)', id: 'amp', fn: decimalSIPrefix('A') }, - { name: 'Kiloampere (kA)', id: 'kamp', fn: decimalSIPrefix('A', 1) }, - { name: 'Milliampere (mA)', id: 'mamp', fn: decimalSIPrefix('A', -1) }, - { name: 'Volt (V)', id: 'volt', fn: decimalSIPrefix('V') }, - { name: 'Kilovolt (kV)', id: 'kvolt', fn: decimalSIPrefix('V', 1) }, - { name: 'Millivolt (mV)', id: 'mvolt', fn: decimalSIPrefix('V', -1) }, - { name: 'Decibel-milliwatt (dBm)', id: 'dBm', fn: decimalSIPrefix('dBm') }, - { name: 'Ohm (Ω)', id: 'ohm', fn: decimalSIPrefix('Ω') }, - { name: 'Kiloohm (kΩ)', id: 'kohm', fn: decimalSIPrefix('Ω', 1) }, - { name: 'Megaohm (MΩ)', id: 'Mohm', fn: decimalSIPrefix('Ω', 2) }, - { name: 'Farad (F)', id: 'farad', fn: decimalSIPrefix('F') }, - { name: 'Microfarad (µF)', id: 'µfarad', fn: decimalSIPrefix('F', -2) }, - { name: 'Nanofarad (nF)', id: 'nfarad', fn: decimalSIPrefix('F', -3) }, - { name: 'Picofarad (pF)', id: 'pfarad', fn: decimalSIPrefix('F', -4) }, - { name: 'Femtofarad (fF)', id: 'ffarad', fn: decimalSIPrefix('F', -5) }, - { name: 'Henry (H)', id: 'henry', fn: decimalSIPrefix('H') }, - { name: 'Millihenry (mH)', id: 'mhenry', fn: decimalSIPrefix('H', -1) }, - { name: 'Microhenry (µH)', id: 'µhenry', fn: decimalSIPrefix('H', -2) }, - { name: 'Lumens (Lm)', id: 'lumens', fn: decimalSIPrefix('Lm') }, + { name: 'Volt-ampere (VA)', id: 'voltamp', fn: SIPrefix('VA') }, + { name: 'Kilovolt-ampere (kVA)', id: 'kvoltamp', fn: SIPrefix('VA', 1) }, + { name: 'Volt-ampere reactive (var)', id: 'voltampreact', fn: SIPrefix('var') }, + { name: 'Kilovolt-ampere reactive (kvar)', id: 'kvoltampreact', fn: SIPrefix('var', 1) }, + { name: 'Watt-hour (Wh)', id: 'watth', fn: SIPrefix('Wh') }, + { name: 'Watt-hour per Kilogram (Wh/kg)', id: 'watthperkg', fn: SIPrefix('Wh/kg') }, + { name: 'Kilowatt-hour (kWh)', id: 'kwatth', fn: SIPrefix('Wh', 1) }, + { name: 'Kilowatt-min (kWm)', id: 'kwattm', fn: SIPrefix('W-Min', 1) }, + { name: 'Ampere-hour (Ah)', id: 'amph', fn: SIPrefix('Ah') }, + { name: 'Kiloampere-hour (kAh)', id: 'kamph', fn: SIPrefix('Ah', 1) }, + { name: 'Milliampere-hour (mAh)', id: 'mamph', fn: SIPrefix('Ah', -1) }, + { name: 'Joule (J)', id: 'joule', fn: SIPrefix('J') }, + { name: 'Electron volt (eV)', id: 'ev', fn: SIPrefix('eV') }, + { name: 'Ampere (A)', id: 'amp', fn: SIPrefix('A') }, + { name: 'Kiloampere (kA)', id: 'kamp', fn: SIPrefix('A', 1) }, + { name: 'Milliampere (mA)', id: 'mamp', fn: SIPrefix('A', -1) }, + { name: 'Volt (V)', id: 'volt', fn: SIPrefix('V') }, + { name: 'Kilovolt (kV)', id: 'kvolt', fn: SIPrefix('V', 1) }, + { name: 'Millivolt (mV)', id: 'mvolt', fn: SIPrefix('V', -1) }, + { name: 'Decibel-milliwatt (dBm)', id: 'dBm', fn: SIPrefix('dBm') }, + { name: 'Ohm (Ω)', id: 'ohm', fn: SIPrefix('Ω') }, + { name: 'Kiloohm (kΩ)', id: 'kohm', fn: SIPrefix('Ω', 1) }, + { name: 'Megaohm (MΩ)', id: 'Mohm', fn: SIPrefix('Ω', 2) }, + { name: 'Farad (F)', id: 'farad', fn: SIPrefix('F') }, + { name: 'Microfarad (µF)', id: 'µfarad', fn: SIPrefix('F', -2) }, + { name: 'Nanofarad (nF)', id: 'nfarad', fn: SIPrefix('F', -3) }, + { name: 'Picofarad (pF)', id: 'pfarad', fn: SIPrefix('F', -4) }, + { name: 'Femtofarad (fF)', id: 'ffarad', fn: SIPrefix('F', -5) }, + { name: 'Henry (H)', id: 'henry', fn: SIPrefix('H') }, + { name: 'Millihenry (mH)', id: 'mhenry', fn: SIPrefix('H', -1) }, + { name: 'Microhenry (µH)', id: 'µhenry', fn: SIPrefix('H', -2) }, + { name: 'Lumens (Lm)', id: 'lumens', fn: SIPrefix('Lm') }, ], }, { @@ -239,50 +246,50 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Force', formats: [ - { name: 'Newton-meters (Nm)', id: 'forceNm', fn: decimalSIPrefix('Nm') }, - { name: 'Kilonewton-meters (kNm)', id: 'forcekNm', fn: decimalSIPrefix('Nm', 1) }, - { name: 'Newtons (N)', id: 'forceN', fn: decimalSIPrefix('N') }, - { name: 'Kilonewtons (kN)', id: 'forcekN', fn: decimalSIPrefix('N', 1) }, + { name: 'Newton-meters (Nm)', id: 'forceNm', fn: SIPrefix('Nm') }, + { name: 'Kilonewton-meters (kNm)', id: 'forcekNm', fn: SIPrefix('Nm', 1) }, + { name: 'Newtons (N)', id: 'forceN', fn: SIPrefix('N') }, + { name: 'Kilonewtons (kN)', id: 'forcekN', fn: SIPrefix('N', 1) }, ], }, { name: 'Hash rate', formats: [ - { name: 'hashes/sec', id: 'Hs', fn: decimalSIPrefix('H/s') }, - { name: 'kilohashes/sec', id: 'KHs', fn: decimalSIPrefix('H/s', 1) }, - { name: 'megahashes/sec', id: 'MHs', fn: decimalSIPrefix('H/s', 2) }, - { name: 'gigahashes/sec', id: 'GHs', fn: decimalSIPrefix('H/s', 3) }, - { name: 'terahashes/sec', id: 'THs', fn: decimalSIPrefix('H/s', 4) }, - { name: 'petahashes/sec', id: 'PHs', fn: decimalSIPrefix('H/s', 5) }, - { name: 'exahashes/sec', id: 'EHs', fn: decimalSIPrefix('H/s', 6) }, + { name: 'hashes/sec', id: 'Hs', fn: SIPrefix('H/s') }, + { name: 'kilohashes/sec', id: 'KHs', fn: SIPrefix('H/s', 1) }, + { name: 'megahashes/sec', id: 'MHs', fn: SIPrefix('H/s', 2) }, + { name: 'gigahashes/sec', id: 'GHs', fn: SIPrefix('H/s', 3) }, + { name: 'terahashes/sec', id: 'THs', fn: SIPrefix('H/s', 4) }, + { name: 'petahashes/sec', id: 'PHs', fn: SIPrefix('H/s', 5) }, + { name: 'exahashes/sec', id: 'EHs', fn: SIPrefix('H/s', 6) }, ], }, { name: 'Mass', formats: [ - { name: 'milligram (mg)', id: 'massmg', fn: decimalSIPrefix('g', -1) }, - { name: 'gram (g)', id: 'massg', fn: decimalSIPrefix('g') }, - { name: 'kilogram (kg)', id: 'masskg', fn: decimalSIPrefix('g', 1) }, + { name: 'milligram (mg)', id: 'massmg', fn: SIPrefix('g', -1) }, + { name: 'gram (g)', id: 'massg', fn: SIPrefix('g') }, + { name: 'kilogram (kg)', id: 'masskg', fn: SIPrefix('g', 1) }, { name: 'metric ton (t)', id: 'masst', fn: toFixedUnit('t') }, ], }, { name: 'Length', formats: [ - { name: 'millimeter (mm)', id: 'lengthmm', fn: decimalSIPrefix('m', -1) }, + { name: 'millimeter (mm)', id: 'lengthmm', fn: SIPrefix('m', -1) }, { name: 'feet (ft)', id: 'lengthft', fn: toFixedUnit('ft') }, - { name: 'meter (m)', id: 'lengthm', fn: decimalSIPrefix('m') }, - { name: 'kilometer (km)', id: 'lengthkm', fn: decimalSIPrefix('m', 1) }, + { name: 'meter (m)', id: 'lengthm', fn: SIPrefix('m') }, + { name: 'kilometer (km)', id: 'lengthkm', fn: SIPrefix('m', 1) }, { name: 'mile (mi)', id: 'lengthmi', fn: toFixedUnit('mi') }, ], }, { name: 'Pressure', formats: [ - { name: 'Millibars', id: 'pressurembar', fn: decimalSIPrefix('bar', -1) }, - { name: 'Bars', id: 'pressurebar', fn: decimalSIPrefix('bar') }, - { name: 'Kilobars', id: 'pressurekbar', fn: decimalSIPrefix('bar', 1) }, - { name: 'Pascals', id: 'pressurepa', fn: decimalSIPrefix('Pa') }, + { name: 'Millibars', id: 'pressurembar', fn: SIPrefix('bar', -1) }, + { name: 'Bars', id: 'pressurebar', fn: SIPrefix('bar') }, + { name: 'Kilobars', id: 'pressurekbar', fn: SIPrefix('bar', 1) }, + { name: 'Pascals', id: 'pressurepa', fn: SIPrefix('Pa') }, { name: 'Hectopascals', id: 'pressurehpa', fn: toFixedUnit('hPa') }, { name: 'Kilopascals', id: 'pressurekpa', fn: toFixedUnit('kPa') }, { name: 'Inches of mercury', id: 'pressurehg', fn: toFixedUnit('"Hg') }, @@ -292,26 +299,26 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Radiation', formats: [ - { name: 'Becquerel (Bq)', id: 'radbq', fn: decimalSIPrefix('Bq') }, - { name: 'curie (Ci)', id: 'radci', fn: decimalSIPrefix('Ci') }, - { name: 'Gray (Gy)', id: 'radgy', fn: decimalSIPrefix('Gy') }, - { name: 'rad', id: 'radrad', fn: decimalSIPrefix('rad') }, - { name: 'Sievert (Sv)', id: 'radsv', fn: decimalSIPrefix('Sv') }, - { name: 'milliSievert (mSv)', id: 'radmsv', fn: decimalSIPrefix('Sv', -1) }, - { name: 'microSievert (µSv)', id: 'radusv', fn: decimalSIPrefix('Sv', -2) }, - { name: 'rem', id: 'radrem', fn: decimalSIPrefix('rem') }, - { name: 'Exposure (C/kg)', id: 'radexpckg', fn: decimalSIPrefix('C/kg') }, - { name: 'roentgen (R)', id: 'radr', fn: decimalSIPrefix('R') }, - { name: 'Sievert/hour (Sv/h)', id: 'radsvh', fn: decimalSIPrefix('Sv/h') }, - { name: 'milliSievert/hour (mSv/h)', id: 'radmsvh', fn: decimalSIPrefix('Sv/h', -1) }, - { name: 'microSievert/hour (µSv/h)', id: 'radusvh', fn: decimalSIPrefix('Sv/h', -2) }, + { name: 'Becquerel (Bq)', id: 'radbq', fn: SIPrefix('Bq') }, + { name: 'curie (Ci)', id: 'radci', fn: SIPrefix('Ci') }, + { name: 'Gray (Gy)', id: 'radgy', fn: SIPrefix('Gy') }, + { name: 'rad', id: 'radrad', fn: SIPrefix('rad') }, + { name: 'Sievert (Sv)', id: 'radsv', fn: SIPrefix('Sv') }, + { name: 'milliSievert (mSv)', id: 'radmsv', fn: SIPrefix('Sv', -1) }, + { name: 'microSievert (µSv)', id: 'radusv', fn: SIPrefix('Sv', -2) }, + { name: 'rem', id: 'radrem', fn: SIPrefix('rem') }, + { name: 'Exposure (C/kg)', id: 'radexpckg', fn: SIPrefix('C/kg') }, + { name: 'roentgen (R)', id: 'radr', fn: SIPrefix('R') }, + { name: 'Sievert/hour (Sv/h)', id: 'radsvh', fn: SIPrefix('Sv/h') }, + { name: 'milliSievert/hour (mSv/h)', id: 'radmsvh', fn: SIPrefix('Sv/h', -1) }, + { name: 'microSievert/hour (µSv/h)', id: 'radusvh', fn: SIPrefix('Sv/h', -2) }, ], }, { name: 'Rotational Speed', formats: [ { name: 'Revolutions per minute (rpm)', id: 'rotrpm', fn: toFixedUnit('rpm') }, - { name: 'Hertz (Hz)', id: 'rothz', fn: decimalSIPrefix('Hz') }, + { name: 'Hertz (Hz)', id: 'rothz', fn: SIPrefix('Hz') }, { name: 'Radians per second (rad/s)', id: 'rotrads', fn: toFixedUnit('rad/s') }, { name: 'Degrees per second (°/s)', id: 'rotdegs', fn: toFixedUnit('°/s') }, ], @@ -327,7 +334,7 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Time', formats: [ - { name: 'Hertz (1/s)', id: 'hertz', fn: decimalSIPrefix('Hz') }, + { name: 'Hertz (1/s)', id: 'hertz', fn: SIPrefix('Hz') }, { name: 'nanoseconds (ns)', id: 'ns', fn: toNanoSeconds }, { name: 'microseconds (µs)', id: 'µs', fn: toMicroSeconds }, { name: 'milliseconds (ms)', id: 'ms', fn: toMilliSeconds }, @@ -371,8 +378,8 @@ export const getCategories = (): ValueFormatCategory[] => [ { name: 'Volume', formats: [ - { name: 'millilitre (mL)', id: 'mlitre', fn: decimalSIPrefix('L', -1) }, - { name: 'litre (L)', id: 'litre', fn: decimalSIPrefix('L') }, + { name: 'millilitre (mL)', id: 'mlitre', fn: SIPrefix('L', -1) }, + { name: 'litre (L)', id: 'litre', fn: SIPrefix('L') }, { name: 'cubic meter', id: 'm3', fn: toFixedUnit('m³') }, { name: 'Normal cubic meter', id: 'Nm3', fn: toFixedUnit('Nm³') }, { name: 'cubic decimeter', id: 'dm3', fn: toFixedUnit('dm³') }, diff --git a/packages/grafana-data/src/valueFormats/symbolFormatters.ts b/packages/grafana-data/src/valueFormats/symbolFormatters.ts index cd3a29707b4..e1ea4d4eeba 100644 --- a/packages/grafana-data/src/valueFormats/symbolFormatters.ts +++ b/packages/grafana-data/src/valueFormats/symbolFormatters.ts @@ -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 => { diff --git a/packages/grafana-data/src/valueFormats/valueFormats.ts b/packages/grafana-data/src/valueFormats/valueFormats.ts index 425ff847ab8..695bf53659b 100644 --- a/packages/grafana-data/src/valueFormats/valueFormats.ts +++ b/packages/grafana-data/src/valueFormats/valueFormats.ts @@ -1,7 +1,7 @@ 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') { diff --git a/public/app/core/logs_model.ts b/public/app/core/logs_model.ts index a6fee79c96a..2f16f4941f6 100644 --- a/public/app/core/logs_model.ts +++ b/public/app/core/logs_model.ts @@ -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}`, diff --git a/public/app/plugins/panel/table-old/specs/renderer.test.ts b/public/app/plugins/panel/table-old/specs/renderer.test.ts index d99e9af7059..1cc83b1cae2 100644 --- a/public/app/plugins/panel/table-old/specs/renderer.test.ts +++ b/public/app/plugins/panel/table-old/specs/renderer.test.ts @@ -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('1.23 kbps'); + expect(html).toBe('1.23 kb/s'); }); it('number column should be formated', () => {