Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let minDistance, minTime;
for (i = 0; i < yAxisDimensions.length; i++) {
field = yAxisDimensions[i];
const time = xAxisDimensions[i];
hoverIndex = findHoverIndexFromData(time, xAxisPosition);
hoverDistance = xAxisPosition - time.values.get(hoverIndex);
pointTime = time.values.get(hoverIndex);
// Take the closest point before the cursor, or if it does not exist, the closest after
if (
minDistance === undefined ||
(hoverDistance >= 0 && (hoverDistance < minDistance || minDistance < 0)) ||
(hoverDistance < 0 && hoverDistance > minDistance)
) {
minDistance = hoverDistance;
minTime = time.display ? formattedValueToString(time.display(pointTime)) : pointTime;
}
const display = field.display ?? getDisplayProcessor({ field });
const disp = display(field.values.get(hoverIndex));
results.push({
value: formattedValueToString(disp),
datapointIndex: hoverIndex,
seriesIndex: i,
color: disp.color,
label: field.name,
time: time.display ? formattedValueToString(time.display(pointTime)) : pointTime,
});
}
return {
formatValue(value: number) {
if (!_.isFinite(value)) {
value = null; // Prevent NaN formatting
}
return formattedValueToString(this.valueFormater(value, this.decimals, this.scaledDecimals));
}
formatValue(value: number) {
if (!_.isFinite(value)) {
value = null; // Prevent NaN formatting
}
return formattedValueToString(this.valueFormater(value, this.decimals, this.scaledDecimals));
}
return (value: any) => {
try {
if (format !== 'none') {
const v = getValueFormat(format)(value, decimals, scaledDecimals);
return formattedValueToString(v);
}
} catch (err) {
console.error(err.message || err);
}
return value;
};
}
function getValueText() {
const data: ShowData = ctrl.data;
let result = panel.prefix ? templateSrv.replace(panel.prefix, data.scopedVars) : '';
result += formattedValueToString(data.display);
result += panel.postfix ? templateSrv.replace(panel.postfix, data.scopedVars) : '';
return result;
}
function getValueText() {
const data: ShowData = ctrl.data;
let result = panel.prefix ? templateSrv.replace(panel.prefix, data.scopedVars) : '';
result += formattedValueToString(data.display);
result += panel.postfix ? templateSrv.replace(panel.postfix, data.scopedVars) : '';
return result;
}
function getBigValueHtml() {
const data: ShowData = ctrl.data;
let body = '<div class="singlestat-panel-value-container">';
if (panel.prefix) {
body += getSpan('singlestat-panel-prefix', panel.prefixFontSize, panel.colorPrefix, panel.prefix);
}
body += getSpan(
'singlestat-panel-value',
panel.valueFontSize,
panel.colorValue,
formattedValueToString(data.display)
);
if (panel.postfix) {
body += getSpan('singlestat-panel-postfix', panel.postfixFontSize, panel.colorPostfix, panel.postfix);
}
body += '</div>';
return body;
}
function getBigValueHtml() {
const data: ShowData = ctrl.data;
let body = '<div class="singlestat-panel-value-container">';
if (panel.prefix) {
body += getSpan('singlestat-panel-prefix', panel.prefixFontSize, panel.colorPrefix, panel.prefix);
}
body += getSpan(
'singlestat-panel-value',
panel.valueFontSize,
panel.colorValue,
formattedValueToString(data.display)
);
if (panel.postfix) {
body += getSpan('singlestat-panel-postfix', panel.postfixFontSize, panel.colorPostfix, panel.postfix);
}
body += '</div>';
return body;
}