Fix tooltip unit when legend isn't shown (#10348)

* graph: fix tooltip unit when legend isn't shown, #10311

* fix broken tests (updateLegendValues() function)
This commit is contained in:
Alexander Zobnin 2017-12-27 11:50:51 +03:00 committed by Torkel Ödegaard
parent c8f87a3d09
commit 1108101087
3 changed files with 6 additions and 11 deletions

View File

@ -28,9 +28,10 @@ export function updateLegendValues(data: TimeSeries[], panel) {
for (let i = 0; i < data.length; i++) {
let series = data[i];
let yaxes = panel.yaxes;
let axis = yaxes[series.yaxis - 1];
const seriesYAxis = series.yaxis || 1;
let axis = yaxes[seriesYAxis - 1];
let { tickDecimals, scaledDecimals } = getFlotTickDecimals(data, axis);
let formater = kbn.valueFormats[panel.yaxes[series.yaxis - 1].format];
let formater = kbn.valueFormats[panel.yaxes[seriesYAxis - 1].format];
// decimal override
if (_.isNumber(panel.decimals)) {

View File

@ -13,7 +13,7 @@ import _ from 'lodash';
import moment from 'moment';
import kbn from 'app/core/utils/kbn';
import { tickStep } from 'app/core/utils/ticks';
import { appEvents, coreModule } from 'app/core/core';
import { appEvents, coreModule, updateLegendValues } from 'app/core/core';
import GraphTooltip from './graph_tooltip';
import { ThresholdManager } from './threshold_manager';
import { EventManager } from 'app/features/annotations/all';
@ -62,6 +62,8 @@ function graphDirective(timeSrv, popoverSrv, contextSrv) {
}
annotations = ctrl.annotations || [];
buildFlotPairs(data);
updateLegendValues(data, panel);
ctrl.events.emit('render-legend');
});

View File

@ -2,7 +2,6 @@ import angular from 'angular';
import _ from 'lodash';
import $ from 'jquery';
import PerfectScrollbar from 'perfect-scrollbar';
import { updateLegendValues } from 'app/core/core';
var module = angular.module('grafana.directives');
@ -31,10 +30,6 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
ctrl.events.emit('legend-rendering-complete');
});
function updateLegendDecimals() {
updateLegendValues(data, panel);
}
function getSeriesIndexForElement(el) {
return el.parents('[data-series-index]').data('series-index');
}
@ -166,10 +161,7 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
// render first time for getting proper legend height
if (!panel.legend.rightSide) {
renderLegendElement(tableHeaderElem);
updateLegendDecimals();
elem.empty();
} else {
updateLegendDecimals();
}
renderLegendElement(tableHeaderElem);