diff --git a/public/app/core/utils/ticks.ts b/public/app/core/utils/ticks.ts index fa68b04d614..b033e9247a1 100644 --- a/public/app/core/utils/ticks.ts +++ b/public/app/core/utils/ticks.ts @@ -29,3 +29,39 @@ export function tickStep(start: number, stop: number, count: number): number { export function getScaledDecimals(decimals, tick_size) { return decimals - Math.floor(Math.log(tick_size) / Math.LN10); } + +/** + * Calculate tick size based on min and max values, number of ticks and precision. + * @param min Axis minimum + * @param max Axis maximum + * @param noTicks Number of ticks + * @param tickDecimals Tick decimal precision + */ +export function getFlotTickSize(min: number, max: number, noTicks: number, tickDecimals: number) { + var delta = (max - min) / noTicks, + dec = -Math.floor(Math.log(delta) / Math.LN10), + maxDec = tickDecimals; + + var magn = Math.pow(10, -dec), + norm = delta / magn, // norm is between 1.0 and 10.0 + size; + + if (norm < 1.5) { + size = 1; + } else if (norm < 3) { + size = 2; + // special case for 2.5, requires an extra decimal + if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) { + size = 2.5; + ++dec; + } + } else if (norm < 7.5) { + size = 5; + } else { + size = 10; + } + + size *= magn; + + return size; +} diff --git a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts index 097d9f5897d..d455d89d3b2 100644 --- a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts +++ b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts @@ -89,7 +89,7 @@ export class HeatmapTooltip { let time = this.dashboard.formatDate(xData.x, tooltipTimeFormat); let decimals = this.panel.tooltipDecimals || this.panelCtrl.decimals; - let scaledDecimals = decimals - 2; + let scaledDecimals = this.panel.tooltipDecimals ? decimals - 2 : this.panelCtrl.scaledDecimals; let valueFormatter = this.valueFormatter(decimals, scaledDecimals); let tooltipHtml = `