Skip to content

Commit

Permalink
Support Kibana 7.10.0
Browse files Browse the repository at this point in the history
Signed-off-by: David Moreno <[email protected]>
  • Loading branch information
dlumbrer committed Jan 31, 2021
1 parent aa20acf commit cc42c5a
Show file tree
Hide file tree
Showing 55 changed files with 24,747 additions and 188 deletions.
2 changes: 2 additions & 0 deletions .gitignore copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
npm-debug.log
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
11 changes: 0 additions & 11 deletions index.js

This file was deleted.

17 changes: 17 additions & 0 deletions kibana.json
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"
]
}
9 changes: 5 additions & 4 deletions package.json
100644 → 100755
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": {
Expand All @@ -16,4 +17,4 @@
"chart.js": "2.7.1",
"randomcolor": "0.5.3"
}
}
}
14 changes: 14 additions & 0 deletions public/agg_table/_agg_table.scss
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;
}
}
1 change: 1 addition & 0 deletions public/agg_table/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'agg_table';
33 changes: 33 additions & 0 deletions public/agg_table/agg_table.html
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>&nbsp;&nbsp;
<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>&nbsp;&nbsp;&nbsp;
<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>
195 changes: 195 additions & 0 deletions public/agg_table/agg_table.js
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;
});
});
}
};
}
67 changes: 67 additions & 0 deletions public/agg_table/agg_table_group.html
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>
Loading

0 comments on commit cc42c5a

Please sign in to comment.