Skip to content

Commit

Permalink
Merge branch '6.2-dev' of https://github.com/dlumbrer/kbn_radar into …
Browse files Browse the repository at this point in the history
…6.2-dev
  • Loading branch information
dlumbrer committed Jan 14, 2019
2 parents 7e0f31e + 0483437 commit b97d67f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion public/kbn_radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function RadarVisTypeProvider(Private) {
title: 'Field',
max: 1,
min: 1,
aggFilter: ['terms']
aggFilter: ['terms', 'filters']
}
])
},
Expand Down
50 changes: 26 additions & 24 deletions public/kbn_radar_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
const randomColor = require('randomcolor');

function normalize(val, max, min, scale) { return (scale * (val - min) / (max - min)); }
function revertNormalize(final, max, min, scale) { return ((final / scale)*(max - min) + min); }
function revertNormalize(final, max, min, scale) { return ((final / scale) * (max - min) + min); }


$scope.$watchMulti(['esResponse'], function ([resp]) {
Expand All @@ -29,11 +29,11 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,



if($scope.radarchart){
if ($scope.radarchart) {
$scope.radarchart.destroy()
}

if(resp){
if (resp) {
var id_firstfield = '0'
var id_secondfield;
var id_x = '1'
Expand All @@ -43,7 +43,9 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
//Names of the field that have been selected
if ($scope.vis.aggs.bySchemaName['field']) {
var firstFieldAggId = $scope.vis.aggs.bySchemaName['field'][0].id;
var fieldAggName = $scope.vis.aggs.bySchemaName['field'][0].params.field.displayName;
if ($scope.vis.aggs.bySchemaName['field'][0].params.field) {
var fieldAggName = $scope.vis.aggs.bySchemaName['field'][0].params.field.displayName;
}
}


Expand All @@ -70,7 +72,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
for (let index = 0; index < resp.tables[0].rows.length; index++) {
const bucket = resp.tables[0].rows[index];
for (let index = 1; index < bucket.length; index++) {
if (!valuesMetrics[index]){
if (!valuesMetrics[index]) {
valuesMetrics[index] = []
}
valuesMetrics[index].push(bucket[index]);
Expand All @@ -85,28 +87,28 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
var originWithoutNormalize = []
var label = bucket[0]
for (let index = 1; index < bucket.length; index++) {
if(normalizeData){
if (normalizeData) {
var normMin = 1;
var normMax = Math.max(...valuesMetrics[index]);
if($scope.vis.params.rangesMetrics){
if ($scope.vis.params.rangesMetrics[index - 1].from){

if ($scope.vis.params.rangesMetrics) {
if ($scope.vis.params.rangesMetrics[index - 1].from) {
normMin = $scope.vis.params.rangesMetrics[index - 1].from;
}
if ($scope.vis.params.rangesMetrics[index - 1].to) {
normMax = $scope.vis.params.rangesMetrics[index - 1].to;
}
}
valuesBucket.push(normalize(bucket[index], normMax, normMin, vertexMaxScale))
}else{
} else {
valuesBucket.push(bucket[index]);
}
originWithoutNormalize.push(bucket[index]);
}
var color = randomColor({
luminosity: 'light',
format: 'rgba',
alpha: 0.2
luminosity: 'light',
format: 'rgba',
alpha: 0.2
});
// Border color must have a complete alpha
var borderColor = color.replace(/[^,]+(?=\))/, '1')
Expand Down Expand Up @@ -140,7 +142,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,

// if the data is normalizated, It is neccesary to change the tooltip and scale

if(normalizeData){
if (normalizeData) {
var options = {
responsive: true,
maintainAspectRadio: false,
Expand All @@ -161,7 +163,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
for (let i = 0; i < data['datasets'].length; i++) {
const e = data['datasets'][i];
var v = e['dataOrig'][tooltipItem['index']];
if(v == value){
if (v == value) {
labelsWithSameValue.push(e.label)
}
}
Expand All @@ -170,13 +172,13 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
var str = "";
for (let index = 0; index < labelsWithSameValue.length; index++) {
const element = labelsWithSameValue[index];
if(index == labelsWithSameValue.length-1){
if (index == labelsWithSameValue.length - 1) {
str += element;
continue
}
str += element + ", "
str += element + ", "
}
return str + ": " + value ;
return str + ": " + value;
},
afterLabel: function (tooltipItem, data) {
var dataset = data['datasets'][tooltipItem['datasetIndex']];
Expand All @@ -192,7 +194,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
displayColors: false
}
};
}else{
} else {
var options = {
responsive: true,
maintainAspectRadio: false,
Expand All @@ -212,7 +214,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
for (let i = 0; i < data['datasets'].length; i++) {
const e = data['datasets'][i];
var v = e['data'][tooltipItem['index']];
if(v == value){
if (v == value) {
labelsWithSameValue.push(e.label)
}
}
Expand All @@ -221,13 +223,13 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
var str = "";
for (let index = 0; index < labelsWithSameValue.length; index++) {
const element = labelsWithSameValue[index];
if(index == labelsWithSameValue.length-1){
if (index == labelsWithSameValue.length - 1) {
str += element;
continue
}
str += element + ", "
str += element + ", "
}
return str + ": " + value ;
return str + ": " + value;
}
},
backgroundColor: '#000',
Expand All @@ -241,7 +243,7 @@ module.controller('KbnRadarVisController', function ($scope, $element, $timeout,
}

var original = Chart.defaults.global.legend.onClick;
Chartjs.defaults.global.legend.onClick = function(e, legendItem) {
Chartjs.defaults.global.legend.onClick = function (e, legendItem) {
console.log(e, legendItem);
original.call(this, e, legendItem);
};
Expand Down

0 comments on commit b97d67f

Please sign in to comment.