-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Moreno <[email protected]>
- Loading branch information
Showing
55 changed files
with
24,747 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"id": "kbnPolar", | ||
"version": "7.10.0", | ||
"server": false, | ||
"ui": true, | ||
"requiredPlugins": [ | ||
"visualizations", | ||
"data", | ||
"inspector", | ||
"kibanaLegacy" | ||
], | ||
"requiredBundles": [ | ||
"kibanaUtils", | ||
"visDefaultEditor", | ||
"share" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
{ | ||
"name": "kbn_polar", | ||
"version": "0.0.1", | ||
"version": "7.10.0", | ||
"description": "Visualize polar charts", | ||
"kibana": { | ||
"version": "kibana" | ||
"version": "7.10.0" | ||
}, | ||
"authors": [ | ||
"David Moreno Lumbreras <[email protected]>" | ||
"David Moreno Lumbreras <[email protected]>" | ||
], | ||
"license": "Apache-2.0", | ||
"repository": { | ||
|
@@ -16,4 +17,4 @@ | |
"chart.js": "2.7.1", | ||
"randomcolor": "0.5.3" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
kbn-polar-agg-table, | ||
kbn-polar-agg-table-group { | ||
display: block; | ||
} | ||
|
||
.striped-rows .kbnAggTable__paginated { | ||
tr:nth-child(odd) td { | ||
background-color: lighten($euiColorLightestShade, 2%); | ||
} | ||
|
||
tr:hover td { | ||
background-color: $euiColorLightestShade; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'agg_table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<polar-paginated-table | ||
ng-if="rows.length" | ||
table="table" | ||
rows="rows" | ||
columns="formattedColumns" | ||
per-page="perPage" | ||
sort="sort" | ||
show-total="showTotal" | ||
filter="filter" | ||
totalFunc="totalFunc"> | ||
|
||
<div class="kbnAggTable__controls"> | ||
<small | ||
i18n-id="visTypeTable.aggTable.exportLabel" | ||
i18n-default-message="Export:" | ||
></small> | ||
<a class="small" ng-click="aggTable.exportAsCsv(false)"> | ||
<span | ||
i18n-id="visTypeTable.aggTable.rawLabel" | ||
i18n-default-message="Raw" | ||
></span> | ||
<i aria-hidden="true" class="fa fa-download"></i> | ||
</a> | ||
<a class="small" ng-click="aggTable.exportAsCsv(true)"> | ||
<span | ||
i18n-id="visTypeTable.aggTable.formattedLabel" | ||
i18n-default-message="Formatted" | ||
></span> | ||
<i aria-hidden="true" class="fa fa-download"></i> | ||
</a> | ||
<paginate-controls></paginate-controls> | ||
</div> | ||
</polar-paginated-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { CSV_SEPARATOR_SETTING, CSV_QUOTE_VALUES_SETTING } from '../../../../src/plugins/share/public'; | ||
import aggTableTemplate from './agg_table.html'; | ||
import { getFormatService } from '../services'; | ||
import { fieldFormatter } from '../field_formatter'; | ||
|
||
export function KbnPolarAggTable(config, RecursionHelper) { | ||
const fieldFormats = getFormatService(); | ||
const numberFormatter = fieldFormats.getDefaultInstance('number').getConverterFor('text'); | ||
|
||
return { | ||
restrict: 'E', | ||
template: aggTableTemplate, | ||
scope: { | ||
table: '=', | ||
perPage: '=?', | ||
sort: '=?', | ||
exportTitle: '=?', | ||
showTotal: '=', | ||
totalFunc: '=', | ||
filter: '=', | ||
}, | ||
controllerAs: 'aggTable', | ||
compile: function ($el) { | ||
// Use the compile function from the RecursionHelper, | ||
// And return the linking function(s) which it returns | ||
return RecursionHelper.compile($el); | ||
}, | ||
controller: function ($scope) { | ||
const self = this; | ||
|
||
self._saveAs = require('@elastic/filesaver').saveAs; | ||
self.csv = { | ||
separator: config.get(CSV_SEPARATOR_SETTING), | ||
quoteValues: config.get(CSV_QUOTE_VALUES_SETTING) | ||
}; | ||
|
||
self.exportAsCsv = function (formatted) { | ||
const csv = new Blob([self.toCsv(formatted)], { type: 'text/plain;charset=utf-8' }); | ||
self._saveAs(csv, self.csv.filename); | ||
}; | ||
|
||
self.toCsv = function (formatted) { | ||
const rows = $scope.table.rows; | ||
const columns = formatted ? $scope.formattedColumns : $scope.table.columns; | ||
const nonAlphaNumRE = /[^a-zA-Z0-9]/; | ||
const allDoubleQuoteRE = /"/g; | ||
|
||
function escape(val) { | ||
if (!formatted && _.isObject(val)) val = val.valueOf(); | ||
val = String(val); | ||
if (self.csv.quoteValues && nonAlphaNumRE.test(val)) { | ||
val = '"' + val.replace(allDoubleQuoteRE, '""') + '"'; | ||
} | ||
return val; | ||
} | ||
|
||
// escape each cell in each row | ||
const csvRows = rows.map(function (row) { | ||
return row.map(escape); | ||
}); | ||
|
||
// add the columns to the rows | ||
csvRows.unshift(columns.map(function (col) { | ||
return escape(col.title); | ||
})); | ||
|
||
return csvRows.map(function (row) { | ||
return row.join(self.csv.separator) + '\r\n'; | ||
}).join(''); | ||
}; | ||
|
||
$scope.$watch('table', function () { | ||
const table = $scope.table; | ||
|
||
if (!table) { | ||
$scope.rows = null; | ||
$scope.formattedColumns = null; | ||
return; | ||
} | ||
|
||
self.csv.filename = ($scope.exportTitle || table.title || 'unsaved') + '.csv'; | ||
$scope.rows = table.rows; | ||
$scope.formattedColumns = table.columns.map(function (col, i) { | ||
const agg = col.aggConfig; | ||
const field = agg.getField(); | ||
const formattedColumn = { | ||
title: col.title, | ||
filterable: field && field.filterable && agg.type.type === 'buckets', | ||
titleAlignmentClass: col.titleAlignmentClass, | ||
totalAlignmentClass: col.totalAlignmentClass | ||
}; | ||
|
||
const last = i === (table.columns.length - 1); | ||
|
||
if (last || (agg.type.type === 'metrics')) { | ||
formattedColumn.class = 'visualize-table-right'; | ||
} | ||
|
||
let isFieldNumeric = false; | ||
let isFieldDate = false; | ||
const aggType = agg.type; | ||
if (aggType && aggType.type === 'metrics') { | ||
if (aggType.name === 'top_hits') { | ||
if (agg.params.aggregate.value !== 'concat') { | ||
// all other aggregate types for top_hits output numbers | ||
// so treat this field as numeric | ||
isFieldNumeric = true; | ||
} | ||
} else if(aggType.name === 'cardinality') { | ||
// Unique count aggregations always produce a numeric value | ||
isFieldNumeric = true; | ||
} else if (field) { | ||
// if the metric has a field, check if it is either number or date | ||
isFieldNumeric = field.type === 'number'; | ||
isFieldDate = field.type === 'date'; | ||
} else { | ||
// if there is no field, then it is count or similar so just say number | ||
isFieldNumeric = true; | ||
} | ||
} else if (field) { | ||
isFieldNumeric = field.type === 'number'; | ||
isFieldDate = field.type === 'date'; | ||
} | ||
|
||
if (isFieldNumeric || isFieldDate || $scope.totalFunc === 'count') { | ||
const sum = function (tableRows) { | ||
return _.reduce(tableRows, function (prev, curr) { | ||
// some metrics return undefined for some of the values | ||
// derivative is an example of this as it returns undefined in the first row | ||
if (curr[i].value === undefined) return prev; | ||
return prev + curr[i].value; | ||
}, 0); | ||
}; | ||
const formatter = col.totalFormatter ? col.totalFormatter('text') : fieldFormatter(agg, 'text'); | ||
|
||
if (col.totalFormula !== undefined) { | ||
formattedColumn.total = formatter(col.total); | ||
} | ||
else { | ||
switch ($scope.totalFunc) { | ||
case 'sum': | ||
if (!isFieldDate) { | ||
formattedColumn.total = formatter(sum(table.rows)); | ||
} | ||
break; | ||
case 'avg': | ||
if (!isFieldDate) { | ||
formattedColumn.total = formatter(sum(table.rows) / table.rows.length); | ||
} | ||
break; | ||
case 'min': | ||
formattedColumn.total = formatter(_.chain(table.rows).map(i).map('value').min().value()); | ||
break; | ||
case 'max': | ||
formattedColumn.total = formatter(_.chain(table.rows).map(i).map('value').max().value()); | ||
break; | ||
case 'count': | ||
formattedColumn.total = numberFormatter(table.rows.length); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (i === 0 && table.totalLabel !== undefined && table.columns.length > 0 && formattedColumn.total === undefined) { | ||
formattedColumn.total = table.totalLabel; | ||
} | ||
|
||
return formattedColumn; | ||
}); | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<table ng-if="rows" class="table kbnAggTable__group" ng-repeat="table in rows"> | ||
<thead> | ||
<tr> | ||
<th ng-if="table.tables" scope="col"> | ||
<span class="kbnAggTable__groupHeader">{{ table.title }}</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<kbn-polar-agg-table-group | ||
ng-if="table.tables" | ||
group="table" | ||
filter="filter" | ||
per-page="perPage" | ||
sort="sort" | ||
show-total="showTotal" | ||
total-func="totalFunc"></kbn-polar-agg-table-group> | ||
<kbn-polar-agg-table | ||
ng-if="table.rows" | ||
filter="filter" | ||
table="table" | ||
export-title="exportTitle" | ||
per-page="perPage" | ||
sort="sort" | ||
show-total="showTotal" | ||
total-func="totalFunc"> | ||
</kbn-polar-agg-table> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<table ng-if="columns" class="table kbnAggTable__group"> | ||
<thead> | ||
<tr> | ||
<th ng-repeat="table in columns" ng-if="table.tables" scope="col"> | ||
<span class="kbnAggTable__groupHeader">{{ table.title }}</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td ng-repeat="table in columns"> | ||
<kbn-polar-agg-table-group | ||
ng-if="table.tables" | ||
filter="filter" | ||
group="table" | ||
per-page="perPage" | ||
sort="sort" | ||
show-total="showTotal" | ||
total-func="totalFunc"></kbn-polar-agg-table-group> | ||
<kbn-polar-agg-table | ||
ng-if="table.rows" | ||
filter="filter" | ||
table="table" | ||
export-title="exportTitle" | ||
per-page="perPage" | ||
sort="sort" | ||
show-total="showTotal" | ||
total-func="totalFunc"> | ||
</kbn-polar-agg-table> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> |
Oops, something went wrong.