mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[eslint] re-enable no-var and prefer-const (#9455)
* [eslint] enable no-var and autofix * [eslint] enable prefer-const and autofix * [eslint] fix autofix-incompatible no-var and prefer-const violations
This commit is contained in:
parent
e125db2b02
commit
2f6654bcec
684 changed files with 4113 additions and 4115 deletions
|
@ -2,7 +2,5 @@
|
|||
extends: '@elastic/kibana'
|
||||
rules:
|
||||
no-unused-vars: off
|
||||
no-var: off
|
||||
prefer-const: off
|
||||
no-extra-semi: off
|
||||
quotes: off
|
||||
|
|
|
@ -5,16 +5,16 @@ import { EventEmitter } from 'events';
|
|||
|
||||
import { BinderFor, fromRoot } from '../../utils';
|
||||
|
||||
let cliPath = fromRoot('src/cli');
|
||||
let baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
|
||||
let baseArgv = [process.execPath, cliPath].concat(baseArgs);
|
||||
const cliPath = fromRoot('src/cli');
|
||||
const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
|
||||
const baseArgv = [process.execPath, cliPath].concat(baseArgs);
|
||||
|
||||
cluster.setupMaster({
|
||||
exec: cliPath,
|
||||
silent: false
|
||||
});
|
||||
|
||||
let dead = fork => {
|
||||
const dead = fork => {
|
||||
return fork.isDead() || fork.killed;
|
||||
};
|
||||
|
||||
|
@ -40,7 +40,7 @@ module.exports = class Worker extends EventEmitter {
|
|||
this.clusterBinder = new BinderFor(cluster);
|
||||
this.processBinder = new BinderFor(process);
|
||||
|
||||
let argv = _.union(baseArgv, opts.argv || []);
|
||||
const argv = _.union(baseArgv, opts.argv || []);
|
||||
this.env = {
|
||||
kbnWorkerType: this.type,
|
||||
kbnWorkerArgv: JSON.stringify(argv)
|
||||
|
@ -124,8 +124,8 @@ module.exports = class Worker extends EventEmitter {
|
|||
}
|
||||
|
||||
flushChangeBuffer() {
|
||||
let files = _.unique(this.changes.splice(0));
|
||||
let prefix = files.length > 1 ? '\n - ' : '';
|
||||
const files = _.unique(this.changes.splice(0));
|
||||
const prefix = files.length > 1 ? '\n - ' : '';
|
||||
return files.reduce(function (list, file) {
|
||||
return `${list || ''}${prefix}"${file}"`;
|
||||
}, '');
|
||||
|
|
|
@ -40,15 +40,15 @@ Command.prototype.unknownArgv = function (argv) {
|
|||
* @return {[type]} [description]
|
||||
*/
|
||||
Command.prototype.collectUnknownOptions = function () {
|
||||
let title = `Extra ${this._name} options`;
|
||||
const title = `Extra ${this._name} options`;
|
||||
|
||||
this.allowUnknownOption();
|
||||
this.getUnknownOptions = function () {
|
||||
let opts = {};
|
||||
let unknowns = this.unknownArgv();
|
||||
const opts = {};
|
||||
const unknowns = this.unknownArgv();
|
||||
|
||||
while (unknowns.length) {
|
||||
let opt = unknowns.shift().split('=');
|
||||
const opt = unknowns.shift().split('=');
|
||||
if (opt[0].slice(0, 2) !== '--') {
|
||||
this.error(`${title} "${opt[0]}" must start with "--"`);
|
||||
}
|
||||
|
@ -75,14 +75,14 @@ Command.prototype.collectUnknownOptions = function () {
|
|||
};
|
||||
|
||||
Command.prototype.parseOptions = _.wrap(Command.prototype.parseOptions, function (parse, argv) {
|
||||
let opts = parse.call(this, argv);
|
||||
const opts = parse.call(this, argv);
|
||||
this.unknownArgv(opts.unknown);
|
||||
return opts;
|
||||
});
|
||||
|
||||
Command.prototype.action = _.wrap(Command.prototype.action, function (action, fn) {
|
||||
return action.call(this, function (...args) {
|
||||
let ret = fn.apply(this, args);
|
||||
const ret = fn.apply(this, args);
|
||||
if (ret && typeof ret.then === 'function') {
|
||||
ret.then(null, function (e) {
|
||||
console.log('FATAL CLI ERROR', e.stack);
|
||||
|
|
|
@ -5,12 +5,12 @@ module.exports = function (command, spaces) {
|
|||
return command.outputHelp();
|
||||
}
|
||||
|
||||
let defCmd = _.find(command.commands, function (cmd) {
|
||||
const defCmd = _.find(command.commands, function (cmd) {
|
||||
return cmd._name === 'serve';
|
||||
});
|
||||
|
||||
let desc = !command.description() ? '' : command.description();
|
||||
let cmdDef = !defCmd ? '' : `=${defCmd._name}`;
|
||||
const desc = !command.description() ? '' : command.description();
|
||||
const cmdDef = !defCmd ? '' : `=${defCmd._name}`;
|
||||
|
||||
return (
|
||||
`
|
||||
|
@ -31,11 +31,11 @@ function indent(str, n) {
|
|||
}
|
||||
|
||||
function commandsSummary(program) {
|
||||
let cmds = _.compact(program.commands.map(function (cmd) {
|
||||
let name = cmd._name;
|
||||
const cmds = _.compact(program.commands.map(function (cmd) {
|
||||
const name = cmd._name;
|
||||
if (name === '*') return;
|
||||
let opts = cmd.options.length ? ' [options]' : '';
|
||||
let args = cmd._args.map(function (arg) {
|
||||
const opts = cmd.options.length ? ' [options]' : '';
|
||||
const args = cmd._args.map(function (arg) {
|
||||
return humanReadableArgName(arg);
|
||||
}).join(' ');
|
||||
|
||||
|
@ -45,7 +45,7 @@ function commandsSummary(program) {
|
|||
];
|
||||
}));
|
||||
|
||||
let cmdLColWidth = cmds.reduce(function (width, cmd) {
|
||||
const cmdLColWidth = cmds.reduce(function (width, cmd) {
|
||||
return Math.max(width, cmd[0].length);
|
||||
}, 0);
|
||||
|
||||
|
@ -69,6 +69,6 @@ ${indent(cmd.optionHelp(), 2)}
|
|||
}
|
||||
|
||||
function humanReadableArgName(arg) {
|
||||
let nameOutput = arg.name + (arg.variadic === true ? '...' : '');
|
||||
const nameOutput = arg.name + (arg.variadic === true ? '...' : '');
|
||||
return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import _ from 'lodash';
|
||||
import ansicolors from 'ansicolors';
|
||||
|
||||
let log = _.restParam(function (color, label, rest1) {
|
||||
const log = _.restParam(function (color, label, rest1) {
|
||||
console.log.apply(console, [color(` ${_.trim(label)} `)].concat(rest1));
|
||||
});
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import listCommand from './list';
|
|||
import installCommand from './install';
|
||||
import removeCommand from './remove';
|
||||
|
||||
let argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
|
||||
let program = new Command('bin/kibana-plugin');
|
||||
const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
|
||||
const program = new Command('bin/kibana-plugin');
|
||||
|
||||
program
|
||||
.version(pkg.version)
|
||||
|
@ -23,7 +23,7 @@ program
|
|||
.command('help <command>')
|
||||
.description('get the help for a specific command')
|
||||
.action(function (cmdName) {
|
||||
let cmd = _.find(program.commands, { _name: cmdName });
|
||||
const cmd = _.find(program.commands, { _name: cmdName });
|
||||
if (!cmd) return program.error(`unknown command ${cmdName}`);
|
||||
cmd.help();
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ program
|
|||
});
|
||||
|
||||
// check for no command name
|
||||
let subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
|
||||
const subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
|
||||
if (!subCommand) {
|
||||
program.defaultHelp();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('kibana cli', function () {
|
|||
|
||||
describe('commander options', function () {
|
||||
|
||||
let program = {
|
||||
const program = {
|
||||
command: function () { return program; },
|
||||
description: function () { return program; },
|
||||
option: function () { return program; },
|
||||
|
|
|
@ -3,7 +3,7 @@ import { createWriteStream, createReadStream, unlinkSync, statSync } from 'fs';
|
|||
|
||||
function openSourceFile({ sourcePath }) {
|
||||
try {
|
||||
let fileInfo = statSync(sourcePath);
|
||||
const fileInfo = statSync(sourcePath);
|
||||
|
||||
const readStream = createReadStream(sourcePath);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ export default async function downloadUrl(logger, sourceUrl, targetPath, timeout
|
|||
const { req, resp } = await sendRequest({ sourceUrl, timeout });
|
||||
|
||||
try {
|
||||
let totalSize = parseFloat(resp.headers['content-length']) || 0;
|
||||
const totalSize = parseFloat(resp.headers['content-length']) || 0;
|
||||
const progress = new Progress(logger);
|
||||
progress.init(totalSize);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ let version = pkg.version;
|
|||
|
||||
describe('plugins/elasticsearch', function () {
|
||||
describe('lib/is_upgradeable', function () {
|
||||
let server = {
|
||||
const server = {
|
||||
config: _.constant({
|
||||
get: function (key) {
|
||||
switch (key) {
|
||||
|
@ -44,7 +44,7 @@ describe('plugins/elasticsearch', function () {
|
|||
upgradeDoc('5.0.0-alpha1', '5.0.0', false);
|
||||
|
||||
it('should handle missing _id field', function () {
|
||||
let doc = {
|
||||
const doc = {
|
||||
'_index': '.kibana',
|
||||
'_type': 'config',
|
||||
'_score': 1,
|
||||
|
@ -58,7 +58,7 @@ describe('plugins/elasticsearch', function () {
|
|||
});
|
||||
|
||||
it('should handle _id of @@version', function () {
|
||||
let doc = {
|
||||
const doc = {
|
||||
'_index': '.kibana',
|
||||
'_type': 'config',
|
||||
'_id': '@@version',
|
||||
|
|
|
@ -26,7 +26,7 @@ docViewsRegistry.register(function () {
|
|||
};
|
||||
|
||||
$scope.showArrayInObjectsWarning = function (row, field) {
|
||||
let value = $scope.flattened[field];
|
||||
const value = $scope.flattened[field];
|
||||
return _.isArray(value) && typeof value[0] === 'object';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ module.exports = function (kibana) {
|
|||
],
|
||||
|
||||
injectVars: function (server, options) {
|
||||
let config = server.config();
|
||||
const config = server.config();
|
||||
return {
|
||||
kbnDefaultAppId: config.get('kibana.defaultAppId'),
|
||||
tilemap: config.get('tilemap')
|
||||
|
|
|
@ -41,7 +41,7 @@ describe('dashboard panels', function () {
|
|||
|
||||
it('loads with no vizualizations', function () {
|
||||
ngMock.inject((SavedDashboard) => {
|
||||
let dash = new SavedDashboard();
|
||||
const dash = new SavedDashboard();
|
||||
dash.init();
|
||||
compile(dash);
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ describe('dashboard panels', function () {
|
|||
|
||||
it('loads one vizualization', function () {
|
||||
ngMock.inject((SavedDashboard) => {
|
||||
let dash = new SavedDashboard();
|
||||
const dash = new SavedDashboard();
|
||||
dash.init();
|
||||
dash.panelsJSON = `[{"col":3,"id":"foo1","row":1,"size_x":2,"size_y":2,"type":"visualization"}]`;
|
||||
compile(dash);
|
||||
|
@ -60,7 +60,7 @@ describe('dashboard panels', function () {
|
|||
|
||||
it('loads vizualizations in correct order', function () {
|
||||
ngMock.inject((SavedDashboard) => {
|
||||
let dash = new SavedDashboard();
|
||||
const dash = new SavedDashboard();
|
||||
dash.init();
|
||||
dash.panelsJSON = `[
|
||||
{"col":3,"id":"foo1","row":1,"size_x":2,"size_y":2,"type":"visualization"},
|
||||
|
@ -90,7 +90,7 @@ describe('dashboard panels', function () {
|
|||
|
||||
it('initializes visualizations with the default size', function () {
|
||||
ngMock.inject((SavedDashboard) => {
|
||||
let dash = new SavedDashboard();
|
||||
const dash = new SavedDashboard();
|
||||
dash.init();
|
||||
dash.panelsJSON = `[
|
||||
{"col":3,"id":"foo1","row":1,"type":"visualization"},
|
||||
|
|
|
@ -144,7 +144,7 @@ function VisEditor($scope, $route, timefilter, AppState, $location, kbnUrl, $tim
|
|||
};
|
||||
|
||||
// Instance of app_state.js.
|
||||
let $state = $scope.$state = (function initState() {
|
||||
const $state = $scope.$state = (function initState() {
|
||||
// This is used to sync visualization state with the url when `appState.save()` is called.
|
||||
const appState = new AppState(stateDefaults);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('createMappingsFromPatternFields', function () {
|
|||
});
|
||||
|
||||
it('should set the same default mapping for all non-strings', function () {
|
||||
let mappings = createMappingsFromPatternFields(testFields);
|
||||
const mappings = createMappingsFromPatternFields(testFields);
|
||||
|
||||
_.forEach(mappings, function (mapping) {
|
||||
if (mapping.type !== 'text') {
|
||||
|
@ -50,7 +50,7 @@ describe('createMappingsFromPatternFields', function () {
|
|||
});
|
||||
|
||||
it('should give strings a multi-field mapping with a "text" base type', function () {
|
||||
let mappings = createMappingsFromPatternFields(testFields);
|
||||
const mappings = createMappingsFromPatternFields(testFields);
|
||||
|
||||
_.forEach(mappings, function (mapping) {
|
||||
if (mapping.type === 'text') {
|
||||
|
@ -61,7 +61,7 @@ describe('createMappingsFromPatternFields', function () {
|
|||
|
||||
it('should handle nested fields', function () {
|
||||
testFields.push({name: 'geo.coordinates', type: 'geo_point'});
|
||||
let mappings = createMappingsFromPatternFields(testFields);
|
||||
const mappings = createMappingsFromPatternFields(testFields);
|
||||
|
||||
expect(mappings).to.have.property('geo');
|
||||
expect(mappings.geo).to.have.property('properties');
|
||||
|
@ -74,7 +74,7 @@ describe('createMappingsFromPatternFields', function () {
|
|||
});
|
||||
|
||||
it('should map all number fields as an ES double', function () {
|
||||
let mappings = createMappingsFromPatternFields(testFields);
|
||||
const mappings = createMappingsFromPatternFields(testFields);
|
||||
|
||||
expect(mappings).to.have.property('bytes');
|
||||
expect(mappings.bytes).to.have.property('type', 'double');
|
||||
|
|
|
@ -11,7 +11,7 @@ const module = uiModules.get('kibana/table_vis', ['kibana']);
|
|||
module.controller('KbnTableVisController', function ($scope, $element, Private) {
|
||||
const tabifyAggResponse = Private(AggResponseTabifyTabifyProvider);
|
||||
|
||||
var uiStateSort = ($scope.uiState) ? $scope.uiState.get('vis.params.sort') : {};
|
||||
const uiStateSort = ($scope.uiState) ? $scope.uiState.get('vis.params.sort') : {};
|
||||
assign($scope.vis.params.sort, uiStateSort);
|
||||
|
||||
$scope.sort = $scope.vis.params.sort;
|
||||
|
|
|
@ -364,7 +364,7 @@ function hashCode(string) {
|
|||
return hash;
|
||||
}
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
let char = string.charCodeAt(i);
|
||||
const char = string.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ uiModules.get('kibana/table_vis')
|
|||
template: tagCloudVisParamsTemplate,
|
||||
link: function ($scope, $element) {
|
||||
const sliderContainer = $element[0];
|
||||
var slider = sliderContainer.querySelector('.tag-cloud-fontsize-slider');
|
||||
const slider = sliderContainer.querySelector('.tag-cloud-fontsize-slider');
|
||||
noUiSlider.create(slider, {
|
||||
start: [$scope.vis.params.minFontSize, $scope.vis.params.maxFontSize],
|
||||
connect: true,
|
||||
|
|
|
@ -5,7 +5,7 @@ import { resolve } from 'path';
|
|||
import { map, fromNode } from 'bluebird';
|
||||
import glob from 'glob-all';
|
||||
|
||||
let findSourceFiles = async (patterns, cwd = fromRoot('.')) => {
|
||||
const findSourceFiles = async (patterns, cwd = fromRoot('.')) => {
|
||||
patterns = [].concat(patterns || []);
|
||||
|
||||
const matches = await fromNode(cb => {
|
||||
|
|
|
@ -16,7 +16,7 @@ export default (kibana) => {
|
|||
uiExports: {
|
||||
bundle: async (UiBundle, env, apps, plugins) => {
|
||||
let modules = [];
|
||||
let config = kibana.config;
|
||||
const config = kibana.config;
|
||||
|
||||
const testGlobs = ['src/ui/public/**/*.js'];
|
||||
const testingPluginIds = config.get('tests_bundle.pluginId');
|
||||
|
@ -28,7 +28,7 @@ export default (kibana) => {
|
|||
if (!plugin) throw new Error('Invalid testingPluginId :: unknown plugin ' + pluginId);
|
||||
|
||||
// add the modules from all of this plugins apps
|
||||
for (let app of plugin.apps) {
|
||||
for (const app of plugin.apps) {
|
||||
modules = union(modules, app.getModules());
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ export default (kibana) => {
|
|||
} else {
|
||||
|
||||
// add the modules from all of the apps
|
||||
for (let app of apps) {
|
||||
for (const app of apps) {
|
||||
modules = union(modules, app.getModules());
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ export default (kibana) => {
|
|||
}
|
||||
|
||||
const testFiles = await findSourceFiles(testGlobs);
|
||||
for (let f of testFiles) modules.push(f);
|
||||
for (const f of testFiles) modules.push(f);
|
||||
|
||||
if (config.get('tests_bundle.instrument')) {
|
||||
env.addPostLoader({
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
var path = require('path');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = function (kibana) {
|
||||
var mainFile = 'plugins/timelion/app';
|
||||
let mainFile = 'plugins/timelion/app';
|
||||
|
||||
var ownDescriptor = Object.getOwnPropertyDescriptor(kibana, 'autoload');
|
||||
var protoDescriptor = Object.getOwnPropertyDescriptor(kibana.constructor.prototype, 'autoload');
|
||||
var descriptor = ownDescriptor || protoDescriptor || {};
|
||||
const ownDescriptor = Object.getOwnPropertyDescriptor(kibana, 'autoload');
|
||||
const protoDescriptor = Object.getOwnPropertyDescriptor(kibana.constructor.prototype, 'autoload');
|
||||
const descriptor = ownDescriptor || protoDescriptor || {};
|
||||
if (descriptor.get) {
|
||||
// the autoload list has been replaced with a getter that complains about
|
||||
// improper access, bypass that getter by seeing if it is defined
|
||||
|
@ -23,7 +23,7 @@ module.exports = function (kibana) {
|
|||
icon: 'plugins/timelion/icon.svg',
|
||||
main: mainFile,
|
||||
injectVars: function (server, options) {
|
||||
var config = server.config();
|
||||
const config = server.config();
|
||||
return {
|
||||
kbnIndex: config.get('kibana.index'),
|
||||
esShardTimeout: config.get('elasticsearch.shardTimeout'),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var _ = require('lodash');
|
||||
var processFunctionDefinition = require('./server/lib/process_function_definition');
|
||||
const _ = require('lodash');
|
||||
const processFunctionDefinition = require('./server/lib/process_function_definition');
|
||||
|
||||
module.exports = function (server) {
|
||||
//var config = server.config();
|
||||
|
@ -8,7 +8,7 @@ module.exports = function (server) {
|
|||
require('./server/routes/functions.js')(server);
|
||||
require('./server/routes/validate_es.js')(server);
|
||||
|
||||
var functions = require('./server/lib/load_functions')('series_functions');
|
||||
const functions = require('./server/lib/load_functions')('series_functions');
|
||||
|
||||
function addFunction(func) {
|
||||
_.assign(functions, processFunctionDefinition(func));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var _ = require('lodash');
|
||||
var logoUrl = require('./logo.png');
|
||||
var moment = require('moment-timezone');
|
||||
const _ = require('lodash');
|
||||
const logoUrl = require('./logo.png');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
require('plugins/timelion/directives/cells/cells');
|
||||
require('plugins/timelion/directives/fullscreen/fullscreen');
|
||||
|
@ -15,7 +15,7 @@ document.title = 'Timelion - Kibana';
|
|||
|
||||
require('ui/chrome');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
|
||||
require('plugins/timelion/services/saved_sheets');
|
||||
require('plugins/timelion/services/_saved_sheet');
|
||||
|
@ -27,7 +27,7 @@ require('./vis');
|
|||
require('ui/saved_objects/saved_object_registry').register(require('plugins/timelion/services/saved_sheet_register'));
|
||||
|
||||
// TODO: Expose an api for dismissing notifications
|
||||
var unsafeNotifications = require('ui/notify')._notifs;
|
||||
const unsafeNotifications = require('ui/notify')._notifs;
|
||||
|
||||
require('ui/routes').enable();
|
||||
|
||||
|
@ -53,15 +53,15 @@ app.controller('timelion', function (
|
|||
moment.tz.setDefault(config.get('dateFormat:tz'));
|
||||
|
||||
timefilter.enabled = true;
|
||||
var notify = new Notifier({
|
||||
const notify = new Notifier({
|
||||
location: 'Timelion'
|
||||
});
|
||||
|
||||
var timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
var docTitle = Private(require('ui/doc_title'));
|
||||
const timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
const docTitle = Private(require('ui/doc_title'));
|
||||
|
||||
var defaultExpression = '.es(*)';
|
||||
var savedSheet = $route.current.locals.savedSheet;
|
||||
const defaultExpression = '.es(*)';
|
||||
const savedSheet = $route.current.locals.savedSheet;
|
||||
|
||||
$scope.topNavMenu = [{
|
||||
key: 'new',
|
||||
|
@ -85,7 +85,7 @@ app.controller('timelion', function (
|
|||
return !savedSheet.id;
|
||||
},
|
||||
run: function () {
|
||||
var title = savedSheet.title;
|
||||
const title = savedSheet.title;
|
||||
safeConfirm('Are you sure you want to delete the sheet ' + title + ' ?').then(function () {
|
||||
savedSheet.delete().then(() => {
|
||||
notify.info('Deleted ' + title);
|
||||
|
@ -129,7 +129,7 @@ app.controller('timelion', function (
|
|||
};
|
||||
}
|
||||
|
||||
var init = function () {
|
||||
const init = function () {
|
||||
$scope.running = false;
|
||||
$scope.search();
|
||||
|
||||
|
@ -149,7 +149,7 @@ app.controller('timelion', function (
|
|||
};
|
||||
};
|
||||
|
||||
var refresher;
|
||||
let refresher;
|
||||
$scope.$watchCollection('timefilter.refreshInterval', function (interval) {
|
||||
if (refresher) $timeout.cancel(refresher);
|
||||
if (interval.value > 0 && !interval.pause) {
|
||||
|
@ -212,7 +212,7 @@ app.controller('timelion', function (
|
|||
$scope.sheet = [];
|
||||
$scope.running = false;
|
||||
|
||||
var err = new Error(resp.message);
|
||||
const err = new Error(resp.message);
|
||||
err.stack = resp.stack;
|
||||
notify.error(err);
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
|
||||
require('angularSortableView');
|
||||
require('plugins/timelion/directives/chart/chart');
|
||||
require('plugins/timelion/directives/timelion_grid');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', ['angular-sortable-view']);
|
||||
var html = require('./cells.html');
|
||||
const app = require('ui/modules').get('apps/timelion', ['angular-sortable-view']);
|
||||
const html = require('./cells.html');
|
||||
|
||||
app.directive('timelionCells', function () {
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var panelRegistryProvider = require('plugins/timelion/lib/panel_registry');
|
||||
const panelRegistryProvider = require('plugins/timelion/lib/panel_registry');
|
||||
|
||||
require('ui/modules')
|
||||
.get('apps/timelion', [])
|
||||
|
@ -12,8 +12,8 @@ require('ui/modules')
|
|||
},
|
||||
link: function ($scope, $elem) {
|
||||
|
||||
var panelRegistry = Private(panelRegistryProvider);
|
||||
var panelScope = $scope.$new(true);
|
||||
const panelRegistry = Private(panelRegistryProvider);
|
||||
let panelScope = $scope.$new(true);
|
||||
|
||||
function render(seriesList) {
|
||||
panelScope.$destroy();
|
||||
|
@ -24,7 +24,7 @@ require('ui/modules')
|
|||
type: 'timechart'
|
||||
};
|
||||
|
||||
var panelSchema = panelRegistry.byName[seriesList.render.type];
|
||||
const panelSchema = panelRegistry.byName[seriesList.render.type];
|
||||
|
||||
if (!panelSchema) {
|
||||
$elem.text('No such panel type: ' + seriesList.render.type);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
define(function (require) {
|
||||
var html = require('../partials/docs/tutorial.html');
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const html = require('../partials/docs/tutorial.html');
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
app.directive('timelionDocs', function (config, $http) {
|
||||
return {
|
||||
|
@ -50,7 +50,7 @@ define(function (require) {
|
|||
$scope.es.valid = false;
|
||||
$scope.es.invalidReason = (function () {
|
||||
try {
|
||||
var esResp = JSON.parse(resp.data.resp.response);
|
||||
const esResp = JSON.parse(resp.data.resp.response);
|
||||
return _.get(esResp, 'error.root_cause[0].reason');
|
||||
} catch (e) {
|
||||
if (_.get(resp, 'data.resp.message')) return _.get(resp, 'data.resp.message');
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var grammar = require('raw!../chain.peg');
|
||||
var PEG = require('pegjs');
|
||||
var Parser = PEG.buildParser(grammar);
|
||||
var template = require('./partials/suggestion.html');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
const grammar = require('raw!../chain.peg');
|
||||
const PEG = require('pegjs');
|
||||
const Parser = PEG.buildParser(grammar);
|
||||
const template = require('./partials/suggestion.html');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
|
||||
/*
|
||||
Autocomplete proposal, this file doesn't actually work like this
|
||||
|
@ -40,7 +40,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
require: 'ngModel',
|
||||
link: function ($scope, $elem, $attrs, ngModelCtrl) {
|
||||
|
||||
var keys = {
|
||||
const keys = {
|
||||
ESC: 27,
|
||||
UP: 38,
|
||||
DOWN: 40,
|
||||
|
@ -48,7 +48,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
ENTER: 13
|
||||
};
|
||||
|
||||
var functionReference = {};
|
||||
const functionReference = {};
|
||||
|
||||
function init() {
|
||||
resetSuggestions();
|
||||
|
@ -81,7 +81,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
function suggest(val) {
|
||||
try {
|
||||
// Inside an existing function providing suggestion only as a reference. Maybe suggest an argument?
|
||||
var possible = findFunction(getCaretPos(), Parser.parse(val).functions);
|
||||
const possible = findFunction(getCaretPos(), Parser.parse(val).functions);
|
||||
// TODO: Reference suggestors. Only supporting completion right now;
|
||||
resetSuggestions();
|
||||
return;
|
||||
|
@ -124,20 +124,20 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
}
|
||||
|
||||
function validateSelection() {
|
||||
var maxSelection = $scope.suggestions.list.length - 1;
|
||||
const maxSelection = $scope.suggestions.list.length - 1;
|
||||
if ($scope.suggestions.selected > maxSelection) $scope.suggestions.selected = maxSelection;
|
||||
else if ($scope.suggestions.selected < 0) $scope.suggestions.selected = 0;
|
||||
}
|
||||
|
||||
$scope.completeExpression = function (selected) {
|
||||
if (!$scope.suggestions.list.length) return;
|
||||
var expression = $attrs.timelionExpression;
|
||||
var startOf = expression.slice(0, $scope.suggestions.location.min);
|
||||
var endOf = expression.slice($scope.suggestions.location.max, expression.length);
|
||||
const expression = $attrs.timelionExpression;
|
||||
const startOf = expression.slice(0, $scope.suggestions.location.min);
|
||||
const endOf = expression.slice($scope.suggestions.location.max, expression.length);
|
||||
|
||||
var completeFunction = $scope.suggestions.list[selected].name + '()';
|
||||
const completeFunction = $scope.suggestions.list[selected].name + '()';
|
||||
|
||||
var newVal = startOf + completeFunction + endOf;
|
||||
const newVal = startOf + completeFunction + endOf;
|
||||
|
||||
$elem.val(newVal);
|
||||
$elem[0].selectionStart = $elem[0].selectionEnd =
|
||||
|
@ -195,8 +195,8 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
|
||||
function scrollTo(suggestions) {
|
||||
validateSelection();
|
||||
var suggestionsListElem = $('.suggestions');
|
||||
var suggestedElem = $($('.suggestion')[suggestions.selected]);
|
||||
const suggestionsListElem = $('.suggestions');
|
||||
const suggestedElem = $($('.suggestion')[suggestions.selected]);
|
||||
|
||||
if (!suggestedElem.position() || !suggestedElem.position().top) return;
|
||||
|
||||
|
@ -204,7 +204,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
|
|||
}
|
||||
|
||||
function findFunction(position, functionList) {
|
||||
var bestFunction;
|
||||
let bestFunction;
|
||||
|
||||
_.each(functionList, function (func) {
|
||||
if ((func.location.min) < position && position < (func.location.max)) {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
app.directive('fixedElementRoot', function ($timeout) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function ($scope, $elem, attrs) {
|
||||
var fixedAt;
|
||||
let fixedAt;
|
||||
$(window).bind('scroll', function () {
|
||||
var fixed = $('[fixed-element]', $elem);
|
||||
var body = $('[fixed-element-body]', $elem);
|
||||
var top = fixed.offset().top;
|
||||
const fixed = $('[fixed-element]', $elem);
|
||||
const body = $('[fixed-element-body]', $elem);
|
||||
const top = fixed.offset().top;
|
||||
|
||||
if ($(window).scrollTop() > top) {
|
||||
// This is a gross hack, but its better than it was. I guess
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
|
||||
require('angularSortableView');
|
||||
require('plugins/timelion/directives/chart/chart');
|
||||
require('plugins/timelion/directives/timelion_grid');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', ['angular-sortable-view']);
|
||||
var html = require('./fullscreen.html');
|
||||
const app = require('ui/modules').get('apps/timelion', ['angular-sortable-view']);
|
||||
const html = require('./fullscreen.html');
|
||||
|
||||
app.directive('timelionFullscreen', function () {
|
||||
return {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
const moment = require('moment');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
var html = require('./interval.html');
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
const html = require('./interval.html');
|
||||
|
||||
app.directive('timelionInterval', function ($compile, $timeout, timefilter) {
|
||||
return {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
|
||||
app.directive('refreshHack', function ($rootScope) {
|
||||
return {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
|
||||
var app = require('ui/modules').get('apps/timelion', []);
|
||||
const app = require('ui/modules').get('apps/timelion', []);
|
||||
app.directive('timelionGrid', function ($compile) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
|
@ -28,9 +28,9 @@ app.directive('timelionGrid', function ($compile) {
|
|||
});
|
||||
|
||||
function setDimensions() {
|
||||
var borderSize = 2;
|
||||
var headerSize = 45 + 35 + 28 + (20 * 2); // chrome + subnav + buttons + (container padding)
|
||||
var verticalPadding = 10;
|
||||
const borderSize = 2;
|
||||
const headerSize = 45 + 35 + 28 + (20 * 2); // chrome + subnav + buttons + (container padding)
|
||||
const verticalPadding = 10;
|
||||
|
||||
if ($scope.timelionGridColumns != null) {
|
||||
$elem.width($elem.parent().width() / $scope.timelionGridColumns - (borderSize * 2));
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
module.exports = function ($elem, fn, frequency) {
|
||||
|
||||
frequency = frequency || 500;
|
||||
var currentHeight = $elem.height();
|
||||
var currentWidth = $elem.width();
|
||||
let currentHeight = $elem.height();
|
||||
let currentWidth = $elem.width();
|
||||
|
||||
var timeout;
|
||||
let timeout;
|
||||
|
||||
function checkLoop() {
|
||||
timeout = setTimeout(function () {
|
||||
|
|
|
@ -1,33 +1,40 @@
|
|||
require('./flot');
|
||||
require('plugins/timelion/panels/timechart/timechart.less');
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var moment = require('moment-timezone');
|
||||
var observeResize = require('plugins/timelion/lib/observe_resize');
|
||||
var calculateInterval = require('plugins/timelion/lib/calculate_interval');
|
||||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
const moment = require('moment-timezone');
|
||||
const observeResize = require('plugins/timelion/lib/observe_resize');
|
||||
const calculateInterval = require('plugins/timelion/lib/calculate_interval');
|
||||
|
||||
const SET_LEGEND_NUMBERS_DELAY = 50;
|
||||
|
||||
module.exports = function timechartFn(Private, config, $rootScope, timefilter, $compile) {
|
||||
return function () {
|
||||
return {
|
||||
help: 'Draw a timeseries chart',
|
||||
render: function ($scope, $elem) {
|
||||
var template = '<div class="chart-top-title"></div><div class="chart-canvas"></div>';
|
||||
var timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
var getxAxisFormatter = Private(require('plugins/timelion/panels/timechart/xaxis_formatter'));
|
||||
const template = '<div class="chart-top-title"></div><div class="chart-canvas"></div>';
|
||||
const timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
const getxAxisFormatter = Private(require('plugins/timelion/panels/timechart/xaxis_formatter'));
|
||||
|
||||
// TODO: I wonder if we should supply our own moment that sets this every time?
|
||||
// could just use angular's injection to provide a moment service?
|
||||
moment.tz.setDefault(config.get('dateFormat:tz'));
|
||||
|
||||
var render = $scope.seriesList.render || {};
|
||||
const render = $scope.seriesList.render || {};
|
||||
|
||||
$scope.chart = $scope.seriesList.list;
|
||||
$scope.interval = $scope.interval;
|
||||
$scope.search = $scope.search || _.noop;
|
||||
|
||||
var legendValueNumbers;
|
||||
var debouncedSetLegendNumbers;
|
||||
var defaultOptions = {
|
||||
let legendValueNumbers;
|
||||
const debouncedSetLegendNumbers = _.debounce(setLegendNumbers, SET_LEGEND_NUMBERS_DELAY, {
|
||||
maxWait: SET_LEGEND_NUMBERS_DELAY,
|
||||
leading: true,
|
||||
trailing: false
|
||||
});
|
||||
|
||||
const defaultOptions = {
|
||||
xaxis: {
|
||||
mode: 'time',
|
||||
tickLength: 5,
|
||||
|
@ -65,12 +72,12 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
|
||||
|
||||
$scope.toggleSeries = function (id) {
|
||||
var series = $scope.chart[id];
|
||||
const series = $scope.chart[id];
|
||||
series._hide = !series._hide;
|
||||
drawPlot($scope.chart);
|
||||
};
|
||||
|
||||
var cancelResize = observeResize($elem, function () {
|
||||
const cancelResize = observeResize($elem, function () {
|
||||
drawPlot($scope.chart);
|
||||
});
|
||||
|
||||
|
@ -108,29 +115,22 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
clearLegendNumbers();
|
||||
});
|
||||
|
||||
var debounceDelay = 50;
|
||||
debouncedSetLegendNumbers = _.debounce(setLegendNumbers, debounceDelay, {
|
||||
maxWait: debounceDelay,
|
||||
leading: true,
|
||||
trailing: false
|
||||
});
|
||||
|
||||
// Shamelessly borrowed from the flotCrosshairs example
|
||||
function setLegendNumbers(pos) {
|
||||
var plot = $scope.plot;
|
||||
const plot = $scope.plot;
|
||||
|
||||
var axes = plot.getAxes();
|
||||
const axes = plot.getAxes();
|
||||
if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max) {
|
||||
return;
|
||||
}
|
||||
|
||||
var i;
|
||||
var j;
|
||||
var dataset = plot.getData();
|
||||
let i;
|
||||
let j;
|
||||
const dataset = plot.getData();
|
||||
for (i = 0; i < dataset.length; ++i) {
|
||||
|
||||
var series = dataset[i];
|
||||
var precision = _.get(series, '_meta.precision', 2);
|
||||
const series = dataset[i];
|
||||
const precision = _.get(series, '_meta.precision', 2);
|
||||
|
||||
if (series._hide) continue;
|
||||
|
||||
|
@ -139,7 +139,7 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
if (series.data[j][0] > pos.x) break;
|
||||
}
|
||||
|
||||
var y;
|
||||
let y;
|
||||
try {
|
||||
y = series.data[j][1];
|
||||
} catch (e) {
|
||||
|
@ -160,7 +160,7 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
});
|
||||
}
|
||||
|
||||
var legendScope = $scope.$new();
|
||||
let legendScope = $scope.$new();
|
||||
function drawPlot(plotConfig) {
|
||||
|
||||
if (!plotConfig || !plotConfig.length) {
|
||||
|
@ -169,22 +169,22 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
}
|
||||
|
||||
if (!$('.chart-canvas', $elem).length) $elem.html(template);
|
||||
var canvasElem = $('.chart-canvas', $elem);
|
||||
const canvasElem = $('.chart-canvas', $elem);
|
||||
|
||||
var title = _(plotConfig).map('_title').compact().last();
|
||||
const title = _(plotConfig).map('_title').compact().last();
|
||||
$('.chart-top-title', $elem).text(title == null ? '' : title);
|
||||
|
||||
var options = _.cloneDeep(defaultOptions);
|
||||
const options = _.cloneDeep(defaultOptions);
|
||||
|
||||
// Get the X-axis tick format
|
||||
var time = timefilter.getBounds();
|
||||
var interval = calculateInterval(
|
||||
const time = timefilter.getBounds();
|
||||
const interval = calculateInterval(
|
||||
time.min.valueOf(),
|
||||
time.max.valueOf(),
|
||||
config.get('timelion:target_buckets') || 200,
|
||||
$scope.interval
|
||||
);
|
||||
var format = getxAxisFormatter(interval);
|
||||
const format = getxAxisFormatter(interval);
|
||||
|
||||
// Use moment to format ticks so we get timezone correction
|
||||
options.xaxis.tickFormatter = function (val) {
|
||||
|
@ -192,11 +192,11 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $
|
|||
};
|
||||
|
||||
// Calculate how many ticks can fit on the axis
|
||||
var tickLetterWidth = 7;
|
||||
var tickPadding = 45;
|
||||
const tickLetterWidth = 7;
|
||||
const tickPadding = 45;
|
||||
options.xaxis.ticks = Math.floor($elem.width() / ((format.length * tickLetterWidth) + tickPadding));
|
||||
|
||||
var series = _.map(plotConfig, function (series, index) {
|
||||
const series = _.map(plotConfig, function (series, index) {
|
||||
series = _.cloneDeep(_.defaults(series, {
|
||||
shadowSize: 0,
|
||||
lines: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var Panel = require('plugins/timelion/panels/panel');
|
||||
var panelRegistry = require('plugins/timelion/lib/panel_registry');
|
||||
const Panel = require('plugins/timelion/panels/panel');
|
||||
const panelRegistry = require('plugins/timelion/lib/panel_registry');
|
||||
|
||||
panelRegistry.register(function timeChartProvider(Private) {
|
||||
// Schema is broken out so that it may be extended for use in other plugins
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
var moment = require('moment');
|
||||
const moment = require('moment');
|
||||
|
||||
module.exports = function xaxisFormatterProvider(config, timefilter) {
|
||||
|
||||
function getFormat(esInterval) {
|
||||
var parts = esInterval.match(/(\d+)(ms|s|m|h|d|w|M|y|)/);
|
||||
const parts = esInterval.match(/(\d+)(ms|s|m|h|d|w|M|y|)/);
|
||||
if (parts == null || parts[1] == null || parts[2] == null) throw new Error ('Unknown interval');
|
||||
|
||||
var interval = moment.duration(Number(parts[1]), parts[2]);
|
||||
const interval = moment.duration(Number(parts[1]), parts[2]);
|
||||
|
||||
// Cribbed from Kibana's TimeBuckets class
|
||||
let rules = config.get('dateFormat:scaled');
|
||||
const rules = config.get('dateFormat:scaled');
|
||||
|
||||
for (let i = rules.length - 1; i >= 0; i--) {
|
||||
let rule = rules[i];
|
||||
const rule = rules[i];
|
||||
if (!rule[0] || interval >= moment.duration(rule[0])) {
|
||||
return rule[1];
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
require('ui/state_management/app_state');
|
||||
|
||||
|
||||
module.exports = function dashboardContext(Private, getAppState) {
|
||||
return function () {
|
||||
var queryFilter = Private(require('ui/filter_bar/query_filter'));
|
||||
var bool = {must: [], must_not: []};
|
||||
var filterBarFilters = queryFilter.getFilters();
|
||||
var queryBarFilter = getAppState().query;
|
||||
const queryFilter = Private(require('ui/filter_bar/query_filter'));
|
||||
const bool = {must: [], must_not: []};
|
||||
const filterBarFilters = queryFilter.getFilters();
|
||||
const queryBarFilter = getAppState().query;
|
||||
|
||||
// Add the query bar filter, its handled differently.
|
||||
bool.must.push(queryBarFilter);
|
||||
|
||||
// Add each of the filter bar filters
|
||||
_.each(filterBarFilters, function (filter) {
|
||||
var esFilter = _.omit(filter, function (val, key) {
|
||||
const esFilter = _.omit(filter, function (val, key) {
|
||||
if (key === 'meta' || key[0] === '$') return true;
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
define(function (require) {
|
||||
var module = require('ui/modules').get('app/sheet');
|
||||
var _ = require('lodash');
|
||||
const module = require('ui/modules').get('app/sheet');
|
||||
const _ = require('lodash');
|
||||
// bring in the factory
|
||||
require('./_saved_sheet.js');
|
||||
|
||||
|
@ -41,8 +41,8 @@ define(function (require) {
|
|||
};
|
||||
|
||||
this.find = function (searchString) {
|
||||
var self = this;
|
||||
var body;
|
||||
const self = this;
|
||||
let body;
|
||||
if (searchString) {
|
||||
body = {
|
||||
query: {
|
||||
|
@ -67,7 +67,7 @@ define(function (require) {
|
|||
return {
|
||||
total: resp.hits.total,
|
||||
hits: resp.hits.hits.map(function (hit) {
|
||||
var source = hit._source;
|
||||
const source = hit._source;
|
||||
source.id = hit._id;
|
||||
source.url = self.urlFor(hit._id);
|
||||
return source;
|
||||
|
|
|
@ -10,7 +10,7 @@ define(function (require) {
|
|||
require('ui/registry/vis_types').register(TimelionVisProvider);
|
||||
|
||||
function TimelionVisProvider(Private) {
|
||||
var TemplateVisType = Private(require('ui/template_vis_type'));
|
||||
const TemplateVisType = Private(require('ui/template_vis_type'));
|
||||
|
||||
// return the visType object, which kibana will use to display and configure new
|
||||
// Vis object of this type.
|
||||
|
|
|
@ -4,8 +4,8 @@ define(function (require) {
|
|||
require('plugins/timelion/directives/refresh_hack');
|
||||
require('ui/state_management/app_state');
|
||||
|
||||
var _ = require('lodash');
|
||||
var module = require('ui/modules').get('kibana/timelion_vis', ['kibana']);
|
||||
const _ = require('lodash');
|
||||
const module = require('ui/modules').get('kibana/timelion_vis', ['kibana']);
|
||||
module.controller('TimelionVisController', function (
|
||||
$scope,
|
||||
$element,
|
||||
|
@ -16,16 +16,16 @@ define(function (require) {
|
|||
timefilter,
|
||||
getAppState
|
||||
) {
|
||||
var queryFilter = Private(require('ui/filter_bar/query_filter'));
|
||||
var timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
var dashboardContext = Private(require('plugins/timelion/services/dashboard_context'));
|
||||
const queryFilter = Private(require('ui/filter_bar/query_filter'));
|
||||
const timezone = Private(require('plugins/timelion/services/timezone'))();
|
||||
const dashboardContext = Private(require('plugins/timelion/services/dashboard_context'));
|
||||
|
||||
var notify = new Notifier({
|
||||
const notify = new Notifier({
|
||||
location: 'Timelion'
|
||||
});
|
||||
|
||||
$scope.search = function run() {
|
||||
var expression = $scope.vis.params.expression;
|
||||
const expression = $scope.vis.params.expression;
|
||||
if (!expression) return;
|
||||
|
||||
$http.post('../api/timelion/run', {
|
||||
|
@ -46,7 +46,7 @@ define(function (require) {
|
|||
})
|
||||
.error(function (resp) {
|
||||
$scope.sheet = [];
|
||||
var err = new Error(resp.message);
|
||||
const err = new Error(resp.message);
|
||||
err.stack = resp.stack;
|
||||
notify.error(err);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
define(function (require) {
|
||||
require('plugins/timelion/directives/expression_directive');
|
||||
|
||||
var module = require('ui/modules').get('kibana/timelion_vis', ['kibana']);
|
||||
const module = require('ui/modules').get('kibana/timelion_vis', ['kibana']);
|
||||
module.controller('TimelionVisParamsController', function ($scope, $rootScope) {
|
||||
$scope.vis.params.expression = $scope.vis.params.expression || '.es(*)';
|
||||
$scope.vis.params.interval = $scope.vis.params.interval || '1m';
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
var moment = require('moment');
|
||||
var expect = require('chai').expect;
|
||||
var _ = require('lodash');
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
const moment = require('moment');
|
||||
const expect = require('chai').expect;
|
||||
const _ = require('lodash');
|
||||
|
||||
describe(filename, function () {
|
||||
|
||||
describe('average', function () {
|
||||
it('fills holes in the data', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), 10],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), 40],
|
||||
[moment.utc('1984', 'YYYY').valueOf(), 50],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), null],
|
||||
|
@ -27,13 +27,13 @@ describe(filename, function () {
|
|||
|
||||
describe('sampling', function () {
|
||||
it('up', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), 10],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), 30],
|
||||
[moment.utc('1985', 'YYYY').valueOf(), 70],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), null],
|
||||
|
@ -46,7 +46,7 @@ describe(filename, function () {
|
|||
|
||||
|
||||
it('down', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), 0],
|
||||
[moment.utc('1981', 'YYYY').valueOf(), 2],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), 4],
|
||||
|
@ -56,7 +56,7 @@ describe(filename, function () {
|
|||
[moment.utc('1986', 'YYYY').valueOf(), 12],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1985', 'YYYY').valueOf(), null],
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
var moment = require('moment');
|
||||
var expect = require('chai').expect;
|
||||
var _ = require('lodash');
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
const moment = require('moment');
|
||||
const expect = require('chai').expect;
|
||||
const _ = require('lodash');
|
||||
|
||||
describe(filename, function () {
|
||||
it('fills holes in the data', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), 10],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), 40],
|
||||
[moment.utc('1984', 'YYYY').valueOf(), 50],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), null],
|
||||
|
@ -25,13 +25,13 @@ describe(filename, function () {
|
|||
|
||||
describe('sampling', function () {
|
||||
it('up', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), 10],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), 30],
|
||||
[moment.utc('1985', 'YYYY').valueOf(), 70],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), null],
|
||||
|
@ -44,7 +44,7 @@ describe(filename, function () {
|
|||
|
||||
|
||||
it('down does not make sense', function () {
|
||||
var data = [
|
||||
const data = [
|
||||
[moment.utc('1980', 'YYYY').valueOf(), 0],
|
||||
[moment.utc('1981', 'YYYY').valueOf(), 2],
|
||||
[moment.utc('1982', 'YYYY').valueOf(), 4],
|
||||
|
@ -54,7 +54,7 @@ describe(filename, function () {
|
|||
[moment.utc('1986', 'YYYY').valueOf(), 12],
|
||||
];
|
||||
|
||||
var target = [
|
||||
const target = [
|
||||
[moment.utc('1981', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1983', 'YYYY').valueOf(), null],
|
||||
[moment.utc('1985', 'YYYY').valueOf(), null],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
// Upsampling and down sampling of non-cummulative sets
|
||||
// Good: min, max, average
|
||||
|
@ -9,12 +9,12 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
// Phase 1: Downsample
|
||||
// We nessecarily won't well match the dataSource here as we don't know how much data
|
||||
// they had when creating their own average
|
||||
var resultTimes = _.pluck(targetTuples, 0);
|
||||
var dataTuplesQueue = _.clone(dataTuples);
|
||||
var resultValues = _.map(targetTuples, function (bucket) {
|
||||
var time = bucket[0];
|
||||
var i = 0;
|
||||
var avgSet = [];
|
||||
const resultTimes = _.pluck(targetTuples, 0);
|
||||
const dataTuplesQueue = _.clone(dataTuples);
|
||||
const resultValues = _.map(targetTuples, function (bucket) {
|
||||
const time = bucket[0];
|
||||
let i = 0;
|
||||
const avgSet = [];
|
||||
|
||||
// This is naive, it doesn't consider where the line is going next,
|
||||
// It simply writes the point and moves on once it hits <= time.
|
||||
|
@ -27,7 +27,7 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
|
||||
dataTuplesQueue.splice(0, i);
|
||||
|
||||
var sum = _.reduce(avgSet, function (sum, num) { return sum + num; }, 0);
|
||||
const sum = _.reduce(avgSet, function (sum, num) { return sum + num; }, 0);
|
||||
|
||||
return avgSet.length ? (sum / avgSet.length) : NaN;
|
||||
});
|
||||
|
@ -35,16 +35,16 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
// Phase 2: Upsample if needed
|
||||
// If we have any NaNs we are probably resampling from a big interval to a small one (eg, 1M as 1d)
|
||||
// So look for the missing stuff in the array, and smooth it out
|
||||
var naNIndex = _.findIndex(resultValues, function (val) {
|
||||
const naNIndex = _.findIndex(resultValues, function (val) {
|
||||
return isNaN(val);
|
||||
});
|
||||
|
||||
if (naNIndex > -1) {
|
||||
var i = 0;
|
||||
var naNCount = 0;
|
||||
var filledValues = [];
|
||||
var previousRealNumber;
|
||||
var stepSize;
|
||||
let i = 0;
|
||||
let naNCount = 0;
|
||||
const filledValues = [];
|
||||
let previousRealNumber;
|
||||
let stepSize;
|
||||
while (i < resultValues.length) {
|
||||
if (isNaN(resultValues[i])) {
|
||||
if (i === 0) {
|
||||
|
@ -70,6 +70,6 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
|
||||
}
|
||||
|
||||
var resultTuples = _.zip(resultTimes, resultValues);
|
||||
const resultTuples = _.zip(resultTimes, resultValues);
|
||||
return resultTuples;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
// Upsampling of non-cummulative sets
|
||||
// Good: average, min, max
|
||||
|
@ -12,10 +12,10 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
throw new Error (`Don't use the 'carry' fit method to down sample, use 'scale' or 'average'`);
|
||||
}
|
||||
|
||||
var currentCarry = dataTuples[0][1];
|
||||
let currentCarry = dataTuples[0][1];
|
||||
return _.map(targetTuples, function (bucket, h) {
|
||||
var targetTime = bucket[0];
|
||||
var dataTime = dataTuples[0][0];
|
||||
const targetTime = bucket[0];
|
||||
const dataTime = dataTuples[0][0];
|
||||
|
||||
if (dataTuples[0] && targetTime >= dataTime) {
|
||||
currentCarry = dataTuples[0][1];
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
// Upsampling and downsampling of non-cummulative sets
|
||||
// Good: average, min, max
|
||||
// Bad: sum, count
|
||||
module.exports = function (dataTuples, targetTuples) {
|
||||
return _.map(targetTuples, function (bucket, h) {
|
||||
var time = bucket[0];
|
||||
var i = 0;
|
||||
const time = bucket[0];
|
||||
let i = 0;
|
||||
while (i < dataTuples.length - 1 &&
|
||||
(Math.abs(dataTuples[i + 1][0] - time) < Math.abs(dataTuples[i][0] - time) ||
|
||||
// TODO: Certain offset= args can cause buckets with duplicate times, eg, offset=-1M
|
||||
|
@ -20,7 +20,7 @@ module.exports = function (dataTuples, targetTuples) {
|
|||
i++;
|
||||
}
|
||||
|
||||
var closest = dataTuples[i];
|
||||
const closest = dataTuples[i];
|
||||
dataTuples.splice(0, i);
|
||||
|
||||
return [bucket[0], closest[1]];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
// Downsampling of cummulative metrics
|
||||
// Good: count, sum
|
||||
|
@ -15,15 +15,15 @@ function sum(set) {
|
|||
|
||||
module.exports = function (dataTuples, targetTuples) {
|
||||
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var spreadCount = 0;
|
||||
var result = [];
|
||||
var bucket;
|
||||
var time;
|
||||
var scaleSet;
|
||||
var step;
|
||||
var nextRealNumber;
|
||||
let i = 0;
|
||||
let j = 0;
|
||||
let spreadCount = 0;
|
||||
const result = [];
|
||||
let bucket;
|
||||
let time;
|
||||
let scaleSet;
|
||||
let step;
|
||||
let nextRealNumber;
|
||||
|
||||
while (i < targetTuples.length) {
|
||||
scaleSet = [];
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
|
||||
var _ = require('lodash');
|
||||
var glob = require('glob');
|
||||
var Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const glob = require('glob');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
var parseSheet = require('./lib/parse_sheet.js');
|
||||
var parseDateMath = require('../lib/date_math.js');
|
||||
var calculateInterval = require('../../public/lib/calculate_interval.js');
|
||||
const parseSheet = require('./lib/parse_sheet.js');
|
||||
const parseDateMath = require('../lib/date_math.js');
|
||||
const calculateInterval = require('../../public/lib/calculate_interval.js');
|
||||
|
||||
var repositionArguments = require('./lib/reposition_arguments.js');
|
||||
var indexArguments = require('./lib/index_arguments.js');
|
||||
var validateTime = require('./lib/validate_time.js');
|
||||
const repositionArguments = require('./lib/reposition_arguments.js');
|
||||
const indexArguments = require('./lib/index_arguments.js');
|
||||
const validateTime = require('./lib/validate_time.js');
|
||||
|
||||
var loadFunctions = require('../lib/load_functions.js');
|
||||
var fitFunctions = loadFunctions('fit_functions');
|
||||
const loadFunctions = require('../lib/load_functions.js');
|
||||
const fitFunctions = loadFunctions('fit_functions');
|
||||
|
||||
module.exports = function (tlConfig) {
|
||||
var preprocessChain = require('./lib/preprocess_chain')(tlConfig);
|
||||
const preprocessChain = require('./lib/preprocess_chain')(tlConfig);
|
||||
|
||||
var queryCache = {};
|
||||
var stats = {};
|
||||
var sheet;
|
||||
let queryCache = {};
|
||||
const stats = {};
|
||||
let sheet;
|
||||
|
||||
function getQueryCacheKey(query) {
|
||||
return JSON.stringify(_.omit(query, 'label'));
|
||||
|
@ -31,7 +31,7 @@ module.exports = function (tlConfig) {
|
|||
|
||||
// Invokes a modifier function, resolving arguments into series as needed
|
||||
function invoke(fnName, args) {
|
||||
var functionDef = tlConfig.server.plugins.timelion.getFunction(fnName);
|
||||
const functionDef = tlConfig.server.plugins.timelion.getFunction(fnName);
|
||||
|
||||
function resolveArgument(item) {
|
||||
if (_.isArray(item)) {
|
||||
|
@ -40,15 +40,16 @@ module.exports = function (tlConfig) {
|
|||
|
||||
if (_.isObject(item)) {
|
||||
switch (item.type) {
|
||||
case 'function':
|
||||
var itemFunctionDef = tlConfig.server.plugins.timelion.getFunction(item.function);
|
||||
case 'function': {
|
||||
const itemFunctionDef = tlConfig.server.plugins.timelion.getFunction(item.function);
|
||||
if (itemFunctionDef.cacheKey && queryCache[itemFunctionDef.cacheKey(item)]) {
|
||||
stats.queryCount++;
|
||||
return Promise.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)]));
|
||||
}
|
||||
return invoke(item.function, item.arguments);
|
||||
case 'reference':
|
||||
var reference;
|
||||
}
|
||||
case 'reference': {
|
||||
let reference;
|
||||
if (item.series) {
|
||||
reference = sheet[item.plot - 1][item.series - 1];
|
||||
} else {
|
||||
|
@ -58,6 +59,7 @@ module.exports = function (tlConfig) {
|
|||
};
|
||||
}
|
||||
return invoke('first', [reference]);
|
||||
}
|
||||
case 'chain':
|
||||
return invokeChain(item);
|
||||
case 'chainList':
|
||||
|
@ -87,16 +89,16 @@ module.exports = function (tlConfig) {
|
|||
function invokeChain(chainObj, result) {
|
||||
if (chainObj.chain.length === 0) return result[0];
|
||||
|
||||
var chain = _.clone(chainObj.chain);
|
||||
var link = chain.shift();
|
||||
const chain = _.clone(chainObj.chain);
|
||||
const link = chain.shift();
|
||||
|
||||
var promise;
|
||||
let promise;
|
||||
if (link.type === 'chain') {
|
||||
promise = invokeChain(link);
|
||||
} else if (!result) {
|
||||
promise = invoke('first', [link]);
|
||||
} else {
|
||||
var args = link.arguments ? result.concat(link.arguments) : result;
|
||||
const args = link.arguments ? result.concat(link.arguments) : result;
|
||||
promise = invoke(link.function, args);
|
||||
}
|
||||
|
||||
|
@ -107,15 +109,15 @@ module.exports = function (tlConfig) {
|
|||
}
|
||||
|
||||
function resolveChainList(chainList) {
|
||||
var seriesList = _.map(chainList, function (chain) {
|
||||
var values = invoke('first', [chain]);
|
||||
const seriesList = _.map(chainList, function (chain) {
|
||||
const values = invoke('first', [chain]);
|
||||
return values.then(function (args) {
|
||||
return args;
|
||||
});
|
||||
});
|
||||
return Promise.all(seriesList).then(function (args) {
|
||||
var list = _.chain(args).pluck('list').flatten().value();
|
||||
var seriesList = _.merge.apply(this, _.flatten([{}, args]));
|
||||
const list = _.chain(args).pluck('list').flatten().value();
|
||||
const seriesList = _.merge.apply(this, _.flatten([{}, args]));
|
||||
seriesList.list = list;
|
||||
return seriesList;
|
||||
});
|
||||
|
@ -123,10 +125,10 @@ module.exports = function (tlConfig) {
|
|||
|
||||
function preProcessSheet(sheet) {
|
||||
|
||||
var queries = {};
|
||||
let queries = {};
|
||||
_.each(sheet, function (chainList, i) {
|
||||
try {
|
||||
var queriesInCell = _.mapValues(preprocessChain(chainList), function (val) {
|
||||
const queriesInCell = _.mapValues(preprocessChain(chainList), function (val) {
|
||||
val.cell = i;
|
||||
return val;
|
||||
});
|
||||
|
@ -137,7 +139,7 @@ module.exports = function (tlConfig) {
|
|||
});
|
||||
queries = _.values(queries);
|
||||
|
||||
var promises = _.chain(queries).values().map(function (query) {
|
||||
const promises = _.chain(queries).values().map(function (query) {
|
||||
return invoke(query.function, query.arguments);
|
||||
}).value();
|
||||
|
||||
|
@ -146,8 +148,8 @@ module.exports = function (tlConfig) {
|
|||
stats.queryTime = (new Date()).getTime();
|
||||
|
||||
_.each(queries, function (query, i) {
|
||||
var functionDef = tlConfig.server.plugins.timelion.getFunction(query.function);
|
||||
var resolvedDatasource = resolvedDatasources[i];
|
||||
const functionDef = tlConfig.server.plugins.timelion.getFunction(query.function);
|
||||
const resolvedDatasource = resolvedDatasources[i];
|
||||
|
||||
if (resolvedDatasource.isRejected()) {
|
||||
if (resolvedDatasource.reason().isBoom) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function argType(arg) {
|
||||
if (_.isArray(arg)) {
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
// Only applies to already resolved arguments
|
||||
module.exports = function indexArguments(functionDef, orderedArgs) {
|
||||
|
||||
var validateArg = require('./validate_arg')(functionDef);
|
||||
const validateArg = require('./validate_arg')(functionDef);
|
||||
|
||||
// This almost certainly is not required
|
||||
var allowedLength = functionDef.extended ? functionDef.args.length + 2 : functionDef.args.length;
|
||||
const allowedLength = functionDef.extended ? functionDef.args.length + 2 : functionDef.args.length;
|
||||
if (orderedArgs.length > allowedLength) throw new Error ('Too many arguments passed to: ' + functionDef.name);
|
||||
|
||||
var indexedArgs = {};
|
||||
const indexedArgs = {};
|
||||
// Check and index each known argument
|
||||
_.each(functionDef.args, function (argDef, i) {
|
||||
var value = orderedArgs[i];
|
||||
const value = orderedArgs[i];
|
||||
validateArg(value, argDef.name, argDef);
|
||||
indexedArgs[argDef.name] = value;
|
||||
});
|
||||
|
||||
// Also check and index the extended arguments if enabled
|
||||
if (functionDef.extended) {
|
||||
var values = orderedArgs[orderedArgs.length - 1];
|
||||
var names = orderedArgs[orderedArgs.length - 2];
|
||||
const values = orderedArgs[orderedArgs.length - 1];
|
||||
const names = orderedArgs[orderedArgs.length - 2];
|
||||
_.each(values, function (value, i) {
|
||||
validateArg(value, names[i], functionDef.extended);
|
||||
indexedArgs[names[i]] = value;
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var grammar = fs.readFileSync(path.resolve(__dirname, '../../../public/chain.peg'), 'utf8');
|
||||
var PEG = require('pegjs');
|
||||
var Parser = PEG.buildParser(grammar);
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const grammar = fs.readFileSync(path.resolve(__dirname, '../../../public/chain.peg'), 'utf8');
|
||||
const PEG = require('pegjs');
|
||||
const Parser = PEG.buildParser(grammar);
|
||||
|
||||
module.exports = function parseSheet(sheet) {
|
||||
return _.map(sheet, function (plot) {
|
||||
try {
|
||||
return Parser.parse(plot).tree;
|
||||
} catch (e) {
|
||||
var message;
|
||||
let message;
|
||||
if (e.expected) {
|
||||
throw new Error('Expected: ' + e.expected[0].description + ' @ character ' + e.column);
|
||||
} else {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function preProcessChainFn(tlConfig) {
|
||||
return function preProcessChain(chain, queries) {
|
||||
queries = queries || {};
|
||||
function validateAndStore(item) {
|
||||
if (_.isObject(item) && item.type === 'function') {
|
||||
var functionDef = tlConfig.server.plugins.timelion.getFunction(item.function);
|
||||
const functionDef = tlConfig.server.plugins.timelion.getFunction(item.function);
|
||||
|
||||
if (functionDef.datasource) {
|
||||
queries[functionDef.cacheKey(item)] = item;
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
// Applies to unresolved arguments in the AST
|
||||
module.exports = function repositionArguments(functionDef, unorderedArgs) {
|
||||
var args = [];
|
||||
const args = [];
|
||||
|
||||
_.each(unorderedArgs, function (unorderedArg, i) {
|
||||
var argDef;
|
||||
var targetIndex;
|
||||
var value;
|
||||
var storeAsArray;
|
||||
let argDef;
|
||||
let targetIndex;
|
||||
let value;
|
||||
let storeAsArray;
|
||||
|
||||
if (_.isObject(unorderedArg) && unorderedArg.type === 'namedArg') {
|
||||
argDef = functionDef.argsByName[unorderedArg.name];
|
||||
|
||||
if (!argDef) {
|
||||
if (functionDef.extended) {
|
||||
var namesIndex = functionDef.args.length;
|
||||
const namesIndex = functionDef.args.length;
|
||||
targetIndex = functionDef.args.length + 1;
|
||||
|
||||
args[namesIndex] = args[namesIndex] || [];
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
var buildTarget = require('../../lib/build_target.js');
|
||||
const buildTarget = require('../../lib/build_target.js');
|
||||
|
||||
module.exports = function (setup) {
|
||||
var targetSeries;
|
||||
let targetSeries;
|
||||
|
||||
var tlConfig = {
|
||||
let tlConfig = {
|
||||
getTargetSeries: function () {
|
||||
return _.map(targetSeries, function (bucket) { // eslint-disable-line no-use-before-define
|
||||
return [bucket, null];
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var argType = require('./arg_type');
|
||||
var _ = require('lodash');
|
||||
const argType = require('./arg_type');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (functionDef) {
|
||||
return function validateArg(value, name, argDef) {
|
||||
var type = argType(value);
|
||||
var required = argDef.types;
|
||||
var multi = argDef.multi;
|
||||
var isCorrectType = (function () {
|
||||
const type = argType(value);
|
||||
const required = argDef.types;
|
||||
const multi = argDef.multi;
|
||||
const isCorrectType = (function () {
|
||||
// If argument is not allow to be specified multiple times, we're dealing with a plain value for type
|
||||
if (!multi) return _.contains(required, type);
|
||||
// If it is, we'll get an array for type
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var parseDateMath = require('../../lib/date_math.js');
|
||||
var toMS = require('../../lib/to_milliseconds.js');
|
||||
const parseDateMath = require('../../lib/date_math.js');
|
||||
const toMS = require('../../lib/to_milliseconds.js');
|
||||
|
||||
module.exports = function validateTime(time, tlConfig) {
|
||||
var span = parseDateMath(time.to, true) - parseDateMath(time.from);
|
||||
var interval = toMS(time.interval);
|
||||
var bucketCount = span / interval;
|
||||
var maxBuckets = tlConfig.settings['timelion:max_buckets'];
|
||||
const span = parseDateMath(time.to, true) - parseDateMath(time.from);
|
||||
const interval = toMS(time.interval);
|
||||
const bucketCount = span / interval;
|
||||
const maxBuckets = tlConfig.settings['timelion:max_buckets'];
|
||||
if (bucketCount > maxBuckets) {
|
||||
throw new Error('Max buckets exceeded: ' +
|
||||
Math.round(bucketCount) + ' of ' + maxBuckets + ' allowed. ' +
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
let filename = require('path').basename(__filename);
|
||||
let fn = require(`../${filename}`);
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
|
||||
let _ = require('lodash');
|
||||
let expect = require('chai').expect;
|
||||
const _ = require('lodash');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe(filename, () => {
|
||||
it('exports a function', () => {
|
||||
|
@ -10,14 +10,14 @@ describe(filename, () => {
|
|||
});
|
||||
|
||||
it('returns an object with keys named for the javascript files in the directory', () => {
|
||||
var fnList = fn('series_functions');
|
||||
const fnList = fn('series_functions');
|
||||
|
||||
expect(fnList).to.be.an('object');
|
||||
expect(fnList.sum).to.be.a('object');
|
||||
});
|
||||
|
||||
it('also includes index.js files in direct subdirectories, and names the keys for the directory', () => {
|
||||
var fnList = fn('series_functions');
|
||||
const fnList = fn('series_functions');
|
||||
|
||||
expect(fnList).to.be.an('object');
|
||||
expect(fnList.es).to.be.a('object');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var Promise = require('bluebird');
|
||||
var _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
|
||||
/* @param {Array} args
|
||||
* - args[0] must be a seriesList
|
||||
|
@ -12,13 +12,13 @@ module.exports = function alter(args, fn) {
|
|||
// In theory none of the args should ever be promises. This is probably a waste.
|
||||
return Promise.all(args).then(function (args) {
|
||||
|
||||
var seriesList = args.shift();
|
||||
const seriesList = args.shift();
|
||||
|
||||
if (seriesList.type !== 'seriesList') {
|
||||
throw new Error ('args[0] must be a seriesList');
|
||||
}
|
||||
|
||||
var list = _.chain(seriesList.list).map(function (series) {
|
||||
const list = _.chain(seriesList.list).map(function (series) {
|
||||
return fn.apply(this, [series].concat(args));
|
||||
}).flatten().value();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
var unzipPairs = require('./unzipPairs.js');
|
||||
const _ = require('lodash');
|
||||
const unzipPairs = require('./unzipPairs.js');
|
||||
|
||||
module.exports = function asSorted(timeValObject, fn) {
|
||||
var data = unzipPairs(timeValObject);
|
||||
const data = unzipPairs(timeValObject);
|
||||
return _.zipObject(fn(data));
|
||||
};
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var moment = require('moment');
|
||||
const moment = require('moment');
|
||||
|
||||
var splitInterval = require('./split_interval.js');
|
||||
const splitInterval = require('./split_interval.js');
|
||||
|
||||
module.exports = function (tlConfig) {
|
||||
var min = moment(tlConfig.time.from);
|
||||
var max = moment(tlConfig.time.to);
|
||||
const min = moment(tlConfig.time.from);
|
||||
const max = moment(tlConfig.time.to);
|
||||
|
||||
var intervalParts = splitInterval(tlConfig.time.interval);
|
||||
const intervalParts = splitInterval(tlConfig.time.interval);
|
||||
|
||||
var current = min.startOf(intervalParts.unit);
|
||||
let current = min.startOf(intervalParts.unit);
|
||||
|
||||
var targetSeries = [];
|
||||
const targetSeries = [];
|
||||
|
||||
while (current.valueOf() < max.valueOf()) {
|
||||
targetSeries.push(current.valueOf());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var TimelionFunction = require('./timelion_function');
|
||||
const TimelionFunction = require('./timelion_function');
|
||||
|
||||
module.exports = class Chainable extends TimelionFunction {
|
||||
constructor(name, config) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var loadFunctions = require('../load_functions.js');
|
||||
var fitFunctions = loadFunctions('fit_functions');
|
||||
var TimelionFunction = require('./timelion_function');
|
||||
var offsetTime = require('../offset_time');
|
||||
const loadFunctions = require('../load_functions.js');
|
||||
const fitFunctions = loadFunctions('fit_functions');
|
||||
const TimelionFunction = require('./timelion_function');
|
||||
const offsetTime = require('../offset_time');
|
||||
|
||||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
|
||||
function offsetSeries(response, offset) {
|
||||
|
@ -33,9 +33,9 @@ module.exports = class Datasource extends TimelionFunction {
|
|||
});
|
||||
|
||||
// Wrap the original function so we can modify inputs/outputs with offset & fit
|
||||
var originalFunction = config.fn;
|
||||
const originalFunction = config.fn;
|
||||
config.fn = function (args, tlConfig) {
|
||||
var config = _.clone(tlConfig);
|
||||
const config = _.clone(tlConfig);
|
||||
if (args.byName.offset) {
|
||||
config.time = _.cloneDeep(tlConfig.time);
|
||||
config.time.from = offsetTime(config.time.from, args.byName.offset);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var _ = require('lodash');
|
||||
var loadFunctions = require('../load_functions.js');
|
||||
var fitFunctions = loadFunctions('fit_functions');
|
||||
const _ = require('lodash');
|
||||
const loadFunctions = require('../load_functions.js');
|
||||
const fitFunctions = loadFunctions('fit_functions');
|
||||
|
||||
module.exports = class TimelionFunction {
|
||||
constructor(name, config) {
|
||||
|
@ -12,21 +12,21 @@ module.exports = class TimelionFunction {
|
|||
this.extended = config.extended || false;
|
||||
|
||||
// WTF is this? How could you not have a fn? Wtf would the thing be used for?
|
||||
var originalFunction = config.fn || function (input) { return input; };
|
||||
const originalFunction = config.fn || function (input) { return input; };
|
||||
|
||||
// Currently only re-fits the series.
|
||||
this.originalFn = originalFunction;
|
||||
|
||||
this.fn = function (args, tlConfig) {
|
||||
var config = _.clone(tlConfig);
|
||||
const config = _.clone(tlConfig);
|
||||
return Promise.resolve(originalFunction(args, config)).then(function (seriesList) {
|
||||
seriesList.list = _.map(seriesList.list, function (series) {
|
||||
var target = tlConfig.getTargetSeries();
|
||||
const target = tlConfig.getTargetSeries();
|
||||
|
||||
// Don't fit if the series are already the same
|
||||
if (_.isEqual(_.map(series.data, 0), _.map(target, 0))) return series;
|
||||
|
||||
var fit;
|
||||
let fit;
|
||||
if (args.byName.fit) {
|
||||
fit = args.byName.fit;
|
||||
} else if (series.fit) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
var units = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
|
||||
const units = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
|
||||
|
||||
/* This is a simplified version of elasticsearch's date parser */
|
||||
function parse(text, roundUp) {
|
||||
|
@ -15,10 +15,10 @@ function parse(text, roundUp) {
|
|||
return moment(text);
|
||||
}
|
||||
|
||||
var time;
|
||||
var mathString = '';
|
||||
var index;
|
||||
var parseString;
|
||||
let time;
|
||||
let mathString = '';
|
||||
let index;
|
||||
let parseString;
|
||||
|
||||
if (text.substring(0, 3) === 'now') {
|
||||
time = moment();
|
||||
|
@ -44,13 +44,12 @@ function parse(text, roundUp) {
|
|||
}
|
||||
|
||||
function parseDateMath(mathString, time, roundUp) {
|
||||
var dateTime = time;
|
||||
const dateTime = time;
|
||||
|
||||
for (var i = 0; i < mathString.length;) {
|
||||
var c = mathString.charAt(i++);
|
||||
var type;
|
||||
var num;
|
||||
var unit;
|
||||
for (let i = 0; i < mathString.length;) {
|
||||
const c = mathString.charAt(i++);
|
||||
let type;
|
||||
let num;
|
||||
|
||||
if (c === '/') {
|
||||
type = 0;
|
||||
|
@ -67,7 +66,7 @@ function parseDateMath(mathString, time, roundUp) {
|
|||
} else if (mathString.length === 2) {
|
||||
num = mathString.charAt(i);
|
||||
} else {
|
||||
var numFrom = i;
|
||||
const numFrom = i;
|
||||
while (!isNaN(mathString.charAt(i))) {
|
||||
i++;
|
||||
if (i > 10) {
|
||||
|
@ -83,7 +82,7 @@ function parseDateMath(mathString, time, roundUp) {
|
|||
return undefined;
|
||||
}
|
||||
}
|
||||
unit = mathString.charAt(i++);
|
||||
const unit = mathString.charAt(i++);
|
||||
|
||||
if (!_.contains(units, unit)) {
|
||||
return undefined;
|
||||
|
@ -104,4 +103,4 @@ function parseDateMath(mathString, time, roundUp) {
|
|||
return dateTime;
|
||||
}
|
||||
|
||||
module.exports = parse;
|
||||
module.exports = parse;
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var loadFunctions = require('./load_functions.js');
|
||||
var functions = loadFunctions('series_functions/');
|
||||
var _ = require('lodash');
|
||||
const loadFunctions = require('./load_functions.js');
|
||||
const functions = loadFunctions('series_functions/');
|
||||
const _ = require('lodash');
|
||||
|
||||
|
||||
module.exports = (function () {
|
||||
var functionArray = _.map(functions, function (val, key) {
|
||||
const functionArray = _.map(functions, function (val, key) {
|
||||
// TODO: This won't work on frozen objects, it should be removed when everything is converted to datasources and chainables
|
||||
return _.extend({}, val, {name: key});
|
||||
});
|
||||
|
||||
function toDocBlock(fn) {
|
||||
var help = '';
|
||||
let help = '';
|
||||
|
||||
if (fn.isAlias) return help;
|
||||
|
||||
|
@ -18,7 +18,7 @@ module.exports = (function () {
|
|||
help += fn.help + '\n\n';
|
||||
|
||||
// If chainable, drop first argument from help
|
||||
var args = fn.chainable ? fn.args.slice(1) : fn.args.slice();
|
||||
const args = fn.chainable ? fn.args.slice(1) : fn.args.slice();
|
||||
if (!args.length) {
|
||||
help += '*This function does not accept any arguments.*\n\n';
|
||||
return help;
|
||||
|
@ -39,7 +39,7 @@ module.exports = (function () {
|
|||
}
|
||||
|
||||
function createDocs() {
|
||||
var help = '';
|
||||
let help = '';
|
||||
help += '## Timelion function reference\n';
|
||||
help += 'This document is auto generated from the timelion code. ' +
|
||||
'Do not submit pulls against this document. You want to submit a pull against something in the ' +
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var _ = require('lodash');
|
||||
var configFile = require('../../timelion.json');
|
||||
const _ = require('lodash');
|
||||
const configFile = require('../../timelion.json');
|
||||
|
||||
module.exports = function () {
|
||||
function flattenWith(dot, nestedObj, flattenArrays) {
|
||||
let stack = []; // track key stack
|
||||
let flatObj = {};
|
||||
const stack = []; // track key stack
|
||||
const flatObj = {};
|
||||
(function flattenObj(obj) {
|
||||
_.keys(obj).forEach(function (key) {
|
||||
stack.push(key);
|
||||
|
@ -17,7 +17,7 @@ module.exports = function () {
|
|||
return flatObj;
|
||||
};
|
||||
|
||||
var timelionDefaults = flattenWith('.', configFile);
|
||||
const timelionDefaults = flattenWith('.', configFile);
|
||||
return _.reduce(timelionDefaults, (result, value, key) => {
|
||||
result['timelion:' + key] = value;
|
||||
return result;
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
var _ = require('lodash');
|
||||
var glob = require('glob');
|
||||
var path = require('path');
|
||||
var processFunctionDefinition = require('./process_function_definition');
|
||||
const _ = require('lodash');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const processFunctionDefinition = require('./process_function_definition');
|
||||
|
||||
module.exports = function (directory) {
|
||||
|
||||
function getTuple(directory, name) {
|
||||
var func = require('../' + directory + '/' + name);
|
||||
const func = require('../' + directory + '/' + name);
|
||||
return [name, require('../' + directory + '/' + name)];
|
||||
}
|
||||
|
||||
// Get a list of all files and use the filename as the object key
|
||||
var files = _.map(glob.sync(path.resolve(__dirname, '../' + directory + '/*.js')), function (file) {
|
||||
var name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.'));
|
||||
const files = _.map(glob.sync(path.resolve(__dirname, '../' + directory + '/*.js')), function (file) {
|
||||
const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.'));
|
||||
return getTuple(directory, name);
|
||||
});
|
||||
|
||||
// Get a list of all directories with an index.js, use the directory name as the key in the object
|
||||
var directories = _.chain(glob.sync(path.resolve(__dirname, '../' + directory + '/*/index.js')))
|
||||
const directories = _.chain(glob.sync(path.resolve(__dirname, '../' + directory + '/*/index.js')))
|
||||
.filter(function (file) {
|
||||
return file.match(/__test__/) == null;
|
||||
})
|
||||
.map(function (file) {
|
||||
var parts = file.split('/');
|
||||
var name = parts[parts.length - 2];
|
||||
const parts = file.split('/');
|
||||
const name = parts[parts.length - 2];
|
||||
return getTuple(directory, parts[parts.length - 2]);
|
||||
}).value();
|
||||
|
||||
var functions = _.zipObject(files.concat(directories));
|
||||
const functions = _.zipObject(files.concat(directories));
|
||||
|
||||
_.each(functions, function (func) {
|
||||
_.assign(functions, processFunctionDefinition(func));
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
var moment = require('moment');
|
||||
const moment = require('moment');
|
||||
|
||||
// usually reverse = false on the request, true on the response
|
||||
module.exports = function offsetTime(milliseconds, offset, reverse) {
|
||||
if (!offset.match(/[-+][0-9]+[mshdwMy]/g)) {
|
||||
throw new Error ('Malformed `offset` at ' + offset);
|
||||
}
|
||||
var parts = offset.match(/[-+]|[0-9]+|[mshdwMy]/g);
|
||||
const parts = offset.match(/[-+]|[0-9]+|[mshdwMy]/g);
|
||||
|
||||
var add = parts[0] === '+';
|
||||
let add = parts[0] === '+';
|
||||
add = reverse ? !add : add;
|
||||
|
||||
var mode = add ? 'add' : 'subtract';
|
||||
const mode = add ? 'add' : 'subtract';
|
||||
|
||||
var momentObj = moment(milliseconds)[mode](parts[1], parts[2]);
|
||||
const momentObj = moment(milliseconds)[mode](parts[1], parts[2]);
|
||||
return momentObj.valueOf();
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (func) {
|
||||
var functions = {};
|
||||
const functions = {};
|
||||
functions[func.name] = func;
|
||||
if (func.aliases) {
|
||||
_.each(func.aliases, function (alias) {
|
||||
var aliasFn = _.clone(func);
|
||||
const aliasFn = _.clone(func);
|
||||
aliasFn.isAlias = true;
|
||||
functions[alias] = aliasFn;
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var _ = require('lodash');
|
||||
var Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,8 +15,8 @@ var Promise = require('bluebird');
|
|||
module.exports = function reduce(args, fn) {
|
||||
return Promise.all(args).then(function (args) {
|
||||
|
||||
var seriesList = args.shift();
|
||||
var argument = args.shift();
|
||||
const seriesList = args.shift();
|
||||
let argument = args.shift();
|
||||
|
||||
if (seriesList.type !== 'seriesList') {
|
||||
throw new Error ('input must be a seriesList');
|
||||
|
@ -34,9 +34,9 @@ module.exports = function reduce(args, fn) {
|
|||
function reduceSeries(series) {
|
||||
return _.reduce(series, function (destinationObject, argument, i, p) {
|
||||
|
||||
var output = _.map(destinationObject.data, function (point, index) {
|
||||
let output = _.map(destinationObject.data, function (point, index) {
|
||||
|
||||
var value = point[1];
|
||||
const value = point[1];
|
||||
|
||||
if (value == null) {
|
||||
return [point[0], null];
|
||||
|
@ -64,7 +64,7 @@ module.exports = function reduce(args, fn) {
|
|||
|
||||
}
|
||||
|
||||
var reduced;
|
||||
let reduced;
|
||||
|
||||
if (argument != null) {
|
||||
reduced = _.map(seriesList.list, function (series) {
|
||||
|
|
|
@ -2,7 +2,7 @@ module.exports = function splitInterval(interval) {
|
|||
if (!interval.match(/[0-9]+[mshdwMy]+/g)) {
|
||||
throw new Error ('Malformed `interval`: ' + interval);
|
||||
}
|
||||
var parts = interval.match(/[0-9]+|[mshdwMy]+/g);
|
||||
const parts = interval.match(/[0-9]+|[mshdwMy]+/g);
|
||||
|
||||
return {
|
||||
count: parts[0],
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
// map of moment's short/long unit ids and elasticsearch's long unit ids
|
||||
// to their value in milliseconds
|
||||
var vals = _.transform([
|
||||
const vals = _.transform([
|
||||
['ms', 'milliseconds', 'millisecond'],
|
||||
['s', 'seconds', 'second', 'sec'],
|
||||
['m', 'minutes', 'minute', 'min'],
|
||||
|
@ -14,17 +14,17 @@ var vals = _.transform([
|
|||
['quarter'],
|
||||
['y', 'years', 'year']
|
||||
], function (vals, units) {
|
||||
var normal = moment.normalizeUnits(units[0]);
|
||||
var val = moment.duration(1, normal).asMilliseconds();
|
||||
const normal = moment.normalizeUnits(units[0]);
|
||||
const val = moment.duration(1, normal).asMilliseconds();
|
||||
[].concat(normal, units).forEach(function (unit) {
|
||||
vals[unit] = val;
|
||||
});
|
||||
}, {});
|
||||
// match any key from the vals object prececed by an optional number
|
||||
var parseRE = new RegExp('^(\\d+(?:\\.\\d*)?)?\\s*(' + _.keys(vals).join('|') + ')$');
|
||||
const parseRE = new RegExp('^(\\d+(?:\\.\\d*)?)?\\s*(' + _.keys(vals).join('|') + ')$');
|
||||
|
||||
module.exports = function (expr) {
|
||||
var match = expr.match(parseRE);
|
||||
const match = expr.match(parseRE);
|
||||
if (match) {
|
||||
if (match[2] === 'M' && match[1] !== '1') {
|
||||
throw new Error ('Invalid interval. 1M is only valid monthly interval.');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function unzipPairs(timeValObject) {
|
||||
var paired = _.chain(timeValObject).pairs().map(function (point) {
|
||||
const paired = _.chain(timeValObject).pairs().map(function (point) {
|
||||
return [parseInt(point[0], 10), point[1]];
|
||||
}).sortBy(function (point) {
|
||||
return point[0];
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (server) {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/api/timelion/functions',
|
||||
handler: function (request, reply) {
|
||||
var functionArray = _.map(server.plugins.timelion.functions, function (val, key) {
|
||||
const functionArray = _.map(server.plugins.timelion.functions, function (val, key) {
|
||||
// TODO: This won't work on frozen objects, it should be removed when everything is converted to datasources and chainables
|
||||
return _.extend({}, val, {name: key});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var Promise = require('bluebird');
|
||||
var _ = require('lodash');
|
||||
var Boom = require('boom');
|
||||
var chainRunnerFn = require('../handlers/chain_runner.js');
|
||||
var timelionDefaults = require('../lib/get_namespaced_settings')();
|
||||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const Boom = require('boom');
|
||||
const chainRunnerFn = require('../handlers/chain_runner.js');
|
||||
const timelionDefaults = require('../lib/get_namespaced_settings')();
|
||||
|
||||
function replyWithError(e, reply) {
|
||||
reply({title: e.toString(), message: e.toString(), stack: e.stack}).code(400);
|
||||
|
|
|
@ -5,11 +5,11 @@ module.exports = function (server) {
|
|||
handler: function (request, reply) {
|
||||
|
||||
return server.uiSettings().getAll(request).then((uiSettings) => {
|
||||
var callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
|
||||
var timefield = uiSettings['timelion:es.timefield'];
|
||||
const timefield = uiSettings['timelion:es.timefield'];
|
||||
|
||||
var body = {
|
||||
const body = {
|
||||
index: uiSettings['es.default_index'],
|
||||
fields:timefield
|
||||
};
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
|
||||
var _ = require('lodash');
|
||||
var expect = require('chai').expect;
|
||||
var seriesList = require('./fixtures/seriesList.js')();
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
const _ = require('lodash');
|
||||
const expect = require('chai').expect;
|
||||
const seriesList = require('./fixtures/seriesList.js')();
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
|
||||
describe(filename, function () {
|
||||
it('should return the positive value of every value', function () {
|
||||
|
||||
return invoke(fn, [seriesList]).then(function (result) {
|
||||
var before = _.filter(result.input[0].list[0].data, function (point) {
|
||||
const before = _.filter(result.input[0].list[0].data, function (point) {
|
||||
return (point[1] < 0);
|
||||
});
|
||||
|
||||
var after = _.filter(result.output.list[0].data, function (point) {
|
||||
const after = _.filter(result.output.list[0].data, function (point) {
|
||||
return (point[1] < 0);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
|
||||
var _ = require('lodash');
|
||||
var expect = require('chai').expect;
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
const _ = require('lodash');
|
||||
const expect = require('chai').expect;
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
|
||||
describe(filename, () => {
|
||||
|
||||
var seriesList;
|
||||
let seriesList;
|
||||
beforeEach(() => {
|
||||
seriesList = require('./fixtures/seriesList.js')();
|
||||
});
|
||||
|
||||
it('creates the bars property, with defaults, on all series', () => {
|
||||
return invoke(fn, [seriesList]).then((r) => {
|
||||
var bars = _.map(r.output.list, 'bars');
|
||||
const bars = _.map(r.output.list, 'bars');
|
||||
_.each(bars, (bar) => expect(bar).to.be.a('object'));
|
||||
_.each(bars, (bar) => expect(bar.lineWidth).to.equal(6));
|
||||
_.each(bars, (bar) => expect(bar.show).to.equal(1));
|
||||
|
@ -24,7 +24,7 @@ describe(filename, () => {
|
|||
it('leaves existing bars alone when called without option, if they exist', () => {
|
||||
seriesList.list[0].bars = {foo: true};
|
||||
return invoke(fn, [seriesList]).then((r) => {
|
||||
var bars = _.map(r.output.list, 'bars');
|
||||
const bars = _.map(r.output.list, 'bars');
|
||||
expect(bars[0].foo).to.equal(true);
|
||||
expect(bars[1].foo).to.equal(undefined);
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ describe(filename, () => {
|
|||
|
||||
it('sets lineWidth and show to the same value', () => {
|
||||
return invoke(fn, [seriesList, 0]).then((r) => {
|
||||
var bars = _.map(r.output.list, 'bars');
|
||||
const bars = _.map(r.output.list, 'bars');
|
||||
expect(bars[0].lineWidth).to.equal(0);
|
||||
expect(bars[0].show).to.equal(0);
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
var moment = require('moment');
|
||||
var expect = require('chai').expect;
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
var getSeriesList = require('./helpers/get_single_series_list');
|
||||
var _ = require('lodash');
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
const moment = require('moment');
|
||||
const expect = require('chai').expect;
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
const getSeriesList = require('./helpers/get_single_series_list');
|
||||
const _ = require('lodash');
|
||||
|
||||
describe(filename, function () {
|
||||
|
||||
var comparable;
|
||||
var seriesList;
|
||||
let comparable;
|
||||
let seriesList;
|
||||
beforeEach(function () {
|
||||
seriesList = require('./fixtures/seriesList.js')();
|
||||
comparable = getSeriesList('',[
|
||||
|
|
|
@ -25,7 +25,7 @@ function stubResponse(response) {
|
|||
}
|
||||
|
||||
describe(filename, () => {
|
||||
var tlConfig;
|
||||
let tlConfig;
|
||||
|
||||
describe('seriesList processor', () => {
|
||||
it('throws an error then the index is missing', () => {
|
||||
|
@ -166,16 +166,16 @@ describe(filename, () => {
|
|||
|
||||
it('adds the contents of payload.extended.es.filter to a filter clause of the bool', () => {
|
||||
config.kibana = true;
|
||||
let request = fn(config, tlConfig);
|
||||
let filter = request.body.query.bool.filter.bool;
|
||||
const request = fn(config, tlConfig);
|
||||
const filter = request.body.query.bool.filter.bool;
|
||||
expect(filter.must.length).to.eql(1);
|
||||
expect(filter.must_not.length).to.eql(2);
|
||||
});
|
||||
|
||||
it('does not include filters if config.kibana = false', () => {
|
||||
config.kibana = false;
|
||||
let request = fn(config, tlConfig);
|
||||
let filter = request.body.query.bool.filter;
|
||||
const request = fn(config, tlConfig);
|
||||
const filter = request.body.query.bool.filter;
|
||||
expect(request.body.query.bool.filter).to.eql(undefined);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
|
||||
var expect = require('chai').expect;
|
||||
var seriesList = require('./fixtures/seriesList.js')();
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
const expect = require('chai').expect;
|
||||
const seriesList = require('./fixtures/seriesList.js')();
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
|
||||
describe(filename, function () {
|
||||
it('should return exactly the data input', function () {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var filename = require('path').basename(__filename);
|
||||
var fn = require(`../${filename}`);
|
||||
var moment = require('moment');
|
||||
var expect = require('chai').expect;
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
var getSeriesList = require('./helpers/get_single_series_list');
|
||||
var _ = require('lodash');
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = require(`../${filename}`);
|
||||
const moment = require('moment');
|
||||
const expect = require('chai').expect;
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
const getSeriesList = require('./helpers/get_single_series_list');
|
||||
const _ = require('lodash');
|
||||
|
||||
describe(filename, function () {
|
||||
|
||||
describe('carry', function () {
|
||||
it('should maintain the previous value until it changes', function () {
|
||||
var seriesList = getSeriesList('',[
|
||||
const seriesList = getSeriesList('',[
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 5],
|
||||
[moment.utc('1981-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), 3.4],
|
||||
|
@ -27,7 +27,7 @@ describe(filename, function () {
|
|||
|
||||
describe('nearest', function () {
|
||||
it('should use the closest temporal value to fill the null', function () {
|
||||
var seriesList = getSeriesList('',[
|
||||
const seriesList = getSeriesList('',[
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 5],
|
||||
[moment.utc('1981-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1981-05-01T00:00:00.000Z'), 3.4],
|
||||
|
@ -46,7 +46,7 @@ describe(filename, function () {
|
|||
|
||||
describe('average', function () {
|
||||
it('should produce a smooth, straight line between points', function () {
|
||||
var seriesList = getSeriesList('',[
|
||||
const seriesList = getSeriesList('',[
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 10],
|
||||
[moment.utc('1981-07-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), null],
|
||||
|
@ -64,7 +64,7 @@ describe(filename, function () {
|
|||
|
||||
describe('scale', function () {
|
||||
it('should distribute the next points value across the preceeding nulls', function () {
|
||||
var seriesList = getSeriesList('', [
|
||||
const seriesList = getSeriesList('', [
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 10],
|
||||
[moment.utc('1981-07-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), null],
|
||||
|
@ -80,7 +80,7 @@ describe(filename, function () {
|
|||
|
||||
describe('none', function () {
|
||||
it('basically just drops the nulls. This is going to screw you', function () {
|
||||
var seriesList = getSeriesList('', [
|
||||
const seriesList = getSeriesList('', [
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 10],
|
||||
[moment.utc('1981-07-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), null],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var moment = require('moment');
|
||||
const moment = require('moment');
|
||||
|
||||
module.exports = [
|
||||
moment('1980-01-01T00:00:00.000Z'),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var Promise = require('bluebird');
|
||||
var buckets = require('./bucketList');
|
||||
var getSeries = require('../helpers/get_series');
|
||||
var getSeriesList = require('../helpers/get_series_list');
|
||||
var _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const buckets = require('./bucketList');
|
||||
const getSeries = require('../helpers/get_series');
|
||||
const getSeriesList = require('../helpers/get_series_list');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function () {
|
||||
return getSeriesList([
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var moment = require('moment');
|
||||
var timelionDefaults = require('../../../lib/get_namespaced_settings');
|
||||
const moment = require('moment');
|
||||
const timelionDefaults = require('../../../lib/get_namespaced_settings');
|
||||
|
||||
module.exports = function () {
|
||||
var tlConfig = require('../../../handlers/lib/tl_config.js')({
|
||||
const tlConfig = require('../../../handlers/lib/tl_config.js')({
|
||||
server: {},
|
||||
request: {}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var proxyquire = require('proxyquire');
|
||||
var Promise = require('bluebird');
|
||||
var _ = require('lodash');
|
||||
var expect = require('chai').expect;
|
||||
const proxyquire = require('proxyquire');
|
||||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
var graphiteResponse = function (url) {
|
||||
const graphiteResponse = function (url) {
|
||||
return Promise.resolve({
|
||||
json: function () {
|
||||
return [{
|
||||
|
@ -19,10 +19,10 @@ var graphiteResponse = function (url) {
|
|||
});
|
||||
};
|
||||
|
||||
var filename = require('path').basename(__filename);
|
||||
var fn = proxyquire(`../${filename}`, {'node-fetch': graphiteResponse});
|
||||
const filename = require('path').basename(__filename);
|
||||
const fn = proxyquire(`../${filename}`, {'node-fetch': graphiteResponse});
|
||||
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
|
||||
describe(filename, function () {
|
||||
it('should wrap the graphite response up in a seriesList', function () {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function getSeries(name, buckets, points) {
|
||||
var fill = _.partial(_.zip, _.map(buckets, function (bucket) { return bucket.valueOf(); }));
|
||||
const fill = _.partial(_.zip, _.map(buckets, function (bucket) { return bucket.valueOf(); }));
|
||||
return {
|
||||
data: fill(points),
|
||||
type: 'series',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (list, overrides) {
|
||||
return _.merge({
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var getSeries = require('../helpers/get_series');
|
||||
var getSeriesList = require('../helpers/get_series_list');
|
||||
var _ = require('lodash');
|
||||
const getSeries = require('../helpers/get_series');
|
||||
const getSeriesList = require('../helpers/get_series_list');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (name, data) {
|
||||
return getSeriesList([getSeries(name, _.map(data, 0), _.map(data, 1))]);
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
// invokes a series_function with the specified arguments
|
||||
var _ = require('lodash');
|
||||
var indexArguments = require('../../../handlers/lib/index_arguments');
|
||||
const _ = require('lodash');
|
||||
const indexArguments = require('../../../handlers/lib/index_arguments');
|
||||
|
||||
module.exports = function invokeSeriesFn(fnDef, args, tlConfigOverrides) {
|
||||
var tlConfig = _.merge(require('../fixtures/tlConfig')(), tlConfigOverrides);
|
||||
const tlConfig = _.merge(require('../fixtures/tlConfig')(), tlConfigOverrides);
|
||||
|
||||
return Promise.all(args).then(function (args) {
|
||||
args.byName = indexArguments(fnDef, args);
|
||||
|
||||
var input = _.cloneDeep(args);
|
||||
const input = _.cloneDeep(args);
|
||||
|
||||
return Promise.resolve(fnDef.originalFn(args, tlConfig)).then(function (output) {
|
||||
|
||||
var result = {
|
||||
const result = {
|
||||
output: output,
|
||||
input: input
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ describe(filename, () => {
|
|||
|
||||
it('computes the moving standard deviation of a list', () => {
|
||||
return invoke(fn, [seriesList, 2]).then((r) => {
|
||||
var values = _.map(r.output.list[1].data, 1);
|
||||
const values = _.map(r.output.list[1].data, 1);
|
||||
expect(values[0]).to.equal(null);
|
||||
expect(values[1]).to.equal(null);
|
||||
expect(values[2]).to.be.within(26, 27);
|
||||
|
|
|
@ -44,7 +44,7 @@ describe(filename, () => {
|
|||
});
|
||||
|
||||
describe('symbol', () => {
|
||||
var symbols = ['triangle', 'cross', 'square', 'diamond', 'circle'];
|
||||
const symbols = ['triangle', 'cross', 'square', 'diamond', 'circle'];
|
||||
_.each(symbols, (symbol) => {
|
||||
it(`is ${symbol}`, () => {
|
||||
return invoke(fn, [seriesList, null, null, null, null, symbol]).then((r) => {
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var proxyquire = require('proxyquire');
|
||||
var Promise = require('bluebird');
|
||||
var _ = require('lodash');
|
||||
const proxyquire = require('proxyquire');
|
||||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const assert = require('chai');
|
||||
const expect = assert.expect;
|
||||
|
||||
var parseURL = require('url').parse;
|
||||
var parseQueryString = require('querystring').parse;
|
||||
var tlConfig = require('./fixtures/tlConfig')();
|
||||
var moment = require('moment');
|
||||
const parseURL = require('url').parse;
|
||||
const parseQueryString = require('querystring').parse;
|
||||
const tlConfig = require('./fixtures/tlConfig')();
|
||||
const moment = require('moment');
|
||||
|
||||
var filename = require('path').basename(__filename);
|
||||
var invoke = require('./helpers/invoke_series_fn.js');
|
||||
const filename = require('path').basename(__filename);
|
||||
const invoke = require('./helpers/invoke_series_fn.js');
|
||||
|
||||
var fn;
|
||||
var response;
|
||||
var calledWith;
|
||||
let fn;
|
||||
let response;
|
||||
let calledWith;
|
||||
describe(filename, function () {
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var _ = require('lodash');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
const alter = require('../lib/alter.js');
|
||||
const _ = require('lodash');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
module.exports = new Chainable('abs', {
|
||||
args: [
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ module.exports = new Chainable('abs', {
|
|||
help: 'Return the absolute value of each value in the series list',
|
||||
fn: function absFn(args) {
|
||||
return alter(args, function (eachSeries) {
|
||||
var data = _.map(eachSeries.data, function (point) {
|
||||
const data = _.map(eachSeries.data, function (point) {
|
||||
return [point[0], Math.abs(point[1])];
|
||||
});
|
||||
eachSeries.data = data;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
const alter = require('../lib/alter.js');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
module.exports = new Chainable('bars', {
|
||||
args: [
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
var tinygradient = require('tinygradient');
|
||||
const alter = require('../lib/alter.js');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
const tinygradient = require('tinygradient');
|
||||
|
||||
module.exports = new Chainable('color', {
|
||||
args: [
|
||||
|
@ -17,13 +17,13 @@ module.exports = new Chainable('color', {
|
|||
],
|
||||
help: 'Change the color of the series',
|
||||
fn: function colorFn(args) {
|
||||
var colors = args.byName.color.split(':');
|
||||
let colors = args.byName.color.split(':');
|
||||
|
||||
if (colors.length > 1 && args.byName.inputSeries.list.length > 1) {
|
||||
colors = tinygradient(colors).rgb(args.byName.inputSeries.list.length);
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
return alter(args, function (eachSeries) {
|
||||
if (colors.length === 1 || args.byName.inputSeries.list.length === 1) {
|
||||
eachSeries.color = colors[0];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var _ = require('lodash');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
var argType = require('../handlers/lib/arg_type.js');
|
||||
const alter = require('../lib/alter.js');
|
||||
const _ = require('lodash');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
const argType = require('../handlers/lib/arg_type.js');
|
||||
|
||||
module.exports = new Chainable('condition', {
|
||||
args: [
|
||||
|
@ -35,9 +35,9 @@ module.exports = new Chainable('condition', {
|
|||
'to the result if the condition proves true, with an optional else.',
|
||||
aliases: ['if'],
|
||||
fn: function conditionFn(args) {
|
||||
var config = args.byName;
|
||||
const config = args.byName;
|
||||
return alter(args, function (eachSeries) {
|
||||
var data = _.map(eachSeries.data, function (point, i) {
|
||||
const data = _.map(eachSeries.data, function (point, i) {
|
||||
function getNumber(source) {
|
||||
if (argType(source) === 'number') return source;
|
||||
if (argType(source) === 'null') return null;
|
||||
|
@ -45,11 +45,11 @@ module.exports = new Chainable('condition', {
|
|||
throw new Error ('must be a number or a seriesList');
|
||||
}
|
||||
|
||||
var ifVal = getNumber(config.if);
|
||||
var thenVal = getNumber(config.then);
|
||||
var elseVal = _.isUndefined(config.else) ? point[1] : getNumber(config.else);
|
||||
const ifVal = getNumber(config.if);
|
||||
const thenVal = getNumber(config.then);
|
||||
const elseVal = _.isUndefined(config.else) ? point[1] : getNumber(config.else);
|
||||
|
||||
var newValue = (function () {
|
||||
const newValue = (function () {
|
||||
switch (config.operator) {
|
||||
case 'lt':
|
||||
return point[1] < ifVal ? thenVal : elseVal;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var _ = require('lodash');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
const alter = require('../lib/alter.js');
|
||||
const _ = require('lodash');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
module.exports = new Chainable('cusum', {
|
||||
args: [
|
||||
{
|
||||
|
@ -16,8 +16,8 @@ module.exports = new Chainable('cusum', {
|
|||
help: 'Return the cumulative sum of a series, starting at a base.',
|
||||
fn: function cusumFn(args) {
|
||||
return alter(args, function (eachSeries, base) {
|
||||
var pairs = eachSeries.data;
|
||||
var total = base || 0;
|
||||
const pairs = eachSeries.data;
|
||||
let total = base || 0;
|
||||
eachSeries.data = _.map(pairs, function (point, i) {
|
||||
total += point[1];
|
||||
return [point[0], total];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var alter = require('../lib/alter.js');
|
||||
var _ = require('lodash');
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
const alter = require('../lib/alter.js');
|
||||
const _ = require('lodash');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
module.exports = new Chainable('derivative', {
|
||||
args: [
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ module.exports = new Chainable('derivative', {
|
|||
help: 'Plot the change in values over time.',
|
||||
fn: function derivativeFn(args) {
|
||||
return alter(args, function (eachSeries) {
|
||||
var pairs = eachSeries.data;
|
||||
const pairs = eachSeries.data;
|
||||
eachSeries.data = _.map(pairs, function (point, i) {
|
||||
if (i === 0 || pairs[i - 1][1] == null || point[1] == null) { return [point[0], null]; }
|
||||
return [point[0], point[1] - pairs[i - 1][1]];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var reduce = require('../lib/reduce.js');
|
||||
const reduce = require('../lib/reduce.js');
|
||||
|
||||
var Chainable = require('../lib/classes/chainable');
|
||||
const Chainable = require('../lib/classes/chainable');
|
||||
module.exports = new Chainable('divide', {
|
||||
args: [
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue