From 9ddfeaa9c263feb27c9f8478319aa32b0845beb8 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 30 Mar 2017 21:36:36 +0300 Subject: [PATCH] heatmap: initial ES histogram support --- .../app/plugins/panel/heatmap/axes_editor.ts | 6 ++ .../app/plugins/panel/heatmap/heatmap_ctrl.ts | 78 ++++++++++++++----- .../panel/heatmap/partials/axes_editor.html | 10 +++ 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/public/app/plugins/panel/heatmap/axes_editor.ts b/public/app/plugins/panel/heatmap/axes_editor.ts index 662b1aba406..5b84f272d95 100644 --- a/public/app/plugins/panel/heatmap/axes_editor.ts +++ b/public/app/plugins/panel/heatmap/axes_editor.ts @@ -7,6 +7,7 @@ export class AxesEditorCtrl { panelCtrl: any; unitFormats: any; logScales: any; + dataFormats: any; /** @ngInject */ constructor($scope) { @@ -23,6 +24,11 @@ export class AxesEditorCtrl { 'log (base 32)': 32, 'log (base 1024)': 1024 }; + + this.dataFormats = { + 'Timeseries': 'timeseries', + 'ES histogram': 'es_histogram' + }; } setUnitFormat(subItem) { diff --git a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts index 13f50eb0b5e..c7572b38745 100644 --- a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts +++ b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts @@ -7,7 +7,7 @@ import TimeSeries from 'app/core/time_series'; import {axesEditor} from './axes_editor'; import {heatmapDisplayEditor} from './display_editor'; import rendering from './rendering'; -import {convertToHeatMap, getMinLog} from './heatmap_data_converter'; +import { convertToHeatMap, elasticHistogramToHeatmap, getMinLog} from './heatmap_data_converter'; let X_BUCKET_NUMBER_DEFAULT = 30; let Y_BUCKET_NUMBER_DEFAULT = 10; @@ -27,6 +27,7 @@ let panelDefaults = { colorScheme: 'interpolateSpectral', fillBackground: false }, + dataFormat: 'timeseries', xBucketSize: null, xBucketNumber: null, yBucketSize: null, @@ -137,7 +138,7 @@ export class HeatmapCtrl extends MetricsPanelCtrl { onRender() { if (!this.range) { return; } - let xBucketSize, yBucketSize; + let xBucketSize, yBucketSize, heatmapStats, bucketsData; let logBase = this.panel.yAxis.logBase; let xBucketNumber = this.panel.xBucketNumber || X_BUCKET_NUMBER_DEFAULT; let xBucketSizeByNumber = Math.floor((this.range.to - this.range.from) / xBucketNumber); @@ -152,25 +153,49 @@ export class HeatmapCtrl extends MetricsPanelCtrl { xBucketSize = Number(this.panel.xBucketSize); } - // Calculate Y bucket size - let heatmapStats = this.parseSeries(this.series); - let yBucketNumber = this.panel.yBucketNumber || Y_BUCKET_NUMBER_DEFAULT; - if (logBase !== 1) { - yBucketSize = this.panel.yAxis.splitFactor; - } else { - if (heatmapStats.max === heatmapStats.min) { - if (heatmapStats.max) { - yBucketSize = heatmapStats.max / Y_BUCKET_NUMBER_DEFAULT; - } else { - yBucketSize = 1; - } - } else { - yBucketSize = (heatmapStats.max - heatmapStats.min) / yBucketNumber; - } - yBucketSize = this.panel.yBucketSize || yBucketSize; - } + if (this.panel.dataFormat === 'es_histogram') { + heatmapStats = this.parseHistogramSeries(this.series); - let bucketsData = convertToHeatMap(this.series, yBucketSize, xBucketSize, logBase); + // Calculate Y bucket size + let yBucketNumber = this.panel.yBucketNumber || Y_BUCKET_NUMBER_DEFAULT; + if (logBase !== 1) { + yBucketSize = this.panel.yAxis.splitFactor; + } else { + if (heatmapStats.max === heatmapStats.min) { + if (heatmapStats.max) { + yBucketSize = heatmapStats.max / Y_BUCKET_NUMBER_DEFAULT; + } else { + yBucketSize = 1; + } + } else { + yBucketSize = (heatmapStats.max - heatmapStats.min) / yBucketNumber; + } + yBucketSize = this.panel.yBucketSize || yBucketSize; + } + + bucketsData = elasticHistogramToHeatmap(this.series); + } else { + + // Calculate Y bucket size + heatmapStats = this.parseSeries(this.series); + let yBucketNumber = this.panel.yBucketNumber || Y_BUCKET_NUMBER_DEFAULT; + if (logBase !== 1) { + yBucketSize = this.panel.yAxis.splitFactor; + } else { + if (heatmapStats.max === heatmapStats.min) { + if (heatmapStats.max) { + yBucketSize = heatmapStats.max / Y_BUCKET_NUMBER_DEFAULT; + } else { + yBucketSize = 1; + } + } else { + yBucketSize = (heatmapStats.max - heatmapStats.min) / yBucketNumber; + } + yBucketSize = this.panel.yBucketSize || yBucketSize; + } + + bucketsData = convertToHeatMap(this.series, yBucketSize, xBucketSize, logBase); + } // Set default Y range if no data if (!heatmapStats.min && !heatmapStats.max) { @@ -252,6 +277,19 @@ export class HeatmapCtrl extends MetricsPanelCtrl { }; } + parseHistogramSeries(series) { + let bounds = _.map(series, s => Number(s.alias)); + let min = _.min(bounds); + let minLog = _.min(bounds); + let max = _.max(bounds); + + return { + max: max, + min: min, + minLog: minLog + }; + } + link(scope, elem, attrs, ctrl) { rendering(scope, elem, attrs, ctrl); } diff --git a/public/app/plugins/panel/heatmap/partials/axes_editor.html b/public/app/plugins/panel/heatmap/partials/axes_editor.html index f9a0464d381..161be2dab19 100644 --- a/public/app/plugins/panel/heatmap/partials/axes_editor.html +++ b/public/app/plugins/panel/heatmap/partials/axes_editor.html @@ -82,4 +82,14 @@ ng-model="ctrl.panel.xBucketSize" ng-change="ctrl.refresh()" ng-model-onblur> + +
+
Data format
+
+ +
+ +
+
+