本文整理汇总了TypeScript中@grafana/ui.getValueFormat函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getValueFormat函数的具体用法?TypeScript getValueFormat怎么用?TypeScript getValueFormat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getValueFormat函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getValueFormat
return value => {
try {
return format !== 'none' ? getValueFormat(format)(value, decimals, scaledDecimals) : value;
} catch (err) {
console.error(err.message || err);
return value;
}
};
示例2: getValueFormat
axis.tickFormatter = (val, axis) => {
const formatter = getValueFormat(format);
if (!formatter) {
throw new Error(`Unit '${format}' is not supported`);
}
return formatter(val, axis.tickDecimals, axis.scaledDecimals);
};
示例3: constructor
constructor(opts) {
this.datapoints = opts.datapoints;
this.label = opts.alias;
this.id = opts.alias;
this.alias = opts.alias;
this.aliasEscaped = _.escape(opts.alias);
this.color = opts.color;
this.bars = { fillColor: opts.color };
this.valueFormater = getValueFormat('none');
this.stats = {};
this.legend = true;
this.unit = opts.unit;
this.hasMsResolution = this.isMsResolutionNeeded();
}
示例4: updateLegendValues
export function updateLegendValues(data: TimeSeries[], panel, height) {
for (let i = 0; i < data.length; i++) {
const series = data[i];
const yaxes = panel.yaxes;
const seriesYAxis = series.yaxis || 1;
const axis = yaxes[seriesYAxis - 1];
const formatter = getValueFormat(axis.format);
// decimal override
if (_.isNumber(panel.decimals)) {
series.updateLegendValues(formatter, panel.decimals, null);
} else if (_.isNumber(axis.decimals)) {
series.updateLegendValues(formatter, axis.decimals + 1, null);
} else {
// auto decimals
// legend and tooltip gets one more decimal precision
// than graph legend ticks
const { datamin, datamax } = getDataMinMax(data);
const { tickDecimals, scaledDecimals } = getFlotTickDecimals(datamin, datamax, axis, height);
const tickDecimalsPlusOne = (tickDecimals || -1) + 1;
series.updateLegendValues(formatter, tickDecimalsPlusOne, scaledDecimals + 2);
}
}
}
示例5: getValueFormats
///// FORMAT MENU /////
kbn.getUnitFormats = () => {
return getValueFormats();
};
//
// Backward compatible layer for value formats to support old plugins
//
if (typeof Proxy !== 'undefined') {
kbn.valueFormats = new Proxy(kbn.valueFormats, {
get(target, name, receiver) {
if (typeof name !== 'string') {
throw { message: `Value format ${String(name)} is not a string` };
}
const formatter = getValueFormat(name);
if (formatter) {
return formatter;
}
// default to look here
return Reflect.get(target, name, receiver);
},
});
} else {
kbn.valueFormats = getValueFormatterIndex();
}
export default kbn;
示例6: createColumnFormatter
createColumnFormatter(column) {
if (!column.style) {
return this.defaultCellFormatter;
}
if (column.style.type === 'hidden') {
return v => {
return undefined;
};
}
if (column.style.type === 'date') {
return v => {
if (v === undefined || v === null) {
return '-';
}
if (_.isArray(v)) {
v = v[0];
}
// if is an epoch (numeric string and len > 12)
if (_.isString(v) && !isNaN(v as any) && v.length > 12) {
v = parseInt(v, 10);
}
let date = dateTime(v);
if (this.isUtc) {
date = date.utc();
}
return date.format(column.style.dateFormat);
};
}
if (column.style.type === 'string') {
return v => {
if (_.isArray(v)) {
v = v.join(', ');
}
const mappingType = column.style.mappingType || 0;
if (mappingType === 1 && column.style.valueMaps) {
for (let i = 0; i < column.style.valueMaps.length; i++) {
const map = column.style.valueMaps[i];
if (v === null) {
if (map.value === 'null') {
return map.text;
}
continue;
}
// Allow both numeric and string values to be mapped
if ((!_.isString(v) && Number(map.value) === Number(v)) || map.value === v) {
this.setColorState(v, column.style);
return this.defaultCellFormatter(map.text, column.style);
}
}
}
if (mappingType === 2 && column.style.rangeMaps) {
for (let i = 0; i < column.style.rangeMaps.length; i++) {
const map = column.style.rangeMaps[i];
if (v === null) {
if (map.from === 'null' && map.to === 'null') {
return map.text;
}
continue;
}
if (Number(map.from) <= Number(v) && Number(map.to) >= Number(v)) {
this.setColorState(v, column.style);
return this.defaultCellFormatter(map.text, column.style);
}
}
}
if (v === null || v === void 0) {
return '-';
}
this.setColorState(v, column.style);
return this.defaultCellFormatter(v, column.style);
};
}
if (column.style.type === 'number') {
const valueFormatter = getValueFormat(column.unit || column.style.unit);
return v => {
if (v === null || v === void 0) {
return '-';
}
if (isNaN(v) || _.isArray(v)) {
return this.defaultCellFormatter(v, column.style);
//.........这里部分代码省略.........
示例7: getValueFormat
return value => {
return getValueFormat(format)(value, decimals, scaledDecimals);
};