diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index d31fab554b4e0..0000000000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "./src/kibana/bower_components" -} diff --git a/.gitignore b/.gitignore index f9eba398ab940..2c48912fd97e0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,8 @@ .DS_Store .node_binaries node_modules -bower_components -**/*.css trash -build +bundles target .jruby .idea @@ -13,4 +11,4 @@ target *.log esvm .htpasswd -src/server/bin/plugins \ No newline at end of file +installed_plugins diff --git a/.jscsrc b/.jscsrc index 285ada95c3ede..da6d1c8ad24d2 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,9 +1,11 @@ { + "esnext": true, "maximumLineLength": { "value": 140, "allowComments": true }, - "requireCurlyBraces": [ + "requireSemicolons": true, + "requireCurlyBraces": [ "for", "do", "try", diff --git a/.jshintrc b/.jshintrc index 8e5b2febb1b7d..240245abeca92 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,21 @@ { // for files at project root "node": true, + "browser": true, + "mocha": true, + + "predef": { + "inject": true, + "module": true, + "define": true, + "console": false, + "-event": true, + "-name": true, + "-Promise": true, + "-Worker": true, + "-status": true, + "-fetch": true + }, // shared with .jshintrc files for browser and node "unused": false, @@ -23,5 +38,6 @@ "sub": true, "-W084": true, "scripturl": true, - "evil": true + "evil": true, + "esnext": true } diff --git a/.jshintrc.browser b/.jshintrc.browser deleted file mode 100644 index 09cdd36321a20..0000000000000 --- a/.jshintrc.browser +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./.jshintrc", - "node": false, - "browser": true, - - "predef": { - // require.js - "define": true, - "require": true, - "console": false, - "-event": true, - "-name": true - } -} diff --git a/.jshintrc.node b/.jshintrc.node deleted file mode 100644 index a77f81af35ec7..0000000000000 --- a/.jshintrc.node +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./.jshintrc", - "node": true, - - "globals": { - "Promise": true, - "status": true - } -} diff --git a/.node-version b/.node-version index 62ed67b9cef40..eb98ec28972b5 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -0.10.x \ No newline at end of file +iojs-v2.4 diff --git a/.travis.yml b/.travis.yml index b0af355f2743c..1989216632bd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,17 @@ language: node_js -node_js: '0.12' +node_js: 'iojs-v2.4' install: npm install -script: npm test +script: ./node_modules/.bin/grunt travis sudo: false cache: directories: - esvm - node_modules - - src/kibana/bower_components before_cache: - - rm -rf esvm/*/logs esvm/data_dir +- rm -rf esvm/*/logs esvm/data_dir +before_script: +- export DISPLAY=:99.0 +- sh -e /etc/init.d/xvfb start notifications: email: - rashid.khan@elastic.co diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fc69656a2f1b..578d1204bdeb4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,36 +10,35 @@ Please make sure you have signed the [Contributor License Agreement](http://www. ### Development Environment Setup -- Install node.js (we recommend using [nvm](https://github.com/creationix/nvm)) +- Clone the kibana repo and move into it ```sh - ## follow directions at https://github.com/creationix/nvm, then - nvm install 0.10 + git clone https://github.com/elastic/kibana.git kibana + cd kibana ``` -- Install grunt and bower globally (as root if not using nvm) +- Install the version of node.js listed in the `.node-version` file (this is made easy with tools like [nvm](https://github.com/creationix/nvm) and [avn](https://github.com/wbyoung/avn)) ```sh - npm install -g grunt-cli bower + nvm install "$(cat .node-version)" ``` -- Clone the kibana repo and move into it +- Install dependencies ```sh - git clone https://github.com/elastic/kibana.git kibana - cd kibana + npm install ``` -- Install node and bower dependencies +- Start elasticsearch, you can use [esvm](https://github.com/simianhacker/esvm) to make that easier. ```sh - npm install && bower install + grunt esvm:dev:keepalive ``` - Start the development server. ```sh - grunt dev # use the "--with-es" flag to install & start elasticsearch too + ./bin/kibana --dev ``` #### Linting @@ -65,7 +64,7 @@ Before running the tests you will need to install the projects dependencies as d Once that is complete just run: ```sh -grunt test build +./node_modules/.bin/grunt test build ``` Distributable, built packages can be found in `target/` after the build completes. diff --git a/Gruntfile.js b/Gruntfile.js index 6625d6d936e1a..51ef8db0ff751 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,28 +1,34 @@ module.exports = function (grunt) { // set the config once before calling load-grunt-config - // and once durring so that we have access to it via + // and once during so that we have access to it via // grunt.config.get() within the config files var config = { pkg: grunt.file.readJSON('package.json'), root: __dirname, - src: __dirname + '/src', // unbuild version of build - build: __dirname + '/build', // copy of source, but optimized - app: __dirname + '/src/kibana', // source directory for the app - plugins: __dirname + '/src/kibana/plugins', // source directory for the app - server: __dirname + '/src/server', // source directory for the server - target: __dirname + '/target', // location of the compressed build targets - buildApp: __dirname + '/build/kibana', // build directory for the app - configFile: __dirname + '/src/server/config/kibana.yml', + src: __dirname + '/src', + build: __dirname + '/build', // temporary build directory + plugins: __dirname + '/src/plugins', + server: __dirname + '/src/server', + target: __dirname + '/target', // location of the compressed build targets + testUtilsDir: __dirname + '/src/testUtils', + configFile: __dirname + '/src/config/kibana.yml', + + karmaBrowser: (function () { + switch (require('os').platform()) { + case 'win32': + return 'IE'; + case 'darwin': + return 'Chrome'; + default: + return 'Firefox'; + } + }()), nodeVersion: '0.10.35', platforms: ['darwin-x64', 'linux-x64', 'linux-x86', 'windows'], services: [ [ 'launchd', '10.9'], [ 'upstart', '1.5'], [ 'systemd', 'default'], [ 'sysv', 'lsb-3.1' ] ], - unitTestDir: __dirname + '/test/unit', - testUtilsDir: __dirname + '/test/utils', - bowerComponentsDir: __dirname + '/src/kibana/bower_components', - - devPlugins: 'vis_debug_spy', + devPlugins: 'devMode', meta: { banner: '/*! <%= package.name %> - v<%= package.version %> - ' + @@ -34,44 +40,13 @@ module.exports = function (grunt) { lintThese: [ 'Gruntfile.js', '<%= root %>/tasks/**/*.js', - '<%= src %>/kibana/*.js', - '<%= src %>/server/bin/*.js', - '<%= src %>/server/{config,lib,plugins}/**/*.js', - '<%= src %>/server/bin/{plugin,startup}/**/*.js', - '<%= src %>/kibana/{components,directives,factories,filters,plugins,registry,services,utils}/**/*.js', - '<%= unitTestDir %>/**/*.js', - '!<%= unitTestDir %>/specs/vislib/fixture/**/*' - ], - lessFiles: [ - '<%= src %>/kibana/components/*/*.less', - '<%= src %>/kibana/styles/main.less', - '<%= src %>/kibana/components/vislib/styles/main.less', - '<%= src %>/server/plugins/status/public/styles/main.less', - '<%= plugins %>/dashboard/styles/main.less', - '<%= plugins %>/discover/styles/main.less', - '<%= plugins %>/settings/styles/main.less', - '<%= plugins %>/visualize/styles/main.less', - '<%= plugins %>/visualize/styles/visualization.less', - '<%= plugins %>/visualize/styles/main.less', - '<%= plugins %>/table_vis/table_vis.less', - '<%= plugins %>/metric_vis/metric_vis.less', - '<%= plugins %>/markdown_vis/markdown_vis.less' + '<%= src %>/**/*.js', + '!<%= src %>/fixtures/**/*.js' ] }; grunt.config.merge(config); - var dirname = require('path').dirname; - var indexFiles = grunt.file.expand({ cwd: 'src/kibana/plugins' }, [ - '*/index.js', - '!' + config.devPlugins + '/index.js' - ]); - var moduleIds = indexFiles.map(function (fileName) { - return 'plugins/' + dirname(fileName) + '/index'; - }); - - config.bundled_plugin_module_ids = grunt.bundled_plugin_module_ids = moduleIds; - // load plugins require('load-grunt-config')(grunt, { configPath: __dirname + '/tasks/config', diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md index c628c98d953be..a0e991bdf254e 100644 --- a/STYLEGUIDE.md +++ b/STYLEGUIDE.md @@ -812,7 +812,7 @@ Kibana is written in Angular, and uses several utility methods to make using Ang Angular modules are defined using a custom require module named `module`. It is used as follows: ```js -var app = require('modules').get('app/namespace'); +var app = require('ui/modules').get('app/namespace'); ``` `app` above is a reference to an Angular module, and can be used to define controllers, providers and anything else used in Angular. @@ -849,7 +849,7 @@ app.service('CustomService', function(Promise, otherDeps) { Angular routes are defined using a custom require modules named `routes` that remove much of the required boilerplate. ```js -require('routes') +require('ui/routes') .when('/my/object/route/:id?', { // angular route code goes here }); diff --git a/bin/kibana b/bin/kibana new file mode 100755 index 0000000000000..ce366929c3808 --- /dev/null +++ b/bin/kibana @@ -0,0 +1,25 @@ +#!/bin/sh +SCRIPT=$0 + +# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. +while [ -h "$SCRIPT" ] ; do + ls=$(ls -ld "$SCRIPT") + # Drop everything prior to -> + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=$(dirname "$SCRIPT")/"$link" + fi +done + +DIR="$(dirname "${SCRIPT}")/.." +NODE="${DIR}/node/bin/node" +test -x "$NODE" || NODE=$(which node) +if [ ! -x "$NODE" ]; then + echo "unable to find usable node.js executable." + exit 1 +fi + +exec "${NODE}" "${DIR}/src/cli/cli" ${@} + diff --git a/bin/kibana.bat b/bin/kibana.bat new file mode 100644 index 0000000000000..c038248b11bae --- /dev/null +++ b/bin/kibana.bat @@ -0,0 +1,25 @@ +@echo off + +SETLOCAL + +set SCRIPT_DIR=%~dp0 +for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI + +set NODE=%DIR%\node\node.exe +for /f "delims=" %%i in ('WHERE node') do set SYS_NODE=%%i + +If Not Exist "%NODE%" ( + IF Exist "%SYS_NODE%" ( + set NODE=%SYS_NODE% + ) else ( + Echo unable to find usable node.js executable. + Exit /B 1 + ) +) + +TITLE Kibana Server +"%NODE%" "%DIR%\src\cli\cli" %* + +:finally + +ENDLOCAL \ No newline at end of file diff --git a/bower.json b/bower.json deleted file mode 100644 index 7355190249dae..0000000000000 --- a/bower.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "kibana", - "authors": [ - "Spencer Alger " - ], - "description": "Browser based analytics and search interface to Logstash and other timestamped data sets stored in ElasticSearch", - "main": "src/index.html", - "keywords": [ - "kibana", - "elasticsearch" - ], - "license": "Apache 2.0", - "homepage": "http://www.elastic.co/products/kibana", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "dependencies": { - "angular": "1.2.28", - "angular-bindonce": "0.3.3", - "angular-bootstrap": "0.10.0", - "angular-elastic": "2.4.2", - "angular-mocks": "1.2.28", - "angular-nvd3": "https://github.com/krispo/angular-nvd3.git#1.0.0-beta", - "angular-route": "1.2.28", - "angular-ui-ace": "0.2.3", - "bluebird": "~2.9.27", - "bootstrap": "3.3.4", - "d3": "3.5.5", - "elasticsearch": "~5.0.0", - "Faker": "1.1.0", - "FileSaver": "babc6d9d8f", - "font-awesome": "4.3.0", - "gridster": "0.5.6", - "jquery": "2.1.4", - "leaflet": "0.7.3", - "Leaflet.heat": "Leaflet/Leaflet.heat#627ede7c11bbe43", - "lesshat": "3.0.2", - "lodash": "3.9.3", - "moment": "2.10.3", - "moment-timezone": "0.4.0", - "ng-clip": "0.2.6", - "require-css": "0.1.8", - "requirejs": "2.1.18", - "requirejs-text": "2.0.14", - "marked": "0.3.3", - "numeral": "1.5.3", - "nvd3": "1.7.1", - "leaflet-draw": "0.2.4" - }, - "devDependencies": {}, - "resolutions": { - "angular": "1.2.28", - "d3": "3.5.5" - } -} diff --git a/config/kibana.yml b/config/kibana.yml new file mode 100644 index 0000000000000..0b39cefc79e19 --- /dev/null +++ b/config/kibana.yml @@ -0,0 +1,63 @@ +# Kibana is served by a back end server. This controls which port to use. +# server.port: 5601 + +# The host to bind the server to. +# server.host: "0.0.0.0" + +# The Elasticsearch instance to use for all your queries. +# elasticsearch.url: "http://localhost:9200" + +# preserve_elasticsearch_host true will send the hostname specified in `elasticsearch`. If you set it to false, +# then the host you use to connect to *this* Kibana instance will be sent. +# elasticsearch.preserveHost: true + +# Kibana uses an index in Elasticsearch to store saved searches, visualizations +# and dashboards. It will create a new index if it doesn't already exist. +# kibana.index: ".kibana" + +# The default application to load. +# kibana.defaultAppId: "discover" + +# If your Elasticsearch is protected with basic auth, this is the user credentials +# used by the Kibana server to perform maintence on the kibana_index at statup. Your Kibana +# users will still need to authenticate with Elasticsearch (which is proxied thorugh +# the Kibana server) +# elasticsearch.username: user +# elasticsearch.password: pass + +# If your Elasticsearch requires client certificate and key +# elasticsearch.ssl.cert: /path/to/your/client.crt +# elasticsearch.ssl.key: /path/to/your/client.key + +# If you need to provide a CA certificate for your Elasticsearch instance, put +# the path of the pem file here. +# elasticsearch.ssl.ca: /path/to/your/CA.pem + +# Set to false to have a complete disregard for the validity of the SSL +# certificate. +# elasticsearch.ssl.verify: true + +# Time in milliseconds to wait for elasticsearch to respond to pings, defaults to +# request_timeout setting +# elasticsearch.pingTimeout: 1500 + +# Time in milliseconds to wait for responses from the back end or elasticsearch. +# This must be > 0 +# elasticsearch.requestTimeout: 300000 + +# Time in milliseconds for Elasticsearch to wait for responses from shards. +# Set to 0 to disable. +# elasticsearch.shardTimeout: 0 + +# Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying +# elasticsearch.startupTimeout: 5000 + +# SSL for outgoing requests from the Kibana Server (PEM formatted) +# server.ssl.cert: /path/to/your/server.key +# server.ssl.key: /path/to/your/server.crt + +# Set the path to where you would like the process id file to be created. +# pid.file: /var/run/kibana.pid + +# If you would like to send the log output to a file you can set the path below. +# logging.dest: stdout diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000000..8047db42cd637 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,62 @@ +// Karma configuration +// Generated on Mon Jul 27 2015 04:03:51 GMT-0700 (MST) + +module.exports = function (config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + captureTimeout: 30000, + browserNoActivityTimeout: 120000, + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha'], + + // list of files / patterns to load in the browser + files: [ + 'http://localhost:5601/bundles/tests.bundle.js', + 'http://localhost:5601/bundles/tests.bundle.style.css' + ], + + proxies: { + '/tests/': 'http://localhost:5601/tests/', + '/bundles/': 'http://localhost:5601/bundles/' + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress', 'growl'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [ + require('os').platform() === 'win32' ? 'IE' : 'Chrome' + ], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }); +}; diff --git a/package.json b/package.json index efe4bbc5139a6..439ddd5e2acf7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,10 @@ ], "private": false, "version": "4.2.0-snapshot", - "main": "src/server/index.js", + "build": { + "num": 8095 + }, + "main": "src/server/KbnServer.js", "homepage": "https://www.elastic.co/products/kibana", "bugs": { "url": "http://github.com/elastic/kibana/issues" @@ -30,7 +33,7 @@ ], "scripts": { "test": "grunt test", - "start": "node ./src/server/bin/kibana.js", + "start": "node ./src/server/cli/index.js --dev", "precommit": "grunt lintStagedFiles" }, "repository": { @@ -38,84 +41,117 @@ "url": "https://github.com/elastic/kibana.git" }, "dependencies": { + "@spalger/angular-bootstrap": "^0.10.0", + "@spalger/filesaver": "^1.1.2", + "@spalger/leaflet-draw": "^0.2.3", + "@spalger/leaflet-heat": "^0.1.3", + "@spalger/ui-ace": "^0.2.3", + "Nonsense": "^0.1.2", + "angular": "1.2.28", + "angular-bindonce": "0.3.1", + "angular-elastic": "2.5.0", + "angular-mocks": "1.2.28", + "angular-nvd3": "panda01/angular-nvd3#kibana", + "angular-route": "1.2.28", "ansicolors": "^0.3.2", + "auto-preload-rjscommon-deps-loader": "^1.0.3", + "autoprefixer": "^5.2.0", + "autoprefixer-loader": "^2.0.0", "bluebird": "^2.9.27", - "body-parser": "^1.10.1", + "boom": "^2.8.0", + "bootstrap": "^3.3.5", + "brace": "^0.5.1", "bunyan": "^1.2.3", - "commander": "^2.6.0", - "compression": "^1.3.0", - "cookie-parser": "^1.3.3", - "debug": "^2.1.1", + "chokidar": "^1.0.4", + "commander": "^2.8.1", + "css-loader": "^0.15.1", + "d3": "^3.5.6", "elasticsearch": "^5.0.0", + "elasticsearch-browser": "^5.0.0", "expiry-js": "^0.1.7", - "express": "^4.10.6", + "exports-loader": "^0.6.2", + "expose-loader": "^0.7.0", + "extract-text-webpack-plugin": "^0.8.2", + "file-loader": "^0.8.4", + "font-awesome": "^4.3.0", "glob": "^4.3.2", - "good": "^5.1.2", - "good-console": "^4.1.0", - "good-file": "^4.0.2", - "good-reporter": "^3.1.0", + "good": "^6.2.0", + "good-squeeze": "^2.1.0", + "gridster": "^0.5.6", "hapi": "^8.6.1", + "imports-loader": "^0.6.4", + "is-array": "^1.0.1", + "jade": "^1.7.2", + "jade-loader": "^0.7.1", "joi": "^6.4.3", + "jquery": "^2.1.4", "js-yaml": "^3.2.5", "json-stringify-safe": "^5.0.1", - "lodash": "^3.9.3", + "leaflet": "^0.7.3", + "less": "^2.5.1", + "less-loader": "^2.2.0", + "lodash": "^3.10.0", + "marked": "^0.3.3", + "memory-fs": "^0.2.0", + "minimatch": "^2.0.8", + "mkdirp": "^0.5.1", "moment": "^2.10.3", + "moment-timezone": "^0.4.0", + "ng-clip": "^0.2.6", "numeral": "^1.5.3", + "nvd3": "panda01/nvd3#kibana", + "raw-loader": "^0.5.1", "request": "^2.40.0", "requirefrom": "^0.2.0", - "rimraf": "^2.4.0", + "rimraf": "^2.4.1", + "script-loader": "^0.6.1", "semver": "^4.3.6", - "serve-favicon": "^2.2.0", - "through": "^2.3.6" + "style-loader": "^0.12.3", + "tar": "^2.1.1", + "url-loader": "^0.5.6", + "webpack": "^1.10.0", + "webpack-directory-name-as-main": "^1.0.0", + "zeroclipboard": "^2.2.0" }, "devDependencies": { - "bower": "^1.4.1", - "bower-license": "^0.2.6", - "event-stream": "^3.1.5", + "auto-release-sinon": "^1.0.3", "expect.js": "^0.3.1", + "faker": "^1.1.0", "grunt": "^0.4.5", "grunt-cli": "0.1.13", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-compress": "^0.13.0", "grunt-contrib-copy": "^0.8.0", - "grunt-contrib-jade": "^0.14.0", "grunt-contrib-jshint": "^0.11", - "grunt-contrib-less": "^1.0.1", - "grunt-contrib-requirejs": "^0.4.4", - "grunt-contrib-watch": "^0.6.1", "grunt-esvm": "^1.0.1", "grunt-jscs": "^1.8.0", - "grunt-mocha": "^0.4.10", + "grunt-karma": "^0.12.0", "grunt-replace": "^0.7.9", - "grunt-run": "^0.3.0", + "grunt-run": "spalger/grunt-run#master", "grunt-s3": "^0.2.0-alpha.3", "grunt-simple-mocha": "^0.4.0", "html-entities": "^1.1.1", - "http-proxy": "^1.8.1", "husky": "^0.8.1", - "istanbul": "^0.3.15", - "jade": "^1.8.2", + "karma": "^0.13.3", + "karma-chrome-launcher": "^0.2.0", + "karma-firefox-launcher": "^0.1.6", + "karma-growl-reporter": "^0.1.1", + "karma-ie-launcher": "^0.2.0", + "karma-mocha": "^0.2.0", "libesvm": "^1.0.1", "license-checker": "^3.1.0", "load-grunt-config": "^0.7.0", - "marked": "^0.3.3", "marked-text-renderer": "^0.1.0", - "mkdirp": "^0.5.0", "mocha": "^2.2.5", - "nock": "^2.7.0", + "nock": "^2.9.0", "npm": "^2.11.0", - "opn": "^1.0.0", - "path-browserify": "0.0.0", "portscanner": "^1.0.0", - "progress": "^1.1.8", - "requirejs": "^2.1.14", - "rjs-build-analysis": "0.0.3", "simple-git": "^1.3.0", - "sinon": "^1.12.2", - "tar": "^2.1.1" + "sinon": "^1.15.4", + "source-map": "^0.4.4", + "whatwg-fetch": "^0.9.0" }, "engines": { - "node": "~0.10 || ~0.12", - "iojs": ">=1.5" + "node": ">=2" } } diff --git a/src/cli/Command.js b/src/cli/Command.js new file mode 100644 index 0000000000000..427725946dab9 --- /dev/null +++ b/src/cli/Command.js @@ -0,0 +1,85 @@ +'use strict'; + +let _ = require('lodash'); +let Command = require('commander').Command; + +let red = require('./color').red; +let yellow = require('./color').yellow; +let help = require('./help'); + +Command.prototype.error = function (err) { + if (err && err.message) err = err.message; + + console.log( +` +${red(' ERROR ')} ${err} + +${help(this, ' ')} +` + ); + + process.exit(64); +}; + +Command.prototype.defaultHelp = function () { + console.log( +` +${help(this, ' ')} + +` + ); + + process.exit(64); +}; + +Command.prototype.unknownArgv = function (argv) { + if (argv) this.__unkownArgv = argv; + return this.__unkownArgv ? this.__unkownArgv.slice(0) : []; +}; + +/** + * setup the command to accept arbitrary configuration via the cli + * @return {[type]} [description] + */ +Command.prototype.collectUnknownOptions = function () { + let title = `Extra ${this._name} options`; + + this.allowUnknownOption(); + this.getUnknownOptions = function () { + let opts = {}; + let unknowns = this.unknownArgv(); + + while (unknowns.length) { + let opt = unknowns.shift().split('='); + if (opt[0].slice(0, 2) !== '--') { + this.error(`${title} "${opt[0]}" must start with "--"`); + } + + if (opt.length === 1) { + if (!unknowns.length || unknowns[0][0] === '-') { + this.error(`${title} "${opt[0]}" must have a value`); + } + + opt.push(unknowns.shift()); + } + + let val = opt[1]; + try { val = JSON.parse(opt[1]); } + catch (e) { val = opt[1]; } + + _.set(opts, opt[0].slice(2), val); + } + + return opts; + }; + + return this; +}; + +Command.prototype.parseOptions = _.wrap(Command.prototype.parseOptions, function (parse, argv) { + let opts = parse.call(this, argv); + this.unknownArgv(opts.unknown); + return opts; +}); + +module.exports = Command; diff --git a/src/cli/Log.js b/src/cli/Log.js new file mode 100644 index 0000000000000..1800093c4062c --- /dev/null +++ b/src/cli/Log.js @@ -0,0 +1,18 @@ +'use strict'; + +let _ = require('lodash'); +let ansicolors = require('ansicolors'); + +let log = _.restParam(function (color, label, rest1) { + console.log.apply(console, [color(` ${_.trim(label)} `)].concat(rest1)); +}); + +let color = require('./color'); + +module.exports = class Log { + constructor(quiet, silent) { + this.good = quiet || silent ? _.noop : _.partial(log, color.green); + this.warn = quiet || silent ? _.noop : _.partial(log, color.yellow); + this.bad = silent ? _.noop : _.partial(log, color.red); + } +}; diff --git a/src/cli/cli.js b/src/cli/cli.js new file mode 100644 index 0000000000000..97b2b4f795c22 --- /dev/null +++ b/src/cli/cli.js @@ -0,0 +1,49 @@ +'use strict'; + +let _ = require('lodash'); + +let utils = require('requirefrom')('src/utils'); +let pkg = utils('packageJson'); +let Command = require('./Command'); + +let argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice(); +let program = new Command('bin/kibana'); + +program +.version(pkg.version) +.description( + 'Kibana is an open source (Apache Licensed), browser ' + + 'based analytics and search dashboard for Elasticsearch.' +); + +// attach commands +require('./serve/serve')(program); +require('./plugin/plugin')(program); + +program +.command('help ') +.description('Get the help for a specific command') +.action(function (cmdName) { + var cmd = _.find(program.commands, { _name: cmdName }); + if (!cmd) return this.error(`unknown command ${cmd}`); + cmd.help(); +}); + +program +.command('*', null, { noHelp: true }) +.action(function (cmd, options) { + program.error(`unknown command ${cmd}`); +}); + +// check for no command name +var subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//); + +if (!subCommand) { + if (_.intersection(argv.slice(2), ['-h', '--help']).length) { + program.defaultHelp(); + } else { + argv.splice(2, 0, ['serve']); + } +} + +program.parse(argv); diff --git a/src/cli/color.js b/src/cli/color.js new file mode 100644 index 0000000000000..ae53be757154e --- /dev/null +++ b/src/cli/color.js @@ -0,0 +1,7 @@ + +var _ = require('lodash'); +var ansicolors = require('ansicolors'); + +exports.green = _.flow(ansicolors.black, ansicolors.bgGreen); +exports.red = _.flow(ansicolors.white, ansicolors.bgRed); +exports.yellow = _.flow(ansicolors.black, ansicolors.bgYellow); diff --git a/src/cli/help.js b/src/cli/help.js new file mode 100644 index 0000000000000..39e775a0d0f2a --- /dev/null +++ b/src/cli/help.js @@ -0,0 +1,76 @@ +'use strict'; + +var _ = require('lodash'); + +module.exports = function (command, spaces) { + if (!_.size(command.commands)) { + return command.outputHelp(); + } + + let defCmd = _.find(command.commands, function (cmd) { + return cmd._name === 'serve'; + }); + + let desc = !command.description() ? '' : command.description(); + let cmdDef = !defCmd ? '' : `=${defCmd._name}`; + + return ( +` +Usage: ${command._name} [command${cmdDef}] [options] + +${desc} + +Commands: +${indent(commandsSummary(command), 2)} + +${cmdHelp(defCmd)} +` + ).trim().replace(/^/gm, spaces || ''); +}; + +function indent(str, n) { + return String(str || '').trim().replace(/^/gm, _.repeat(' ', n)); +} + +function commandsSummary(program) { + let cmds = _.compact(program.commands.map(function (cmd) { + let name = cmd._name; + if (name === '*') return; + let opts = cmd.options.length ? ' [options]' : ''; + let args = cmd._args.map(function (arg) { + return humanReadableArgName(arg); + }).join(' '); + + return [ + `${name} ${opts} ${args}`, + cmd.description() + ]; + })); + + let cmdLColWidth = cmds.reduce(function (width, cmd) { + return Math.max(width, cmd[0].length); + }, 0); + + return cmds.reduce(function (help, cmd) { + return `${help || ''}${_.padRight(cmd[0], cmdLColWidth)} ${cmd[1] || ''}\n`; + }, ''); +} + +function cmdHelp(cmd) { + if (!cmd) return ''; + return ( + +` +"${cmd._name}" Options: + +${indent(cmd.optionHelp(), 2)} +` + + ).trim(); + +} + +function humanReadableArgName(arg) { + var nameOutput = arg.name + (arg.variadic === true ? '...' : ''); + return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']'; +} diff --git a/test/unit/server/bin/plugin/npmInstall.js b/src/cli/plugin/__tests__/npmInstall.js similarity index 91% rename from test/unit/server/bin/plugin/npmInstall.js rename to src/cli/plugin/__tests__/npmInstall.js index 60c6593766a13..1994f3d568e7b 100644 --- a/test/unit/server/bin/plugin/npmInstall.js +++ b/src/cli/plugin/__tests__/npmInstall.js @@ -1,4 +1,3 @@ -var root = require('requirefrom')(''); var expect = require('expect.js'); var nock = require('nock'); var glob = require('glob'); @@ -6,8 +5,9 @@ var rimraf = require('rimraf'); var fs = require('fs'); var join = require('path').join; var sinon = require('sinon'); -var pluginLogger = root('src/server/bin/plugin/pluginLogger'); -var npmInstall = root('src/server/bin/plugin/npmInstall'); + +var pluginLogger = require('../pluginLogger'); +var npmInstall = require('../npmInstall'); describe('kibana cli', function () { @@ -66,4 +66,4 @@ describe('kibana cli', function () { }); -}); \ No newline at end of file +}); diff --git a/src/cli/plugin/__tests__/plugin.js b/src/cli/plugin/__tests__/plugin.js new file mode 100644 index 0000000000000..1a53ce3b61158 --- /dev/null +++ b/src/cli/plugin/__tests__/plugin.js @@ -0,0 +1,80 @@ +var expect = require('expect.js'); +var sinon = require('sinon'); + +var plugin = require('../plugin'); +var installer = require('../pluginInstaller'); +var remover = require('../pluginRemover'); +var settingParser = require('../settingParser'); + +describe('kibana cli', function () { + + describe('plugin installer', function () { + + describe('commander options', function () { + + var program = { + command: function () { return program; }, + description: function () { return program; }, + option: function () { return program; }, + action: function () { return program; } + }; + + it('should define the command', function () { + sinon.spy(program, 'command'); + + plugin(program); + expect(program.command.calledWith('plugin')).to.be(true); + + program.command.restore(); + }); + + it('should define the description', function () { + sinon.spy(program, 'description'); + + plugin(program); + expect(program.description.calledWith('Maintain Plugins')).to.be(true); + + program.description.restore(); + }); + + it('should define the command line options', function () { + var spy = sinon.spy(program, 'option'); + + var options = [ + /-i/, + /-r/, + /-s/, + /-u/, + /-t/ + ]; + + plugin(program); + + for (var i = 0; i < spy.callCount; i++) { + var call = spy.getCall(i); + for (var o = 0; o < options.length; o++) { + var option = options[o]; + if (call.args[0].match(option)) { + options.splice(o, 1); + break; + } + } + } + + expect(options).to.have.length(0); + }); + + it('should call the action function', function () { + sinon.spy(program, 'action'); + + plugin(program); + expect(program.action.calledOnce).to.be(true); + + program.action.restore(); + }); + + }); + + }); + +}); diff --git a/test/unit/server/bin/plugin/pluginCleaner.js b/src/cli/plugin/__tests__/pluginCleaner.js similarity index 95% rename from test/unit/server/bin/plugin/pluginCleaner.js rename to src/cli/plugin/__tests__/pluginCleaner.js index 933c32b683ba8..2cf0f7d610e75 100644 --- a/test/unit/server/bin/plugin/pluginCleaner.js +++ b/src/cli/plugin/__tests__/pluginCleaner.js @@ -1,10 +1,10 @@ -var root = require('requirefrom')(''); var expect = require('expect.js'); var sinon = require('sinon'); var fs = require('fs'); var rimraf = require('rimraf'); -var pluginCleaner = root('src/server/bin/plugin/pluginCleaner'); -var pluginLogger = root('src/server/bin/plugin/pluginLogger'); + +var pluginCleaner = require('../pluginCleaner'); +var pluginLogger = require('../pluginLogger'); describe('kibana cli', function () { @@ -144,4 +144,4 @@ describe('kibana cli', function () { }); -}); \ No newline at end of file +}); diff --git a/src/cli/plugin/__tests__/pluginDownloader.js b/src/cli/plugin/__tests__/pluginDownloader.js new file mode 100644 index 0000000000000..e1c56ea333c63 --- /dev/null +++ b/src/cli/plugin/__tests__/pluginDownloader.js @@ -0,0 +1,249 @@ +var expect = require('expect.js'); +var sinon = require('sinon'); +var nock = require('nock'); +var glob = require('glob'); +var rimraf = require('rimraf'); +var join = require('path').join; + +var pluginLogger = require('../pluginLogger'); +var pluginDownloader = require('../pluginDownloader'); + +describe('kibana cli', function () { + + describe('plugin downloader', function () { + + var testWorkingPath = join(__dirname, '.test.data'); + var logger; + var downloader; + + beforeEach(function () { + logger = pluginLogger(false); + sinon.stub(logger, 'log'); + sinon.stub(logger, 'error'); + rimraf.sync(testWorkingPath); + }); + + afterEach(function () { + logger.log.restore(); + logger.error.restore(); + rimraf.sync(testWorkingPath); + }); + + describe('_downloadSingle', function () { + + beforeEach(function () { + downloader = pluginDownloader({}, logger); + }); + + afterEach(function () { + }); + + it.skip('should throw an ENOTFOUND error for a 404 error', function () { + var couchdb = nock('http://www.files.com') + .get('/plugin.tar.gz') + .reply(404); + + var source = 'http://www.files.com/plugin.tar.gz'; + + var errorStub = sinon.stub(); + return downloader._downloadSingle(source, testWorkingPath, 0, logger) + .catch(errorStub) + .then(function (data) { + expect(errorStub.called).to.be(true); + expect(errorStub.lastCall.args[0].message).to.match(/ENOTFOUND/); + + var files = glob.sync('**/*', { cwd: testWorkingPath }); + expect(files).to.eql([]); + }); + }); + + it.skip('should download and extract a valid plugin', function () { + var filename = join(__dirname, 'replies/test-plugin-master.tar.gz'); + var couchdb = nock('http://www.files.com') + .defaultReplyHeaders({ + 'content-length': '10' + }) + .get('/plugin.tar.gz') + .replyWithFile(200, filename); + + var source = 'http://www.files.com/plugin.tar.gz'; + + return downloader._downloadSingle(source, testWorkingPath, 0, logger) + .then(function (data) { + var files = glob.sync('**/*', { cwd: testWorkingPath }); + var expected = [ + 'README.md', + 'index.js', + 'package.json', + 'public', + 'public/app.js' + ]; + expect(files.sort()).to.eql(expected.sort()); + }); + }); + + it('should abort the download and extraction for a corrupt archive.', function () { + var filename = join(__dirname, 'replies/corrupt.tar.gz'); + var couchdb = nock('http://www.files.com') + .get('/plugin.tar.gz') + .replyWithFile(200, filename); + + var source = 'http://www.files.com/plugin.tar.gz'; + + var errorStub = sinon.stub(); + return downloader._downloadSingle(source, testWorkingPath, 0, logger) + .catch(errorStub) + .then(function (data) { + expect(errorStub.called).to.be(true); + + var files = glob.sync('**/*', { cwd: testWorkingPath }); + expect(files).to.eql([]); + }); + }); + + }); + + describe('download', function () { + + beforeEach(function () {}); + + afterEach(function () {}); + + it.skip('should loop through bad urls until it finds a good one.', function () { + var filename = join(__dirname, 'replies/test-plugin-master.tar.gz'); + var settings = { + urls: [ + 'http://www.files.com/badfile1.tar.gz', + 'http://www.files.com/badfile2.tar.gz', + 'I am a bad uri', + 'http://www.files.com/goodfile.tar.gz' + ], + workingPath: testWorkingPath, + timeout: 0 + }; + downloader = pluginDownloader(settings, logger); + + var couchdb = nock('http://www.files.com') + .defaultReplyHeaders({ + 'content-length': '10' + }) + .get('/badfile1.tar.gz') + .reply(404) + .get('/badfile2.tar.gz') + .reply(404) + .get('/goodfile.tar.gz') + .replyWithFile(200, filename); + + var errorStub = sinon.stub(); + return downloader.download(settings, logger) + .catch(errorStub) + .then(function (data) { + expect(errorStub.called).to.be(false); + + expect(logger.log.getCall(0).args[0]).to.match(/badfile1.tar.gz/); + expect(logger.log.getCall(1).args[0]).to.match(/badfile2.tar.gz/); + expect(logger.log.getCall(2).args[0]).to.match(/I am a bad uri/); + expect(logger.log.getCall(3).args[0]).to.match(/goodfile.tar.gz/); + expect(logger.log.lastCall.args[0]).to.match(/complete/i); + + var files = glob.sync('**/*', { cwd: testWorkingPath }); + var expected = [ + 'README.md', + 'index.js', + 'package.json', + 'public', + 'public/app.js' + ]; + expect(files.sort()).to.eql(expected.sort()); + }); + }); + + it.skip('should stop looping through urls when it finds a good one.', function () { + var filename = join(__dirname, 'replies/test-plugin-master.tar.gz'); + var settings = { + urls: [ + 'http://www.files.com/badfile1.tar.gz', + 'http://www.files.com/badfile2.tar.gz', + 'http://www.files.com/goodfile.tar.gz', + 'http://www.files.com/badfile3.tar.gz' + ], + workingPath: testWorkingPath, + timeout: 0 + }; + downloader = pluginDownloader(settings, logger); + + var couchdb = nock('http://www.files.com') + .defaultReplyHeaders({ + 'content-length': '10' + }) + .get('/badfile1.tar.gz') + .reply(404) + .get('/badfile2.tar.gz') + .reply(404) + .get('/goodfile.tar.gz') + .replyWithFile(200, filename) + .get('/badfile3.tar.gz') + .reply(404); + + var errorStub = sinon.stub(); + return downloader.download(settings, logger) + .catch(errorStub) + .then(function (data) { + expect(errorStub.called).to.be(false); + + for (var i = 0; i < logger.log.callCount; i++) { + expect(logger.log.getCall(i).args[0]).to.not.match(/badfile3.tar.gz/); + } + + var files = glob.sync('**/*', { cwd: testWorkingPath }); + var expected = [ + 'README.md', + 'index.js', + 'package.json', + 'public', + 'public/app.js' + ]; + expect(files.sort()).to.eql(expected.sort()); + }); + }); + + it.skip('should throw an error when it doesn\'t find a good url.', function () { + var settings = { + urls: [ + 'http://www.files.com/badfile1.tar.gz', + 'http://www.files.com/badfile2.tar.gz', + 'http://www.files.com/badfile3.tar.gz' + ], + workingPath: testWorkingPath, + timeout: 0 + }; + downloader = pluginDownloader(settings, logger); + + var couchdb = nock('http://www.files.com') + .defaultReplyHeaders({ + 'content-length': '10' + }) + .get('/badfile1.tar.gz') + .reply(404) + .get('/badfile2.tar.gz') + .reply(404) + .get('/badfile3.tar.gz') + .reply(404); + + var errorStub = sinon.stub(); + return downloader.download(settings, logger) + .catch(errorStub) + .then(function (data) { + expect(errorStub.called).to.be(true); + expect(errorStub.lastCall.args[0].message).to.match(/not a valid/i); + + var files = glob.sync('**/*', { cwd: testWorkingPath }); + expect(files).to.eql([]); + }); + }); + + }); + + }); + +}); diff --git a/test/unit/server/bin/plugin/pluginInstaller.js b/src/cli/plugin/__tests__/pluginInstaller.js similarity index 91% rename from test/unit/server/bin/plugin/pluginInstaller.js rename to src/cli/plugin/__tests__/pluginInstaller.js index 05e6b62b54874..f8a3de3c04939 100644 --- a/test/unit/server/bin/plugin/pluginInstaller.js +++ b/src/cli/plugin/__tests__/pluginInstaller.js @@ -1,4 +1,3 @@ -var root = require('requirefrom')(''); var expect = require('expect.js'); var sinon = require('sinon'); var nock = require('nock'); @@ -6,10 +5,11 @@ var glob = require('glob'); var rimraf = require('rimraf'); var fs = require('fs'); var join = require('path').join; -var pluginLogger = root('src/server/bin/plugin/pluginLogger'); -var pluginInstaller = root('src/server/bin/plugin/pluginInstaller'); var Promise = require('bluebird'); +var pluginLogger = require('../pluginLogger'); +var pluginInstaller = require('../pluginInstaller'); + describe('kibana cli', function () { describe('plugin installer', function () { @@ -71,4 +71,4 @@ describe('kibana cli', function () { }); -}); \ No newline at end of file +}); diff --git a/test/unit/server/bin/plugin/pluginLogger.js b/src/cli/plugin/__tests__/pluginLogger.js similarity index 97% rename from test/unit/server/bin/plugin/pluginLogger.js rename to src/cli/plugin/__tests__/pluginLogger.js index c19885d2f296c..9390c46089c04 100644 --- a/test/unit/server/bin/plugin/pluginLogger.js +++ b/src/cli/plugin/__tests__/pluginLogger.js @@ -1,8 +1,8 @@ -var root = require('requirefrom')(''); -var pluginLogger = root('src/server/bin/plugin/pluginLogger'); var expect = require('expect.js'); var sinon = require('sinon'); +var pluginLogger = require('../pluginLogger'); + describe('kibana cli', function () { describe('plugin installer', function () { @@ -125,4 +125,4 @@ describe('kibana cli', function () { }); -}); \ No newline at end of file +}); diff --git a/test/unit/server/bin/plugin/progressReporter.js b/src/cli/plugin/__tests__/progressReporter.js similarity index 98% rename from test/unit/server/bin/plugin/progressReporter.js rename to src/cli/plugin/__tests__/progressReporter.js index 68d5d64d82274..d943a45ffc12c 100644 --- a/test/unit/server/bin/plugin/progressReporter.js +++ b/src/cli/plugin/__tests__/progressReporter.js @@ -1,8 +1,7 @@ -var root = require('requirefrom')(''); var expect = require('expect.js'); var sinon = require('sinon'); -var progressReporter = root('src/server/bin/plugin/progressReporter'); -var pluginLogger = root('src/server/bin/plugin/pluginLogger'); +var progressReporter = require('../progressReporter'); +var pluginLogger = require('../pluginLogger'); describe('kibana cli', function () { @@ -299,4 +298,4 @@ describe('kibana cli', function () { }); -}); \ No newline at end of file +}); diff --git a/test/unit/server/bin/plugin/replies/corrupt.tar.gz b/src/cli/plugin/__tests__/replies/corrupt.tar.gz similarity index 100% rename from test/unit/server/bin/plugin/replies/corrupt.tar.gz rename to src/cli/plugin/__tests__/replies/corrupt.tar.gz diff --git a/test/unit/server/bin/plugin/replies/package.json b/src/cli/plugin/__tests__/replies/package.json similarity index 100% rename from test/unit/server/bin/plugin/replies/package.json rename to src/cli/plugin/__tests__/replies/package.json diff --git a/test/unit/server/bin/plugin/replies/plugin-no-package.gz b/src/cli/plugin/__tests__/replies/plugin-no-package.gz similarity index 100% rename from test/unit/server/bin/plugin/replies/plugin-no-package.gz rename to src/cli/plugin/__tests__/replies/plugin-no-package.gz diff --git a/test/unit/server/bin/plugin/replies/test-plugin-master.tar.gz b/src/cli/plugin/__tests__/replies/test-plugin-master.tar.gz similarity index 100% rename from test/unit/server/bin/plugin/replies/test-plugin-master.tar.gz rename to src/cli/plugin/__tests__/replies/test-plugin-master.tar.gz diff --git a/src/cli/plugin/__tests__/settingParser.js b/src/cli/plugin/__tests__/settingParser.js new file mode 100644 index 0000000000000..afb499a794d59 --- /dev/null +++ b/src/cli/plugin/__tests__/settingParser.js @@ -0,0 +1,325 @@ +var path = require('path'); +var expect = require('expect.js'); + +var utils = require('requirefrom')('src/utils'); +var fromRoot = utils('fromRoot'); +var settingParser = require('../settingParser'); + +describe('kibana cli', function () { + + describe('plugin installer', function () { + + describe('command line option parsing', function () { + + describe('parseMilliseconds function', function () { + + var parser = settingParser(); + + it('should return 0 for an empty string', function () { + var value = ''; + + var result = parser.parseMilliseconds(value); + + expect(result).to.be(0); + }); + + it('should return 0 for a number with an invalid unit of measure', function () { + var result = parser.parseMilliseconds('1gigablasts'); + expect(result).to.be(0); + }); + + it('should assume a number with no unit of measure is specified as milliseconds', function () { + var result = parser.parseMilliseconds(1); + expect(result).to.be(1); + + result = parser.parseMilliseconds('1'); + expect(result).to.be(1); + }); + + it('should interpret a number with "s" as the unit of measure as seconds', function () { + var result = parser.parseMilliseconds('5s'); + expect(result).to.be(5 * 1000); + }); + + it('should interpret a number with "second" as the unit of measure as seconds', function () { + var result = parser.parseMilliseconds('5second'); + expect(result).to.be(5 * 1000); + }); + + it('should interpret a number with "seconds" as the unit of measure as seconds', function () { + var result = parser.parseMilliseconds('5seconds'); + expect(result).to.be(5 * 1000); + }); + + it('should interpret a number with "m" as the unit of measure as minutes', function () { + var result = parser.parseMilliseconds('9m'); + expect(result).to.be(9 * 1000 * 60); + }); + + it('should interpret a number with "minute" as the unit of measure as minutes', function () { + var result = parser.parseMilliseconds('9minute'); + expect(result).to.be(9 * 1000 * 60); + }); + + it('should interpret a number with "minutes" as the unit of measure as minutes', function () { + var result = parser.parseMilliseconds('9minutes'); + expect(result).to.be(9 * 1000 * 60); + }); + + }); + + describe('parse function', function () { + + var options; + var parser; + beforeEach(function () { + options = { install: 'dummy/dummy', pluginDir: fromRoot('installedPlugins') }; + }); + + it('should require the user to specify either install and remove', function () { + options.install = null; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.throwError(/Please specify either --install or --remove./); + }); + + it('should not allow the user to specify both install and remove', function () { + options.remove = 'package'; + options.install = 'org/package/version'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.throwError(/Please specify either --install or --remove./); + }); + + describe('quiet option', function () { + + it('should default to false', function () { + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings.quiet).to.be(false); + }); + + it('should set settings.quiet property to true', function () { + options.parent = { quiet: true }; + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings.quiet).to.be(true); + }); + + }); + + describe('silent option', function () { + + it('should default to false', function () { + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings).to.have.property('silent', false); + }); + + it('should set settings.silent property to true', function () { + options.silent = true; + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings).to.have.property('silent', true); + }); + + }); + + + describe('timeout option', function () { + + it('should default to 0 (milliseconds)', function () { + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings).to.have.property('timeout', 0); + }); + + it('should set settings.timeout property to specified value', function () { + options.timeout = 1234; + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings).to.have.property('timeout', 1234); + }); + + }); + + describe('install option', function () { + + it('should set settings.action property to "install"', function () { + options.install = 'org/package/version'; + parser = settingParser(options); + var settings = parser.parse(options); + + expect(settings).to.have.property('action', 'install'); + }); + + it('should allow two parts to the install parameter', function () { + options.install = 'kibana/test-plugin'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.not.throwError(); + + var settings = parser.parse(options); + + expect(settings).to.have.property('organization', 'kibana'); + expect(settings).to.have.property('package', 'test-plugin'); + expect(settings).to.have.property('version', undefined); + }); + + it('should allow three parts to the install parameter', function () { + options.install = 'kibana/test-plugin/v1.0.1'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.not.throwError(); + + var settings = parser.parse(options); + + expect(settings).to.have.property('organization', 'kibana'); + expect(settings).to.have.property('package', 'test-plugin'); + expect(settings).to.have.property('version', 'v1.0.1'); + }); + + it('should not allow one part to the install parameter', function () { + options.install = 'test-plugin'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.throwError(/Invalid install option. Please use the format \/\/./); + }); + + it('should not allow more than three parts to the install parameter', function () { + options.install = 'kibana/test-plugin/v1.0.1/dummy'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.throwError(/Invalid install option. Please use the format \/\/./); + }); + + it('should populate the urls collection properly when no version specified', function () { + options.install = 'kibana/test-plugin'; + parser = settingParser(options); + + var settings = parser.parse(); + + expect(settings.urls).to.have.property('length', 2); + expect(settings.urls).to.contain('https://download.elastic.co/kibana/test-plugin/test-plugin-latest.tar.gz'); + expect(settings.urls).to.contain('https://github.com/kibana/test-plugin/archive/master.tar.gz'); + }); + + it('should populate the urls collection properly version specified', function () { + options.install = 'kibana/test-plugin/v1.1.1'; + parser = settingParser(options); + + var settings = parser.parse(); + + expect(settings.urls).to.have.property('length', 2); + expect(settings.urls).to.contain('https://download.elastic.co/kibana/test-plugin/test-plugin-v1.1.1.tar.gz'); + expect(settings.urls).to.contain('https://github.com/kibana/test-plugin/archive/v1.1.1.tar.gz'); + }); + + it('should populate the pluginPath', function () { + options.install = 'kibana/test-plugin'; + parser = settingParser(options); + + var settings = parser.parse(); + var expected = fromRoot('installedPlugins/test-plugin'); + + expect(settings).to.have.property('pluginPath', expected); + }); + + describe('with url option', function () { + + it('should allow one part to the install parameter', function () { + options.install = 'test-plugin'; + options.url = 'http://www.google.com/plugin.tar.gz'; + parser = settingParser(options); + + expect(parser.parse).withArgs().to.not.throwError(); + + var settings = parser.parse(); + + expect(settings).to.have.property('package', 'test-plugin'); + }); + + it('should not allow more than one part to the install parameter', function () { + options.url = 'http://www.google.com/plugin.tar.gz'; + options.install = 'kibana/test-plugin'; + parser = settingParser(options); + + expect(parser.parse).withArgs() + .to.throwError(/Invalid install option. When providing a url, please use the format ./); + }); + + it('should result in only the specified url in urls collection', function () { + var url = 'http://www.google.com/plugin.tar.gz'; + options.install = 'test-plugin'; + options.url = url; + parser = settingParser(options); + + var settings = parser.parse(); + + expect(settings).to.have.property('urls'); + expect(settings.urls).to.be.an('array'); + expect(settings.urls).to.have.property('length', 1); + expect(settings.urls).to.contain(url); + }); + + }); + + }); + + describe('remove option', function () { + + it('should set settings.action property to "remove"', function () { + options.install = null; + options.remove = 'package'; + parser = settingParser(options); + + var settings = parser.parse(); + + expect(settings).to.have.property('action', 'remove'); + }); + + it('should allow one part to the remove parameter', function () { + options.install = null; + options.remove = 'test-plugin'; + parser = settingParser(options); + + var settings = parser.parse(); + + expect(settings).to.have.property('package', 'test-plugin'); + }); + + it('should not allow more than one part to the install parameter', function () { + options.install = null; + options.remove = 'kibana/test-plugin'; + parser = settingParser(options); + + expect(parser.parse).withArgs() + .to.throwError(/Invalid remove option. Please use the format ./); + }); + + it('should populate the pluginPath', function () { + options.install = null; + options.remove = 'test-plugin'; + parser = settingParser(options); + + var settings = parser.parse(); + var expected = fromRoot('installedPlugins/test-plugin'); + + expect(settings).to.have.property('pluginPath', expected); + }); + + }); + + }); + + }); + + }); + +}); diff --git a/src/server/bin/plugin/npmInstall.js b/src/cli/plugin/npmInstall.js similarity index 100% rename from src/server/bin/plugin/npmInstall.js rename to src/cli/plugin/npmInstall.js diff --git a/src/cli/plugin/plugin.js b/src/cli/plugin/plugin.js new file mode 100644 index 0000000000000..078c5ddb262b8 --- /dev/null +++ b/src/cli/plugin/plugin.js @@ -0,0 +1,67 @@ +var utils = require('requirefrom')('src/utils'); +var fromRoot = utils('fromRoot'); + +var settingParser = require('./settingParser'); +var installer = require('./pluginInstaller'); +var remover = require('./pluginRemover'); +var pluginLogger = require('./pluginLogger'); + +module.exports = function (program) { + function processCommand(command, options) { + var settings; + try { + settings = settingParser(command).parse(); + } catch (ex) { + //The logger has not yet been initialized. + console.error(ex.message); + process.exit(64); + } + + var logger = pluginLogger(settings); + + if (settings.action === 'install') { + installer.install(settings, logger); + } + if (settings.action === 'remove') { + remover.remove(settings, logger); + } + } + + program + .command('plugin') + .option('-i, --install //', 'The plugin to install') + .option('-r, --remove ', 'The plugin to remove') + .option('-q, --quiet', 'Disable all process messaging except errors') + .option('-s, --silent', 'Disable all process messaging') + .option('-u, --url ', 'Specify download url') + .option( + '-t, --timeout ', + 'Length of time before failing; 0 for never fail', + settingParser.parseMilliseconds + ) + .option( + '-d, --plugin-dir ', + 'The path to the directory where plugins are stored', + fromRoot('installedPlugins') + ) + .description( + 'Maintain Plugins', +` + Common examples: + -i username/sample + attempts to download the latest version from the following urls: + https://download.elastic.co/username/sample/sample-latest.tar.gz + https://github.com/username/sample/archive/master.tar.gz + + -i username/sample/v1.1.1 + attempts to download version v1.1.1 from the following urls: + https://download.elastic.co/username/sample/sample-v1.1.1.tar.gz + https://github.com/username/sample/archive/v1.1.1.tar.gz + + -i sample -u http://www.example.com/other_name.tar.gz + attempts to download from the specified url, + and installs the plugin found at that url as "sample" +` + ) + .action(processCommand); +}; diff --git a/src/server/bin/plugin/pluginCleaner.js b/src/cli/plugin/pluginCleaner.js similarity index 100% rename from src/server/bin/plugin/pluginCleaner.js rename to src/cli/plugin/pluginCleaner.js diff --git a/src/cli/plugin/pluginDownloader.js b/src/cli/plugin/pluginDownloader.js new file mode 100644 index 0000000000000..56b99ae75c35f --- /dev/null +++ b/src/cli/plugin/pluginDownloader.js @@ -0,0 +1,91 @@ +var _ = require('lodash'); +var zlib = require('zlib'); +var Promise = require('bluebird'); +var request = require('request'); +var tar = require('tar'); +var progressReporter = require('./progressReporter'); + +module.exports = function (settings, logger) { + + //Attempts to download each url in turn until one is successful + function download() { + var urls = settings.urls; + + function tryNext() { + var sourceUrl = urls.shift(); + if (!sourceUrl) { + throw new Error('Not a valid url.'); + } + + logger.log('attempting to download ' + sourceUrl); + + return Promise.try(function () { + return downloadSingle(sourceUrl, settings.workingPath, settings.timeout, logger) + .catch(function (err) { + if (err.message === 'ENOTFOUND') { + return tryNext(); + } + if (err.message === 'EEXTRACT') { + throw (new Error('Error extracting the plugin archive')); + } + throw (err); + }); + }) + .catch(function (err) { + //Special case for when request.get throws an exception + if (err.message.match(/invalid uri/i)) { + return tryNext(); + } + throw (err); + }); + } + + return tryNext(); + } + + //Attempts to download a single url + function downloadSingle(source, dest, timeout) { + var gunzip = zlib.createGunzip(); + var tarExtract = tar.Extract({ path: dest, strip: 1 }); + + var requestOptions = { url: source }; + if (timeout !== 0) { + requestOptions.timeout = timeout; + } + + return wrappedRequest(requestOptions) + .then(function (req) { + var reporter = progressReporter(logger, req); + + req + .on('response', reporter.handleResponse) + .on('data', reporter.handleData) + .on('error', _.partial(reporter.handleError, 'ENOTFOUND')) + .pipe(gunzip) + .on('error', _.partial(reporter.handleError, 'EEXTRACT')) + .pipe(tarExtract) + .on('error', _.partial(reporter.handleError, 'EEXTRACT')) + .on('end', reporter.handleEnd); + + return reporter.promise; + }); + } + + function wrappedRequest(requestOptions) { + return Promise.try(function () { + return request.get(requestOptions); + }) + .catch(function (err) { + if (err.message.match(/invalid uri/i)) { + throw new Error('ENOTFOUND'); + } + throw err; + }); + } + + + return { + download: download, + _downloadSingle: downloadSingle + }; +}; diff --git a/src/server/bin/plugin/pluginInstaller.js b/src/cli/plugin/pluginInstaller.js similarity index 100% rename from src/server/bin/plugin/pluginInstaller.js rename to src/cli/plugin/pluginInstaller.js diff --git a/src/server/bin/plugin/pluginLogger.js b/src/cli/plugin/pluginLogger.js similarity index 100% rename from src/server/bin/plugin/pluginLogger.js rename to src/cli/plugin/pluginLogger.js diff --git a/src/server/bin/plugin/pluginRemover.js b/src/cli/plugin/pluginRemover.js similarity index 100% rename from src/server/bin/plugin/pluginRemover.js rename to src/cli/plugin/pluginRemover.js diff --git a/src/server/bin/plugin/progressReporter.js b/src/cli/plugin/progressReporter.js similarity index 100% rename from src/server/bin/plugin/progressReporter.js rename to src/cli/plugin/progressReporter.js diff --git a/src/cli/plugin/settingParser.js b/src/cli/plugin/settingParser.js new file mode 100644 index 0000000000000..652b29bcaa5ce --- /dev/null +++ b/src/cli/plugin/settingParser.js @@ -0,0 +1,108 @@ +var resolve = require('path').resolve; +var expiry = require('expiry-js'); + +module.exports = function (options) { + function parseMilliseconds(val) { + var result; + + try { + var timeVal = expiry(val); + result = timeVal.asMilliseconds(); + } catch (ex) { + result = 0; + } + + return result; + } + + function generateDownloadUrl(settings) { + var version = (settings.version) || 'latest'; + var filename = settings.package + '-' + version + '.tar.gz'; + + return 'https://download.elastic.co/' + settings.organization + '/' + settings.package + '/' + filename; + } + + function generateGithubUrl(settings) { + var version = (settings.version) || 'master'; + var filename = version + '.tar.gz'; + + return 'https://github.com/' + settings.organization + '/' + settings.package + '/archive/' + filename; + } + + function parse() { + var parts; + var settings = { + timeout: 0, + silent: false, + quiet: false, + urls: [] + }; + + if (options.timeout) { + settings.timeout = options.timeout; + } + + if (options.parent && options.parent.quiet) { + settings.quiet = options.parent.quiet; + } + + if (options.silent) { + settings.silent = options.silent; + } + + if (options.url) { + settings.urls.push(options.url); + } + + if (options.install) { + settings.action = 'install'; + parts = options.install.split('/'); + + if (options.url) { + if (parts.length !== 1) { + throw new Error('Invalid install option. When providing a url, please use the format .'); + } + + settings.package = parts.shift(); + } else { + if (parts.length < 2 || parts.length > 3) { + throw new Error('Invalid install option. Please use the format //.'); + } + + settings.organization = parts.shift(); + settings.package = parts.shift(); + settings.version = parts.shift(); + + settings.urls.push(generateDownloadUrl(settings)); + settings.urls.push(generateGithubUrl(settings)); + } + } + + if (options.remove) { + settings.action = 'remove'; + parts = options.remove.split('/'); + + if (parts.length !== 1) { + throw new Error('Invalid remove option. Please use the format .'); + } + settings.package = parts.shift(); + } + + if (!settings.action || (options.install && options.remove)) { + throw new Error('Please specify either --install or --remove.'); + } + + settings.pluginDir = options.pluginDir; + if (settings.package) { + settings.pluginPath = resolve(settings.pluginDir, settings.package); + settings.workingPath = resolve(settings.pluginDir, '.plugin.installing'); + } + + return settings; + } + + return { + parse: parse, + parseMilliseconds: parseMilliseconds + }; +}; diff --git a/src/cli/serve/readYamlConfig.js b/src/cli/serve/readYamlConfig.js new file mode 100644 index 0000000000000..aa5f7ff691b2f --- /dev/null +++ b/src/cli/serve/readYamlConfig.js @@ -0,0 +1,64 @@ +'use strict'; + +let _ = require('lodash'); +let fs = require('fs'); +let yaml = require('js-yaml'); + +let utils = require('requirefrom')('src/utils'); +let fromRoot = utils('fromRoot'); + +let legacySettingMap = { + // server + port: 'server.port', + host: 'server.host', + pid_file: 'pid.file', + ssl_cert_file: 'server.ssl.cert', + ssl_key_file: 'server.ssl.key', + + // logging + log_file: 'logging.dest', + + // kibana + kibana_index: 'kibana.index', + default_app_id: 'kibana.defaultAppId', + + // es + ca: 'elasticsearch.ssl.ca', + elasticsearch_preserve_host: 'elasticsearch.preserveHost', + elasticsearch_url: 'elasticsearch.url', + kibana_elasticsearch_client_crt: 'elasticsearch.ssl.cert', + kibana_elasticsearch_client_key: 'elasticsearch.ssl.key', + kibana_elasticsearch_password: 'elasticsearch.password', + kibana_elasticsearch_username: 'elasticsearch.username', + ping_timeout: 'elasticsearch.pingTimeout', + request_timeout: 'elasticsearch.requestTimeout', + shard_timeout: 'elasticsearch.shardTimeout', + startup_timeout: 'elasticsearch.startupTimeout', + verify_ssl: 'elasticsearch.ssl.verify', +}; + +module.exports = function (path) { + if (!path) return {}; + + let file = yaml.safeLoad(fs.readFileSync(path, 'utf8')); + + function apply(config, val, key) { + if (_.isPlainObject(val)) { + _.forOwn(val, function (subVal, subKey) { + apply(config, subVal, key + '.' + subKey); + }); + } else { + _.set(config, key, val); + } + } + + // transform legeacy options into new namespaced versions + return _.transform(file, function (config, val, key) { + if (legacySettingMap.hasOwnProperty(key)) { + key = legacySettingMap[key]; + } + + apply(config, val, key); + }, {}); +}; + diff --git a/src/cli/serve/serve.js b/src/cli/serve/serve.js new file mode 100644 index 0000000000000..283b1193c7233 --- /dev/null +++ b/src/cli/serve/serve.js @@ -0,0 +1,96 @@ +'use strict'; + +let _ = require('lodash'); +let isWorker = require('cluster').isWorker; +let resolve = require('path').resolve; + +let cwd = process.cwd(); +let readYamlConfig = require('./readYamlConfig'); +let src = require('requirefrom')('src'); +let fromRoot = src('utils/fromRoot'); +let KbnServer = src('server/KbnServer'); + +let pathCollector = function () { + let paths = []; + return function (path) { + paths.push(resolve(process.cwd(), path)); + return paths; + }; +}; + +let pluginDirCollector = pathCollector(); +let pluginPathCollector = pathCollector(); + +module.exports = function (program) { + program + .command('serve') + .description('Run the kibana server') + .collectUnknownOptions() + .option('-e, --elasticsearch ', 'Elasticsearch instance') + .option('-c, --config ', 'Path to the config file') + .option('-p, --port ', 'The port to bind to', parseInt) + .option('-q, --quiet', 'Prevent all logging except errors') + .option('-Q, --silent', 'Prevent all logging') + .option('--verbose', 'Turns on verbose logging') + .option('-H, --host ', 'The host to bind to') + .option('-l, --log-file ', 'The file to log to') + .option( + '--plugin-dir ', + 'A path to scan for plugins, this can be specified multiple ' + + 'times to specify multiple directories', + pluginDirCollector, + [ + fromRoot('installedPlugins'), + fromRoot('src/plugins') + ] + ) + .option( + '--plugin-path ', + 'A path to a plugin which should be included by the server, ' + + 'this can be specified multiple times to specify multiple paths', + pluginPathCollector, + [] + ) + .option('--plugins ', 'an alias for --plugin-dir', pluginDirCollector) + .option('--dev', 'Run the server with development mode defaults') + .option('--no-watch', 'Prevent watching, use with --dev to prevent server restarts') + .action(function (opts) { + if (opts.dev && opts.watch && !isWorker) { + // stop processing the action and handoff to watch cluster manager + return require('../watch/watch')(opts); + } + + let settings = readYamlConfig(opts.config || fromRoot('config/kibana.yml')); + let set = _.partial(_.set, settings); + let get = _.partial(_.get, settings); + + if (opts.dev) { + set('env', 'development'); + set('optimize.watch', opts.watch); + } + + if (opts.elasticsearch) set('elasticsearch.url', opts.elasticsearch); + if (opts.port) set('server.port', opts.port); + if (opts.host) set('server.host', opts.host); + if (opts.quiet) set('logging.quiet', true); + if (opts.silent) set('logging.silent', true); + if (opts.verbose) set('logging.verbose', true); + if (opts.logFile) set('logging.dest', opts.logFile); + + set('plugins.scanDirs', _.compact([].concat( + get('plugins.scanDirs'), + opts.pluginDir + ))); + + set('plugins.paths', [].concat(opts.pluginPath || [])); + + let server = new KbnServer(_.merge(settings, this.getUnknownOptions())); + + server.ready().catch(function (err) { + console.error(err.stack); + process.exit(1); + }); + + return server; + }); +}; diff --git a/src/cli/watch/Worker.js b/src/cli/watch/Worker.js new file mode 100644 index 0000000000000..3e7511c9186a6 --- /dev/null +++ b/src/cli/watch/Worker.js @@ -0,0 +1,106 @@ +'use strict'; + +let _ = require('lodash'); +let cluster = require('cluster'); +let resolve = require('path').resolve; +let EventEmitter = require('events').EventEmitter; + +let fromRoot = require('../../utils/fromRoot'); + +let cliPath = fromRoot('src/cli/cli.js'); +let baseArgs = _.difference(process.argv.slice(2), ['--no-watch']); +let baseArgv = [process.execPath, cliPath].concat(baseArgs); + +cluster.setupMaster({ + exec: cliPath, + silent: false +}); + +module.exports = class Worker extends EventEmitter { + constructor(opts) { + opts = opts || {}; + super(); + + this.log = opts.log; + this.type = opts.type; + this.title = opts.title || opts.type; + this.filters = opts.filters; + this.changes = []; + + let argv = _.union(baseArgv, opts.argv || []); + this.env = { + kbnWorkerType: this.type, + kbnWorkerArgv: JSON.stringify(argv) + }; + + _.bindAll(this, ['onExit', 'onMessage', 'shutdown', 'start']); + + this.start = _.debounce(this.start, 25); + cluster.on('exit', this.onExit); + process.on('exit', this.shutdown); + } + + onExit(fork, code) { + if (this.fork !== fork) return; + + // our fork is gone, clear our ref so we don't try to talk to it anymore + this.fork = null; + + if (code) { + this.log.bad(`${this.title} crashed`, 'with status code', code); + } else { + // restart after graceful shutdowns + this.start(); + } + } + + onChange(path) { + var valid = true; + + if (this.filters) { + valid = _.any(this.filters, function (filter) { + return filter.test(path); + }); + } + + if (!valid) return; + this.changes.push(path); + this.start(); + } + + shutdown() { + if (this.fork && !this.fork.isDead()) { + this.fork.kill(); + this.fork.removeListener('message', this.onMessage); + } + } + + onMessage(msg) { + if (!_.isArray(msg) || msg[0] !== 'WORKER_BROADCAST') return; + this.emit('broadcast', msg[1]); + } + + flushChangeBuffer() { + let files = _.unique(this.changes.splice(0)); + let prefix = files.length > 1 ? '\n - ' : ''; + return files.reduce(function (list, file, i, files) { + return `${list || ''}${prefix}"${file}"`; + }, ''); + } + + start() { + if (this.fork && !this.fork.isDead()) { + // once "exit" event is received with 0 status, start() is called again + return this.shutdown(); + } + + if (this.fork && this.changes.length) { + this.log.warn(`${this.title} restarting`, `due to changes in ${this.flushChangeBuffer()}`); + } else { + this.log.warn(`${this.title} starting`); + } + + this.fork = cluster.fork(this.env); + this.fork.on('message', this.onMessage); + } +}; diff --git a/src/cli/watch/watch.js b/src/cli/watch/watch.js new file mode 100644 index 0000000000000..fe9b037eb5158 --- /dev/null +++ b/src/cli/watch/watch.js @@ -0,0 +1,92 @@ +'use strict'; + +let cluster = require('cluster'); +let join = require('path').join; +let _ = require('lodash'); +var chokidar = require('chokidar'); + +let utils = require('requirefrom')('src/utils'); +let fromRoot = utils('fromRoot'); +let Log = require('../Log'); +let Worker = require('./Worker'); + +module.exports = function (opts) { + + let watcher = chokidar.watch([ + 'src/cli', + 'src/fixtures', + 'src/server', + 'src/utils', + 'src/plugins', + 'config', + ], { + cwd: fromRoot('.'), + ignore: 'src/plugins/*/public/**/*' + }); + + let log = new Log(opts.quiet, opts.silent); + let customLogging = opts.quiet || opts.silent || opts.verbose; + + let workers = [ + new Worker({ + type: 'optmzr', + title: 'optimizer', + log: log, + argv: _.compact([ + customLogging ? null : '--quiet', + '--plugins.initialize=false', + '--server.autoListen=false', + '--optimize._workerRole=send' + ]), + filters: [ + /src\/server\/(optimize|ui|plugins)\//, + /src\/plugins\/[^\/]+\/[^\/]+\.js$/, + /src\/cli\// + ] + }), + + new Worker({ + type: 'server', + log: log, + argv: [ + '--optimize._workerRole=receive' + ] + }) + ]; + + workers.forEach(function (worker) { + worker.on('broadcast', function (msg) { + workers.forEach(function (to) { + if (to !== worker && to.fork) to.fork.send(msg); + }); + }); + }); + + + var addedCount = 0; + function onAddBeforeReady() { + addedCount += 1; + } + + function onReady() { + // start sending changes to workers + watcher.removeListener('add', onAddBeforeReady); + watcher.on('all', onAnyChangeAfterReady); + + log.good('Watching for changes', `(${addedCount} files)`); + _.invoke(workers, 'start'); + } + + function onAnyChangeAfterReady(e, path) { + _.invoke(workers, 'onChange', path); + } + + function onError(err) { + log.bad('Failed to watch files!\n', err.stack); + process.exit(1); + } + + watcher.on('add', onAddBeforeReady); + watcher.on('ready', onReady); + watcher.on('error', onError); +}; diff --git a/test/unit/fixtures/agg_resp/date_histogram.js b/src/fixtures/agg_resp/date_histogram.js similarity index 100% rename from test/unit/fixtures/agg_resp/date_histogram.js rename to src/fixtures/agg_resp/date_histogram.js diff --git a/test/unit/fixtures/agg_resp/geohash_grid.js b/src/fixtures/agg_resp/geohash_grid.js similarity index 100% rename from test/unit/fixtures/agg_resp/geohash_grid.js rename to src/fixtures/agg_resp/geohash_grid.js diff --git a/test/unit/fixtures/config_upgrade_from_4.0.0.json b/src/fixtures/config_upgrade_from_4.0.0.json similarity index 100% rename from test/unit/fixtures/config_upgrade_from_4.0.0.json rename to src/fixtures/config_upgrade_from_4.0.0.json diff --git a/test/unit/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json b/src/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json similarity index 100% rename from test/unit/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json rename to src/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json diff --git a/test/unit/fixtures/config_upgrade_from_4.0.0_to_4.0.1.json b/src/fixtures/config_upgrade_from_4.0.0_to_4.0.1.json similarity index 100% rename from test/unit/fixtures/config_upgrade_from_4.0.0_to_4.0.1.json rename to src/fixtures/config_upgrade_from_4.0.0_to_4.0.1.json diff --git a/test/unit/fixtures/fake_chart_events.js b/src/fixtures/fake_chart_events.js similarity index 100% rename from test/unit/fixtures/fake_chart_events.js rename to src/fixtures/fake_chart_events.js diff --git a/test/unit/fixtures/fake_hierarchical_data.js b/src/fixtures/fake_hierarchical_data.js similarity index 100% rename from test/unit/fixtures/fake_hierarchical_data.js rename to src/fixtures/fake_hierarchical_data.js diff --git a/test/unit/fixtures/fake_row.js b/src/fixtures/fake_row.js similarity index 100% rename from test/unit/fixtures/fake_row.js rename to src/fixtures/fake_row.js diff --git a/test/unit/fixtures/field_mapping.js b/src/fixtures/field_mapping.js similarity index 100% rename from test/unit/fixtures/field_mapping.js rename to src/fixtures/field_mapping.js diff --git a/test/unit/fixtures/filter_skeleton.js b/src/fixtures/filter_skeleton.js similarity index 100% rename from test/unit/fixtures/filter_skeleton.js rename to src/fixtures/filter_skeleton.js diff --git a/test/unit/fixtures/hits.js b/src/fixtures/hits.js similarity index 100% rename from test/unit/fixtures/hits.js rename to src/fixtures/hits.js diff --git a/test/unit/fixtures/logstash_fields.js b/src/fixtures/logstash_fields.js similarity index 100% rename from test/unit/fixtures/logstash_fields.js rename to src/fixtures/logstash_fields.js diff --git a/test/unit/fixtures/mapping_with_dupes.js b/src/fixtures/mapping_with_dupes.js similarity index 100% rename from test/unit/fixtures/mapping_with_dupes.js rename to src/fixtures/mapping_with_dupes.js diff --git a/test/unit/fixtures/mock_courier.js b/src/fixtures/mock_courier.js similarity index 88% rename from test/unit/fixtures/mock_courier.js rename to src/fixtures/mock_courier.js index 933c54dd1efc8..07e6de0091f62 100644 --- a/test/unit/fixtures/mock_courier.js +++ b/src/fixtures/mock_courier.js @@ -1,6 +1,6 @@ define(function (require) { var _ = require('lodash'); - var sinon = require('test_utils/auto_release_sinon'); + var sinon = require('auto-release-sinon'); return function (Private, Promise) { var indexPatterns = Private(require('fixtures/stubbed_logstash_index_pattern')); diff --git a/test/unit/fixtures/mock_state.js b/src/fixtures/mock_state.js similarity index 85% rename from test/unit/fixtures/mock_state.js rename to src/fixtures/mock_state.js index ce0b14312d0b0..1346b8386ec02 100644 --- a/test/unit/fixtures/mock_state.js +++ b/src/fixtures/mock_state.js @@ -1,6 +1,6 @@ define(function (require) { var _ = require('lodash'); - var sinon = require('test_utils/auto_release_sinon'); + var sinon = require('auto-release-sinon'); function MockState(defaults) { this.on = _.noop; diff --git a/test/unit/fixtures/real_hits.js b/src/fixtures/real_hits.js similarity index 100% rename from test/unit/fixtures/real_hits.js rename to src/fixtures/real_hits.js diff --git a/test/unit/fixtures/require_from.js b/src/fixtures/require_from.js similarity index 100% rename from test/unit/fixtures/require_from.js rename to src/fixtures/require_from.js diff --git a/test/unit/fixtures/search_response.js b/src/fixtures/search_response.js similarity index 100% rename from test/unit/fixtures/search_response.js rename to src/fixtures/search_response.js diff --git a/test/unit/fixtures/stubbed_doc_source_response.js b/src/fixtures/stubbed_doc_source_response.js similarity index 100% rename from test/unit/fixtures/stubbed_doc_source_response.js rename to src/fixtures/stubbed_doc_source_response.js diff --git a/test/unit/fixtures/stubbed_logstash_index_pattern.js b/src/fixtures/stubbed_logstash_index_pattern.js similarity index 82% rename from test/unit/fixtures/stubbed_logstash_index_pattern.js rename to src/fixtures/stubbed_logstash_index_pattern.js index 75b8c8811b5d3..2b114919a81e5 100644 --- a/test/unit/fixtures/stubbed_logstash_index_pattern.js +++ b/src/fixtures/stubbed_logstash_index_pattern.js @@ -1,7 +1,7 @@ define(function (require) { return function stubbedLogstashIndexPatternService(Private) { - var StubIndexPattern = Private(require('test_utils/stub_index_pattern')); - var fieldTypes = Private(require('components/index_patterns/_field_types')); + var StubIndexPattern = Private(require('testUtils/stubIndexPattern')); + var fieldTypes = Private(require('ui/index_patterns/_field_types')); var mockLogstashFields = Private(require('fixtures/logstash_fields')); var _ = require('lodash'); diff --git a/test/unit/fixtures/stubbed_search_source.js b/src/fixtures/stubbed_search_source.js similarity index 94% rename from test/unit/fixtures/stubbed_search_source.js rename to src/fixtures/stubbed_search_source.js index d7067d868534b..d738f8c1e8d7c 100644 --- a/test/unit/fixtures/stubbed_search_source.js +++ b/src/fixtures/stubbed_search_source.js @@ -1,5 +1,5 @@ define(function (require) { - var sinon = require('test_utils/auto_release_sinon'); + var sinon = require('auto-release-sinon'); var searchResponse = require('fixtures/search_response'); return function stubSearchSource(Private, $q) { diff --git a/test/unit/fixtures/tilemap_map.js b/src/fixtures/tilemap_map.js similarity index 88% rename from test/unit/fixtures/tilemap_map.js rename to src/fixtures/tilemap_map.js index 0c7a69781b6e8..5d07de8349212 100644 --- a/test/unit/fixtures/tilemap_map.js +++ b/src/fixtures/tilemap_map.js @@ -1,5 +1,5 @@ define(function (require) { - var sinon = require('test_utils/auto_release_sinon'); + var sinon = require('auto-release-sinon'); function MockMap(container, chartData, params) { this.container = container; diff --git a/src/fixtures/vislib/_vis_fixture.js b/src/fixtures/vislib/_vis_fixture.js new file mode 100644 index 0000000000000..d7e74a634f3c0 --- /dev/null +++ b/src/fixtures/vislib/_vis_fixture.js @@ -0,0 +1,33 @@ +var $ = require('jquery'); +var _ = require('lodash'); + +var $visCanvas = $('
').attr('id', 'vislib-vis-fixtures').appendTo('body'); +var count = 0; +var visHeight = $visCanvas.height(); + +$visCanvas.new = function () { + count += 1; + if (count > 1) $visCanvas.height(visHeight * count); + return $('
').addClass('visualize-chart').appendTo($visCanvas); +}; + +afterEach(function () { + $visCanvas.empty(); + if (count > 1) $visCanvas.height(visHeight); + count = 0; +}); + +module.exports = function VislibFixtures(Private) { + return function (visLibParams) { + var Vis = Private(require('ui/vislib/vis')); + return new Vis($visCanvas.new(), _.defaults({}, visLibParams || {}, { + shareYAxis: true, + addTooltip: true, + addLegend: true, + defaultYExtents: false, + setYExtents: false, + yAxis: {}, + type: 'histogram' + })); + }; +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_columns.js b/src/fixtures/vislib/mock_data/date_histogram/_columns.js new file mode 100644 index 0000000000000..6fa4d1ee8aad2 --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_columns.js @@ -0,0 +1,264 @@ +var moment = require('moment'); + +module.exports = { + 'columns': [ + { + 'label': '200: response', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1415826608440, + 'max': 1415827508440 + }, + 'yAxisLabel': 'Count of documents', + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + }, + 'series': [ + { + 'values': [ + { + 'x': 1415826600000, + 'y': 4 + }, + { + 'x': 1415826630000, + 'y': 8 + }, + { + 'x': 1415826660000, + 'y': 7 + }, + { + 'x': 1415826690000, + 'y': 5 + }, + { + 'x': 1415826720000, + 'y': 5 + }, + { + 'x': 1415826750000, + 'y': 4 + }, + { + 'x': 1415826780000, + 'y': 10 + }, + { + 'x': 1415826810000, + 'y': 7 + }, + { + 'x': 1415826840000, + 'y': 9 + }, + { + 'x': 1415826870000, + 'y': 8 + }, + { + 'x': 1415826900000, + 'y': 9 + }, + { + 'x': 1415826930000, + 'y': 8 + }, + { + 'x': 1415826960000, + 'y': 3 + }, + { + 'x': 1415826990000, + 'y': 9 + }, + { + 'x': 1415827020000, + 'y': 6 + }, + { + 'x': 1415827050000, + 'y': 8 + }, + { + 'x': 1415827080000, + 'y': 7 + }, + { + 'x': 1415827110000, + 'y': 4 + }, + { + 'x': 1415827140000, + 'y': 6 + }, + { + 'x': 1415827170000, + 'y': 10 + }, + { + 'x': 1415827200000, + 'y': 2 + }, + { + 'x': 1415827230000, + 'y': 8 + }, + { + 'x': 1415827260000, + 'y': 5 + }, + { + 'x': 1415827290000, + 'y': 6 + }, + { + 'x': 1415827320000, + 'y': 6 + }, + { + 'x': 1415827350000, + 'y': 10 + }, + { + 'x': 1415827380000, + 'y': 6 + }, + { + 'x': 1415827410000, + 'y': 6 + }, + { + 'x': 1415827440000, + 'y': 12 + }, + { + 'x': 1415827470000, + 'y': 9 + }, + { + 'x': 1415827500000, + 'y': 1 + } + ] + } + ] + }, + { + 'label': '503: response', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1415826608440, + 'max': 1415827508440 + }, + 'yAxisLabel': 'Count of documents', + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + }, + 'series': [ + { + 'values': [ + { + 'x': 1415826630000, + 'y': 1 + }, + { + 'x': 1415826660000, + 'y': 1 + }, + { + 'x': 1415826720000, + 'y': 1 + }, + { + 'x': 1415826780000, + 'y': 1 + }, + { + 'x': 1415826900000, + 'y': 1 + }, + { + 'x': 1415827020000, + 'y': 1 + }, + { + 'x': 1415827080000, + 'y': 1 + }, + { + 'x': 1415827110000, + 'y': 2 + } + ] + } + ] + }, + { + 'label': '404: response', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1415826608440, + 'max': 1415827508440 + }, + 'yAxisLabel': 'Count of documents', + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + }, + 'series': [ + { + 'values': [ + { + 'x': 1415826660000, + 'y': 1 + }, + { + 'x': 1415826720000, + 'y': 1 + }, + { + 'x': 1415826810000, + 'y': 1 + }, + { + 'x': 1415826960000, + 'y': 1 + }, + { + 'x': 1415827050000, + 'y': 1 + }, + { + 'x': 1415827260000, + 'y': 1 + }, + { + 'x': 1415827380000, + 'y': 1 + }, + { + 'x': 1415827410000, + 'y': 1 + } + ] + } + ] + } + ], + 'hits': 225 +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_rows.js b/src/fixtures/vislib/mock_data/date_histogram/_rows.js new file mode 100644 index 0000000000000..c2ff7a40de5f5 --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_rows.js @@ -0,0 +1,1645 @@ +var moment = require('moment'); + +module.exports = { + 'rows': [ + { + 'label': '0.0-1000.0: bytes', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1415826260456, + 'max': 1415827160456 + }, + 'yAxisLabel': 'Count of documents', + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + }, + 'series': [ + { + 'label': 'jpg', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'css', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'png', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827110000, + 'y': 1, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'php', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 2 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'gif', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 3, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826660000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 1, + 'y0': 1 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 1, + 'y0': 1 + }, + { + 'x': 1415827110000, + 'y': 1, + 'y0': 2 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + } + ] + }, + { + 'label': '1000.0-2000.0: bytes', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1415826260457, + 'max': 1415827160457 + }, + 'yAxisLabel': 'Count of documents', + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + }, + 'series': [ + { + 'label': 'jpg', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 2, + 'y0': 0 + }, + { + 'x': 1415826840000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'css', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 2 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'png', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 2 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'php', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 2 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + }, + { + 'label': 'gif', + 'values': [ + { + 'x': 1415826240000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826270000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826300000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826330000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826360000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826390000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826420000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826450000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826480000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826510000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826540000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826570000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826600000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826630000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826660000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826690000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826720000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826750000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826780000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826810000, + 'y': 0, + 'y0': 2 + }, + { + 'x': 1415826840000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826870000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826900000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415826930000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826960000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415826990000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827020000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827050000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827080000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 1415827110000, + 'y': 0, + 'y0': 1 + }, + { + 'x': 1415827140000, + 'y': 0, + 'y0': 0 + } + ] + } + ] + } + ], + 'hits': 236 +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series.js b/src/fixtures/vislib/mock_data/date_histogram/_series.js new file mode 100644 index 0000000000000..7c126c41eb9d3 --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_series.js @@ -0,0 +1,150 @@ +var moment = require('moment'); + +module.exports = { + 'label': '', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'min': 1411761457636, + 'max': 1411762357636, + 'interval': 30000 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 1411761450000, + 'y': 41 + }, + { + 'x': 1411761480000, + 'y': 18 + }, + { + 'x': 1411761510000, + 'y': 22 + }, + { + 'x': 1411761540000, + 'y': 17 + }, + { + 'x': 1411761570000, + 'y': 17 + }, + { + 'x': 1411761600000, + 'y': 21 + }, + { + 'x': 1411761630000, + 'y': 16 + }, + { + 'x': 1411761660000, + 'y': 17 + }, + { + 'x': 1411761690000, + 'y': 15 + }, + { + 'x': 1411761720000, + 'y': 19 + }, + { + 'x': 1411761750000, + 'y': 11 + }, + { + 'x': 1411761780000, + 'y': 13 + }, + { + 'x': 1411761810000, + 'y': 24 + }, + { + 'x': 1411761840000, + 'y': 20 + }, + { + 'x': 1411761870000, + 'y': 20 + }, + { + 'x': 1411761900000, + 'y': 21 + }, + { + 'x': 1411761930000, + 'y': 17 + }, + { + 'x': 1411761960000, + 'y': 20 + }, + { + 'x': 1411761990000, + 'y': 13 + }, + { + 'x': 1411762020000, + 'y': 14 + }, + { + 'x': 1411762050000, + 'y': 25 + }, + { + 'x': 1411762080000, + 'y': 17 + }, + { + 'x': 1411762110000, + 'y': 14 + }, + { + 'x': 1411762140000, + 'y': 22 + }, + { + 'x': 1411762170000, + 'y': 14 + }, + { + 'x': 1411762200000, + 'y': 19 + }, + { + 'x': 1411762230000, + 'y': 22 + }, + { + 'x': 1411762260000, + 'y': 17 + }, + { + 'x': 1411762290000, + 'y': 8 + }, + { + 'x': 1411762320000, + 'y': 15 + }, + { + 'x': 1411762350000, + 'y': 4 + } + ] + } + ], + 'hits': 533, + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js b/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js new file mode 100644 index 0000000000000..a514c0000efcf --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js @@ -0,0 +1,150 @@ +var moment = require('moment'); + +module.exports = { + 'label': '', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'min': 1411761457636, + 'max': 1411762357636, + 'interval': 30000 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 1411761450000, + 'y': -41 + }, + { + 'x': 1411761480000, + 'y': -18 + }, + { + 'x': 1411761510000, + 'y': -22 + }, + { + 'x': 1411761540000, + 'y': -17 + }, + { + 'x': 1411761570000, + 'y': -17 + }, + { + 'x': 1411761600000, + 'y': -21 + }, + { + 'x': 1411761630000, + 'y': -16 + }, + { + 'x': 1411761660000, + 'y': -17 + }, + { + 'x': 1411761690000, + 'y': -15 + }, + { + 'x': 1411761720000, + 'y': -19 + }, + { + 'x': 1411761750000, + 'y': -11 + }, + { + 'x': 1411761780000, + 'y': -13 + }, + { + 'x': 1411761810000, + 'y': -24 + }, + { + 'x': 1411761840000, + 'y': -20 + }, + { + 'x': 1411761870000, + 'y': -20 + }, + { + 'x': 1411761900000, + 'y': -21 + }, + { + 'x': 1411761930000, + 'y': -17 + }, + { + 'x': 1411761960000, + 'y': -20 + }, + { + 'x': 1411761990000, + 'y': -13 + }, + { + 'x': 1411762020000, + 'y': -14 + }, + { + 'x': 1411762050000, + 'y': -25 + }, + { + 'x': 1411762080000, + 'y': -17 + }, + { + 'x': 1411762110000, + 'y': -14 + }, + { + 'x': 1411762140000, + 'y': -22 + }, + { + 'x': 1411762170000, + 'y': -14 + }, + { + 'x': 1411762200000, + 'y': -19 + }, + { + 'x': 1411762230000, + 'y': -22 + }, + { + 'x': 1411762260000, + 'y': -17 + }, + { + 'x': 1411762290000, + 'y': -8 + }, + { + 'x': 1411762320000, + 'y': -15 + }, + { + 'x': 1411762350000, + 'y': -4 + } + ] + } + ], + 'hits': 533, + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js b/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js new file mode 100644 index 0000000000000..f7345c1e10c8a --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js @@ -0,0 +1,150 @@ +var moment = require('moment'); + +module.exports = { + 'label': '', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'min': 1411761457636, + 'max': 1411762357636, + 'interval': 30000 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 1411761450000, + 'y': 41 + }, + { + 'x': 1411761480000, + 'y': 18 + }, + { + 'x': 1411761510000, + 'y': -22 + }, + { + 'x': 1411761540000, + 'y': -17 + }, + { + 'x': 1411761570000, + 'y': -17 + }, + { + 'x': 1411761600000, + 'y': -21 + }, + { + 'x': 1411761630000, + 'y': -16 + }, + { + 'x': 1411761660000, + 'y': 17 + }, + { + 'x': 1411761690000, + 'y': 15 + }, + { + 'x': 1411761720000, + 'y': 19 + }, + { + 'x': 1411761750000, + 'y': 11 + }, + { + 'x': 1411761780000, + 'y': -13 + }, + { + 'x': 1411761810000, + 'y': -24 + }, + { + 'x': 1411761840000, + 'y': -20 + }, + { + 'x': 1411761870000, + 'y': -20 + }, + { + 'x': 1411761900000, + 'y': -21 + }, + { + 'x': 1411761930000, + 'y': 17 + }, + { + 'x': 1411761960000, + 'y': 20 + }, + { + 'x': 1411761990000, + 'y': -13 + }, + { + 'x': 1411762020000, + 'y': -14 + }, + { + 'x': 1411762050000, + 'y': 25 + }, + { + 'x': 1411762080000, + 'y': -17 + }, + { + 'x': 1411762110000, + 'y': -14 + }, + { + 'x': 1411762140000, + 'y': -22 + }, + { + 'x': 1411762170000, + 'y': -14 + }, + { + 'x': 1411762200000, + 'y': 19 + }, + { + 'x': 1411762230000, + 'y': 22 + }, + { + 'x': 1411762260000, + 'y': 17 + }, + { + 'x': 1411762290000, + 'y': 8 + }, + { + 'x': 1411762320000, + 'y': -15 + }, + { + 'x': 1411762350000, + 'y': -4 + } + ] + } + ], + 'hits': 533, + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js b/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js new file mode 100644 index 0000000000000..e124703fda690 --- /dev/null +++ b/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js @@ -0,0 +1,1483 @@ +var moment = require('moment'); + +module.exports = { + 'label': '', + 'xAxisLabel': '@timestamp per 10 min', + 'ordered': { + 'date': true, + 'min': 1413544140087, + 'max': 1413587340087, + 'interval': 600000 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'label': 'html', + 'values': [ + { + 'x': 1413543600000, + 'y': 140 + }, + { + 'x': 1413544200000, + 'y': 1388 + }, + { + 'x': 1413544800000, + 'y': 1308 + }, + { + 'x': 1413545400000, + 'y': 1356 + }, + { + 'x': 1413546000000, + 'y': 1314 + }, + { + 'x': 1413546600000, + 'y': 1343 + }, + { + 'x': 1413547200000, + 'y': 1353 + }, + { + 'x': 1413547800000, + 'y': 1353 + }, + { + 'x': 1413548400000, + 'y': 1334 + }, + { + 'x': 1413549000000, + 'y': 1433 + }, + { + 'x': 1413549600000, + 'y': 1331 + }, + { + 'x': 1413550200000, + 'y': 1349 + }, + { + 'x': 1413550800000, + 'y': 1323 + }, + { + 'x': 1413551400000, + 'y': 1203 + }, + { + 'x': 1413552000000, + 'y': 1231 + }, + { + 'x': 1413552600000, + 'y': 1227 + }, + { + 'x': 1413553200000, + 'y': 1187 + }, + { + 'x': 1413553800000, + 'y': 1119 + }, + { + 'x': 1413554400000, + 'y': 1159 + }, + { + 'x': 1413555000000, + 'y': 1117 + }, + { + 'x': 1413555600000, + 'y': 1152 + }, + { + 'x': 1413556200000, + 'y': 1057 + }, + { + 'x': 1413556800000, + 'y': 1009 + }, + { + 'x': 1413557400000, + 'y': 979 + }, + { + 'x': 1413558000000, + 'y': 975 + }, + { + 'x': 1413558600000, + 'y': 848 + }, + { + 'x': 1413559200000, + 'y': 873 + }, + { + 'x': 1413559800000, + 'y': 808 + }, + { + 'x': 1413560400000, + 'y': 784 + }, + { + 'x': 1413561000000, + 'y': 799 + }, + { + 'x': 1413561600000, + 'y': 684 + }, + { + 'x': 1413562200000, + 'y': 727 + }, + { + 'x': 1413562800000, + 'y': 621 + }, + { + 'x': 1413563400000, + 'y': 615 + }, + { + 'x': 1413564000000, + 'y': 569 + }, + { + 'x': 1413564600000, + 'y': 523 + }, + { + 'x': 1413565200000, + 'y': 474 + }, + { + 'x': 1413565800000, + 'y': 470 + }, + { + 'x': 1413566400000, + 'y': 466 + }, + { + 'x': 1413567000000, + 'y': 394 + }, + { + 'x': 1413567600000, + 'y': 404 + }, + { + 'x': 1413568200000, + 'y': 389 + }, + { + 'x': 1413568800000, + 'y': 312 + }, + { + 'x': 1413569400000, + 'y': 274 + }, + { + 'x': 1413570000000, + 'y': 285 + }, + { + 'x': 1413570600000, + 'y': 299 + }, + { + 'x': 1413571200000, + 'y': 207 + }, + { + 'x': 1413571800000, + 'y': 213 + }, + { + 'x': 1413572400000, + 'y': 119 + }, + { + 'x': 1413573600000, + 'y': 122 + }, + { + 'x': 1413574200000, + 'y': 169 + }, + { + 'x': 1413574800000, + 'y': 151 + }, + { + 'x': 1413575400000, + 'y': 152 + }, + { + 'x': 1413576000000, + 'y': 115 + }, + { + 'x': 1413576600000, + 'y': 117 + }, + { + 'x': 1413577200000, + 'y': 108 + }, + { + 'x': 1413577800000, + 'y': 100 + }, + { + 'x': 1413578400000, + 'y': 78 + }, + { + 'x': 1413579000000, + 'y': 88 + }, + { + 'x': 1413579600000, + 'y': 63 + }, + { + 'x': 1413580200000, + 'y': 58 + }, + { + 'x': 1413580800000, + 'y': 45 + }, + { + 'x': 1413581400000, + 'y': 57 + }, + { + 'x': 1413582000000, + 'y': 34 + }, + { + 'x': 1413582600000, + 'y': 41 + }, + { + 'x': 1413583200000, + 'y': 24 + }, + { + 'x': 1413583800000, + 'y': 27 + }, + { + 'x': 1413584400000, + 'y': 19 + }, + { + 'x': 1413585000000, + 'y': 24 + }, + { + 'x': 1413585600000, + 'y': 18 + }, + { + 'x': 1413586200000, + 'y': 17 + }, + { + 'x': 1413586800000, + 'y': 14 + } + ] + }, + { + 'label': 'php', + 'values': [ + { + 'x': 1413543600000, + 'y': 90 + }, + { + 'x': 1413544200000, + 'y': 949 + }, + { + 'x': 1413544800000, + 'y': 1012 + }, + { + 'x': 1413545400000, + 'y': 1027 + }, + { + 'x': 1413546000000, + 'y': 1073 + }, + { + 'x': 1413546600000, + 'y': 992 + }, + { + 'x': 1413547200000, + 'y': 1005 + }, + { + 'x': 1413547800000, + 'y': 1014 + }, + { + 'x': 1413548400000, + 'y': 987 + }, + { + 'x': 1413549000000, + 'y': 982 + }, + { + 'x': 1413549600000, + 'y': 1086 + }, + { + 'x': 1413550200000, + 'y': 998 + }, + { + 'x': 1413550800000, + 'y': 935 + }, + { + 'x': 1413551400000, + 'y': 995 + }, + { + 'x': 1413552000000, + 'y': 926 + }, + { + 'x': 1413552600000, + 'y': 897 + }, + { + 'x': 1413553200000, + 'y': 873 + }, + { + 'x': 1413553800000, + 'y': 885 + }, + { + 'x': 1413554400000, + 'y': 859 + }, + { + 'x': 1413555000000, + 'y': 852 + }, + { + 'x': 1413555600000, + 'y': 779 + }, + { + 'x': 1413556200000, + 'y': 739 + }, + { + 'x': 1413556800000, + 'y': 783 + }, + { + 'x': 1413557400000, + 'y': 784 + }, + { + 'x': 1413558000000, + 'y': 687 + }, + { + 'x': 1413558600000, + 'y': 660 + }, + { + 'x': 1413559200000, + 'y': 672 + }, + { + 'x': 1413559800000, + 'y': 600 + }, + { + 'x': 1413560400000, + 'y': 659 + }, + { + 'x': 1413561000000, + 'y': 540 + }, + { + 'x': 1413561600000, + 'y': 539 + }, + { + 'x': 1413562200000, + 'y': 481 + }, + { + 'x': 1413562800000, + 'y': 498 + }, + { + 'x': 1413563400000, + 'y': 444 + }, + { + 'x': 1413564000000, + 'y': 452 + }, + { + 'x': 1413564600000, + 'y': 408 + }, + { + 'x': 1413565200000, + 'y': 358 + }, + { + 'x': 1413565800000, + 'y': 321 + }, + { + 'x': 1413566400000, + 'y': 305 + }, + { + 'x': 1413567000000, + 'y': 292 + }, + { + 'x': 1413567600000, + 'y': 289 + }, + { + 'x': 1413568200000, + 'y': 239 + }, + { + 'x': 1413568800000, + 'y': 256 + }, + { + 'x': 1413569400000, + 'y': 220 + }, + { + 'x': 1413570000000, + 'y': 205 + }, + { + 'x': 1413570600000, + 'y': 201 + }, + { + 'x': 1413571200000, + 'y': 183 + }, + { + 'x': 1413571800000, + 'y': 172 + }, + { + 'x': 1413572400000, + 'y': 73 + }, + { + 'x': 1413573600000, + 'y': 90 + }, + { + 'x': 1413574200000, + 'y': 130 + }, + { + 'x': 1413574800000, + 'y': 104 + }, + { + 'x': 1413575400000, + 'y': 108 + }, + { + 'x': 1413576000000, + 'y': 92 + }, + { + 'x': 1413576600000, + 'y': 79 + }, + { + 'x': 1413577200000, + 'y': 90 + }, + { + 'x': 1413577800000, + 'y': 72 + }, + { + 'x': 1413578400000, + 'y': 68 + }, + { + 'x': 1413579000000, + 'y': 52 + }, + { + 'x': 1413579600000, + 'y': 60 + }, + { + 'x': 1413580200000, + 'y': 51 + }, + { + 'x': 1413580800000, + 'y': 32 + }, + { + 'x': 1413581400000, + 'y': 37 + }, + { + 'x': 1413582000000, + 'y': 30 + }, + { + 'x': 1413582600000, + 'y': 29 + }, + { + 'x': 1413583200000, + 'y': 24 + }, + { + 'x': 1413583800000, + 'y': 16 + }, + { + 'x': 1413584400000, + 'y': 15 + }, + { + 'x': 1413585000000, + 'y': 15 + }, + { + 'x': 1413585600000, + 'y': 10 + }, + { + 'x': 1413586200000, + 'y': 9 + }, + { + 'x': 1413586800000, + 'y': 9 + } + ] + }, + { + 'label': 'png', + 'values': [ + { + 'x': 1413543600000, + 'y': 44 + }, + { + 'x': 1413544200000, + 'y': 495 + }, + { + 'x': 1413544800000, + 'y': 489 + }, + { + 'x': 1413545400000, + 'y': 492 + }, + { + 'x': 1413546000000, + 'y': 556 + }, + { + 'x': 1413546600000, + 'y': 536 + }, + { + 'x': 1413547200000, + 'y': 511 + }, + { + 'x': 1413547800000, + 'y': 479 + }, + { + 'x': 1413548400000, + 'y': 544 + }, + { + 'x': 1413549000000, + 'y': 513 + }, + { + 'x': 1413549600000, + 'y': 501 + }, + { + 'x': 1413550200000, + 'y': 532 + }, + { + 'x': 1413550800000, + 'y': 440 + }, + { + 'x': 1413551400000, + 'y': 455 + }, + { + 'x': 1413552000000, + 'y': 455 + }, + { + 'x': 1413552600000, + 'y': 471 + }, + { + 'x': 1413553200000, + 'y': 428 + }, + { + 'x': 1413553800000, + 'y': 457 + }, + { + 'x': 1413554400000, + 'y': 450 + }, + { + 'x': 1413555000000, + 'y': 418 + }, + { + 'x': 1413555600000, + 'y': 398 + }, + { + 'x': 1413556200000, + 'y': 397 + }, + { + 'x': 1413556800000, + 'y': 359 + }, + { + 'x': 1413557400000, + 'y': 398 + }, + { + 'x': 1413558000000, + 'y': 339 + }, + { + 'x': 1413558600000, + 'y': 363 + }, + { + 'x': 1413559200000, + 'y': 297 + }, + { + 'x': 1413559800000, + 'y': 323 + }, + { + 'x': 1413560400000, + 'y': 302 + }, + { + 'x': 1413561000000, + 'y': 260 + }, + { + 'x': 1413561600000, + 'y': 276 + }, + { + 'x': 1413562200000, + 'y': 249 + }, + { + 'x': 1413562800000, + 'y': 248 + }, + { + 'x': 1413563400000, + 'y': 235 + }, + { + 'x': 1413564000000, + 'y': 234 + }, + { + 'x': 1413564600000, + 'y': 188 + }, + { + 'x': 1413565200000, + 'y': 192 + }, + { + 'x': 1413565800000, + 'y': 173 + }, + { + 'x': 1413566400000, + 'y': 160 + }, + { + 'x': 1413567000000, + 'y': 137 + }, + { + 'x': 1413567600000, + 'y': 158 + }, + { + 'x': 1413568200000, + 'y': 111 + }, + { + 'x': 1413568800000, + 'y': 145 + }, + { + 'x': 1413569400000, + 'y': 118 + }, + { + 'x': 1413570000000, + 'y': 104 + }, + { + 'x': 1413570600000, + 'y': 80 + }, + { + 'x': 1413571200000, + 'y': 79 + }, + { + 'x': 1413571800000, + 'y': 86 + }, + { + 'x': 1413572400000, + 'y': 47 + }, + { + 'x': 1413573600000, + 'y': 49 + }, + { + 'x': 1413574200000, + 'y': 68 + }, + { + 'x': 1413574800000, + 'y': 78 + }, + { + 'x': 1413575400000, + 'y': 77 + }, + { + 'x': 1413576000000, + 'y': 50 + }, + { + 'x': 1413576600000, + 'y': 51 + }, + { + 'x': 1413577200000, + 'y': 40 + }, + { + 'x': 1413577800000, + 'y': 42 + }, + { + 'x': 1413578400000, + 'y': 29 + }, + { + 'x': 1413579000000, + 'y': 24 + }, + { + 'x': 1413579600000, + 'y': 30 + }, + { + 'x': 1413580200000, + 'y': 18 + }, + { + 'x': 1413580800000, + 'y': 15 + }, + { + 'x': 1413581400000, + 'y': 19 + }, + { + 'x': 1413582000000, + 'y': 18 + }, + { + 'x': 1413582600000, + 'y': 13 + }, + { + 'x': 1413583200000, + 'y': 11 + }, + { + 'x': 1413583800000, + 'y': 11 + }, + { + 'x': 1413584400000, + 'y': 13 + }, + { + 'x': 1413585000000, + 'y': 9 + }, + { + 'x': 1413585600000, + 'y': 9 + }, + { + 'x': 1413586200000, + 'y': 9 + }, + { + 'x': 1413586800000, + 'y': 3 + } + ] + }, + { + 'label': 'css', + 'values': [ + { + 'x': 1413543600000, + 'y': 35 + }, + { + 'x': 1413544200000, + 'y': 360 + }, + { + 'x': 1413544800000, + 'y': 343 + }, + { + 'x': 1413545400000, + 'y': 329 + }, + { + 'x': 1413546000000, + 'y': 345 + }, + { + 'x': 1413546600000, + 'y': 336 + }, + { + 'x': 1413547200000, + 'y': 330 + }, + { + 'x': 1413547800000, + 'y': 334 + }, + { + 'x': 1413548400000, + 'y': 326 + }, + { + 'x': 1413549000000, + 'y': 351 + }, + { + 'x': 1413549600000, + 'y': 334 + }, + { + 'x': 1413550200000, + 'y': 351 + }, + { + 'x': 1413550800000, + 'y': 337 + }, + { + 'x': 1413551400000, + 'y': 306 + }, + { + 'x': 1413552000000, + 'y': 346 + }, + { + 'x': 1413552600000, + 'y': 317 + }, + { + 'x': 1413553200000, + 'y': 298 + }, + { + 'x': 1413553800000, + 'y': 288 + }, + { + 'x': 1413554400000, + 'y': 283 + }, + { + 'x': 1413555000000, + 'y': 262 + }, + { + 'x': 1413555600000, + 'y': 245 + }, + { + 'x': 1413556200000, + 'y': 259 + }, + { + 'x': 1413556800000, + 'y': 267 + }, + { + 'x': 1413557400000, + 'y': 230 + }, + { + 'x': 1413558000000, + 'y': 218 + }, + { + 'x': 1413558600000, + 'y': 241 + }, + { + 'x': 1413559200000, + 'y': 213 + }, + { + 'x': 1413559800000, + 'y': 239 + }, + { + 'x': 1413560400000, + 'y': 208 + }, + { + 'x': 1413561000000, + 'y': 187 + }, + { + 'x': 1413561600000, + 'y': 166 + }, + { + 'x': 1413562200000, + 'y': 154 + }, + { + 'x': 1413562800000, + 'y': 184 + }, + { + 'x': 1413563400000, + 'y': 148 + }, + { + 'x': 1413564000000, + 'y': 153 + }, + { + 'x': 1413564600000, + 'y': 149 + }, + { + 'x': 1413565200000, + 'y': 102 + }, + { + 'x': 1413565800000, + 'y': 110 + }, + { + 'x': 1413566400000, + 'y': 121 + }, + { + 'x': 1413567000000, + 'y': 120 + }, + { + 'x': 1413567600000, + 'y': 86 + }, + { + 'x': 1413568200000, + 'y': 96 + }, + { + 'x': 1413568800000, + 'y': 71 + }, + { + 'x': 1413569400000, + 'y': 92 + }, + { + 'x': 1413570000000, + 'y': 65 + }, + { + 'x': 1413570600000, + 'y': 54 + }, + { + 'x': 1413571200000, + 'y': 68 + }, + { + 'x': 1413571800000, + 'y': 57 + }, + { + 'x': 1413572400000, + 'y': 33 + }, + { + 'x': 1413573600000, + 'y': 47 + }, + { + 'x': 1413574200000, + 'y': 42 + }, + { + 'x': 1413574800000, + 'y': 39 + }, + { + 'x': 1413575400000, + 'y': 25 + }, + { + 'x': 1413576000000, + 'y': 31 + }, + { + 'x': 1413576600000, + 'y': 37 + }, + { + 'x': 1413577200000, + 'y': 35 + }, + { + 'x': 1413577800000, + 'y': 19 + }, + { + 'x': 1413578400000, + 'y': 15 + }, + { + 'x': 1413579000000, + 'y': 21 + }, + { + 'x': 1413579600000, + 'y': 16 + }, + { + 'x': 1413580200000, + 'y': 18 + }, + { + 'x': 1413580800000, + 'y': 10 + }, + { + 'x': 1413581400000, + 'y': 13 + }, + { + 'x': 1413582000000, + 'y': 14 + }, + { + 'x': 1413582600000, + 'y': 11 + }, + { + 'x': 1413583200000, + 'y': 4 + }, + { + 'x': 1413583800000, + 'y': 6 + }, + { + 'x': 1413584400000, + 'y': 3 + }, + { + 'x': 1413585000000, + 'y': 6 + }, + { + 'x': 1413585600000, + 'y': 6 + }, + { + 'x': 1413586200000, + 'y': 2 + }, + { + 'x': 1413586800000, + 'y': 3 + } + ] + }, + { + 'label': 'gif', + 'values': [ + { + 'x': 1413543600000, + 'y': 21 + }, + { + 'x': 1413544200000, + 'y': 191 + }, + { + 'x': 1413544800000, + 'y': 176 + }, + { + 'x': 1413545400000, + 'y': 166 + }, + { + 'x': 1413546000000, + 'y': 183 + }, + { + 'x': 1413546600000, + 'y': 170 + }, + { + 'x': 1413547200000, + 'y': 153 + }, + { + 'x': 1413547800000, + 'y': 202 + }, + { + 'x': 1413548400000, + 'y': 175 + }, + { + 'x': 1413549000000, + 'y': 161 + }, + { + 'x': 1413549600000, + 'y': 174 + }, + { + 'x': 1413550200000, + 'y': 167 + }, + { + 'x': 1413550800000, + 'y': 171 + }, + { + 'x': 1413551400000, + 'y': 176 + }, + { + 'x': 1413552000000, + 'y': 139 + }, + { + 'x': 1413552600000, + 'y': 145 + }, + { + 'x': 1413553200000, + 'y': 157 + }, + { + 'x': 1413553800000, + 'y': 148 + }, + { + 'x': 1413554400000, + 'y': 149 + }, + { + 'x': 1413555000000, + 'y': 135 + }, + { + 'x': 1413555600000, + 'y': 118 + }, + { + 'x': 1413556200000, + 'y': 142 + }, + { + 'x': 1413556800000, + 'y': 141 + }, + { + 'x': 1413557400000, + 'y': 146 + }, + { + 'x': 1413558000000, + 'y': 114 + }, + { + 'x': 1413558600000, + 'y': 115 + }, + { + 'x': 1413559200000, + 'y': 136 + }, + { + 'x': 1413559800000, + 'y': 106 + }, + { + 'x': 1413560400000, + 'y': 92 + }, + { + 'x': 1413561000000, + 'y': 97 + }, + { + 'x': 1413561600000, + 'y': 90 + }, + { + 'x': 1413562200000, + 'y': 69 + }, + { + 'x': 1413562800000, + 'y': 66 + }, + { + 'x': 1413563400000, + 'y': 93 + }, + { + 'x': 1413564000000, + 'y': 75 + }, + { + 'x': 1413564600000, + 'y': 68 + }, + { + 'x': 1413565200000, + 'y': 55 + }, + { + 'x': 1413565800000, + 'y': 73 + }, + { + 'x': 1413566400000, + 'y': 57 + }, + { + 'x': 1413567000000, + 'y': 48 + }, + { + 'x': 1413567600000, + 'y': 41 + }, + { + 'x': 1413568200000, + 'y': 39 + }, + { + 'x': 1413568800000, + 'y': 32 + }, + { + 'x': 1413569400000, + 'y': 33 + }, + { + 'x': 1413570000000, + 'y': 39 + }, + { + 'x': 1413570600000, + 'y': 35 + }, + { + 'x': 1413571200000, + 'y': 25 + }, + { + 'x': 1413571800000, + 'y': 28 + }, + { + 'x': 1413572400000, + 'y': 8 + }, + { + 'x': 1413573600000, + 'y': 13 + }, + { + 'x': 1413574200000, + 'y': 23 + }, + { + 'x': 1413574800000, + 'y': 19 + }, + { + 'x': 1413575400000, + 'y': 16 + }, + { + 'x': 1413576000000, + 'y': 22 + }, + { + 'x': 1413576600000, + 'y': 13 + }, + { + 'x': 1413577200000, + 'y': 21 + }, + { + 'x': 1413577800000, + 'y': 11 + }, + { + 'x': 1413578400000, + 'y': 12 + }, + { + 'x': 1413579000000, + 'y': 10 + }, + { + 'x': 1413579600000, + 'y': 7 + }, + { + 'x': 1413580200000, + 'y': 4 + }, + { + 'x': 1413580800000, + 'y': 5 + }, + { + 'x': 1413581400000, + 'y': 7 + }, + { + 'x': 1413582000000, + 'y': 9 + }, + { + 'x': 1413582600000, + 'y': 2 + }, + { + 'x': 1413583200000, + 'y': 2 + }, + { + 'x': 1413583800000, + 'y': 4 + }, + { + 'x': 1413584400000, + 'y': 6 + }, + { + 'x': 1413585600000, + 'y': 2 + }, + { + 'x': 1413586200000, + 'y': 4 + }, + { + 'x': 1413586800000, + 'y': 4 + } + ] + } + ], + 'hits': 108970, + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/filters/_columns.js b/src/fixtures/vislib/mock_data/filters/_columns.js new file mode 100644 index 0000000000000..ea5ab1b097070 --- /dev/null +++ b/src/fixtures/vislib/mock_data/filters/_columns.js @@ -0,0 +1,106 @@ +var _ = require('lodash'); + +module.exports = { + 'columns': [ + { + 'label': 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1: agent.raw', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 10379 + }, + { + 'x': 'png', + 'y': 6395 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24: agent.raw', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 9253 + }, + { + 'x': 'png', + 'y': 5571 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322): agent.raw', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 7740 + }, + { + 'x': 'png', + 'y': 4697 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171443 +}; diff --git a/src/fixtures/vislib/mock_data/filters/_rows.js b/src/fixtures/vislib/mock_data/filters/_rows.js new file mode 100644 index 0000000000000..d3c27ed491b50 --- /dev/null +++ b/src/fixtures/vislib/mock_data/filters/_rows.js @@ -0,0 +1,106 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'label': '200: response', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 25260 + }, + { + 'x': 'png', + 'y': 15311 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '404: response', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 1352 + }, + { + 'x': 'png', + 'y': 826 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '503: response', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 761 + }, + { + 'x': 'png', + 'y': 527 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171443 +}; diff --git a/src/fixtures/vislib/mock_data/filters/_series.js b/src/fixtures/vislib/mock_data/filters/_series.js new file mode 100644 index 0000000000000..46cdbbc3794a4 --- /dev/null +++ b/src/fixtures/vislib/mock_data/filters/_series.js @@ -0,0 +1,40 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': 'filters', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'css', + 'y': 27374 + }, + { + 'x': 'html', + 'y': 0 + }, + { + 'x': 'png', + 'y': 16663 + } + ] + } + ], + 'hits': 171454, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/geohash/_columns.js b/src/fixtures/vislib/mock_data/geohash/_columns.js new file mode 100644 index 0000000000000..2f39a449c9551 --- /dev/null +++ b/src/fixtures/vislib/mock_data/geohash/_columns.js @@ -0,0 +1,3744 @@ +var _ = require('lodash'); +module.exports = { + 'columns': [ + { + 'title': 'Top 2 geo.dest: CN', + 'valueFormatter': _.identity, + 'geoJson': { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 22.5 + ] + }, + 'properties': { + 'value': 42, + 'geohash': 's', + 'center': [ + 22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 's', + 'value': 's', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 42, + 'value': 42, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 0 + ], + [ + 45, + 0 + ], + [ + 45, + 45 + ], + [ + 0, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 22.5 + ] + }, + 'properties': { + 'value': 31, + 'geohash': 'd', + 'center': [ + -67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'd', + 'value': 'd', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 31, + 'value': 31, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 0 + ], + [ + -45, + 0 + ], + [ + -45, + 45 + ], + [ + -90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 22.5 + ] + }, + 'properties': { + 'value': 30, + 'geohash': 'w', + 'center': [ + 112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'w', + 'value': 'w', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 30, + 'value': 30, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 0 + ], + [ + 135, + 0 + ], + [ + 135, + 45 + ], + [ + 90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 22.5 + ] + }, + 'properties': { + 'value': 25, + 'geohash': '9', + 'center': [ + -112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '9', + 'value': '9', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 25, + 'value': 25, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 0 + ], + [ + -90, + 0 + ], + [ + -90, + 45 + ], + [ + -135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 22.5 + ] + }, + 'properties': { + 'value': 22, + 'geohash': 't', + 'center': [ + 67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 't', + 'value': 't', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 22, + 'value': 22, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 0 + ], + [ + 90, + 0 + ], + [ + 90, + 45 + ], + [ + 45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -22.5 + ] + }, + 'properties': { + 'value': 22, + 'geohash': 'k', + 'center': [ + 22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'k', + 'value': 'k', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 22, + 'value': 22, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -45 + ], + [ + 45, + -45 + ], + [ + 45, + 0 + ], + [ + 0, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -22.5 + ] + }, + 'properties': { + 'value': 21, + 'geohash': '6', + 'center': [ + -67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '6', + 'value': '6', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 21, + 'value': 21, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -45 + ], + [ + -45, + -45 + ], + [ + -45, + 0 + ], + [ + -90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 67.5 + ] + }, + 'properties': { + 'value': 19, + 'geohash': 'u', + 'center': [ + 22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'u', + 'value': 'u', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 19, + 'value': 19, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 45 + ], + [ + 45, + 45 + ], + [ + 45, + 90 + ], + [ + 0, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 67.5 + ] + }, + 'properties': { + 'value': 18, + 'geohash': 'v', + 'center': [ + 67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'v', + 'value': 'v', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 18, + 'value': 18, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 45 + ], + [ + 90, + 45 + ], + [ + 90, + 90 + ], + [ + 45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 67.5 + ] + }, + 'properties': { + 'value': 11, + 'geohash': 'c', + 'center': [ + -112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'c', + 'value': 'c', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 11, + 'value': 11, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 45 + ], + [ + -90, + 45 + ], + [ + -90, + 90 + ], + [ + -135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -22.5 + ] + }, + 'properties': { + 'value': 10, + 'geohash': 'r', + 'center': [ + 157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'r', + 'value': 'r', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 10, + 'value': 10, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -45 + ], + [ + 180, + -45 + ], + [ + 180, + 0 + ], + [ + 135, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 67.5 + ] + }, + 'properties': { + 'value': 9, + 'geohash': 'y', + 'center': [ + 112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'y', + 'value': 'y', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 9, + 'value': 9, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 45 + ], + [ + 135, + 45 + ], + [ + 135, + 90 + ], + [ + 90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 22.5 + ] + }, + 'properties': { + 'value': 9, + 'geohash': 'e', + 'center': [ + -22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'e', + 'value': 'e', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 9, + 'value': 9, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + 45 + ], + [ + -45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 67.5 + ] + }, + 'properties': { + 'value': 8, + 'geohash': 'f', + 'center': [ + -67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'f', + 'value': 'f', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 8, + 'value': 8, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 45 + ], + [ + -45, + 45 + ], + [ + -45, + 90 + ], + [ + -90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -22.5 + ] + }, + 'properties': { + 'value': 8, + 'geohash': '7', + 'center': [ + -22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '7', + 'value': '7', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 8, + 'value': 8, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -45 + ], + [ + 0, + -45 + ], + [ + 0, + 0 + ], + [ + -45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -22.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'q', + 'center': [ + 112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'q', + 'value': 'q', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + -45 + ], + [ + 135, + -45 + ], + [ + 135, + 0 + ], + [ + 90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'g', + 'center': [ + -22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'g', + 'value': 'g', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 45 + ], + [ + 0, + 45 + ], + [ + 0, + 90 + ], + [ + -45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 22.5 + ] + }, + 'properties': { + 'value': 4, + 'geohash': 'x', + 'center': [ + 157.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'x', + 'value': 'x', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 4, + 'value': 4, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 0 + ], + [ + 180, + 0 + ], + [ + 180, + 45 + ], + [ + 135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + 67.5 + ] + }, + 'properties': { + 'value': 3, + 'geohash': 'b', + 'center': [ + -157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'b', + 'value': 'b', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 3, + 'value': 3, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -180, + 45 + ], + [ + -135, + 45 + ], + [ + -135, + 90 + ], + [ + -180, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': 'z', + 'center': [ + 157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'z', + 'value': 'z', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 45 + ], + [ + 180, + 45 + ], + [ + 180, + 90 + ], + [ + 135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'm', + 'center': [ + 67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'm', + 'value': 'm', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -45 + ], + [ + 90, + -45 + ], + [ + 90, + 0 + ], + [ + 45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '5', + 'center': [ + -22.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '5', + 'value': '5', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -90 + ], + [ + 0, + -90 + ], + [ + 0, + -45 + ], + [ + -45, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '4', + 'center': [ + -67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '4', + 'value': '4', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -90 + ], + [ + -45, + -90 + ], + [ + -45, + -45 + ], + [ + -90, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '3', + 'center': [ + -112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '3', + 'value': '3', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + -45 + ], + [ + -90, + -45 + ], + [ + -90, + 0 + ], + [ + -135, + 0 + ] + ] + } + } + ], + 'properties': { + 'min': 1, + 'max': 42 + } + } + }, + { + 'label': 'Top 2 geo.dest: IN', + 'valueFormatter': _.identity, + 'geoJson': { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 22.5 + ] + }, + 'properties': { + 'value': 32, + 'geohash': 's', + 'center': [ + 22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 's', + 'value': 's', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 32, + 'value': 32, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 0 + ], + [ + 45, + 0 + ], + [ + 45, + 45 + ], + [ + 0, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -22.5 + ] + }, + 'properties': { + 'value': 31, + 'geohash': '6', + 'center': [ + -67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '6', + 'value': '6', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 31, + 'value': 31, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -45 + ], + [ + -45, + -45 + ], + [ + -45, + 0 + ], + [ + -90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 22.5 + ] + }, + 'properties': { + 'value': 28, + 'geohash': 'd', + 'center': [ + -67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'd', + 'value': 'd', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 28, + 'value': 28, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 0 + ], + [ + -45, + 0 + ], + [ + -45, + 45 + ], + [ + -90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 22.5 + ] + }, + 'properties': { + 'value': 27, + 'geohash': 'w', + 'center': [ + 112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'w', + 'value': 'w', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 27, + 'value': 27, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 0 + ], + [ + 135, + 0 + ], + [ + 135, + 45 + ], + [ + 90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 22.5 + ] + }, + 'properties': { + 'value': 24, + 'geohash': 't', + 'center': [ + 67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 't', + 'value': 't', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 24, + 'value': 24, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 0 + ], + [ + 90, + 0 + ], + [ + 90, + 45 + ], + [ + 45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -22.5 + ] + }, + 'properties': { + 'value': 23, + 'geohash': 'k', + 'center': [ + 22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'k', + 'value': 'k', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 23, + 'value': 23, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -45 + ], + [ + 45, + -45 + ], + [ + 45, + 0 + ], + [ + 0, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 67.5 + ] + }, + 'properties': { + 'value': 17, + 'geohash': 'u', + 'center': [ + 22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'u', + 'value': 'u', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 17, + 'value': 17, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 45 + ], + [ + 45, + 45 + ], + [ + 45, + 90 + ], + [ + 0, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 22.5 + ] + }, + 'properties': { + 'value': 16, + 'geohash': '9', + 'center': [ + -112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '9', + 'value': '9', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 16, + 'value': 16, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 0 + ], + [ + -90, + 0 + ], + [ + -90, + 45 + ], + [ + -135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 67.5 + ] + }, + 'properties': { + 'value': 14, + 'geohash': 'v', + 'center': [ + 67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'v', + 'value': 'v', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 14, + 'value': 14, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 45 + ], + [ + 90, + 45 + ], + [ + 90, + 90 + ], + [ + 45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 22.5 + ] + }, + 'properties': { + 'value': 13, + 'geohash': 'e', + 'center': [ + -22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'e', + 'value': 'e', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 13, + 'value': 13, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + 45 + ], + [ + -45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -22.5 + ] + }, + 'properties': { + 'value': 9, + 'geohash': 'r', + 'center': [ + 157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'r', + 'value': 'r', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 9, + 'value': 9, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -45 + ], + [ + 180, + -45 + ], + [ + 180, + 0 + ], + [ + 135, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'y', + 'center': [ + 112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'y', + 'value': 'y', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 45 + ], + [ + 135, + 45 + ], + [ + 135, + 90 + ], + [ + 90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'g', + 'center': [ + -22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'g', + 'value': 'g', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 45 + ], + [ + 0, + 45 + ], + [ + 0, + 90 + ], + [ + -45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'f', + 'center': [ + -67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'f', + 'value': 'f', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 45 + ], + [ + -45, + 45 + ], + [ + -45, + 90 + ], + [ + -90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 67.5 + ] + }, + 'properties': { + 'value': 5, + 'geohash': 'c', + 'center': [ + -112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'c', + 'value': 'c', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 5, + 'value': 5, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 45 + ], + [ + -90, + 45 + ], + [ + -90, + 90 + ], + [ + -135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + 67.5 + ] + }, + 'properties': { + 'value': 4, + 'geohash': 'b', + 'center': [ + -157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'b', + 'value': 'b', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 4, + 'value': 4, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -180, + 45 + ], + [ + -135, + 45 + ], + [ + -135, + 90 + ], + [ + -180, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -22.5 + ] + }, + 'properties': { + 'value': 3, + 'geohash': 'q', + 'center': [ + 112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'q', + 'value': 'q', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 3, + 'value': 3, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + -45 + ], + [ + 135, + -45 + ], + [ + 135, + 0 + ], + [ + 90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': '4', + 'center': [ + -67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '4', + 'value': '4', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -90 + ], + [ + -45, + -90 + ], + [ + -45, + -45 + ], + [ + -90, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'z', + 'center': [ + 157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'z', + 'value': 'z', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 45 + ], + [ + 180, + 45 + ], + [ + 180, + 90 + ], + [ + 135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'x', + 'center': [ + 157.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'x', + 'value': 'x', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 0 + ], + [ + 180, + 0 + ], + [ + 180, + 45 + ], + [ + 135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'p', + 'center': [ + 157.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'p', + 'value': 'p', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -90 + ], + [ + 180, + -90 + ], + [ + 180, + -45 + ], + [ + 135, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'm', + 'center': [ + 67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': 'm', + 'value': 'm', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -45 + ], + [ + 90, + -45 + ], + [ + 90, + 0 + ], + [ + 45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '7', + 'center': [ + -22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': false + } + }, + 'type': 'bucket' + }, + 'key': '7', + 'value': '7', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -45 + ], + [ + 0, + -45 + ], + [ + 0, + 0 + ], + [ + -45, + 0 + ] + ] + } + } + ], + 'properties': { + 'min': 1, + 'max': 32 + } + } + } + ] +}; diff --git a/src/fixtures/vislib/mock_data/geohash/_geo_json.js b/src/fixtures/vislib/mock_data/geohash/_geo_json.js new file mode 100644 index 0000000000000..ac84284a1a78a --- /dev/null +++ b/src/fixtures/vislib/mock_data/geohash/_geo_json.js @@ -0,0 +1,1846 @@ +var _ = require('lodash'); + +module.exports = { + 'valueFormatter': _.identity, + 'geoJson': { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 22.5 + ] + }, + 'properties': { + 'value': 608, + 'geohash': 's', + 'center': [ + 22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 's', + 'value': 's', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 608, + 'value': 608, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 0 + ], + [ + 0, + 45 + ], + [ + 45, + 45 + ], + [ + 45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 22.5 + ] + }, + 'properties': { + 'value': 522, + 'geohash': 'w', + 'center': [ + 112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'w', + 'value': 'w', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 522, + 'value': 522, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 90 + ], + [ + 0, + 135 + ], + [ + 45, + 135 + ], + [ + 45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -22.5 + ] + }, + 'properties': { + 'value': 517, + 'geohash': '6', + 'center': [ + -67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '6', + 'value': '6', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 517, + 'value': 517, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -90 + ], + [ + -45, + -45 + ], + [ + 0, + -45 + ], + [ + 0, + -90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 22.5 + ] + }, + 'properties': { + 'value': 446, + 'geohash': 'd', + 'center': [ + -67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'd', + 'value': 'd', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 446, + 'value': 446, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -90 + ], + [ + 0, + -45 + ], + [ + 45, + -45 + ], + [ + 45, + -90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 67.5 + ] + }, + 'properties': { + 'value': 426, + 'geohash': 'u', + 'center': [ + 22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'u', + 'value': 'u', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 426, + 'value': 426, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 0 + ], + [ + 45, + 45 + ], + [ + 90, + 45 + ], + [ + 90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 22.5 + ] + }, + 'properties': { + 'value': 413, + 'geohash': 't', + 'center': [ + 67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 't', + 'value': 't', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 413, + 'value': 413, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 45 + ], + [ + 0, + 90 + ], + [ + 45, + 90 + ], + [ + 45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -22.5 + ] + }, + 'properties': { + 'value': 362, + 'geohash': 'k', + 'center': [ + 22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'k', + 'value': 'k', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 362, + 'value': 362, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 0 + ], + [ + -45, + 45 + ], + [ + 0, + 45 + ], + [ + 0, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 22.5 + ] + }, + 'properties': { + 'value': 352, + 'geohash': '9', + 'center': [ + -112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '9', + 'value': '9', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 352, + 'value': 352, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -135 + ], + [ + 0, + -90 + ], + [ + 45, + -90 + ], + [ + 45, + -135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 22.5 + ] + }, + 'properties': { + 'value': 216, + 'geohash': 'e', + 'center': [ + -22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'e', + 'value': 'e', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 216, + 'value': 216, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -45 + ], + [ + 0, + 0 + ], + [ + 45, + 0 + ], + [ + 45, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 67.5 + ] + }, + 'properties': { + 'value': 183, + 'geohash': 'v', + 'center': [ + 67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'v', + 'value': 'v', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 183, + 'value': 183, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 45 + ], + [ + 45, + 90 + ], + [ + 90, + 90 + ], + [ + 90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -22.5 + ] + }, + 'properties': { + 'value': 158, + 'geohash': 'r', + 'center': [ + 157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'r', + 'value': 'r', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 158, + 'value': 158, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 135 + ], + [ + -45, + 180 + ], + [ + 0, + 180 + ], + [ + 0, + 135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 67.5 + ] + }, + 'properties': { + 'value': 139, + 'geohash': 'y', + 'center': [ + 112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'y', + 'value': 'y', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 139, + 'value': 139, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 90 + ], + [ + 45, + 135 + ], + [ + 90, + 135 + ], + [ + 90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 67.5 + ] + }, + 'properties': { + 'value': 110, + 'geohash': 'c', + 'center': [ + -112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'c', + 'value': 'c', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 110, + 'value': 110, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -135 + ], + [ + 45, + -90 + ], + [ + 90, + -90 + ], + [ + 90, + -135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -22.5 + ] + }, + 'properties': { + 'value': 101, + 'geohash': 'q', + 'center': [ + 112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'q', + 'value': 'q', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 101, + 'value': 101, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 90 + ], + [ + -45, + 135 + ], + [ + 0, + 135 + ], + [ + 0, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -22.5 + ] + }, + 'properties': { + 'value': 101, + 'geohash': '7', + 'center': [ + -22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '7', + 'value': '7', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 101, + 'value': 101, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -45 + ], + [ + -45, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 67.5 + ] + }, + 'properties': { + 'value': 92, + 'geohash': 'f', + 'center': [ + -67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'f', + 'value': 'f', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 92, + 'value': 92, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -90 + ], + [ + 45, + -45 + ], + [ + 90, + -45 + ], + [ + 90, + -90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + 67.5 + ] + }, + 'properties': { + 'value': 75, + 'geohash': 'b', + 'center': [ + -157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'b', + 'value': 'b', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 75, + 'value': 75, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -180 + ], + [ + 45, + -135 + ], + [ + 90, + -135 + ], + [ + 90, + -180 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 67.5 + ] + }, + 'properties': { + 'value': 64, + 'geohash': 'g', + 'center': [ + -22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'g', + 'value': 'g', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 64, + 'value': 64, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -45 + ], + [ + 45, + 0 + ], + [ + 90, + 0 + ], + [ + 90, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 67.5 + ] + }, + 'properties': { + 'value': 36, + 'geohash': 'z', + 'center': [ + 157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'z', + 'value': 'z', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 36, + 'value': 36, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 135 + ], + [ + 45, + 180 + ], + [ + 90, + 180 + ], + [ + 90, + 135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 22.5 + ] + }, + 'properties': { + 'value': 34, + 'geohash': 'x', + 'center': [ + 157.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'x', + 'value': 'x', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 34, + 'value': 34, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 135 + ], + [ + 0, + 180 + ], + [ + 45, + 180 + ], + [ + 45, + 135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -67.5 + ] + }, + 'properties': { + 'value': 30, + 'geohash': '4', + 'center': [ + -67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '4', + 'value': '4', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 30, + 'value': 30, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -90 + ], + [ + -90, + -45 + ], + [ + -45, + -45 + ], + [ + -45, + -90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + -22.5 + ] + }, + 'properties': { + 'value': 16, + 'geohash': 'm', + 'center': [ + 67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'm', + 'value': 'm', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 16, + 'value': 16, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 45 + ], + [ + -45, + 90 + ], + [ + 0, + 90 + ], + [ + 0, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -67.5 + ] + }, + 'properties': { + 'value': 10, + 'geohash': '5', + 'center': [ + -22.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '5', + 'value': '5', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 10, + 'value': 10, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -45 + ], + [ + -90, + 0 + ], + [ + -45, + 0 + ], + [ + -45, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'p', + 'center': [ + 157.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'p', + 'value': 'p', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 135 + ], + [ + -90, + 180 + ], + [ + -45, + 180 + ], + [ + -45, + 135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + -22.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': '2', + 'center': [ + -157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '2', + 'value': '2', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -180 + ], + [ + -45, + -135 + ], + [ + 0, + -135 + ], + [ + 0, + -180 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -67.5 + ] + }, + 'properties': { + 'value': 4, + 'geohash': 'h', + 'center': [ + 22.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'h', + 'value': 'h', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 4, + 'value': 4, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 0 + ], + [ + -90, + 45 + ], + [ + -45, + 45 + ], + [ + -45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': 'n', + 'center': [ + 112.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'n', + 'value': 'n', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 90 + ], + [ + -90, + 135 + ], + [ + -45, + 135 + ], + [ + -45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + -67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': 'j', + 'center': [ + 67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': 'j', + 'value': 'j', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 45 + ], + [ + -90, + 90 + ], + [ + -45, + 90 + ], + [ + -45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '3', + 'center': [ + -112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '3', + 'value': '3', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -135 + ], + [ + -45, + -90 + ], + [ + 0, + -90 + ], + [ + 0, + -135 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '1', + 'center': [ + -112.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + 'key': '1', + 'value': '1', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -135 + ], + [ + -90, + -90 + ], + [ + -45, + -90 + ], + [ + -45, + -135 + ] + ] + } + } + ], + 'properties': { + 'min': 1, + 'max': 608, + 'zoom': 2, + 'center': [5, 15] + } + }, +}; diff --git a/src/fixtures/vislib/mock_data/geohash/_rows.js b/src/fixtures/vislib/mock_data/geohash/_rows.js new file mode 100644 index 0000000000000..e0e1e6e7560c1 --- /dev/null +++ b/src/fixtures/vislib/mock_data/geohash/_rows.js @@ -0,0 +1,3667 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'title': 'Top 2 geo.dest: CN', + 'valueFormatter': _.identity, + 'geoJson': { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 22.5 + ] + }, + 'properties': { + 'value': 39, + 'geohash': 's', + 'center': [ + 22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 's', + 'value': 's', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 39, + 'value': 39, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 0 + ], + [ + 45, + 0 + ], + [ + 45, + 45 + ], + [ + 0, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 22.5 + ] + }, + 'properties': { + 'value': 31, + 'geohash': 'w', + 'center': [ + 112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'w', + 'value': 'w', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 31, + 'value': 31, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 0 + ], + [ + 135, + 0 + ], + [ + 135, + 45 + ], + [ + 90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 22.5 + ] + }, + 'properties': { + 'value': 30, + 'geohash': 'd', + 'center': [ + -67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'd', + 'value': 'd', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 30, + 'value': 30, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 0 + ], + [ + -45, + 0 + ], + [ + -45, + 45 + ], + [ + -90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 22.5 + ] + }, + 'properties': { + 'value': 25, + 'geohash': '9', + 'center': [ + -112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '9', + 'value': '9', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 25, + 'value': 25, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 0 + ], + [ + -90, + 0 + ], + [ + -90, + 45 + ], + [ + -135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 22.5 + ] + }, + 'properties': { + 'value': 23, + 'geohash': 't', + 'center': [ + 67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 't', + 'value': 't', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 23, + 'value': 23, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 0 + ], + [ + 90, + 0 + ], + [ + 90, + 45 + ], + [ + 45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -22.5 + ] + }, + 'properties': { + 'value': 23, + 'geohash': 'k', + 'center': [ + 22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'k', + 'value': 'k', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 23, + 'value': 23, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -45 + ], + [ + 45, + -45 + ], + [ + 45, + 0 + ], + [ + 0, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -22.5 + ] + }, + 'properties': { + 'value': 22, + 'geohash': '6', + 'center': [ + -67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '6', + 'value': '6', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 22, + 'value': 22, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -45 + ], + [ + -45, + -45 + ], + [ + -45, + 0 + ], + [ + -90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 67.5 + ] + }, + 'properties': { + 'value': 20, + 'geohash': 'u', + 'center': [ + 22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'u', + 'value': 'u', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 20, + 'value': 20, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 45 + ], + [ + 45, + 45 + ], + [ + 45, + 90 + ], + [ + 0, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 67.5 + ] + }, + 'properties': { + 'value': 18, + 'geohash': 'v', + 'center': [ + 67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'v', + 'value': 'v', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 18, + 'value': 18, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 45 + ], + [ + 90, + 45 + ], + [ + 90, + 90 + ], + [ + 45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -22.5 + ] + }, + 'properties': { + 'value': 11, + 'geohash': 'r', + 'center': [ + 157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'r', + 'value': 'r', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 11, + 'value': 11, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -45 + ], + [ + 180, + -45 + ], + [ + 180, + 0 + ], + [ + 135, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 22.5 + ] + }, + 'properties': { + 'value': 11, + 'geohash': 'e', + 'center': [ + -22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'e', + 'value': 'e', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 11, + 'value': 11, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + 45 + ], + [ + -45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 67.5 + ] + }, + 'properties': { + 'value': 10, + 'geohash': 'y', + 'center': [ + 112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'y', + 'value': 'y', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 10, + 'value': 10, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 45 + ], + [ + 135, + 45 + ], + [ + 135, + 90 + ], + [ + 90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 67.5 + ] + }, + 'properties': { + 'value': 10, + 'geohash': 'c', + 'center': [ + -112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'c', + 'value': 'c', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 10, + 'value': 10, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 45 + ], + [ + -90, + 45 + ], + [ + -90, + 90 + ], + [ + -135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 67.5 + ] + }, + 'properties': { + 'value': 8, + 'geohash': 'f', + 'center': [ + -67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'f', + 'value': 'f', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 8, + 'value': 8, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 45 + ], + [ + -45, + 45 + ], + [ + -45, + 90 + ], + [ + -90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -22.5 + ] + }, + 'properties': { + 'value': 8, + 'geohash': '7', + 'center': [ + -22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '7', + 'value': '7', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 8, + 'value': 8, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -45 + ], + [ + 0, + -45 + ], + [ + 0, + 0 + ], + [ + -45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -22.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'q', + 'center': [ + 112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'q', + 'value': 'q', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + -45 + ], + [ + 135, + -45 + ], + [ + 135, + 0 + ], + [ + 90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'g', + 'center': [ + -22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'g', + 'value': 'g', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 45 + ], + [ + 0, + 45 + ], + [ + 0, + 90 + ], + [ + -45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 22.5 + ] + }, + 'properties': { + 'value': 4, + 'geohash': 'x', + 'center': [ + 157.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'x', + 'value': 'x', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 4, + 'value': 4, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 0 + ], + [ + 180, + 0 + ], + [ + 180, + 45 + ], + [ + 135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + 67.5 + ] + }, + 'properties': { + 'value': 3, + 'geohash': 'b', + 'center': [ + -157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'b', + 'value': 'b', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 3, + 'value': 3, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -180, + 45 + ], + [ + -135, + 45 + ], + [ + -135, + 90 + ], + [ + -180, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': 'z', + 'center': [ + 157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'z', + 'value': 'z', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 45 + ], + [ + 180, + 45 + ], + [ + 180, + 90 + ], + [ + 135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': '4', + 'center': [ + -67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '4', + 'value': '4', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -90 + ], + [ + -45, + -90 + ], + [ + -45, + -45 + ], + [ + -90, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '5', + 'center': [ + -22.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '5', + 'value': '5', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -90 + ], + [ + 0, + -90 + ], + [ + 0, + -45 + ], + [ + -45, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '3', + 'center': [ + -112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'CN', + 'value': 'CN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '3', + 'value': '3', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + -45 + ], + [ + -90, + -45 + ], + [ + -90, + 0 + ], + [ + -135, + 0 + ] + ] + } + } + ], + 'properties': { + 'min': 1, + 'max': 39 + } + } + }, + { + 'label': 'Top 2 geo.dest: IN', + 'valueFormatter': _.identity, + 'geoJson': { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -22.5 + ] + }, + 'properties': { + 'value': 31, + 'geohash': '6', + 'center': [ + -67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '6', + 'value': '6', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 31, + 'value': 31, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -45 + ], + [ + -45, + -45 + ], + [ + -45, + 0 + ], + [ + -90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 22.5 + ] + }, + 'properties': { + 'value': 30, + 'geohash': 's', + 'center': [ + 22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 's', + 'value': 's', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 30, + 'value': 30, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 0 + ], + [ + 45, + 0 + ], + [ + 45, + 45 + ], + [ + 0, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 22.5 + ] + }, + 'properties': { + 'value': 29, + 'geohash': 'w', + 'center': [ + 112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'w', + 'value': 'w', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 29, + 'value': 29, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 0 + ], + [ + 135, + 0 + ], + [ + 135, + 45 + ], + [ + 90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 22.5 + ] + }, + 'properties': { + 'value': 28, + 'geohash': 'd', + 'center': [ + -67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'd', + 'value': 'd', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 28, + 'value': 28, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 0 + ], + [ + -45, + 0 + ], + [ + -45, + 45 + ], + [ + -90, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 22.5 + ] + }, + 'properties': { + 'value': 25, + 'geohash': 't', + 'center': [ + 67.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 't', + 'value': 't', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 25, + 'value': 25, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 0 + ], + [ + 90, + 0 + ], + [ + 90, + 45 + ], + [ + 45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + -22.5 + ] + }, + 'properties': { + 'value': 24, + 'geohash': 'k', + 'center': [ + 22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'k', + 'value': 'k', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 24, + 'value': 24, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + -45 + ], + [ + 45, + -45 + ], + [ + 45, + 0 + ], + [ + 0, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 22.5, + 67.5 + ] + }, + 'properties': { + 'value': 20, + 'geohash': 'u', + 'center': [ + 22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'u', + 'value': 'u', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 20, + 'value': 20, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 0, + 45 + ], + [ + 45, + 45 + ], + [ + 45, + 90 + ], + [ + 0, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 22.5 + ] + }, + 'properties': { + 'value': 18, + 'geohash': '9', + 'center': [ + -112.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '9', + 'value': '9', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 18, + 'value': 18, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 0 + ], + [ + -90, + 0 + ], + [ + -90, + 45 + ], + [ + -135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + 67.5 + ] + }, + 'properties': { + 'value': 14, + 'geohash': 'v', + 'center': [ + 67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'v', + 'value': 'v', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 14, + 'value': 14, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + 45 + ], + [ + 90, + 45 + ], + [ + 90, + 90 + ], + [ + 45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 22.5 + ] + }, + 'properties': { + 'value': 11, + 'geohash': 'e', + 'center': [ + -22.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'e', + 'value': 'e', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 11, + 'value': 11, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + 45 + ], + [ + -45, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -22.5 + ] + }, + 'properties': { + 'value': 9, + 'geohash': 'r', + 'center': [ + 157.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'r', + 'value': 'r', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 9, + 'value': 9, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -45 + ], + [ + 180, + -45 + ], + [ + 180, + 0 + ], + [ + 135, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'y', + 'center': [ + 112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'y', + 'value': 'y', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + 45 + ], + [ + 135, + 45 + ], + [ + 135, + 90 + ], + [ + 90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + 67.5 + ] + }, + 'properties': { + 'value': 6, + 'geohash': 'f', + 'center': [ + -67.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'f', + 'value': 'f', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 6, + 'value': 6, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + 45 + ], + [ + -45, + 45 + ], + [ + -45, + 90 + ], + [ + -90, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + 67.5 + ] + }, + 'properties': { + 'value': 5, + 'geohash': 'g', + 'center': [ + -22.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'g', + 'value': 'g', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 5, + 'value': 5, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + 45 + ], + [ + 0, + 45 + ], + [ + 0, + 90 + ], + [ + -45, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -112.5, + 67.5 + ] + }, + 'properties': { + 'value': 5, + 'geohash': 'c', + 'center': [ + -112.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'c', + 'value': 'c', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 5, + 'value': 5, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -135, + 45 + ], + [ + -90, + 45 + ], + [ + -90, + 90 + ], + [ + -135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -157.5, + 67.5 + ] + }, + 'properties': { + 'value': 4, + 'geohash': 'b', + 'center': [ + -157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'b', + 'value': 'b', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 4, + 'value': 4, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -180, + 45 + ], + [ + -135, + 45 + ], + [ + -135, + 90 + ], + [ + -180, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 112.5, + -22.5 + ] + }, + 'properties': { + 'value': 3, + 'geohash': 'q', + 'center': [ + 112.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'q', + 'value': 'q', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 3, + 'value': 3, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 90, + -45 + ], + [ + 135, + -45 + ], + [ + 135, + 0 + ], + [ + 90, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -67.5, + -67.5 + ] + }, + 'properties': { + 'value': 2, + 'geohash': '4', + 'center': [ + -67.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '4', + 'value': '4', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 2, + 'value': 2, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -90, + -90 + ], + [ + -45, + -90 + ], + [ + -45, + -45 + ], + [ + -90, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'z', + 'center': [ + 157.5, + 67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'z', + 'value': 'z', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 45 + ], + [ + 180, + 45 + ], + [ + 180, + 90 + ], + [ + 135, + 90 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + 22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'x', + 'center': [ + 157.5, + 22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'x', + 'value': 'x', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + 0 + ], + [ + 180, + 0 + ], + [ + 180, + 45 + ], + [ + 135, + 45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 157.5, + -67.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'p', + 'center': [ + 157.5, + -67.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'p', + 'value': 'p', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 135, + -90 + ], + [ + 180, + -90 + ], + [ + 180, + -45 + ], + [ + 135, + -45 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + 67.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': 'm', + 'center': [ + 67.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': 'm', + 'value': 'm', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + 45, + -45 + ], + [ + 90, + -45 + ], + [ + 90, + 0 + ], + [ + 45, + 0 + ] + ] + } + }, + { + 'type': 'Feature', + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -22.5, + -22.5 + ] + }, + 'properties': { + 'value': 1, + 'geohash': '7', + 'center': [ + -22.5, + -22.5 + ], + 'aggConfigResult': { + '$parent': { + '$parent': { + '$parent': null, + 'key': 'IN', + 'value': 'IN', + 'aggConfig': { + 'id': '3', + 'type': 'terms', + 'schema': 'split', + 'params': { + 'field': 'geo.dest', + 'size': 2, + 'order': 'desc', + 'orderBy': '1', + 'row': true + } + }, + 'type': 'bucket' + }, + 'key': '7', + 'value': '7', + 'aggConfig': { + 'id': '2', + 'type': 'geohash_grid', + 'schema': 'segment', + 'params': { + 'field': 'geo.coordinates', + 'precision': 1 + } + }, + 'type': 'bucket' + }, + 'key': 1, + 'value': 1, + 'aggConfig': { + 'id': '1', + 'type': 'count', + 'schema': 'metric', + 'params': {} + }, + 'type': 'metric' + }, + 'rectangle': [ + [ + -45, + -45 + ], + [ + 0, + -45 + ], + [ + 0, + 0 + ], + [ + -45, + 0 + ] + ] + } + } + ], + 'properties': { + 'min': 1, + 'max': 31 + } + } + } + ], + 'hits': 1639 +}; diff --git a/src/fixtures/vislib/mock_data/histogram/_columns.js b/src/fixtures/vislib/mock_data/histogram/_columns.js new file mode 100644 index 0000000000000..aa022fefa2a05 --- /dev/null +++ b/src/fixtures/vislib/mock_data/histogram/_columns.js @@ -0,0 +1,346 @@ +var _ = require('lodash'); + +module.exports = { + 'columns': [ + { + 'label': '404: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 2147483600, + 'y': 1, + 'y0': 0 + }, + { + 'x': 3221225400, + 'y': 0, + 'y0': 0 + }, + { + 'x': 4294967200, + 'y': 0, + 'y0': 0 + }, + { + 'x': 5368709100, + 'y': 0, + 'y0': 0 + }, + { + 'x': 6442450900, + 'y': 0, + 'y0': 0 + }, + { + 'x': 7516192700, + 'y': 0, + 'y0': 0 + }, + { + 'x': 8589934500, + 'y': 0, + 'y0': 0 + }, + { + 'x': 10737418200, + 'y': 0, + 'y0': 0 + }, + { + 'x': 11811160000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 12884901800, + 'y': 1, + 'y0': 0 + }, + { + 'x': 13958643700, + 'y': 0, + 'y0': 0 + }, + { + 'x': 15032385500, + 'y': 0, + 'y0': 0 + }, + { + 'x': 16106127300, + 'y': 0, + 'y0': 0 + }, + { + 'x': 18253611000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 19327352800, + 'y': 0, + 'y0': 0 + }, + { + 'x': 20401094600, + 'y': 0, + 'y0': 0 + }, + { + 'x': 21474836400, + 'y': 0, + 'y0': 0 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '200: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 2147483600, + 'y': 0, + 'y0': 0 + }, + { + 'x': 3221225400, + 'y': 2, + 'y0': 0 + }, + { + 'x': 4294967200, + 'y': 3, + 'y0': 0 + }, + { + 'x': 5368709100, + 'y': 3, + 'y0': 0 + }, + { + 'x': 6442450900, + 'y': 1, + 'y0': 0 + }, + { + 'x': 7516192700, + 'y': 1, + 'y0': 0 + }, + { + 'x': 8589934500, + 'y': 4, + 'y0': 0 + }, + { + 'x': 10737418200, + 'y': 0, + 'y0': 0 + }, + { + 'x': 11811160000, + 'y': 1, + 'y0': 0 + }, + { + 'x': 12884901800, + 'y': 1, + 'y0': 0 + }, + { + 'x': 13958643700, + 'y': 1, + 'y0': 0 + }, + { + 'x': 15032385500, + 'y': 2, + 'y0': 0 + }, + { + 'x': 16106127300, + 'y': 3, + 'y0': 0 + }, + { + 'x': 18253611000, + 'y': 4, + 'y0': 0 + }, + { + 'x': 19327352800, + 'y': 5, + 'y0': 0 + }, + { + 'x': 20401094600, + 'y': 2, + 'y0': 0 + }, + { + 'x': 21474836400, + 'y': 2, + 'y0': 0 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '503: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 2147483600, + 'y': 0, + 'y0': 0 + }, + { + 'x': 3221225400, + 'y': 0, + 'y0': 0 + }, + { + 'x': 4294967200, + 'y': 0, + 'y0': 0 + }, + { + 'x': 5368709100, + 'y': 0, + 'y0': 0 + }, + { + 'x': 6442450900, + 'y': 0, + 'y0': 0 + }, + { + 'x': 7516192700, + 'y': 0, + 'y0': 0 + }, + { + 'x': 8589934500, + 'y': 0, + 'y0': 0 + }, + { + 'x': 10737418200, + 'y': 1, + 'y0': 0 + }, + { + 'x': 11811160000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 12884901800, + 'y': 0, + 'y0': 0 + }, + { + 'x': 13958643700, + 'y': 0, + 'y0': 0 + }, + { + 'x': 15032385500, + 'y': 0, + 'y0': 0 + }, + { + 'x': 16106127300, + 'y': 0, + 'y0': 0 + }, + { + 'x': 18253611000, + 'y': 0, + 'y0': 0 + }, + { + 'x': 19327352800, + 'y': 0, + 'y0': 0 + }, + { + 'x': 20401094600, + 'y': 0, + 'y0': 0 + }, + { + 'x': 21474836400, + 'y': 0, + 'y0': 0 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 40 +}; diff --git a/src/fixtures/vislib/mock_data/histogram/_rows.js b/src/fixtures/vislib/mock_data/histogram/_rows.js new file mode 100644 index 0000000000000..bf15c31b9ceb5 --- /dev/null +++ b/src/fixtures/vislib/mock_data/histogram/_rows.js @@ -0,0 +1,187 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'label': '404: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 2147483600, + 'y': 1 + }, + { + 'x': 10737418200, + 'y': 1 + }, + { + 'x': 15032385500, + 'y': 2 + }, + { + 'x': 19327352800, + 'y': 1 + }, + { + 'x': 32212254700, + 'y': 1 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '200: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 3221225400, + 'y': 4 + }, + { + 'x': 4294967200, + 'y': 3 + }, + { + 'x': 5368709100, + 'y': 3 + }, + { + 'x': 6442450900, + 'y': 2 + }, + { + 'x': 7516192700, + 'y': 2 + }, + { + 'x': 8589934500, + 'y': 2 + }, + { + 'x': 9663676400, + 'y': 3 + }, + { + 'x': 11811160000, + 'y': 3 + }, + { + 'x': 12884901800, + 'y': 2 + }, + { + 'x': 13958643700, + 'y': 1 + }, + { + 'x': 15032385500, + 'y': 2 + }, + { + 'x': 16106127300, + 'y': 3 + }, + { + 'x': 17179869100, + 'y': 1 + }, + { + 'x': 18253611000, + 'y': 4 + }, + { + 'x': 19327352800, + 'y': 1 + }, + { + 'x': 20401094600, + 'y': 1 + }, + { + 'x': 21474836400, + 'y': 4 + }, + { + 'x': 32212254700, + 'y': 3 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '503: response', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 10737418200, + 'y': 1 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 51 +}; diff --git a/src/fixtures/vislib/mock_data/histogram/_series.js b/src/fixtures/vislib/mock_data/histogram/_series.js new file mode 100644 index 0000000000000..6eb3d10b12b21 --- /dev/null +++ b/src/fixtures/vislib/mock_data/histogram/_series.js @@ -0,0 +1,103 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': 'machine.ram', + 'ordered': { + 'interval': 100 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 3221225400, + 'y': 5 + }, + { + 'x': 4294967200, + 'y': 2 + }, + { + 'x': 5368709100, + 'y': 5 + }, + { + 'x': 6442450900, + 'y': 4 + }, + { + 'x': 7516192700, + 'y': 1 + }, + { + 'x': 9663676400, + 'y': 9 + }, + { + 'x': 10737418200, + 'y': 5 + }, + { + 'x': 11811160000, + 'y': 5 + }, + { + 'x': 12884901800, + 'y': 2 + }, + { + 'x': 13958643700, + 'y': 3 + }, + { + 'x': 15032385500, + 'y': 3 + }, + { + 'x': 16106127300, + 'y': 3 + }, + { + 'x': 17179869100, + 'y': 1 + }, + { + 'x': 18253611000, + 'y': 6 + }, + { + 'x': 19327352800, + 'y': 3 + }, + { + 'x': 20401094600, + 'y': 3 + }, + { + 'x': 21474836400, + 'y': 7 + }, + { + 'x': 32212254700, + 'y': 4 + } + ] + } + ], + 'hits': 71, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/histogram/_slices.js b/src/fixtures/vislib/mock_data/histogram/_slices.js new file mode 100644 index 0000000000000..0d280cad11bec --- /dev/null +++ b/src/fixtures/vislib/mock_data/histogram/_slices.js @@ -0,0 +1,309 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'slices': { + 'children': [ + { + 'name': 0, + 'size': 378611, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 1000, + 'size': 205997, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 2000, + 'size': 397189, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 3000, + 'size': 397195, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 4000, + 'size': 398429, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 5000, + 'size': 397843, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 6000, + 'size': 398140, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 7000, + 'size': 398076, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 8000, + 'size': 396746, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 9000, + 'size': 397418, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 10000, + 'size': 20222, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 11000, + 'size': 20173, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 12000, + 'size': 20026, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 13000, + 'size': 19986, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 14000, + 'size': 20091, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 15000, + 'size': 20052, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 16000, + 'size': 20349, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 17000, + 'size': 20290, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 18000, + 'size': 20399, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 19000, + 'size': 20133, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + }, + { + 'name': 20000, + 'size': 9, + 'aggConfig': { + 'type': 'histogram', + 'schema': 'segment', + 'fieldFormatter': _.constant(String), + 'params': { + 'interval': 1000, + 'extended_bounds': {} + } + } + } + ] + }, + 'names': [ + 0, + 1000, + 2000, + 3000, + 4000, + 5000, + 6000, + 7000, + 8000, + 9000, + 10000, + 11000, + 12000, + 13000, + 14000, + 15000, + 16000, + 17000, + 18000, + 19000, + 20000 + ], + 'hits': 3967374, + 'tooltipFormatter': function (event) { + return event.point; + } +}; diff --git a/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js b/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js new file mode 100644 index 0000000000000..c08ba4444e37a --- /dev/null +++ b/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js @@ -0,0 +1,32 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': '', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '_all', + 'y': 274 + } + ] + } + ], + 'hits': 274, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/range/_columns.js b/src/fixtures/vislib/mock_data/range/_columns.js new file mode 100644 index 0000000000000..1ac57060f323d --- /dev/null +++ b/src/fixtures/vislib/mock_data/range/_columns.js @@ -0,0 +1,59 @@ +var _ = require('lodash'); + +module.exports = { + 'columns': [ + { + 'label': 'apache: _type', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 13309 + }, + { + 'x': '1000.0-2000.0', + 'y': 7196 + } + ] + } + ] + }, + { + 'label': 'nginx: _type', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 3278 + }, + { + 'x': '1000.0-2000.0', + 'y': 1804 + } + ] + } + ] + } + ], + 'hits': 171499, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/range/_rows.js b/src/fixtures/vislib/mock_data/range/_rows.js new file mode 100644 index 0000000000000..3868b0ff9b27b --- /dev/null +++ b/src/fixtures/vislib/mock_data/range/_rows.js @@ -0,0 +1,84 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'label': 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1: agent.raw', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 6422, + 'y0': 0 + }, + { + 'x': '1000.0-2000.0', + 'y': 3446, + 'y0': 0 + } + ] + } + ] + }, + { + 'label': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24: agent.raw', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 5430, + 'y0': 0 + }, + { + 'x': '1000.0-2000.0', + 'y': 3010, + 'y0': 0 + } + ] + } + ] + }, + { + 'label': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322): agent.raw', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 4735, + 'y0': 0 + }, + { + 'x': '1000.0-2000.0', + 'y': 2542, + 'y0': 0 + } + ] + } + ] + } + ], + 'hits': 171501, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/range/_series.js b/src/fixtures/vislib/mock_data/range/_series.js new file mode 100644 index 0000000000000..4b5e8f6181695 --- /dev/null +++ b/src/fixtures/vislib/mock_data/range/_series.js @@ -0,0 +1,36 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': 'bytes ranges', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': '0.0-1000.0', + 'y': 16576 + }, + { + 'x': '1000.0-2000.0', + 'y': 9005 + } + ] + } + ], + 'hits': 171500, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/significant_terms/_columns.js b/src/fixtures/vislib/mock_data/significant_terms/_columns.js new file mode 100644 index 0000000000000..3bdaa0dc3954a --- /dev/null +++ b/src/fixtures/vislib/mock_data/significant_terms/_columns.js @@ -0,0 +1,232 @@ +var _ = require('lodash'); + +module.exports = { + 'columns': [ + { + 'label': 'http: links', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 144000 + }, + { + 'x': 'info', + 'y': 128237 + }, + { + 'x': 'security', + 'y': 34518 + }, + { + 'x': 'error', + 'y': 10258 + }, + { + 'x': 'warning', + 'y': 17188 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'info: links', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 108148 + }, + { + 'x': 'info', + 'y': 96242 + }, + { + 'x': 'security', + 'y': 25889 + }, + { + 'x': 'error', + 'y': 7673 + }, + { + 'x': 'warning', + 'y': 12842 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'www.slate.com: links', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 98056 + }, + { + 'x': 'info', + 'y': 87344 + }, + { + 'x': 'security', + 'y': 23577 + }, + { + 'x': 'error', + 'y': 7004 + }, + { + 'x': 'warning', + 'y': 11759 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'twitter.com: links', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 74154 + }, + { + 'x': 'info', + 'y': 65963 + }, + { + 'x': 'security', + 'y': 17832 + }, + { + 'x': 'error', + 'y': 5258 + }, + { + 'x': 'warning', + 'y': 8906 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'www.www.slate.com: links', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 62591 + }, + { + 'x': 'info', + 'y': 55822 + }, + { + 'x': 'security', + 'y': 15100 + }, + { + 'x': 'error', + 'y': 4564 + }, + { + 'x': 'warning', + 'y': 7498 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171446 +}; diff --git a/src/fixtures/vislib/mock_data/significant_terms/_rows.js b/src/fixtures/vislib/mock_data/significant_terms/_rows.js new file mode 100644 index 0000000000000..b7d07251b5ca8 --- /dev/null +++ b/src/fixtures/vislib/mock_data/significant_terms/_rows.js @@ -0,0 +1,232 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'label': 'h3: headings', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 144000 + }, + { + 'x': 'info', + 'y': 128235 + }, + { + 'x': 'security', + 'y': 34518 + }, + { + 'x': 'error', + 'y': 10257 + }, + { + 'x': 'warning', + 'y': 17188 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'h5: headings', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 144000 + }, + { + 'x': 'info', + 'y': 128235 + }, + { + 'x': 'security', + 'y': 34518 + }, + { + 'x': 'error', + 'y': 10257 + }, + { + 'x': 'warning', + 'y': 17188 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'http: headings', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 144000 + }, + { + 'x': 'info', + 'y': 128235 + }, + { + 'x': 'security', + 'y': 34518 + }, + { + 'x': 'error', + 'y': 10257 + }, + { + 'x': 'warning', + 'y': 17188 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'success: headings', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 120689 + }, + { + 'x': 'info', + 'y': 107621 + }, + { + 'x': 'security', + 'y': 28916 + }, + { + 'x': 'error', + 'y': 8590 + }, + { + 'x': 'warning', + 'y': 14548 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': 'www.slate.com: headings', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 62292 + }, + { + 'x': 'info', + 'y': 55646 + }, + { + 'x': 'security', + 'y': 14823 + }, + { + 'x': 'error', + 'y': 4441 + }, + { + 'x': 'warning', + 'y': 7539 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171445 +}; diff --git a/src/fixtures/vislib/mock_data/significant_terms/_series.js b/src/fixtures/vislib/mock_data/significant_terms/_series.js new file mode 100644 index 0000000000000..c4feebaef9d4d --- /dev/null +++ b/src/fixtures/vislib/mock_data/significant_terms/_series.js @@ -0,0 +1,48 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': 'Top 5 unusual terms in @tags', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'success', + 'y': 143995 + }, + { + 'x': 'info', + 'y': 128233 + }, + { + 'x': 'security', + 'y': 34515 + }, + { + 'x': 'error', + 'y': 10256 + }, + { + 'x': 'warning', + 'y': 17188 + } + ] + } + ], + 'hits': 171439, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/stacked/_stacked.js b/src/fixtures/vislib/mock_data/stacked/_stacked.js new file mode 100644 index 0000000000000..2df6f83a68307 --- /dev/null +++ b/src/fixtures/vislib/mock_data/stacked/_stacked.js @@ -0,0 +1,1572 @@ +var moment = require('moment'); + +module.exports = { + 'label': '', + 'xAxisLabel': '@timestamp per 30 sec', + 'ordered': { + 'date': true, + 'interval': 30000, + 'min': 1416850340336, + 'max': 1416852140336 + }, + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'label': 'jpg', + 'values': [ + { + 'x': 1416850320000, + 'y': 110, + 'y0': 0 + }, + { + 'x': 1416850350000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416850380000, + 'y': 34, + 'y0': 0 + }, + { + 'x': 1416850410000, + 'y': 21, + 'y0': 0 + }, + { + 'x': 1416850440000, + 'y': 32, + 'y0': 0 + }, + { + 'x': 1416850470000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416850500000, + 'y': 16, + 'y0': 0 + }, + { + 'x': 1416850530000, + 'y': 27, + 'y0': 0 + }, + { + 'x': 1416850560000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416850590000, + 'y': 38, + 'y0': 0 + }, + { + 'x': 1416850620000, + 'y': 33, + 'y0': 0 + }, + { + 'x': 1416850650000, + 'y': 33, + 'y0': 0 + }, + { + 'x': 1416850680000, + 'y': 31, + 'y0': 0 + }, + { + 'x': 1416850710000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416850740000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416850770000, + 'y': 38, + 'y0': 0 + }, + { + 'x': 1416850800000, + 'y': 34, + 'y0': 0 + }, + { + 'x': 1416850830000, + 'y': 30, + 'y0': 0 + }, + { + 'x': 1416850860000, + 'y': 38, + 'y0': 0 + }, + { + 'x': 1416850890000, + 'y': 19, + 'y0': 0 + }, + { + 'x': 1416850920000, + 'y': 23, + 'y0': 0 + }, + { + 'x': 1416850950000, + 'y': 33, + 'y0': 0 + }, + { + 'x': 1416850980000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851010000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416851040000, + 'y': 22, + 'y0': 0 + }, + { + 'x': 1416851070000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851100000, + 'y': 27, + 'y0': 0 + }, + { + 'x': 1416851130000, + 'y': 32, + 'y0': 0 + }, + { + 'x': 1416851160000, + 'y': 32, + 'y0': 0 + }, + { + 'x': 1416851190000, + 'y': 30, + 'y0': 0 + }, + { + 'x': 1416851220000, + 'y': 32, + 'y0': 0 + }, + { + 'x': 1416851250000, + 'y': 36, + 'y0': 0 + }, + { + 'x': 1416851280000, + 'y': 32, + 'y0': 0 + }, + { + 'x': 1416851310000, + 'y': 29, + 'y0': 0 + }, + { + 'x': 1416851340000, + 'y': 22, + 'y0': 0 + }, + { + 'x': 1416851370000, + 'y': 29, + 'y0': 0 + }, + { + 'x': 1416851400000, + 'y': 33, + 'y0': 0 + }, + { + 'x': 1416851430000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851460000, + 'y': 39, + 'y0': 0 + }, + { + 'x': 1416851490000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851520000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851550000, + 'y': 28, + 'y0': 0 + }, + { + 'x': 1416851580000, + 'y': 30, + 'y0': 0 + }, + { + 'x': 1416851610000, + 'y': 29, + 'y0': 0 + }, + { + 'x': 1416851640000, + 'y': 30, + 'y0': 0 + }, + { + 'x': 1416851670000, + 'y': 23, + 'y0': 0 + }, + { + 'x': 1416851700000, + 'y': 23, + 'y0': 0 + }, + { + 'x': 1416851730000, + 'y': 27, + 'y0': 0 + }, + { + 'x': 1416851760000, + 'y': 21, + 'y0': 0 + }, + { + 'x': 1416851790000, + 'y': 24, + 'y0': 0 + }, + { + 'x': 1416851820000, + 'y': 26, + 'y0': 0 + }, + { + 'x': 1416851850000, + 'y': 26, + 'y0': 0 + }, + { + 'x': 1416851880000, + 'y': 21, + 'y0': 0 + }, + { + 'x': 1416851910000, + 'y': 33, + 'y0': 0 + }, + { + 'x': 1416851940000, + 'y': 23, + 'y0': 0 + }, + { + 'x': 1416851970000, + 'y': 46, + 'y0': 0 + }, + { + 'x': 1416852000000, + 'y': 27, + 'y0': 0 + }, + { + 'x': 1416852030000, + 'y': 20, + 'y0': 0 + }, + { + 'x': 1416852060000, + 'y': 34, + 'y0': 0 + }, + { + 'x': 1416852090000, + 'y': 15, + 'y0': 0 + }, + { + 'x': 1416852120000, + 'y': 18, + 'y0': 0 + } + ] + }, + { + 'label': 'css', + 'values': [ + { + 'x': 1416850320000, + 'y': 3, + 'y0': 11 + }, + { + 'x': 1416850350000, + 'y': 13, + 'y0': 24 + }, + { + 'x': 1416850380000, + 'y': 5, + 'y0': 34 + }, + { + 'x': 1416850410000, + 'y': 12, + 'y0': 21 + }, + { + 'x': 1416850440000, + 'y': 9, + 'y0': 32 + }, + { + 'x': 1416850470000, + 'y': 12, + 'y0': 24 + }, + { + 'x': 1416850500000, + 'y': 6, + 'y0': 16 + }, + { + 'x': 1416850530000, + 'y': 6, + 'y0': 27 + }, + { + 'x': 1416850560000, + 'y': 11, + 'y0': 24 + }, + { + 'x': 1416850590000, + 'y': 11, + 'y0': 38 + }, + { + 'x': 1416850620000, + 'y': 6, + 'y0': 33 + }, + { + 'x': 1416850650000, + 'y': 8, + 'y0': 33 + }, + { + 'x': 1416850680000, + 'y': 6, + 'y0': 31 + }, + { + 'x': 1416850710000, + 'y': 4, + 'y0': 24 + }, + { + 'x': 1416850740000, + 'y': 9, + 'y0': 24 + }, + { + 'x': 1416850770000, + 'y': 3, + 'y0': 38 + }, + { + 'x': 1416850800000, + 'y': 5, + 'y0': 34 + }, + { + 'x': 1416850830000, + 'y': 6, + 'y0': 30 + }, + { + 'x': 1416850860000, + 'y': 9, + 'y0': 38 + }, + { + 'x': 1416850890000, + 'y': 5, + 'y0': 19 + }, + { + 'x': 1416850920000, + 'y': 8, + 'y0': 23 + }, + { + 'x': 1416850950000, + 'y': 9, + 'y0': 33 + }, + { + 'x': 1416850980000, + 'y': 5, + 'y0': 28 + }, + { + 'x': 1416851010000, + 'y': 6, + 'y0': 24 + }, + { + 'x': 1416851040000, + 'y': 9, + 'y0': 22 + }, + { + 'x': 1416851070000, + 'y': 9, + 'y0': 28 + }, + { + 'x': 1416851100000, + 'y': 11, + 'y0': 27 + }, + { + 'x': 1416851130000, + 'y': 5, + 'y0': 32 + }, + { + 'x': 1416851160000, + 'y': 8, + 'y0': 32 + }, + { + 'x': 1416851190000, + 'y': 6, + 'y0': 30 + }, + { + 'x': 1416851220000, + 'y': 10, + 'y0': 32 + }, + { + 'x': 1416851250000, + 'y': 5, + 'y0': 36 + }, + { + 'x': 1416851280000, + 'y': 6, + 'y0': 32 + }, + { + 'x': 1416851310000, + 'y': 4, + 'y0': 29 + }, + { + 'x': 1416851340000, + 'y': 8, + 'y0': 22 + }, + { + 'x': 1416851370000, + 'y': 3, + 'y0': 29 + }, + { + 'x': 1416851400000, + 'y': 8, + 'y0': 33 + }, + { + 'x': 1416851430000, + 'y': 10, + 'y0': 28 + }, + { + 'x': 1416851460000, + 'y': 5, + 'y0': 39 + }, + { + 'x': 1416851490000, + 'y': 7, + 'y0': 28 + }, + { + 'x': 1416851520000, + 'y': 6, + 'y0': 28 + }, + { + 'x': 1416851550000, + 'y': 4, + 'y0': 28 + }, + { + 'x': 1416851580000, + 'y': 9, + 'y0': 30 + }, + { + 'x': 1416851610000, + 'y': 3, + 'y0': 29 + }, + { + 'x': 1416851640000, + 'y': 9, + 'y0': 30 + }, + { + 'x': 1416851670000, + 'y': 6, + 'y0': 23 + }, + { + 'x': 1416851700000, + 'y': 11, + 'y0': 23 + }, + { + 'x': 1416851730000, + 'y': 4, + 'y0': 27 + }, + { + 'x': 1416851760000, + 'y': 8, + 'y0': 21 + }, + { + 'x': 1416851790000, + 'y': 5, + 'y0': 24 + }, + { + 'x': 1416851820000, + 'y': 7, + 'y0': 26 + }, + { + 'x': 1416851850000, + 'y': 7, + 'y0': 26 + }, + { + 'x': 1416851880000, + 'y': 4, + 'y0': 21 + }, + { + 'x': 1416851910000, + 'y': 8, + 'y0': 33 + }, + { + 'x': 1416851940000, + 'y': 6, + 'y0': 23 + }, + { + 'x': 1416851970000, + 'y': 6, + 'y0': 46 + }, + { + 'x': 1416852000000, + 'y': 3, + 'y0': 27 + }, + { + 'x': 1416852030000, + 'y': 6, + 'y0': 20 + }, + { + 'x': 1416852060000, + 'y': 5, + 'y0': 34 + }, + { + 'x': 1416852090000, + 'y': 5, + 'y0': 15 + }, + { + 'x': 1416852120000, + 'y': 1, + 'y0': 18 + } + ] + }, + { + 'label': 'gif', + 'values': [ + { + 'x': 1416850320000, + 'y': 1, + 'y0': 14 + }, + { + 'x': 1416850350000, + 'y': 2, + 'y0': 37 + }, + { + 'x': 1416850380000, + 'y': 4, + 'y0': 39 + }, + { + 'x': 1416850410000, + 'y': 2, + 'y0': 33 + }, + { + 'x': 1416850440000, + 'y': 3, + 'y0': 41 + }, + { + 'x': 1416850470000, + 'y': 1, + 'y0': 36 + }, + { + 'x': 1416850500000, + 'y': 1, + 'y0': 22 + }, + { + 'x': 1416850530000, + 'y': 1, + 'y0': 33 + }, + { + 'x': 1416850560000, + 'y': 2, + 'y0': 35 + }, + { + 'x': 1416850590000, + 'y': 5, + 'y0': 49 + }, + { + 'x': 1416850620000, + 'y': 1, + 'y0': 39 + }, + { + 'x': 1416850650000, + 'y': 1, + 'y0': 41 + }, + { + 'x': 1416850680000, + 'y': 4, + 'y0': 37 + }, + { + 'x': 1416850710000, + 'y': 1, + 'y0': 28 + }, + { + 'x': 1416850740000, + 'y': 3, + 'y0': 33 + }, + { + 'x': 1416850770000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416850800000, + 'y': 2, + 'y0': 39 + }, + { + 'x': 1416850830000, + 'y': 5, + 'y0': 36 + }, + { + 'x': 1416850860000, + 'y': 3, + 'y0': 47 + }, + { + 'x': 1416850890000, + 'y': 1, + 'y0': 24 + }, + { + 'x': 1416850920000, + 'y': 3, + 'y0': 31 + }, + { + 'x': 1416850950000, + 'y': 4, + 'y0': 42 + }, + { + 'x': 1416850980000, + 'y': 3, + 'y0': 33 + }, + { + 'x': 1416851010000, + 'y': 5, + 'y0': 30 + }, + { + 'x': 1416851040000, + 'y': 2, + 'y0': 31 + }, + { + 'x': 1416851070000, + 'y': 3, + 'y0': 37 + }, + { + 'x': 1416851100000, + 'y': 5, + 'y0': 38 + }, + { + 'x': 1416851130000, + 'y': 3, + 'y0': 37 + }, + { + 'x': 1416851160000, + 'y': 4, + 'y0': 40 + }, + { + 'x': 1416851190000, + 'y': 9, + 'y0': 36 + }, + { + 'x': 1416851220000, + 'y': 7, + 'y0': 42 + }, + { + 'x': 1416851250000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416851280000, + 'y': 1, + 'y0': 38 + }, + { + 'x': 1416851310000, + 'y': 2, + 'y0': 33 + }, + { + 'x': 1416851340000, + 'y': 5, + 'y0': 30 + }, + { + 'x': 1416851370000, + 'y': 3, + 'y0': 32 + }, + { + 'x': 1416851400000, + 'y': 5, + 'y0': 41 + }, + { + 'x': 1416851430000, + 'y': 4, + 'y0': 38 + }, + { + 'x': 1416851460000, + 'y': 5, + 'y0': 44 + }, + { + 'x': 1416851490000, + 'y': 2, + 'y0': 35 + }, + { + 'x': 1416851520000, + 'y': 2, + 'y0': 34 + }, + { + 'x': 1416851550000, + 'y': 4, + 'y0': 32 + }, + { + 'x': 1416851580000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416851610000, + 'y': 4, + 'y0': 32 + }, + { + 'x': 1416851640000, + 'y': 0, + 'y0': 39 + }, + { + 'x': 1416851670000, + 'y': 2, + 'y0': 29 + }, + { + 'x': 1416851700000, + 'y': 1, + 'y0': 34 + }, + { + 'x': 1416851730000, + 'y': 3, + 'y0': 31 + }, + { + 'x': 1416851760000, + 'y': 0, + 'y0': 29 + }, + { + 'x': 1416851790000, + 'y': 4, + 'y0': 29 + }, + { + 'x': 1416851820000, + 'y': 3, + 'y0': 33 + }, + { + 'x': 1416851850000, + 'y': 3, + 'y0': 33 + }, + { + 'x': 1416851880000, + 'y': 0, + 'y0': 25 + }, + { + 'x': 1416851910000, + 'y': 0, + 'y0': 41 + }, + { + 'x': 1416851940000, + 'y': 3, + 'y0': 29 + }, + { + 'x': 1416851970000, + 'y': 3, + 'y0': 52 + }, + { + 'x': 1416852000000, + 'y': 1, + 'y0': 30 + }, + { + 'x': 1416852030000, + 'y': 5, + 'y0': 26 + }, + { + 'x': 1416852060000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416852090000, + 'y': 1, + 'y0': 20 + }, + { + 'x': 1416852120000, + 'y': 2, + 'y0': 19 + } + ] + }, + { + 'label': 'png', + 'values': [ + { + 'x': 1416850320000, + 'y': 1, + 'y0': 15 + }, + { + 'x': 1416850350000, + 'y': 6, + 'y0': 39 + }, + { + 'x': 1416850380000, + 'y': 6, + 'y0': 43 + }, + { + 'x': 1416850410000, + 'y': 5, + 'y0': 35 + }, + { + 'x': 1416850440000, + 'y': 3, + 'y0': 44 + }, + { + 'x': 1416850470000, + 'y': 5, + 'y0': 37 + }, + { + 'x': 1416850500000, + 'y': 6, + 'y0': 23 + }, + { + 'x': 1416850530000, + 'y': 1, + 'y0': 34 + }, + { + 'x': 1416850560000, + 'y': 3, + 'y0': 37 + }, + { + 'x': 1416850590000, + 'y': 2, + 'y0': 54 + }, + { + 'x': 1416850620000, + 'y': 1, + 'y0': 40 + }, + { + 'x': 1416850650000, + 'y': 1, + 'y0': 42 + }, + { + 'x': 1416850680000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416850710000, + 'y': 5, + 'y0': 29 + }, + { + 'x': 1416850740000, + 'y': 7, + 'y0': 36 + }, + { + 'x': 1416850770000, + 'y': 2, + 'y0': 43 + }, + { + 'x': 1416850800000, + 'y': 3, + 'y0': 41 + }, + { + 'x': 1416850830000, + 'y': 6, + 'y0': 41 + }, + { + 'x': 1416850860000, + 'y': 2, + 'y0': 50 + }, + { + 'x': 1416850890000, + 'y': 4, + 'y0': 25 + }, + { + 'x': 1416850920000, + 'y': 2, + 'y0': 34 + }, + { + 'x': 1416850950000, + 'y': 3, + 'y0': 46 + }, + { + 'x': 1416850980000, + 'y': 8, + 'y0': 36 + }, + { + 'x': 1416851010000, + 'y': 4, + 'y0': 35 + }, + { + 'x': 1416851040000, + 'y': 4, + 'y0': 33 + }, + { + 'x': 1416851070000, + 'y': 1, + 'y0': 40 + }, + { + 'x': 1416851100000, + 'y': 2, + 'y0': 43 + }, + { + 'x': 1416851130000, + 'y': 4, + 'y0': 40 + }, + { + 'x': 1416851160000, + 'y': 3, + 'y0': 44 + }, + { + 'x': 1416851190000, + 'y': 4, + 'y0': 45 + }, + { + 'x': 1416851220000, + 'y': 2, + 'y0': 49 + }, + { + 'x': 1416851250000, + 'y': 4, + 'y0': 43 + }, + { + 'x': 1416851280000, + 'y': 8, + 'y0': 39 + }, + { + 'x': 1416851310000, + 'y': 4, + 'y0': 35 + }, + { + 'x': 1416851340000, + 'y': 4, + 'y0': 35 + }, + { + 'x': 1416851370000, + 'y': 7, + 'y0': 35 + }, + { + 'x': 1416851400000, + 'y': 2, + 'y0': 46 + }, + { + 'x': 1416851430000, + 'y': 3, + 'y0': 42 + }, + { + 'x': 1416851460000, + 'y': 3, + 'y0': 49 + }, + { + 'x': 1416851490000, + 'y': 3, + 'y0': 37 + }, + { + 'x': 1416851520000, + 'y': 4, + 'y0': 36 + }, + { + 'x': 1416851550000, + 'y': 3, + 'y0': 36 + }, + { + 'x': 1416851580000, + 'y': 4, + 'y0': 42 + }, + { + 'x': 1416851610000, + 'y': 5, + 'y0': 36 + }, + { + 'x': 1416851640000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416851670000, + 'y': 3, + 'y0': 31 + }, + { + 'x': 1416851700000, + 'y': 2, + 'y0': 35 + }, + { + 'x': 1416851730000, + 'y': 5, + 'y0': 34 + }, + { + 'x': 1416851760000, + 'y': 4, + 'y0': 29 + }, + { + 'x': 1416851790000, + 'y': 5, + 'y0': 33 + }, + { + 'x': 1416851820000, + 'y': 1, + 'y0': 36 + }, + { + 'x': 1416851850000, + 'y': 3, + 'y0': 36 + }, + { + 'x': 1416851880000, + 'y': 6, + 'y0': 25 + }, + { + 'x': 1416851910000, + 'y': 4, + 'y0': 41 + }, + { + 'x': 1416851940000, + 'y': 7, + 'y0': 32 + }, + { + 'x': 1416851970000, + 'y': 5, + 'y0': 55 + }, + { + 'x': 1416852000000, + 'y': 2, + 'y0': 31 + }, + { + 'x': 1416852030000, + 'y': 2, + 'y0': 31 + }, + { + 'x': 1416852060000, + 'y': 4, + 'y0': 42 + }, + { + 'x': 1416852090000, + 'y': 6, + 'y0': 21 + }, + { + 'x': 1416852120000, + 'y': 2, + 'y0': 21 + } + ] + }, + { + 'label': 'php', + 'values': [ + { + 'x': 1416850320000, + 'y': 0, + 'y0': 16 + }, + { + 'x': 1416850350000, + 'y': 1, + 'y0': 45 + }, + { + 'x': 1416850380000, + 'y': 0, + 'y0': 49 + }, + { + 'x': 1416850410000, + 'y': 2, + 'y0': 40 + }, + { + 'x': 1416850440000, + 'y': 0, + 'y0': 47 + }, + { + 'x': 1416850470000, + 'y': 0, + 'y0': 42 + }, + { + 'x': 1416850500000, + 'y': 3, + 'y0': 29 + }, + { + 'x': 1416850530000, + 'y': 1, + 'y0': 35 + }, + { + 'x': 1416850560000, + 'y': 3, + 'y0': 40 + }, + { + 'x': 1416850590000, + 'y': 2, + 'y0': 56 + }, + { + 'x': 1416850620000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416850650000, + 'y': 5, + 'y0': 43 + }, + { + 'x': 1416850680000, + 'y': 2, + 'y0': 43 + }, + { + 'x': 1416850710000, + 'y': 1, + 'y0': 34 + }, + { + 'x': 1416850740000, + 'y': 2, + 'y0': 43 + }, + { + 'x': 1416850770000, + 'y': 2, + 'y0': 45 + }, + { + 'x': 1416850800000, + 'y': 1, + 'y0': 44 + }, + { + 'x': 1416850830000, + 'y': 1, + 'y0': 47 + }, + { + 'x': 1416850860000, + 'y': 1, + 'y0': 52 + }, + { + 'x': 1416850890000, + 'y': 1, + 'y0': 29 + }, + { + 'x': 1416850920000, + 'y': 2, + 'y0': 36 + }, + { + 'x': 1416850950000, + 'y': 2, + 'y0': 49 + }, + { + 'x': 1416850980000, + 'y': 0, + 'y0': 44 + }, + { + 'x': 1416851010000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416851040000, + 'y': 2, + 'y0': 37 + }, + { + 'x': 1416851070000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416851100000, + 'y': 2, + 'y0': 45 + }, + { + 'x': 1416851130000, + 'y': 0, + 'y0': 44 + }, + { + 'x': 1416851160000, + 'y': 1, + 'y0': 47 + }, + { + 'x': 1416851190000, + 'y': 2, + 'y0': 49 + }, + { + 'x': 1416851220000, + 'y': 4, + 'y0': 51 + }, + { + 'x': 1416851250000, + 'y': 0, + 'y0': 47 + }, + { + 'x': 1416851280000, + 'y': 3, + 'y0': 47 + }, + { + 'x': 1416851310000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416851340000, + 'y': 2, + 'y0': 39 + }, + { + 'x': 1416851370000, + 'y': 2, + 'y0': 42 + }, + { + 'x': 1416851400000, + 'y': 3, + 'y0': 48 + }, + { + 'x': 1416851430000, + 'y': 1, + 'y0': 45 + }, + { + 'x': 1416851460000, + 'y': 0, + 'y0': 52 + }, + { + 'x': 1416851490000, + 'y': 2, + 'y0': 40 + }, + { + 'x': 1416851520000, + 'y': 1, + 'y0': 40 + }, + { + 'x': 1416851550000, + 'y': 3, + 'y0': 39 + }, + { + 'x': 1416851580000, + 'y': 1, + 'y0': 46 + }, + { + 'x': 1416851610000, + 'y': 2, + 'y0': 41 + }, + { + 'x': 1416851640000, + 'y': 1, + 'y0': 42 + }, + { + 'x': 1416851670000, + 'y': 2, + 'y0': 34 + }, + { + 'x': 1416851700000, + 'y': 3, + 'y0': 37 + }, + { + 'x': 1416851730000, + 'y': 1, + 'y0': 39 + }, + { + 'x': 1416851760000, + 'y': 1, + 'y0': 33 + }, + { + 'x': 1416851790000, + 'y': 1, + 'y0': 38 + }, + { + 'x': 1416851820000, + 'y': 1, + 'y0': 37 + }, + { + 'x': 1416851850000, + 'y': 1, + 'y0': 39 + }, + { + 'x': 1416851880000, + 'y': 1, + 'y0': 31 + }, + { + 'x': 1416851910000, + 'y': 2, + 'y0': 45 + }, + { + 'x': 1416851940000, + 'y': 0, + 'y0': 39 + }, + { + 'x': 1416851970000, + 'y': 0, + 'y0': 60 + }, + { + 'x': 1416852000000, + 'y': 1, + 'y0': 33 + }, + { + 'x': 1416852030000, + 'y': 2, + 'y0': 33 + }, + { + 'x': 1416852060000, + 'y': 1, + 'y0': 46 + }, + { + 'x': 1416852090000, + 'y': 1, + 'y0': 27 + }, + { + 'x': 1416852120000, + 'y': 0, + 'y0': 23 + } + ] + } + ], + 'hits': 2595, + 'xAxisFormatter': function (thing) { + return moment(thing); + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/fixtures/vislib/mock_data/terms/_columns.js b/src/fixtures/vislib/mock_data/terms/_columns.js new file mode 100644 index 0000000000000..5ddb10819f5dd --- /dev/null +++ b/src/fixtures/vislib/mock_data/terms/_columns.js @@ -0,0 +1,142 @@ +var _ = require('lodash'); + +module.exports = { + 'columns': [ + { + 'label': 'logstash: index', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 110710 + }, + { + 'x': 'css', + 'y': 27376 + }, + { + 'x': 'png', + 'y': 16664 + }, + { + 'x': 'gif', + 'y': 11264 + }, + { + 'x': 'php', + 'y': 5448 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '2014.11.12: index', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 110643 + }, + { + 'x': 'css', + 'y': 27350 + }, + { + 'x': 'png', + 'y': 16648 + }, + { + 'x': 'gif', + 'y': 11257 + }, + { + 'x': 'php', + 'y': 5440 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '2014.11.11: index', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 67 + }, + { + 'x': 'css', + 'y': 26 + }, + { + 'x': 'png', + 'y': 16 + }, + { + 'x': 'gif', + 'y': 7 + }, + { + 'x': 'php', + 'y': 8 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171462 +}; diff --git a/src/fixtures/vislib/mock_data/terms/_rows.js b/src/fixtures/vislib/mock_data/terms/_rows.js new file mode 100644 index 0000000000000..46e06d57f2e4c --- /dev/null +++ b/src/fixtures/vislib/mock_data/terms/_rows.js @@ -0,0 +1,97 @@ +var _ = require('lodash'); + +module.exports = { + 'rows': [ + { + 'label': '0.0-1000.0: bytes', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 3378 + }, + { + 'x': 'css', + 'y': 762 + }, + { + 'x': 'png', + 'y': 527 + }, + { + 'x': 'gif', + 'y': 11258 + }, + { + 'x': 'php', + 'y': 653 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + }, + { + 'label': '1000.0-2000.0: bytes', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 6422 + }, + { + 'x': 'css', + 'y': 1591 + }, + { + 'x': 'png', + 'y': 430 + }, + { + 'x': 'gif', + 'y': 8 + }, + { + 'x': 'php', + 'y': 561 + } + ] + } + ], + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } + } + ], + 'hits': 171458 +}; diff --git a/src/fixtures/vislib/mock_data/terms/_series.js b/src/fixtures/vislib/mock_data/terms/_series.js new file mode 100644 index 0000000000000..f3732f6061764 --- /dev/null +++ b/src/fixtures/vislib/mock_data/terms/_series.js @@ -0,0 +1,48 @@ +var _ = require('lodash'); + +module.exports = { + 'label': '', + 'xAxisLabel': 'Top 5 extension', + 'yAxisLabel': 'Count of documents', + 'series': [ + { + 'values': [ + { + 'x': 'jpg', + 'y': 110710 + }, + { + 'x': 'css', + 'y': 27389 + }, + { + 'x': 'png', + 'y': 16661 + }, + { + 'x': 'gif', + 'y': 11269 + }, + { + 'x': 'php', + 'y': 5447 + } + ] + } + ], + 'hits': 171476, + 'xAxisFormatter': function (val) { + if (_.isObject(val)) { + return JSON.stringify(val); + } + else if (val == null) { + return ''; + } + else { + return '' + val; + } + }, + 'tooltipFormatter': function (d) { + return d; + } +}; diff --git a/src/kibana/.jshintrc b/src/kibana/.jshintrc deleted file mode 100644 index 01e95284c83cc..0000000000000 --- a/src/kibana/.jshintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../.jshintrc.browser" -} \ No newline at end of file diff --git a/src/kibana/components/agg_response/geo_json/_tooltip_formatter.js b/src/kibana/components/agg_response/geo_json/_tooltip_formatter.js deleted file mode 100644 index 65cc855357547..0000000000000 --- a/src/kibana/components/agg_response/geo_json/_tooltip_formatter.js +++ /dev/null @@ -1,41 +0,0 @@ -define(function (require) { - return function TileMapTooltipFormatter($compile, $rootScope, Private) { - var $ = require('jquery'); - var _ = require('lodash'); - - var fieldFormats = Private(require('registry/field_formats')); - var $tooltipScope = $rootScope.$new(); - var $el = $('
').html(require('text!components/agg_response/geo_json/_tooltip.html')); - $compile($el)($tooltipScope); - - return function tooltipFormatter(feature) { - if (!feature) return ''; - - var value = feature.properties.value; - var acr = feature.properties.aggConfigResult; - var vis = acr.aggConfig.vis; - - var metricAgg = acr.aggConfig; - var geoFormat = _.get(vis.aggs, 'byTypeName.geohash_grid[0].format'); - if (!geoFormat) geoFormat = fieldFormats.getDefaultInstance('geo_point'); - - $tooltipScope.details = [ - { - label: metricAgg.makeLabel(), - value: metricAgg.fieldFormatter()(value) - }, - { - label: 'Center', - value: geoFormat.convert({ - lat: feature.geometry.coordinates[1], - lon: feature.geometry.coordinates[0] - }) - } - ]; - - $tooltipScope.$apply(); - - return $el.html(); - }; - }; -}); diff --git a/src/kibana/components/agg_response/geo_json/geo_json.js b/src/kibana/components/agg_response/geo_json/geo_json.js deleted file mode 100644 index 8b95026636148..0000000000000 --- a/src/kibana/components/agg_response/geo_json/geo_json.js +++ /dev/null @@ -1,44 +0,0 @@ -define(function (require) { - return function TileMapConverterFn(Private, timefilter, $compile, $rootScope) { - var _ = require('lodash'); - - var rowsToFeatures = require('components/agg_response/geo_json/rowsToFeatures'); - var tooltipFormatter = Private(require('components/agg_response/geo_json/_tooltip_formatter')); - - return function (vis, table) { - - function columnIndex(schema) { - return _.findIndex(table.columns, function (col) { - return col.aggConfig.schema.name === schema; - }); - } - - var geoI = columnIndex('segment'); - var metricI = columnIndex('metric'); - var geoAgg = _.get(table.columns, [geoI, 'aggConfig']); - var metricAgg = _.get(table.columns, [metricI, 'aggConfig']); - - var features = rowsToFeatures(table, geoI, metricI); - var values = features.map(function (feature) { - return feature.properties.value; - }); - - return { - title: table.title(), - valueFormatter: metricAgg && metricAgg.fieldFormatter(), - tooltipFormatter: tooltipFormatter, - geohashGridAgg: geoAgg, - geoJson: { - type: 'FeatureCollection', - features: features, - properties: { - min: _.min(values), - max: _.max(values), - zoom: _.get(geoAgg, 'params.mapZoom'), - center: _.get(geoAgg, 'params.mapCenter') - } - } - }; - }; - }; -}); diff --git a/src/kibana/components/agg_response/hierarchical/_build_split.js b/src/kibana/components/agg_response/hierarchical/_build_split.js deleted file mode 100644 index 3f4501153b4af..0000000000000 --- a/src/kibana/components/agg_response/hierarchical/_build_split.js +++ /dev/null @@ -1,17 +0,0 @@ -define(function (require) { - return function biuldSplitProvider(Private) { - var transformer = Private(require('components/agg_response/hierarchical/_transform_aggregation')); - var collectKeys = require('components/agg_response/hierarchical/_collect_keys'); - return function (agg, metric, aggData) { - // Ceate the split structure - var split = { label: '', slices: { children: [] } }; - - // Transform the aggData into splits - split.slices.children = transformer(agg, metric, aggData); - - // Collect all the keys - split.names = collectKeys(split.slices.children); - return split; - }; - }; -}); diff --git a/src/kibana/components/agg_response/hierarchical/build_hierarchical_data.js b/src/kibana/components/agg_response/hierarchical/build_hierarchical_data.js deleted file mode 100644 index e688a7cfe475e..0000000000000 --- a/src/kibana/components/agg_response/hierarchical/build_hierarchical_data.js +++ /dev/null @@ -1,96 +0,0 @@ -define(function (require) { - return function buildHierarchicalDataProvider(Private, Notifier) { - var _ = require('lodash'); - var buildSplit = Private(require('components/agg_response/hierarchical/_build_split')); - var extractBuckets = require('components/agg_response/hierarchical/_extract_buckets'); - var createRawData = require('components/agg_response/hierarchical/_create_raw_data'); - var arrayToLinkedList = require('components/agg_response/hierarchical/_array_to_linked_list'); - var tooltipFormatter = Private(require('components/agg_response/hierarchical/_hierarchical_tooltip_formatter')); - - var AggConfigResult = require('components/vis/AggConfigResult'); - - var notify = new Notifier({ - location: 'Pie chart response converter' - }); - - return function (vis, resp) { - // Create a refrenece to the buckets - var buckets = vis.aggs.bySchemaGroup.buckets; - - - // Find the metric so it's easier to reference. - // TODO: Change this to support multiple metrics. - var metric = vis.aggs.bySchemaGroup.metrics[0]; - - // Link each agg to the next agg. This will be - // to identify the next bucket aggregation - buckets = arrayToLinkedList(buckets); - - // Create the raw data to be used in the spy panel - var raw = createRawData(vis, resp); - - // If buckets is falsy then we should just return the aggs - if (!buckets) { - var value = resp.aggregations - && resp.aggregations[metric.id] - && resp.aggregations[metric.id].value - || resp.hits.total; - return { - hits: resp.hits.total, - raw: raw, - names: ['_all'], - tooltipFormatter: tooltipFormatter(raw.columns), - slices: { - children: [ - { name: '_all', size: value } - ] - } - }; - } - - var firstAgg = buckets[0]; - var aggData = resp.aggregations[firstAgg.id]; - - if (!firstAgg._next && firstAgg.schema.name === 'split') { - notify.error('Splitting charts without splitting slices is not supported. Pretending that we are just splitting slices.'); - } - - // start with splitting slices - if (!firstAgg._next || firstAgg.schema.name === 'segment') { - var split = buildSplit(firstAgg, metric, aggData); - split.hits = resp.hits.total; - split.raw = raw; - split.tooltipFormatter = tooltipFormatter(raw.columns); - return split; - } - - // map the split aggregations into rows. - var rows = _.map(extractBuckets(aggData), function (bucket) { - var agg = firstAgg._next; - var split = buildSplit(agg, metric, bucket[agg.id]); - // Since splits display labels we need to set it. - split.label = firstAgg.fieldFormatter()(bucket.key); - - var displayName = firstAgg.fieldDisplayName(); - if (!_.isEmpty(displayName)) split.label += ': ' + displayName; - - split.tooltipFormatter = tooltipFormatter(raw.columns); - var aggConfigResult = new AggConfigResult(firstAgg, null, null, firstAgg.getKey(bucket)); - split.split = { aggConfig: firstAgg, aggConfigResult: aggConfigResult, key: bucket.key }; - _.each(split.slices.children, function (child) { - child.aggConfigResult.$parent = aggConfigResult; - }); - return split; - }); - - var result = { hits: resp.hits.total, raw: raw }; - if (firstAgg.params.row) { - result.rows = rows; - } else { - result.columns = rows; - } - - return result; - }; - }; -}); diff --git a/src/kibana/components/agg_response/index.js b/src/kibana/components/agg_response/index.js deleted file mode 100644 index d5fda98a15609..0000000000000 --- a/src/kibana/components/agg_response/index.js +++ /dev/null @@ -1,10 +0,0 @@ -define(function (require) { - return function NormalizeChartDataFactory(Private) { - return { - hierarchical: Private(require('components/agg_response/hierarchical/build_hierarchical_data')), - pointSeries: Private(require('components/agg_response/point_series/point_series')), - tabify: Private(require('components/agg_response/tabify/tabify')), - geoJson: Private(require('components/agg_response/geo_json/geo_json')) - }; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_response/point_series/_fake_x_aspect.js b/src/kibana/components/agg_response/point_series/_fake_x_aspect.js deleted file mode 100644 index f15390474908d..0000000000000 --- a/src/kibana/components/agg_response/point_series/_fake_x_aspect.js +++ /dev/null @@ -1,29 +0,0 @@ -define(function (require) { - return function PointSeriesFakeXAxis(Private) { - var AggConfig = Private(require('components/vis/AggConfig')); - var AggType = Private(require('components/agg_types/_agg_type')); - - var allAgg = new AggType({ - name: 'all', - title: 'All docs', - ordered: false, - hasNoDsl: true - }); - - return function makeFakeXAxis(vis) { - var fake = new AggConfig(vis, { - type: allAgg, - schema: vis.type.schemas.all.byName.segment - }); - - return { - i: -1, - agg: fake, - col: { - aggConfig: fake, - label: fake.makeLabel() - } - }; - }; - }; -}); diff --git a/src/kibana/components/agg_response/point_series/_get_aspects.js b/src/kibana/components/agg_response/point_series/_get_aspects.js deleted file mode 100644 index fd1158e7e0062..0000000000000 --- a/src/kibana/components/agg_response/point_series/_get_aspects.js +++ /dev/null @@ -1,59 +0,0 @@ -define(function (require) { - return function PointSeriesGetAspects(Private) { - var _ = require('lodash'); - var fakeXAspect = Private(require('components/agg_response/point_series/_fake_x_aspect')); - - var map = { - segment: 'x', - metric: 'y', - radius: 'z', - width: 'width', - group: 'series' - }; - - function columnToAspect(aspects, col, i) { - var schema = col.aggConfig.schema.name; - - var name = map[schema]; - if (!name) throw new TypeError('unknown schema name "' + schema + '"'); - - var aspect = { - i: i, - col: col, - agg: col.aggConfig - }; - - if (!aspects[name]) aspects[name] = []; - aspects[name].push(aspect); - } - - /** - * Identify and group the columns based on the aspect of the pointSeries - * they represent. - * - * @param {array} columns - the list of columns - * @return {object} - an object with a key for each aspect (see map). The values - * may be undefined, a single aspect, or an array of aspects. - */ - return function getAspects(vis, table) { - var aspects = _(table.columns) - // write each column into the aspects under it's group - .transform(columnToAspect, {}) - // unwrap groups that only have one value, and validate groups that have more - .transform(function (aspects, group, name) { - if (name !== 'y' && group.length > 1) { - throw new TypeError('Only multiple metrics are supported in point series'); - } - - aspects[name] = group.length > 1 ? group : group[0]; - }) - .value(); - - if (!aspects.x) { - aspects.x = fakeXAspect(vis); - } - - return aspects; - }; - }; -}); diff --git a/src/kibana/components/agg_response/point_series/_get_series.js b/src/kibana/components/agg_response/point_series/_get_series.js deleted file mode 100644 index 84c59e50d63b1..0000000000000 --- a/src/kibana/components/agg_response/point_series/_get_series.js +++ /dev/null @@ -1,56 +0,0 @@ -define(function (require) { - return function PointSeriesGetSeries(Private) { - var _ = require('lodash'); - var getPoint = Private(require('components/agg_response/point_series/_get_point')); - var addToSiri = Private(require('components/agg_response/point_series/_add_to_siri')); - - return function getSeries(rows, chart) { - var aspects = chart.aspects; - var multiY = _.isArray(aspects.y); - var yScale = chart.yScale; - var partGetPoint = _.partial(getPoint, aspects.x, aspects.series, yScale); - - var series = _(rows) - .transform(function (series, row) { - - if (!multiY) { - var point = partGetPoint(row, aspects.y, aspects.z); - if (point) addToSiri(series, point, point.series); - return; - } - - aspects.y.forEach(function (y) { - var point = partGetPoint(row, y, aspects.z); - if (!point) return; - - var prefix = point.series ? point.series + ': ' : ''; - var seriesId = prefix + y.agg.id; - var seriesLabel = prefix + y.col.title; - - addToSiri(series, point, seriesId, seriesLabel); - }); - - }, {}) - .values() - .value(); - - if (multiY) { - series = _.sortBy(series, function (siri) { - var firstVal = siri.values[0]; - var y; - - if (firstVal) { - var agg = firstVal.aggConfigResult.aggConfig; - y = _.find(aspects.y, function (y) { - return y.agg === agg; - }); - } - - return y ? y.i : series.length; - }); - } - - return series; - }; - }; -}); diff --git a/src/kibana/components/agg_response/point_series/_tooltip_formatter.js b/src/kibana/components/agg_response/point_series/_tooltip_formatter.js deleted file mode 100644 index 9a9a023cc9ad1..0000000000000 --- a/src/kibana/components/agg_response/point_series/_tooltip_formatter.js +++ /dev/null @@ -1,45 +0,0 @@ -define(function (require) { - return function PointSeriesTooltipFormatter($compile, $rootScope) { - var $ = require('jquery'); - - var $tooltipScope = $rootScope.$new(); - var $tooltip = $(require('text!components/agg_response/point_series/_tooltip.html')); - $compile($tooltip)($tooltipScope); - - return function tooltipFormatter(event) { - var datum = event.datum; - if (!datum || !datum.aggConfigResult) return ''; - - var details = $tooltipScope.details = []; - var result = { $parent: datum.aggConfigResult }; - - function addDetail(result) { - var agg = result.aggConfig; - var value = result.value; - - var detail = { - value: agg.fieldFormatter()(value), - label: agg.makeLabel() - }; - - if (agg === datum.aggConfigResult.aggConfig) { - detail.percent = event.percent; - if (datum.yScale != null) { - detail.value = agg.fieldFormatter()(value * datum.yScale); - } - } - - details.push(detail); - } - - datum.extraMetrics.forEach(addDetail); - while ((result = result.$parent) && result.aggConfig) { - addDetail(result); - } - - - $tooltipScope.$apply(); - return $tooltip[0].outerHTML; - }; - }; -}); diff --git a/src/kibana/components/agg_response/point_series/point_series.js b/src/kibana/components/agg_response/point_series/point_series.js deleted file mode 100644 index eece0f4b22fab..0000000000000 --- a/src/kibana/components/agg_response/point_series/point_series.js +++ /dev/null @@ -1,32 +0,0 @@ -define(function (require) { - return function PointSeriesProvider(Private) { - var _ = require('lodash'); - - var getSeries = Private(require('components/agg_response/point_series/_get_series')); - var getAspects = Private(require('components/agg_response/point_series/_get_aspects')); - var initYAxis = Private(require('components/agg_response/point_series/_init_y_axis')); - var initXAxis = Private(require('components/agg_response/point_series/_init_x_axis')); - var setupOrderedDateXAxis = Private(require('components/agg_response/point_series/_ordered_date_axis')); - var tooltipFormatter = Private(require('components/agg_response/point_series/_tooltip_formatter')); - - return function pointSeriesChartDataFromTable(vis, table) { - var chart = {}; - var aspects = chart.aspects = getAspects(vis, table); - - chart.tooltipFormatter = tooltipFormatter; - - initXAxis(chart); - initYAxis(chart); - - var datedX = aspects.x.agg.type.ordered && aspects.x.agg.type.ordered.date; - if (datedX) { - setupOrderedDateXAxis(vis, chart); - } - - chart.series = getSeries(table.rows, chart); - - delete chart.aspects; - return chart; - }; - }; -}); diff --git a/src/kibana/components/agg_response/tabify/_get_columns.js b/src/kibana/components/agg_response/tabify/_get_columns.js deleted file mode 100644 index be7ac725b2c8c..0000000000000 --- a/src/kibana/components/agg_response/tabify/_get_columns.js +++ /dev/null @@ -1,51 +0,0 @@ -define(function (require) { - return function GetColumnsProvider(Private) { - var _ = require('lodash'); - var AggConfig = Private(require('components/vis/AggConfig')); - - return function getColumns(vis, minimal) { - var aggs = vis.aggs.getResponseAggs(); - - if (minimal == null) minimal = !vis.isHierarchical(); - - if (!vis.aggs.bySchemaGroup.metrics) { - aggs.push(new AggConfig(vis, { - type: 'count', - schema: vis.type.schemas.metrics[0].name - })); - } - - // pick the columns - if (minimal) { - return aggs.map(function (agg) { - return { aggConfig: agg }; - }); - } - - // supposed to be bucket,...metrics,bucket,...metrics - var columns = []; - - // seperate the metrics - var grouped = _.groupBy(aggs, function (agg) { - return agg.schema.group; - }); - - if (!grouped.buckets) { - // return just the metrics, in column format - return grouped.metrics.map(function (agg) { - return { aggConfig: agg }; - }); - } - - // return the buckets, and after each place all of the metrics - grouped.buckets.forEach(function (agg, i) { - columns.push({ aggConfig: agg }); - grouped.metrics.forEach(function (metric) { - columns.push({ aggConfig: metric }); - }); - }); - - return columns; - }; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_response/tabify/_response_writer.js b/src/kibana/components/agg_response/tabify/_response_writer.js deleted file mode 100644 index 6c1b2426c3e4f..0000000000000 --- a/src/kibana/components/agg_response/tabify/_response_writer.js +++ /dev/null @@ -1,282 +0,0 @@ -define(function (require) { - return function TabbedAggResponseWriterProvider(Private) { - var _ = require('lodash'); - var Table = Private(require('components/agg_response/tabify/_table')); - var TableGroup = Private(require('components/agg_response/tabify/_table_group')); - var getColumns = Private(require('components/agg_response/tabify/_get_columns')); - - var AggConfigResult = require('components/vis/AggConfigResult'); - - _.class(SplitAcr).inherits(AggConfigResult); - function SplitAcr(agg, parent, key) { - SplitAcr.Super.call(this, agg, parent, key, key); - } - - /** - * Writer class that collects information about an aggregation response and - * produces a table, or a series of tables. - * - * @param {Vis} vis - the vis object to which the aggregation response correlates - */ - function TabbedAggResponseWriter(vis, opts) { - this.vis = vis; - this.opts = opts || {}; - this.rowBuffer = []; - - var visIsHier = vis.isHierarchical(); - - // do the options allow for splitting? we will only split if true and - // tabify calls the split method. - this.canSplit = this.opts.canSplit !== false; - - // should we allow partial rows to be included in the tables? if a - // partial row is found, it is filled with empty strings '' - this.partialRows = this.opts.partialRows == null ? visIsHier : this.opts.partialRows; - - // if true, we will not place metric columns after every bucket - // even if the vis is hierarchical. if false, and the vis is - // hierarchical, then we will display metric columns after - // every bucket col - this.minimalColumns = visIsHier ? !!this.opts.minimalColumns : true; - - // true if we can expect metrics to have been calculated - // for every bucket - this.metricsForAllBuckets = visIsHier; - - // if true, values will be wrapped in aggConfigResult objects which link them - // to their aggConfig and enable the filterbar and tooltip formatters - this.asAggConfigResults = !!this.opts.asAggConfigResults; - - this.columns = getColumns(vis, this.minimalColumns); - this.aggStack = _.pluck(this.columns, 'aggConfig'); - - this.root = new TableGroup(); - this.acrStack = []; - this.splitStack = [this.root]; - } - - /** - * Create a Table of TableGroup object, link it to it's parent (if any), and determine if - * it's the root - * - * @param {boolean} group - is this a TableGroup or just a normal Table - * @param {AggConfig} agg - the aggregation that create this table, only applies to groups - * @param {any} key - the bucketKey that this table relates to - * @return {Table/TableGroup} table - the created table - */ - TabbedAggResponseWriter.prototype._table = function (group, agg, key) { - var Class = (group) ? TableGroup : Table; - var table = new Class(); - var parent = this.splitStack[0]; - - if (group) { - table.aggConfig = agg; - table.key = key; - table.title = (table.fieldFormatter()(key)) + ': ' + agg.makeLabel() ; - } - - // link the parent and child - table.$parent = parent; - parent.tables.push(table); - - return table; - }; - - /** - * Enter into a split table, called for each bucket of a splitting agg. The new table - * is either created or located using the agg and key arguments, and then the block is - * executed with the table as it's this context. Within this function, you should - * walk into the remaining branches and end up writing some rows to the table. - * - * @param {aggConfig} agg - the aggConfig that created this split - * @param {Buckets} buckets - the buckets produces by the agg - * @param {function} block - a function to execute for each sub bucket - */ - TabbedAggResponseWriter.prototype.split = function (agg, buckets, block) { - var self = this; - - if (!self.canSplit) { - throw new Error('attempted to split when splitting is disabled'); - } - - self._removeAggFromColumns(agg); - - buckets.forEach(function (bucket, key) { - // find the existing split that we should extend - var tableGroup = _.find(self.splitStack[0].tables, { aggConfig: agg, key: key }); - // create the split if it doesn't exist yet - if (!tableGroup) tableGroup = self._table(true, agg, key); - - var splitAcr = false; - if (self.asAggConfigResults) { - splitAcr = self._injectParentSplit(agg, key); - } - - // push the split onto the stack so that it will receive written tables - self.splitStack.unshift(tableGroup); - - // call the block - if (_.isFunction(block)) block.call(self, bucket, key); - - // remove the split from the stack - self.splitStack.shift(); - splitAcr && _.pull(self.acrStack, splitAcr); - }); - }; - - TabbedAggResponseWriter.prototype._removeAggFromColumns = function (agg) { - var i = _.findIndex(this.columns, function (col) { - return col.aggConfig === agg; - }); - - // we must have already removed this column - if (i === -1) return; - - this.columns.splice(i, 1); - - if (this.minimalColumns) return; - - // hierarchical vis creats additional columns for each bucket - // we will remove those too - var mCol = this.columns.splice(i, 1).pop(); - var mI = _.findIndex(this.aggStack, function (agg) { - return agg === mCol.aggConfig; - }); - - if (mI > -1) this.aggStack.splice(mI, 1); - }; - - /** - * When a split is found while building the aggConfigResult tree, we - * want to push the split into the tree at another point. Since each - * branch in the tree is a double-linked list we need do some special - * shit to pull this off. - * - * @private - * @param {AggConfig} - The agg which produced the split bucket - * @param {any} - The value which identifies the bucket - * @return {SplitAcr} - the AggConfigResult created for the split bucket - */ - TabbedAggResponseWriter.prototype._injectParentSplit = function (agg, key) { - var oldList = this.acrStack; - var newList = this.acrStack = []; - - // walk from right to left through the old stack - // and move things to the new stack - var injected = false; - - if (!oldList.length) { - injected = new SplitAcr(agg, null, key); - newList.unshift(injected); - return injected; - } - - // walk from right to left, emptying the previous list - while (oldList.length) { - var acr = oldList.pop(); - - // ignore other splits - if (acr instanceof SplitAcr) { - newList.unshift(acr); - continue; - } - - // inject the split - if (!injected) { - injected = new SplitAcr(agg, newList[0], key); - newList.unshift(injected); - } - - var newAcr = new AggConfigResult(acr.aggConfig, newList[0], acr.value, acr.aggConfig.getKey(acr)); - newList.unshift(newAcr); - - // and replace the acr in the row buffer if its there - var rowI = this.rowBuffer.indexOf(acr); - if (rowI > -1) { - this.rowBuffer[rowI] = newAcr; - } - } - - return injected; - }; - - /** - * Push a value into the row, then run a block. Once the block is - * complete the value is pulled from the stack. - * - * @param {any} value - the value that should be added to the row - * @param {function} block - the function to run while this value is in the row - * @return {any} - the value that was added - */ - TabbedAggResponseWriter.prototype.cell = function (agg, value, block) { - if (this.asAggConfigResults) { - value = new AggConfigResult(agg, this.acrStack[0], value, value); - } - - var staskResult = this.asAggConfigResults && value.type === 'bucket'; - - this.rowBuffer.push(value); - if (staskResult) this.acrStack.unshift(value); - - if (_.isFunction(block)) block.call(this); - - this.rowBuffer.pop(value); - if (staskResult) this.acrStack.shift(); - - return value; - }; - - /** - * Create a new row by reading the row buffer. This will do nothing if - * the row is incomplete and the vis this data came from is NOT flagged as - * hierarchical. - * - * @param {array} [buffer] - optional buffer to use in place of the stored rowBuffer - * @return {undefined} - */ - TabbedAggResponseWriter.prototype.row = function (buffer) { - var cells = buffer || this.rowBuffer.slice(0); - - if (!this.partialRows && cells.length < this.columns.length) { - return; - } - - var split = this.splitStack[0]; - var table = split.tables[0] || this._table(false); - - while (cells.length < this.columns.length) cells.push(''); - table.rows.push(cells); - return table; - }; - - /** - * Get the actual response - * - * @return {object} - the final table-tree - */ - TabbedAggResponseWriter.prototype.response = function () { - var columns = this.columns; - - // give the columns some metadata - columns.map(function (col) { - col.title = col.aggConfig.makeLabel(); - }); - - // walk the tree and write the columns to each table - (function step(table, group) { - if (table.tables) table.tables.forEach(step); - else table.columns = columns.slice(0); - }(this.root)); - - if (this.canSplit) return this.root; - - var table = this.root.tables[0]; - if (!table) return; - - delete table.$parent; - return table; - }; - - return TabbedAggResponseWriter; - }; -}); diff --git a/src/kibana/components/agg_response/tabify/tabify.js b/src/kibana/components/agg_response/tabify/tabify.js deleted file mode 100644 index 8946848752a1e..0000000000000 --- a/src/kibana/components/agg_response/tabify/tabify.js +++ /dev/null @@ -1,103 +0,0 @@ -define(function (require) { - return function tabifyAggResponseProvider(Private, Notifier) { - var _ = require('lodash'); - - var AggConfig = Private(require('components/vis/AggConfig')); - var TabbedAggResponseWriter = Private(require('components/agg_response/tabify/_response_writer')); - var Buckets = Private(require('components/agg_response/tabify/_buckets')); - var notify = new Notifier({ location: 'agg_response/tabify'}); - - function tabifyAggResponse(vis, esResponse, respOpts) { - var write = new TabbedAggResponseWriter(vis, respOpts); - - var topLevelBucket = _.assign({}, esResponse.aggregations, { - doc_count: esResponse.hits.total - }); - - collectBucket(write, topLevelBucket); - - return write.response(); - } - - /** - * read an aggregation from a bucket, which is *might* be found at key (if - * the response came in object form), and will recurse down the aggregation - * tree and will pass the read values to the ResponseWriter. - * - * @param {object} bucket - a bucket from the aggResponse - * @param {undefined|string} key - the key where the bucket was found - * @returns {undefined} - */ - function collectBucket(write, bucket, key) { - var agg = write.aggStack.shift(); - - switch (agg.schema.group) { - case 'buckets': - var buckets = new Buckets(bucket[agg.id]); - if (buckets.length) { - var splitting = write.canSplit && agg.schema.name === 'split'; - if (splitting) { - write.split(agg, buckets, function forEachBucket(subBucket, key) { - collectBucket(write, subBucket, agg.getKey(subBucket), key); - }); - } else { - buckets.forEach(function (subBucket, key) { - write.cell(agg, agg.getKey(subBucket, key), function () { - collectBucket(write, subBucket, agg.getKey(subBucket, key)); - }); - }); - } - } else if (write.partialRows && write.metricsForAllBuckets && write.minimalColumns) { - // we don't have any buckets, but we do have metrics at this - // level, then pass all the empty buckets and jump back in for - // the metrics. - write.aggStack.unshift(agg); - passEmptyBuckets(write, bucket, key); - write.aggStack.shift(); - } else { - // we don't have any buckets, and we don't have isHierarchical - // data, so no metrics, just try to write the row - write.row(); - } - break; - case 'metrics': - var value = agg.getValue(bucket); - write.cell(agg, value, function () { - if (!write.aggStack.length) { - // row complete - write.row(); - } else { - // process the next agg at this same level - collectBucket(write, bucket, key); - } - }); - break; - } - - write.aggStack.unshift(agg); - } - - // write empty values for each bucket agg, then write - // the metrics from the initial bucket using collectBucket() - function passEmptyBuckets(write, bucket, key) { - var agg = write.aggStack.shift(); - - switch (agg.schema.group) { - case 'metrics': - // pass control back to collectBucket() - write.aggStack.unshift(agg); - collectBucket(write, bucket, key); - return; - - case 'buckets': - write.cell(agg, '', function () { - passEmptyBuckets(write, bucket, key); - }); - } - - write.aggStack.unshift(agg); - } - - return notify.timed('tabify agg response', tabifyAggResponse); - }; -}); diff --git a/src/kibana/components/agg_table/agg_table.less b/src/kibana/components/agg_table/agg_table.less deleted file mode 100644 index f90c56354f346..0000000000000 --- a/src/kibana/components/agg_table/agg_table.less +++ /dev/null @@ -1,43 +0,0 @@ -@import (reference) "lesshat.less"; -@import (reference) "../../styles/theme/_variables.less"; - -kbn-agg-table, -kbn-agg-table-group { - display: block; -} - -.agg-table { - .display(flex); - .flex(1, 1, auto); - .flex-direction(column); - - &-paginated { - .flex(1, 1, auto); - overflow: auto; - - tr:hover td { - background-color: lighten(@gray-lighter, 4%); - } - - .cell-hover:hover { - background-color: @gray-lighter; - } - - th i.fa-sort { - color: @gray-light; - } - } - - &-controls { - .flex(0, 0, auto); - .display(flex); - .align-items(center); - margin: 10px 5px; - - > paginate-controls { - .flex(1, 0, auto); - margin: 0; - padding: 0; - } - } -} diff --git a/src/kibana/components/agg_types/README.md b/src/kibana/components/agg_types/README.md deleted file mode 100644 index 35ad6465239c7..0000000000000 --- a/src/kibana/components/agg_types/README.md +++ /dev/null @@ -1,18 +0,0 @@ -| Private | module id | -| --- | --- | -| `true` | `components/agg_config/index` | - -```js -var aggTypes = Private(require('components/agg_types/index')); -``` - -Collection of `AggType` definition objects. See the [Vis component](../vis) for an overall explaination of how `AggTypes` are used. - -### Included - - - [`AggType`](_agg_type.js) - - `AggParam` - - [`BaseAggParam`](param_types/base.js) - - [`FieldAggParam`](param_types/field.js) - - [`OptionedAggParam`](param_types/optioned.js) - - [`AggParams`](_agg_params.js) \ No newline at end of file diff --git a/src/kibana/components/agg_types/_agg_params.js b/src/kibana/components/agg_types/_agg_params.js deleted file mode 100644 index b4a71b4cfc963..0000000000000 --- a/src/kibana/components/agg_types/_agg_params.js +++ /dev/null @@ -1,72 +0,0 @@ -define(function (require) { - return function AggParamsFactory(Private) { - require('filters/label'); - var _ = require('lodash'); - var IndexedArray = require('utils/indexed_array/index'); - - var paramTypeMap = { - field: Private(require('components/agg_types/param_types/field')), - optioned: Private(require('components/agg_types/param_types/optioned')), - regex: Private(require('components/agg_types/param_types/regex')), - string: Private(require('components/agg_types/param_types/string')), - json: Private(require('components/agg_types/param_types/raw_json')), - _default: Private(require('components/agg_types/param_types/base')) - }; - - /** - * Wraps a list of {{#crossLink "AggParam"}}{{/crossLink}} objects; owned by an {{#crossLink "AggType"}}{{/crossLink}} - * - * used to create: - * - `FieldAggParam` – When the config has `name: "field"` - * - `*AggParam` – When the type matches something in the map above - * - `BaseAggParam` – All other params - * - * @class AggParams - * @constructor - * @extends IndexedArray - * @param {object[]} params - array of params that get new-ed up as AggParam objects as descibed above - */ - _.class(AggParams).inherits(IndexedArray); - function AggParams(params) { - AggParams.Super.call(this, { - index: ['name'], - initialSet: params.map(function (config) { - var type = config.name === 'field' ? config.name : config.type; - var Class = paramTypeMap[type] || paramTypeMap._default; - return new Class(config); - }) - }); - } - - /** - * Reads an aggConfigs - * - * @method write - * @param {AggConfig} aggConfig - * the AggConfig object who's type owns these aggParams and contains the param values for our param defs - * @param {object} [locals] - * an array of locals that will be available to the write function (can be used to enhance - * the quality of things like date_histogram's "auto" interval) - * @return {object} output - * output of the write calls, reduced into a single object. A `params: {}` property is exposed on the - * output object which is used to create the agg dsl for the search request. All other properties - * are dependent on the AggParam#write methods which should be studied for each AggType. - */ - AggParams.prototype.write = function (aggConfig, locals) { - var output = { params: {} }; - locals = locals || {}; - - this.forEach(function (param) { - if (param.write) { - param.write(aggConfig, output, locals); - } else { - output.params[param.name] = aggConfig.params[param.name]; - } - }); - - return output; - }; - - return AggParams; - }; -}); diff --git a/src/kibana/components/agg_types/_agg_type.js b/src/kibana/components/agg_types/_agg_type.js deleted file mode 100644 index 09c9221153d51..0000000000000 --- a/src/kibana/components/agg_types/_agg_type.js +++ /dev/null @@ -1,141 +0,0 @@ -define(function (require) { - return function AggTypeFactory(Private) { - var _ = require('lodash'); - var AggParams = Private(require('components/agg_types/_agg_params')); - var fieldFormats = Private(require('registry/field_formats')); - - /** - * Generic AggType Constructor - * - * Used to create the values exposed by the agg_types module. - * - * @class AggType - * @private - * @param {object} config - used to set the properties of the AggType - */ - function AggType(config) { - - /** - * the unique, unchanging, name that we have assigned this aggType - * - * @property name - * @type {string} - */ - this.name = config.name; - - /** - * the name of the elasticsearch aggregation that this aggType represents. Usually just this.name - * - * @property name - * @type {string} - */ - this.dslName = config.dslName || config.name; - - /** - * the user friendly name that will be shown in the ui for this aggType - * - * @property title - * @type {string} - */ - this.title = config.title; - - /** - * a function that will be called when this aggType is assigned to - * an aggConfig, and that aggConfig is being rendered (in a form, chart, etc.). - * - * @method makeLabel - * @param {AggConfig} aggConfig - an agg config of this type - * @returns {string} - label that can be used in the ui to descripe the aggConfig - */ - this.makeLabel = config.makeLabel || _.constant(this.name); - - /** - * Describes if this aggType creates data that is ordered, and if that ordered data - * is some sort of time series. - * - * If the aggType does not create ordered data, set this to something "falsey". - * - * If this does create orderedData, then the value should be an object. - * - * If the orderdata is some sort of time series, `this.ordered` should be an object - * with the property `date: true` - * - * @property ordered - * @type {object|undefined} - */ - this.ordered = config.ordered; - - /** - * Flag that prevents this aggregation from being included in the dsl. This is only - * used by the count aggregation (currently) since it doesn't really exist and it's output - * is available on every bucket. - * - * @type {Boolean} - */ - this.hasNoDsl = !!config.hasNoDsl; - - /** - * The method to create a filter representation of the bucket - * @param {object} aggConfig The instance of the aggConfig - * @param {mixed} key The key for the bucket - * @returns {object} The filter - */ - this.createFilter = config.createFilter; - - /** - * An instance of {{#crossLink "AggParams"}}{{/crossLink}}. - * - * @property params - * @type {AggParams} - */ - this.params = config.params || []; - if (!(this.params instanceof AggParams)) { - // always append the raw JSON param - this.params.push({ - name: 'json', - type: 'json', - advanced: true - }); - - this.params = new AggParams(this.params); - } - - /** - * Designed for multi-value metric aggs, this method can return a - * set of AggConfigs that should replace this aggConfig in result sets - * that walk the AggConfig set. - * - * @method getResponseAggs - * @returns {array[AggConfig]|undefined} - an array of aggConfig objects - * that should replace this one, - * or undefined - */ - this.getResponseAggs = config.getResponseAggs || _.noop; - - /** - * A function that will be called each time an aggConfig of this type - * is created, giving the agg type a chance to modify the agg config - */ - this.decorateAggConfig = config.decorateAggConfig || null; - - if (config.getFormat) { - this.getFormat = config.getFormat; - } - } - - /** - * Pick a format for the values produced by this agg type, - * overriden by several metrics that always output a simple - * number - * - * @param {agg} agg - the agg to pick a format for - * @return {FieldFromat} - */ - AggType.prototype.getFormat = function (agg) { - var field = agg.field(); - return field ? field.format : fieldFormats.getDefaultInstance('string'); - }; - - return AggType; - }; -}); diff --git a/src/kibana/components/agg_types/buckets/_bucket_count_between.js b/src/kibana/components/agg_types/buckets/_bucket_count_between.js deleted file mode 100644 index 59b5ebab12585..0000000000000 --- a/src/kibana/components/agg_types/buckets/_bucket_count_between.js +++ /dev/null @@ -1,44 +0,0 @@ -define(function (require) { - return function BucketCountBetweenUtil() { - - /** - * Count the number of bucket aggs between two agg config objects owned - * by the same vis. - * - * If one of the two aggs was not found in the agg list, returns null. - * If a was found after b, the count will be negative - * If a was found first, the count will be positive. - * - * @param {AggConfig} aggConfigA - the aggConfig that is expected first - * @param {AggConfig} aggConfigB - the aggConfig that is expected second - * @return {null|number} - */ - function bucketCountBetween(aggConfigA, aggConfigB) { - var aggs = aggConfigA.vis.aggs.getRequestAggs(); - - var aIndex = aggs.indexOf(aggConfigA); - var bIndex = aggs.indexOf(aggConfigB); - - if (aIndex === -1 || bIndex === -1) { - return null; - } - - // return a negative distance, if b is before a - var negative = (aIndex > bIndex); - - var count = aggs - .slice(Math.min(aIndex, bIndex), Math.max(aIndex, bIndex)) - .reduce(function (count, cfg) { - if (cfg === aggConfigA || cfg === aggConfigB || cfg.schema.group !== 'buckets') { - return count; - } else { - return count + 1; - } - }, 0); - - return (negative ? -1 : 1) * count; - } - - return bucketCountBetween; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_types/buckets/create_filter/date_histogram.js b/src/kibana/components/agg_types/buckets/create_filter/date_histogram.js deleted file mode 100644 index acbecec937102..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/date_histogram.js +++ /dev/null @@ -1,17 +0,0 @@ -define(function (require) { - return function createDateHistogramFilterProvider(Private) { - var moment = require('moment'); - var buildRangeFilter = require('components/filter_manager/lib/range'); - - return function (agg, key) { - var start = moment(key); - var interval = agg.buckets.getInterval(); - - return buildRangeFilter(agg.params.field, { - gte: start.valueOf(), - lte: start.add(interval).subtract(1, 'ms').valueOf() - }, agg.vis.indexPattern); - }; - - }; -}); diff --git a/src/kibana/components/agg_types/buckets/create_filter/date_range.js b/src/kibana/components/agg_types/buckets/create_filter/date_range.js deleted file mode 100644 index f5710533ec97e..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/date_range.js +++ /dev/null @@ -1,19 +0,0 @@ -define(function (require) { - var dateRange = require('utils/date_range'); - - return function createDateRangeFilterProvider(config) { - var buildRangeFilter = require('components/filter_manager/lib/range'); - - return function (agg, key) { - var range = dateRange.parse(key, config.get('dateFormat')); - - var filter = {}; - if (range.from) filter.gte = +range.from; - if (range.to) filter.lt = +range.to; - if (range.to && range.from) filter.format = 'epoch_millis'; - - return buildRangeFilter(agg.params.field, filter, agg.vis.indexPattern); - }; - - }; -}); diff --git a/src/kibana/components/agg_types/buckets/create_filter/filters.js b/src/kibana/components/agg_types/buckets/create_filter/filters.js deleted file mode 100644 index b8d2c1d96ec37..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/filters.js +++ /dev/null @@ -1,15 +0,0 @@ -define(function (require) { - var buildQueryFilter = require('components/filter_manager/lib/query'); - var _ = require('lodash'); - return function CreateFilterFiltersProvider(Private) { - return function (aggConfig, key) { - // have the aggConfig write agg dsl params - var dslFilters = _.get(aggConfig.toDsl(), 'filters.filters'); - var filter = dslFilters[key]; - - if (filter) { - return buildQueryFilter(filter.query, aggConfig.vis.indexPattern.id); - } - }; - }; -}); diff --git a/src/kibana/components/agg_types/buckets/create_filter/histogram.js b/src/kibana/components/agg_types/buckets/create_filter/histogram.js deleted file mode 100644 index 302fec17e0709..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/histogram.js +++ /dev/null @@ -1,14 +0,0 @@ -define(function (require) { - var buildRangeFilter = require('components/filter_manager/lib/range'); - - return function createHistogramFitlerProvider(Private) { - return function (aggConfig, key) { - var value = parseInt(key, 10); - - return buildRangeFilter(aggConfig.params.field, { - gte: value, - lt: value + aggConfig.params.interval - }, aggConfig.vis.indexPattern); - }; - }; -}); diff --git a/src/kibana/components/agg_types/buckets/create_filter/ip_range.js b/src/kibana/components/agg_types/buckets/create_filter/ip_range.js deleted file mode 100644 index 8ec5e1bd208b1..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/ip_range.js +++ /dev/null @@ -1,20 +0,0 @@ -define(function (require) { - var CidrMask = require('utils/cidr_mask'); - var buildRangeFilter = require('components/filter_manager/lib/range'); - return function createIpRangeFilterProvider() { - return function (aggConfig, key) { - var range; - if (aggConfig.params.ipRangeType === 'mask') { - range = new CidrMask(key).getRange(); - } else { - var addresses = key.split(/\-/); - range = { - from: addresses[0], - to: addresses[1] - }; - } - - return buildRangeFilter(aggConfig.params.field, {gte: range.from, lte: range.to}, aggConfig.vis.indexPattern); - }; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_types/buckets/create_filter/range.js b/src/kibana/components/agg_types/buckets/create_filter/range.js deleted file mode 100644 index f3b74853d8291..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/range.js +++ /dev/null @@ -1,14 +0,0 @@ -define(function (require) { - var buildRangeFilter = require('components/filter_manager/lib/range'); - return function createRangeFilterProvider(Private) { - return function (aggConfig, key) { - var splits = key.split(/\-/); - var gte = Number(splits[0]); - var lt = Number(splits[1]); - return buildRangeFilter(aggConfig.params.field, { - gte: gte, - lt: lt - }, aggConfig.vis.indexPattern); - }; - }; -}); diff --git a/src/kibana/components/agg_types/buckets/create_filter/terms.js b/src/kibana/components/agg_types/buckets/create_filter/terms.js deleted file mode 100644 index 0745be5b82890..0000000000000 --- a/src/kibana/components/agg_types/buckets/create_filter/terms.js +++ /dev/null @@ -1,8 +0,0 @@ -define(function (require) { - var buildPhraseFilter = require('components/filter_manager/lib/phrase'); - return function createTermsFilterProvider(Private) { - return function (aggConfig, key) { - return buildPhraseFilter(aggConfig.params.field, key, aggConfig.vis.indexPattern); - }; - }; -}); diff --git a/src/kibana/components/agg_types/buckets/date_histogram.js b/src/kibana/components/agg_types/buckets/date_histogram.js deleted file mode 100644 index 33f0ea8c7b822..0000000000000 --- a/src/kibana/components/agg_types/buckets/date_histogram.js +++ /dev/null @@ -1,154 +0,0 @@ -define(function (require) { - return function DateHistogramAggType(timefilter, config, Private) { - var _ = require('lodash'); - var moment = require('moment'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var TimeBuckets = Private(require('components/time_buckets/time_buckets')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/date_histogram')); - var intervalOptions = Private(require('components/agg_types/buckets/_interval_options')); - - var tzOffset = moment().format('Z'); - - function getInterval(agg) { - var interval = _.get(agg, ['params', 'interval']); - if (interval && interval.val === 'custom') interval = _.get(agg, ['params', 'customInterval']); - return interval; - } - - function setBounds(agg, force) { - if (agg.buckets._alreadySet && !force) return; - agg.buckets._alreadySet = true; - agg.buckets.setBounds(agg.fieldIsTimeField() && timefilter.getActiveBounds()); - } - - require('filters/field_type'); - require('components/validateDateInterval'); - - return new BucketAggType({ - name: 'date_histogram', - title: 'Date Histogram', - ordered: { - date: true - }, - makeLabel: function (agg) { - var output = this.params.write(agg); - var params = output.params; - return params.field + ' per ' + (output.metricScaleText || output.bucketInterval.description); - }, - createFilter: createFilter, - decorateAggConfig: function () { - var buckets; - return { - buckets: { - configurable: true, - get: function () { - if (buckets) return buckets; - - buckets = new TimeBuckets(); - buckets.setInterval(getInterval(this)); - setBounds(this); - - return buckets; - } - } - }; - }, - params: [ - { - name: 'field', - filterFieldTypes: 'date', - default: function (agg) { - return agg.vis.indexPattern.timeFieldName; - }, - onChange: function (agg) { - if (_.get(agg, 'params.interval.val') === 'auto' && !agg.fieldIsTimeField()) { - delete agg.params.interval; - } - - setBounds(agg, true); - } - }, - - { - name: 'interval', - type: 'optioned', - deserialize: function (state) { - var interval = _.find(intervalOptions, {val: state}); - return interval || _.find(intervalOptions, function (option) { - // For upgrading from 4.0.x to 4.1.x - intervals are now stored as 'y' instead of 'year', - // but this maps the old values to the new values - return Number(moment.duration(1, state)) === Number(moment.duration(1, option.val)); - }); - }, - default: 'auto', - options: intervalOptions, - editor: require('text!components/agg_types/controls/interval.html'), - onRequest: function (agg) { - setBounds(agg, true); - }, - write: function (agg, output) { - setBounds(agg); - agg.buckets.setInterval(getInterval(agg)); - - var interval = agg.buckets.getInterval(); - output.bucketInterval = interval; - output.params.interval = interval.expression; - output.params.time_zone = tzOffset; - - var scaleMetrics = interval.scaled && interval.scale < 1; - if (scaleMetrics) { - scaleMetrics = _.every(agg.vis.aggs.bySchemaGroup.metrics, function (agg) { - return agg.type && (agg.type.name === 'count' || agg.type.name === 'sum'); - }); - } - - if (scaleMetrics) { - output.metricScale = interval.scale; - output.metricScaleText = interval.preScaled.description; - } - } - }, - - { - name: 'customInterval', - default: '2h', - write: _.noop - }, - - { - name: 'format' - }, - - { - name: 'min_doc_count', - default: 1 - }, - - { - name: 'extended_bounds', - default: {}, - write: function (agg, output) { - var val = agg.params.extended_bounds; - - if (val.min != null || val.max != null) { - output.params.extended_bounds = { - min: moment(val.min).valueOf(), - max: moment(val.max).valueOf() - }; - - return; - } - - var bounds = timefilter.getActiveBounds(); - if (bounds) { - output.params.extended_bounds = { - min: moment(bounds.min).valueOf(), - max: moment(bounds.max).valueOf() - }; - } - } - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/buckets/date_range.js b/src/kibana/components/agg_types/buckets/date_range.js deleted file mode 100644 index e45024c9bf8ef..0000000000000 --- a/src/kibana/components/agg_types/buckets/date_range.js +++ /dev/null @@ -1,47 +0,0 @@ -define(function (require) { - var moment = require('moment'); - var dateRange = require('utils/date_range'); - require('directives/validate_date_math'); - - return function DateRangeAggDefinition(Private, config) { - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/date_range')); - var fieldFormats = Private(require('registry/field_formats')); - - - return new BucketAggType({ - name: 'date_range', - title: 'Date Range', - createFilter: createFilter, - getKey: function (bucket, key, agg) { - var formatter; - if (agg.field()) { - formatter = agg.field().format.getConverterFor('text'); - } else { - formatter = fieldFormats.getDefaultInstance('date').getConverterFor('text'); - } - return dateRange.toString(bucket, formatter); - }, - getFormat: function () { - return fieldFormats.getDefaultInstance('string'); - }, - makeLabel: function (aggConfig) { - return aggConfig.params.field.displayName + ' date ranges'; - }, - params: [{ - name: 'field', - filterFieldTypes: 'date', - default: function (agg) { - return agg.vis.indexPattern.timeFieldName; - } - }, { - name: 'ranges', - default: [{ - from: 'now-1w/w', - to: 'now' - }], - editor: require('text!components/agg_types/controls/date_ranges.html') - }] - }); - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_types/buckets/filters.js b/src/kibana/components/agg_types/buckets/filters.js deleted file mode 100644 index 5066233309c43..0000000000000 --- a/src/kibana/components/agg_types/buckets/filters.js +++ /dev/null @@ -1,45 +0,0 @@ -define(function (require) { - return function FiltersAggDefinition(Private, Notifier) { - var _ = require('lodash'); - var angular = require('angular'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/filters')); - var decorateQuery = Private(require('components/courier/data_source/_decorate_query')); - var notif = new Notifier({ location: 'Filters Agg' }); - - return new BucketAggType({ - name: 'filters', - title: 'Filters', - createFilter: createFilter, - params: [ - { - name: 'filters', - editor: require('text!components/agg_types/controls/filters.html'), - default: [ {input: {}, label: ''} ], - write: function (aggConfig, output) { - var inFilters = aggConfig.params.filters; - if (!_.size(inFilters)) return; - - var outFilters = _.transform(inFilters, function (filters, filter) { - var input = filter.input; - if (!input) return notif.log('malformed filter agg params, missing "input" query'); - - var query = input.query; - if (!query) return notif.log('malformed filter agg params, missing "query" on input'); - - decorateQuery(query); - - var label = filter.label || _.get(query, 'query_string.query') || angular.toJson(query); - filters[label] = input; - }, {}); - - if (!_.size(outFilters)) return; - - var params = output.params || (output.params = {}); - params.filters = outFilters; - } - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/buckets/histogram.js b/src/kibana/components/agg_types/buckets/histogram.js deleted file mode 100644 index ccdf664c5ab68..0000000000000 --- a/src/kibana/components/agg_types/buckets/histogram.js +++ /dev/null @@ -1,72 +0,0 @@ -define(function (require) { - return function HistogramAggDefinition(Private) { - var _ = require('lodash'); - var moment = require('moment'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/histogram')); - - require('components/validateDateInterval'); - - return new BucketAggType({ - name: 'histogram', - title: 'Histogram', - ordered: {}, - makeLabel: function (aggConfig) { - return aggConfig.params.field.displayName; - }, - createFilter: createFilter, - params: [ - { - name: 'field', - filterFieldTypes: 'number' - }, - - { - name: 'interval', - editor: require('text!components/agg_types/controls/interval.html'), - write: function (aggConfig, output) { - output.params.interval = parseInt(aggConfig.params.interval, 10); - } - }, - - { - name: 'min_doc_count', - default: null, - editor: require('text!components/agg_types/controls/min_doc_count.html'), - write: function (aggConfig, output) { - if (aggConfig.params.min_doc_count) { - output.params.min_doc_count = 0; - } - } - }, - - { - name: 'extended_bounds', - default: {}, - editor: require('text!components/agg_types/controls/extended_bounds.html'), - write: function (aggConfig, output) { - var val = aggConfig.params.extended_bounds; - - if (val.min != null || val.max != null) { - output.params.extended_bounds = { - min: val.min, - max: val.max - }; - } - }, - - // called from the editor - shouldShow: function (aggConfig) { - var field = aggConfig.params.field; - if ( - field - && (field.type === 'number' || field.type === 'date') - ) { - return aggConfig.params.min_doc_count; - } - } - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/buckets/ip_range.js b/src/kibana/components/agg_types/buckets/ip_range.js deleted file mode 100644 index 80d4f5491d6a4..0000000000000 --- a/src/kibana/components/agg_types/buckets/ip_range.js +++ /dev/null @@ -1,46 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - require('directives/validate_ip'); - require('directives/validate_cidr_mask'); - - return function RangeAggDefinition(Private) { - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/ip_range')); - - return new BucketAggType({ - name: 'ip_range', - title: 'IPv4 Range', - createFilter: createFilter, - makeLabel: function (aggConfig) { - return aggConfig.params.field.displayName + ' IP ranges'; - }, - params: [ - { - name: 'field', - filterFieldTypes: 'ip' - }, { - name: 'ipRangeType', - default: 'fromTo', - write: _.noop - }, { - name: 'ranges', - default: { - fromTo: [ - {from: '0.0.0.0', to: '127.255.255.255'}, - {from: '128.0.0.0', to: '191.255.255.255'} - ], - mask: [ - {mask: '0.0.0.0/1'}, - {mask: '128.0.0.0/2'} - ] - }, - editor: require('text!components/agg_types/controls/ip_ranges.html'), - write: function (aggConfig, output) { - var ipRangeType = aggConfig.params.ipRangeType; - output.params.ranges = aggConfig.params.ranges[ipRangeType]; - } - } - ] - }); - }; -}); \ No newline at end of file diff --git a/src/kibana/components/agg_types/buckets/range.js b/src/kibana/components/agg_types/buckets/range.js deleted file mode 100644 index a6433716602e4..0000000000000 --- a/src/kibana/components/agg_types/buckets/range.js +++ /dev/null @@ -1,36 +0,0 @@ -define(function (require) { - return function RangeAggDefinition(Private) { - var _ = require('lodash'); - var moment = require('moment'); - var angular = require('angular'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/range')); - - return new BucketAggType({ - name: 'range', - title: 'Range', - createFilter: createFilter, - makeLabel: function (aggConfig) { - return aggConfig.params.field.displayName + ' ranges'; - }, - params: [ - { - name: 'field', - filterFieldTypes: ['number'] - }, - { - name: 'ranges', - default: [ - { from: 0, to: 1000 }, - { from: 1000, to: 2000 } - ], - editor: require('text!components/agg_types/controls/ranges.html'), - write: function (aggConfig, output) { - output.params.ranges = aggConfig.params.ranges; - output.params.keyed = true; - } - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/buckets/significant_terms.js b/src/kibana/components/agg_types/buckets/significant_terms.js deleted file mode 100644 index 57233333ebfd3..0000000000000 --- a/src/kibana/components/agg_types/buckets/significant_terms.js +++ /dev/null @@ -1,36 +0,0 @@ -define(function (require) { - return function SignificantTermsAggDefinition(Private) { - var _ = require('lodash'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/terms')); - - return new BucketAggType({ - name: 'significant_terms', - title: 'Significant Terms', - makeLabel: function (aggConfig) { - return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.displayName; - }, - createFilter: createFilter, - params: [ - { - name: 'field', - filterFieldTypes: 'string' - }, - { - name: 'size', - editor: require('text!components/agg_types/controls/order_and_size.html'), - }, - { - name: 'exclude', - type: 'regex', - advanced: true - }, - { - name: 'include', - type: 'regex', - advanced: true - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/buckets/terms.js b/src/kibana/components/agg_types/buckets/terms.js deleted file mode 100644 index c8277ffca7b0b..0000000000000 --- a/src/kibana/components/agg_types/buckets/terms.js +++ /dev/null @@ -1,177 +0,0 @@ -define(function (require) { - return function TermsAggDefinition(Private) { - var _ = require('lodash'); - var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type')); - var bucketCountBetween = Private(require('components/agg_types/buckets/_bucket_count_between')); - var AggConfig = Private(require('components/vis/AggConfig')); - var Schemas = Private(require('components/vis/Schemas')); - var createFilter = Private(require('components/agg_types/buckets/create_filter/terms')); - - var orderAggSchema = (new Schemas([ - { - group: 'none', - name: 'orderAgg', - title: 'Order Agg', - aggFilter: ['!percentiles', '!median', '!std_dev'] - } - ])).all[0]; - - function isNotType(type) { - return function (agg) { - var field = agg.params.field; - return !field || field.type !== type; - }; - } - - return new BucketAggType({ - name: 'terms', - title: 'Terms', - makeLabel: function (agg) { - var params = agg.params; - return params.field.displayName + ': ' + params.order.display; - }, - createFilter: createFilter, - params: [ - { - name: 'field', - scriptable: true, - filterFieldTypes: ['number', 'boolean', 'date', 'ip', 'string'] - }, - { - name: 'exclude', - type: 'regex', - advanced: true, - disabled: isNotType('string') - }, - { - name: 'include', - type: 'regex', - advanced: true, - disabled: isNotType('string') - }, - { - name: 'size', - default: 5 - }, - { - name: 'orderAgg', - type: AggConfig, - default: null, - editor: require('text!components/agg_types/controls/order_agg.html'), - serialize: function (orderAgg) { - return orderAgg.toJSON(); - }, - deserialize: function (state, agg) { - return this.makeOrderAgg(agg, state); - }, - makeOrderAgg: function (termsAgg, state) { - state = state || {}; - state.schema = orderAggSchema; - var orderAgg = new AggConfig(termsAgg.vis, state); - orderAgg.id = termsAgg.id + '-orderAgg'; - return orderAgg; - }, - controller: function ($scope) { - $scope.safeMakeLabel = function (agg) { - try { - return agg.makeLabel(); - } catch (e) { - return '- agg not valid -'; - } - }; - - var INIT = {}; // flag to know when prevOrderBy has changed - var prevOrderBy = INIT; - - $scope.$watch('responseValueAggs', updateOrderAgg); - $scope.$watch('agg.params.orderBy', updateOrderAgg); - - function updateOrderAgg() { - var agg = $scope.agg; - var aggs = agg.vis.aggs; - var params = agg.params; - var orderBy = params.orderBy; - var paramDef = agg.type.params.byName.orderAgg; - - // setup the initial value of orderBy - if (!orderBy && prevOrderBy === INIT) { - // abort until we get the responseValueAggs - if (!$scope.responseValueAggs) return; - params.orderBy = (_.first($scope.responseValueAggs) || { id: 'custom' }).id; - return; - } - - // track the previous value - prevOrderBy = orderBy; - - // we aren't creating a custom aggConfig - if (!orderBy || orderBy !== 'custom') { - params.orderAgg = null; - - if (orderBy === '_term') { - params.orderBy = '_term'; - return; - } - - // ensure that orderBy is set to a valid agg - if (!_.find($scope.responseValueAggs, { id: orderBy })) { - params.orderBy = null; - } - return; - } - - params.orderAgg = params.orderAgg || paramDef.makeOrderAgg(agg); - } - }, - write: function (agg, output) { - var vis = agg.vis; - var dir = agg.params.order.val; - var order = output.params.order = {}; - - var orderAgg = agg.params.orderAgg || vis.aggs.getResponseAggById(agg.params.orderBy); - - // TODO: This works around an Elasticsearch bug the always casts terms agg scripts to strings - // thus causing issues with filtering. This probably causes other issues since float might not - // be able to contain the number on the elasticsearch side - if (output.params.script) { - output.params.valueType = agg.field().type === 'number' ? 'float' : agg.field().type; - } - - if (!orderAgg) { - order[agg.params.orderBy || '_count'] = dir; - return; - } - - if (orderAgg.type.name === 'count') { - order._count = dir; - return; - } - - var orderAggId = orderAgg.id; - if (orderAgg.parentId) { - orderAgg = vis.aggs.byId[orderAgg.parentId]; - } - - output.subAggs = (output.subAggs || []).concat(orderAgg); - order[orderAggId] = dir; - } - }, - { - name: 'order', - type: 'optioned', - default: 'desc', - editor: require('text!components/agg_types/controls/order_and_size.html'), - options: [ - { display: 'Descending', val: 'desc' }, - { display: 'Ascending', val: 'asc' } - ], - write: _.noop // prevent default write, it's handled by orderAgg - }, - { - name: 'orderBy', - write: _.noop // prevent default write, it's handled by orderAgg - } - ] - }); - }; -}); diff --git a/src/kibana/components/agg_types/index.js b/src/kibana/components/agg_types/index.js deleted file mode 100644 index 69ce391f0ca0d..0000000000000 --- a/src/kibana/components/agg_types/index.js +++ /dev/null @@ -1,61 +0,0 @@ -define(function (require) { - return function AggTypeService(Private) { - var IndexedArray = require('utils/indexed_array/index'); - - var aggs = { - metrics: [ - Private(require('components/agg_types/metrics/count')), - Private(require('components/agg_types/metrics/avg')), - Private(require('components/agg_types/metrics/sum')), - Private(require('components/agg_types/metrics/median')), - Private(require('components/agg_types/metrics/min')), - Private(require('components/agg_types/metrics/max')), - Private(require('components/agg_types/metrics/std_deviation')), - Private(require('components/agg_types/metrics/cardinality')), - Private(require('components/agg_types/metrics/percentiles')), - Private(require('components/agg_types/metrics/percentile_ranks')) - ], - buckets: [ - Private(require('components/agg_types/buckets/date_histogram')), - Private(require('components/agg_types/buckets/histogram')), - Private(require('components/agg_types/buckets/range')), - Private(require('components/agg_types/buckets/date_range')), - Private(require('components/agg_types/buckets/ip_range')), - Private(require('components/agg_types/buckets/terms')), - Private(require('components/agg_types/buckets/filters')), - Private(require('components/agg_types/buckets/significant_terms')), - Private(require('components/agg_types/buckets/geo_hash')) - ] - }; - - Object.keys(aggs).forEach(function (type) { - aggs[type].forEach(function (agg) { - agg.type = type; - }); - }); - - - /** - * IndexedArray of Aggregation Types. - * - * These types form two groups, metric and buckets. - * - * @module agg_types - * @type {IndexedArray} - */ - return new IndexedArray({ - - /** - * @type {Array} - */ - index: ['name'], - - /** - * [group description] - * @type {Array} - */ - group: ['type'], - initialSet: aggs.metrics.concat(aggs.buckets) - }); - }; -}); diff --git a/src/kibana/components/agg_types/metrics/_metric_agg_type.js b/src/kibana/components/agg_types/metrics/_metric_agg_type.js deleted file mode 100644 index e7808ec3f0642..0000000000000 --- a/src/kibana/components/agg_types/metrics/_metric_agg_type.js +++ /dev/null @@ -1,43 +0,0 @@ -define(function (require) { - return function MetricAggTypeProvider(Private) { - var _ = require('lodash'); - var AggType = Private(require('components/agg_types/_agg_type')); - var fieldFormats = Private(require('registry/field_formats')); - - _.class(MetricAggType).inherits(AggType); - function MetricAggType(config) { - MetricAggType.Super.call(this, config); - - // allow overriding any value on the prototype - _.forOwn(config, function (val, key) { - if (_.has(MetricAggType.prototype, key)) { - this[key] = val; - } - }, this); - } - - /** - * Read the values for this metric from the - * @param {[type]} bucket [description] - * @return {[type]} [description] - */ - MetricAggType.prototype.getValue = function (agg, bucket) { - return bucket[agg.id].value; - }; - - /** - * Pick a format for the values produced by this agg type, - * overriden by several metrics that always output a simple - * number - * - * @param {agg} agg - the agg to pick a format for - * @return {FieldFromat} - */ - MetricAggType.prototype.getFormat = function (agg) { - var field = agg.field(); - return field ? field.format : fieldFormats.getDefaultInstance('number'); - }; - - return MetricAggType; - }; -}); diff --git a/src/kibana/components/agg_types/metrics/count.js b/src/kibana/components/agg_types/metrics/count.js deleted file mode 100644 index 8b6de55ff0c4d..0000000000000 --- a/src/kibana/components/agg_types/metrics/count.js +++ /dev/null @@ -1,21 +0,0 @@ -define(function (require) { - return function AggTypeMetricCountProvider(Private) { - var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type')); - var fieldFormats = Private(require('registry/field_formats')); - - return new MetricAggType({ - name: 'count', - title: 'Count', - hasNoDsl: true, - makeLabel: function () { - return 'Count'; - }, - getFormat: function () { - return fieldFormats.getDefaultInstance('number'); - }, - getValue: function (agg, bucket) { - return bucket.doc_count; - } - }); - }; -}); diff --git a/src/kibana/components/agg_types/metrics/median.js b/src/kibana/components/agg_types/metrics/median.js deleted file mode 100644 index 8efdd2e93c20d..0000000000000 --- a/src/kibana/components/agg_types/metrics/median.js +++ /dev/null @@ -1,29 +0,0 @@ -define(function (require) { - return function AggTypeMetricMaxProvider(Private) { - var _ = require('lodash'); - var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type')); - var getResponseAggConfig = Private(require('components/agg_types/metrics/_get_response_agg_config')); - var percentiles = Private(require('components/agg_types/metrics/percentiles')); - - return new MetricAggType({ - name: 'median', - dslName: 'percentiles', - title: 'Median', - makeLabel: function (aggConfig) { - return 'Median ' + aggConfig.params.field.displayName; - }, - params: [ - { - name: 'field', - filterFieldTypes: 'number' - }, - { - name: 'percents', - default: [50] - } - ], - getResponseAggs: percentiles.getResponseAggs, - getValue: percentiles.getValue - }); - }; -}); diff --git a/src/kibana/components/agg_types/metrics/percentiles.js b/src/kibana/components/agg_types/metrics/percentiles.js deleted file mode 100644 index a79352ae21a49..0000000000000 --- a/src/kibana/components/agg_types/metrics/percentiles.js +++ /dev/null @@ -1,53 +0,0 @@ -define(function (require) { - return function AggTypeMetricPercentilesProvider(Private) { - var _ = require('lodash'); - - var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type')); - var getResponseAggConfig = Private(require('components/agg_types/metrics/_get_response_agg_config')); - var ordinalSuffix = require('utils/ordinal_suffix'); - var fieldFormats = Private(require('registry/field_formats')); - - var percentsEditor = require('text!components/agg_types/controls/percentiles.html'); - // required by the percentiles editor - require('components/number_list/number_list'); - - var valueProps = { - makeLabel: function () { - return ordinalSuffix(this.key) + ' percentile of ' + this.fieldDisplayName(); - } - }; - - return new MetricAggType({ - name: 'percentiles', - title: 'Percentiles', - makeLabel: function (agg) { - return 'Percentiles of ' + agg.fieldDisplayName(); - }, - params: [ - { - name: 'field', - filterFieldTypes: 'number' - }, - { - name: 'percents', - editor: percentsEditor, - default: [1, 5, 25, 50, 75, 95, 99] - } - ], - getResponseAggs: function (agg) { - var ValueAggConfig = getResponseAggConfig(agg, valueProps); - - return agg.params.percents.map(function (percent) { - return new ValueAggConfig(percent); - }); - }, - getValue: function (agg, bucket) { - // percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we - // parse the keys and respond with the value that matches - return _.find(bucket[agg.parentId].values, function (value, key) { - return agg.key === parseFloat(key); - }); - } - }); - }; -}); diff --git a/src/kibana/components/agg_types/metrics/std_deviation.js b/src/kibana/components/agg_types/metrics/std_deviation.js deleted file mode 100644 index 65d35c452c937..0000000000000 --- a/src/kibana/components/agg_types/metrics/std_deviation.js +++ /dev/null @@ -1,61 +0,0 @@ -define(function (require) { - return function AggTypeMetricStandardDeviationProvider(Private) { - var _ = require('lodash'); - var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type')); - var getResponseAggConfig = Private(require('components/agg_types/metrics/_get_response_agg_config')); - - var responseAggConfigProps = { - valProp: function () { - var details = this.keyedDetails[this.key]; - return details.valProp; - }, - makeLabel: function () { - var details = this.keyedDetails[this.key]; - return details.title + ' of ' + this.fieldDisplayName(); - }, - keyedDetails: { - std_lower: { - valProp: ['std_deviation_bounds', 'lower'], - title: 'Lower Standard Deviation' - }, - avg: { - valProp: 'avg', - title: 'Average' - }, - std_upper: { - valProp: ['std_deviation_bounds', 'upper'], - title: 'Upper Standard Deviation' - } - } - }; - - return new MetricAggType({ - name: 'std_dev', - dslName: 'extended_stats', - title: 'Standard Deviation', - makeLabel: function (agg) { - return 'Standard Deviation of ' + agg.fieldDisplayName(); - }, - params: [ - { - name: 'field', - filterFieldTypes: 'number' - } - ], - - getResponseAggs: function (agg) { - var ValueAggConfig = getResponseAggConfig(agg, responseAggConfigProps); - - return [ - new ValueAggConfig('std_lower'), - new ValueAggConfig('avg'), - new ValueAggConfig('std_upper') - ]; - }, - - getValue: function (agg, bucket) { - return _.get(bucket[agg.parentId], agg.valProp()); - } - }); - }; -}); \ No newline at end of file diff --git a/src/kibana/components/bind.js b/src/kibana/components/bind.js deleted file mode 100644 index bb136d569d262..0000000000000 --- a/src/kibana/components/bind.js +++ /dev/null @@ -1,80 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var angular = require('angular'); - - require('modules').get('kibana') - .config(function ($provide) { - - function strictEquality(a, b) { - // are the values equal? or, are they both NaN? - return a === b || (a !== a && b !== b); - } - - function errorNotAssignable(source, target) { - throw Error('Unable to accept change to bound $scope property "' + source + '"' + - ' because source expression "' + target + '" is not assignable!'); - } - - $provide.decorator('$rootScope', function ($delegate, $parse) { - /** - * Two-way bind a value from scope to another property on scope. This - * allow values on scope that work like they do in an isolate scope, but - * without requiring one. - * - * @param {expression} to - the location on scope to bind to - * @param {expression} from - the location on scope to bind from - * @param {Scope} $sourceScope - the scope to read "from" expression from - * @return {undefined} - */ - $delegate.constructor.prototype.$bind = function (to, from, $sourceScope) { - var $source = $sourceScope || this.$parent; - var $target = this; - - // parse expressions - var $to = $parse(to); - if (!$to.assign) errorNotAssignable(to, from); - var $from = $parse(from); - $from.assignOrFail = $from.assign || function () { - // revert the change and throw an error, child writes aren't supported - $to($target, lastSourceVal = $from($source)); - errorNotAssignable(from, to); - }; - - // bind scopes to expressions - var getTarget = function () { return $to($target); }; - var setTarget = function (v) { return $to.assign($target, v); }; - var getSource = function () { return $from($source); }; - var setSource = function (v) { return $from.assignOrFail($source, v); }; - - // if we are syncing down a literal, then we use loose equality check - var strict = !$from.literal; - var compare = strict ? strictEquality : angular.equals; - - // to support writing from the child to the parent we need to know - // which source has changed. Track the source value and anytime it - // changes (even if the target value changed too) push from source - // to target. If the source hasn't changed then the change is from - // the target and push accordingly - var lastSourceVal = getSource(); - - // push the initial value down, start off in sync - setTarget(lastSourceVal); - - $target.$watch(function () { - var sourceVal = getSource(); - var targetVal = getTarget(); - - var outOfSync = !compare(sourceVal, targetVal); - var sourceChanged = outOfSync && !compare(sourceVal, lastSourceVal); - - if (sourceChanged) setTarget(sourceVal); - else if (outOfSync) setSource(targetVal); - - return lastSourceVal = sourceVal; - }, null, !strict); - }; - - return $delegate; - }); - }); -}); diff --git a/src/kibana/components/clipboard/clipboard.js b/src/kibana/components/clipboard/clipboard.js deleted file mode 100644 index 46f99320153d0..0000000000000 --- a/src/kibana/components/clipboard/clipboard.js +++ /dev/null @@ -1,49 +0,0 @@ -define(function (require) { - // ng-clip expects ZeroClipboard to be global, but it's AMD, so it never is - var ZeroClipboard = window.ZeroClipboard = require('zeroclipboard'); - require('ng-clip'); - - var $ = require('jquery'); - var html = require('text!components/clipboard/clipboard.html'); - var module = require('modules').get('kibana'); - - module.directive('kbnClipboard', function ($compile, $timeout) { - return { - restrict: 'E', - template: html, - replace: true, - scope: { - copyText: '=copy' - }, - transclude: true, - link: function ($scope, $el, attr) { - if (ZeroClipboard.isFlashUnusable()) { - $scope.disabled = true; - return; - } - - $scope.tipPlacement = attr.tipPlacement || 'top'; - $scope.tipText = attr.tipText || 'Copy to clipboard'; - $scope.tipConfirm = attr.tipConfirm = 'Copied!'; - $scope.icon = attr.icon || 'fa-clipboard'; - - $scope.shownText = $scope.tipText; - - $el.on('click', function () { - $scope.shownText = $scope.tipConfirm; - // Reposition tooltip to account for text length change - $('a', $el).mouseenter(); - }); - - $el.on('mouseleave', function () { - $scope.shownText = $scope.tipText; - }); - - $scope.$on('$destroy', function () { - $el.off('click'); - $el.off('mouseleave'); - }); - } - }; - }); -}); \ No newline at end of file diff --git a/src/kibana/components/comma_list_filter.js b/src/kibana/components/comma_list_filter.js deleted file mode 100644 index 7af78739743c1..0000000000000 --- a/src/kibana/components/comma_list_filter.js +++ /dev/null @@ -1,26 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - require('modules') - .get('kibana') - .filter('commaList', function () { - /** - * Angular filter that accepts either an array or a comma-seperated string - * and outputs either an array, or a comma-seperated string for presentation. - * - * @param {String|Array} input - The comma-seperated list or array - * @param {Boolean} inclusive - Should the list be joined with an "and"? - * @return {String} - */ - return function (input, inclusive) { - var list = _.commaSeperatedList(input); - if (list.length < 2) { - return list.join(''); - } - - var conj = inclusive ? ' and ' : ' or '; - return list.slice(0, -1).join(', ') + conj + _.last(list); - - }; - }); -}); diff --git a/src/kibana/components/config/config.js b/src/kibana/components/config/config.js deleted file mode 100644 index b47a05e7f87e1..0000000000000 --- a/src/kibana/components/config/config.js +++ /dev/null @@ -1,166 +0,0 @@ -define(function (require) { - var module = require('modules').get('kibana/config', [ - 'kibana/notify' - ]); - - var configFile = JSON.parse(require('text!config')); - configFile.elasticsearch = (function () { - var a = document.createElement('a'); - a.href = 'elasticsearch'; - return a.href; - }()); - - // allow the rest of the app to get the configFile easily - module.constant('configFile', configFile); - - // service for delivering config variables to everywhere else - module.service('config', function (Private, Notifier, kbnVersion, kbnSetup, $rootScope, buildNum) { - var config = this; - - var angular = require('angular'); - var _ = require('lodash'); - var defaults = Private(require('components/config/defaults')); - var DelayedUpdater = Private(require('components/config/_delayed_updater')); - var vals = Private(require('components/config/_vals')); - - var notify = new Notifier({ - location: 'Config' - }); - - // active or previous instance of DelayedUpdater. This will log and then process an - // update once it is requested by calling #set() or #clear(). - var updater; - - var DocSource = Private(require('components/courier/data_source/doc_source')); - var doc = (new DocSource()) - .index(configFile.kibana_index) - .type('config') - .id(kbnVersion); - - /****** - * PUBLIC API - ******/ - - config.file = configFile; - - /** - * Executes once and returns a promise that is resolved once the - * config has loaded for the first time. - * - * @return {Promise} - Resolved when the config loads initially - */ - config.init = _.once(function () { - var complete = notify.lifecycle('config init'); - return kbnSetup() - .then(function getDoc() { - - // used to apply an entire es response to the vals, silentAndLocal will prevent - // event/notifications/writes from occuring. - var applyMassUpdate = function (resp, silentAndLocal) { - _.union(_.keys(resp._source), _.keys(vals)).forEach(function (key) { - change(key, resp._source[key], silentAndLocal); - }); - }; - - return doc.fetch().then(function initDoc(resp) { - if (!resp.found) { - return doc.doIndex({ - buildNum: buildNum - }).then(getDoc); - } else { - // apply update, and keep it quiet the first time - applyMassUpdate(resp, true); - - // don't keep it quiet other times - doc.onUpdate(function (resp) { - applyMassUpdate(resp, false); - }); - } - }); - }) - .then(function () { - $rootScope.$broadcast('init:config'); - }) - .then(complete, complete.failure); - }); - - config.get = function (key, defaultVal) { - var keyVal; - - if (vals[key] == null) { - if (defaultVal == null) { - keyVal = defaults[key].value; - } else { - keyVal = _.cloneDeep(defaultVal); - } - } else { - keyVal = vals[key]; - } - - if (defaults[key] && defaults[key].type === 'json') { - return JSON.parse(keyVal); - } - return keyVal; - }; - - // sets a value in the config - config.set = function (key, val) { - if (_.isPlainObject(val)) { - return change(key, angular.toJson(val)); - } else { - return change(key, val); - } - }; - - // clears a value from the config - config.clear = function (key) { - return change(key); - }; - // alias for clear - config.delete = config.clear; - - config.close = function () { - if (updater) updater.fire(); - }; - - /** - * A little helper for binding config variables to $scopes - * - * @param {Scope} $scope - an angular $scope object - * @param {string} key - the config key to bind to - * @param {string} [property] - optional property name where the value should - * be stored. Defaults to the config key - * @return {function} - an unbind function - */ - config.$bind = function ($scope, key, property) { - if (!property) property = key; - - var update = function () { - $scope[property] = config.get(key); - }; - - update(); - return _.partial(_.invoke, [ - $scope.$on('change:config.' + key, update), - $scope.$on('init:config', update) - ], 'call'); - }; - - /***** - * PRIVATE API - *****/ - var change = function (key, val, silentAndLocal) { - // if the previous updater has already fired, then start over with null - if (updater && updater.fired) updater = null; - // create a new updater - if (!updater) updater = new DelayedUpdater(doc); - // return a promise that will be resolved once the action is eventually done - return updater.update(key, val, silentAndLocal); - }; - - config._vals = function () { - return _.cloneDeep(vals); - }; - - }); -}); diff --git a/src/kibana/components/courier/courier.js b/src/kibana/components/courier/courier.js deleted file mode 100644 index 5c073815ed7fc..0000000000000 --- a/src/kibana/components/courier/courier.js +++ /dev/null @@ -1,139 +0,0 @@ -define(function (require) { - var errors = require('errors'); - var _ = require('lodash'); - - require('services/es'); - require('services/promises'); - require('components/index_patterns/index_patterns'); - - require('modules').get('kibana/courier') - .service('courier', function ($rootScope, Private, Promise, indexPatterns, Notifier) { - function Courier() { - var self = this; - - var DocSource = Private(require('components/courier/data_source/doc_source')); - var SearchSource = Private(require('components/courier/data_source/search_source')); - var searchStrategy = Private(require('components/courier/fetch/strategy/search')); - - var requestQueue = Private(require('components/courier/_request_queue')); - var errorHandlers = Private(require('components/courier/_error_handlers')); - - var fetch = Private(require('components/courier/fetch/fetch')); - var docLooper = self.docLooper = Private(require('components/courier/looper/doc')); - var searchLooper = self.searchLooper = Private(require('components/courier/looper/search')); - - // expose some internal modules - self.setRootSearchSource = Private(require('components/courier/data_source/_root_search_source')).set; - - self.SavedObject = Private(require('components/courier/saved_object/saved_object')); - self.indexPatterns = indexPatterns; - self.redirectWhenMissing = Private(require('components/courier/_redirect_when_missing')); - - self.DocSource = DocSource; - self.SearchSource = SearchSource; - - var HastyRefresh = errors.HastyRefresh; - - /** - * update the time between automatic search requests - * - * @chainable - */ - self.fetchInterval = function (ms) { - searchLooper.ms(ms); - return this; - }; - - /** - * Start fetching search requests on an interval - * @chainable - */ - self.start = function () { - searchLooper.start(); - docLooper.start(); - return this; - }; - - /** - * Process the pending request queue right now, returns - * a promise that resembles the success of the fetch completing, - * individual errors are routed to their respective requests. - */ - self.fetch = function () { - fetch.fetchQueued(searchStrategy).then(function () { - searchLooper.restart(); - }); - }; - - - /** - * is the currior currently fetching search - * results automatically? - * - * @return {boolean} - */ - self.started = function () { - return searchLooper.started(); - }; - - - /** - * stop the courier from fetching more search - * results, does not stop vaidating docs. - * - * @chainable - */ - self.stop = function () { - searchLooper.stop(); - return this; - }; - - - /** - * create a source object that is a child of this courier - * - * @param {string} type - the type of Source to create - */ - self.createSource = function (type) { - switch (type) { - case 'doc': - return new DocSource(); - case 'search': - return new SearchSource(); - } - }; - - /** - * Abort all pending requests - * @return {[type]} [description] - */ - self.close = function () { - searchLooper.stop(); - docLooper.stop(); - - _.invoke(requestQueue, 'abort'); - - if (requestQueue.length) { - throw new Error('Aborting all pending requests failed.'); - } - }; - - // Listen for refreshInterval changes - $rootScope.$watchCollection('timefilter.refreshInterval', function () { - var refreshValue = _.get($rootScope, 'timefilter.refreshInterval.value'); - var refreshPause = _.get($rootScope, 'timefilter.refreshInterval.pause'); - if (_.isNumber(refreshValue) && !refreshPause) { - self.fetchInterval(refreshValue); - } else { - self.fetchInterval(0); - } - }); - - var onFatalDefer = Promise.defer(); - onFatalDefer.promise.then(self.close); - Notifier.fatalCallbacks.push(onFatalDefer.resolve); - } - - return new Courier(); - }); -}); diff --git a/src/kibana/components/courier/fetch/_call_response_handlers.js b/src/kibana/components/courier/fetch/_call_response_handlers.js deleted file mode 100644 index c1cf0e117f349..0000000000000 --- a/src/kibana/components/courier/fetch/_call_response_handlers.js +++ /dev/null @@ -1,57 +0,0 @@ -define(function (require) { - return function CourierFetchCallResponseHandlers(Private, Promise) { - var ABORTED = Private(require('components/courier/fetch/_req_status')).ABORTED; - var INCOMPLETE = Private(require('components/courier/fetch/_req_status')).INCOMPLETE; - var notify = Private(require('components/courier/fetch/_notifier')); - - var SearchTimeout = require('errors').SearchTimeout; - var RequestFailure = require('errors').RequestFailure; - var ShardFailure = require('errors').ShardFailure; - - function callResponseHandlers(requests, responses) { - return Promise.map(requests, function (req, i) { - if (req === ABORTED || req.aborted) { - return ABORTED; - } - - var resp = responses[i]; - - if (resp.timed_out) { - notify.warning(new SearchTimeout()); - } - - if (resp._shards && resp._shards.failed) { - notify.warning(new ShardFailure(resp)); - } - - function progress() { - if (req.isIncomplete()) { - return INCOMPLETE; - } - - req.complete(); - return resp; - } - - if (resp.error) { - if (req.filterError(resp)) { - return progress(); - } else { - return req.handleFailure(new RequestFailure(null, resp)); - } - } - - return Promise.try(function () { - return req.transformResponse(resp); - }) - .then(function () { - resp = arguments[0]; - return req.handleResponse(resp); - }) - .then(progress); - }); - } - - return callResponseHandlers; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/courier/fetch/_fetch_these.js b/src/kibana/components/courier/fetch/_fetch_these.js deleted file mode 100644 index 125d2bef2465d..0000000000000 --- a/src/kibana/components/courier/fetch/_fetch_these.js +++ /dev/null @@ -1,68 +0,0 @@ -define(function (require) { - return function FetchTheseProvider(Private, Promise) { - var notify = Private(require('components/courier/fetch/_notifier')); - var forEachStrategy = Private(require('components/courier/fetch/_for_each_strategy')); - - // core tasks - var callClient = Private(require('components/courier/fetch/_call_client')); - var callResponseHandlers = Private(require('components/courier/fetch/_call_response_handlers')); - var continueIncomplete = Private(require('components/courier/fetch/_continue_incomplete')); - - var ABORTED = Private(require('components/courier/fetch/_req_status')).ABORTED; - var DUPLICATE = Private(require('components/courier/fetch/_req_status')).DUPLICATE; - var INCOMPLETE = Private(require('components/courier/fetch/_req_status')).INCOMPLETE; - - function fetchThese(requests) { - return forEachStrategy(requests, function (strategy, requests) { - return fetchWithStrategy(strategy, requests.map(function (req) { - if (!req.started) return req; - return req.retry(); - })); - }) - .catch(notify.fatal); - } - - function fetchWithStrategy(strategy, requests) { - - requests = requests.map(function (req) { - if (req.aborted) { - return ABORTED; - } - - if (req.started) { - req.continue(); - } else { - req.start(); - } - - return req; - }); - - return Promise.resolve() - .then(function () { - return callClient(strategy, requests); - }) - .then(function (responses) { - return callResponseHandlers(requests, responses); - }) - .then(function (responses) { - return continueIncomplete(strategy, requests, responses, fetchWithStrategy); - }) - .then(function (responses) { - return responses.map(function (resp) { - switch (resp) { - case ABORTED: - return null; - case DUPLICATE: - case INCOMPLETE: - throw new Error('Failed to clear incomplete or duplicate request from responses.'); - default: - return resp; - } - }); - }); - } - - return fetchThese; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/courier/fetch/_is_request.js b/src/kibana/components/courier/fetch/_is_request.js deleted file mode 100644 index 51d022e856866..0000000000000 --- a/src/kibana/components/courier/fetch/_is_request.js +++ /dev/null @@ -1,9 +0,0 @@ -define(function (require) { - return function CourierFetchIsRequestProvider(Private) { - var AbstractRequest = Private(require('components/courier/fetch/request/request')); - - return function isRequest(obj) { - return obj instanceof AbstractRequest; - }; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/courier/fetch/request/_error_handler.js b/src/kibana/components/courier/fetch/request/_error_handler.js deleted file mode 100644 index 6e4be03abda6e..0000000000000 --- a/src/kibana/components/courier/fetch/request/_error_handler.js +++ /dev/null @@ -1,27 +0,0 @@ -define(function (require) { - return function RequestErrorHandlerFactory(Private, Notifier) { - var errHandlers = Private(require('components/courier/_error_handlers')); - - var notify = new Notifier({ - location: 'Courier Fetch Error' - }); - - function handleError(req, error) { - var myHandlers = []; - - errHandlers.splice(0).forEach(function (handler) { - (handler.source === req.source ? myHandlers : errHandlers).push(handler); - }); - - if (!myHandlers.length) { - notify.fatal(new Error('unhandled error ' + (error.stack || error.message))); - } else { - myHandlers.forEach(function (handler) { - handler.defer.resolve(error); - }); - } - } - - return handleError; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/courier/fetch/request/doc.js b/src/kibana/components/courier/fetch/request/doc.js deleted file mode 100644 index bf27485bd8d93..0000000000000 --- a/src/kibana/components/courier/fetch/request/doc.js +++ /dev/null @@ -1,42 +0,0 @@ -define(function (require) { - return function DocRequestProvider(Private) { - var _ = require('lodash'); - - var docStrategy = Private(require('components/courier/fetch/strategy/doc')); - var AbstractRequest = Private(require('components/courier/fetch/request/request')); - - _.class(DocRequest).inherits(AbstractRequest); - function DocRequest(source, defer) { - DocRequest.Super.call(this, source, defer); - - this.type = 'doc'; - this.strategy = docStrategy; - } - - DocRequest.prototype.canStart = function () { - var parent = DocRequest.Super.prototype.canStart.call(this); - if (!parent) return false; - - var version = this.source._version; - var storedVersion = this.source._getStoredVersion(); - - // conditions that equal "fetch This DOC!" - var unkown = !version && !storedVersion; - var mismatch = version !== storedVersion; - - return Boolean(mismatch || (unkown && !this.started)); - }; - - DocRequest.prototype.handleResponse = function (resp) { - if (resp.found) { - this.source._storeVersion(resp._version); - } else { - this.source._clearVersion(); - } - - return DocRequest.Super.prototype.handleResponse.call(this, resp); - }; - - return DocRequest; - }; -}); diff --git a/src/kibana/components/courier/fetch/request/search.js b/src/kibana/components/courier/fetch/request/search.js deleted file mode 100644 index 6b6846595395b..0000000000000 --- a/src/kibana/components/courier/fetch/request/search.js +++ /dev/null @@ -1,19 +0,0 @@ -define(function (require) { - return function SearchReqProvider(Private) { - var _ = require('lodash'); - - var searchStrategy = Private(require('components/courier/fetch/strategy/search')); - var AbstractRequest = Private(require('components/courier/fetch/request/request')); - - _.class(SearchReq).inherits(AbstractRequest); - var Super = SearchReq.Super; - function SearchReq(source, defer) { - Super.call(this, source, defer); - - this.type = 'search'; - this.strategy = searchStrategy; - } - - return SearchReq; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/courier/fetch/strategy/search.js b/src/kibana/components/courier/fetch/strategy/search.js deleted file mode 100644 index f8aa674f928eb..0000000000000 --- a/src/kibana/components/courier/fetch/strategy/search.js +++ /dev/null @@ -1,45 +0,0 @@ -define(function (require) { - return function FetchStrategyForSearch(Private, Promise, timefilter, configFile) { - var _ = require('lodash'); - var angular = require('angular'); - - return { - clientMethod: 'msearch', - - /** - * Flatten a series of requests into as ES request body - * - * @param {array} requests - the requests to serialize - * @return {string} - the request body - */ - reqsFetchParamsToBody: function (reqsFetchParams) { - return reqsFetchParams.map(function (fetchParams) { - var indexList = fetchParams.index; - - if (_.isFunction(_.get(indexList, 'toIndexList'))) { - var timeBounds = timefilter.getBounds(); - indexList = indexList.toIndexList(timeBounds.min, timeBounds.max); - } - - return angular.toJson({ - index: indexList, - type: fetchParams.type, - search_type: fetchParams.search_type, - ignore_unavailable: true - }) - + '\n' - + angular.toJson(fetchParams.body || {}); - }).join('\n') + '\n'; - }, - - /** - * Fetch the multiple responses from the ES Response - * @param {object} resp - The response sent from Elasticsearch - * @return {array} - the list of responses - */ - getResponses: function (resp) { - return resp.responses; - } - }; - }; -}); diff --git a/src/kibana/components/courier/looper/doc.js b/src/kibana/components/courier/looper/doc.js deleted file mode 100644 index 57bcbbcf74bdd..0000000000000 --- a/src/kibana/components/courier/looper/doc.js +++ /dev/null @@ -1,17 +0,0 @@ -define(function (require) { - return function DocLooperService(Private) { - var fetch = Private(require('components/courier/fetch/fetch')); - var Looper = Private(require('components/courier/looper/_looper')); - var docStrategy = Private(require('components/courier/fetch/strategy/doc')); - - /** - * The Looper which will manage the doc fetch interval - * @type {Looper} - */ - var docLooper = new Looper(1500, function () { - fetch.fetchQueued(docStrategy); - }); - - return docLooper; - }; -}); diff --git a/src/kibana/components/courier/looper/search.js b/src/kibana/components/courier/looper/search.js deleted file mode 100644 index c8191e9beb6ef..0000000000000 --- a/src/kibana/components/courier/looper/search.js +++ /dev/null @@ -1,27 +0,0 @@ -define(function (require) { - return function SearchLooperService(Private, Promise, Notifier, $rootScope) { - var fetch = Private(require('components/courier/fetch/fetch')); - var searchStrategy = Private(require('components/courier/fetch/strategy/search')); - var requestQueue = Private(require('components/courier/_request_queue')); - - var Looper = Private(require('components/courier/looper/_looper')); - var notif = new Notifier({ location: 'Search Looper' }); - - /** - * The Looper which will manage the doc fetch interval - * @type {Looper} - */ - var searchLooper = new Looper(null, function () { - $rootScope.$broadcast('courier:searchRefresh'); - return fetch.these( - requestQueue.getInactive(searchStrategy) - ); - }); - - searchLooper.onHastyLoop = function () { - notif.warning('Skipping search attempt because previous search request has not completed'); - }; - - return searchLooper; - }; -}); diff --git a/src/kibana/components/doc_table/doc_table.js b/src/kibana/components/doc_table/doc_table.js deleted file mode 100644 index d2c04a69d24fc..0000000000000 --- a/src/kibana/components/doc_table/doc_table.js +++ /dev/null @@ -1,115 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - var html = require('text!components/doc_table/doc_table.html'); - var getSort = require('components/doc_table/lib/get_sort'); - - require('css!components/doc_table/doc_table.css'); - require('directives/truncated'); - require('directives/infinite_scroll'); - require('components/doc_table/components/table_header'); - require('components/doc_table/components/table_row'); - - require('modules').get('kibana') - .directive('docTable', function (config, Notifier, getAppState) { - return { - restrict: 'E', - template: html, - scope: { - sorting: '=', - columns: '=', - hits: '=?', // You really want either hits & indexPattern, OR searchSource - indexPattern: '=?', - searchSource: '=?', - infiniteScroll: '=?', - filter: '=?', - }, - link: function ($scope) { - var notify = new Notifier(); - $scope.limit = 50; - $scope.persist = { - sorting: $scope.sorting, - columns: $scope.columns - }; - - var prereq = (function () { - var fns = []; - - return function register(fn) { - fns.push(fn); - - return function () { - fn.apply(this, arguments); - - if (fns.length) { - _.pull(fns, fn); - if (!fns.length) { - $scope.$root.$broadcast('ready:vis'); - } - } - }; - }; - }()); - - $scope.addRows = function () { - $scope.limit += 50; - }; - - // This exists to fix the problem of an empty initial column list not playing nice with watchCollection. - $scope.$watch('columns', function (columns) { - if (columns.length !== 0) return; - - var $state = getAppState(); - $scope.columns.push('_source'); - if ($state) $state.replace(); - }); - - $scope.$watchCollection('columns', function (columns, oldColumns) { - if (oldColumns.length === 1 && oldColumns[0] === '_source' && $scope.columns.length > 1) { - _.pull($scope.columns, '_source'); - } - - if ($scope.columns.length === 0) $scope.columns.push('_source'); - }); - - - $scope.$watch('searchSource', prereq(function (searchSource) { - if (!$scope.searchSource) return; - - $scope.indexPattern = $scope.searchSource.get('index'); - - $scope.searchSource.size(config.get('discover:sampleSize')); - $scope.searchSource.sort(getSort($scope.sorting, $scope.indexPattern)); - - // Set the watcher after initialization - $scope.$watchCollection('sorting', function (newSort, oldSort) { - // Don't react if sort values didn't really change - if (newSort === oldSort) return; - $scope.searchSource.sort(getSort(newSort, $scope.indexPattern)); - $scope.searchSource.fetchQueued(); - }); - - $scope.$on('$destroy', function () { - if ($scope.searchSource) $scope.searchSource.destroy(); - }); - - // TODO: we need to have some way to clean up result requests - $scope.searchSource.onResults().then(function onResults(resp) { - // Reset infinite scroll limit - $scope.limit = 50; - - // Abort if something changed - if ($scope.searchSource !== $scope.searchSource) return; - - $scope.hits = resp.hits.hits; - - return $scope.searchSource.onResults().then(onResults); - }).catch(notify.fatal); - - $scope.searchSource.onError(notify.error).catch(notify.fatal); - })); - - } - }; - }); -}); \ No newline at end of file diff --git a/src/kibana/components/doc_table/doc_table.less b/src/kibana/components/doc_table/doc_table.less deleted file mode 100644 index 29a0b9d76b4f2..0000000000000 --- a/src/kibana/components/doc_table/doc_table.less +++ /dev/null @@ -1,26 +0,0 @@ -@import (reference) "../../styles/_bootstrap.less"; -@import (reference) "../../styles/theme/_theme.less"; -@import (reference) "lesshat.less"; - -doc-table { - overflow: auto; - margin: 5px; - .flex(1, 1, 100%); - - .discover-table-datafield { - white-space: pre-wrap; - } - - .loading { - opacity: @loading-opacity; - } - - .spinner { - position: absolute; - top: 40%; - left: 0; - right: 0; - z-index: 20; - opacity: @loading-opacity; - } -} diff --git a/src/kibana/components/doc_title/doc_title.js b/src/kibana/components/doc_title/doc_title.js deleted file mode 100644 index d479bee1c1eac..0000000000000 --- a/src/kibana/components/doc_title/doc_title.js +++ /dev/null @@ -1,52 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - require('modules').get('kibana') - .run(function ($rootScope, docTitle) { - // always bind to the route events - $rootScope.$on('$routeChangeStart', docTitle.reset); - $rootScope.$on('$routeChangeError', docTitle.update); - $rootScope.$on('$routeChangeSuccess', docTitle.update); - $rootScope.$watch('activeApp', docTitle.update); - }) - .service('docTitle', function ($rootScope) { - var baseTitle = document.title; - var self = this; - - var lastChange; - - function render() { - lastChange = lastChange || []; - - var parts = [lastChange[0]]; - - if ($rootScope.activeApp) { - parts.push($rootScope.activeApp.name); - } - - if (!lastChange[1]) { - parts.push(baseTitle); - } - - return _(parts).flattenDeep().compact().join(' - '); - } - - self.change = function (title, complete) { - lastChange = [title, complete]; - self.update(); - }; - - self.reset = function () { - lastChange = null; - }; - - self.update = function () { - document.title = render(); - }; - }); - - // return a "private module" so that it can be used both ways - return function DoctitleProvider(docTitle) { - return docTitle; - }; -}); diff --git a/src/kibana/components/doc_viewer/doc_viewer.js b/src/kibana/components/doc_viewer/doc_viewer.js deleted file mode 100644 index f06837f45f145..0000000000000 --- a/src/kibana/components/doc_viewer/doc_viewer.js +++ /dev/null @@ -1,41 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var angular = require('angular'); - require('angular-ui-ace'); - - var html = require('text!components/doc_viewer/doc_viewer.html'); - require('css!components/doc_viewer/doc_viewer.css'); - - require('modules').get('kibana') - .directive('docViewer', function (config, Private) { - return { - restrict: 'E', - template: html, - scope: { - hit: '=', - indexPattern: '=', - filter: '=?', - columns: '=?' - }, - link: function ($scope, $el, attr) { - // If a field isn't in the mapping, use this - $scope.mode = 'table'; - $scope.mapping = $scope.indexPattern.fields.byName; - $scope.flattened = $scope.indexPattern.flattenHit($scope.hit); - $scope.hitJson = angular.toJson($scope.hit, true); - $scope.formatted = $scope.indexPattern.formatHit($scope.hit); - $scope.fields = _.keys($scope.flattened).sort(); - - $scope.toggleColumn = function (fieldName) { - _.toggleInOut($scope.columns, fieldName); - }; - - $scope.showArrayInObjectsWarning = function (row, field) { - var value = $scope.flattened[field]; - return _.isArray(value) && typeof value[0] === 'object'; - }; - - } - }; - }); -}); diff --git a/src/kibana/components/doc_viewer/doc_viewer.less b/src/kibana/components/doc_viewer/doc_viewer.less deleted file mode 100644 index e70ccea239628..0000000000000 --- a/src/kibana/components/doc_viewer/doc_viewer.less +++ /dev/null @@ -1,25 +0,0 @@ -@import (reference) "../../styles/_bootstrap.less"; -@import (reference) "../../styles/theme/_theme.less"; -@import (reference) "lesshat.less"; - -doc-viewer .doc-viewer { - - &-buttons, &-field { - white-space: nowrap; - } - - &-value, pre { - display: inline-block; - word-break: break-all; - word-wrap: break-word; - white-space: pre-wrap; - } - - td, pre { - font-family: "Lucida Console", Monaco, monospace; - } - - &-content { - margin-top: @padding-base-vertical; - } -} diff --git a/src/kibana/components/errors.js b/src/kibana/components/errors.js deleted file mode 100644 index 0231b534fddf3..0000000000000 --- a/src/kibana/components/errors.js +++ /dev/null @@ -1,268 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var angular = require('angular'); - - var canStack = (function () { - var err = new Error(); - return !!err.stack; - }()); - - var errors = {}; - - // abstract error class - function KbnError(msg, constructor) { - this.message = msg; - - Error.call(this, this.message); - if (Error.captureStackTrace) { - Error.captureStackTrace(this, constructor || KbnError); - } else if (canStack) { - this.stack = (new Error()).stack; - } else { - this.stack = ''; - } - } - errors.KbnError = KbnError; - _.class(KbnError).inherits(Error); - - /** - * HastyRefresh error class - * @param {String} [msg] - An error message that will probably end up in a log. - */ - errors.HastyRefresh = function HastyRefresh() { - KbnError.call(this, - 'Courier attempted to start a query before the previous had finished.', - errors.HastyRefresh); - }; - _.class(errors.HastyRefresh).inherits(KbnError); - - /** - * SearchTimeout error class - */ - errors.SearchTimeout = function SearchTimeout() { - KbnError.call(this, - 'All or part of your request has timed out. The data shown may be incomplete.', - errors.SearchTimeout); - }; - _.class(errors.SearchTimeout).inherits(KbnError); - - /** - * Request Failure - When an entire mutli request fails - * @param {Error} err - the Error that came back - * @param {Object} resp - optional HTTP response - */ - errors.RequestFailure = function RequestFailure(err, resp) { - err = err || false; - - KbnError.call(this, - 'Request to Elasticsearch failed: ' + angular.toJson(resp || err.message), - errors.RequestFailure); - - this.origError = err; - this.resp = resp; - }; - _.class(errors.RequestFailure).inherits(KbnError); - - /** - * FetchFailure Error - when there is an error getting a doc or search within - * a multi-response response body - * @param {String} [msg] - An error message that will probably end up in a log. - */ - errors.FetchFailure = function FetchFailure(resp) { - KbnError.call(this, - 'Failed to get the doc: ' + angular.toJson(resp), - errors.FetchFailure); - - this.resp = resp; - }; - _.class(errors.FetchFailure).inherits(KbnError); - - /** - * ShardFailure Error - when one or more shards fail - * @param {String} [msg] - An error message that will probably end up in a log. - */ - errors.ShardFailure = function ShardFailure(resp) { - KbnError.call(this, resp._shards.failed + ' of ' + resp._shards.total + ' shards failed.', - errors.ShardFailure); - - this.resp = resp; - }; - _.class(errors.ShardFailure).inherits(KbnError); - - - /** - * A doc was re-indexed but it was out of date. - * @param {Object} resp - The response from es (one of the multi-response responses). - */ - errors.VersionConflict = function VersionConflict(resp) { - KbnError.call(this, - 'Failed to store document changes do to a version conflict.', - errors.VersionConflict); - - this.resp = resp; - }; - _.class(errors.VersionConflict).inherits(KbnError); - - - /** - * there was a conflict storing a doc - * @param {String} field - the fields which contains the conflict - */ - errors.MappingConflict = function MappingConflict(field) { - KbnError.call(this, - 'Field "' + field + '" is defined with at least two different types in indices matching the pattern', - errors.MappingConflict); - }; - _.class(errors.MappingConflict).inherits(KbnError); - - /** - * a field mapping was using a restricted fields name - * @param {String} field - the fields which contains the conflict - */ - errors.RestrictedMapping = function RestrictedMapping(field, index) { - var msg = field + ' is a restricted field name'; - if (index) msg += ', found it while attempting to fetch mapping for index pattern: ' + index; - - KbnError.call(this, msg, errors.RestrictedMapping); - }; - _.class(errors.RestrictedMapping).inherits(KbnError); - - /** - * a non-critical cache write to elasticseach failed - */ - errors.CacheWriteFailure = function CacheWriteFailure() { - KbnError.call(this, - 'A Elasticsearch cache write has failed.', - errors.CacheWriteFailure); - }; - _.class(errors.CacheWriteFailure).inherits(KbnError); - - /** - * when a field mapping is requested for an unknown field - * @param {String} name - the field name - */ - errors.FieldNotFoundInCache = function FieldNotFoundInCache(name) { - KbnError.call(this, - 'The ' + name + ' field was not found in the cached mappings', - errors.FieldNotFoundInCache); - }; - _.class(errors.FieldNotFoundInCache).inherits(KbnError); - - /** - * when a mapping already exists for a field the user is attempting to add - * @param {String} name - the field name - */ - errors.DuplicateField = function DuplicateField(name) { - KbnError.call(this, - 'The "' + name + '" field already exists in this mapping', - errors.DuplicateField); - }; - _.class(errors.DuplicateField).inherits(KbnError); - - /** - * A saved object was not found - * @param {String} field - the fields which contains the conflict - */ - errors.SavedObjectNotFound = function SavedObjectNotFound(type, id) { - this.savedObjectType = type; - this.savedObjectId = id; - var idMsg = id ? ' (id: ' + id + ')' : ''; - KbnError.call(this, - 'Could not locate that ' + type + idMsg, - errors.SavedObjectNotFound); - }; - _.class(errors.SavedObjectNotFound).inherits(KbnError); - - /** - * Tried to call a method that relies on SearchSource having an indexPattern assigned - */ - errors.IndexPatternMissingIndices = function IndexPatternMissingIndices(type) { - KbnError.call(this, - 'IndexPattern\'s configured pattern does not match any indices', - errors.IndexPatternMissingIndices); - }; - _.class(errors.IndexPatternMissingIndices).inherits(KbnError); - - /** - * Tried to call a method that relies on SearchSource having an indexPattern assigned - */ - errors.NoDefinedIndexPatterns = function NoDefinedIndexPatterns(type) { - KbnError.call(this, - 'Define at least one index pattern to continue', - errors.NoDefinedIndexPatterns); - }; - _.class(errors.NoDefinedIndexPatterns).inherits(KbnError); - - - /** - * Tried to load a route besides settings/indices but you don't have a default index pattern! - */ - errors.NoDefaultIndexPattern = function NoDefaultIndexPattern(type) { - KbnError.call(this, - 'Please specify a default index pattern', - errors.NoDefaultIndexPattern); - }; - _.class(errors.NoDefaultIndexPattern).inherits(KbnError); - - - /** - * user with the vislib, when the container is too small - * @param {String} message - the message to provide with the error - */ - errors.ContainerTooSmall = function ContainerTooSmall() { - KbnError.call(this, - 'This container is too small to render the visualization', - errors.ContainerTooSmall); - }; - _.class(errors.ContainerTooSmall).inherits(KbnError); - - /** - * error thrown when user tries to render an chart with less - * than the required number of data points - * @param {String} message - the message to provide with the error - */ - errors.NotEnoughData = function NotEnoughData(message) { - KbnError.call(this, message, errors.NotEnoughData); - }; - _.class(errors.NotEnoughData).inherits(KbnError); - - /** - * error thrown when no results are returned from an elasticsearch query - */ - errors.NoResults = function NoResults() { - KbnError.call(this, - 'No results found', - errors.NoResults); - }; - _.class(errors.NoResults).inherits(KbnError); - - /** - * error thrown when no results are returned from an elasticsearch query - */ - errors.PieContainsAllZeros = function PieContainsAllZeros() { - KbnError.call(this, - 'No results displayed because all values equal 0', - errors.PieContainsAllZeros); - }; - _.class(errors.PieContainsAllZeros).inherits(KbnError); - - /** - * error thrown when no results are returned from an elasticsearch query - */ - errors.InvalidLogScaleValues = function InvalidLogScaleValues() { - KbnError.call(this, - 'Values less than 1 cannot be displayed on a log scale', - errors.InvalidLogScaleValues); - }; - _.class(errors.InvalidLogScaleValues).inherits(KbnError); - - /** error thrown when wiggle chart is selected for non linear data */ - errors.InvalidWiggleSelection = function InvalidWiggleSelection() { - KbnError.call(this, - 'In wiggle mode the area chart requires ordered values on the x-axis. Try using a Histogram or Date Histogram aggregation.', - errors.InvalidWiggleSelection); - }; - _.class(errors.InvalidWiggleSelection).inherits(KbnError); - - return errors; -}); diff --git a/src/kibana/components/fancy_forms/fancy_forms.js b/src/kibana/components/fancy_forms/fancy_forms.js deleted file mode 100644 index aa095e2937430..0000000000000 --- a/src/kibana/components/fancy_forms/fancy_forms.js +++ /dev/null @@ -1,45 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var $ = require('jquery'); - - var KbnFormController = require('components/fancy_forms/kbn_form'); - var KbnModelController = require('components/fancy_forms/kbn_model'); - - require('modules') - .get('kibana') - .config(function ($provide) { - function decorateDirectiveController(DecorativeController) { - return function ($delegate, $injector) { - // directive providers are arrays - $delegate.forEach(function (directive) { - // get metadata about all init fns - var chain = [directive.controller, DecorativeController].map(function (fn) { - var deps = $injector.annotate(fn); - return { deps: deps, fn: _.isArray(fn) ? _.last(fn) : fn }; - }); - - // replace the controller with one that will setup the actual controller - directive.controller = function stub() { - var allDeps = _.toArray(arguments); - return chain.reduce(function (controller, link, i) { - var deps = allDeps.splice(0, link.deps.length); - return link.fn.apply(controller, deps) || controller; - }, this); - }; - - // set the deps of our new controller to be the merged deps of every fn - directive.controller.$inject = chain.reduce(function (deps, link) { - return deps.concat(link.deps); - }, []); - }); - - return $delegate; - }; - } - - - $provide.decorator('formDirective', decorateDirectiveController(KbnFormController)); - $provide.decorator('ngFormDirective', decorateDirectiveController(KbnFormController)); - $provide.decorator('ngModelDirective', decorateDirectiveController(KbnModelController)); - }); -}); \ No newline at end of file diff --git a/src/kibana/components/field_editor/field_editor.js b/src/kibana/components/field_editor/field_editor.js deleted file mode 100644 index 667940ad9aa76..0000000000000 --- a/src/kibana/components/field_editor/field_editor.js +++ /dev/null @@ -1,141 +0,0 @@ -define(function (require) { - - require('components/field_format_editor/field_format_editor'); - - require('modules') - .get('kibana') - .directive('fieldEditor', function (Private, $sce) { - var _ = require('lodash'); - var fieldFormats = Private(require('registry/field_formats')); - var Field = Private(require('components/index_patterns/_field')); - var scriptingInfo = $sce.trustAsHtml(require('text!components/field_editor/scripting_info.html')); - var scriptingWarning = $sce.trustAsHtml(require('text!components/field_editor/scripting_warning.html')); - - return { - restrict: 'E', - template: require('text!components/field_editor/field_editor.html'), - scope: { - getIndexPattern: '&indexPattern', - getField: '&field' - }, - controllerAs: 'editor', - controller: function ($scope, Notifier, kbnUrl) { - var self = this; - var notify = new Notifier({ location: 'Field Editor' }); - - self.scriptingInfo = scriptingInfo; - self.scriptingWarning = scriptingWarning; - - self.indexPattern = $scope.getIndexPattern(); - self.field = shadowCopy($scope.getField()); - self.formatParams = self.field.format.params(); - - // only init on first create - self.creating = !self.indexPattern.fields.byName[self.field.name]; - self.selectedFormatId = _.get(self.indexPattern, ['fieldFormatMap', self.field.name, 'type', 'id']); - self.defFormatType = initDefaultFormat(); - self.fieldFormatTypes = [self.defFormatType].concat(fieldFormats.byFieldType[self.field.type] || []); - - self.cancel = redirectAway; - self.save = function () { - var indexPattern = self.indexPattern; - var fields = indexPattern.fields; - var field = self.field.toActualField(); - - fields.remove({ name: field.name }); - fields.push(field); - - if (!self.selectedFormatId) { - delete indexPattern.fieldFormatMap[field.name]; - } else { - indexPattern.fieldFormatMap[field.name] = self.field.format; - } - - return indexPattern.save() - .then(function () { - notify.info('Saved Field "' + self.field.name + '"'); - redirectAway(); - }); - }; - - self.delete = function () { - var indexPattern = self.indexPattern; - var field = self.field; - - indexPattern.fields.remove({ name: field.name }); - return indexPattern.save() - .then(function () { - notify.info('Deleted Field "' + field.name + '"'); - redirectAway(); - }); - }; - - $scope.$watch('editor.selectedFormatId', function (cur, prev) { - var format = self.field.format; - var changedFormat = cur !== prev; - var missingFormat = cur && (!format || format.type.id !== cur); - - if (!changedFormat || !missingFormat) return; - - // reset to the defaults, but make sure it's an object - self.formatParams = _.assign({}, getFieldFormatType().paramDefaults); - }); - - $scope.$watch('editor.formatParams', function () { - var FieldFormat = getFieldFormatType(); - self.field.format = new FieldFormat(self.formatParams); - }, true); - - // copy the defined properties of the field to a plain object - // which is mutable, and capture the changed seperately. - function shadowCopy(field) { - var changes = {}; - var shadowProps = { - toActualField: { - // bring the shadow copy out of the shadows - value: function toActualField() { - return new Field(self.indexPattern, _.defaults({}, changes, field.$$spec)); - } - } - }; - - Object.getOwnPropertyNames(field).forEach(function (prop) { - var desc = Object.getOwnPropertyDescriptor(field, prop); - shadowProps[prop] = { - enumerable: desc.enumerable, - get: function () { - return _.has(changes, prop) ? changes[prop] : field[prop]; - }, - set: function (v) { - changes[prop] = v; - } - }; - }); - - return Object.create(null, shadowProps); - } - - function redirectAway() { - kbnUrl.changeToRoute(self.indexPattern, self.field.scripted ? 'scriptedFields' : 'indexedFields'); - } - - function getFieldFormatType() { - if (self.selectedFormatId) return fieldFormats.getType(self.selectedFormatId); - else return fieldFormats.getDefaultType(self.field.type); - } - - function initDefaultFormat() { - var def = Object.create(fieldFormats.getDefaultType(self.field.type)); - - // explicitly set to undefined to prevent inheritting the prototypes id - def.id = undefined; - def.resolvedTitle = def.title; - def.title = '- default - '; - - return def; - } - } - }; - }); - -}); diff --git a/src/kibana/components/field_format_editor/numeral/numeral.js b/src/kibana/components/field_format_editor/numeral/numeral.js deleted file mode 100644 index 23cf21acc1ebc..0000000000000 --- a/src/kibana/components/field_format_editor/numeral/numeral.js +++ /dev/null @@ -1,12 +0,0 @@ -define(function (require) { - require('components/field_format_editor/pattern/pattern'); - - require('modules') - .get('kibana') - .directive('fieldEditorNumeral', function () { - return { - restrict: 'E', - template: require('text!components/field_format_editor/numeral/numeral.html') - }; - }); -}); diff --git a/src/kibana/components/filter_bar/filter_bar.js b/src/kibana/components/filter_bar/filter_bar.js deleted file mode 100644 index 42ecd2dac8b86..0000000000000 --- a/src/kibana/components/filter_bar/filter_bar.js +++ /dev/null @@ -1,113 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var module = require('modules').get('kibana'); - var template = require('text!components/filter_bar/filter_bar.html'); - var moment = require('moment'); - - module.directive('filterBar', function (Private, Promise, getAppState) { - var mapAndFlattenFilters = Private(require('components/filter_bar/lib/mapAndFlattenFilters')); - var mapFlattenAndWrapFilters = Private(require('components/filter_bar/lib/mapFlattenAndWrapFilters')); - var extractTimeFilter = Private(require('components/filter_bar/lib/extractTimeFilter')); - var filterOutTimeBasedFilter = Private(require('components/filter_bar/lib/filterOutTimeBasedFilter')); - var filterAppliedAndUnwrap = require('components/filter_bar/lib/filterAppliedAndUnwrap'); - var changeTimeFilter = Private(require('components/filter_bar/lib/changeTimeFilter')); - var queryFilter = Private(require('components/filter_bar/query_filter')); - - return { - restrict: 'E', - template: template, - scope: {}, - link: function ($scope, $el, attrs) { - // bind query filter actions to the scope - [ - 'addFilters', - 'toggleFilter', - 'toggleAll', - 'pinFilter', - 'pinAll', - 'invertFilter', - 'invertAll', - 'removeFilter', - 'removeAll' - ].forEach(function (method) { - $scope[method] = queryFilter[method]; - }); - - $scope.state = getAppState(); - - $scope.applyFilters = function (filters) { - // add new filters - $scope.addFilters(filterAppliedAndUnwrap(filters)); - $scope.newFilters = []; - - // change time filter - if ($scope.changeTimeFilter && $scope.changeTimeFilter.meta && $scope.changeTimeFilter.meta.apply) { - changeTimeFilter($scope.changeTimeFilter); - } - }; - - $scope.clearFilterBar = function () { - $scope.newFilters = []; - $scope.changeTimeFilter = null; - }; - - // update the scope filter list on filter changes - $scope.$listen(queryFilter, 'update', function () { - updateFilters(); - }); - - // when appState changes, update scope's state - $scope.$watch(getAppState, function (appState) { - $scope.state = appState; - }); - - $scope.$watch('state.$newFilters', function (filters) { - if (!filters) return; - - // If filters is not undefined and the length is greater than - // one we need to set the newFilters attribute and allow the - // users to decide what they want to apply. - if (filters.length > 1) { - return mapFlattenAndWrapFilters(filters) - .then(function (results) { - extractTimeFilter(results).then(function (filter) { - $scope.changeTimeFilter = filter; - }); - return results; - }) - .then(filterOutTimeBasedFilter) - .then(function (results) { - $scope.newFilters = results; - }); - } - - // Just add single filters to the state. - if (filters.length === 1) { - Promise.resolve(filters).then(function (filters) { - extractTimeFilter(filters) - .then(function (timeFilter) { - if (timeFilter) changeTimeFilter(timeFilter); - }); - return filters; - }) - .then(filterOutTimeBasedFilter) - .then($scope.addFilters); - } - }); - - function updateFilters() { - var filters = queryFilter.getFilters(); - mapAndFlattenFilters(filters).then(function (results) { - // used to display the current filters in the state - $scope.filters = _.sortBy(results, function (filter) { - return !filter.meta.pinned; - }); - $scope.$emit('filterbar:updated'); - }); - } - - updateFilters(); - } - }; - }); -}); diff --git a/src/kibana/components/filter_bar/lib/dedupFilters.js b/src/kibana/components/filter_bar/lib/dedupFilters.js deleted file mode 100644 index a325b7e71219d..0000000000000 --- a/src/kibana/components/filter_bar/lib/dedupFilters.js +++ /dev/null @@ -1,22 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var angular = require('angular'); - var compareFilters = require('components/filter_bar/lib/compareFilters'); - - /** - * Combine 2 filter collections, removing duplicates - * @param {object} existing The filters to compare to - * @param {object} filters The filters being added - * @param {object} comparatorOptions Parameters to use for comparison - * @returns {object} An array of filters that were not in existing - */ - return function (existingFilters, filters, comparatorOptions) { - if (!_.isArray(filters)) filters = [filters]; - - return _.filter(filters, function (filter) { - return !_.find(existingFilters, function (existingFilter) { - return compareFilters(existingFilter, filter, comparatorOptions); - }); - }); - }; -}); diff --git a/src/kibana/components/filter_bar/lib/mapAndFlattenFilters.js b/src/kibana/components/filter_bar/lib/mapAndFlattenFilters.js deleted file mode 100644 index ae99fb1edbecf..0000000000000 --- a/src/kibana/components/filter_bar/lib/mapAndFlattenFilters.js +++ /dev/null @@ -1,14 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - return function mapAndFlattenFiltersProvider(Private, Promise) { - var mapFilter = Private(require('components/filter_bar/lib/mapFilter')); - return function (filters) { - return _(filters) - .flatten() - .compact() - .map(mapFilter) - .thru(Promise.all) - .value(); - }; - }; -}); diff --git a/src/kibana/components/filter_bar/lib/mapFlattenAndWrapFilters.js b/src/kibana/components/filter_bar/lib/mapFlattenAndWrapFilters.js deleted file mode 100644 index 8cc079568976e..0000000000000 --- a/src/kibana/components/filter_bar/lib/mapFlattenAndWrapFilters.js +++ /dev/null @@ -1,15 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - return function mapFlattenAndWrapFilters(Private) { - var mapAndFlattenFilters = Private(require('components/filter_bar/lib/mapAndFlattenFilters')); - return function (filters) { - return mapAndFlattenFilters(filters).then(function (filters) { - return _.map(filters, function (filter) { - filter.meta = filter.meta || {}; - filter.meta.apply = true; - return filter; - }); - }); - }; - }; -}); diff --git a/src/kibana/components/filter_bar/lib/uniqFilters.js b/src/kibana/components/filter_bar/lib/uniqFilters.js deleted file mode 100644 index d7c363759800c..0000000000000 --- a/src/kibana/components/filter_bar/lib/uniqFilters.js +++ /dev/null @@ -1,17 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var dedupFilters = require('components/filter_bar/lib/dedupFilters'); - - /** - * Remove duplicate filters from an array of filters - * @param {array} filters The filters to remove duplicates from - * @returns {object} The original filters array with duplicates removed - */ - return function (filters, comparatorOptions) { - var results = []; - _.each(filters, function (filter) { - results = _.union(results, dedupFilters(results, [filter], comparatorOptions)); - }); - return results; - }; -}); diff --git a/src/kibana/components/filter_bar/query_filter.js b/src/kibana/components/filter_bar/query_filter.js deleted file mode 100644 index ce92b3ac95b8e..0000000000000 --- a/src/kibana/components/filter_bar/query_filter.js +++ /dev/null @@ -1,335 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - return function (Private, $rootScope, getAppState, globalState) { - var EventEmitter = Private(require('factories/events')); - var onlyDisabled = require('components/filter_bar/lib/onlyDisabled'); - var onlyStateChanged = require('components/filter_bar/lib/onlyStateChanged'); - var uniqFilters = require('components/filter_bar/lib/uniqFilters'); - var compareFilters = require('components/filter_bar/lib/compareFilters'); - var mapAndFlattenFilters = Private(require('components/filter_bar/lib/mapAndFlattenFilters')); - - var queryFilter = new EventEmitter(); - - queryFilter.getFilters = function () { - var compareOptions = { disabled: true, negate: true }; - var appFilters = queryFilter.getAppFilters(); - var globalFilters = queryFilter.getGlobalFilters(); - - return uniqFilters(globalFilters.concat(appFilters), compareOptions); - }; - - queryFilter.getAppFilters = function () { - var appState = getAppState(); - if (!appState || !appState.filters) return []; - return (appState.filters) ? _.map(appState.filters, appendStoreType('appState')) : []; - }; - - queryFilter.getGlobalFilters = function () { - if (!globalState.filters) return []; - return _.map(globalState.filters, appendStoreType('globalState')); - }; - - /** - * Adds new filters to the scope and state - * @param {object|array} fitlers Filter(s) to add - * @param {bool} global Should be added to global state - * @retuns {Promise} filter map promise - */ - queryFilter.addFilters = function (filters, global) { - var appState = getAppState(); - var state = (global) ? globalState : appState; - - if (!_.isArray(filters)) { - filters = [filters]; - } - - return mapAndFlattenFilters(filters) - .then(function (filters) { - if (global) { - // simply concat global filters, they will be deduped - globalState.filters = globalState.filters.concat(filters); - } else if (appState) { - if (!appState.filters) appState.filters = []; - appState.filters = appState.filters.concat(filters); - } - }); - }; - - /** - * Removes the filter from the proper state - * @param {object} matchFilter The filter to remove - */ - queryFilter.removeFilter = function (matchFilter) { - var appState = getAppState(); - var filter = _.omit(matchFilter, ['$$hashKey']); - var state; - var index; - - // check for filter in appState - if (appState) { - index = _.findIndex(appState.filters, filter); - if (index !== -1) state = appState; - } - - // if not found, check for filter in globalState - if (!state) { - index = _.findIndex(globalState.filters, filter); - if (index !== -1) state = globalState; - else return; // not found in either state, do nothing - } - - state.filters.splice(index, 1); - }; - - /** - * Removes all filters - */ - queryFilter.removeAll = function () { - var appState = getAppState(); - appState.filters = []; - globalState.filters = []; - }; - - /** - * Toggles the filter between enabled/disabled. - * @param {object} filter The filter to toggle - & @param {boolean} force Disabled true/false - * @returns {object} updated filter - */ - queryFilter.toggleFilter = function (filter, force) { - // Toggle the disabled flag - var disabled = _.isUndefined(force) ? !filter.meta.disabled : !!force; - filter.meta.disabled = disabled; - return filter; - }; - - /** - * Disables all filters - * @params {boolean} force Disable/enable all filters - */ - queryFilter.toggleAll = function (force) { - function doToggle(filter) { - queryFilter.toggleFilter(filter, force); - } - - executeOnFilters(doToggle); - }; - - - /** - * Inverts the nagate value on the filter - * @param {object} filter The filter to toggle - * @returns {object} updated filter - */ - queryFilter.invertFilter = function (filter) { - // Toggle the negate meta state - filter.meta.negate = !filter.meta.negate; - return filter; - }; - - /** - * Inverts all filters - * @returns {object} Resulting updated filter list - */ - queryFilter.invertAll = function () { - executeOnFilters(queryFilter.invertFilter); - }; - - - /** - * Pins the filter to the global state - * @param {object} filter The filter to pin - * @param {boolean} force pinned state - * @returns {object} updated filter - */ - queryFilter.pinFilter = function (filter, force) { - var appState = getAppState(); - if (!appState) return filter; - - // ensure that both states have a filters property - if (!_.isArray(globalState.filters)) globalState.filters = []; - if (!_.isArray(appState.filters)) appState.filters = []; - - var appIndex = _.indexOf(appState.filters, filter); - - if (appIndex !== -1 && force !== false) { - appState.filters.splice(appIndex, 1); - globalState.filters.push(filter); - } else { - var globalIndex = _.indexOf(globalState.filters, filter); - - if (globalIndex === -1 || force === true) return filter; - - globalState.filters.splice(globalIndex, 1); - appState.filters.push(filter); - } - - return filter; - }; - - /** - * Pins all filters - * @params {boolean} force Pin/Unpin all filters - */ - queryFilter.pinAll = function (force) { - function pin(filter) { - queryFilter.pinFilter(filter, force); - } - - executeOnFilters(pin); - }; - - initWatchers(); - - return queryFilter; - - /** - * Saves both app and global states, ensuring filters are persisted - * @returns {object} Resulting filter list, app and global combined - */ - function saveState() { - var appState = getAppState(); - if (appState) appState.save(); - globalState.save(); - } - - function appendStoreType(type) { - return function (filter) { - filter.$state = { - store: type - }; - return filter; - }; - } - - // helper to run a function on all filters in all states - function executeOnFilters(fn) { - var appState = getAppState(); - var globalFilters = []; - var appFilters = []; - - if (globalState.filters) globalFilters = globalState.filters; - if (appState && appState.filters) appFilters = appState.filters; - - globalFilters.concat(appFilters).forEach(fn); - } - - function mergeStateFilters(gFilters, aFilters, compareOptions) { - // ensure we don't mutate the filters passed in - var globalFilters = gFilters ? _.cloneDeep(gFilters) : []; - var appFilters = aFilters ? _.cloneDeep(aFilters) : []; - compareOptions = _.defaults(compareOptions || {}, { disabled: true }); - - // existing globalFilters should be mutated by appFilters - _.each(appFilters, function (filter, i) { - var match = _.find(globalFilters, function (globalFilter) { - return compareFilters(globalFilter, filter, compareOptions); - }); - - // no match, do nothing - if (!match) return; - - // matching filter in globalState, update global and remove from appState - _.assign(match.meta, filter.meta); - appFilters.splice(i, 1); - }); - - return [ - uniqFilters(globalFilters, { disabled: true }), - uniqFilters(appFilters, { disabled: true }) - ]; - } - - /** - * Initializes state watchers that use the event emitter - * @returns {void} - */ - function initWatchers() { - var removeAppStateWatchers; - - $rootScope.$watch(getAppState, function () { - removeAppStateWatchers && removeAppStateWatchers(); - removeAppStateWatchers = initAppStateWatchers(); - }); - - function initAppStateWatchers() { - // multi watch on the app and global states - var stateWatchers = [{ - fn: $rootScope.$watch, - deep: true, - get: queryFilter.getGlobalFilters - }, { - fn: $rootScope.$watch, - deep: true, - get: queryFilter.getAppFilters - }]; - - // when states change, use event emitter to trigger updates and fetches - return $rootScope.$watchMulti(stateWatchers, function (next, prev) { - // prevent execution on watcher instantiation - if (_.isEqual(next, prev)) return; - - var doUpdate = false; - var doFetch = false; - - // reconcile filter in global and app states - var filters = mergeStateFilters(next[0], next[1]); - var globalFilters = filters[0]; - var appFilters = filters[1]; - var appState = getAppState(); - - // save the state, as it may have updated - var globalChanged = !_.isEqual(next[0], globalFilters); - var appChanged = !_.isEqual(next[1], appFilters); - - // the filters were changed, apply to state (re-triggers this watcher) - if (globalChanged || appChanged) { - globalState.filters = globalFilters; - if (appState) appState.filters = appFilters; - return; - } - - // check for actions, bail if we're done - getActions(); - if (!doUpdate) return; - - // save states and emit the required events - saveState(); - queryFilter.emit('update') - .then(function () { - if (!doFetch) return; - queryFilter.emit('fetch'); - }); - - // iterate over each state type, checking for changes - function getActions() { - var newFilters = []; - var oldFilters = []; - - stateWatchers.forEach(function (watcher, i) { - var nextVal = next[i]; - var prevVal = prev[i]; - newFilters = newFilters.concat(nextVal); - oldFilters = oldFilters.concat(prevVal); - - // no update or fetch if there was no change - if (nextVal === prevVal) return; - - if (nextVal) doUpdate = true; - - // don't trigger fetch when only disabled filters - if (!onlyDisabled(nextVal, prevVal)) doFetch = true; - }); - - // make sure change wasn't only a state move - // checking length first is an optimization - if (doFetch && newFilters.length === oldFilters.length) { - if (onlyStateChanged(newFilters, oldFilters)) doFetch = false; - } - } - }); - } - } - }; -}); diff --git a/src/kibana/components/filter_manager/filter_manager.js b/src/kibana/components/filter_manager/filter_manager.js deleted file mode 100644 index 3b137af9da856..0000000000000 --- a/src/kibana/components/filter_manager/filter_manager.js +++ /dev/null @@ -1,79 +0,0 @@ -// Adds a filter to a passed state -define(function (require) { - return function (Private) { - var _ = require('lodash'); - var queryFilter = Private(require('components/filter_bar/query_filter')); - var filterManager = {}; - - filterManager.add = function (field, values, operation, index) { - values = _.isArray(values) ? values : [values]; - var fieldName = _.isObject(field) ? field.name : field; - var filters = _.flatten([queryFilter.getAppFilters()]); - var newFilters = []; - - var negate = (operation === '-'); - - // TODO: On array fields, negating does not negate the combination, rather all terms - _.each(values, function (value) { - var filter; - var existing = _.find(filters, function (filter) { - if (!filter) return; - - if (fieldName === '_exists_' && filter.exists) { - return filter.exists.field === value; - } - - if (filter.query) { - return filter.query.match[fieldName] && filter.query.match[fieldName].query === value; - } - }); - - if (existing) { - existing.meta.disabled = false; - if (existing.meta.negate !== negate) { - queryFilter.invertFilter(existing); - } - return; - } - - switch (fieldName) { - case '_exists_': - filter = { - meta: { - negate: negate, - index: index - }, - exists: { - field: value - } - }; - break; - default: - if (field.scripted) { - filter = { - meta: { negate: negate, index: index, field: fieldName }, - script: { - script: '(' + field.script + ') == value', - lang: field.lang, - params: { - value: value - } - } - }; - } else { - filter = { meta: { negate: negate, index: index }, query: { match: {} } }; - filter.query.match[fieldName] = { query: value, type: 'phrase' }; - } - - break; - } - - newFilters.push(filter); - }); - - return queryFilter.addFilters(newFilters); - }; - - return filterManager; - }; -}); diff --git a/src/kibana/components/fixedScroll.js b/src/kibana/components/fixedScroll.js deleted file mode 100644 index 15d885f2ff4f8..0000000000000 --- a/src/kibana/components/fixedScroll.js +++ /dev/null @@ -1,114 +0,0 @@ -define(function (require) { - var $ = require('jquery'); - var _ = require('lodash'); - - var SCROLLER_HEIGHT = 20; - - require('modules') - .get('kibana') - .directive('fixedScroll', function ($timeout) { - return { - restrict: 'A', - link: function ($scope, $el) { - var $window = $(window); - var $scroller = $('
').height(SCROLLER_HEIGHT); - - /** - * Listen for scroll events on the $scroller and the $el, sets unlisten() - * - * unlisten must be called before calling or listen() will throw an Error - * - * Since the browser emits "scroll" events after setting scrollLeft - * the listeners also prevent tug-of-war - * - * @throws {Error} If unlisten was not called first - * @return {undefined} - */ - function listen() { - if (unlisten !== _.noop) { - throw new Error('fixedScroll listeners were not cleaned up properly before re-listening!'); - } - - var blockTo; - function bind($from, $to) { - function handler() { - if (blockTo === $to) return (blockTo = null); - $to.scrollLeft((blockTo = $from).scrollLeft()); - } - - $from.on('scroll', handler); - return function () { - $from.off('scroll', handler); - }; - } - - unlisten = _.flow( - bind($el, $scroller), - bind($scroller, $el), - function () { unlisten = _.noop; } - ); - } - - /** - * Remove the listeners bound in listen() - * @type {function} - */ - var unlisten = _.noop; - - /** - * Revert DOM changes and event listeners - * @return {undefined} - */ - function cleanUp() { - unlisten(); - $scroller.detach(); - $el.css('padding-bottom', 0); - } - - /** - * Modify the DOM and attach event listeners based on need. - * Is called many times to re-setup, must be idempotent - * @return {undefined} - */ - function setup() { - cleanUp(); - - var containerWidth = $el.width(); - var contentWidth = $el.prop('scrollWidth'); - var containerHorizOverflow = contentWidth - containerWidth; - - var elTop = $el.offset().top - $window.scrollTop(); - var elBottom = elTop + $el.height(); - var windowVertOverflow = elBottom - $window.height(); - - var requireScroller = containerHorizOverflow > 0 && windowVertOverflow > 0; - if (!requireScroller) return; - - // push the content away from the scroller - $el.css('padding-bottom', SCROLLER_HEIGHT); - - // fill the scroller with a dummy element that mimics the content - $scroller - .width(containerWidth) - .html($('
').css({ width: contentWidth, height: SCROLLER_HEIGHT })) - .insertAfter($el); - - // listen for scroll events - listen(); - } - - // reset when the width or scrollWidth of the $el changes - $scope.$watchMulti([ - function () { return $el.prop('scrollWidth'); }, - function () { return $el.width(); } - ], setup); - - // cleanup when the scope is destroyed - $scope.$on('$destroy', function () { - cleanUp(); - $scroller = $window = null; - }); - } - }; - }); -}); diff --git a/src/kibana/components/highlight/highlight.js b/src/kibana/components/highlight/highlight.js deleted file mode 100644 index cfe92e704be6b..0000000000000 --- a/src/kibana/components/highlight/highlight.js +++ /dev/null @@ -1,32 +0,0 @@ -define(function (require) { - require('components/highlight/highlight_tags'); - - var _ = require('lodash'); - var angular = require('angular'); - var module = require('modules').get('kibana'); - - module.filter('highlight', function (highlightTags) { - return function (formatted, highlight) { - if (typeof formatted === 'object') formatted = angular.toJson(formatted); - - _.each(highlight, function (section) { - section = _.escape(section); - - // Strip out the highlight tags to compare against the formatted string - var untagged = section - .split(highlightTags.pre).join('') - .split(highlightTags.post).join(''); - - // Replace all highlight tags with proper html tags - var tagged = section - .split(highlightTags.pre).join('') - .split(highlightTags.post).join(''); - - // Replace all instances of the untagged string with the properly tagged string - formatted = formatted.split(untagged).join(tagged); - }); - - return formatted; - }; - }); -}); diff --git a/src/kibana/components/index_patterns/_cast_mapping_type.js b/src/kibana/components/index_patterns/_cast_mapping_type.js deleted file mode 100644 index 524c2f191bcb5..0000000000000 --- a/src/kibana/components/index_patterns/_cast_mapping_type.js +++ /dev/null @@ -1,42 +0,0 @@ -define(function (require) { - return function CastMappingTypeFn() { - var IndexedArray = require('utils/indexed_array/index'); - - castMappingType.types = new IndexedArray({ - index: ['name'], - group: ['type'], - immutable: true, - initialSet: [ - { name: 'string', type: 'string', group: 'base' }, - { name: 'date', type: 'date', group: 'base' }, - { name: 'boolean', type: 'boolean', group: 'base' }, - { name: 'float', type: 'number', group: 'number' }, - { name: 'double', type: 'number', group: 'number' }, - { name: 'integer', type: 'number', group: 'number' }, - { name: 'long', type: 'number', group: 'number' }, - { name: 'short', type: 'number', group: 'number' }, - { name: 'byte', type: 'number', group: 'number' }, - { name: 'token_count', type: 'number', group: 'number' }, - { name: 'geo_point', type: 'geo_point', group: 'geo' }, - { name: 'geo_shape', type: 'geo_shape', group: 'geo' }, - { name: 'ip', type: 'ip', group: 'other' }, - { name: 'attachment', type: 'attachment', group: 'other' }, - { name: 'murmur3', type: 'murmur3', group: 'hash' } - ] - }); - - /** - * Accepts a mapping type, and converts it into it's js equivilent - * @param {String} type - the type from the mapping's 'type' field - * @return {String} - the most specific type that we care for - */ - function castMappingType(name) { - if (!name) return 'unknown'; - - var match = castMappingType.types.byName[name]; - return match ? match.type : 'string'; - } - - return castMappingType; - }; -}); diff --git a/src/kibana/components/index_patterns/_field.js b/src/kibana/components/index_patterns/_field.js deleted file mode 100644 index fd0c1dab40485..0000000000000 --- a/src/kibana/components/index_patterns/_field.js +++ /dev/null @@ -1,79 +0,0 @@ -define(function (require) { - return function FieldObjectProvider(Private, shortDotsFilter, $rootScope, Notifier) { - var notify = new Notifier({ location: 'IndexPattern Field' }); - var FieldFormat = Private(require('components/index_patterns/_field_format/FieldFormat')); - var fieldTypes = Private(require('components/index_patterns/_field_types')); - var fieldFormats = Private(require('registry/field_formats')); - var ObjDefine = require('utils/obj_define'); - - function Field(indexPattern, spec) { - // unwrap old instances of Field - if (spec instanceof Field) spec = spec.$$spec; - - // constuct this object using ObjDefine class, which - // extends the Field.prototype but gets it's properties - // defined using the logic below - var obj = new ObjDefine(spec, Field.prototype); - - if (spec.name === '_source') { - spec.type = '_source'; - } - - // find the type for this field, fallback to unkown type - var type = fieldTypes.byName[spec.type]; - if (spec.type && !type) { - notify.error( - 'Unkown field type "' + spec.type + '"' + - ' for field "' + spec.name + '"' + - ' in indexPattern "' + indexPattern.id + '"' - ); - } - - if (!type) type = fieldTypes.byName.unknown; - - var format = spec.format; - if (!format || !(format instanceof FieldFormat)) { - format = indexPattern.fieldFormatMap[spec.name] || fieldFormats.getDefaultInstance(spec.type); - } - - var indexed = !!spec.indexed; - var scripted = !!spec.scripted; - var sortable = spec.name === '_score' || ((indexed || scripted) && type.sortable); - var bucketable = indexed || scripted; - var filterable = spec.name === '_id' || scripted || (indexed && type.filterable); - - obj.fact('name'); - obj.fact('type'); - obj.writ('count', spec.count || 0); - - // scripted objs - obj.fact('scripted', scripted); - obj.writ('script', scripted ? spec.script : null); - obj.writ('lang', scripted ? (spec.lang || 'expression') : null); - - // mapping info - obj.fact('indexed', indexed); - obj.fact('analyzed', !!spec.analyzed); - obj.fact('doc_values', !!spec.doc_values); - - // usage flags, read-only and won't be saved - obj.comp('format', format); - obj.comp('sortable', sortable); - obj.comp('bucketable', bucketable); - obj.comp('filterable', filterable); - - // computed values - obj.comp('indexPattern', indexPattern); - obj.comp('displayName', shortDotsFilter(spec.name)); - obj.comp('$$spec', spec); - - return obj.create(); - } - - Field.prototype.routes = { - edit: '/settings/indices/{{indexPattern.id}}/field/{{name}}' - }; - - return Field; - }; -}); diff --git a/src/kibana/components/index_patterns/_index_pattern.js b/src/kibana/components/index_patterns/_index_pattern.js deleted file mode 100644 index 3654a96b43618..0000000000000 --- a/src/kibana/components/index_patterns/_index_pattern.js +++ /dev/null @@ -1,271 +0,0 @@ -define(function (require) { - return function IndexPatternFactory(Private, timefilter, Notifier, config, Promise, $rootScope) { - var _ = require('lodash'); - var errors = require('errors'); - var angular = require('angular'); - - var fieldformats = Private(require('registry/field_formats')); - var getIds = Private(require('components/index_patterns/_get_ids')); - var mapper = Private(require('components/index_patterns/_mapper')); - var intervals = Private(require('components/index_patterns/_intervals')); - var getComputedFields = require('components/index_patterns/_get_computed_fields'); - var DocSource = Private(require('components/courier/data_source/doc_source')); - var mappingSetup = Private(require('utils/mapping_setup')); - var FieldList = Private(require('components/index_patterns/_field_list')); - - var flattenHit = Private(require('components/index_patterns/_flatten_hit')); - var formatHit = require('components/index_patterns/_format_hit'); - - var type = 'index-pattern'; - - var notify = new Notifier(); - - var mapping = mappingSetup.expandShorthand({ - title: 'string', - timeFieldName: 'string', - intervalName: 'string', - fields: 'json', - fieldFormatMap: { - type: 'string', - _serialize: function (map) { - if (map == null) return; - - var count = 0; - var serialized = _.transform(map, function (flat, format, field) { - if (!format) return; - count++; - flat[field] = format; - }); - - if (count) return angular.toJson(serialized); - }, - _deserialize: function (map) { - if (map == null) return {}; - return _.mapValues(angular.fromJson(map), function (mapping) { - var FieldFormat = fieldformats.byId[mapping.id]; - return FieldFormat && new FieldFormat(mapping.params); - }); - } - } - }); - - function IndexPattern(id) { - var self = this; - - setId(id); - - var docSource = new DocSource(); - - self.init = function () { - // tell the docSource where to find the doc - docSource - .index(config.file.kibana_index) - .type(type) - .id(self.id); - - // listen for config changes and update field list - $rootScope.$on('change:config', function () { - initFields(); - }); - - return mappingSetup.isDefined(type) - .then(function (defined) { - // create mapping for this type if one does not exist - if (defined) return true; - return mappingSetup.setup(type, mapping); - }) - .then(function () { - // If there is no id, then there is no document to fetch from elasticsearch - if (!self.id) return; - - // fetch the object from ES - return docSource.fetch() - .then(function applyESResp(resp) { - if (!resp.found) throw new errors.SavedObjectNotFound(type, self.id); - - // deserialize any json fields - _.forOwn(mapping, function ittr(fieldMapping, name) { - if (fieldMapping._deserialize) { - resp._source[name] = fieldMapping._deserialize(resp._source[name], resp, name, fieldMapping); - } - }); - - // Give obj all of the values in _source - _.assign(self, resp._source); - - self._indexFields(); - - // Any time obj is updated, re-call applyESResp - docSource.onUpdate().then(applyESResp, notify.fatal); - }); - }) - .then(function () { - // return our obj as the result of init() - return self; - }); - }; - - function initFields(fields) { - self.fields = new FieldList(self, fields || self.fields || []); - } - - self._indexFields = function () { - if (self.id) { - if (!self.fields) { - return self.refreshFields(); - } else { - initFields(); - } - } - }; - - self.addScriptedField = function (name, script, type, lang) { - type = type || 'string'; - - var scriptFields = _.pluck(self.getScriptedFields(), 'name'); - - if (_.contains(scriptFields, name)) { - throw new errors.DuplicateField(name); - } - - self.fields.push({ - name: name, - script: script, - type: type, - scripted: true, - lang: lang - }); - - self.save(); - }; - - self.removeScriptedField = function (name) { - var fieldIndex = _.findIndex(self.fields, { - name: name, - scripted: true - }); - - self.fields.splice(fieldIndex, 1); - - self.save(); - }; - - self.popularizeField = function (fieldName, unit) { - if (unit == null) unit = 1; - - var field = _.get(self, ['fields', 'byName', fieldName]); - if (!field) return; - - var count = Math.max((field.count || 0) + unit, 0); - if (field.count !== count) { - field.count = count; - self.save(); - } - }; - - self.getNonScriptedFields = function () { - return _.where(self.fields, { scripted: false }); - }; - - self.getScriptedFields = function () { - return _.where(self.fields, { scripted: true }); - }; - - self.getInterval = function () { - return this.intervalName && _.find(intervals, { name: this.intervalName }); - }; - - self.toIndexList = function (start, stop) { - var interval = this.getInterval(); - if (interval) { - return intervals.toIndexList(self.id, interval, start, stop); - } else { - return self.id; - } - }; - - self.prepBody = function () { - var body = {}; - - // serialize json fields - _.forOwn(mapping, function (fieldMapping, fieldName) { - if (self[fieldName] != null) { - body[fieldName] = (fieldMapping._serialize) - ? fieldMapping._serialize(self[fieldName]) - : self[fieldName]; - } - }); - - // ensure that the docSource has the current self.id - docSource.id(self.id); - - // clear the indexPattern list cache - getIds.clearCache(); - return body; - }; - - function setId(id) { - return self.id = id; - } - - self.create = function () { - var body = self.prepBody(); - return docSource.doCreate(body) - .then(setId) - .catch(function (err) { - var confirmMessage = 'Are you sure you want to overwrite this?'; - if (_.get(err, 'origError.status') === 409 && window.confirm(confirmMessage)) { - return docSource.doIndex(body).then(setId); - } - return Promise.resolve(false); - }); - }; - - self.save = function () { - var body = self.prepBody(); - return docSource.doIndex(body).then(setId); - }; - - self.refreshFields = function () { - return mapper.clearCache(self) - .then(self._fetchFields) - .then(self.save); - }; - - self._fetchFields = function () { - return mapper.getFieldsForIndexPattern(self, true) - .then(function (fields) { - // append existing scripted fields - fields = fields.concat(self.getScriptedFields()); - - // initialize self.field with this field list - initFields(fields); - }); - }; - - self.toJSON = function () { - return self.id; - }; - - self.toString = function () { - return '' + self.toJSON(); - }; - - self.metaFields = config.get('metaFields'); - self.getComputedFields = getComputedFields.bind(self); - - self.flattenHit = flattenHit(self); - self.formatHit = formatHit(self, fieldformats.getDefaultInstance('string')); - self.formatField = self.formatHit.formatField; - } - - IndexPattern.prototype.routes = { - edit: '/settings/indices/{{id}}', - addField: '/settings/indices/{{id}}/create-field', - indexedFields: '/settings/indices/{{id}}?_a=(tab:indexedFields)', - scriptedFields: '/settings/indices/{{id}}?_a=(tab:scriptedFields)' - }; - - return IndexPattern; - }; -}); diff --git a/src/kibana/components/index_patterns/_map_field.js b/src/kibana/components/index_patterns/_map_field.js deleted file mode 100644 index d9a3b661f8915..0000000000000 --- a/src/kibana/components/index_patterns/_map_field.js +++ /dev/null @@ -1,51 +0,0 @@ -define(function (require) { - return function MapFieldFn(Private, config) { - var _ = require('lodash'); - var castMappingType = Private(require('components/index_patterns/_cast_mapping_type')); - - /** - * Accepts a field object and its name, and tries to give it a mapping - * @param {Object} field - the field mapping returned by elasticsearch - * @param {String} type - name of the field - * @return {Object} - the resulting field after overrides and tweaking - */ - return function mapField(field, name) { - var keys = Object.keys(field.mapping); - if (keys.length === 0 || (name[0] === '_') && !_.contains(config.get('metaFields'), name)) return; - - var mapping = _.cloneDeep(field.mapping[keys.shift()]); - mapping.type = castMappingType(mapping.type); - - // Override the mapping, even if elasticsearch says otherwise - var mappingOverrides = { - _source: { type: '_source' }, - _index: { type: 'string' }, - _type: { type: 'string' }, - _id: { type: 'string' }, - _timestamp: { - type: 'date', - indexed: true - }, - _score: { - type: 'number', - indexed: false - } - }; - - if (!mapping.index || mapping.index === 'no') { - // elasticsearch responds with false sometimes and 'no' others - mapping.indexed = false; - } else { - mapping.indexed = true; - } - - mapping.analyzed = mapping.index === 'analyzed' ? true : false; - - if (mappingOverrides[name]) { - _.merge(mapping, mappingOverrides[name]); - } - - return mapping; - }; - }; -}); diff --git a/src/kibana/components/index_patterns/index_patterns.js b/src/kibana/components/index_patterns/index_patterns.js deleted file mode 100644 index ee48459cc57a4..0000000000000 --- a/src/kibana/components/index_patterns/index_patterns.js +++ /dev/null @@ -1,48 +0,0 @@ -define(function (require) { - var module = require('modules').get('kibana/index_patterns'); - require('filters/short_dots'); - - module.service('indexPatterns', function (configFile, es, Notifier, Private, Promise) { - var self = this; - var _ = require('lodash'); - var errors = require('errors'); - - var IndexPattern = Private(require('components/index_patterns/_index_pattern')); - var patternCache = Private(require('components/index_patterns/_pattern_cache')); - - var notify = new Notifier({ location: 'IndexPatterns Service'}); - - self.get = function (id) { - if (!id) return self.make(); - - var cache = patternCache.get(id); - return cache || patternCache.set(id, self.make(id)); - }; - - self.make = function (id) { - return (new IndexPattern(id)).init(); - }; - - self.delete = function (pattern) { - self.getIds.clearCache(); - patternCache.delete(pattern.id); - return es.delete({ - index: configFile.kibana_index, - type: 'index-pattern', - id: pattern.id - }); - }; - - self.errors = { - MissingIndices: errors.IndexPatternMissingIndices - }; - - self.cache = patternCache; - self.getIds = Private(require('components/index_patterns/_get_ids')); - self.intervals = Private(require('components/index_patterns/_intervals')); - self.mapper = Private(require('components/index_patterns/_mapper')); - self.patternToWildcard = Private(require('components/index_patterns/_pattern_to_wildcard')); - self.fieldFormats = Private(require('registry/field_formats')); - self.IndexPattern = IndexPattern; - }); -}); diff --git a/src/kibana/components/listen.js b/src/kibana/components/listen.js deleted file mode 100644 index 4954ec770c25e..0000000000000 --- a/src/kibana/components/listen.js +++ /dev/null @@ -1,24 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - require('modules').get('kibana') - .run(function ($rootScope) { - - /** - * Helper that registers an event listener, and removes that listener when - * the $scope is destroyed. - * - * @param {EventEmitter} emitter - the event emitter to listen to - * @param {string} eventName - the event name - * @param {Function} handler - the event handler - * @return {undefined} - */ - $rootScope.constructor.prototype.$listen = function (emitter, eventName, handler) { - emitter.on(eventName, handler); - this.$on('$destroy', function () { - emitter.off(eventName, handler); - }); - }; - - }); -}); \ No newline at end of file diff --git a/src/kibana/components/notify/_errors.js b/src/kibana/components/notify/_errors.js deleted file mode 100644 index 995b55ae51eb0..0000000000000 --- a/src/kibana/components/notify/_errors.js +++ /dev/null @@ -1,71 +0,0 @@ -define(function (require) { - var errors = {}; - var _ = require('lodash'); - - var canStack = (function () { - var err = new Error(); - return !!err.stack; - }()); - - // abstract error class - _.class(KibanaError).inherits(Error); - function KibanaError(msg, constructor) { - this.message = msg; - - Error.call(this, this.message); - if (!this.stack) { - if (Error.captureStackTrace) { - Error.captureStackTrace(this, constructor || KibanaError); - } else if (canStack) { - this.stack = (new Error()).stack; - } else { - this.stack = ''; - } - } - } - errors.KibanaError = KibanaError; - - /** - * Map of error text for different error types - * @type {Object} - */ - var requireTypeText = { - timeout: 'a network timeout', - nodefine: 'an invalid module definition', - scripterror: 'a generic script error' - }; - - /** - * ScriptLoadFailure error class for handling requirejs load failures - * @param {String} [msg] - - */ - errors.ScriptLoadFailure = function ScriptLoadFailure(err) { - var explain = requireTypeText[err.requireType] || err.requireType || 'an unknown error'; - - this.stack = err.stack; - var modules = err.requireModules; - if (_.isArray(modules) && modules.length > 0) { - modules = modules.map(JSON.stringify); - - if (modules.length > 1) { - modules = modules.slice(0, -1).join(', ') + ' and ' + modules.slice(-1)[0]; - } else { - modules = modules[0]; - } - - modules += ' modules'; - } - - if (!modules || !modules.length) { - modules = 'unknown modules'; - } - - - KibanaError.call(this, - 'Unable to load ' + modules + ' because of ' + explain + '.', - errors.ScriptLoadFailure); - }; - _.class(errors.ScriptLoadFailure).inherits(KibanaError); - - return errors; -}); \ No newline at end of file diff --git a/src/kibana/components/notify/_notifier.js b/src/kibana/components/notify/_notifier.js deleted file mode 100644 index e8c7ed00658ad..0000000000000 --- a/src/kibana/components/notify/_notifier.js +++ /dev/null @@ -1,355 +0,0 @@ - -define(function (require) { - var _ = require('lodash'); - var $ = require('jquery'); - - var notifs = []; - var setTO = setTimeout; - var clearTO = clearTimeout; - var consoleGroups = ('group' in window.console) && ('groupCollapsed' in window.console) && ('groupEnd' in window.console); - - var fatalSplashScreen = require('text!components/notify/partials/fatal_splash_screen.html'); - - var log = _.noop; - if (typeof KIBANA_DIST === 'undefined') { - log = function () { - console.log.apply(console, arguments); - }; - } - - // used to identify the first call to fatal, set to false there - var firstFatal = true; - - var fatalToastTemplate = (function lazyTemplate(tmpl) { - var compiled; - return function (vars) { - return (compiled || (compiled = _.template(tmpl)))(vars); - }; - }(require('text!components/notify/partials/fatal.html'))); - - function now() { - if (window.performance && window.performance.now) { - return window.performance.now(); - } - return Date.now(); - } - - function closeNotif(cb, key) { - return function () { - // this === notif - var i = notifs.indexOf(this); - if (i !== -1) notifs.splice(i, 1); - if (this.timerId) this.timerId = clearTO(this.timerId); - if (typeof cb === 'function') cb(key); - }; - } - - function add(notif, cb) { - if (notif.lifetime !== Infinity) { - notif.timerId = setTO(function () { - closeNotif(cb, 'ignore').call(notif); - }, notif.lifetime); - } - - if (notif.actions) { - notif.actions.forEach(function (action) { - notif[action] = closeNotif(cb, action); - }); - } - - notif.count = (notif.count || 0) + 1; - - var dup = _.find(notifs, function (item) { - return item.content === notif.content && item.lifetime === notif.lifetime; - }); - - if (dup) { - dup.count += 1; - dup.stacks = _.union(dup.stacks, [notif.stack]); - } else { - notif.stacks = [notif.stack]; - notifs.push(notif); - } - } - - function formatMsg(msg, from) { - var rtn = ''; - if (from) { - rtn += from + ': '; - } - - if (typeof msg === 'string') { - rtn += msg; - } else if (msg instanceof Error) { - rtn += msg.message; - } - - return rtn; - } - - // browsers format Error.stack differently; always include message - function formatStack(err) { - if (err.stack && !~err.stack.indexOf(err.message)) { - return 'Error: ' + err.message + '\n' + err.stack; - } - return err.stack; - } - - /** - * Functionality to check that - */ - function Notifier(opts) { - var self = this; - opts = opts || {}; - - // label type thing to say where notifications came from - self.from = opts.location; - - 'event lifecycle timed fatal error warning info'.split(' ').forEach(function (m) { - self[m] = _.bind(self[m], self); - }); - } - - // to be notified when the first fatal error occurs, push a function into this array. - Notifier.fatalCallbacks = []; - - // set the timer functions that all notification managers will use - Notifier.setTimerFns = function (set, clear) { - setTO = set; - clearTO = clear; - }; - - // simply a pointer to the global notif list - Notifier.prototype._notifs = notifs; - - /** - * Log a sometimes redundant event - * @param {string} name - The name of the group - * @param {boolean} success - Simple flag stating whether the event succeeded - */ - Notifier.prototype.event = createGroupLogger('event', { - open: true - }); - - /** - * Log a major, important, event in the lifecycle of the application - * @param {string} name - The name of the lifecycle event - * @param {boolean} success - Simple flag stating whether the lifecycle event succeeded - */ - Notifier.prototype.lifecycle = createGroupLogger('lifecycle', { - open: true - }); - - /** - * Wrap a function so that it's execution time gets logged. - * - * @param {function} fn - the function to wrap, it's .name property is - * read so make sure to set it - * @return {function} - the wrapped function - */ - Notifier.prototype.timed = function (name, fn) { - var self = this; - - if (typeof name === 'function') { - fn = name; - name = fn.name; - } - - return function WrappedNotifierFunction() { - var cntx = this; - var args = arguments; - - return self.event(name, function () { - return fn.apply(cntx, args); - }); - }; - }; - - /** - * Kill the page, display an error, then throw the error. - * Used as a last-resort error back in many promise chains - * so it rethrows the error that's displayed on the page. - * - * @param {Error} err - The error that occured - */ - Notifier.prototype.fatal = function (err) { - this._showFatal(err); - throw err; - }; - - /** - * Display an error that destroys the entire app. Broken out so that - * global error handlers can display fatal errors without throwing another - * error like in #fatal() - * - * @param {Error} err - The fatal error that occured - */ - Notifier.prototype._showFatal = function (err) { - if (firstFatal) { - _.callEach(Notifier.fatalCallbacks); - firstFatal = false; - window.addEventListener('hashchange', function () { - window.location.reload(); - }); - } - - var html = fatalToastTemplate({ - msg: formatMsg(err, this.from), - stack: formatStack(err) - }); - - var $container = $('#fatal-splash-screen'); - - if (!$container.size()) { - $(document.body) - // in case the app has not completed boot - .removeAttr('ng-cloak') - .html(fatalSplashScreen); - - $container = $('#fatal-splash-screen'); - } - - $container.append(html); - console.error(err.stack); - }; - - /** - * Alert the user of an error that occured - * @param {Error|String} err - */ - Notifier.prototype.error = function (err, cb) { - add({ - type: 'danger', - content: formatMsg(err, this.from), - icon: 'warning', - title: 'Error', - lifetime: Infinity, - actions: ['report', 'accept'], - stack: formatStack(err) - }, cb); - }; - - /** - * Warn the user abort something - * @param {[type]} msg [description] - * @return {[type]} [description] - */ - Notifier.prototype.warning = function (msg, cb) { - add({ - type: 'warning', - content: formatMsg(msg, this.from), - icon: 'warning', - title: 'Warning', - lifetime: 10000, - actions: ['accept'] - }, cb); - }; - - /** - * Display a debug message - * @param {String} msg [description] - * @return {[type]} [description] - */ - Notifier.prototype.info = function (msg, cb) { - add({ - type: 'info', - content: formatMsg(msg, this.from), - icon: 'info-circle', - title: 'Debug', - lifetime: 5000, - actions: ['accept'] - }, cb); - }; - - if (log === _.noop) { - Notifier.prototype.log = _.noop; - } else { - Notifier.prototype.log = function () { - var args = [].slice.apply(arguments); - if (this.from) args.unshift(this.from + ':'); - log.apply(null, args); - }; - } - - // general functionality used by .event() and .lifecycle() - function createGroupLogger(type, opts) { - // Track the groups managed by this logger - var groups = window[type + 'Groups'] = {}; - - return function logger(name, success) { - var status; // status of the timer - var exec; // function to execute and wrap - var ret; // return value - - var complete = function (val) { logger(name, true); return val; }; - var failure = function (err) { logger(name, false); throw err; }; - - if (typeof success === 'function' || success === void 0) { - // start - groups[name] = now(); - if (success) { - // success === the function to time - exec = success; - } else { - // function that can report on the success or failure of an op, and pass their value along - ret = complete; - ret.failure = failure; - } - } - else { - groups[name] = now() - (groups[name] || 0); - var time = ' in ' + groups[name].toFixed(2) + 'ms'; - - // end - if (success) { - status = 'complete' + time; - } else { - groups[name] = false; - status = 'failure' + time; - } - } - - if (consoleGroups) { - if (status) { - console.log(status); - console.groupEnd(); - } else { - if (opts.open) { - console.group(name); - } else { - console.groupCollapsed(name); - } - } - } else { - log('KBN: ' + name + (status ? ' - ' + status : '')); - } - - if (exec) { - try { - ret = exec(); - } catch (e) { - return failure(e); - } - - if (ret && typeof ret.then === 'function') { - // return a new promise that proxies the value - // and logs about the promise outcome - return ret.then(function (val) { - complete(); - return val; - }, function (err) { - failure(err); - throw err; - }); - } - - // the function executed fine, and didn't return a promise, move along - complete(); - } - - return ret; - }; - } - - return Notifier; -}); diff --git a/src/kibana/components/notify/directives.js b/src/kibana/components/notify/directives.js deleted file mode 100644 index 4c9d9a59d0d65..0000000000000 --- a/src/kibana/components/notify/directives.js +++ /dev/null @@ -1,15 +0,0 @@ -define(function (require) { - var notify = require('modules').get('kibana/notify'); - var _ = require('lodash'); - - notify.directive('kbnNotifications', function () { - return { - restrict: 'E', - scope: { - list: '=list' - }, - replace: true, - template: require('text!components/notify/partials/toaster.html') - }; - }); -}); diff --git a/src/kibana/components/notify/notify.js b/src/kibana/components/notify/notify.js deleted file mode 100644 index 201adf7bcafbf..0000000000000 --- a/src/kibana/components/notify/notify.js +++ /dev/null @@ -1,52 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var $ = require('jquery'); - var modules = require('modules'); - var module = modules.get('kibana/notify'); - var errors = require('components/notify/_errors'); - var Notifier = require('components/notify/_notifier'); - var rootNotifier = new Notifier(); - - require('components/notify/directives'); - - module.factory('createNotifier', function () { - return function (opts) { - return new Notifier(opts); - }; - }); - - module.factory('Notifier', function () { - return Notifier; - }); - - module.run(function ($timeout) { - // provide alternate methods for setting timeouts, which will properly trigger digest cycles - Notifier.setTimerFns($timeout, $timeout.cancel); - }); - - /** - * Global Angular exception handler (NOT JUST UNCAUGHT EXCEPTIONS) - */ - // modules - // .get('exceptionOverride') - // .factory('$exceptionHandler', function () { - // return function (exception, cause) { - // rootNotifier.fatal(exception, cause); - // }; - // }); - - /** - * Global Require.js exception handler - */ - window.requirejs.onError = function (err) { - rootNotifier.fatal(new errors.ScriptLoadFailure(err)); - }; - - window.onerror = function (err, url, line) { - rootNotifier.fatal(new Error(err + ' (' + url + ':' + line + ')')); - return true; - }; - - return rootNotifier; - -}); diff --git a/src/kibana/components/number_list/number_list.js b/src/kibana/components/number_list/number_list.js deleted file mode 100644 index e9d779926fb05..0000000000000 --- a/src/kibana/components/number_list/number_list.js +++ /dev/null @@ -1,108 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var parseRange = require('utils/range'); - - require('components/number_list/number_list_input'); - require('modules') - .get('kibana') - .directive('kbnNumberList', function () { - return { - restrict: 'E', - template: require('text!components/number_list/number_list.html'), - controllerAs: 'numberListCntr', - require: 'ngModel', - controller: function ($scope, $attrs, $parse) { - var self = this; - - // Called from the pre-link function once we have the controllers - self.init = function (modelCntr) { - self.modelCntr = modelCntr; - - self.getList = function () { - return self.modelCntr.$modelValue; - }; - - self.getUnitName = _.partial($parse($attrs.unit), $scope); - - var defaultRange = self.range = parseRange('[0,Infinity)'); - - $scope.$watch(function () { - return $attrs.range; - }, function (range, prev) { - if (!range) { - self.range = defaultRange; - return; - } - - try { - self.range = parseRange(range); - } catch (e) { - throw new TypeError('Unable to parse range: ' + e.message); - } - }); - - /** - * Remove an item from list by index - * @param {number} index - * @return {undefined} - */ - self.remove = function (index) { - var list = self.getList(); - if (!list) return; - - list.splice(index, 1); - }; - - /** - * Add an item to the end of the list - * @return {undefined} - */ - self.add = function () { - var list = self.getList(); - if (!list) return; - - list.push(_.last(list) + 1); - }; - - /** - * Check to see if the list is too short. - * - * @return {Boolean} - */ - self.tooShort = function () { - return _.size(self.getList()) < 1; - }; - - /** - * Check to see if the list is too short, but simply - * because the user hasn't interacted with it yet - * - * @return {Boolean} - */ - self.undefinedLength = function () { - return self.tooShort() && (self.modelCntr.$untouched && self.modelCntr.$pristine); - }; - - /** - * Check to see if the list is too short - * - * @return {Boolean} - */ - self.invalidLength = function () { - return self.tooShort() && !self.undefinedLength(); - }; - - $scope.$watchCollection(self.getList, function () { - self.modelCntr.$setValidity('numberListLength', !self.tooShort()); - }); - }; - }, - link: { - pre: function ($scope, $el, attrs, ngModelCntr) { - $scope.numberListCntr.init(ngModelCntr); - } - }, - }; - }); - -}); diff --git a/src/kibana/components/persisted_log/persisted_log.js b/src/kibana/components/persisted_log/persisted_log.js deleted file mode 100644 index 1e7427b6f1524..0000000000000 --- a/src/kibana/components/persisted_log/persisted_log.js +++ /dev/null @@ -1,48 +0,0 @@ -define(function (require) { - var modules = require('modules'); - var _ = require('lodash'); - - modules.get('kibana/persisted_log') - .factory('PersistedLog', function ($window, localStorage) { - function PersistedLog(name, options) { - options = options || {}; - this.name = name; - this.maxLength = options.maxLength || 0; - this.filterDuplicates = options.filterDuplicates || false; - this.items = localStorage.get(this.name) || []; - } - - PersistedLog.prototype.add = function (val) { - if (val == null) { - return this.items; - } - - var stack = this.items; - - // remove any matching items from the stack if option is set - if (this.filterDuplicates) { - stack = _.pull(this.items, val); - stack = _.filter(stack, function (item) { - return !_.isEqual(item, val); - }); - } - - stack.unshift(val); - - // if maxLength is set, truncate the stack - if (this.maxLength > 0) { - stack = stack.slice(0, this.maxLength); - } - - // persist the stack - localStorage.set(this.name, stack); - return this.items = stack; - }; - - PersistedLog.prototype.get = function () { - return this.items; - }; - - return PersistedLog; - }); -}); \ No newline at end of file diff --git a/src/kibana/components/reflow_watcher.js b/src/kibana/components/reflow_watcher.js deleted file mode 100644 index bc9e8a441e224..0000000000000 --- a/src/kibana/components/reflow_watcher.js +++ /dev/null @@ -1,68 +0,0 @@ -define(function (require) { - return function ReflowWatcherService(Private, $rootScope, $http) { - var angular = require('angular'); - var $ = require('jquery'); - var _ = require('lodash'); - - var EventEmitter = Private(require('factories/events')); - var $body = $(document.body); - var $window = $(window); - - var MOUSE_EVENTS = 'mouseup'; - var WINDOW_EVENTS = 'resize'; - - _.class(ReflowWatcher).inherits(EventEmitter); - /** - * Watches global activity which might hint at a change in the content, which - * in turn provides a hint to resizers that they should check their size - */ - function ReflowWatcher() { - ReflowWatcher.Super.call(this); - - // bound version of trigger that can be used as a handler - this.trigger = _.bind(this.trigger, this); - this._emitReflow = _.bind(this._emitReflow, this); - - // list of functions to call that will unbind our watchers - this._unwatchers = [ - $rootScope.$watchCollection(function () { - return $http.pendingRequests; - }, this.trigger) - ]; - - $body.on(MOUSE_EVENTS, this.trigger); - $window.on(WINDOW_EVENTS, this.trigger); - } - - /** - * Simply emit reflow, but in a way that can be bound and passed to - * other functions. Using _.bind caused extra arguments to be added, and - * then emitted to other places. No Bueno - * - * @return {void} - */ - ReflowWatcher.prototype._emitReflow = function () { - this.emit('reflow'); - }; - - /** - * Emit the "reflow" event in the next tick of the digest cycle - * @return {void} - */ - ReflowWatcher.prototype.trigger = function () { - $rootScope.$evalAsync(this._emitReflow); - }; - - /** - * Signal to the ReflowWatcher that it should clean up it's listeners - * @return {void} - */ - ReflowWatcher.prototype.destroy = function () { - $body.off(MOUSE_EVENTS, this.trigger); - $window.off(WINDOW_EVENTS, this.trigger); - _.callEach(this._unwatchers); - }; - - return new ReflowWatcher(); - }; -}); \ No newline at end of file diff --git a/src/kibana/components/setup/_setup_error.js b/src/kibana/components/setup/_setup_error.js deleted file mode 100644 index 0c30cb6b64391..0000000000000 --- a/src/kibana/components/setup/_setup_error.js +++ /dev/null @@ -1,18 +0,0 @@ -define(function (require) { - return function SetupErrorFactory(configFile) { - var _ = require('lodash'); - - function SetupError(template, err) { - // don't override other setup errors - if (err && err instanceof SetupError) return err; - - var err2 = new Error(_.template(template)({ configFile: configFile })); - if (err) { - err2.origError = err; - if (err.stack) err2.stack = err.stack; - } - return err2; - } - return SetupError; - }; -}); diff --git a/src/kibana/components/setup/setup.js b/src/kibana/components/setup/setup.js deleted file mode 100644 index af5e88beb5b35..0000000000000 --- a/src/kibana/components/setup/setup.js +++ /dev/null @@ -1,29 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var $ = require('jquery'); - - require('components/notify/notify'); - - require('modules').get('components/setup', ['kibana', 'kibana/notify', 'kibana/config']) - .service('kbnSetup', function (Private, Promise, Notifier, es, configFile) { - // setup steps - var checkForEs = Private(require('components/setup/steps/check_for_es')); - var checkEsVersion = Private(require('components/setup/steps/check_es_version')); - var checkForKibanaIndex = Private(require('components/setup/steps/check_for_kibana_index')); - var createKibanaIndex = Private(require('components/setup/steps/create_kibana_index')); - - var notify = new Notifier({ location: 'Setup' }); - - return _.once(function () { - var complete = notify.lifecycle('bootstrap'); - - return checkForEs() - .then(checkEsVersion) - .then(checkForKibanaIndex) - .then(function (exists) { - if (!exists) return createKibanaIndex(); - }) - .then(complete, complete.failure); - }); - }); -}); \ No newline at end of file diff --git a/src/kibana/components/setup/steps/check_es_version.js b/src/kibana/components/setup/steps/check_es_version.js deleted file mode 100644 index 54534043d4c69..0000000000000 --- a/src/kibana/components/setup/steps/check_es_version.js +++ /dev/null @@ -1,43 +0,0 @@ -define(function (require) { - return function CheckEsVersionFn(Private, es, configFile, Notifier, minimumElasticsearchVersion) { - - var _ = require('lodash'); - var versionmath = require('utils/versionmath'); - var esBool = require('utils/esBool'); - var notify = new Notifier({ - location: 'Setup: Elasticsearch version check' - }); - - return notify.timed(function checkEsVersion() { - var SetupError = Private(require('components/setup/_setup_error')); - - return es.nodes.info() - .then(function (info) { - var badNodes = _.filter(info.nodes, function (node) { - // remove client nodes (Logstash) - var isClient = _.get(node, 'attributes.client'); - if (isClient != null && esBool(isClient) === true) { - return false; - } - - // remove nodes that are gte the min version - var v = node.version.split('-')[0]; - return !versionmath.gte(minimumElasticsearchVersion, v); - }); - - if (!badNodes.length) return true; - - var badNodeNames = badNodes.map(function (node) { - return 'Elasticsearch v' + node.version + ' @ ' + node.http_address + ' (' + node.ip + ')'; - }); - - throw SetupError( - 'This version of Kibana requires Elasticsearch ' + - minimumElasticsearchVersion + ' or higher on all nodes. ' + - 'I found the following incompatible nodes in your cluster: \n\n' + - badNodeNames.join('\n') - ); - }); - }); - }; -}); \ No newline at end of file diff --git a/src/kibana/components/setup/steps/check_for_es.js b/src/kibana/components/setup/steps/check_for_es.js deleted file mode 100644 index 951f52543281e..0000000000000 --- a/src/kibana/components/setup/steps/check_for_es.js +++ /dev/null @@ -1,21 +0,0 @@ -define(function (require) { - return function checkForEsFunction(Private, Notifier, es, configFile) { - var SetupError = Private(require('components/setup/_setup_error')); - var notify = new Notifier({ location: 'Setup: Elasticsearch check' }); - - return function checkForES() { - var complete = notify.lifecycle('es check'); - return es.info({ - method: 'GET' - }) - .catch(function (err) { - if (err.body && err.body.message) { - throw new SetupError(err.body.message, err); - } else { - throw new SetupError('Unknown error while connecting to Elasticsearch', err); - } - }) - .then(complete, complete.failure); - }; - }; -}); \ No newline at end of file diff --git a/src/kibana/components/setup/steps/check_for_kibana_index.js b/src/kibana/components/setup/steps/check_for_kibana_index.js deleted file mode 100644 index ca962e372cd59..0000000000000 --- a/src/kibana/components/setup/steps/check_for_kibana_index.js +++ /dev/null @@ -1,17 +0,0 @@ -define(function (require) { - return function CheckForKibanaIndexFn(Private, es, Notifier, configFile) { - var SetupError = Private(require('components/setup/_setup_error')); - var notify = new Notifier({ location: 'Setup: Kibana index check' }); - - return function checkForKibana() { - var complete = notify.lifecycle('kibana index check'); - return es.indices.exists({ - index: configFile.kibana_index - }) - .catch(function (err) { - throw new SetupError('Unable to check for Kibana index "<%= configFile.kibana_index %>"', err); - }) - .then(complete, complete.failure); - }; - }; -}); diff --git a/src/kibana/components/setup/steps/create_kibana_index.js b/src/kibana/components/setup/steps/create_kibana_index.js deleted file mode 100644 index 840984c57f07d..0000000000000 --- a/src/kibana/components/setup/steps/create_kibana_index.js +++ /dev/null @@ -1,31 +0,0 @@ -define(function (require) { - return function CreateKibanaIndexFn(Private, es, configFile, Notifier) { - return function createKibanaIndex() { - var notify = new Notifier({ location: 'Setup: Kibana Index Creation' }); - var complete = notify.lifecycle('kibana index creation'); - var SetupError = Private(require('components/setup/_setup_error')); - - return es.indices.create({ - index: configFile.kibana_index, - body: { - settings: { - number_of_shards : 1 - } - } - }) - .catch(function (err) { - throw new SetupError('Unable to create Kibana index "<%= configFile.kibana_index %>"', err); - }) - .then(function () { - return es.cluster.health({ - waitForStatus: 'yellow', - index: configFile.kibana_index - }) - .catch(function (err) { - throw new SetupError('Waiting for Kibana index "<%= configFile.kibana_index %>" to come online failed', err); - }); - }) - .then(complete, complete.failure); - }; - }; -}); diff --git a/src/kibana/components/state_management/app_state.js b/src/kibana/components/state_management/app_state.js deleted file mode 100644 index 509e4bcdd4571..0000000000000 --- a/src/kibana/components/state_management/app_state.js +++ /dev/null @@ -1,54 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var modules = require('modules'); - var urlParam = '_a'; - - - function AppStateProvider(Private, $rootScope, getAppState) { - var State = Private(require('components/state_management/state')); - - - _.class(AppState).inherits(State); - function AppState(defaults) { - AppState.Super.call(this, urlParam, defaults); - getAppState._set(this); - } - - // if the url param is missing, write it back - AppState.prototype._persistAcrossApps = false; - - - AppState.prototype.destroy = function () { - AppState.Super.prototype.destroy.call(this); - getAppState._set(null); - }; - - return AppState; - } - - modules.get('kibana/global_state') - .factory('AppState', function (Private) { - return Private(AppStateProvider); - }) - .service('getAppState', function ($location) { - var currentAppState; - - function get() { - return currentAppState; - } - - // Checks to see if the appState might already exist, even if it hasn't been newed up - get.previouslyStored = function () { - var search = $location.search(); - return search[urlParam] ? true : false; - }; - - get._set = function (current) { - currentAppState = current; - }; - - return get; - }); - - return AppStateProvider; -}); diff --git a/src/kibana/components/state_management/global_state.js b/src/kibana/components/state_management/global_state.js deleted file mode 100644 index 7d4b6b1d46919..0000000000000 --- a/src/kibana/components/state_management/global_state.js +++ /dev/null @@ -1,26 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var angular = require('angular'); - var qs = require('utils/query_string'); - var rison = require('utils/rison'); - - var module = require('modules').get('kibana/global_state'); - - module.service('globalState', function (Private, $rootScope, $location) { - var State = Private(require('components/state_management/state')); - - _.class(GlobalState).inherits(State); - function GlobalState(defaults) { - GlobalState.Super.call(this, '_g', defaults); - } - - // if the url param is missing, write it back - GlobalState.prototype._persistAcrossApps = true; - - GlobalState.prototype.removeFromUrl = function (url) { - return qs.replaceParamInUrl(url, this._urlParam, null); - }; - - return new GlobalState(); - }); -}); diff --git a/src/kibana/components/state_management/state.js b/src/kibana/components/state_management/state.js deleted file mode 100644 index 399e08de8d215..0000000000000 --- a/src/kibana/components/state_management/state.js +++ /dev/null @@ -1,151 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var rison = require('utils/rison'); - - var applyDiff = require('utils/diff_object'); - var qs = require('utils/query_string'); - - return function StateProvider(Notifier, Private, $rootScope, $location) { - var Events = Private(require('factories/events')); - - _.class(State).inherits(Events); - function State(urlParam, defaults) { - State.Super.call(this); - - var self = this; - self.setDefaults(defaults); - self._urlParam = urlParam || '_s'; - - // When the URL updates we need to fetch the values from the URL - self._cleanUpListeners = _.partial(_.callEach, [ - // partial route update, no app reload - $rootScope.$on('$routeUpdate', function () { - self.fetch(); - }), - - // begining of full route update, new app will be initialized before - // $routeChangeSuccess or $routeChangeError - $rootScope.$on('$routeChangeStart', function () { - if (self._persistAcrossApps) { - self.fetch(); - } else { - self.destroy(); - } - }) - ]); - - // Initialize the State with fetch - self.fetch(); - } - - State.prototype._readFromURL = function () { - var search = $location.search(); - try { - return search[this._urlParam] ? rison.decode(search[this._urlParam]) : null; - } catch (e) { - var notify = new Notifier(); - notify.error('Unable to parse URL'); - search[this._urlParam] = rison.encode(this._defaults); - $location.search(search).replace(); - return null; - } - }; - - /** - * Fetches the state from the url - * @returns {void} - */ - State.prototype.fetch = function () { - var stash = this._readFromURL(); - - // nothing to read from the url? save if ordered to persist - if (stash === null) { - if (this._persistAcrossApps) { - return this.save(); - } else { - stash = {}; - } - } - - _.defaults(stash, this._defaults); - // apply diff to state from stash, will change state in place via side effect - var diffResults = applyDiff(this, stash); - - if (diffResults.keys.length) { - this.emit('fetch_with_changes', diffResults.keys); - } - }; - - /** - * Saves the state to the url - * @returns {void} - */ - State.prototype.save = function (replace) { - var stash = this._readFromURL(); - var state = this.toObject(); - replace = replace || false; - - if (!stash) { - replace = true; - stash = {}; - } - - _.defaults(state, this._defaults); - // apply diff to state from stash, will change state in place via side effect - var diffResults = applyDiff(stash, state); - - if (diffResults.keys.length) { - this.emit('save_with_changes', diffResults.keys); - } - - // persist the state in the URL - var search = $location.search(); - search[this._urlParam] = this.toRISON(); - if (replace) { - $location.search(search).replace(); - } else { - $location.search(search); - } - }; - - /** - * Calls save with a forced replace - * @returns {void} - */ - State.prototype.replace = function () { - this.save(true); - }; - - /** - * Resets the state to the defaults - * - * @returns {void} - */ - State.prototype.reset = function () { - // apply diff to _attributes from defaults, this is side effecting so - // it will change the state in place. - var diffResults = applyDiff(this, this._defaults); - if (diffResults.keys.length) { - this.emit('reset_with_changes', diffResults.keys); - } - this.save(); - }; - - /** - * Cleans up the state object - * @returns {void} - */ - State.prototype.destroy = function () { - this.off(); // removes all listners - this._cleanUpListeners(); // Removes the $routeUpdate listner - }; - - State.prototype.setDefaults = function (defaults) { - this._defaults = defaults || {}; - }; - - return State; - - }; - -}); diff --git a/src/kibana/components/storage/storage.js b/src/kibana/components/storage/storage.js deleted file mode 100644 index d8873c104e3d1..0000000000000 --- a/src/kibana/components/storage/storage.js +++ /dev/null @@ -1,43 +0,0 @@ -define(function (require) { - var modules = require('modules'); - var angular = require('angular'); - - function Storage(store) { - var self = this; - self.store = store; - - self.get = function (key) { - try { - return JSON.parse(self.store.getItem(key)); - } catch (e) { - return null; - } - }; - - self.set = function (key, value) { - try { - return self.store.setItem(key, angular.toJson(value)); - } catch (e) { - return false; - } - }; - - self.remove = function (key) { - return self.store.removeItem(key); - }; - - self.clear = function () { - return self.store.clear(); - }; - } - - var createService = function (type) { - return function ($window) { - return new Storage($window[type]); - }; - }; - - modules.get('kibana/storage') - .service('localStorage', createService('localStorage')) - .service('sessionStorage', createService('sessionStorage')); -}); \ No newline at end of file diff --git a/src/kibana/components/stringify/.jshintrc b/src/kibana/components/stringify/.jshintrc deleted file mode 100644 index 6a5e6e12a7db9..0000000000000 --- a/src/kibana/components/stringify/.jshintrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../.jshintrc", - "unused": true -} diff --git a/src/kibana/components/stringify/register.js b/src/kibana/components/stringify/register.js deleted file mode 100644 index d4c5970f7f61c..0000000000000 --- a/src/kibana/components/stringify/register.js +++ /dev/null @@ -1,11 +0,0 @@ -define(function (require) { - var fieldFormats = require('registry/field_formats'); - fieldFormats.register(require('components/stringify/types/Url')); - fieldFormats.register(require('components/stringify/types/Bytes')); - fieldFormats.register(require('components/stringify/types/Date')); - fieldFormats.register(require('components/stringify/types/Ip')); - fieldFormats.register(require('components/stringify/types/Number')); - fieldFormats.register(require('components/stringify/types/Percent')); - fieldFormats.register(require('components/stringify/types/String')); - fieldFormats.register(require('components/stringify/types/Source')); -}); diff --git a/src/kibana/components/stringify/types/Bytes.js b/src/kibana/components/stringify/types/Bytes.js deleted file mode 100644 index 2cfeb57667ad0..0000000000000 --- a/src/kibana/components/stringify/types/Bytes.js +++ /dev/null @@ -1,10 +0,0 @@ -define(function (require) { - return function BytesFormatProvider(Private) { - var Numeral = Private(require('components/stringify/types/_Numeral')); - return Numeral.factory({ - id: 'bytes', - title: 'Bytes', - sampleInputs: [1024, 5150000, 1990000000] - }); - }; -}); diff --git a/src/kibana/components/style_compile/style_compile.css.tmpl b/src/kibana/components/style_compile/style_compile.css.tmpl deleted file mode 100644 index 1f23c6fb57a06..0000000000000 --- a/src/kibana/components/style_compile/style_compile.css.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -.truncate-by-height { - max-height: <%= truncateMaxHeight %>; - display: inline-block; -} -.truncate-by-height::before { - top: <%= truncateGradientTop %>; -} \ No newline at end of file diff --git a/src/kibana/components/style_compile/style_compile.js b/src/kibana/components/style_compile/style_compile.js deleted file mode 100644 index 5ce60aca5acc1..0000000000000 --- a/src/kibana/components/style_compile/style_compile.js +++ /dev/null @@ -1,32 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - var $ = require('jquery'); - var $style = $('");}.call(this,"cov" in locals_for_with?locals_for_with.cov:typeof cov!=="undefined"?cov:undefined,"coverageClass" in locals_for_with?locals_for_with.coverageClass:typeof coverageClass!=="undefined"?coverageClass:undefined,"id" in locals_for_with?locals_for_with.id:typeof id!=="undefined"?id:undefined,"undefined" in locals_for_with?locals_for_with.undefined:typeof undefined!=="undefined"?undefined:undefined));;return buf.join(""); -} - -}); \ No newline at end of file diff --git a/test/utils/istanbul_reporter/reporter.js b/test/utils/istanbul_reporter/reporter.js deleted file mode 100644 index b53e3d2f25378..0000000000000 --- a/test/utils/istanbul_reporter/reporter.js +++ /dev/null @@ -1,256 +0,0 @@ -/** - * TODO: move this into it's own module, with it's own dependencies - */ - -require.config({ - paths: { - // jade runtime is required by the AMD wrapped jade templates as "jade" - jade: '/amd-wrap/node_modules/grunt-contrib-jade/node_modules/jade/runtime' - } -}); - -// fake fs module to make jade/runtime.js happy -define('fs', function () {}); - -// fake process obejct to make browserify-path happy -window.process = window.process || { cwd: function () { return '.'; }}; - -// the actual reporter module -define(function (require) { - - var _ = require('lodash'); - var $ = require('jquery'); - - var InsertionText = require('/amd-wrap/node_modules/istanbul/lib/util/insertion-text.js'); - var objUtils = require('/amd-wrap/node_modules/istanbul/lib/object-utils.js'); - // var annotate = require('/amd-wrap/node_modules/istanbul/lib/annotate.js'); - var Progress = require('/amd-wrap/node_modules/mocha/lib/browser/progress.js'); - var path = require('/amd-wrap/node_modules/path-browserify/index.js'); - - var template = require('./report.jade'); - - var Base = window.Mocha.reporters.Base; - - var covGrepQueryParamRE = /cov_grep=([^&]+)/; - - var afterDraw = window.requestAnimationFrame || function (cb) { setTimeout(cb, 500); }; - - function IstanbulReporter(runner) { - // "inherit" the base reporters characteristics - Base.call(this, runner); - - var stats = this.stats; - var gotoFile = window.location.hash; - if (gotoFile) window.location.hash = ''; - - $(document.body) - .html('
'); - - var canvas = document.getElementsByTagName('canvas')[0]; - var ctx; - var progress; - if (canvas.getContext) { - var ratio = window.devicePixelRatio || 1; - canvas.style.width = canvas.width; - canvas.style.height = canvas.height; - canvas.width *= ratio; - canvas.height *= ratio; - ctx = canvas.getContext('2d'); - ctx.scale(ratio, ratio); - progress = new Progress(); - progress.size(40); - } - - runner.on('test end', function () { - if (progress) { - progress - .update((stats.tests / this.total) * 100 || 0) - .draw(ctx); - } - }); - - runner.on('end', function () { - var stats = _.omit(this.stats, 'start', 'end', 'suites'); - - stats['create report'] = Date.now(); - $(document.body).empty().append($(createReport())); // attempt to force parsing immediately - stats['create report'] = Date.now() - stats['create report']; - - toSec(stats, 'create report'); - toSec(stats, 'duration'); - console.log(JSON.stringify(stats, null, ' ')); - - linkNav(); - if (gotoFile) { - afterDraw(function () { - window.location.hash = gotoFile; - }); - } - }); - } - - function createReport() { - var covResults = window.__coverage__; - var grep = window.location.search.match(covGrepQueryParamRE); - if (grep) { - grep = decodeURIComponent(grep[1]); - covResults = _.transform(covResults, function (results, cov, filename) { - if (~filename.indexOf(grep)) { - results[filename] = cov; - } - }); - } - - var summary = objUtils.summarizeCoverage(covResults); - - var dirs = _(covResults) - .map(convertFile) - .groupBy(function (file) { - var dir = path.dirname(file.filename); - return dir === '.' ? '' : dir; - }) - .transform(function (dirs, files, dirname) { - _.each(files, function (file) { - file.relname = dirname ? path.relative(dirname, file.filename) : file.filename; - }); - - dirs.push({ - name: dirname, - files: files, - coverage: _.reduce(files, function (sum, file) { - return sum + file.coverage; - }, 0) / files.length - }); - }, []) - .sortBy('name') - .value(); - - return template({ - cov: { - dirs: dirs, - coverage: summary.lines.pct, - sloc: summary.lines.total, - hits: summary.lines.covered, - misses: summary.lines.total - summary.lines.covered - }, - dirname: path.dirname, - relative: path.relative, - coverageClass: function (coverage) { - if (coverage >= 75) return 'high'; - if (coverage >= 50) return 'medium'; - if (coverage >= 25) return 'low'; - return 'terrible'; - } - }); - } - - function convertFile(file) { - var summary = objUtils.summarizeFileCoverage(file); - var count = 0; - var structured = file.code.map(function (str) { - count += 1; - return { - line: count, - covered: null, - text: new InsertionText(str, true) - }; - }); - var html = ''; - - structured.unshift({ - line: 0, - covered: null, - text: new InsertionText('') - }); - - _.forOwn(file.l, function (count, lineNumber) { - structured[lineNumber].covered = count > 0 ? true : false; - }); - - // annotate.Lines(file, structured); - //note: order is important, since statements typically result in spanning the whole line and doing branches late - //causes mismatched tags - // annotate.Branches(file, structured); - // annotate.Functions(file, structured); - // annotate.Statements(file, structured); - - structured.shift(); - - var context = { - filename: file.path, - sloc: summary.lines.total, - coverage: summary.lines.pct, - hits: summary.lines.covered, - misses: summary.lines.total - summary.lines.covered, - source: _.map(structured, function (line, lineNumber) { - return { - coverage: file.l[line.line], - source: line.text + '' - }; - }) - }; - - return context; - - // writer.write(detailTemplate(context)); - // writer.write('\n'); - // writer.write(footerTemplate(templateData)); - } - - function linkNav() { - var headings = $('h2').toArray(); - - // when scrolling, highlight the related menu item - $(window).scroll(function (e) { - var heading = find(window.scrollY); - if (!heading) return; - var links = document.querySelectorAll('#menu a') - , link; - - for (var i = 0, len = links.length; i < len; ++i) { - link = links[i]; - link.className = link.getAttribute('href') === '#' + heading.id - ? 'active' - : ''; - } - }); - - // find the file they are probably looking at - function find(y) { - var i = headings.length - , heading; - - while (i--) { - heading = headings[i]; - if (y >= heading.offsetTop) { - return heading; - } - } - } - - $('#menu').on('click', '.dirname .cov', function () { - var dir = $(this).parent()[0].childNodes[0].textContent; - var loc = window.location; - var proto = loc.protocol; - var host = loc.host; - var path = loc.pathname; - var search = loc.search; - var hash = loc.hash; - - var grep = 'cov_grep=' + encodeURIComponent(dir); - if (search && search.match(covGrepQueryParamRE)) { - search = search.replace(covGrepQueryParamRE, grep); - } else { - search = (search ? search + '&' : '?') + grep; - } - - window.location = path + search + hash; - }); - } - - function toSec(stats, prop) { - return stats[prop] = (stats[prop] / 1000).toFixed(2) + ' sec'; - } - - return IstanbulReporter; -}); diff --git a/test/utils/no_digest_promises.js b/test/utils/no_digest_promises.js deleted file mode 100644 index b6fdb3fd64be8..0000000000000 --- a/test/utils/no_digest_promises.js +++ /dev/null @@ -1,34 +0,0 @@ -define(['angular', 'bluebird', 'services/promises'], function (angular, Bluebird) { - /** - * replace the Promise service with Bluebird so that tests - * can use promises without having to call $rootScope.apply() - * - * var nonDigestPromises = require('test_utils/non_digest_promises'); - * - * describe('some module that does complex shit with promises', function () { - * beforeEach(nonDigestPromises.activate); - * - * }); - */ - - var active = false; - - angular.module('kibana') - .config(function ($provide) { - $provide.decorator('Promise', function ($delegate) { - return active ? Bluebird : $delegate; - }); - }); - - function activate() { active = true; } - function deactivate() { active = false; } - - return { - activate: activate, - deactivate: deactivate, - activateForSuite: function () { - before(activate); - after(deactivate); - } - }; -}); \ No newline at end of file diff --git a/test/utils/simulate_keys.js b/test/utils/simulate_keys.js deleted file mode 100644 index c397a2101a91f..0000000000000 --- a/test/utils/simulate_keys.js +++ /dev/null @@ -1,105 +0,0 @@ -define(function (require) { - var $ = require('jquery'); - var _ = require('lodash'); - var Promise = require('bluebird'); - var keyMap = require('utils/key_map'); - var reverseKeyMap = _.mapValues(_.invert(keyMap), _.ary(_.parseInt, 1)); - var KeyboardEvent = window.KeyboardEvent; - - /** - * Simulate keyboard events in an element. This allows testing the way that - * elements respond to keyboard input. - * - * # sequence style - * keyboard events occur in a sequence, this array of events describe that sequence. - * - * ## event - * an object with a type property, or a string which will be turned into a single press - * - * ## event types - * ### press - * represents a key press - * - `key`: the key for the button pressed - * - `events`: optional list of events that occur before this press completes - * - * ### wait - * represents a pause in a sequence - * - `ms`: the number of milliseconds that the pause takes - * - * ### repeat - * represents a key being repeated because it is held down. Should only exist as a - * sub event of `press` events. - * - `count`: the number of times the repeat occurs - * - * @param {element} $el - jQuery element where events should occur - * @param {[type]} sequence - an array of events - * @async - */ - return function ($el, sequence) { - var modifierState = { - ctrlKey: false, - shiftKey: false, - altKey: false, - metaKey: false - }; - - return doList(_.clone(sequence)); - - function setModifier(key, state) { - var name = key + 'Key'; - if (modifierState.hasOwnProperty(name)) { - modifierState[name] = !!state; - } - } - - function doList(list) { - return Promise.try(function () { - if (!list || !list.length) return; - - var event = list[0]; - if (_.isString(event)) { - event = { type: 'press', key: event }; - } - - switch (event.type) { - case 'press': - return Promise.resolve() - .then(_.partial(fire, 'keydown', event.key)) - .then(_.partial(fire, 'keypress', event.key)) - .then(_.partial(doList, event.events)) - .then(_.partial(fire, 'keyup', event.key)); - - case 'wait': - return Promise.delay(event.ms); - - case 'repeat': - return (function again(remaining) { - if (!remaining) return Promise.resolve(); - remaining = remaining - 1; - return Promise.resolve() - .then(_.partial(fire, 'keydown', event.key, true)) - .then(_.partial(fire, 'keypress', event.key, true)) - .then(_.partial(again, remaining)); - }(event.count)); - - default: - throw new TypeError('invalid event type "' + event.type + '"'); - } - }) - .then(function () { - if (_.size(list) > 1) return doList(list.slice(1)); - }); - } - - function fire(type, key, repeat) { - var keyCode = reverseKeyMap[key]; - if (!keyCode) throw new TypeError('invalid key "' + key + '"'); - - if (type === 'keydown') setModifier(key, true); - if (type === 'keyup') setModifier(key, false); - - var $target = _.isFunction($el) ? $el() : $el; - $target.trigger($.Event(type, _.defaults({ keyCode: keyCode }, modifierState))); - } - }; -}); \ No newline at end of file diff --git a/test/utils/sinon/sinon-1.8.2.js b/test/utils/sinon/sinon-1.8.2.js deleted file mode 100644 index 657ee9e957d74..0000000000000 --- a/test/utils/sinon/sinon-1.8.2.js +++ /dev/null @@ -1,4728 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -this.sinon = (function () { -var samsam, formatio; -function define(mod, deps, fn) { if (mod == "samsam") { samsam = deps(); } else { formatio = fn(samsam); } } -define.amd = true; -((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) || - (typeof module === "object" && - function (m) { module.exports = m(); }) || // Node - function (m) { this.samsam = m(); } // Browser globals -)(function () { - var o = Object.prototype; - var div = typeof document !== "undefined" && document.createElement("div"); - - function isNaN(value) { - // Unlike global isNaN, this avoids type coercion - // typeof check avoids IE host object issues, hat tip to - // lodash - var val = value; // JsLint thinks value !== value is "weird" - return typeof value === "number" && value !== val; - } - - function getClass(value) { - // Returns the internal [[Class]] by calling Object.prototype.toString - // with the provided value as this. Return value is a string, naming the - // internal class, e.g. "Array" - return o.toString.call(value).split(/[ \]]/)[1]; - } - - /** - * @name samsam.isArguments - * @param Object object - * - * Returns ``true`` if ``object`` is an ``arguments`` object, - * ``false`` otherwise. - */ - function isArguments(object) { - if (typeof object !== "object" || typeof object.length !== "number" || - getClass(object) === "Array") { - return false; - } - if (typeof object.callee == "function") { return true; } - try { - object[object.length] = 6; - delete object[object.length]; - } catch (e) { - return true; - } - return false; - } - - /** - * @name samsam.isElement - * @param Object object - * - * Returns ``true`` if ``object`` is a DOM element node. Unlike - * Underscore.js/lodash, this function will return ``false`` if ``object`` - * is an *element-like* object, i.e. a regular object with a ``nodeType`` - * property that holds the value ``1``. - */ - function isElement(object) { - if (!object || object.nodeType !== 1 || !div) { return false; } - try { - object.appendChild(div); - object.removeChild(div); - } catch (e) { - return false; - } - return true; - } - - /** - * @name samsam.keys - * @param Object object - * - * Return an array of own property names. - */ - function keys(object) { - var ks = [], prop; - for (prop in object) { - if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); } - } - return ks; - } - - /** - * @name samsam.isDate - * @param Object value - * - * Returns true if the object is a ``Date``, or *date-like*. Duck typing - * of date objects work by checking that the object has a ``getTime`` - * function whose return value equals the return value from the object's - * ``valueOf``. - */ - function isDate(value) { - return typeof value.getTime == "function" && - value.getTime() == value.valueOf(); - } - - /** - * @name samsam.isNegZero - * @param Object value - * - * Returns ``true`` if ``value`` is ``-0``. - */ - function isNegZero(value) { - return value === 0 && 1 / value === -Infinity; - } - - /** - * @name samsam.equal - * @param Object obj1 - * @param Object obj2 - * - * Returns ``true`` if two objects are strictly equal. Compared to - * ``===`` there are two exceptions: - * - * - NaN is considered equal to NaN - * - -0 and +0 are not considered equal - */ - function identical(obj1, obj2) { - if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) { - return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2); - } - } - - - /** - * @name samsam.deepEqual - * @param Object obj1 - * @param Object obj2 - * - * Deep equal comparison. Two values are "deep equal" if: - * - * - They are equal, according to samsam.identical - * - They are both date objects representing the same time - * - They are both arrays containing elements that are all deepEqual - * - They are objects with the same set of properties, and each property - * in ``obj1`` is deepEqual to the corresponding property in ``obj2`` - * - * Supports cyclic objects. - */ - function deepEqualCyclic(obj1, obj2) { - - // used for cyclic comparison - // contain already visited objects - var objects1 = [], - objects2 = [], - // contain pathes (position in the object structure) - // of the already visited objects - // indexes same as in objects arrays - paths1 = [], - paths2 = [], - // contains combinations of already compared objects - // in the manner: { "$1['ref']$2['ref']": true } - compared = {}; - - /** - * used to check, if the value of a property is an object - * (cyclic logic is only needed for objects) - * only needed for cyclic logic - */ - function isObject(value) { - - if (typeof value === 'object' && value !== null && - !(value instanceof Boolean) && - !(value instanceof Date) && - !(value instanceof Number) && - !(value instanceof RegExp) && - !(value instanceof String)) { - - return true; - } - - return false; - } - - /** - * returns the index of the given object in the - * given objects array, -1 if not contained - * only needed for cyclic logic - */ - function getIndex(objects, obj) { - - var i; - for (i = 0; i < objects.length; i++) { - if (objects[i] === obj) { - return i; - } - } - - return -1; - } - - // does the recursion for the deep equal check - return (function deepEqual(obj1, obj2, path1, path2) { - var type1 = typeof obj1; - var type2 = typeof obj2; - - // == null also matches undefined - if (obj1 === obj2 || - isNaN(obj1) || isNaN(obj2) || - obj1 == null || obj2 == null || - type1 !== "object" || type2 !== "object") { - - return identical(obj1, obj2); - } - - // Elements are only equal if identical(expected, actual) - if (isElement(obj1) || isElement(obj2)) { return false; } - - var isDate1 = isDate(obj1), isDate2 = isDate(obj2); - if (isDate1 || isDate2) { - if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) { - return false; - } - } - - if (obj1 instanceof RegExp && obj2 instanceof RegExp) { - if (obj1.toString() !== obj2.toString()) { return false; } - } - - var class1 = getClass(obj1); - var class2 = getClass(obj2); - var keys1 = keys(obj1); - var keys2 = keys(obj2); - - if (isArguments(obj1) || isArguments(obj2)) { - if (obj1.length !== obj2.length) { return false; } - } else { - if (type1 !== type2 || class1 !== class2 || - keys1.length !== keys2.length) { - return false; - } - } - - var key, i, l, - // following vars are used for the cyclic logic - value1, value2, - isObject1, isObject2, - index1, index2, - newPath1, newPath2; - - for (i = 0, l = keys1.length; i < l; i++) { - key = keys1[i]; - if (!o.hasOwnProperty.call(obj2, key)) { - return false; - } - - // Start of the cyclic logic - - value1 = obj1[key]; - value2 = obj2[key]; - - isObject1 = isObject(value1); - isObject2 = isObject(value2); - - // determine, if the objects were already visited - // (it's faster to check for isObject first, than to - // get -1 from getIndex for non objects) - index1 = isObject1 ? getIndex(objects1, value1) : -1; - index2 = isObject2 ? getIndex(objects2, value2) : -1; - - // determine the new pathes of the objects - // - for non cyclic objects the current path will be extended - // by current property name - // - for cyclic objects the stored path is taken - newPath1 = index1 !== -1 - ? paths1[index1] - : path1 + '[' + JSON.stringify(key) + ']'; - newPath2 = index2 !== -1 - ? paths2[index2] - : path2 + '[' + JSON.stringify(key) + ']'; - - // stop recursion if current objects are already compared - if (compared[newPath1 + newPath2]) { - return true; - } - - // remember the current objects and their pathes - if (index1 === -1 && isObject1) { - objects1.push(value1); - paths1.push(newPath1); - } - if (index2 === -1 && isObject2) { - objects2.push(value2); - paths2.push(newPath2); - } - - // remember that the current objects are already compared - if (isObject1 && isObject2) { - compared[newPath1 + newPath2] = true; - } - - // End of cyclic logic - - // neither value1 nor value2 is a cycle - // continue with next level - if (!deepEqual(value1, value2, newPath1, newPath2)) { - return false; - } - } - - return true; - - }(obj1, obj2, '$1', '$2')); - } - - var match; - - function arrayContains(array, subset) { - if (subset.length === 0) { return true; } - var i, l, j, k; - for (i = 0, l = array.length; i < l; ++i) { - if (match(array[i], subset[0])) { - for (j = 0, k = subset.length; j < k; ++j) { - if (!match(array[i + j], subset[j])) { return false; } - } - return true; - } - } - return false; - } - - /** - * @name samsam.match - * @param Object object - * @param Object matcher - * - * Compare arbitrary value ``object`` with matcher. - */ - match = function match(object, matcher) { - if (matcher && typeof matcher.test === "function") { - return matcher.test(object); - } - - if (typeof matcher === "function") { - return matcher(object) === true; - } - - if (typeof matcher === "string") { - matcher = matcher.toLowerCase(); - var notNull = typeof object === "string" || !!object; - return notNull && - (String(object)).toLowerCase().indexOf(matcher) >= 0; - } - - if (typeof matcher === "number") { - return matcher === object; - } - - if (typeof matcher === "boolean") { - return matcher === object; - } - - if (getClass(object) === "Array" && getClass(matcher) === "Array") { - return arrayContains(object, matcher); - } - - if (matcher && typeof matcher === "object") { - var prop; - for (prop in matcher) { - if (!match(object[prop], matcher[prop])) { - return false; - } - } - return true; - } - - throw new Error("Matcher was not a string, a number, a " + - "function, a boolean or an object"); - }; - - return { - isArguments: isArguments, - isElement: isElement, - isDate: isDate, - isNegZero: isNegZero, - identical: identical, - deepEqual: deepEqualCyclic, - match: match, - keys: keys - }; -}); -((typeof define === "function" && define.amd && function (m) { - define("formatio", ["samsam"], m); -}) || (typeof module === "object" && function (m) { - module.exports = m(require("samsam")); -}) || function (m) { this.formatio = m(this.samsam); } -)(function (samsam) { - - var formatio = { - excludeConstructors: ["Object", /^.$/], - quoteStrings: true - }; - - var hasOwn = Object.prototype.hasOwnProperty; - - var specialObjects = []; - if (typeof global !== "undefined") { - specialObjects.push({ object: global, value: "[object global]" }); - } - if (typeof document !== "undefined") { - specialObjects.push({ - object: document, - value: "[object HTMLDocument]" - }); - } - if (typeof window !== "undefined") { - specialObjects.push({ object: window, value: "[object Window]" }); - } - - function functionName(func) { - if (!func) { return ""; } - if (func.displayName) { return func.displayName; } - if (func.name) { return func.name; } - var matches = func.toString().match(/function\s+([^\(]+)/m); - return (matches && matches[1]) || ""; - } - - function constructorName(f, object) { - var name = functionName(object && object.constructor); - var excludes = f.excludeConstructors || - formatio.excludeConstructors || []; - - var i, l; - for (i = 0, l = excludes.length; i < l; ++i) { - if (typeof excludes[i] === "string" && excludes[i] === name) { - return ""; - } else if (excludes[i].test && excludes[i].test(name)) { - return ""; - } - } - - return name; - } - - function isCircular(object, objects) { - if (typeof object !== "object") { return false; } - var i, l; - for (i = 0, l = objects.length; i < l; ++i) { - if (objects[i] === object) { return true; } - } - return false; - } - - function ascii(f, object, processed, indent) { - if (typeof object === "string") { - var qs = f.quoteStrings; - var quote = typeof qs !== "boolean" || qs; - return processed || quote ? '"' + object + '"' : object; - } - - if (typeof object === "function" && !(object instanceof RegExp)) { - return ascii.func(object); - } - - processed = processed || []; - - if (isCircular(object, processed)) { return "[Circular]"; } - - if (Object.prototype.toString.call(object) === "[object Array]") { - return ascii.array.call(f, object, processed); - } - - if (!object) { return String((1/object) === -Infinity ? "-0" : object); } - if (samsam.isElement(object)) { return ascii.element(object); } - - if (typeof object.toString === "function" && - object.toString !== Object.prototype.toString) { - return object.toString(); - } - - var i, l; - for (i = 0, l = specialObjects.length; i < l; i++) { - if (object === specialObjects[i].object) { - return specialObjects[i].value; - } - } - - return ascii.object.call(f, object, processed, indent); - } - - ascii.func = function (func) { - return "function " + functionName(func) + "() {}"; - }; - - ascii.array = function (array, processed) { - processed = processed || []; - processed.push(array); - var i, l, pieces = []; - for (i = 0, l = array.length; i < l; ++i) { - pieces.push(ascii(this, array[i], processed)); - } - return "[" + pieces.join(", ") + "]"; - }; - - ascii.object = function (object, processed, indent) { - processed = processed || []; - processed.push(object); - indent = indent || 0; - var pieces = [], properties = samsam.keys(object).sort(); - var length = 3; - var prop, str, obj, i, l; - - for (i = 0, l = properties.length; i < l; ++i) { - prop = properties[i]; - obj = object[prop]; - - if (isCircular(obj, processed)) { - str = "[Circular]"; - } else { - str = ascii(this, obj, processed, indent + 2); - } - - str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str; - length += str.length; - pieces.push(str); - } - - var cons = constructorName(this, object); - var prefix = cons ? "[" + cons + "] " : ""; - var is = ""; - for (i = 0, l = indent; i < l; ++i) { is += " "; } - - if (length + indent > 80) { - return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + - is + "}"; - } - return prefix + "{ " + pieces.join(", ") + " }"; - }; - - ascii.element = function (element) { - var tagName = element.tagName.toLowerCase(); - var attrs = element.attributes, attr, pairs = [], attrName, i, l, val; - - for (i = 0, l = attrs.length; i < l; ++i) { - attr = attrs.item(i); - attrName = attr.nodeName.toLowerCase().replace("html:", ""); - val = attr.nodeValue; - if (attrName !== "contenteditable" || val !== "inherit") { - if (!!val) { pairs.push(attrName + "=\"" + val + "\""); } - } - } - - var formatted = "<" + tagName + (pairs.length > 0 ? " " : ""); - var content = element.innerHTML; - - if (content.length > 20) { - content = content.substr(0, 20) + "[...]"; - } - - var res = formatted + pairs.join(" ") + ">" + content + - ""; - - return res.replace(/ contentEditable="inherit"/, ""); - }; - - function Formatio(options) { - for (var opt in options) { - this[opt] = options[opt]; - } - } - - Formatio.prototype = { - functionName: functionName, - - configure: function (options) { - return new Formatio(options); - }, - - constructorName: function (object) { - return constructorName(this, object); - }, - - ascii: function (object, processed, indent) { - return ascii(this, object, processed, indent); - } - }; - - return Formatio.prototype; -}); -/*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ -/*global module, require, __dirname, document*/ -/** - * Sinon core utilities. For internal use only. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -var sinon = (function (formatio) { - var div = typeof document != "undefined" && document.createElement("div"); - var hasOwn = Object.prototype.hasOwnProperty; - - function isDOMNode(obj) { - var success = false; - - try { - obj.appendChild(div); - success = div.parentNode == obj; - } catch (e) { - return false; - } finally { - try { - obj.removeChild(div); - } catch (e) { - // Remove failed, not much we can do about that - } - } - - return success; - } - - function isElement(obj) { - return div && obj && obj.nodeType === 1 && isDOMNode(obj); - } - - function isFunction(obj) { - return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); - } - - function mirrorProperties(target, source) { - for (var prop in source) { - if (!hasOwn.call(target, prop)) { - target[prop] = source[prop]; - } - } - } - - function isRestorable (obj) { - return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon; - } - - var sinon = { - wrapMethod: function wrapMethod(object, property, method) { - if (!object) { - throw new TypeError("Should wrap property of object"); - } - - if (typeof method != "function") { - throw new TypeError("Method wrapper should be function"); - } - - var wrappedMethod = object[property], - error; - - if (!isFunction(wrappedMethod)) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); - } - - if (wrappedMethod.restore && wrappedMethod.restore.sinon) { - error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); - } - - if (wrappedMethod.calledBefore) { - var verb = !!wrappedMethod.returns ? "stubbed" : "spied on"; - error = new TypeError("Attempted to wrap " + property + " which is already " + verb); - } - - if (error) { - if (wrappedMethod._stack) { - error.stack += '\n--------------\n' + wrappedMethod._stack; - } - throw error; - } - - // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem - // when using hasOwn.call on objects from other frames. - var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); - object[property] = method; - method.displayName = property; - // Set up a stack trace which can be used later to find what line of - // code the original method was created on. - method._stack = (new Error('Stack Trace for original')).stack; - - method.restore = function () { - // For prototype properties try to reset by delete first. - // If this fails (ex: localStorage on mobile safari) then force a reset - // via direct assignment. - if (!owned) { - delete object[property]; - } - if (object[property] === method) { - object[property] = wrappedMethod; - } - }; - - method.restore.sinon = true; - mirrorProperties(method, wrappedMethod); - - return method; - }, - - extend: function extend(target) { - for (var i = 1, l = arguments.length; i < l; i += 1) { - for (var prop in arguments[i]) { - if (arguments[i].hasOwnProperty(prop)) { - target[prop] = arguments[i][prop]; - } - - // DONT ENUM bug, only care about toString - if (arguments[i].hasOwnProperty("toString") && - arguments[i].toString != target.toString) { - target.toString = arguments[i].toString; - } - } - } - - return target; - }, - - create: function create(proto) { - var F = function () {}; - F.prototype = proto; - return new F(); - }, - - deepEqual: function deepEqual(a, b) { - if (sinon.match && sinon.match.isMatcher(a)) { - return a.test(b); - } - if (typeof a != "object" || typeof b != "object") { - return a === b; - } - - if (isElement(a) || isElement(b)) { - return a === b; - } - - if (a === b) { - return true; - } - - if ((a === null && b !== null) || (a !== null && b === null)) { - return false; - } - - var aString = Object.prototype.toString.call(a); - if (aString != Object.prototype.toString.call(b)) { - return false; - } - - if (aString == "[object Date]") { - return a.valueOf() === b.valueOf(); - } - - var prop, aLength = 0, bLength = 0; - - if (aString == "[object Array]" && a.length !== b.length) { - return false; - } - - for (prop in a) { - aLength += 1; - - if (!deepEqual(a[prop], b[prop])) { - return false; - } - } - - for (prop in b) { - bLength += 1; - } - - return aLength == bLength; - }, - - functionName: function functionName(func) { - var name = func.displayName || func.name; - - // Use function decomposition as a last resort to get function - // name. Does not rely on function decomposition to work - if it - // doesn't debugging will be slightly less informative - // (i.e. toString will say 'spy' rather than 'myFunc'). - if (!name) { - var matches = func.toString().match(/function ([^\s\(]+)/); - name = matches && matches[1]; - } - - return name; - }, - - functionToString: function toString() { - if (this.getCall && this.callCount) { - var thisValue, prop, i = this.callCount; - - while (i--) { - thisValue = this.getCall(i).thisValue; - - for (prop in thisValue) { - if (thisValue[prop] === this) { - return prop; - } - } - } - } - - return this.displayName || "sinon fake"; - }, - - getConfig: function (custom) { - var config = {}; - custom = custom || {}; - var defaults = sinon.defaultConfig; - - for (var prop in defaults) { - if (defaults.hasOwnProperty(prop)) { - config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop]; - } - } - - return config; - }, - - format: function (val) { - return "" + val; - }, - - defaultConfig: { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }, - - timesInWords: function timesInWords(count) { - return count == 1 && "once" || - count == 2 && "twice" || - count == 3 && "thrice" || - (count || 0) + " times"; - }, - - calledInOrder: function (spies) { - for (var i = 1, l = spies.length; i < l; i++) { - if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) { - return false; - } - } - - return true; - }, - - orderByFirstCall: function (spies) { - return spies.sort(function (a, b) { - // uuid, won't ever be equal - var aCall = a.getCall(0); - var bCall = b.getCall(0); - var aId = aCall && aCall.callId || -1; - var bId = bCall && bCall.callId || -1; - - return aId < bId ? -1 : 1; - }); - }, - - log: function () {}, - - logError: function (label, err) { - var msg = label + " threw exception: "; - sinon.log(msg + "[" + err.name + "] " + err.message); - if (err.stack) { sinon.log(err.stack); } - - setTimeout(function () { - err.message = msg + err.message; - throw err; - }, 0); - }, - - typeOf: function (value) { - if (value === null) { - return "null"; - } - else if (value === undefined) { - return "undefined"; - } - var string = Object.prototype.toString.call(value); - return string.substring(8, string.length - 1).toLowerCase(); - }, - - createStubInstance: function (constructor) { - if (typeof constructor !== "function") { - throw new TypeError("The constructor should be a function."); - } - return sinon.stub(sinon.create(constructor.prototype)); - }, - - restore: function (object) { - if (object !== null && typeof object === "object") { - for (var prop in object) { - if (isRestorable(object[prop])) { - object[prop].restore(); - } - } - } - else if (isRestorable(object)) { - object.restore(); - } - } - }; - - var isNode = typeof module !== "undefined" && module.exports; - var isAMD = typeof define === 'function' && typeof define.amd === 'object' && define.amd; - - if (isAMD) { - define(function(){ - return sinon; - }); - } else if (isNode) { - try { - formatio = require("formatio"); - } catch (e) {} - module.exports = sinon; - module.exports.spy = require("./sinon/spy"); - module.exports.spyCall = require("./sinon/call"); - module.exports.behavior = require("./sinon/behavior"); - module.exports.stub = require("./sinon/stub"); - module.exports.mock = require("./sinon/mock"); - module.exports.collection = require("./sinon/collection"); - module.exports.assert = require("./sinon/assert"); - module.exports.sandbox = require("./sinon/sandbox"); - module.exports.test = require("./sinon/test"); - module.exports.testCase = require("./sinon/test_case"); - module.exports.assert = require("./sinon/assert"); - module.exports.match = require("./sinon/match"); - } - - if (formatio) { - var formatter = formatio.configure({ quoteStrings: false }); - sinon.format = function () { - return formatter.ascii.apply(formatter, arguments); - }; - } else if (isNode) { - try { - var util = require("util"); - sinon.format = function (value) { - return typeof value == "object" && value.toString === Object.prototype.toString ? util.inspect(value) : value; - }; - } catch (e) { - /* Node, but no util module - would be very old, but better safe than - sorry */ - } - } - - return sinon; -}(typeof formatio == "object" && formatio)); - -/* @depend ../sinon.js */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Match functions - * - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2012 Maximilian Antoni - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function assertType(value, type, name) { - var actual = sinon.typeOf(value); - if (actual !== type) { - throw new TypeError("Expected type of " + name + " to be " + - type + ", but was " + actual); - } - } - - var matcher = { - toString: function () { - return this.message; - } - }; - - function isMatcher(object) { - return matcher.isPrototypeOf(object); - } - - function matchObject(expectation, actual) { - if (actual === null || actual === undefined) { - return false; - } - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - var exp = expectation[key]; - var act = actual[key]; - if (match.isMatcher(exp)) { - if (!exp.test(act)) { - return false; - } - } else if (sinon.typeOf(exp) === "object") { - if (!matchObject(exp, act)) { - return false; - } - } else if (!sinon.deepEqual(exp, act)) { - return false; - } - } - } - return true; - } - - matcher.or = function (m2) { - if (!isMatcher(m2)) { - throw new TypeError("Matcher expected"); - } - var m1 = this; - var or = sinon.create(matcher); - or.test = function (actual) { - return m1.test(actual) || m2.test(actual); - }; - or.message = m1.message + ".or(" + m2.message + ")"; - return or; - }; - - matcher.and = function (m2) { - if (!isMatcher(m2)) { - throw new TypeError("Matcher expected"); - } - var m1 = this; - var and = sinon.create(matcher); - and.test = function (actual) { - return m1.test(actual) && m2.test(actual); - }; - and.message = m1.message + ".and(" + m2.message + ")"; - return and; - }; - - var match = function (expectation, message) { - var m = sinon.create(matcher); - var type = sinon.typeOf(expectation); - switch (type) { - case "object": - if (typeof expectation.test === "function") { - m.test = function (actual) { - return expectation.test(actual) === true; - }; - m.message = "match(" + sinon.functionName(expectation.test) + ")"; - return m; - } - var str = []; - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - str.push(key + ": " + expectation[key]); - } - } - m.test = function (actual) { - return matchObject(expectation, actual); - }; - m.message = "match(" + str.join(", ") + ")"; - break; - case "number": - m.test = function (actual) { - return expectation == actual; - }; - break; - case "string": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; - } - return actual.indexOf(expectation) !== -1; - }; - m.message = "match(\"" + expectation + "\")"; - break; - case "regexp": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; - } - return expectation.test(actual); - }; - break; - case "function": - m.test = expectation; - if (message) { - m.message = message; - } else { - m.message = "match(" + sinon.functionName(expectation) + ")"; - } - break; - default: - m.test = function (actual) { - return sinon.deepEqual(expectation, actual); - }; - } - if (!m.message) { - m.message = "match(" + expectation + ")"; - } - return m; - }; - - match.isMatcher = isMatcher; - - match.any = match(function () { - return true; - }, "any"); - - match.defined = match(function (actual) { - return actual !== null && actual !== undefined; - }, "defined"); - - match.truthy = match(function (actual) { - return !!actual; - }, "truthy"); - - match.falsy = match(function (actual) { - return !actual; - }, "falsy"); - - match.same = function (expectation) { - return match(function (actual) { - return expectation === actual; - }, "same(" + expectation + ")"); - }; - - match.typeOf = function (type) { - assertType(type, "string", "type"); - return match(function (actual) { - return sinon.typeOf(actual) === type; - }, "typeOf(\"" + type + "\")"); - }; - - match.instanceOf = function (type) { - assertType(type, "function", "type"); - return match(function (actual) { - return actual instanceof type; - }, "instanceOf(" + sinon.functionName(type) + ")"); - }; - - function createPropertyMatcher(propertyTest, messagePrefix) { - return function (property, value) { - assertType(property, "string", "property"); - var onlyProperty = arguments.length === 1; - var message = messagePrefix + "(\"" + property + "\""; - if (!onlyProperty) { - message += ", " + value; - } - message += ")"; - return match(function (actual) { - if (actual === undefined || actual === null || - !propertyTest(actual, property)) { - return false; - } - return onlyProperty || sinon.deepEqual(value, actual[property]); - }, message); - }; - } - - match.has = createPropertyMatcher(function (actual, property) { - if (typeof actual === "object") { - return property in actual; - } - return actual[property] !== undefined; - }, "has"); - - match.hasOwn = createPropertyMatcher(function (actual, property) { - return actual.hasOwnProperty(property); - }, "hasOwn"); - - match.bool = match.typeOf("boolean"); - match.number = match.typeOf("number"); - match.string = match.typeOf("string"); - match.object = match.typeOf("object"); - match.func = match.typeOf("function"); - match.array = match.typeOf("array"); - match.regexp = match.typeOf("regexp"); - match.date = match.typeOf("date"); - - if (commonJSModule) { - module.exports = match; - } else { - sinon.match = match; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend match.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Spy calls - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - * Copyright (c) 2013 Maximilian Antoni - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function throwYieldError(proxy, text, args) { - var msg = sinon.functionName(proxy) + text; - if (args.length) { - msg += " Received [" + slice.call(args).join(", ") + "]"; - } - throw new Error(msg); - } - - var slice = Array.prototype.slice; - - var callProto = { - calledOn: function calledOn(thisValue) { - if (sinon.match && sinon.match.isMatcher(thisValue)) { - return thisValue.test(this.thisValue); - } - return this.thisValue === thisValue; - }, - - calledWith: function calledWith() { - for (var i = 0, l = arguments.length; i < l; i += 1) { - if (!sinon.deepEqual(arguments[i], this.args[i])) { - return false; - } - } - - return true; - }, - - calledWithMatch: function calledWithMatch() { - for (var i = 0, l = arguments.length; i < l; i += 1) { - var actual = this.args[i]; - var expectation = arguments[i]; - if (!sinon.match || !sinon.match(expectation).test(actual)) { - return false; - } - } - return true; - }, - - calledWithExactly: function calledWithExactly() { - return arguments.length == this.args.length && - this.calledWith.apply(this, arguments); - }, - - notCalledWith: function notCalledWith() { - return !this.calledWith.apply(this, arguments); - }, - - notCalledWithMatch: function notCalledWithMatch() { - return !this.calledWithMatch.apply(this, arguments); - }, - - returned: function returned(value) { - return sinon.deepEqual(value, this.returnValue); - }, - - threw: function threw(error) { - if (typeof error === "undefined" || !this.exception) { - return !!this.exception; - } - - return this.exception === error || this.exception.name === error; - }, - - calledWithNew: function calledWithNew() { - return this.proxy.prototype && this.thisValue instanceof this.proxy; - }, - - calledBefore: function (other) { - return this.callId < other.callId; - }, - - calledAfter: function (other) { - return this.callId > other.callId; - }, - - callArg: function (pos) { - this.args[pos](); - }, - - callArgOn: function (pos, thisValue) { - this.args[pos].apply(thisValue); - }, - - callArgWith: function (pos) { - this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1))); - }, - - callArgOnWith: function (pos, thisValue) { - var args = slice.call(arguments, 2); - this.args[pos].apply(thisValue, args); - }, - - "yield": function () { - this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0))); - }, - - yieldOn: function (thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (typeof args[i] === "function") { - args[i].apply(thisValue, slice.call(arguments, 1)); - return; - } - } - throwYieldError(this.proxy, " cannot yield since no callback was passed.", args); - }, - - yieldTo: function (prop) { - this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1))); - }, - - yieldToOn: function (prop, thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (args[i] && typeof args[i][prop] === "function") { - args[i][prop].apply(thisValue, slice.call(arguments, 2)); - return; - } - } - throwYieldError(this.proxy, " cannot yield to '" + prop + - "' since no callback was passed.", args); - }, - - toString: function () { - var callStr = this.proxy.toString() + "("; - var args = []; - - for (var i = 0, l = this.args.length; i < l; ++i) { - args.push(sinon.format(this.args[i])); - } - - callStr = callStr + args.join(", ") + ")"; - - if (typeof this.returnValue != "undefined") { - callStr += " => " + sinon.format(this.returnValue); - } - - if (this.exception) { - callStr += " !" + this.exception.name; - - if (this.exception.message) { - callStr += "(" + this.exception.message + ")"; - } - } - - return callStr; - } - }; - - callProto.invokeCallback = callProto.yield; - - function createSpyCall(spy, thisValue, args, returnValue, exception, id) { - if (typeof id !== "number") { - throw new TypeError("Call id is not a number"); - } - var proxyCall = sinon.create(callProto); - proxyCall.proxy = spy; - proxyCall.thisValue = thisValue; - proxyCall.args = args; - proxyCall.returnValue = returnValue; - proxyCall.exception = exception; - proxyCall.callId = id; - - return proxyCall; - } - createSpyCall.toString = callProto.toString; // used by mocks - - if (commonJSModule) { - module.exports = createSpyCall; - } else { - sinon.spyCall = createSpyCall; - } -}(typeof sinon == "object" && sinon || null)); - - -/** - * @depend ../sinon.js - * @depend call.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Spy functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = Array.prototype.push; - var slice = Array.prototype.slice; - var callId = 0; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function spy(object, property) { - if (!property && typeof object == "function") { - return spy.create(object); - } - - if (!object && !property) { - return spy.create(function () { }); - } - - var method = object[property]; - return sinon.wrapMethod(object, property, spy.create(method)); - } - - function matchingFake(fakes, args, strict) { - if (!fakes) { - return; - } - - for (var i = 0, l = fakes.length; i < l; i++) { - if (fakes[i].matches(args, strict)) { - return fakes[i]; - } - } - } - - function incrementCallCount() { - this.called = true; - this.callCount += 1; - this.notCalled = false; - this.calledOnce = this.callCount == 1; - this.calledTwice = this.callCount == 2; - this.calledThrice = this.callCount == 3; - } - - function createCallProperties() { - this.firstCall = this.getCall(0); - this.secondCall = this.getCall(1); - this.thirdCall = this.getCall(2); - this.lastCall = this.getCall(this.callCount - 1); - } - - var vars = "a,b,c,d,e,f,g,h,i,j,k,l"; - function createProxy(func) { - // Retain the function length: - var p; - if (func.length) { - eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) + - ") { return p.invoke(func, this, slice.call(arguments)); });"); - } - else { - p = function proxy() { - return p.invoke(func, this, slice.call(arguments)); - }; - } - return p; - } - - var uuid = 0; - - // Public API - var spyApi = { - reset: function () { - this.called = false; - this.notCalled = true; - this.calledOnce = false; - this.calledTwice = false; - this.calledThrice = false; - this.callCount = 0; - this.firstCall = null; - this.secondCall = null; - this.thirdCall = null; - this.lastCall = null; - this.args = []; - this.returnValues = []; - this.thisValues = []; - this.exceptions = []; - this.callIds = []; - if (this.fakes) { - for (var i = 0; i < this.fakes.length; i++) { - this.fakes[i].reset(); - } - } - }, - - create: function create(func) { - var name; - - if (typeof func != "function") { - func = function () { }; - } else { - name = sinon.functionName(func); - } - - var proxy = createProxy(func); - - sinon.extend(proxy, spy); - delete proxy.create; - sinon.extend(proxy, func); - - proxy.reset(); - proxy.prototype = func.prototype; - proxy.displayName = name || "spy"; - proxy.toString = sinon.functionToString; - proxy._create = sinon.spy.create; - proxy.id = "spy#" + uuid++; - - return proxy; - }, - - invoke: function invoke(func, thisValue, args) { - var matching = matchingFake(this.fakes, args); - var exception, returnValue; - - incrementCallCount.call(this); - push.call(this.thisValues, thisValue); - push.call(this.args, args); - push.call(this.callIds, callId++); - - try { - if (matching) { - returnValue = matching.invoke(func, thisValue, args); - } else { - returnValue = (this.func || func).apply(thisValue, args); - } - - var thisCall = this.getCall(this.callCount - 1); - if (thisCall.calledWithNew() && typeof returnValue !== 'object') { - returnValue = thisValue; - } - } catch (e) { - exception = e; - } - - push.call(this.exceptions, exception); - push.call(this.returnValues, returnValue); - - createCallProperties.call(this); - - if (exception !== undefined) { - throw exception; - } - - return returnValue; - }, - - getCall: function getCall(i) { - if (i < 0 || i >= this.callCount) { - return null; - } - - return sinon.spyCall(this, this.thisValues[i], this.args[i], - this.returnValues[i], this.exceptions[i], - this.callIds[i]); - }, - - getCalls: function () { - var calls = []; - var i; - - for (i = 0; i < this.callCount; i++) { - calls.push(this.getCall(i)); - } - - return calls; - }, - - calledBefore: function calledBefore(spyFn) { - if (!this.called) { - return false; - } - - if (!spyFn.called) { - return true; - } - - return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1]; - }, - - calledAfter: function calledAfter(spyFn) { - if (!this.called || !spyFn.called) { - return false; - } - - return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1]; - }, - - withArgs: function () { - var args = slice.call(arguments); - - if (this.fakes) { - var match = matchingFake(this.fakes, args, true); - - if (match) { - return match; - } - } else { - this.fakes = []; - } - - var original = this; - var fake = this._create(); - fake.matchingAguments = args; - fake.parent = this; - push.call(this.fakes, fake); - - fake.withArgs = function () { - return original.withArgs.apply(original, arguments); - }; - - for (var i = 0; i < this.args.length; i++) { - if (fake.matches(this.args[i])) { - incrementCallCount.call(fake); - push.call(fake.thisValues, this.thisValues[i]); - push.call(fake.args, this.args[i]); - push.call(fake.returnValues, this.returnValues[i]); - push.call(fake.exceptions, this.exceptions[i]); - push.call(fake.callIds, this.callIds[i]); - } - } - createCallProperties.call(fake); - - return fake; - }, - - matches: function (args, strict) { - var margs = this.matchingAguments; - - if (margs.length <= args.length && - sinon.deepEqual(margs, args.slice(0, margs.length))) { - return !strict || margs.length == args.length; - } - }, - - printf: function (format) { - var spy = this; - var args = slice.call(arguments, 1); - var formatter; - - return (format || "").replace(/%(.)/g, function (match, specifyer) { - formatter = spyApi.formatters[specifyer]; - - if (typeof formatter == "function") { - return formatter.call(null, spy, args); - } else if (!isNaN(parseInt(specifyer, 10))) { - return sinon.format(args[specifyer - 1]); - } - - return "%" + specifyer; - }); - } - }; - - function delegateToCalls(method, matchAny, actual, notCalled) { - spyApi[method] = function () { - if (!this.called) { - if (notCalled) { - return notCalled.apply(this, arguments); - } - return false; - } - - var currentCall; - var matches = 0; - - for (var i = 0, l = this.callCount; i < l; i += 1) { - currentCall = this.getCall(i); - - if (currentCall[actual || method].apply(currentCall, arguments)) { - matches += 1; - - if (matchAny) { - return true; - } - } - } - - return matches === this.callCount; - }; - } - - delegateToCalls("calledOn", true); - delegateToCalls("alwaysCalledOn", false, "calledOn"); - delegateToCalls("calledWith", true); - delegateToCalls("calledWithMatch", true); - delegateToCalls("alwaysCalledWith", false, "calledWith"); - delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); - delegateToCalls("calledWithExactly", true); - delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); - delegateToCalls("neverCalledWith", false, "notCalledWith", - function () { return true; }); - delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", - function () { return true; }); - delegateToCalls("threw", true); - delegateToCalls("alwaysThrew", false, "threw"); - delegateToCalls("returned", true); - delegateToCalls("alwaysReturned", false, "returned"); - delegateToCalls("calledWithNew", true); - delegateToCalls("alwaysCalledWithNew", false, "calledWithNew"); - delegateToCalls("callArg", false, "callArgWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgWith = spyApi.callArg; - delegateToCalls("callArgOn", false, "callArgOnWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgOnWith = spyApi.callArgOn; - delegateToCalls("yield", false, "yield", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode. - spyApi.invokeCallback = spyApi.yield; - delegateToCalls("yieldOn", false, "yieldOn", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - delegateToCalls("yieldTo", false, "yieldTo", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); - delegateToCalls("yieldToOn", false, "yieldToOn", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); - - spyApi.formatters = { - "c": function (spy) { - return sinon.timesInWords(spy.callCount); - }, - - "n": function (spy) { - return spy.toString(); - }, - - "C": function (spy) { - var calls = []; - - for (var i = 0, l = spy.callCount; i < l; ++i) { - var stringifiedCall = " " + spy.getCall(i).toString(); - if (/\n/.test(calls[i - 1])) { - stringifiedCall = "\n" + stringifiedCall; - } - push.call(calls, stringifiedCall); - } - - return calls.length > 0 ? "\n" + calls.join("\n") : ""; - }, - - "t": function (spy) { - var objects = []; - - for (var i = 0, l = spy.callCount; i < l; ++i) { - push.call(objects, sinon.format(spy.thisValues[i])); - } - - return objects.join(", "); - }, - - "*": function (spy, args) { - var formatted = []; - - for (var i = 0, l = args.length; i < l; ++i) { - push.call(formatted, sinon.format(args[i])); - } - - return formatted.join(", "); - } - }; - - sinon.extend(spy, spyApi); - - spy.spyCall = sinon.spyCall; - - if (commonJSModule) { - module.exports = spy; - } else { - sinon.spy = spy; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global module, require, sinon, process, setImmediate, setTimeout*/ -/** - * Stub behavior - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Tim Fischbach (mail@timfischbach.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - var slice = Array.prototype.slice; - var join = Array.prototype.join; - var proto; - - var nextTick = (function () { - if (typeof process === "object" && typeof process.nextTick === "function") { - return process.nextTick; - } else if (typeof setImmediate === "function") { - return setImmediate; - } else { - return function (callback) { - setTimeout(callback, 0); - }; - } - })(); - - function throwsException(error, message) { - if (typeof error == "string") { - this.exception = new Error(message || ""); - this.exception.name = error; - } else if (!error) { - this.exception = new Error("Error"); - } else { - this.exception = error; - } - - return this; - } - - function getCallback(behavior, args) { - var callArgAt = behavior.callArgAt; - - if (callArgAt < 0) { - var callArgProp = behavior.callArgProp; - - for (var i = 0, l = args.length; i < l; ++i) { - if (!callArgProp && typeof args[i] == "function") { - return args[i]; - } - - if (callArgProp && args[i] && - typeof args[i][callArgProp] == "function") { - return args[i][callArgProp]; - } - } - - return null; - } - - return args[callArgAt]; - } - - function getCallbackError(behavior, func, args) { - if (behavior.callArgAt < 0) { - var msg; - - if (behavior.callArgProp) { - msg = sinon.functionName(behavior.stub) + - " expected to yield to '" + behavior.callArgProp + - "', but no object with such a property was passed."; - } else { - msg = sinon.functionName(behavior.stub) + - " expected to yield, but no callback was passed."; - } - - if (args.length > 0) { - msg += " Received [" + join.call(args, ", ") + "]"; - } - - return msg; - } - - return "argument at index " + behavior.callArgAt + " is not a function: " + func; - } - - function callCallback(behavior, args) { - if (typeof behavior.callArgAt == "number") { - var func = getCallback(behavior, args); - - if (typeof func != "function") { - throw new TypeError(getCallbackError(behavior, func, args)); - } - - if (behavior.callbackAsync) { - nextTick(function() { - func.apply(behavior.callbackContext, behavior.callbackArguments); - }); - } else { - func.apply(behavior.callbackContext, behavior.callbackArguments); - } - } - } - - proto = { - create: function(stub) { - var behavior = sinon.extend({}, sinon.behavior); - delete behavior.create; - behavior.stub = stub; - - return behavior; - }, - - isPresent: function() { - return (typeof this.callArgAt == 'number' || - this.exception || - typeof this.returnArgAt == 'number' || - this.returnThis || - this.returnValueDefined); - }, - - invoke: function(context, args) { - callCallback(this, args); - - if (this.exception) { - throw this.exception; - } else if (typeof this.returnArgAt == 'number') { - return args[this.returnArgAt]; - } else if (this.returnThis) { - return context; - } - - return this.returnValue; - }, - - onCall: function(index) { - return this.stub.onCall(index); - }, - - onFirstCall: function() { - return this.stub.onFirstCall(); - }, - - onSecondCall: function() { - return this.stub.onSecondCall(); - }, - - onThirdCall: function() { - return this.stub.onThirdCall(); - }, - - withArgs: function(/* arguments */) { - throw new Error('Defining a stub by invoking "stub.onCall(...).withArgs(...)" is not supported. ' + - 'Use "stub.withArgs(...).onCall(...)" to define sequential behavior for calls with certain arguments.'); - }, - - callsArg: function callsArg(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgOn: function callsArgOn(pos, context) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgWith: function callsArgWith(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgOnWith: function callsArgWith(pos, context) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yields: function () { - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 0); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yieldsOn: function (context) { - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yieldsTo: function (prop) { - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = prop; - this.callbackAsync = false; - - return this; - }, - - yieldsToOn: function (prop, context) { - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = prop; - this.callbackAsync = false; - - return this; - }, - - - "throws": throwsException, - throwsException: throwsException, - - returns: function returns(value) { - this.returnValue = value; - this.returnValueDefined = true; - - return this; - }, - - returnsArg: function returnsArg(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.returnArgAt = pos; - - return this; - }, - - returnsThis: function returnsThis() { - this.returnThis = true; - - return this; - } - }; - - // create asynchronous versions of callsArg* and yields* methods - for (var method in proto) { - // need to avoid creating anotherasync versions of the newly added async methods - if (proto.hasOwnProperty(method) && - method.match(/^(callsArg|yields)/) && - !method.match(/Async/)) { - proto[method + 'Async'] = (function (syncFnName) { - return function () { - var result = this[syncFnName].apply(this, arguments); - this.callbackAsync = true; - return result; - }; - })(method); - } - } - - if (commonJSModule) { - module.exports = proto; - } else { - sinon.behavior = proto; - } -}(typeof sinon == "object" && sinon || null)); -/** - * @depend ../sinon.js - * @depend spy.js - * @depend behavior.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global module, require, sinon*/ -/** - * Stub functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function stub(object, property, func) { - if (!!func && typeof func != "function") { - throw new TypeError("Custom stub should be function"); - } - - var wrapper; - - if (func) { - wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func; - } else { - wrapper = stub.create(); - } - - if (!object && typeof property === "undefined") { - return sinon.stub.create(); - } - - if (typeof property === "undefined" && typeof object == "object") { - for (var prop in object) { - if (typeof object[prop] === "function") { - stub(object, prop); - } - } - - return object; - } - - return sinon.wrapMethod(object, property, wrapper); - } - - function getDefaultBehavior(stub) { - return stub.defaultBehavior || getParentBehaviour(stub) || sinon.behavior.create(stub); - } - - function getParentBehaviour(stub) { - return (stub.parent && getCurrentBehavior(stub.parent)); - } - - function getCurrentBehavior(stub) { - var behavior = stub.behaviors[stub.callCount - 1]; - return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stub); - } - - var uuid = 0; - - sinon.extend(stub, (function () { - var proto = { - create: function create() { - var functionStub = function () { - return getCurrentBehavior(functionStub).invoke(this, arguments); - }; - - functionStub.id = "stub#" + uuid++; - var orig = functionStub; - functionStub = sinon.spy.create(functionStub); - functionStub.func = orig; - - sinon.extend(functionStub, stub); - functionStub._create = sinon.stub.create; - functionStub.displayName = "stub"; - functionStub.toString = sinon.functionToString; - - functionStub.defaultBehavior = null; - functionStub.behaviors = []; - - return functionStub; - }, - - resetBehavior: function () { - var i; - - this.defaultBehavior = null; - this.behaviors = []; - - delete this.returnValue; - delete this.returnArgAt; - this.returnThis = false; - - if (this.fakes) { - for (i = 0; i < this.fakes.length; i++) { - this.fakes[i].resetBehavior(); - } - } - }, - - onCall: function(index) { - if (!this.behaviors[index]) { - this.behaviors[index] = sinon.behavior.create(this); - } - - return this.behaviors[index]; - }, - - onFirstCall: function() { - return this.onCall(0); - }, - - onSecondCall: function() { - return this.onCall(1); - }, - - onThirdCall: function() { - return this.onCall(2); - } - }; - - for (var method in sinon.behavior) { - if (sinon.behavior.hasOwnProperty(method) && - !proto.hasOwnProperty(method) && - method != 'create' && - method != 'withArgs' && - method != 'invoke') { - proto[method] = (function(behaviorMethod) { - return function() { - this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this); - this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); - return this; - }; - }(method)); - } - } - - return proto; - }())); - - if (commonJSModule) { - module.exports = stub; - } else { - sinon.stub = stub; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - */ -/*jslint eqeqeq: false, onevar: false, nomen: false*/ -/*global module, require, sinon*/ -/** - * Mock functions. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = [].push; - var match; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - match = sinon.match; - - if (!match && commonJSModule) { - match = require("./match"); - } - - function mock(object) { - if (!object) { - return sinon.expectation.create("Anonymous mock"); - } - - return mock.create(object); - } - - sinon.mock = mock; - - sinon.extend(mock, (function () { - function each(collection, callback) { - if (!collection) { - return; - } - - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } - } - - return { - create: function create(object) { - if (!object) { - throw new TypeError("object is null"); - } - - var mockObject = sinon.extend({}, mock); - mockObject.object = object; - delete mockObject.create; - - return mockObject; - }, - - expects: function expects(method) { - if (!method) { - throw new TypeError("method is falsy"); - } - - if (!this.expectations) { - this.expectations = {}; - this.proxies = []; - } - - if (!this.expectations[method]) { - this.expectations[method] = []; - var mockObject = this; - - sinon.wrapMethod(this.object, method, function () { - return mockObject.invokeMethod(method, this, arguments); - }); - - push.call(this.proxies, method); - } - - var expectation = sinon.expectation.create(method); - push.call(this.expectations[method], expectation); - - return expectation; - }, - - restore: function restore() { - var object = this.object; - - each(this.proxies, function (proxy) { - if (typeof object[proxy].restore == "function") { - object[proxy].restore(); - } - }); - }, - - verify: function verify() { - var expectations = this.expectations || {}; - var messages = [], met = []; - - each(this.proxies, function (proxy) { - each(expectations[proxy], function (expectation) { - if (!expectation.met()) { - push.call(messages, expectation.toString()); - } else { - push.call(met, expectation.toString()); - } - }); - }); - - this.restore(); - - if (messages.length > 0) { - sinon.expectation.fail(messages.concat(met).join("\n")); - } else { - sinon.expectation.pass(messages.concat(met).join("\n")); - } - - return true; - }, - - invokeMethod: function invokeMethod(method, thisValue, args) { - var expectations = this.expectations && this.expectations[method]; - var length = expectations && expectations.length || 0, i; - - for (i = 0; i < length; i += 1) { - if (!expectations[i].met() && - expectations[i].allowsCall(thisValue, args)) { - return expectations[i].apply(thisValue, args); - } - } - - var messages = [], available, exhausted = 0; - - for (i = 0; i < length; i += 1) { - if (expectations[i].allowsCall(thisValue, args)) { - available = available || expectations[i]; - } else { - exhausted += 1; - } - push.call(messages, " " + expectations[i].toString()); - } - - if (exhausted === 0) { - return available.apply(thisValue, args); - } - - messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({ - proxy: method, - args: args - })); - - sinon.expectation.fail(messages.join("\n")); - } - }; - }())); - - var times = sinon.timesInWords; - - sinon.expectation = (function () { - var slice = Array.prototype.slice; - var _invoke = sinon.spy.invoke; - - function callCountInWords(callCount) { - if (callCount == 0) { - return "never called"; - } else { - return "called " + times(callCount); - } - } - - function expectedCallCountInWords(expectation) { - var min = expectation.minCalls; - var max = expectation.maxCalls; - - if (typeof min == "number" && typeof max == "number") { - var str = times(min); - - if (min != max) { - str = "at least " + str + " and at most " + times(max); - } - - return str; - } - - if (typeof min == "number") { - return "at least " + times(min); - } - - return "at most " + times(max); - } - - function receivedMinCalls(expectation) { - var hasMinLimit = typeof expectation.minCalls == "number"; - return !hasMinLimit || expectation.callCount >= expectation.minCalls; - } - - function receivedMaxCalls(expectation) { - if (typeof expectation.maxCalls != "number") { - return false; - } - - return expectation.callCount == expectation.maxCalls; - } - - function verifyMatcher(possibleMatcher, arg){ - if (match && match.isMatcher(possibleMatcher)) { - return possibleMatcher.test(arg); - } else { - return true; - } - } - - return { - minCalls: 1, - maxCalls: 1, - - create: function create(methodName) { - var expectation = sinon.extend(sinon.stub.create(), sinon.expectation); - delete expectation.create; - expectation.method = methodName; - - return expectation; - }, - - invoke: function invoke(func, thisValue, args) { - this.verifyCallAllowed(thisValue, args); - - return _invoke.apply(this, arguments); - }, - - atLeast: function atLeast(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not number"); - } - - if (!this.limitsSet) { - this.maxCalls = null; - this.limitsSet = true; - } - - this.minCalls = num; - - return this; - }, - - atMost: function atMost(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not number"); - } - - if (!this.limitsSet) { - this.minCalls = null; - this.limitsSet = true; - } - - this.maxCalls = num; - - return this; - }, - - never: function never() { - return this.exactly(0); - }, - - once: function once() { - return this.exactly(1); - }, - - twice: function twice() { - return this.exactly(2); - }, - - thrice: function thrice() { - return this.exactly(3); - }, - - exactly: function exactly(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not a number"); - } - - this.atLeast(num); - return this.atMost(num); - }, - - met: function met() { - return !this.failed && receivedMinCalls(this); - }, - - verifyCallAllowed: function verifyCallAllowed(thisValue, args) { - if (receivedMaxCalls(this)) { - this.failed = true; - sinon.expectation.fail(this.method + " already called " + times(this.maxCalls)); - } - - if ("expectedThis" in this && this.expectedThis !== thisValue) { - sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + - this.expectedThis); - } - - if (!("expectedArguments" in this)) { - return; - } - - if (!args) { - sinon.expectation.fail(this.method + " received no arguments, expected " + - sinon.format(this.expectedArguments)); - } - - if (args.length < this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } - - if (this.expectsExactArgCount && - args.length != this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } - - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - - if (!verifyMatcher(this.expectedArguments[i],args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", didn't match " + this.expectedArguments.toString()); - } - - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", expected " + sinon.format(this.expectedArguments)); - } - } - }, - - allowsCall: function allowsCall(thisValue, args) { - if (this.met() && receivedMaxCalls(this)) { - return false; - } - - if ("expectedThis" in this && this.expectedThis !== thisValue) { - return false; - } - - if (!("expectedArguments" in this)) { - return true; - } - - args = args || []; - - if (args.length < this.expectedArguments.length) { - return false; - } - - if (this.expectsExactArgCount && - args.length != this.expectedArguments.length) { - return false; - } - - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - if (!verifyMatcher(this.expectedArguments[i],args[i])) { - return false; - } - - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { - return false; - } - } - - return true; - }, - - withArgs: function withArgs() { - this.expectedArguments = slice.call(arguments); - return this; - }, - - withExactArgs: function withExactArgs() { - this.withArgs.apply(this, arguments); - this.expectsExactArgCount = true; - return this; - }, - - on: function on(thisValue) { - this.expectedThis = thisValue; - return this; - }, - - toString: function () { - var args = (this.expectedArguments || []).slice(); - - if (!this.expectsExactArgCount) { - push.call(args, "[...]"); - } - - var callStr = sinon.spyCall.toString.call({ - proxy: this.method || "anonymous mock expectation", - args: args - }); - - var message = callStr.replace(", [...", "[, ...") + " " + - expectedCallCountInWords(this); - - if (this.met()) { - return "Expectation met: " + message; - } - - return "Expected " + message + " (" + - callCountInWords(this.callCount) + ")"; - }, - - verify: function verify() { - if (!this.met()) { - sinon.expectation.fail(this.toString()); - } else { - sinon.expectation.pass(this.toString()); - } - - return true; - }, - - pass: function(message) { - sinon.assert.pass(message); - }, - fail: function (message) { - var exception = new Error(message); - exception.name = "ExpectationError"; - - throw exception; - } - }; - }()); - - if (commonJSModule) { - module.exports = mock; - } else { - sinon.mock = mock; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - * @depend mock.js - */ -/*jslint eqeqeq: false, onevar: false, forin: true*/ -/*global module, require, sinon*/ -/** - * Collections of stubs, spies and mocks. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = [].push; - var hasOwnProperty = Object.prototype.hasOwnProperty; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function getFakes(fakeCollection) { - if (!fakeCollection.fakes) { - fakeCollection.fakes = []; - } - - return fakeCollection.fakes; - } - - function each(fakeCollection, method) { - var fakes = getFakes(fakeCollection); - - for (var i = 0, l = fakes.length; i < l; i += 1) { - if (typeof fakes[i][method] == "function") { - fakes[i][method](); - } - } - } - - function compact(fakeCollection) { - var fakes = getFakes(fakeCollection); - var i = 0; - while (i < fakes.length) { - fakes.splice(i, 1); - } - } - - var collection = { - verify: function resolve() { - each(this, "verify"); - }, - - restore: function restore() { - each(this, "restore"); - compact(this); - }, - - verifyAndRestore: function verifyAndRestore() { - var exception; - - try { - this.verify(); - } catch (e) { - exception = e; - } - - this.restore(); - - if (exception) { - throw exception; - } - }, - - add: function add(fake) { - push.call(getFakes(this), fake); - return fake; - }, - - spy: function spy() { - return this.add(sinon.spy.apply(sinon, arguments)); - }, - - stub: function stub(object, property, value) { - if (property) { - var original = object[property]; - - if (typeof original != "function") { - if (!hasOwnProperty.call(object, property)) { - throw new TypeError("Cannot stub non-existent own property " + property); - } - - object[property] = value; - - return this.add({ - restore: function () { - object[property] = original; - } - }); - } - } - if (!property && !!object && typeof object == "object") { - var stubbedObj = sinon.stub.apply(sinon, arguments); - - for (var prop in stubbedObj) { - if (typeof stubbedObj[prop] === "function") { - this.add(stubbedObj[prop]); - } - } - - return stubbedObj; - } - - return this.add(sinon.stub.apply(sinon, arguments)); - }, - - mock: function mock() { - return this.add(sinon.mock.apply(sinon, arguments)); - }, - - inject: function inject(obj) { - var col = this; - - obj.spy = function () { - return col.spy.apply(col, arguments); - }; - - obj.stub = function () { - return col.stub.apply(col, arguments); - }; - - obj.mock = function () { - return col.mock.apply(col, arguments); - }; - - return obj; - } - }; - - if (commonJSModule) { - module.exports = collection; - } else { - sinon.collection = collection; - } -}(typeof sinon == "object" && sinon || null)); - -/*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ -/*global module, require, window*/ -/** - * Fake timer API - * setTimeout - * setInterval - * clearTimeout - * clearInterval - * tick - * reset - * Date - * - * Inspired by jsUnitMockTimeOut from JsUnit - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -(function (global) { - var id = 1; - - function addTimer(args, recurring) { - if (args.length === 0) { - throw new Error("Function requires at least 1 parameter"); - } - - if (typeof args[0] === "undefined") { - throw new Error("Callback must be provided to timer calls"); - } - - var toId = id++; - var delay = args[1] || 0; - - if (!this.timeouts) { - this.timeouts = {}; - } - - this.timeouts[toId] = { - id: toId, - func: args[0], - callAt: this.now + delay, - invokeArgs: Array.prototype.slice.call(args, 2) - }; - - if (recurring === true) { - this.timeouts[toId].interval = delay; - } - - return toId; - } - - function parseTime(str) { - if (!str) { - return 0; - } - - var strings = str.split(":"); - var l = strings.length, i = l; - var ms = 0, parsed; - - if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { - throw new Error("tick only understands numbers and 'h:m:s'"); - } - - while (i--) { - parsed = parseInt(strings[i], 10); - - if (parsed >= 60) { - throw new Error("Invalid time " + str); - } - - ms += parsed * Math.pow(60, (l - i - 1)); - } - - return ms * 1000; - } - - function createObject(object) { - var newObject; - - if (Object.create) { - newObject = Object.create(object); - } else { - var F = function () {}; - F.prototype = object; - newObject = new F(); - } - - newObject.Date.clock = newObject; - return newObject; - } - - sinon.clock = { - now: 0, - - create: function create(now) { - var clock = createObject(this); - - if (typeof now == "number") { - clock.now = now; - } - - if (!!now && typeof now == "object") { - throw new TypeError("now should be milliseconds since UNIX epoch"); - } - - return clock; - }, - - setTimeout: function setTimeout(callback, timeout) { - return addTimer.call(this, arguments, false); - }, - - clearTimeout: function clearTimeout(timerId) { - if (!this.timeouts) { - this.timeouts = []; - } - - if (timerId in this.timeouts) { - delete this.timeouts[timerId]; - } - }, - - setInterval: function setInterval(callback, timeout) { - return addTimer.call(this, arguments, true); - }, - - clearInterval: function clearInterval(timerId) { - this.clearTimeout(timerId); - }, - - setImmediate: function setImmediate(callback) { - var passThruArgs = Array.prototype.slice.call(arguments, 1); - - return addTimer.call(this, [callback, 0].concat(passThruArgs), false); - }, - - clearImmediate: function clearImmediate(timerId) { - this.clearTimeout(timerId); - }, - - tick: function tick(ms) { - ms = typeof ms == "number" ? ms : parseTime(ms); - var tickFrom = this.now, tickTo = this.now + ms, previous = this.now; - var timer = this.firstTimerInRange(tickFrom, tickTo); - - var firstException; - while (timer && tickFrom <= tickTo) { - if (this.timeouts[timer.id]) { - tickFrom = this.now = timer.callAt; - try { - this.callTimer(timer); - } catch (e) { - firstException = firstException || e; - } - } - - timer = this.firstTimerInRange(previous, tickTo); - previous = tickFrom; - } - - this.now = tickTo; - - if (firstException) { - throw firstException; - } - - return this.now; - }, - - firstTimerInRange: function (from, to) { - var timer, smallest = null, originalTimer; - - for (var id in this.timeouts) { - if (this.timeouts.hasOwnProperty(id)) { - if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) { - continue; - } - - if (smallest === null || this.timeouts[id].callAt < smallest) { - originalTimer = this.timeouts[id]; - smallest = this.timeouts[id].callAt; - - timer = { - func: this.timeouts[id].func, - callAt: this.timeouts[id].callAt, - interval: this.timeouts[id].interval, - id: this.timeouts[id].id, - invokeArgs: this.timeouts[id].invokeArgs - }; - } - } - } - - return timer || null; - }, - - callTimer: function (timer) { - if (typeof timer.interval == "number") { - this.timeouts[timer.id].callAt += timer.interval; - } else { - delete this.timeouts[timer.id]; - } - - try { - if (typeof timer.func == "function") { - timer.func.apply(null, timer.invokeArgs); - } else { - eval(timer.func); - } - } catch (e) { - var exception = e; - } - - if (!this.timeouts[timer.id]) { - if (exception) { - throw exception; - } - return; - } - - if (exception) { - throw exception; - } - }, - - reset: function reset() { - this.timeouts = {}; - }, - - Date: (function () { - var NativeDate = Date; - - function ClockDate(year, month, date, hour, minute, second, ms) { - // Defensive and verbose to avoid potential harm in passing - // explicit undefined when user does not pass argument - switch (arguments.length) { - case 0: - return new NativeDate(ClockDate.clock.now); - case 1: - return new NativeDate(year); - case 2: - return new NativeDate(year, month); - case 3: - return new NativeDate(year, month, date); - case 4: - return new NativeDate(year, month, date, hour); - case 5: - return new NativeDate(year, month, date, hour, minute); - case 6: - return new NativeDate(year, month, date, hour, minute, second); - default: - return new NativeDate(year, month, date, hour, minute, second, ms); - } - } - - return mirrorDateProperties(ClockDate, NativeDate); - }()) - }; - - function mirrorDateProperties(target, source) { - if (source.now) { - target.now = function now() { - return target.clock.now; - }; - } else { - delete target.now; - } - - if (source.toSource) { - target.toSource = function toSource() { - return source.toSource(); - }; - } else { - delete target.toSource; - } - - target.toString = function toString() { - return source.toString(); - }; - - target.prototype = source.prototype; - target.parse = source.parse; - target.UTC = source.UTC; - target.prototype.toUTCString = source.prototype.toUTCString; - - for (var prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - - return target; - } - - var methods = ["Date", "setTimeout", "setInterval", - "clearTimeout", "clearInterval"]; - - if (typeof global.setImmediate !== "undefined") { - methods.push("setImmediate"); - } - - if (typeof global.clearImmediate !== "undefined") { - methods.push("clearImmediate"); - } - - function restore() { - var method; - - for (var i = 0, l = this.methods.length; i < l; i++) { - method = this.methods[i]; - - if (global[method].hadOwnProperty) { - global[method] = this["_" + method]; - } else { - try { - delete global[method]; - } catch (e) {} - } - } - - // Prevent multiple executions which will completely remove these props - this.methods = []; - } - - function stubGlobal(method, clock) { - clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method); - clock["_" + method] = global[method]; - - if (method == "Date") { - var date = mirrorDateProperties(clock[method], global[method]); - global[method] = date; - } else { - global[method] = function () { - return clock[method].apply(clock, arguments); - }; - - for (var prop in clock[method]) { - if (clock[method].hasOwnProperty(prop)) { - global[method][prop] = clock[method][prop]; - } - } - } - - global[method].clock = clock; - } - - sinon.useFakeTimers = function useFakeTimers(now) { - var clock = sinon.clock.create(now); - clock.restore = restore; - clock.methods = Array.prototype.slice.call(arguments, - typeof now == "number" ? 1 : 0); - - if (clock.methods.length === 0) { - clock.methods = methods; - } - - for (var i = 0, l = clock.methods.length; i < l; i++) { - stubGlobal(clock.methods[i], clock); - } - - return clock; - }; -}(typeof global != "undefined" && typeof global !== "function" ? global : this)); - -sinon.timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined), - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date -}; - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Minimal Event interface implementation - * - * Original implementation by Sven Fuchs: https://gist.github.com/995028 - * Modifications and tests by Christian Johansen. - * - * @author Sven Fuchs (svenfuchs@artweb-design.de) - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2011 Sven Fuchs, Christian Johansen - */ - -if (typeof sinon == "undefined") { - this.sinon = {}; -} - -(function () { - var push = [].push; - - sinon.Event = function Event(type, bubbles, cancelable, target) { - this.initEvent(type, bubbles, cancelable, target); - }; - - sinon.Event.prototype = { - initEvent: function(type, bubbles, cancelable, target) { - this.type = type; - this.bubbles = bubbles; - this.cancelable = cancelable; - this.target = target; - }, - - stopPropagation: function () {}, - - preventDefault: function () { - this.defaultPrevented = true; - } - }; - - sinon.EventTarget = { - addEventListener: function addEventListener(event, listener) { - this.eventListeners = this.eventListeners || {}; - this.eventListeners[event] = this.eventListeners[event] || []; - push.call(this.eventListeners[event], listener); - }, - - removeEventListener: function removeEventListener(event, listener) { - var listeners = this.eventListeners && this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }, - - dispatchEvent: function dispatchEvent(event) { - var type = event.type; - var listeners = this.eventListeners && this.eventListeners[type] || []; - - for (var i = 0; i < listeners.length; i++) { - if (typeof listeners[i] == "function") { - listeners[i].call(this, event); - } else { - listeners[i].handleEvent(event); - } - } - - return !!event.defaultPrevented; - } - }; -}()); - -/** - * @depend ../../sinon.js - * @depend event.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Fake XMLHttpRequest object - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -// wrapper for global -(function(global) { - if (typeof sinon === "undefined") { - global.sinon = {}; - } - - var supportsProgress = typeof ProgressEvent !== "undefined"; - var supportsCustomEvent = typeof CustomEvent !== "undefined"; - sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest }; - var xhr = sinon.xhr; - xhr.GlobalXMLHttpRequest = global.XMLHttpRequest; - xhr.GlobalActiveXObject = global.ActiveXObject; - xhr.supportsActiveX = typeof xhr.GlobalActiveXObject != "undefined"; - xhr.supportsXHR = typeof xhr.GlobalXMLHttpRequest != "undefined"; - xhr.workingXHR = xhr.supportsXHR ? xhr.GlobalXMLHttpRequest : xhr.supportsActiveX - ? function() { return new xhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0") } : false; - xhr.supportsCORS = 'withCredentials' in (new sinon.xhr.GlobalXMLHttpRequest()); - - /*jsl:ignore*/ - var unsafeHeaders = { - "Accept-Charset": true, - "Accept-Encoding": true, - "Connection": true, - "Content-Length": true, - "Cookie": true, - "Cookie2": true, - "Content-Transfer-Encoding": true, - "Date": true, - "Expect": true, - "Host": true, - "Keep-Alive": true, - "Referer": true, - "TE": true, - "Trailer": true, - "Transfer-Encoding": true, - "Upgrade": true, - "User-Agent": true, - "Via": true - }; - /*jsl:end*/ - - function FakeXMLHttpRequest() { - this.readyState = FakeXMLHttpRequest.UNSENT; - this.requestHeaders = {}; - this.requestBody = null; - this.status = 0; - this.statusText = ""; - this.upload = new UploadProgress(); - if (sinon.xhr.supportsCORS) { - this.withCredentials = false; - } - - - var xhr = this; - var events = ["loadstart", "load", "abort", "loadend"]; - - function addEventListener(eventName) { - xhr.addEventListener(eventName, function (event) { - var listener = xhr["on" + eventName]; - - if (listener && typeof listener == "function") { - listener(event); - } - }); - } - - for (var i = events.length - 1; i >= 0; i--) { - addEventListener(events[i]); - } - - if (typeof FakeXMLHttpRequest.onCreate == "function") { - FakeXMLHttpRequest.onCreate(this); - } - } - - // An upload object is created for each - // FakeXMLHttpRequest and allows upload - // events to be simulated using uploadProgress - // and uploadError. - function UploadProgress() { - this.eventListeners = { - "progress": [], - "load": [], - "abort": [], - "error": [] - } - } - - UploadProgress.prototype.addEventListener = function(event, listener) { - this.eventListeners[event].push(listener); - }; - - UploadProgress.prototype.removeEventListener = function(event, listener) { - var listeners = this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }; - - UploadProgress.prototype.dispatchEvent = function(event) { - var listeners = this.eventListeners[event.type] || []; - - for (var i = 0, listener; (listener = listeners[i]) != null; i++) { - listener(event); - } - }; - - function verifyState(xhr) { - if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { - throw new Error("INVALID_STATE_ERR"); - } - - if (xhr.sendFlag) { - throw new Error("INVALID_STATE_ERR"); - } - } - - // filtering to enable a white-list version of Sinon FakeXhr, - // where whitelisted requests are passed through to real XHR - function each(collection, callback) { - if (!collection) return; - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } - } - function some(collection, callback) { - for (var index = 0; index < collection.length; index++) { - if(callback(collection[index]) === true) return true; - } - return false; - } - // largest arity in XHR is 5 - XHR#open - var apply = function(obj,method,args) { - switch(args.length) { - case 0: return obj[method](); - case 1: return obj[method](args[0]); - case 2: return obj[method](args[0],args[1]); - case 3: return obj[method](args[0],args[1],args[2]); - case 4: return obj[method](args[0],args[1],args[2],args[3]); - case 5: return obj[method](args[0],args[1],args[2],args[3],args[4]); - } - }; - - FakeXMLHttpRequest.filters = []; - FakeXMLHttpRequest.addFilter = function(fn) { - this.filters.push(fn) - }; - var IE6Re = /MSIE 6/; - FakeXMLHttpRequest.defake = function(fakeXhr,xhrArgs) { - var xhr = new sinon.xhr.workingXHR(); - each(["open","setRequestHeader","send","abort","getResponseHeader", - "getAllResponseHeaders","addEventListener","overrideMimeType","removeEventListener"], - function(method) { - fakeXhr[method] = function() { - return apply(xhr,method,arguments); - }; - }); - - var copyAttrs = function(args) { - each(args, function(attr) { - try { - fakeXhr[attr] = xhr[attr] - } catch(e) { - if(!IE6Re.test(navigator.userAgent)) throw e; - } - }); - }; - - var stateChange = function() { - fakeXhr.readyState = xhr.readyState; - if(xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) { - copyAttrs(["status","statusText"]); - } - if(xhr.readyState >= FakeXMLHttpRequest.LOADING) { - copyAttrs(["responseText"]); - } - if(xhr.readyState === FakeXMLHttpRequest.DONE) { - copyAttrs(["responseXML"]); - } - if(fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr }); - }; - if(xhr.addEventListener) { - for(var event in fakeXhr.eventListeners) { - if(fakeXhr.eventListeners.hasOwnProperty(event)) { - each(fakeXhr.eventListeners[event],function(handler) { - xhr.addEventListener(event, handler); - }); - } - } - xhr.addEventListener("readystatechange",stateChange); - } else { - xhr.onreadystatechange = stateChange; - } - apply(xhr,"open",xhrArgs); - }; - FakeXMLHttpRequest.useFilters = false; - - function verifyRequestSent(xhr) { - if (xhr.readyState == FakeXMLHttpRequest.DONE) { - throw new Error("Request done"); - } - } - - function verifyHeadersReceived(xhr) { - if (xhr.async && xhr.readyState != FakeXMLHttpRequest.HEADERS_RECEIVED) { - throw new Error("No headers received"); - } - } - - function verifyResponseBodyType(body) { - if (typeof body != "string") { - var error = new Error("Attempted to respond to fake XMLHttpRequest with " + - body + ", which is not a string."); - error.name = "InvalidBodyException"; - throw error; - } - } - - sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { - async: true, - - open: function open(method, url, async, username, password) { - this.method = method; - this.url = url; - this.async = typeof async == "boolean" ? async : true; - this.username = username; - this.password = password; - this.responseText = null; - this.responseXML = null; - this.requestHeaders = {}; - this.sendFlag = false; - if(sinon.FakeXMLHttpRequest.useFilters === true) { - var xhrArgs = arguments; - var defake = some(FakeXMLHttpRequest.filters,function(filter) { - return filter.apply(this,xhrArgs) - }); - if (defake) { - return sinon.FakeXMLHttpRequest.defake(this,arguments); - } - } - this.readyStateChange(FakeXMLHttpRequest.OPENED); - }, - - readyStateChange: function readyStateChange(state) { - this.readyState = state; - - if (typeof this.onreadystatechange == "function") { - try { - this.onreadystatechange(); - } catch (e) { - sinon.logError("Fake XHR onreadystatechange handler", e); - } - } - - this.dispatchEvent(new sinon.Event("readystatechange")); - - switch (this.readyState) { - case FakeXMLHttpRequest.DONE: - this.dispatchEvent(new sinon.Event("load", false, false, this)); - this.dispatchEvent(new sinon.Event("loadend", false, false, this)); - this.upload.dispatchEvent(new sinon.Event("load", false, false, this)); - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", {loaded: 100, total: 100})); - } - break; - } - }, - - setRequestHeader: function setRequestHeader(header, value) { - verifyState(this); - - if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) { - throw new Error("Refused to set unsafe header \"" + header + "\""); - } - - if (this.requestHeaders[header]) { - this.requestHeaders[header] += "," + value; - } else { - this.requestHeaders[header] = value; - } - }, - - // Helps testing - setResponseHeaders: function setResponseHeaders(headers) { - this.responseHeaders = {}; - - for (var header in headers) { - if (headers.hasOwnProperty(header)) { - this.responseHeaders[header] = headers[header]; - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED); - } else { - this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED; - } - }, - - // Currently treats ALL data as a DOMString (i.e. no Document) - send: function send(data) { - verifyState(this); - - if (!/^(get|head)$/i.test(this.method)) { - if (this.requestHeaders["Content-Type"]) { - var value = this.requestHeaders["Content-Type"].split(";"); - this.requestHeaders["Content-Type"] = value[0] + ";charset=utf-8"; - } else { - this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; - } - - this.requestBody = data; - } - - this.errorFlag = false; - this.sendFlag = this.async; - this.readyStateChange(FakeXMLHttpRequest.OPENED); - - if (typeof this.onSend == "function") { - this.onSend(this); - } - - this.dispatchEvent(new sinon.Event("loadstart", false, false, this)); - }, - - abort: function abort() { - this.aborted = true; - this.responseText = null; - this.errorFlag = true; - this.requestHeaders = {}; - - if (this.readyState > sinon.FakeXMLHttpRequest.UNSENT && this.sendFlag) { - this.readyStateChange(sinon.FakeXMLHttpRequest.DONE); - this.sendFlag = false; - } - - this.readyState = sinon.FakeXMLHttpRequest.UNSENT; - - this.dispatchEvent(new sinon.Event("abort", false, false, this)); - - this.upload.dispatchEvent(new sinon.Event("abort", false, false, this)); - - if (typeof this.onerror === "function") { - this.onerror(); - } - }, - - getResponseHeader: function getResponseHeader(header) { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return null; - } - - if (/^Set-Cookie2?$/i.test(header)) { - return null; - } - - header = header.toLowerCase(); - - for (var h in this.responseHeaders) { - if (h.toLowerCase() == header) { - return this.responseHeaders[h]; - } - } - - return null; - }, - - getAllResponseHeaders: function getAllResponseHeaders() { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return ""; - } - - var headers = ""; - - for (var header in this.responseHeaders) { - if (this.responseHeaders.hasOwnProperty(header) && - !/^Set-Cookie2?$/i.test(header)) { - headers += header + ": " + this.responseHeaders[header] + "\r\n"; - } - } - - return headers; - }, - - setResponseBody: function setResponseBody(body) { - verifyRequestSent(this); - verifyHeadersReceived(this); - verifyResponseBodyType(body); - - var chunkSize = this.chunkSize || 10; - var index = 0; - this.responseText = ""; - - do { - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.LOADING); - } - - this.responseText += body.substring(index, index + chunkSize); - index += chunkSize; - } while (index < body.length); - - var type = this.getResponseHeader("Content-Type"); - - if (this.responseText && - (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) { - try { - this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText); - } catch (e) { - // Unable to parse XML - no biggie - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.DONE); - } else { - this.readyState = FakeXMLHttpRequest.DONE; - } - }, - - respond: function respond(status, headers, body) { - this.status = typeof status == "number" ? status : 200; - this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; - this.setResponseHeaders(headers || {}); - this.setResponseBody(body || ""); - }, - - uploadProgress: function uploadProgress(progressEventRaw) { - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", progressEventRaw)); - } - }, - - uploadError: function uploadError(error) { - if (supportsCustomEvent) { - this.upload.dispatchEvent(new CustomEvent("error", {"detail": error})); - } - } - }); - - sinon.extend(FakeXMLHttpRequest, { - UNSENT: 0, - OPENED: 1, - HEADERS_RECEIVED: 2, - LOADING: 3, - DONE: 4 - }); - - // Borrowed from JSpec - FakeXMLHttpRequest.parseXML = function parseXML(text) { - var xmlDoc; - - if (typeof DOMParser != "undefined") { - var parser = new DOMParser(); - xmlDoc = parser.parseFromString(text, "text/xml"); - } else { - xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); - xmlDoc.async = "false"; - xmlDoc.loadXML(text); - } - - return xmlDoc; - }; - - FakeXMLHttpRequest.statusCodes = { - 100: "Continue", - 101: "Switching Protocols", - 200: "OK", - 201: "Created", - 202: "Accepted", - 203: "Non-Authoritative Information", - 204: "No Content", - 205: "Reset Content", - 206: "Partial Content", - 300: "Multiple Choice", - 301: "Moved Permanently", - 302: "Found", - 303: "See Other", - 304: "Not Modified", - 305: "Use Proxy", - 307: "Temporary Redirect", - 400: "Bad Request", - 401: "Unauthorized", - 402: "Payment Required", - 403: "Forbidden", - 404: "Not Found", - 405: "Method Not Allowed", - 406: "Not Acceptable", - 407: "Proxy Authentication Required", - 408: "Request Timeout", - 409: "Conflict", - 410: "Gone", - 411: "Length Required", - 412: "Precondition Failed", - 413: "Request Entity Too Large", - 414: "Request-URI Too Long", - 415: "Unsupported Media Type", - 416: "Requested Range Not Satisfiable", - 417: "Expectation Failed", - 422: "Unprocessable Entity", - 500: "Internal Server Error", - 501: "Not Implemented", - 502: "Bad Gateway", - 503: "Service Unavailable", - 504: "Gateway Timeout", - 505: "HTTP Version Not Supported" - }; - - sinon.useFakeXMLHttpRequest = function () { - sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) { - if (xhr.supportsXHR) { - global.XMLHttpRequest = xhr.GlobalXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = xhr.GlobalActiveXObject; - } - - delete sinon.FakeXMLHttpRequest.restore; - - if (keepOnCreate !== true) { - delete sinon.FakeXMLHttpRequest.onCreate; - } - }; - if (xhr.supportsXHR) { - global.XMLHttpRequest = sinon.FakeXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = function ActiveXObject(objId) { - if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { - - return new sinon.FakeXMLHttpRequest(); - } - - return new xhr.GlobalActiveXObject(objId); - }; - } - - return sinon.FakeXMLHttpRequest; - }; - - sinon.FakeXMLHttpRequest = FakeXMLHttpRequest; - -})(typeof global === "object" ? global : this); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_xml_http_request.js - */ -/*jslint eqeqeq: false, onevar: false, regexp: false, plusplus: false*/ -/*global module, require, window*/ -/** - * The Sinon "server" mimics a web server that receives requests from - * sinon.FakeXMLHttpRequest and provides an API to respond to those requests, - * both synchronously and asynchronously. To respond synchronuously, canned - * answers have to be provided upfront. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -sinon.fakeServer = (function () { - var push = [].push; - function F() {} - - function create(proto) { - F.prototype = proto; - return new F(); - } - - function responseArray(handler) { - var response = handler; - - if (Object.prototype.toString.call(handler) != "[object Array]") { - response = [200, {}, handler]; - } - - if (typeof response[2] != "string") { - throw new TypeError("Fake server response body should be string, but was " + - typeof response[2]); - } - - return response; - } - - var wloc = typeof window !== "undefined" ? window.location : {}; - var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host); - - function matchOne(response, reqMethod, reqUrl) { - var rmeth = response.method; - var matchMethod = !rmeth || rmeth.toLowerCase() == reqMethod.toLowerCase(); - var url = response.url; - var matchUrl = !url || url == reqUrl || (typeof url.test == "function" && url.test(reqUrl)); - - return matchMethod && matchUrl; - } - - function match(response, request) { - var requestUrl = request.url; - - if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) { - requestUrl = requestUrl.replace(rCurrLoc, ""); - } - - if (matchOne(response, this.getHTTPMethod(request), requestUrl)) { - if (typeof response.response == "function") { - var ru = response.url; - var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []); - return response.response.apply(response, args); - } - - return true; - } - - return false; - } - - function log(response, request) { - var str; - - str = "Request:\n" + sinon.format(request) + "\n\n"; - str += "Response:\n" + sinon.format(response) + "\n\n"; - - sinon.log(str); - } - - return { - create: function () { - var server = create(this); - this.xhr = sinon.useFakeXMLHttpRequest(); - server.requests = []; - - this.xhr.onCreate = function (xhrObj) { - server.addRequest(xhrObj); - }; - - return server; - }, - - addRequest: function addRequest(xhrObj) { - var server = this; - push.call(this.requests, xhrObj); - - xhrObj.onSend = function () { - server.handleRequest(this); - - if (server.autoRespond && !server.responding) { - setTimeout(function () { - server.responding = false; - server.respond(); - }, server.autoRespondAfter || 10); - - server.responding = true; - } - }; - }, - - getHTTPMethod: function getHTTPMethod(request) { - if (this.fakeHTTPMethods && /post/i.test(request.method)) { - var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); - return !!matches ? matches[1] : request.method; - } - - return request.method; - }, - - handleRequest: function handleRequest(xhr) { - if (xhr.async) { - if (!this.queue) { - this.queue = []; - } - - push.call(this.queue, xhr); - } else { - this.processRequest(xhr); - } - }, - - respondWith: function respondWith(method, url, body) { - if (arguments.length == 1 && typeof method != "function") { - this.response = responseArray(method); - return; - } - - if (!this.responses) { this.responses = []; } - - if (arguments.length == 1) { - body = method; - url = method = null; - } - - if (arguments.length == 2) { - body = url; - url = method; - method = null; - } - - push.call(this.responses, { - method: method, - url: url, - response: typeof body == "function" ? body : responseArray(body) - }); - }, - - respond: function respond() { - if (arguments.length > 0) this.respondWith.apply(this, arguments); - var queue = this.queue || []; - var requests = queue.splice(0); - var request; - - while(request = requests.shift()) { - this.processRequest(request); - } - }, - - processRequest: function processRequest(request) { - try { - if (request.aborted) { - return; - } - - var response = this.response || [404, {}, ""]; - - if (this.responses) { - for (var l = this.responses.length, i = l - 1; i >= 0; i--) { - if (match.call(this, this.responses[i], request)) { - response = this.responses[i].response; - break; - } - } - } - - if (request.readyState != 4) { - log(response, request); - - request.respond(response[0], response[1], response[2]); - } - } catch (e) { - sinon.logError("Fake server request processing", e); - } - }, - - restore: function restore() { - return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments); - } - }; -}()); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_server.js - * @depend fake_timers.js - */ -/*jslint browser: true, eqeqeq: false, onevar: false*/ -/*global sinon*/ -/** - * Add-on for sinon.fakeServer that automatically handles a fake timer along with - * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery - * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead, - * it polls the object for completion with setInterval. Dispite the direct - * motivation, there is nothing jQuery-specific in this file, so it can be used - * in any environment where the ajax implementation depends on setInterval or - * setTimeout. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function () { - function Server() {} - Server.prototype = sinon.fakeServer; - - sinon.fakeServerWithClock = new Server(); - - sinon.fakeServerWithClock.addRequest = function addRequest(xhr) { - if (xhr.async) { - if (typeof setTimeout.clock == "object") { - this.clock = setTimeout.clock; - } else { - this.clock = sinon.useFakeTimers(); - this.resetClock = true; - } - - if (!this.longestTimeout) { - var clockSetTimeout = this.clock.setTimeout; - var clockSetInterval = this.clock.setInterval; - var server = this; - - this.clock.setTimeout = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetTimeout.apply(this, arguments); - }; - - this.clock.setInterval = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetInterval.apply(this, arguments); - }; - } - } - - return sinon.fakeServer.addRequest.call(this, xhr); - }; - - sinon.fakeServerWithClock.respond = function respond() { - var returnVal = sinon.fakeServer.respond.apply(this, arguments); - - if (this.clock) { - this.clock.tick(this.longestTimeout || 0); - this.longestTimeout = 0; - - if (this.resetClock) { - this.clock.restore(); - this.resetClock = false; - } - } - - return returnVal; - }; - - sinon.fakeServerWithClock.restore = function restore() { - if (this.clock) { - this.clock.restore(); - } - - return sinon.fakeServer.restore.apply(this, arguments); - }; -}()); - -/** - * @depend ../sinon.js - * @depend collection.js - * @depend util/fake_timers.js - * @depend util/fake_server_with_clock.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global require, module*/ -/** - * Manages fake collections as well as fake utilities such as Sinon's - * timers and fake XHR implementation in one convenient object. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof module !== 'undefined' && module.exports) { - var sinon = require("../sinon"); - sinon.extend(sinon, require("./util/fake_timers")); -} - -(function () { - var push = [].push; - - function exposeValue(sandbox, config, key, value) { - if (!value) { - return; - } - - if (config.injectInto && !(key in config.injectInto) ) { - config.injectInto[key] = value; - } else { - push.call(sandbox.args, value); - } - } - - function prepareSandboxFromConfig(config) { - var sandbox = sinon.create(sinon.sandbox); - - if (config.useFakeServer) { - if (typeof config.useFakeServer == "object") { - sandbox.serverPrototype = config.useFakeServer; - } - - sandbox.useFakeServer(); - } - - if (config.useFakeTimers) { - if (typeof config.useFakeTimers == "object") { - sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers); - } else { - sandbox.useFakeTimers(); - } - } - - return sandbox; - } - - sinon.sandbox = sinon.extend(sinon.create(sinon.collection), { - useFakeTimers: function useFakeTimers() { - this.clock = sinon.useFakeTimers.apply(sinon, arguments); - - return this.add(this.clock); - }, - - serverPrototype: sinon.fakeServer, - - useFakeServer: function useFakeServer() { - var proto = this.serverPrototype || sinon.fakeServer; - - if (!proto || !proto.create) { - return null; - } - - this.server = proto.create(); - return this.add(this.server); - }, - - inject: function (obj) { - sinon.collection.inject.call(this, obj); - - if (this.clock) { - obj.clock = this.clock; - } - - if (this.server) { - obj.server = this.server; - obj.requests = this.server.requests; - } - - return obj; - }, - - create: function (config) { - if (!config) { - return sinon.create(sinon.sandbox); - } - - var sandbox = prepareSandboxFromConfig(config); - sandbox.args = sandbox.args || []; - var prop, value, exposed = sandbox.inject({}); - - if (config.properties) { - for (var i = 0, l = config.properties.length; i < l; i++) { - prop = config.properties[i]; - value = exposed[prop] || prop == "sandbox" && sandbox; - exposeValue(sandbox, config, prop, value); - } - } else { - exposeValue(sandbox, config, "sandbox", value); - } - - return sandbox; - } - }); - - sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer; - - if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon.sandbox; - } -}()); - -/** - * @depend ../sinon.js - * @depend stub.js - * @depend mock.js - * @depend sandbox.js - */ -/*jslint eqeqeq: false, onevar: false, forin: true, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Test function, sandboxes fakes - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function test(callback) { - var type = typeof callback; - - if (type != "function") { - throw new TypeError("sinon.test needs to wrap a test function, got " + type); - } - - return function () { - var config = sinon.getConfig(sinon.config); - config.injectInto = config.injectIntoThis && this || config.injectInto; - var sandbox = sinon.sandbox.create(config); - var exception, result; - var args = Array.prototype.slice.call(arguments).concat(sandbox.args); - - try { - result = callback.apply(this, args); - } catch (e) { - exception = e; - } - - if (typeof exception !== "undefined") { - sandbox.restore(); - throw exception; - } - else { - sandbox.verifyAndRestore(); - } - - return result; - }; - } - - test.config = { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }; - - if (commonJSModule) { - module.exports = test; - } else { - sinon.test = test; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend test.js - */ -/*jslint eqeqeq: false, onevar: false, eqeqeq: false*/ -/*global module, require, sinon*/ -/** - * Test case, sandboxes all test functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon || !Object.prototype.hasOwnProperty) { - return; - } - - function createTest(property, setUp, tearDown) { - return function () { - if (setUp) { - setUp.apply(this, arguments); - } - - var exception, result; - - try { - result = property.apply(this, arguments); - } catch (e) { - exception = e; - } - - if (tearDown) { - tearDown.apply(this, arguments); - } - - if (exception) { - throw exception; - } - - return result; - }; - } - - function testCase(tests, prefix) { - /*jsl:ignore*/ - if (!tests || typeof tests != "object") { - throw new TypeError("sinon.testCase needs an object with test functions"); - } - /*jsl:end*/ - - prefix = prefix || "test"; - var rPrefix = new RegExp("^" + prefix); - var methods = {}, testName, property, method; - var setUp = tests.setUp; - var tearDown = tests.tearDown; - - for (testName in tests) { - if (tests.hasOwnProperty(testName)) { - property = tests[testName]; - - if (/^(setUp|tearDown)$/.test(testName)) { - continue; - } - - if (typeof property == "function" && rPrefix.test(testName)) { - method = property; - - if (setUp || tearDown) { - method = createTest(property, setUp, tearDown); - } - - methods[testName] = sinon.test(method); - } else { - methods[testName] = tests[testName]; - } - } - } - - return methods; - } - - if (commonJSModule) { - module.exports = testCase; - } else { - sinon.testCase = testCase; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - */ -/*jslint eqeqeq: false, onevar: false, nomen: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Assertions matching the test spy retrieval interface. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon, global) { - var commonJSModule = typeof module !== "undefined" && module.exports; - var slice = Array.prototype.slice; - var assert; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function verifyIsStub() { - var method; - - for (var i = 0, l = arguments.length; i < l; ++i) { - method = arguments[i]; - - if (!method) { - assert.fail("fake is not a spy"); - } - - if (typeof method != "function") { - assert.fail(method + " is not a function"); - } - - if (typeof method.getCall != "function") { - assert.fail(method + " is not stubbed"); - } - } - } - - function failAssertion(object, msg) { - object = object || global; - var failMethod = object.fail || assert.fail; - failMethod.call(object, msg); - } - - function mirrorPropAsAssertion(name, method, message) { - if (arguments.length == 2) { - message = method; - method = name; - } - - assert[name] = function (fake) { - verifyIsStub(fake); - - var args = slice.call(arguments, 1); - var failed = false; - - if (typeof method == "function") { - failed = !method(fake); - } else { - failed = typeof fake[method] == "function" ? - !fake[method].apply(fake, args) : !fake[method]; - } - - if (failed) { - failAssertion(this, fake.printf.apply(fake, [message].concat(args))); - } else { - assert.pass(name); - } - }; - } - - function exposedName(prefix, prop) { - return !prefix || /^fail/.test(prop) ? prop : - prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); - } - - assert = { - failException: "AssertError", - - fail: function fail(message) { - var error = new Error(message); - error.name = this.failException || assert.failException; - - throw error; - }, - - pass: function pass(assertion) {}, - - callOrder: function assertCallOrder() { - verifyIsStub.apply(null, arguments); - var expected = "", actual = ""; - - if (!sinon.calledInOrder(arguments)) { - try { - expected = [].join.call(arguments, ", "); - var calls = slice.call(arguments); - var i = calls.length; - while (i) { - if (!calls[--i].called) { - calls.splice(i, 1); - } - } - actual = sinon.orderByFirstCall(calls).join(", "); - } catch (e) { - // If this fails, we'll just fall back to the blank string - } - - failAssertion(this, "expected " + expected + " to be " + - "called in order but were called as " + actual); - } else { - assert.pass("callOrder"); - } - }, - - callCount: function assertCallCount(method, count) { - verifyIsStub(method); - - if (method.callCount != count) { - var msg = "expected %n to be called " + sinon.timesInWords(count) + - " but was called %c%C"; - failAssertion(this, method.printf(msg)); - } else { - assert.pass("callCount"); - } - }, - - expose: function expose(target, options) { - if (!target) { - throw new TypeError("target is null or undefined"); - } - - var o = options || {}; - var prefix = typeof o.prefix == "undefined" && "assert" || o.prefix; - var includeFail = typeof o.includeFail == "undefined" || !!o.includeFail; - - for (var method in this) { - if (method != "export" && (includeFail || !/^(fail)/.test(method))) { - target[exposedName(prefix, method)] = this[method]; - } - } - - return target; - } - }; - - mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); - mirrorPropAsAssertion("notCalled", function (spy) { return !spy.called; }, - "expected %n to not have been called but was called %c%C"); - mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); - mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); - mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); - mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); - mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t"); - mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); - mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); - mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); - mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); - mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); - mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); - mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); - mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); - mirrorPropAsAssertion("threw", "%n did not throw exception%C"); - mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); - - if (commonJSModule) { - module.exports = assert; - } else { - sinon.assert = assert; - } -}(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global)); - -return sinon;}.call(typeof window != 'undefined' && window || {})); diff --git a/test/utils/sinon/sinon-ie-1.8.2.js b/test/utils/sinon/sinon-ie-1.8.2.js deleted file mode 100644 index 6e255ba83bd94..0000000000000 --- a/test/utils/sinon/sinon-ie-1.8.2.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/ -/** - * Helps IE run the fake timers. By defining global functions, IE allows - * them to be overwritten at a later point. If these are not defined like - * this, overwriting them will result in anything from an exception to browser - * crash. - * - * If you don't require fake timers to work in IE, don't include this file. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -function setTimeout() {} -function clearTimeout() {} -function setImmediate() {} -function clearImmediate() {} -function setInterval() {} -function clearInterval() {} -function Date() {} - -// Reassign the original functions. Now their writable attribute -// should be true. Hackish, I know, but it works. -setTimeout = sinon.timers.setTimeout; -clearTimeout = sinon.timers.clearTimeout; -setImmediate = sinon.timers.setImmediate; -clearImmediate = sinon.timers.clearImmediate; -setInterval = sinon.timers.setInterval; -clearInterval = sinon.timers.clearInterval; -Date = sinon.timers.Date; - -/*global sinon*/ -/** - * Helps IE run the fake XMLHttpRequest. By defining global functions, IE allows - * them to be overwritten at a later point. If these are not defined like - * this, overwriting them will result in anything from an exception to browser - * crash. - * - * If you don't require fake XHR to work in IE, don't include this file. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -function XMLHttpRequest() {} - -// Reassign the original function. Now its writable attribute -// should be true. Hackish, I know, but it works. -XMLHttpRequest = sinon.xhr.XMLHttpRequest || undefined; diff --git a/test/utils/sinon/sinon-ie.js b/test/utils/sinon/sinon-ie.js deleted file mode 100644 index 6e255ba83bd94..0000000000000 --- a/test/utils/sinon/sinon-ie.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/ -/** - * Helps IE run the fake timers. By defining global functions, IE allows - * them to be overwritten at a later point. If these are not defined like - * this, overwriting them will result in anything from an exception to browser - * crash. - * - * If you don't require fake timers to work in IE, don't include this file. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -function setTimeout() {} -function clearTimeout() {} -function setImmediate() {} -function clearImmediate() {} -function setInterval() {} -function clearInterval() {} -function Date() {} - -// Reassign the original functions. Now their writable attribute -// should be true. Hackish, I know, but it works. -setTimeout = sinon.timers.setTimeout; -clearTimeout = sinon.timers.clearTimeout; -setImmediate = sinon.timers.setImmediate; -clearImmediate = sinon.timers.clearImmediate; -setInterval = sinon.timers.setInterval; -clearInterval = sinon.timers.clearInterval; -Date = sinon.timers.Date; - -/*global sinon*/ -/** - * Helps IE run the fake XMLHttpRequest. By defining global functions, IE allows - * them to be overwritten at a later point. If these are not defined like - * this, overwriting them will result in anything from an exception to browser - * crash. - * - * If you don't require fake XHR to work in IE, don't include this file. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -function XMLHttpRequest() {} - -// Reassign the original function. Now its writable attribute -// should be true. Hackish, I know, but it works. -XMLHttpRequest = sinon.xhr.XMLHttpRequest || undefined; diff --git a/test/utils/sinon/sinon-server-1.8.2.js b/test/utils/sinon/sinon-server-1.8.2.js deleted file mode 100644 index 409c0dc16c258..0000000000000 --- a/test/utils/sinon/sinon-server-1.8.2.js +++ /dev/null @@ -1,1726 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ -/*global module, require, __dirname, document*/ -/** - * Sinon core utilities. For internal use only. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -var sinon = (function (formatio) { - var div = typeof document != "undefined" && document.createElement("div"); - var hasOwn = Object.prototype.hasOwnProperty; - - function isDOMNode(obj) { - var success = false; - - try { - obj.appendChild(div); - success = div.parentNode == obj; - } catch (e) { - return false; - } finally { - try { - obj.removeChild(div); - } catch (e) { - // Remove failed, not much we can do about that - } - } - - return success; - } - - function isElement(obj) { - return div && obj && obj.nodeType === 1 && isDOMNode(obj); - } - - function isFunction(obj) { - return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); - } - - function mirrorProperties(target, source) { - for (var prop in source) { - if (!hasOwn.call(target, prop)) { - target[prop] = source[prop]; - } - } - } - - function isRestorable (obj) { - return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon; - } - - var sinon = { - wrapMethod: function wrapMethod(object, property, method) { - if (!object) { - throw new TypeError("Should wrap property of object"); - } - - if (typeof method != "function") { - throw new TypeError("Method wrapper should be function"); - } - - var wrappedMethod = object[property], - error; - - if (!isFunction(wrappedMethod)) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); - } - - if (wrappedMethod.restore && wrappedMethod.restore.sinon) { - error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); - } - - if (wrappedMethod.calledBefore) { - var verb = !!wrappedMethod.returns ? "stubbed" : "spied on"; - error = new TypeError("Attempted to wrap " + property + " which is already " + verb); - } - - if (error) { - if (wrappedMethod._stack) { - error.stack += '\n--------------\n' + wrappedMethod._stack; - } - throw error; - } - - // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem - // when using hasOwn.call on objects from other frames. - var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); - object[property] = method; - method.displayName = property; - // Set up a stack trace which can be used later to find what line of - // code the original method was created on. - method._stack = (new Error('Stack Trace for original')).stack; - - method.restore = function () { - // For prototype properties try to reset by delete first. - // If this fails (ex: localStorage on mobile safari) then force a reset - // via direct assignment. - if (!owned) { - delete object[property]; - } - if (object[property] === method) { - object[property] = wrappedMethod; - } - }; - - method.restore.sinon = true; - mirrorProperties(method, wrappedMethod); - - return method; - }, - - extend: function extend(target) { - for (var i = 1, l = arguments.length; i < l; i += 1) { - for (var prop in arguments[i]) { - if (arguments[i].hasOwnProperty(prop)) { - target[prop] = arguments[i][prop]; - } - - // DONT ENUM bug, only care about toString - if (arguments[i].hasOwnProperty("toString") && - arguments[i].toString != target.toString) { - target.toString = arguments[i].toString; - } - } - } - - return target; - }, - - create: function create(proto) { - var F = function () {}; - F.prototype = proto; - return new F(); - }, - - deepEqual: function deepEqual(a, b) { - if (sinon.match && sinon.match.isMatcher(a)) { - return a.test(b); - } - if (typeof a != "object" || typeof b != "object") { - return a === b; - } - - if (isElement(a) || isElement(b)) { - return a === b; - } - - if (a === b) { - return true; - } - - if ((a === null && b !== null) || (a !== null && b === null)) { - return false; - } - - var aString = Object.prototype.toString.call(a); - if (aString != Object.prototype.toString.call(b)) { - return false; - } - - if (aString == "[object Date]") { - return a.valueOf() === b.valueOf(); - } - - var prop, aLength = 0, bLength = 0; - - if (aString == "[object Array]" && a.length !== b.length) { - return false; - } - - for (prop in a) { - aLength += 1; - - if (!deepEqual(a[prop], b[prop])) { - return false; - } - } - - for (prop in b) { - bLength += 1; - } - - return aLength == bLength; - }, - - functionName: function functionName(func) { - var name = func.displayName || func.name; - - // Use function decomposition as a last resort to get function - // name. Does not rely on function decomposition to work - if it - // doesn't debugging will be slightly less informative - // (i.e. toString will say 'spy' rather than 'myFunc'). - if (!name) { - var matches = func.toString().match(/function ([^\s\(]+)/); - name = matches && matches[1]; - } - - return name; - }, - - functionToString: function toString() { - if (this.getCall && this.callCount) { - var thisValue, prop, i = this.callCount; - - while (i--) { - thisValue = this.getCall(i).thisValue; - - for (prop in thisValue) { - if (thisValue[prop] === this) { - return prop; - } - } - } - } - - return this.displayName || "sinon fake"; - }, - - getConfig: function (custom) { - var config = {}; - custom = custom || {}; - var defaults = sinon.defaultConfig; - - for (var prop in defaults) { - if (defaults.hasOwnProperty(prop)) { - config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop]; - } - } - - return config; - }, - - format: function (val) { - return "" + val; - }, - - defaultConfig: { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }, - - timesInWords: function timesInWords(count) { - return count == 1 && "once" || - count == 2 && "twice" || - count == 3 && "thrice" || - (count || 0) + " times"; - }, - - calledInOrder: function (spies) { - for (var i = 1, l = spies.length; i < l; i++) { - if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) { - return false; - } - } - - return true; - }, - - orderByFirstCall: function (spies) { - return spies.sort(function (a, b) { - // uuid, won't ever be equal - var aCall = a.getCall(0); - var bCall = b.getCall(0); - var aId = aCall && aCall.callId || -1; - var bId = bCall && bCall.callId || -1; - - return aId < bId ? -1 : 1; - }); - }, - - log: function () {}, - - logError: function (label, err) { - var msg = label + " threw exception: "; - sinon.log(msg + "[" + err.name + "] " + err.message); - if (err.stack) { sinon.log(err.stack); } - - setTimeout(function () { - err.message = msg + err.message; - throw err; - }, 0); - }, - - typeOf: function (value) { - if (value === null) { - return "null"; - } - else if (value === undefined) { - return "undefined"; - } - var string = Object.prototype.toString.call(value); - return string.substring(8, string.length - 1).toLowerCase(); - }, - - createStubInstance: function (constructor) { - if (typeof constructor !== "function") { - throw new TypeError("The constructor should be a function."); - } - return sinon.stub(sinon.create(constructor.prototype)); - }, - - restore: function (object) { - if (object !== null && typeof object === "object") { - for (var prop in object) { - if (isRestorable(object[prop])) { - object[prop].restore(); - } - } - } - else if (isRestorable(object)) { - object.restore(); - } - } - }; - - var isNode = typeof module !== "undefined" && module.exports; - var isAMD = typeof define === 'function' && typeof define.amd === 'object' && define.amd; - - if (isAMD) { - define(function(){ - return sinon; - }); - } else if (isNode) { - try { - formatio = require("formatio"); - } catch (e) {} - module.exports = sinon; - module.exports.spy = require("./sinon/spy"); - module.exports.spyCall = require("./sinon/call"); - module.exports.behavior = require("./sinon/behavior"); - module.exports.stub = require("./sinon/stub"); - module.exports.mock = require("./sinon/mock"); - module.exports.collection = require("./sinon/collection"); - module.exports.assert = require("./sinon/assert"); - module.exports.sandbox = require("./sinon/sandbox"); - module.exports.test = require("./sinon/test"); - module.exports.testCase = require("./sinon/test_case"); - module.exports.assert = require("./sinon/assert"); - module.exports.match = require("./sinon/match"); - } - - if (formatio) { - var formatter = formatio.configure({ quoteStrings: false }); - sinon.format = function () { - return formatter.ascii.apply(formatter, arguments); - }; - } else if (isNode) { - try { - var util = require("util"); - sinon.format = function (value) { - return typeof value == "object" && value.toString === Object.prototype.toString ? util.inspect(value) : value; - }; - } catch (e) { - /* Node, but no util module - would be very old, but better safe than - sorry */ - } - } - - return sinon; -}(typeof formatio == "object" && formatio)); - -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Minimal Event interface implementation - * - * Original implementation by Sven Fuchs: https://gist.github.com/995028 - * Modifications and tests by Christian Johansen. - * - * @author Sven Fuchs (svenfuchs@artweb-design.de) - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2011 Sven Fuchs, Christian Johansen - */ - -if (typeof sinon == "undefined") { - this.sinon = {}; -} - -(function () { - var push = [].push; - - sinon.Event = function Event(type, bubbles, cancelable, target) { - this.initEvent(type, bubbles, cancelable, target); - }; - - sinon.Event.prototype = { - initEvent: function(type, bubbles, cancelable, target) { - this.type = type; - this.bubbles = bubbles; - this.cancelable = cancelable; - this.target = target; - }, - - stopPropagation: function () {}, - - preventDefault: function () { - this.defaultPrevented = true; - } - }; - - sinon.EventTarget = { - addEventListener: function addEventListener(event, listener) { - this.eventListeners = this.eventListeners || {}; - this.eventListeners[event] = this.eventListeners[event] || []; - push.call(this.eventListeners[event], listener); - }, - - removeEventListener: function removeEventListener(event, listener) { - var listeners = this.eventListeners && this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }, - - dispatchEvent: function dispatchEvent(event) { - var type = event.type; - var listeners = this.eventListeners && this.eventListeners[type] || []; - - for (var i = 0; i < listeners.length; i++) { - if (typeof listeners[i] == "function") { - listeners[i].call(this, event); - } else { - listeners[i].handleEvent(event); - } - } - - return !!event.defaultPrevented; - } - }; -}()); - -/** - * @depend ../../sinon.js - * @depend event.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Fake XMLHttpRequest object - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -// wrapper for global -(function(global) { - if (typeof sinon === "undefined") { - global.sinon = {}; - } - - var supportsProgress = typeof ProgressEvent !== "undefined"; - var supportsCustomEvent = typeof CustomEvent !== "undefined"; - sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest }; - var xhr = sinon.xhr; - xhr.GlobalXMLHttpRequest = global.XMLHttpRequest; - xhr.GlobalActiveXObject = global.ActiveXObject; - xhr.supportsActiveX = typeof xhr.GlobalActiveXObject != "undefined"; - xhr.supportsXHR = typeof xhr.GlobalXMLHttpRequest != "undefined"; - xhr.workingXHR = xhr.supportsXHR ? xhr.GlobalXMLHttpRequest : xhr.supportsActiveX - ? function() { return new xhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0") } : false; - xhr.supportsCORS = 'withCredentials' in (new sinon.xhr.GlobalXMLHttpRequest()); - - /*jsl:ignore*/ - var unsafeHeaders = { - "Accept-Charset": true, - "Accept-Encoding": true, - "Connection": true, - "Content-Length": true, - "Cookie": true, - "Cookie2": true, - "Content-Transfer-Encoding": true, - "Date": true, - "Expect": true, - "Host": true, - "Keep-Alive": true, - "Referer": true, - "TE": true, - "Trailer": true, - "Transfer-Encoding": true, - "Upgrade": true, - "User-Agent": true, - "Via": true - }; - /*jsl:end*/ - - function FakeXMLHttpRequest() { - this.readyState = FakeXMLHttpRequest.UNSENT; - this.requestHeaders = {}; - this.requestBody = null; - this.status = 0; - this.statusText = ""; - this.upload = new UploadProgress(); - if (sinon.xhr.supportsCORS) { - this.withCredentials = false; - } - - - var xhr = this; - var events = ["loadstart", "load", "abort", "loadend"]; - - function addEventListener(eventName) { - xhr.addEventListener(eventName, function (event) { - var listener = xhr["on" + eventName]; - - if (listener && typeof listener == "function") { - listener(event); - } - }); - } - - for (var i = events.length - 1; i >= 0; i--) { - addEventListener(events[i]); - } - - if (typeof FakeXMLHttpRequest.onCreate == "function") { - FakeXMLHttpRequest.onCreate(this); - } - } - - // An upload object is created for each - // FakeXMLHttpRequest and allows upload - // events to be simulated using uploadProgress - // and uploadError. - function UploadProgress() { - this.eventListeners = { - "progress": [], - "load": [], - "abort": [], - "error": [] - } - } - - UploadProgress.prototype.addEventListener = function(event, listener) { - this.eventListeners[event].push(listener); - }; - - UploadProgress.prototype.removeEventListener = function(event, listener) { - var listeners = this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }; - - UploadProgress.prototype.dispatchEvent = function(event) { - var listeners = this.eventListeners[event.type] || []; - - for (var i = 0, listener; (listener = listeners[i]) != null; i++) { - listener(event); - } - }; - - function verifyState(xhr) { - if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { - throw new Error("INVALID_STATE_ERR"); - } - - if (xhr.sendFlag) { - throw new Error("INVALID_STATE_ERR"); - } - } - - // filtering to enable a white-list version of Sinon FakeXhr, - // where whitelisted requests are passed through to real XHR - function each(collection, callback) { - if (!collection) return; - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } - } - function some(collection, callback) { - for (var index = 0; index < collection.length; index++) { - if(callback(collection[index]) === true) return true; - } - return false; - } - // largest arity in XHR is 5 - XHR#open - var apply = function(obj,method,args) { - switch(args.length) { - case 0: return obj[method](); - case 1: return obj[method](args[0]); - case 2: return obj[method](args[0],args[1]); - case 3: return obj[method](args[0],args[1],args[2]); - case 4: return obj[method](args[0],args[1],args[2],args[3]); - case 5: return obj[method](args[0],args[1],args[2],args[3],args[4]); - } - }; - - FakeXMLHttpRequest.filters = []; - FakeXMLHttpRequest.addFilter = function(fn) { - this.filters.push(fn) - }; - var IE6Re = /MSIE 6/; - FakeXMLHttpRequest.defake = function(fakeXhr,xhrArgs) { - var xhr = new sinon.xhr.workingXHR(); - each(["open","setRequestHeader","send","abort","getResponseHeader", - "getAllResponseHeaders","addEventListener","overrideMimeType","removeEventListener"], - function(method) { - fakeXhr[method] = function() { - return apply(xhr,method,arguments); - }; - }); - - var copyAttrs = function(args) { - each(args, function(attr) { - try { - fakeXhr[attr] = xhr[attr] - } catch(e) { - if(!IE6Re.test(navigator.userAgent)) throw e; - } - }); - }; - - var stateChange = function() { - fakeXhr.readyState = xhr.readyState; - if(xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) { - copyAttrs(["status","statusText"]); - } - if(xhr.readyState >= FakeXMLHttpRequest.LOADING) { - copyAttrs(["responseText"]); - } - if(xhr.readyState === FakeXMLHttpRequest.DONE) { - copyAttrs(["responseXML"]); - } - if(fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr }); - }; - if(xhr.addEventListener) { - for(var event in fakeXhr.eventListeners) { - if(fakeXhr.eventListeners.hasOwnProperty(event)) { - each(fakeXhr.eventListeners[event],function(handler) { - xhr.addEventListener(event, handler); - }); - } - } - xhr.addEventListener("readystatechange",stateChange); - } else { - xhr.onreadystatechange = stateChange; - } - apply(xhr,"open",xhrArgs); - }; - FakeXMLHttpRequest.useFilters = false; - - function verifyRequestSent(xhr) { - if (xhr.readyState == FakeXMLHttpRequest.DONE) { - throw new Error("Request done"); - } - } - - function verifyHeadersReceived(xhr) { - if (xhr.async && xhr.readyState != FakeXMLHttpRequest.HEADERS_RECEIVED) { - throw new Error("No headers received"); - } - } - - function verifyResponseBodyType(body) { - if (typeof body != "string") { - var error = new Error("Attempted to respond to fake XMLHttpRequest with " + - body + ", which is not a string."); - error.name = "InvalidBodyException"; - throw error; - } - } - - sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { - async: true, - - open: function open(method, url, async, username, password) { - this.method = method; - this.url = url; - this.async = typeof async == "boolean" ? async : true; - this.username = username; - this.password = password; - this.responseText = null; - this.responseXML = null; - this.requestHeaders = {}; - this.sendFlag = false; - if(sinon.FakeXMLHttpRequest.useFilters === true) { - var xhrArgs = arguments; - var defake = some(FakeXMLHttpRequest.filters,function(filter) { - return filter.apply(this,xhrArgs) - }); - if (defake) { - return sinon.FakeXMLHttpRequest.defake(this,arguments); - } - } - this.readyStateChange(FakeXMLHttpRequest.OPENED); - }, - - readyStateChange: function readyStateChange(state) { - this.readyState = state; - - if (typeof this.onreadystatechange == "function") { - try { - this.onreadystatechange(); - } catch (e) { - sinon.logError("Fake XHR onreadystatechange handler", e); - } - } - - this.dispatchEvent(new sinon.Event("readystatechange")); - - switch (this.readyState) { - case FakeXMLHttpRequest.DONE: - this.dispatchEvent(new sinon.Event("load", false, false, this)); - this.dispatchEvent(new sinon.Event("loadend", false, false, this)); - this.upload.dispatchEvent(new sinon.Event("load", false, false, this)); - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", {loaded: 100, total: 100})); - } - break; - } - }, - - setRequestHeader: function setRequestHeader(header, value) { - verifyState(this); - - if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) { - throw new Error("Refused to set unsafe header \"" + header + "\""); - } - - if (this.requestHeaders[header]) { - this.requestHeaders[header] += "," + value; - } else { - this.requestHeaders[header] = value; - } - }, - - // Helps testing - setResponseHeaders: function setResponseHeaders(headers) { - this.responseHeaders = {}; - - for (var header in headers) { - if (headers.hasOwnProperty(header)) { - this.responseHeaders[header] = headers[header]; - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED); - } else { - this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED; - } - }, - - // Currently treats ALL data as a DOMString (i.e. no Document) - send: function send(data) { - verifyState(this); - - if (!/^(get|head)$/i.test(this.method)) { - if (this.requestHeaders["Content-Type"]) { - var value = this.requestHeaders["Content-Type"].split(";"); - this.requestHeaders["Content-Type"] = value[0] + ";charset=utf-8"; - } else { - this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; - } - - this.requestBody = data; - } - - this.errorFlag = false; - this.sendFlag = this.async; - this.readyStateChange(FakeXMLHttpRequest.OPENED); - - if (typeof this.onSend == "function") { - this.onSend(this); - } - - this.dispatchEvent(new sinon.Event("loadstart", false, false, this)); - }, - - abort: function abort() { - this.aborted = true; - this.responseText = null; - this.errorFlag = true; - this.requestHeaders = {}; - - if (this.readyState > sinon.FakeXMLHttpRequest.UNSENT && this.sendFlag) { - this.readyStateChange(sinon.FakeXMLHttpRequest.DONE); - this.sendFlag = false; - } - - this.readyState = sinon.FakeXMLHttpRequest.UNSENT; - - this.dispatchEvent(new sinon.Event("abort", false, false, this)); - - this.upload.dispatchEvent(new sinon.Event("abort", false, false, this)); - - if (typeof this.onerror === "function") { - this.onerror(); - } - }, - - getResponseHeader: function getResponseHeader(header) { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return null; - } - - if (/^Set-Cookie2?$/i.test(header)) { - return null; - } - - header = header.toLowerCase(); - - for (var h in this.responseHeaders) { - if (h.toLowerCase() == header) { - return this.responseHeaders[h]; - } - } - - return null; - }, - - getAllResponseHeaders: function getAllResponseHeaders() { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return ""; - } - - var headers = ""; - - for (var header in this.responseHeaders) { - if (this.responseHeaders.hasOwnProperty(header) && - !/^Set-Cookie2?$/i.test(header)) { - headers += header + ": " + this.responseHeaders[header] + "\r\n"; - } - } - - return headers; - }, - - setResponseBody: function setResponseBody(body) { - verifyRequestSent(this); - verifyHeadersReceived(this); - verifyResponseBodyType(body); - - var chunkSize = this.chunkSize || 10; - var index = 0; - this.responseText = ""; - - do { - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.LOADING); - } - - this.responseText += body.substring(index, index + chunkSize); - index += chunkSize; - } while (index < body.length); - - var type = this.getResponseHeader("Content-Type"); - - if (this.responseText && - (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) { - try { - this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText); - } catch (e) { - // Unable to parse XML - no biggie - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.DONE); - } else { - this.readyState = FakeXMLHttpRequest.DONE; - } - }, - - respond: function respond(status, headers, body) { - this.status = typeof status == "number" ? status : 200; - this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; - this.setResponseHeaders(headers || {}); - this.setResponseBody(body || ""); - }, - - uploadProgress: function uploadProgress(progressEventRaw) { - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", progressEventRaw)); - } - }, - - uploadError: function uploadError(error) { - if (supportsCustomEvent) { - this.upload.dispatchEvent(new CustomEvent("error", {"detail": error})); - } - } - }); - - sinon.extend(FakeXMLHttpRequest, { - UNSENT: 0, - OPENED: 1, - HEADERS_RECEIVED: 2, - LOADING: 3, - DONE: 4 - }); - - // Borrowed from JSpec - FakeXMLHttpRequest.parseXML = function parseXML(text) { - var xmlDoc; - - if (typeof DOMParser != "undefined") { - var parser = new DOMParser(); - xmlDoc = parser.parseFromString(text, "text/xml"); - } else { - xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); - xmlDoc.async = "false"; - xmlDoc.loadXML(text); - } - - return xmlDoc; - }; - - FakeXMLHttpRequest.statusCodes = { - 100: "Continue", - 101: "Switching Protocols", - 200: "OK", - 201: "Created", - 202: "Accepted", - 203: "Non-Authoritative Information", - 204: "No Content", - 205: "Reset Content", - 206: "Partial Content", - 300: "Multiple Choice", - 301: "Moved Permanently", - 302: "Found", - 303: "See Other", - 304: "Not Modified", - 305: "Use Proxy", - 307: "Temporary Redirect", - 400: "Bad Request", - 401: "Unauthorized", - 402: "Payment Required", - 403: "Forbidden", - 404: "Not Found", - 405: "Method Not Allowed", - 406: "Not Acceptable", - 407: "Proxy Authentication Required", - 408: "Request Timeout", - 409: "Conflict", - 410: "Gone", - 411: "Length Required", - 412: "Precondition Failed", - 413: "Request Entity Too Large", - 414: "Request-URI Too Long", - 415: "Unsupported Media Type", - 416: "Requested Range Not Satisfiable", - 417: "Expectation Failed", - 422: "Unprocessable Entity", - 500: "Internal Server Error", - 501: "Not Implemented", - 502: "Bad Gateway", - 503: "Service Unavailable", - 504: "Gateway Timeout", - 505: "HTTP Version Not Supported" - }; - - sinon.useFakeXMLHttpRequest = function () { - sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) { - if (xhr.supportsXHR) { - global.XMLHttpRequest = xhr.GlobalXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = xhr.GlobalActiveXObject; - } - - delete sinon.FakeXMLHttpRequest.restore; - - if (keepOnCreate !== true) { - delete sinon.FakeXMLHttpRequest.onCreate; - } - }; - if (xhr.supportsXHR) { - global.XMLHttpRequest = sinon.FakeXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = function ActiveXObject(objId) { - if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { - - return new sinon.FakeXMLHttpRequest(); - } - - return new xhr.GlobalActiveXObject(objId); - }; - } - - return sinon.FakeXMLHttpRequest; - }; - - sinon.FakeXMLHttpRequest = FakeXMLHttpRequest; - -})(typeof global === "object" ? global : this); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_xml_http_request.js - */ -/*jslint eqeqeq: false, onevar: false, regexp: false, plusplus: false*/ -/*global module, require, window*/ -/** - * The Sinon "server" mimics a web server that receives requests from - * sinon.FakeXMLHttpRequest and provides an API to respond to those requests, - * both synchronously and asynchronously. To respond synchronuously, canned - * answers have to be provided upfront. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -sinon.fakeServer = (function () { - var push = [].push; - function F() {} - - function create(proto) { - F.prototype = proto; - return new F(); - } - - function responseArray(handler) { - var response = handler; - - if (Object.prototype.toString.call(handler) != "[object Array]") { - response = [200, {}, handler]; - } - - if (typeof response[2] != "string") { - throw new TypeError("Fake server response body should be string, but was " + - typeof response[2]); - } - - return response; - } - - var wloc = typeof window !== "undefined" ? window.location : {}; - var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host); - - function matchOne(response, reqMethod, reqUrl) { - var rmeth = response.method; - var matchMethod = !rmeth || rmeth.toLowerCase() == reqMethod.toLowerCase(); - var url = response.url; - var matchUrl = !url || url == reqUrl || (typeof url.test == "function" && url.test(reqUrl)); - - return matchMethod && matchUrl; - } - - function match(response, request) { - var requestUrl = request.url; - - if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) { - requestUrl = requestUrl.replace(rCurrLoc, ""); - } - - if (matchOne(response, this.getHTTPMethod(request), requestUrl)) { - if (typeof response.response == "function") { - var ru = response.url; - var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []); - return response.response.apply(response, args); - } - - return true; - } - - return false; - } - - function log(response, request) { - var str; - - str = "Request:\n" + sinon.format(request) + "\n\n"; - str += "Response:\n" + sinon.format(response) + "\n\n"; - - sinon.log(str); - } - - return { - create: function () { - var server = create(this); - this.xhr = sinon.useFakeXMLHttpRequest(); - server.requests = []; - - this.xhr.onCreate = function (xhrObj) { - server.addRequest(xhrObj); - }; - - return server; - }, - - addRequest: function addRequest(xhrObj) { - var server = this; - push.call(this.requests, xhrObj); - - xhrObj.onSend = function () { - server.handleRequest(this); - - if (server.autoRespond && !server.responding) { - setTimeout(function () { - server.responding = false; - server.respond(); - }, server.autoRespondAfter || 10); - - server.responding = true; - } - }; - }, - - getHTTPMethod: function getHTTPMethod(request) { - if (this.fakeHTTPMethods && /post/i.test(request.method)) { - var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); - return !!matches ? matches[1] : request.method; - } - - return request.method; - }, - - handleRequest: function handleRequest(xhr) { - if (xhr.async) { - if (!this.queue) { - this.queue = []; - } - - push.call(this.queue, xhr); - } else { - this.processRequest(xhr); - } - }, - - respondWith: function respondWith(method, url, body) { - if (arguments.length == 1 && typeof method != "function") { - this.response = responseArray(method); - return; - } - - if (!this.responses) { this.responses = []; } - - if (arguments.length == 1) { - body = method; - url = method = null; - } - - if (arguments.length == 2) { - body = url; - url = method; - method = null; - } - - push.call(this.responses, { - method: method, - url: url, - response: typeof body == "function" ? body : responseArray(body) - }); - }, - - respond: function respond() { - if (arguments.length > 0) this.respondWith.apply(this, arguments); - var queue = this.queue || []; - var requests = queue.splice(0); - var request; - - while(request = requests.shift()) { - this.processRequest(request); - } - }, - - processRequest: function processRequest(request) { - try { - if (request.aborted) { - return; - } - - var response = this.response || [404, {}, ""]; - - if (this.responses) { - for (var l = this.responses.length, i = l - 1; i >= 0; i--) { - if (match.call(this, this.responses[i], request)) { - response = this.responses[i].response; - break; - } - } - } - - if (request.readyState != 4) { - log(response, request); - - request.respond(response[0], response[1], response[2]); - } - } catch (e) { - sinon.logError("Fake server request processing", e); - } - }, - - restore: function restore() { - return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments); - } - }; -}()); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ -/*global module, require, window*/ -/** - * Fake timer API - * setTimeout - * setInterval - * clearTimeout - * clearInterval - * tick - * reset - * Date - * - * Inspired by jsUnitMockTimeOut from JsUnit - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -(function (global) { - var id = 1; - - function addTimer(args, recurring) { - if (args.length === 0) { - throw new Error("Function requires at least 1 parameter"); - } - - if (typeof args[0] === "undefined") { - throw new Error("Callback must be provided to timer calls"); - } - - var toId = id++; - var delay = args[1] || 0; - - if (!this.timeouts) { - this.timeouts = {}; - } - - this.timeouts[toId] = { - id: toId, - func: args[0], - callAt: this.now + delay, - invokeArgs: Array.prototype.slice.call(args, 2) - }; - - if (recurring === true) { - this.timeouts[toId].interval = delay; - } - - return toId; - } - - function parseTime(str) { - if (!str) { - return 0; - } - - var strings = str.split(":"); - var l = strings.length, i = l; - var ms = 0, parsed; - - if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { - throw new Error("tick only understands numbers and 'h:m:s'"); - } - - while (i--) { - parsed = parseInt(strings[i], 10); - - if (parsed >= 60) { - throw new Error("Invalid time " + str); - } - - ms += parsed * Math.pow(60, (l - i - 1)); - } - - return ms * 1000; - } - - function createObject(object) { - var newObject; - - if (Object.create) { - newObject = Object.create(object); - } else { - var F = function () {}; - F.prototype = object; - newObject = new F(); - } - - newObject.Date.clock = newObject; - return newObject; - } - - sinon.clock = { - now: 0, - - create: function create(now) { - var clock = createObject(this); - - if (typeof now == "number") { - clock.now = now; - } - - if (!!now && typeof now == "object") { - throw new TypeError("now should be milliseconds since UNIX epoch"); - } - - return clock; - }, - - setTimeout: function setTimeout(callback, timeout) { - return addTimer.call(this, arguments, false); - }, - - clearTimeout: function clearTimeout(timerId) { - if (!this.timeouts) { - this.timeouts = []; - } - - if (timerId in this.timeouts) { - delete this.timeouts[timerId]; - } - }, - - setInterval: function setInterval(callback, timeout) { - return addTimer.call(this, arguments, true); - }, - - clearInterval: function clearInterval(timerId) { - this.clearTimeout(timerId); - }, - - setImmediate: function setImmediate(callback) { - var passThruArgs = Array.prototype.slice.call(arguments, 1); - - return addTimer.call(this, [callback, 0].concat(passThruArgs), false); - }, - - clearImmediate: function clearImmediate(timerId) { - this.clearTimeout(timerId); - }, - - tick: function tick(ms) { - ms = typeof ms == "number" ? ms : parseTime(ms); - var tickFrom = this.now, tickTo = this.now + ms, previous = this.now; - var timer = this.firstTimerInRange(tickFrom, tickTo); - - var firstException; - while (timer && tickFrom <= tickTo) { - if (this.timeouts[timer.id]) { - tickFrom = this.now = timer.callAt; - try { - this.callTimer(timer); - } catch (e) { - firstException = firstException || e; - } - } - - timer = this.firstTimerInRange(previous, tickTo); - previous = tickFrom; - } - - this.now = tickTo; - - if (firstException) { - throw firstException; - } - - return this.now; - }, - - firstTimerInRange: function (from, to) { - var timer, smallest = null, originalTimer; - - for (var id in this.timeouts) { - if (this.timeouts.hasOwnProperty(id)) { - if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) { - continue; - } - - if (smallest === null || this.timeouts[id].callAt < smallest) { - originalTimer = this.timeouts[id]; - smallest = this.timeouts[id].callAt; - - timer = { - func: this.timeouts[id].func, - callAt: this.timeouts[id].callAt, - interval: this.timeouts[id].interval, - id: this.timeouts[id].id, - invokeArgs: this.timeouts[id].invokeArgs - }; - } - } - } - - return timer || null; - }, - - callTimer: function (timer) { - if (typeof timer.interval == "number") { - this.timeouts[timer.id].callAt += timer.interval; - } else { - delete this.timeouts[timer.id]; - } - - try { - if (typeof timer.func == "function") { - timer.func.apply(null, timer.invokeArgs); - } else { - eval(timer.func); - } - } catch (e) { - var exception = e; - } - - if (!this.timeouts[timer.id]) { - if (exception) { - throw exception; - } - return; - } - - if (exception) { - throw exception; - } - }, - - reset: function reset() { - this.timeouts = {}; - }, - - Date: (function () { - var NativeDate = Date; - - function ClockDate(year, month, date, hour, minute, second, ms) { - // Defensive and verbose to avoid potential harm in passing - // explicit undefined when user does not pass argument - switch (arguments.length) { - case 0: - return new NativeDate(ClockDate.clock.now); - case 1: - return new NativeDate(year); - case 2: - return new NativeDate(year, month); - case 3: - return new NativeDate(year, month, date); - case 4: - return new NativeDate(year, month, date, hour); - case 5: - return new NativeDate(year, month, date, hour, minute); - case 6: - return new NativeDate(year, month, date, hour, minute, second); - default: - return new NativeDate(year, month, date, hour, minute, second, ms); - } - } - - return mirrorDateProperties(ClockDate, NativeDate); - }()) - }; - - function mirrorDateProperties(target, source) { - if (source.now) { - target.now = function now() { - return target.clock.now; - }; - } else { - delete target.now; - } - - if (source.toSource) { - target.toSource = function toSource() { - return source.toSource(); - }; - } else { - delete target.toSource; - } - - target.toString = function toString() { - return source.toString(); - }; - - target.prototype = source.prototype; - target.parse = source.parse; - target.UTC = source.UTC; - target.prototype.toUTCString = source.prototype.toUTCString; - - for (var prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - - return target; - } - - var methods = ["Date", "setTimeout", "setInterval", - "clearTimeout", "clearInterval"]; - - if (typeof global.setImmediate !== "undefined") { - methods.push("setImmediate"); - } - - if (typeof global.clearImmediate !== "undefined") { - methods.push("clearImmediate"); - } - - function restore() { - var method; - - for (var i = 0, l = this.methods.length; i < l; i++) { - method = this.methods[i]; - - if (global[method].hadOwnProperty) { - global[method] = this["_" + method]; - } else { - try { - delete global[method]; - } catch (e) {} - } - } - - // Prevent multiple executions which will completely remove these props - this.methods = []; - } - - function stubGlobal(method, clock) { - clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method); - clock["_" + method] = global[method]; - - if (method == "Date") { - var date = mirrorDateProperties(clock[method], global[method]); - global[method] = date; - } else { - global[method] = function () { - return clock[method].apply(clock, arguments); - }; - - for (var prop in clock[method]) { - if (clock[method].hasOwnProperty(prop)) { - global[method][prop] = clock[method][prop]; - } - } - } - - global[method].clock = clock; - } - - sinon.useFakeTimers = function useFakeTimers(now) { - var clock = sinon.clock.create(now); - clock.restore = restore; - clock.methods = Array.prototype.slice.call(arguments, - typeof now == "number" ? 1 : 0); - - if (clock.methods.length === 0) { - clock.methods = methods; - } - - for (var i = 0, l = clock.methods.length; i < l; i++) { - stubGlobal(clock.methods[i], clock); - } - - return clock; - }; -}(typeof global != "undefined" && typeof global !== "function" ? global : this)); - -sinon.timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined), - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date -}; - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_server.js - * @depend fake_timers.js - */ -/*jslint browser: true, eqeqeq: false, onevar: false*/ -/*global sinon*/ -/** - * Add-on for sinon.fakeServer that automatically handles a fake timer along with - * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery - * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead, - * it polls the object for completion with setInterval. Dispite the direct - * motivation, there is nothing jQuery-specific in this file, so it can be used - * in any environment where the ajax implementation depends on setInterval or - * setTimeout. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function () { - function Server() {} - Server.prototype = sinon.fakeServer; - - sinon.fakeServerWithClock = new Server(); - - sinon.fakeServerWithClock.addRequest = function addRequest(xhr) { - if (xhr.async) { - if (typeof setTimeout.clock == "object") { - this.clock = setTimeout.clock; - } else { - this.clock = sinon.useFakeTimers(); - this.resetClock = true; - } - - if (!this.longestTimeout) { - var clockSetTimeout = this.clock.setTimeout; - var clockSetInterval = this.clock.setInterval; - var server = this; - - this.clock.setTimeout = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetTimeout.apply(this, arguments); - }; - - this.clock.setInterval = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetInterval.apply(this, arguments); - }; - } - } - - return sinon.fakeServer.addRequest.call(this, xhr); - }; - - sinon.fakeServerWithClock.respond = function respond() { - var returnVal = sinon.fakeServer.respond.apply(this, arguments); - - if (this.clock) { - this.clock.tick(this.longestTimeout || 0); - this.longestTimeout = 0; - - if (this.resetClock) { - this.clock.restore(); - this.resetClock = false; - } - } - - return returnVal; - }; - - sinon.fakeServerWithClock.restore = function restore() { - if (this.clock) { - this.clock.restore(); - } - - return sinon.fakeServer.restore.apply(this, arguments); - }; -}()); - diff --git a/test/utils/sinon/sinon-timers-1.8.2.js b/test/utils/sinon/sinon-timers-1.8.2.js deleted file mode 100644 index b08f5c03bee30..0000000000000 --- a/test/utils/sinon/sinon-timers-1.8.2.js +++ /dev/null @@ -1,419 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ -/*global module, require, window*/ -/** - * Fake timer API - * setTimeout - * setInterval - * clearTimeout - * clearInterval - * tick - * reset - * Date - * - * Inspired by jsUnitMockTimeOut from JsUnit - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -(function (global) { - var id = 1; - - function addTimer(args, recurring) { - if (args.length === 0) { - throw new Error("Function requires at least 1 parameter"); - } - - if (typeof args[0] === "undefined") { - throw new Error("Callback must be provided to timer calls"); - } - - var toId = id++; - var delay = args[1] || 0; - - if (!this.timeouts) { - this.timeouts = {}; - } - - this.timeouts[toId] = { - id: toId, - func: args[0], - callAt: this.now + delay, - invokeArgs: Array.prototype.slice.call(args, 2) - }; - - if (recurring === true) { - this.timeouts[toId].interval = delay; - } - - return toId; - } - - function parseTime(str) { - if (!str) { - return 0; - } - - var strings = str.split(":"); - var l = strings.length, i = l; - var ms = 0, parsed; - - if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { - throw new Error("tick only understands numbers and 'h:m:s'"); - } - - while (i--) { - parsed = parseInt(strings[i], 10); - - if (parsed >= 60) { - throw new Error("Invalid time " + str); - } - - ms += parsed * Math.pow(60, (l - i - 1)); - } - - return ms * 1000; - } - - function createObject(object) { - var newObject; - - if (Object.create) { - newObject = Object.create(object); - } else { - var F = function () {}; - F.prototype = object; - newObject = new F(); - } - - newObject.Date.clock = newObject; - return newObject; - } - - sinon.clock = { - now: 0, - - create: function create(now) { - var clock = createObject(this); - - if (typeof now == "number") { - clock.now = now; - } - - if (!!now && typeof now == "object") { - throw new TypeError("now should be milliseconds since UNIX epoch"); - } - - return clock; - }, - - setTimeout: function setTimeout(callback, timeout) { - return addTimer.call(this, arguments, false); - }, - - clearTimeout: function clearTimeout(timerId) { - if (!this.timeouts) { - this.timeouts = []; - } - - if (timerId in this.timeouts) { - delete this.timeouts[timerId]; - } - }, - - setInterval: function setInterval(callback, timeout) { - return addTimer.call(this, arguments, true); - }, - - clearInterval: function clearInterval(timerId) { - this.clearTimeout(timerId); - }, - - setImmediate: function setImmediate(callback) { - var passThruArgs = Array.prototype.slice.call(arguments, 1); - - return addTimer.call(this, [callback, 0].concat(passThruArgs), false); - }, - - clearImmediate: function clearImmediate(timerId) { - this.clearTimeout(timerId); - }, - - tick: function tick(ms) { - ms = typeof ms == "number" ? ms : parseTime(ms); - var tickFrom = this.now, tickTo = this.now + ms, previous = this.now; - var timer = this.firstTimerInRange(tickFrom, tickTo); - - var firstException; - while (timer && tickFrom <= tickTo) { - if (this.timeouts[timer.id]) { - tickFrom = this.now = timer.callAt; - try { - this.callTimer(timer); - } catch (e) { - firstException = firstException || e; - } - } - - timer = this.firstTimerInRange(previous, tickTo); - previous = tickFrom; - } - - this.now = tickTo; - - if (firstException) { - throw firstException; - } - - return this.now; - }, - - firstTimerInRange: function (from, to) { - var timer, smallest = null, originalTimer; - - for (var id in this.timeouts) { - if (this.timeouts.hasOwnProperty(id)) { - if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) { - continue; - } - - if (smallest === null || this.timeouts[id].callAt < smallest) { - originalTimer = this.timeouts[id]; - smallest = this.timeouts[id].callAt; - - timer = { - func: this.timeouts[id].func, - callAt: this.timeouts[id].callAt, - interval: this.timeouts[id].interval, - id: this.timeouts[id].id, - invokeArgs: this.timeouts[id].invokeArgs - }; - } - } - } - - return timer || null; - }, - - callTimer: function (timer) { - if (typeof timer.interval == "number") { - this.timeouts[timer.id].callAt += timer.interval; - } else { - delete this.timeouts[timer.id]; - } - - try { - if (typeof timer.func == "function") { - timer.func.apply(null, timer.invokeArgs); - } else { - eval(timer.func); - } - } catch (e) { - var exception = e; - } - - if (!this.timeouts[timer.id]) { - if (exception) { - throw exception; - } - return; - } - - if (exception) { - throw exception; - } - }, - - reset: function reset() { - this.timeouts = {}; - }, - - Date: (function () { - var NativeDate = Date; - - function ClockDate(year, month, date, hour, minute, second, ms) { - // Defensive and verbose to avoid potential harm in passing - // explicit undefined when user does not pass argument - switch (arguments.length) { - case 0: - return new NativeDate(ClockDate.clock.now); - case 1: - return new NativeDate(year); - case 2: - return new NativeDate(year, month); - case 3: - return new NativeDate(year, month, date); - case 4: - return new NativeDate(year, month, date, hour); - case 5: - return new NativeDate(year, month, date, hour, minute); - case 6: - return new NativeDate(year, month, date, hour, minute, second); - default: - return new NativeDate(year, month, date, hour, minute, second, ms); - } - } - - return mirrorDateProperties(ClockDate, NativeDate); - }()) - }; - - function mirrorDateProperties(target, source) { - if (source.now) { - target.now = function now() { - return target.clock.now; - }; - } else { - delete target.now; - } - - if (source.toSource) { - target.toSource = function toSource() { - return source.toSource(); - }; - } else { - delete target.toSource; - } - - target.toString = function toString() { - return source.toString(); - }; - - target.prototype = source.prototype; - target.parse = source.parse; - target.UTC = source.UTC; - target.prototype.toUTCString = source.prototype.toUTCString; - - for (var prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - - return target; - } - - var methods = ["Date", "setTimeout", "setInterval", - "clearTimeout", "clearInterval"]; - - if (typeof global.setImmediate !== "undefined") { - methods.push("setImmediate"); - } - - if (typeof global.clearImmediate !== "undefined") { - methods.push("clearImmediate"); - } - - function restore() { - var method; - - for (var i = 0, l = this.methods.length; i < l; i++) { - method = this.methods[i]; - - if (global[method].hadOwnProperty) { - global[method] = this["_" + method]; - } else { - try { - delete global[method]; - } catch (e) {} - } - } - - // Prevent multiple executions which will completely remove these props - this.methods = []; - } - - function stubGlobal(method, clock) { - clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method); - clock["_" + method] = global[method]; - - if (method == "Date") { - var date = mirrorDateProperties(clock[method], global[method]); - global[method] = date; - } else { - global[method] = function () { - return clock[method].apply(clock, arguments); - }; - - for (var prop in clock[method]) { - if (clock[method].hasOwnProperty(prop)) { - global[method][prop] = clock[method][prop]; - } - } - } - - global[method].clock = clock; - } - - sinon.useFakeTimers = function useFakeTimers(now) { - var clock = sinon.clock.create(now); - clock.restore = restore; - clock.methods = Array.prototype.slice.call(arguments, - typeof now == "number" ? 1 : 0); - - if (clock.methods.length === 0) { - clock.methods = methods; - } - - for (var i = 0, l = clock.methods.length; i < l; i++) { - stubGlobal(clock.methods[i], clock); - } - - return clock; - }; -}(typeof global != "undefined" && typeof global !== "function" ? global : this)); - -sinon.timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined), - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date -}; - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} diff --git a/test/utils/sinon/sinon-timers-ie-1.8.2.js b/test/utils/sinon/sinon-timers-ie-1.8.2.js deleted file mode 100644 index 5a7509a91a85c..0000000000000 --- a/test/utils/sinon/sinon-timers-ie-1.8.2.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/ -/** - * Helps IE run the fake timers. By defining global functions, IE allows - * them to be overwritten at a later point. If these are not defined like - * this, overwriting them will result in anything from an exception to browser - * crash. - * - * If you don't require fake timers to work in IE, don't include this file. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -function setTimeout() {} -function clearTimeout() {} -function setImmediate() {} -function clearImmediate() {} -function setInterval() {} -function clearInterval() {} -function Date() {} - -// Reassign the original functions. Now their writable attribute -// should be true. Hackish, I know, but it works. -setTimeout = sinon.timers.setTimeout; -clearTimeout = sinon.timers.clearTimeout; -setImmediate = sinon.timers.setImmediate; -clearImmediate = sinon.timers.clearImmediate; -setInterval = sinon.timers.setInterval; -clearInterval = sinon.timers.clearInterval; -Date = sinon.timers.Date; diff --git a/test/utils/sinon/sinon.js b/test/utils/sinon/sinon.js deleted file mode 100644 index 657ee9e957d74..0000000000000 --- a/test/utils/sinon/sinon.js +++ /dev/null @@ -1,4728 +0,0 @@ -/** - * Sinon.JS 1.8.2, 2014/02/13 - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS - * - * (The BSD License) - * - * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Christian Johansen nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -this.sinon = (function () { -var samsam, formatio; -function define(mod, deps, fn) { if (mod == "samsam") { samsam = deps(); } else { formatio = fn(samsam); } } -define.amd = true; -((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) || - (typeof module === "object" && - function (m) { module.exports = m(); }) || // Node - function (m) { this.samsam = m(); } // Browser globals -)(function () { - var o = Object.prototype; - var div = typeof document !== "undefined" && document.createElement("div"); - - function isNaN(value) { - // Unlike global isNaN, this avoids type coercion - // typeof check avoids IE host object issues, hat tip to - // lodash - var val = value; // JsLint thinks value !== value is "weird" - return typeof value === "number" && value !== val; - } - - function getClass(value) { - // Returns the internal [[Class]] by calling Object.prototype.toString - // with the provided value as this. Return value is a string, naming the - // internal class, e.g. "Array" - return o.toString.call(value).split(/[ \]]/)[1]; - } - - /** - * @name samsam.isArguments - * @param Object object - * - * Returns ``true`` if ``object`` is an ``arguments`` object, - * ``false`` otherwise. - */ - function isArguments(object) { - if (typeof object !== "object" || typeof object.length !== "number" || - getClass(object) === "Array") { - return false; - } - if (typeof object.callee == "function") { return true; } - try { - object[object.length] = 6; - delete object[object.length]; - } catch (e) { - return true; - } - return false; - } - - /** - * @name samsam.isElement - * @param Object object - * - * Returns ``true`` if ``object`` is a DOM element node. Unlike - * Underscore.js/lodash, this function will return ``false`` if ``object`` - * is an *element-like* object, i.e. a regular object with a ``nodeType`` - * property that holds the value ``1``. - */ - function isElement(object) { - if (!object || object.nodeType !== 1 || !div) { return false; } - try { - object.appendChild(div); - object.removeChild(div); - } catch (e) { - return false; - } - return true; - } - - /** - * @name samsam.keys - * @param Object object - * - * Return an array of own property names. - */ - function keys(object) { - var ks = [], prop; - for (prop in object) { - if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); } - } - return ks; - } - - /** - * @name samsam.isDate - * @param Object value - * - * Returns true if the object is a ``Date``, or *date-like*. Duck typing - * of date objects work by checking that the object has a ``getTime`` - * function whose return value equals the return value from the object's - * ``valueOf``. - */ - function isDate(value) { - return typeof value.getTime == "function" && - value.getTime() == value.valueOf(); - } - - /** - * @name samsam.isNegZero - * @param Object value - * - * Returns ``true`` if ``value`` is ``-0``. - */ - function isNegZero(value) { - return value === 0 && 1 / value === -Infinity; - } - - /** - * @name samsam.equal - * @param Object obj1 - * @param Object obj2 - * - * Returns ``true`` if two objects are strictly equal. Compared to - * ``===`` there are two exceptions: - * - * - NaN is considered equal to NaN - * - -0 and +0 are not considered equal - */ - function identical(obj1, obj2) { - if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) { - return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2); - } - } - - - /** - * @name samsam.deepEqual - * @param Object obj1 - * @param Object obj2 - * - * Deep equal comparison. Two values are "deep equal" if: - * - * - They are equal, according to samsam.identical - * - They are both date objects representing the same time - * - They are both arrays containing elements that are all deepEqual - * - They are objects with the same set of properties, and each property - * in ``obj1`` is deepEqual to the corresponding property in ``obj2`` - * - * Supports cyclic objects. - */ - function deepEqualCyclic(obj1, obj2) { - - // used for cyclic comparison - // contain already visited objects - var objects1 = [], - objects2 = [], - // contain pathes (position in the object structure) - // of the already visited objects - // indexes same as in objects arrays - paths1 = [], - paths2 = [], - // contains combinations of already compared objects - // in the manner: { "$1['ref']$2['ref']": true } - compared = {}; - - /** - * used to check, if the value of a property is an object - * (cyclic logic is only needed for objects) - * only needed for cyclic logic - */ - function isObject(value) { - - if (typeof value === 'object' && value !== null && - !(value instanceof Boolean) && - !(value instanceof Date) && - !(value instanceof Number) && - !(value instanceof RegExp) && - !(value instanceof String)) { - - return true; - } - - return false; - } - - /** - * returns the index of the given object in the - * given objects array, -1 if not contained - * only needed for cyclic logic - */ - function getIndex(objects, obj) { - - var i; - for (i = 0; i < objects.length; i++) { - if (objects[i] === obj) { - return i; - } - } - - return -1; - } - - // does the recursion for the deep equal check - return (function deepEqual(obj1, obj2, path1, path2) { - var type1 = typeof obj1; - var type2 = typeof obj2; - - // == null also matches undefined - if (obj1 === obj2 || - isNaN(obj1) || isNaN(obj2) || - obj1 == null || obj2 == null || - type1 !== "object" || type2 !== "object") { - - return identical(obj1, obj2); - } - - // Elements are only equal if identical(expected, actual) - if (isElement(obj1) || isElement(obj2)) { return false; } - - var isDate1 = isDate(obj1), isDate2 = isDate(obj2); - if (isDate1 || isDate2) { - if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) { - return false; - } - } - - if (obj1 instanceof RegExp && obj2 instanceof RegExp) { - if (obj1.toString() !== obj2.toString()) { return false; } - } - - var class1 = getClass(obj1); - var class2 = getClass(obj2); - var keys1 = keys(obj1); - var keys2 = keys(obj2); - - if (isArguments(obj1) || isArguments(obj2)) { - if (obj1.length !== obj2.length) { return false; } - } else { - if (type1 !== type2 || class1 !== class2 || - keys1.length !== keys2.length) { - return false; - } - } - - var key, i, l, - // following vars are used for the cyclic logic - value1, value2, - isObject1, isObject2, - index1, index2, - newPath1, newPath2; - - for (i = 0, l = keys1.length; i < l; i++) { - key = keys1[i]; - if (!o.hasOwnProperty.call(obj2, key)) { - return false; - } - - // Start of the cyclic logic - - value1 = obj1[key]; - value2 = obj2[key]; - - isObject1 = isObject(value1); - isObject2 = isObject(value2); - - // determine, if the objects were already visited - // (it's faster to check for isObject first, than to - // get -1 from getIndex for non objects) - index1 = isObject1 ? getIndex(objects1, value1) : -1; - index2 = isObject2 ? getIndex(objects2, value2) : -1; - - // determine the new pathes of the objects - // - for non cyclic objects the current path will be extended - // by current property name - // - for cyclic objects the stored path is taken - newPath1 = index1 !== -1 - ? paths1[index1] - : path1 + '[' + JSON.stringify(key) + ']'; - newPath2 = index2 !== -1 - ? paths2[index2] - : path2 + '[' + JSON.stringify(key) + ']'; - - // stop recursion if current objects are already compared - if (compared[newPath1 + newPath2]) { - return true; - } - - // remember the current objects and their pathes - if (index1 === -1 && isObject1) { - objects1.push(value1); - paths1.push(newPath1); - } - if (index2 === -1 && isObject2) { - objects2.push(value2); - paths2.push(newPath2); - } - - // remember that the current objects are already compared - if (isObject1 && isObject2) { - compared[newPath1 + newPath2] = true; - } - - // End of cyclic logic - - // neither value1 nor value2 is a cycle - // continue with next level - if (!deepEqual(value1, value2, newPath1, newPath2)) { - return false; - } - } - - return true; - - }(obj1, obj2, '$1', '$2')); - } - - var match; - - function arrayContains(array, subset) { - if (subset.length === 0) { return true; } - var i, l, j, k; - for (i = 0, l = array.length; i < l; ++i) { - if (match(array[i], subset[0])) { - for (j = 0, k = subset.length; j < k; ++j) { - if (!match(array[i + j], subset[j])) { return false; } - } - return true; - } - } - return false; - } - - /** - * @name samsam.match - * @param Object object - * @param Object matcher - * - * Compare arbitrary value ``object`` with matcher. - */ - match = function match(object, matcher) { - if (matcher && typeof matcher.test === "function") { - return matcher.test(object); - } - - if (typeof matcher === "function") { - return matcher(object) === true; - } - - if (typeof matcher === "string") { - matcher = matcher.toLowerCase(); - var notNull = typeof object === "string" || !!object; - return notNull && - (String(object)).toLowerCase().indexOf(matcher) >= 0; - } - - if (typeof matcher === "number") { - return matcher === object; - } - - if (typeof matcher === "boolean") { - return matcher === object; - } - - if (getClass(object) === "Array" && getClass(matcher) === "Array") { - return arrayContains(object, matcher); - } - - if (matcher && typeof matcher === "object") { - var prop; - for (prop in matcher) { - if (!match(object[prop], matcher[prop])) { - return false; - } - } - return true; - } - - throw new Error("Matcher was not a string, a number, a " + - "function, a boolean or an object"); - }; - - return { - isArguments: isArguments, - isElement: isElement, - isDate: isDate, - isNegZero: isNegZero, - identical: identical, - deepEqual: deepEqualCyclic, - match: match, - keys: keys - }; -}); -((typeof define === "function" && define.amd && function (m) { - define("formatio", ["samsam"], m); -}) || (typeof module === "object" && function (m) { - module.exports = m(require("samsam")); -}) || function (m) { this.formatio = m(this.samsam); } -)(function (samsam) { - - var formatio = { - excludeConstructors: ["Object", /^.$/], - quoteStrings: true - }; - - var hasOwn = Object.prototype.hasOwnProperty; - - var specialObjects = []; - if (typeof global !== "undefined") { - specialObjects.push({ object: global, value: "[object global]" }); - } - if (typeof document !== "undefined") { - specialObjects.push({ - object: document, - value: "[object HTMLDocument]" - }); - } - if (typeof window !== "undefined") { - specialObjects.push({ object: window, value: "[object Window]" }); - } - - function functionName(func) { - if (!func) { return ""; } - if (func.displayName) { return func.displayName; } - if (func.name) { return func.name; } - var matches = func.toString().match(/function\s+([^\(]+)/m); - return (matches && matches[1]) || ""; - } - - function constructorName(f, object) { - var name = functionName(object && object.constructor); - var excludes = f.excludeConstructors || - formatio.excludeConstructors || []; - - var i, l; - for (i = 0, l = excludes.length; i < l; ++i) { - if (typeof excludes[i] === "string" && excludes[i] === name) { - return ""; - } else if (excludes[i].test && excludes[i].test(name)) { - return ""; - } - } - - return name; - } - - function isCircular(object, objects) { - if (typeof object !== "object") { return false; } - var i, l; - for (i = 0, l = objects.length; i < l; ++i) { - if (objects[i] === object) { return true; } - } - return false; - } - - function ascii(f, object, processed, indent) { - if (typeof object === "string") { - var qs = f.quoteStrings; - var quote = typeof qs !== "boolean" || qs; - return processed || quote ? '"' + object + '"' : object; - } - - if (typeof object === "function" && !(object instanceof RegExp)) { - return ascii.func(object); - } - - processed = processed || []; - - if (isCircular(object, processed)) { return "[Circular]"; } - - if (Object.prototype.toString.call(object) === "[object Array]") { - return ascii.array.call(f, object, processed); - } - - if (!object) { return String((1/object) === -Infinity ? "-0" : object); } - if (samsam.isElement(object)) { return ascii.element(object); } - - if (typeof object.toString === "function" && - object.toString !== Object.prototype.toString) { - return object.toString(); - } - - var i, l; - for (i = 0, l = specialObjects.length; i < l; i++) { - if (object === specialObjects[i].object) { - return specialObjects[i].value; - } - } - - return ascii.object.call(f, object, processed, indent); - } - - ascii.func = function (func) { - return "function " + functionName(func) + "() {}"; - }; - - ascii.array = function (array, processed) { - processed = processed || []; - processed.push(array); - var i, l, pieces = []; - for (i = 0, l = array.length; i < l; ++i) { - pieces.push(ascii(this, array[i], processed)); - } - return "[" + pieces.join(", ") + "]"; - }; - - ascii.object = function (object, processed, indent) { - processed = processed || []; - processed.push(object); - indent = indent || 0; - var pieces = [], properties = samsam.keys(object).sort(); - var length = 3; - var prop, str, obj, i, l; - - for (i = 0, l = properties.length; i < l; ++i) { - prop = properties[i]; - obj = object[prop]; - - if (isCircular(obj, processed)) { - str = "[Circular]"; - } else { - str = ascii(this, obj, processed, indent + 2); - } - - str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str; - length += str.length; - pieces.push(str); - } - - var cons = constructorName(this, object); - var prefix = cons ? "[" + cons + "] " : ""; - var is = ""; - for (i = 0, l = indent; i < l; ++i) { is += " "; } - - if (length + indent > 80) { - return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + - is + "}"; - } - return prefix + "{ " + pieces.join(", ") + " }"; - }; - - ascii.element = function (element) { - var tagName = element.tagName.toLowerCase(); - var attrs = element.attributes, attr, pairs = [], attrName, i, l, val; - - for (i = 0, l = attrs.length; i < l; ++i) { - attr = attrs.item(i); - attrName = attr.nodeName.toLowerCase().replace("html:", ""); - val = attr.nodeValue; - if (attrName !== "contenteditable" || val !== "inherit") { - if (!!val) { pairs.push(attrName + "=\"" + val + "\""); } - } - } - - var formatted = "<" + tagName + (pairs.length > 0 ? " " : ""); - var content = element.innerHTML; - - if (content.length > 20) { - content = content.substr(0, 20) + "[...]"; - } - - var res = formatted + pairs.join(" ") + ">" + content + - ""; - - return res.replace(/ contentEditable="inherit"/, ""); - }; - - function Formatio(options) { - for (var opt in options) { - this[opt] = options[opt]; - } - } - - Formatio.prototype = { - functionName: functionName, - - configure: function (options) { - return new Formatio(options); - }, - - constructorName: function (object) { - return constructorName(this, object); - }, - - ascii: function (object, processed, indent) { - return ascii(this, object, processed, indent); - } - }; - - return Formatio.prototype; -}); -/*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ -/*global module, require, __dirname, document*/ -/** - * Sinon core utilities. For internal use only. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -var sinon = (function (formatio) { - var div = typeof document != "undefined" && document.createElement("div"); - var hasOwn = Object.prototype.hasOwnProperty; - - function isDOMNode(obj) { - var success = false; - - try { - obj.appendChild(div); - success = div.parentNode == obj; - } catch (e) { - return false; - } finally { - try { - obj.removeChild(div); - } catch (e) { - // Remove failed, not much we can do about that - } - } - - return success; - } - - function isElement(obj) { - return div && obj && obj.nodeType === 1 && isDOMNode(obj); - } - - function isFunction(obj) { - return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); - } - - function mirrorProperties(target, source) { - for (var prop in source) { - if (!hasOwn.call(target, prop)) { - target[prop] = source[prop]; - } - } - } - - function isRestorable (obj) { - return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon; - } - - var sinon = { - wrapMethod: function wrapMethod(object, property, method) { - if (!object) { - throw new TypeError("Should wrap property of object"); - } - - if (typeof method != "function") { - throw new TypeError("Method wrapper should be function"); - } - - var wrappedMethod = object[property], - error; - - if (!isFunction(wrappedMethod)) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); - } - - if (wrappedMethod.restore && wrappedMethod.restore.sinon) { - error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); - } - - if (wrappedMethod.calledBefore) { - var verb = !!wrappedMethod.returns ? "stubbed" : "spied on"; - error = new TypeError("Attempted to wrap " + property + " which is already " + verb); - } - - if (error) { - if (wrappedMethod._stack) { - error.stack += '\n--------------\n' + wrappedMethod._stack; - } - throw error; - } - - // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem - // when using hasOwn.call on objects from other frames. - var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); - object[property] = method; - method.displayName = property; - // Set up a stack trace which can be used later to find what line of - // code the original method was created on. - method._stack = (new Error('Stack Trace for original')).stack; - - method.restore = function () { - // For prototype properties try to reset by delete first. - // If this fails (ex: localStorage on mobile safari) then force a reset - // via direct assignment. - if (!owned) { - delete object[property]; - } - if (object[property] === method) { - object[property] = wrappedMethod; - } - }; - - method.restore.sinon = true; - mirrorProperties(method, wrappedMethod); - - return method; - }, - - extend: function extend(target) { - for (var i = 1, l = arguments.length; i < l; i += 1) { - for (var prop in arguments[i]) { - if (arguments[i].hasOwnProperty(prop)) { - target[prop] = arguments[i][prop]; - } - - // DONT ENUM bug, only care about toString - if (arguments[i].hasOwnProperty("toString") && - arguments[i].toString != target.toString) { - target.toString = arguments[i].toString; - } - } - } - - return target; - }, - - create: function create(proto) { - var F = function () {}; - F.prototype = proto; - return new F(); - }, - - deepEqual: function deepEqual(a, b) { - if (sinon.match && sinon.match.isMatcher(a)) { - return a.test(b); - } - if (typeof a != "object" || typeof b != "object") { - return a === b; - } - - if (isElement(a) || isElement(b)) { - return a === b; - } - - if (a === b) { - return true; - } - - if ((a === null && b !== null) || (a !== null && b === null)) { - return false; - } - - var aString = Object.prototype.toString.call(a); - if (aString != Object.prototype.toString.call(b)) { - return false; - } - - if (aString == "[object Date]") { - return a.valueOf() === b.valueOf(); - } - - var prop, aLength = 0, bLength = 0; - - if (aString == "[object Array]" && a.length !== b.length) { - return false; - } - - for (prop in a) { - aLength += 1; - - if (!deepEqual(a[prop], b[prop])) { - return false; - } - } - - for (prop in b) { - bLength += 1; - } - - return aLength == bLength; - }, - - functionName: function functionName(func) { - var name = func.displayName || func.name; - - // Use function decomposition as a last resort to get function - // name. Does not rely on function decomposition to work - if it - // doesn't debugging will be slightly less informative - // (i.e. toString will say 'spy' rather than 'myFunc'). - if (!name) { - var matches = func.toString().match(/function ([^\s\(]+)/); - name = matches && matches[1]; - } - - return name; - }, - - functionToString: function toString() { - if (this.getCall && this.callCount) { - var thisValue, prop, i = this.callCount; - - while (i--) { - thisValue = this.getCall(i).thisValue; - - for (prop in thisValue) { - if (thisValue[prop] === this) { - return prop; - } - } - } - } - - return this.displayName || "sinon fake"; - }, - - getConfig: function (custom) { - var config = {}; - custom = custom || {}; - var defaults = sinon.defaultConfig; - - for (var prop in defaults) { - if (defaults.hasOwnProperty(prop)) { - config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop]; - } - } - - return config; - }, - - format: function (val) { - return "" + val; - }, - - defaultConfig: { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }, - - timesInWords: function timesInWords(count) { - return count == 1 && "once" || - count == 2 && "twice" || - count == 3 && "thrice" || - (count || 0) + " times"; - }, - - calledInOrder: function (spies) { - for (var i = 1, l = spies.length; i < l; i++) { - if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) { - return false; - } - } - - return true; - }, - - orderByFirstCall: function (spies) { - return spies.sort(function (a, b) { - // uuid, won't ever be equal - var aCall = a.getCall(0); - var bCall = b.getCall(0); - var aId = aCall && aCall.callId || -1; - var bId = bCall && bCall.callId || -1; - - return aId < bId ? -1 : 1; - }); - }, - - log: function () {}, - - logError: function (label, err) { - var msg = label + " threw exception: "; - sinon.log(msg + "[" + err.name + "] " + err.message); - if (err.stack) { sinon.log(err.stack); } - - setTimeout(function () { - err.message = msg + err.message; - throw err; - }, 0); - }, - - typeOf: function (value) { - if (value === null) { - return "null"; - } - else if (value === undefined) { - return "undefined"; - } - var string = Object.prototype.toString.call(value); - return string.substring(8, string.length - 1).toLowerCase(); - }, - - createStubInstance: function (constructor) { - if (typeof constructor !== "function") { - throw new TypeError("The constructor should be a function."); - } - return sinon.stub(sinon.create(constructor.prototype)); - }, - - restore: function (object) { - if (object !== null && typeof object === "object") { - for (var prop in object) { - if (isRestorable(object[prop])) { - object[prop].restore(); - } - } - } - else if (isRestorable(object)) { - object.restore(); - } - } - }; - - var isNode = typeof module !== "undefined" && module.exports; - var isAMD = typeof define === 'function' && typeof define.amd === 'object' && define.amd; - - if (isAMD) { - define(function(){ - return sinon; - }); - } else if (isNode) { - try { - formatio = require("formatio"); - } catch (e) {} - module.exports = sinon; - module.exports.spy = require("./sinon/spy"); - module.exports.spyCall = require("./sinon/call"); - module.exports.behavior = require("./sinon/behavior"); - module.exports.stub = require("./sinon/stub"); - module.exports.mock = require("./sinon/mock"); - module.exports.collection = require("./sinon/collection"); - module.exports.assert = require("./sinon/assert"); - module.exports.sandbox = require("./sinon/sandbox"); - module.exports.test = require("./sinon/test"); - module.exports.testCase = require("./sinon/test_case"); - module.exports.assert = require("./sinon/assert"); - module.exports.match = require("./sinon/match"); - } - - if (formatio) { - var formatter = formatio.configure({ quoteStrings: false }); - sinon.format = function () { - return formatter.ascii.apply(formatter, arguments); - }; - } else if (isNode) { - try { - var util = require("util"); - sinon.format = function (value) { - return typeof value == "object" && value.toString === Object.prototype.toString ? util.inspect(value) : value; - }; - } catch (e) { - /* Node, but no util module - would be very old, but better safe than - sorry */ - } - } - - return sinon; -}(typeof formatio == "object" && formatio)); - -/* @depend ../sinon.js */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Match functions - * - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2012 Maximilian Antoni - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function assertType(value, type, name) { - var actual = sinon.typeOf(value); - if (actual !== type) { - throw new TypeError("Expected type of " + name + " to be " + - type + ", but was " + actual); - } - } - - var matcher = { - toString: function () { - return this.message; - } - }; - - function isMatcher(object) { - return matcher.isPrototypeOf(object); - } - - function matchObject(expectation, actual) { - if (actual === null || actual === undefined) { - return false; - } - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - var exp = expectation[key]; - var act = actual[key]; - if (match.isMatcher(exp)) { - if (!exp.test(act)) { - return false; - } - } else if (sinon.typeOf(exp) === "object") { - if (!matchObject(exp, act)) { - return false; - } - } else if (!sinon.deepEqual(exp, act)) { - return false; - } - } - } - return true; - } - - matcher.or = function (m2) { - if (!isMatcher(m2)) { - throw new TypeError("Matcher expected"); - } - var m1 = this; - var or = sinon.create(matcher); - or.test = function (actual) { - return m1.test(actual) || m2.test(actual); - }; - or.message = m1.message + ".or(" + m2.message + ")"; - return or; - }; - - matcher.and = function (m2) { - if (!isMatcher(m2)) { - throw new TypeError("Matcher expected"); - } - var m1 = this; - var and = sinon.create(matcher); - and.test = function (actual) { - return m1.test(actual) && m2.test(actual); - }; - and.message = m1.message + ".and(" + m2.message + ")"; - return and; - }; - - var match = function (expectation, message) { - var m = sinon.create(matcher); - var type = sinon.typeOf(expectation); - switch (type) { - case "object": - if (typeof expectation.test === "function") { - m.test = function (actual) { - return expectation.test(actual) === true; - }; - m.message = "match(" + sinon.functionName(expectation.test) + ")"; - return m; - } - var str = []; - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - str.push(key + ": " + expectation[key]); - } - } - m.test = function (actual) { - return matchObject(expectation, actual); - }; - m.message = "match(" + str.join(", ") + ")"; - break; - case "number": - m.test = function (actual) { - return expectation == actual; - }; - break; - case "string": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; - } - return actual.indexOf(expectation) !== -1; - }; - m.message = "match(\"" + expectation + "\")"; - break; - case "regexp": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; - } - return expectation.test(actual); - }; - break; - case "function": - m.test = expectation; - if (message) { - m.message = message; - } else { - m.message = "match(" + sinon.functionName(expectation) + ")"; - } - break; - default: - m.test = function (actual) { - return sinon.deepEqual(expectation, actual); - }; - } - if (!m.message) { - m.message = "match(" + expectation + ")"; - } - return m; - }; - - match.isMatcher = isMatcher; - - match.any = match(function () { - return true; - }, "any"); - - match.defined = match(function (actual) { - return actual !== null && actual !== undefined; - }, "defined"); - - match.truthy = match(function (actual) { - return !!actual; - }, "truthy"); - - match.falsy = match(function (actual) { - return !actual; - }, "falsy"); - - match.same = function (expectation) { - return match(function (actual) { - return expectation === actual; - }, "same(" + expectation + ")"); - }; - - match.typeOf = function (type) { - assertType(type, "string", "type"); - return match(function (actual) { - return sinon.typeOf(actual) === type; - }, "typeOf(\"" + type + "\")"); - }; - - match.instanceOf = function (type) { - assertType(type, "function", "type"); - return match(function (actual) { - return actual instanceof type; - }, "instanceOf(" + sinon.functionName(type) + ")"); - }; - - function createPropertyMatcher(propertyTest, messagePrefix) { - return function (property, value) { - assertType(property, "string", "property"); - var onlyProperty = arguments.length === 1; - var message = messagePrefix + "(\"" + property + "\""; - if (!onlyProperty) { - message += ", " + value; - } - message += ")"; - return match(function (actual) { - if (actual === undefined || actual === null || - !propertyTest(actual, property)) { - return false; - } - return onlyProperty || sinon.deepEqual(value, actual[property]); - }, message); - }; - } - - match.has = createPropertyMatcher(function (actual, property) { - if (typeof actual === "object") { - return property in actual; - } - return actual[property] !== undefined; - }, "has"); - - match.hasOwn = createPropertyMatcher(function (actual, property) { - return actual.hasOwnProperty(property); - }, "hasOwn"); - - match.bool = match.typeOf("boolean"); - match.number = match.typeOf("number"); - match.string = match.typeOf("string"); - match.object = match.typeOf("object"); - match.func = match.typeOf("function"); - match.array = match.typeOf("array"); - match.regexp = match.typeOf("regexp"); - match.date = match.typeOf("date"); - - if (commonJSModule) { - module.exports = match; - } else { - sinon.match = match; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend match.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Spy calls - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - * Copyright (c) 2013 Maximilian Antoni - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function throwYieldError(proxy, text, args) { - var msg = sinon.functionName(proxy) + text; - if (args.length) { - msg += " Received [" + slice.call(args).join(", ") + "]"; - } - throw new Error(msg); - } - - var slice = Array.prototype.slice; - - var callProto = { - calledOn: function calledOn(thisValue) { - if (sinon.match && sinon.match.isMatcher(thisValue)) { - return thisValue.test(this.thisValue); - } - return this.thisValue === thisValue; - }, - - calledWith: function calledWith() { - for (var i = 0, l = arguments.length; i < l; i += 1) { - if (!sinon.deepEqual(arguments[i], this.args[i])) { - return false; - } - } - - return true; - }, - - calledWithMatch: function calledWithMatch() { - for (var i = 0, l = arguments.length; i < l; i += 1) { - var actual = this.args[i]; - var expectation = arguments[i]; - if (!sinon.match || !sinon.match(expectation).test(actual)) { - return false; - } - } - return true; - }, - - calledWithExactly: function calledWithExactly() { - return arguments.length == this.args.length && - this.calledWith.apply(this, arguments); - }, - - notCalledWith: function notCalledWith() { - return !this.calledWith.apply(this, arguments); - }, - - notCalledWithMatch: function notCalledWithMatch() { - return !this.calledWithMatch.apply(this, arguments); - }, - - returned: function returned(value) { - return sinon.deepEqual(value, this.returnValue); - }, - - threw: function threw(error) { - if (typeof error === "undefined" || !this.exception) { - return !!this.exception; - } - - return this.exception === error || this.exception.name === error; - }, - - calledWithNew: function calledWithNew() { - return this.proxy.prototype && this.thisValue instanceof this.proxy; - }, - - calledBefore: function (other) { - return this.callId < other.callId; - }, - - calledAfter: function (other) { - return this.callId > other.callId; - }, - - callArg: function (pos) { - this.args[pos](); - }, - - callArgOn: function (pos, thisValue) { - this.args[pos].apply(thisValue); - }, - - callArgWith: function (pos) { - this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1))); - }, - - callArgOnWith: function (pos, thisValue) { - var args = slice.call(arguments, 2); - this.args[pos].apply(thisValue, args); - }, - - "yield": function () { - this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0))); - }, - - yieldOn: function (thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (typeof args[i] === "function") { - args[i].apply(thisValue, slice.call(arguments, 1)); - return; - } - } - throwYieldError(this.proxy, " cannot yield since no callback was passed.", args); - }, - - yieldTo: function (prop) { - this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1))); - }, - - yieldToOn: function (prop, thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (args[i] && typeof args[i][prop] === "function") { - args[i][prop].apply(thisValue, slice.call(arguments, 2)); - return; - } - } - throwYieldError(this.proxy, " cannot yield to '" + prop + - "' since no callback was passed.", args); - }, - - toString: function () { - var callStr = this.proxy.toString() + "("; - var args = []; - - for (var i = 0, l = this.args.length; i < l; ++i) { - args.push(sinon.format(this.args[i])); - } - - callStr = callStr + args.join(", ") + ")"; - - if (typeof this.returnValue != "undefined") { - callStr += " => " + sinon.format(this.returnValue); - } - - if (this.exception) { - callStr += " !" + this.exception.name; - - if (this.exception.message) { - callStr += "(" + this.exception.message + ")"; - } - } - - return callStr; - } - }; - - callProto.invokeCallback = callProto.yield; - - function createSpyCall(spy, thisValue, args, returnValue, exception, id) { - if (typeof id !== "number") { - throw new TypeError("Call id is not a number"); - } - var proxyCall = sinon.create(callProto); - proxyCall.proxy = spy; - proxyCall.thisValue = thisValue; - proxyCall.args = args; - proxyCall.returnValue = returnValue; - proxyCall.exception = exception; - proxyCall.callId = id; - - return proxyCall; - } - createSpyCall.toString = callProto.toString; // used by mocks - - if (commonJSModule) { - module.exports = createSpyCall; - } else { - sinon.spyCall = createSpyCall; - } -}(typeof sinon == "object" && sinon || null)); - - -/** - * @depend ../sinon.js - * @depend call.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Spy functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = Array.prototype.push; - var slice = Array.prototype.slice; - var callId = 0; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function spy(object, property) { - if (!property && typeof object == "function") { - return spy.create(object); - } - - if (!object && !property) { - return spy.create(function () { }); - } - - var method = object[property]; - return sinon.wrapMethod(object, property, spy.create(method)); - } - - function matchingFake(fakes, args, strict) { - if (!fakes) { - return; - } - - for (var i = 0, l = fakes.length; i < l; i++) { - if (fakes[i].matches(args, strict)) { - return fakes[i]; - } - } - } - - function incrementCallCount() { - this.called = true; - this.callCount += 1; - this.notCalled = false; - this.calledOnce = this.callCount == 1; - this.calledTwice = this.callCount == 2; - this.calledThrice = this.callCount == 3; - } - - function createCallProperties() { - this.firstCall = this.getCall(0); - this.secondCall = this.getCall(1); - this.thirdCall = this.getCall(2); - this.lastCall = this.getCall(this.callCount - 1); - } - - var vars = "a,b,c,d,e,f,g,h,i,j,k,l"; - function createProxy(func) { - // Retain the function length: - var p; - if (func.length) { - eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) + - ") { return p.invoke(func, this, slice.call(arguments)); });"); - } - else { - p = function proxy() { - return p.invoke(func, this, slice.call(arguments)); - }; - } - return p; - } - - var uuid = 0; - - // Public API - var spyApi = { - reset: function () { - this.called = false; - this.notCalled = true; - this.calledOnce = false; - this.calledTwice = false; - this.calledThrice = false; - this.callCount = 0; - this.firstCall = null; - this.secondCall = null; - this.thirdCall = null; - this.lastCall = null; - this.args = []; - this.returnValues = []; - this.thisValues = []; - this.exceptions = []; - this.callIds = []; - if (this.fakes) { - for (var i = 0; i < this.fakes.length; i++) { - this.fakes[i].reset(); - } - } - }, - - create: function create(func) { - var name; - - if (typeof func != "function") { - func = function () { }; - } else { - name = sinon.functionName(func); - } - - var proxy = createProxy(func); - - sinon.extend(proxy, spy); - delete proxy.create; - sinon.extend(proxy, func); - - proxy.reset(); - proxy.prototype = func.prototype; - proxy.displayName = name || "spy"; - proxy.toString = sinon.functionToString; - proxy._create = sinon.spy.create; - proxy.id = "spy#" + uuid++; - - return proxy; - }, - - invoke: function invoke(func, thisValue, args) { - var matching = matchingFake(this.fakes, args); - var exception, returnValue; - - incrementCallCount.call(this); - push.call(this.thisValues, thisValue); - push.call(this.args, args); - push.call(this.callIds, callId++); - - try { - if (matching) { - returnValue = matching.invoke(func, thisValue, args); - } else { - returnValue = (this.func || func).apply(thisValue, args); - } - - var thisCall = this.getCall(this.callCount - 1); - if (thisCall.calledWithNew() && typeof returnValue !== 'object') { - returnValue = thisValue; - } - } catch (e) { - exception = e; - } - - push.call(this.exceptions, exception); - push.call(this.returnValues, returnValue); - - createCallProperties.call(this); - - if (exception !== undefined) { - throw exception; - } - - return returnValue; - }, - - getCall: function getCall(i) { - if (i < 0 || i >= this.callCount) { - return null; - } - - return sinon.spyCall(this, this.thisValues[i], this.args[i], - this.returnValues[i], this.exceptions[i], - this.callIds[i]); - }, - - getCalls: function () { - var calls = []; - var i; - - for (i = 0; i < this.callCount; i++) { - calls.push(this.getCall(i)); - } - - return calls; - }, - - calledBefore: function calledBefore(spyFn) { - if (!this.called) { - return false; - } - - if (!spyFn.called) { - return true; - } - - return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1]; - }, - - calledAfter: function calledAfter(spyFn) { - if (!this.called || !spyFn.called) { - return false; - } - - return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1]; - }, - - withArgs: function () { - var args = slice.call(arguments); - - if (this.fakes) { - var match = matchingFake(this.fakes, args, true); - - if (match) { - return match; - } - } else { - this.fakes = []; - } - - var original = this; - var fake = this._create(); - fake.matchingAguments = args; - fake.parent = this; - push.call(this.fakes, fake); - - fake.withArgs = function () { - return original.withArgs.apply(original, arguments); - }; - - for (var i = 0; i < this.args.length; i++) { - if (fake.matches(this.args[i])) { - incrementCallCount.call(fake); - push.call(fake.thisValues, this.thisValues[i]); - push.call(fake.args, this.args[i]); - push.call(fake.returnValues, this.returnValues[i]); - push.call(fake.exceptions, this.exceptions[i]); - push.call(fake.callIds, this.callIds[i]); - } - } - createCallProperties.call(fake); - - return fake; - }, - - matches: function (args, strict) { - var margs = this.matchingAguments; - - if (margs.length <= args.length && - sinon.deepEqual(margs, args.slice(0, margs.length))) { - return !strict || margs.length == args.length; - } - }, - - printf: function (format) { - var spy = this; - var args = slice.call(arguments, 1); - var formatter; - - return (format || "").replace(/%(.)/g, function (match, specifyer) { - formatter = spyApi.formatters[specifyer]; - - if (typeof formatter == "function") { - return formatter.call(null, spy, args); - } else if (!isNaN(parseInt(specifyer, 10))) { - return sinon.format(args[specifyer - 1]); - } - - return "%" + specifyer; - }); - } - }; - - function delegateToCalls(method, matchAny, actual, notCalled) { - spyApi[method] = function () { - if (!this.called) { - if (notCalled) { - return notCalled.apply(this, arguments); - } - return false; - } - - var currentCall; - var matches = 0; - - for (var i = 0, l = this.callCount; i < l; i += 1) { - currentCall = this.getCall(i); - - if (currentCall[actual || method].apply(currentCall, arguments)) { - matches += 1; - - if (matchAny) { - return true; - } - } - } - - return matches === this.callCount; - }; - } - - delegateToCalls("calledOn", true); - delegateToCalls("alwaysCalledOn", false, "calledOn"); - delegateToCalls("calledWith", true); - delegateToCalls("calledWithMatch", true); - delegateToCalls("alwaysCalledWith", false, "calledWith"); - delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); - delegateToCalls("calledWithExactly", true); - delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); - delegateToCalls("neverCalledWith", false, "notCalledWith", - function () { return true; }); - delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", - function () { return true; }); - delegateToCalls("threw", true); - delegateToCalls("alwaysThrew", false, "threw"); - delegateToCalls("returned", true); - delegateToCalls("alwaysReturned", false, "returned"); - delegateToCalls("calledWithNew", true); - delegateToCalls("alwaysCalledWithNew", false, "calledWithNew"); - delegateToCalls("callArg", false, "callArgWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgWith = spyApi.callArg; - delegateToCalls("callArgOn", false, "callArgOnWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgOnWith = spyApi.callArgOn; - delegateToCalls("yield", false, "yield", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode. - spyApi.invokeCallback = spyApi.yield; - delegateToCalls("yieldOn", false, "yieldOn", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - delegateToCalls("yieldTo", false, "yieldTo", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); - delegateToCalls("yieldToOn", false, "yieldToOn", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); - - spyApi.formatters = { - "c": function (spy) { - return sinon.timesInWords(spy.callCount); - }, - - "n": function (spy) { - return spy.toString(); - }, - - "C": function (spy) { - var calls = []; - - for (var i = 0, l = spy.callCount; i < l; ++i) { - var stringifiedCall = " " + spy.getCall(i).toString(); - if (/\n/.test(calls[i - 1])) { - stringifiedCall = "\n" + stringifiedCall; - } - push.call(calls, stringifiedCall); - } - - return calls.length > 0 ? "\n" + calls.join("\n") : ""; - }, - - "t": function (spy) { - var objects = []; - - for (var i = 0, l = spy.callCount; i < l; ++i) { - push.call(objects, sinon.format(spy.thisValues[i])); - } - - return objects.join(", "); - }, - - "*": function (spy, args) { - var formatted = []; - - for (var i = 0, l = args.length; i < l; ++i) { - push.call(formatted, sinon.format(args[i])); - } - - return formatted.join(", "); - } - }; - - sinon.extend(spy, spyApi); - - spy.spyCall = sinon.spyCall; - - if (commonJSModule) { - module.exports = spy; - } else { - sinon.spy = spy; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global module, require, sinon, process, setImmediate, setTimeout*/ -/** - * Stub behavior - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Tim Fischbach (mail@timfischbach.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - var slice = Array.prototype.slice; - var join = Array.prototype.join; - var proto; - - var nextTick = (function () { - if (typeof process === "object" && typeof process.nextTick === "function") { - return process.nextTick; - } else if (typeof setImmediate === "function") { - return setImmediate; - } else { - return function (callback) { - setTimeout(callback, 0); - }; - } - })(); - - function throwsException(error, message) { - if (typeof error == "string") { - this.exception = new Error(message || ""); - this.exception.name = error; - } else if (!error) { - this.exception = new Error("Error"); - } else { - this.exception = error; - } - - return this; - } - - function getCallback(behavior, args) { - var callArgAt = behavior.callArgAt; - - if (callArgAt < 0) { - var callArgProp = behavior.callArgProp; - - for (var i = 0, l = args.length; i < l; ++i) { - if (!callArgProp && typeof args[i] == "function") { - return args[i]; - } - - if (callArgProp && args[i] && - typeof args[i][callArgProp] == "function") { - return args[i][callArgProp]; - } - } - - return null; - } - - return args[callArgAt]; - } - - function getCallbackError(behavior, func, args) { - if (behavior.callArgAt < 0) { - var msg; - - if (behavior.callArgProp) { - msg = sinon.functionName(behavior.stub) + - " expected to yield to '" + behavior.callArgProp + - "', but no object with such a property was passed."; - } else { - msg = sinon.functionName(behavior.stub) + - " expected to yield, but no callback was passed."; - } - - if (args.length > 0) { - msg += " Received [" + join.call(args, ", ") + "]"; - } - - return msg; - } - - return "argument at index " + behavior.callArgAt + " is not a function: " + func; - } - - function callCallback(behavior, args) { - if (typeof behavior.callArgAt == "number") { - var func = getCallback(behavior, args); - - if (typeof func != "function") { - throw new TypeError(getCallbackError(behavior, func, args)); - } - - if (behavior.callbackAsync) { - nextTick(function() { - func.apply(behavior.callbackContext, behavior.callbackArguments); - }); - } else { - func.apply(behavior.callbackContext, behavior.callbackArguments); - } - } - } - - proto = { - create: function(stub) { - var behavior = sinon.extend({}, sinon.behavior); - delete behavior.create; - behavior.stub = stub; - - return behavior; - }, - - isPresent: function() { - return (typeof this.callArgAt == 'number' || - this.exception || - typeof this.returnArgAt == 'number' || - this.returnThis || - this.returnValueDefined); - }, - - invoke: function(context, args) { - callCallback(this, args); - - if (this.exception) { - throw this.exception; - } else if (typeof this.returnArgAt == 'number') { - return args[this.returnArgAt]; - } else if (this.returnThis) { - return context; - } - - return this.returnValue; - }, - - onCall: function(index) { - return this.stub.onCall(index); - }, - - onFirstCall: function() { - return this.stub.onFirstCall(); - }, - - onSecondCall: function() { - return this.stub.onSecondCall(); - }, - - onThirdCall: function() { - return this.stub.onThirdCall(); - }, - - withArgs: function(/* arguments */) { - throw new Error('Defining a stub by invoking "stub.onCall(...).withArgs(...)" is not supported. ' + - 'Use "stub.withArgs(...).onCall(...)" to define sequential behavior for calls with certain arguments.'); - }, - - callsArg: function callsArg(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgOn: function callsArgOn(pos, context) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgWith: function callsArgWith(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - callsArgOnWith: function callsArgWith(pos, context) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yields: function () { - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 0); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yieldsOn: function (context) { - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, - - yieldsTo: function (prop) { - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = prop; - this.callbackAsync = false; - - return this; - }, - - yieldsToOn: function (prop, context) { - if (typeof context != "object") { - throw new TypeError("argument context is not an object"); - } - - this.callArgAt = -1; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = prop; - this.callbackAsync = false; - - return this; - }, - - - "throws": throwsException, - throwsException: throwsException, - - returns: function returns(value) { - this.returnValue = value; - this.returnValueDefined = true; - - return this; - }, - - returnsArg: function returnsArg(pos) { - if (typeof pos != "number") { - throw new TypeError("argument index is not number"); - } - - this.returnArgAt = pos; - - return this; - }, - - returnsThis: function returnsThis() { - this.returnThis = true; - - return this; - } - }; - - // create asynchronous versions of callsArg* and yields* methods - for (var method in proto) { - // need to avoid creating anotherasync versions of the newly added async methods - if (proto.hasOwnProperty(method) && - method.match(/^(callsArg|yields)/) && - !method.match(/Async/)) { - proto[method + 'Async'] = (function (syncFnName) { - return function () { - var result = this[syncFnName].apply(this, arguments); - this.callbackAsync = true; - return result; - }; - })(method); - } - } - - if (commonJSModule) { - module.exports = proto; - } else { - sinon.behavior = proto; - } -}(typeof sinon == "object" && sinon || null)); -/** - * @depend ../sinon.js - * @depend spy.js - * @depend behavior.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global module, require, sinon*/ -/** - * Stub functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function stub(object, property, func) { - if (!!func && typeof func != "function") { - throw new TypeError("Custom stub should be function"); - } - - var wrapper; - - if (func) { - wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func; - } else { - wrapper = stub.create(); - } - - if (!object && typeof property === "undefined") { - return sinon.stub.create(); - } - - if (typeof property === "undefined" && typeof object == "object") { - for (var prop in object) { - if (typeof object[prop] === "function") { - stub(object, prop); - } - } - - return object; - } - - return sinon.wrapMethod(object, property, wrapper); - } - - function getDefaultBehavior(stub) { - return stub.defaultBehavior || getParentBehaviour(stub) || sinon.behavior.create(stub); - } - - function getParentBehaviour(stub) { - return (stub.parent && getCurrentBehavior(stub.parent)); - } - - function getCurrentBehavior(stub) { - var behavior = stub.behaviors[stub.callCount - 1]; - return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stub); - } - - var uuid = 0; - - sinon.extend(stub, (function () { - var proto = { - create: function create() { - var functionStub = function () { - return getCurrentBehavior(functionStub).invoke(this, arguments); - }; - - functionStub.id = "stub#" + uuid++; - var orig = functionStub; - functionStub = sinon.spy.create(functionStub); - functionStub.func = orig; - - sinon.extend(functionStub, stub); - functionStub._create = sinon.stub.create; - functionStub.displayName = "stub"; - functionStub.toString = sinon.functionToString; - - functionStub.defaultBehavior = null; - functionStub.behaviors = []; - - return functionStub; - }, - - resetBehavior: function () { - var i; - - this.defaultBehavior = null; - this.behaviors = []; - - delete this.returnValue; - delete this.returnArgAt; - this.returnThis = false; - - if (this.fakes) { - for (i = 0; i < this.fakes.length; i++) { - this.fakes[i].resetBehavior(); - } - } - }, - - onCall: function(index) { - if (!this.behaviors[index]) { - this.behaviors[index] = sinon.behavior.create(this); - } - - return this.behaviors[index]; - }, - - onFirstCall: function() { - return this.onCall(0); - }, - - onSecondCall: function() { - return this.onCall(1); - }, - - onThirdCall: function() { - return this.onCall(2); - } - }; - - for (var method in sinon.behavior) { - if (sinon.behavior.hasOwnProperty(method) && - !proto.hasOwnProperty(method) && - method != 'create' && - method != 'withArgs' && - method != 'invoke') { - proto[method] = (function(behaviorMethod) { - return function() { - this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this); - this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); - return this; - }; - }(method)); - } - } - - return proto; - }())); - - if (commonJSModule) { - module.exports = stub; - } else { - sinon.stub = stub; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - */ -/*jslint eqeqeq: false, onevar: false, nomen: false*/ -/*global module, require, sinon*/ -/** - * Mock functions. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = [].push; - var match; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - match = sinon.match; - - if (!match && commonJSModule) { - match = require("./match"); - } - - function mock(object) { - if (!object) { - return sinon.expectation.create("Anonymous mock"); - } - - return mock.create(object); - } - - sinon.mock = mock; - - sinon.extend(mock, (function () { - function each(collection, callback) { - if (!collection) { - return; - } - - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } - } - - return { - create: function create(object) { - if (!object) { - throw new TypeError("object is null"); - } - - var mockObject = sinon.extend({}, mock); - mockObject.object = object; - delete mockObject.create; - - return mockObject; - }, - - expects: function expects(method) { - if (!method) { - throw new TypeError("method is falsy"); - } - - if (!this.expectations) { - this.expectations = {}; - this.proxies = []; - } - - if (!this.expectations[method]) { - this.expectations[method] = []; - var mockObject = this; - - sinon.wrapMethod(this.object, method, function () { - return mockObject.invokeMethod(method, this, arguments); - }); - - push.call(this.proxies, method); - } - - var expectation = sinon.expectation.create(method); - push.call(this.expectations[method], expectation); - - return expectation; - }, - - restore: function restore() { - var object = this.object; - - each(this.proxies, function (proxy) { - if (typeof object[proxy].restore == "function") { - object[proxy].restore(); - } - }); - }, - - verify: function verify() { - var expectations = this.expectations || {}; - var messages = [], met = []; - - each(this.proxies, function (proxy) { - each(expectations[proxy], function (expectation) { - if (!expectation.met()) { - push.call(messages, expectation.toString()); - } else { - push.call(met, expectation.toString()); - } - }); - }); - - this.restore(); - - if (messages.length > 0) { - sinon.expectation.fail(messages.concat(met).join("\n")); - } else { - sinon.expectation.pass(messages.concat(met).join("\n")); - } - - return true; - }, - - invokeMethod: function invokeMethod(method, thisValue, args) { - var expectations = this.expectations && this.expectations[method]; - var length = expectations && expectations.length || 0, i; - - for (i = 0; i < length; i += 1) { - if (!expectations[i].met() && - expectations[i].allowsCall(thisValue, args)) { - return expectations[i].apply(thisValue, args); - } - } - - var messages = [], available, exhausted = 0; - - for (i = 0; i < length; i += 1) { - if (expectations[i].allowsCall(thisValue, args)) { - available = available || expectations[i]; - } else { - exhausted += 1; - } - push.call(messages, " " + expectations[i].toString()); - } - - if (exhausted === 0) { - return available.apply(thisValue, args); - } - - messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({ - proxy: method, - args: args - })); - - sinon.expectation.fail(messages.join("\n")); - } - }; - }())); - - var times = sinon.timesInWords; - - sinon.expectation = (function () { - var slice = Array.prototype.slice; - var _invoke = sinon.spy.invoke; - - function callCountInWords(callCount) { - if (callCount == 0) { - return "never called"; - } else { - return "called " + times(callCount); - } - } - - function expectedCallCountInWords(expectation) { - var min = expectation.minCalls; - var max = expectation.maxCalls; - - if (typeof min == "number" && typeof max == "number") { - var str = times(min); - - if (min != max) { - str = "at least " + str + " and at most " + times(max); - } - - return str; - } - - if (typeof min == "number") { - return "at least " + times(min); - } - - return "at most " + times(max); - } - - function receivedMinCalls(expectation) { - var hasMinLimit = typeof expectation.minCalls == "number"; - return !hasMinLimit || expectation.callCount >= expectation.minCalls; - } - - function receivedMaxCalls(expectation) { - if (typeof expectation.maxCalls != "number") { - return false; - } - - return expectation.callCount == expectation.maxCalls; - } - - function verifyMatcher(possibleMatcher, arg){ - if (match && match.isMatcher(possibleMatcher)) { - return possibleMatcher.test(arg); - } else { - return true; - } - } - - return { - minCalls: 1, - maxCalls: 1, - - create: function create(methodName) { - var expectation = sinon.extend(sinon.stub.create(), sinon.expectation); - delete expectation.create; - expectation.method = methodName; - - return expectation; - }, - - invoke: function invoke(func, thisValue, args) { - this.verifyCallAllowed(thisValue, args); - - return _invoke.apply(this, arguments); - }, - - atLeast: function atLeast(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not number"); - } - - if (!this.limitsSet) { - this.maxCalls = null; - this.limitsSet = true; - } - - this.minCalls = num; - - return this; - }, - - atMost: function atMost(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not number"); - } - - if (!this.limitsSet) { - this.minCalls = null; - this.limitsSet = true; - } - - this.maxCalls = num; - - return this; - }, - - never: function never() { - return this.exactly(0); - }, - - once: function once() { - return this.exactly(1); - }, - - twice: function twice() { - return this.exactly(2); - }, - - thrice: function thrice() { - return this.exactly(3); - }, - - exactly: function exactly(num) { - if (typeof num != "number") { - throw new TypeError("'" + num + "' is not a number"); - } - - this.atLeast(num); - return this.atMost(num); - }, - - met: function met() { - return !this.failed && receivedMinCalls(this); - }, - - verifyCallAllowed: function verifyCallAllowed(thisValue, args) { - if (receivedMaxCalls(this)) { - this.failed = true; - sinon.expectation.fail(this.method + " already called " + times(this.maxCalls)); - } - - if ("expectedThis" in this && this.expectedThis !== thisValue) { - sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + - this.expectedThis); - } - - if (!("expectedArguments" in this)) { - return; - } - - if (!args) { - sinon.expectation.fail(this.method + " received no arguments, expected " + - sinon.format(this.expectedArguments)); - } - - if (args.length < this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } - - if (this.expectsExactArgCount && - args.length != this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } - - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - - if (!verifyMatcher(this.expectedArguments[i],args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", didn't match " + this.expectedArguments.toString()); - } - - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", expected " + sinon.format(this.expectedArguments)); - } - } - }, - - allowsCall: function allowsCall(thisValue, args) { - if (this.met() && receivedMaxCalls(this)) { - return false; - } - - if ("expectedThis" in this && this.expectedThis !== thisValue) { - return false; - } - - if (!("expectedArguments" in this)) { - return true; - } - - args = args || []; - - if (args.length < this.expectedArguments.length) { - return false; - } - - if (this.expectsExactArgCount && - args.length != this.expectedArguments.length) { - return false; - } - - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - if (!verifyMatcher(this.expectedArguments[i],args[i])) { - return false; - } - - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { - return false; - } - } - - return true; - }, - - withArgs: function withArgs() { - this.expectedArguments = slice.call(arguments); - return this; - }, - - withExactArgs: function withExactArgs() { - this.withArgs.apply(this, arguments); - this.expectsExactArgCount = true; - return this; - }, - - on: function on(thisValue) { - this.expectedThis = thisValue; - return this; - }, - - toString: function () { - var args = (this.expectedArguments || []).slice(); - - if (!this.expectsExactArgCount) { - push.call(args, "[...]"); - } - - var callStr = sinon.spyCall.toString.call({ - proxy: this.method || "anonymous mock expectation", - args: args - }); - - var message = callStr.replace(", [...", "[, ...") + " " + - expectedCallCountInWords(this); - - if (this.met()) { - return "Expectation met: " + message; - } - - return "Expected " + message + " (" + - callCountInWords(this.callCount) + ")"; - }, - - verify: function verify() { - if (!this.met()) { - sinon.expectation.fail(this.toString()); - } else { - sinon.expectation.pass(this.toString()); - } - - return true; - }, - - pass: function(message) { - sinon.assert.pass(message); - }, - fail: function (message) { - var exception = new Error(message); - exception.name = "ExpectationError"; - - throw exception; - } - }; - }()); - - if (commonJSModule) { - module.exports = mock; - } else { - sinon.mock = mock; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - * @depend mock.js - */ -/*jslint eqeqeq: false, onevar: false, forin: true*/ -/*global module, require, sinon*/ -/** - * Collections of stubs, spies and mocks. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - var push = [].push; - var hasOwnProperty = Object.prototype.hasOwnProperty; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function getFakes(fakeCollection) { - if (!fakeCollection.fakes) { - fakeCollection.fakes = []; - } - - return fakeCollection.fakes; - } - - function each(fakeCollection, method) { - var fakes = getFakes(fakeCollection); - - for (var i = 0, l = fakes.length; i < l; i += 1) { - if (typeof fakes[i][method] == "function") { - fakes[i][method](); - } - } - } - - function compact(fakeCollection) { - var fakes = getFakes(fakeCollection); - var i = 0; - while (i < fakes.length) { - fakes.splice(i, 1); - } - } - - var collection = { - verify: function resolve() { - each(this, "verify"); - }, - - restore: function restore() { - each(this, "restore"); - compact(this); - }, - - verifyAndRestore: function verifyAndRestore() { - var exception; - - try { - this.verify(); - } catch (e) { - exception = e; - } - - this.restore(); - - if (exception) { - throw exception; - } - }, - - add: function add(fake) { - push.call(getFakes(this), fake); - return fake; - }, - - spy: function spy() { - return this.add(sinon.spy.apply(sinon, arguments)); - }, - - stub: function stub(object, property, value) { - if (property) { - var original = object[property]; - - if (typeof original != "function") { - if (!hasOwnProperty.call(object, property)) { - throw new TypeError("Cannot stub non-existent own property " + property); - } - - object[property] = value; - - return this.add({ - restore: function () { - object[property] = original; - } - }); - } - } - if (!property && !!object && typeof object == "object") { - var stubbedObj = sinon.stub.apply(sinon, arguments); - - for (var prop in stubbedObj) { - if (typeof stubbedObj[prop] === "function") { - this.add(stubbedObj[prop]); - } - } - - return stubbedObj; - } - - return this.add(sinon.stub.apply(sinon, arguments)); - }, - - mock: function mock() { - return this.add(sinon.mock.apply(sinon, arguments)); - }, - - inject: function inject(obj) { - var col = this; - - obj.spy = function () { - return col.spy.apply(col, arguments); - }; - - obj.stub = function () { - return col.stub.apply(col, arguments); - }; - - obj.mock = function () { - return col.mock.apply(col, arguments); - }; - - return obj; - } - }; - - if (commonJSModule) { - module.exports = collection; - } else { - sinon.collection = collection; - } -}(typeof sinon == "object" && sinon || null)); - -/*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ -/*global module, require, window*/ -/** - * Fake timer API - * setTimeout - * setInterval - * clearTimeout - * clearInterval - * tick - * reset - * Date - * - * Inspired by jsUnitMockTimeOut from JsUnit - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -(function (global) { - var id = 1; - - function addTimer(args, recurring) { - if (args.length === 0) { - throw new Error("Function requires at least 1 parameter"); - } - - if (typeof args[0] === "undefined") { - throw new Error("Callback must be provided to timer calls"); - } - - var toId = id++; - var delay = args[1] || 0; - - if (!this.timeouts) { - this.timeouts = {}; - } - - this.timeouts[toId] = { - id: toId, - func: args[0], - callAt: this.now + delay, - invokeArgs: Array.prototype.slice.call(args, 2) - }; - - if (recurring === true) { - this.timeouts[toId].interval = delay; - } - - return toId; - } - - function parseTime(str) { - if (!str) { - return 0; - } - - var strings = str.split(":"); - var l = strings.length, i = l; - var ms = 0, parsed; - - if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { - throw new Error("tick only understands numbers and 'h:m:s'"); - } - - while (i--) { - parsed = parseInt(strings[i], 10); - - if (parsed >= 60) { - throw new Error("Invalid time " + str); - } - - ms += parsed * Math.pow(60, (l - i - 1)); - } - - return ms * 1000; - } - - function createObject(object) { - var newObject; - - if (Object.create) { - newObject = Object.create(object); - } else { - var F = function () {}; - F.prototype = object; - newObject = new F(); - } - - newObject.Date.clock = newObject; - return newObject; - } - - sinon.clock = { - now: 0, - - create: function create(now) { - var clock = createObject(this); - - if (typeof now == "number") { - clock.now = now; - } - - if (!!now && typeof now == "object") { - throw new TypeError("now should be milliseconds since UNIX epoch"); - } - - return clock; - }, - - setTimeout: function setTimeout(callback, timeout) { - return addTimer.call(this, arguments, false); - }, - - clearTimeout: function clearTimeout(timerId) { - if (!this.timeouts) { - this.timeouts = []; - } - - if (timerId in this.timeouts) { - delete this.timeouts[timerId]; - } - }, - - setInterval: function setInterval(callback, timeout) { - return addTimer.call(this, arguments, true); - }, - - clearInterval: function clearInterval(timerId) { - this.clearTimeout(timerId); - }, - - setImmediate: function setImmediate(callback) { - var passThruArgs = Array.prototype.slice.call(arguments, 1); - - return addTimer.call(this, [callback, 0].concat(passThruArgs), false); - }, - - clearImmediate: function clearImmediate(timerId) { - this.clearTimeout(timerId); - }, - - tick: function tick(ms) { - ms = typeof ms == "number" ? ms : parseTime(ms); - var tickFrom = this.now, tickTo = this.now + ms, previous = this.now; - var timer = this.firstTimerInRange(tickFrom, tickTo); - - var firstException; - while (timer && tickFrom <= tickTo) { - if (this.timeouts[timer.id]) { - tickFrom = this.now = timer.callAt; - try { - this.callTimer(timer); - } catch (e) { - firstException = firstException || e; - } - } - - timer = this.firstTimerInRange(previous, tickTo); - previous = tickFrom; - } - - this.now = tickTo; - - if (firstException) { - throw firstException; - } - - return this.now; - }, - - firstTimerInRange: function (from, to) { - var timer, smallest = null, originalTimer; - - for (var id in this.timeouts) { - if (this.timeouts.hasOwnProperty(id)) { - if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) { - continue; - } - - if (smallest === null || this.timeouts[id].callAt < smallest) { - originalTimer = this.timeouts[id]; - smallest = this.timeouts[id].callAt; - - timer = { - func: this.timeouts[id].func, - callAt: this.timeouts[id].callAt, - interval: this.timeouts[id].interval, - id: this.timeouts[id].id, - invokeArgs: this.timeouts[id].invokeArgs - }; - } - } - } - - return timer || null; - }, - - callTimer: function (timer) { - if (typeof timer.interval == "number") { - this.timeouts[timer.id].callAt += timer.interval; - } else { - delete this.timeouts[timer.id]; - } - - try { - if (typeof timer.func == "function") { - timer.func.apply(null, timer.invokeArgs); - } else { - eval(timer.func); - } - } catch (e) { - var exception = e; - } - - if (!this.timeouts[timer.id]) { - if (exception) { - throw exception; - } - return; - } - - if (exception) { - throw exception; - } - }, - - reset: function reset() { - this.timeouts = {}; - }, - - Date: (function () { - var NativeDate = Date; - - function ClockDate(year, month, date, hour, minute, second, ms) { - // Defensive and verbose to avoid potential harm in passing - // explicit undefined when user does not pass argument - switch (arguments.length) { - case 0: - return new NativeDate(ClockDate.clock.now); - case 1: - return new NativeDate(year); - case 2: - return new NativeDate(year, month); - case 3: - return new NativeDate(year, month, date); - case 4: - return new NativeDate(year, month, date, hour); - case 5: - return new NativeDate(year, month, date, hour, minute); - case 6: - return new NativeDate(year, month, date, hour, minute, second); - default: - return new NativeDate(year, month, date, hour, minute, second, ms); - } - } - - return mirrorDateProperties(ClockDate, NativeDate); - }()) - }; - - function mirrorDateProperties(target, source) { - if (source.now) { - target.now = function now() { - return target.clock.now; - }; - } else { - delete target.now; - } - - if (source.toSource) { - target.toSource = function toSource() { - return source.toSource(); - }; - } else { - delete target.toSource; - } - - target.toString = function toString() { - return source.toString(); - }; - - target.prototype = source.prototype; - target.parse = source.parse; - target.UTC = source.UTC; - target.prototype.toUTCString = source.prototype.toUTCString; - - for (var prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - - return target; - } - - var methods = ["Date", "setTimeout", "setInterval", - "clearTimeout", "clearInterval"]; - - if (typeof global.setImmediate !== "undefined") { - methods.push("setImmediate"); - } - - if (typeof global.clearImmediate !== "undefined") { - methods.push("clearImmediate"); - } - - function restore() { - var method; - - for (var i = 0, l = this.methods.length; i < l; i++) { - method = this.methods[i]; - - if (global[method].hadOwnProperty) { - global[method] = this["_" + method]; - } else { - try { - delete global[method]; - } catch (e) {} - } - } - - // Prevent multiple executions which will completely remove these props - this.methods = []; - } - - function stubGlobal(method, clock) { - clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method); - clock["_" + method] = global[method]; - - if (method == "Date") { - var date = mirrorDateProperties(clock[method], global[method]); - global[method] = date; - } else { - global[method] = function () { - return clock[method].apply(clock, arguments); - }; - - for (var prop in clock[method]) { - if (clock[method].hasOwnProperty(prop)) { - global[method][prop] = clock[method][prop]; - } - } - } - - global[method].clock = clock; - } - - sinon.useFakeTimers = function useFakeTimers(now) { - var clock = sinon.clock.create(now); - clock.restore = restore; - clock.methods = Array.prototype.slice.call(arguments, - typeof now == "number" ? 1 : 0); - - if (clock.methods.length === 0) { - clock.methods = methods; - } - - for (var i = 0, l = clock.methods.length; i < l; i++) { - stubGlobal(clock.methods[i], clock); - } - - return clock; - }; -}(typeof global != "undefined" && typeof global !== "function" ? global : this)); - -sinon.timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined), - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date -}; - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Minimal Event interface implementation - * - * Original implementation by Sven Fuchs: https://gist.github.com/995028 - * Modifications and tests by Christian Johansen. - * - * @author Sven Fuchs (svenfuchs@artweb-design.de) - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2011 Sven Fuchs, Christian Johansen - */ - -if (typeof sinon == "undefined") { - this.sinon = {}; -} - -(function () { - var push = [].push; - - sinon.Event = function Event(type, bubbles, cancelable, target) { - this.initEvent(type, bubbles, cancelable, target); - }; - - sinon.Event.prototype = { - initEvent: function(type, bubbles, cancelable, target) { - this.type = type; - this.bubbles = bubbles; - this.cancelable = cancelable; - this.target = target; - }, - - stopPropagation: function () {}, - - preventDefault: function () { - this.defaultPrevented = true; - } - }; - - sinon.EventTarget = { - addEventListener: function addEventListener(event, listener) { - this.eventListeners = this.eventListeners || {}; - this.eventListeners[event] = this.eventListeners[event] || []; - push.call(this.eventListeners[event], listener); - }, - - removeEventListener: function removeEventListener(event, listener) { - var listeners = this.eventListeners && this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }, - - dispatchEvent: function dispatchEvent(event) { - var type = event.type; - var listeners = this.eventListeners && this.eventListeners[type] || []; - - for (var i = 0; i < listeners.length; i++) { - if (typeof listeners[i] == "function") { - listeners[i].call(this, event); - } else { - listeners[i].handleEvent(event); - } - } - - return !!event.defaultPrevented; - } - }; -}()); - -/** - * @depend ../../sinon.js - * @depend event.js - */ -/*jslint eqeqeq: false, onevar: false*/ -/*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ -/** - * Fake XMLHttpRequest object - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -// wrapper for global -(function(global) { - if (typeof sinon === "undefined") { - global.sinon = {}; - } - - var supportsProgress = typeof ProgressEvent !== "undefined"; - var supportsCustomEvent = typeof CustomEvent !== "undefined"; - sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest }; - var xhr = sinon.xhr; - xhr.GlobalXMLHttpRequest = global.XMLHttpRequest; - xhr.GlobalActiveXObject = global.ActiveXObject; - xhr.supportsActiveX = typeof xhr.GlobalActiveXObject != "undefined"; - xhr.supportsXHR = typeof xhr.GlobalXMLHttpRequest != "undefined"; - xhr.workingXHR = xhr.supportsXHR ? xhr.GlobalXMLHttpRequest : xhr.supportsActiveX - ? function() { return new xhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0") } : false; - xhr.supportsCORS = 'withCredentials' in (new sinon.xhr.GlobalXMLHttpRequest()); - - /*jsl:ignore*/ - var unsafeHeaders = { - "Accept-Charset": true, - "Accept-Encoding": true, - "Connection": true, - "Content-Length": true, - "Cookie": true, - "Cookie2": true, - "Content-Transfer-Encoding": true, - "Date": true, - "Expect": true, - "Host": true, - "Keep-Alive": true, - "Referer": true, - "TE": true, - "Trailer": true, - "Transfer-Encoding": true, - "Upgrade": true, - "User-Agent": true, - "Via": true - }; - /*jsl:end*/ - - function FakeXMLHttpRequest() { - this.readyState = FakeXMLHttpRequest.UNSENT; - this.requestHeaders = {}; - this.requestBody = null; - this.status = 0; - this.statusText = ""; - this.upload = new UploadProgress(); - if (sinon.xhr.supportsCORS) { - this.withCredentials = false; - } - - - var xhr = this; - var events = ["loadstart", "load", "abort", "loadend"]; - - function addEventListener(eventName) { - xhr.addEventListener(eventName, function (event) { - var listener = xhr["on" + eventName]; - - if (listener && typeof listener == "function") { - listener(event); - } - }); - } - - for (var i = events.length - 1; i >= 0; i--) { - addEventListener(events[i]); - } - - if (typeof FakeXMLHttpRequest.onCreate == "function") { - FakeXMLHttpRequest.onCreate(this); - } - } - - // An upload object is created for each - // FakeXMLHttpRequest and allows upload - // events to be simulated using uploadProgress - // and uploadError. - function UploadProgress() { - this.eventListeners = { - "progress": [], - "load": [], - "abort": [], - "error": [] - } - } - - UploadProgress.prototype.addEventListener = function(event, listener) { - this.eventListeners[event].push(listener); - }; - - UploadProgress.prototype.removeEventListener = function(event, listener) { - var listeners = this.eventListeners[event] || []; - - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] == listener) { - return listeners.splice(i, 1); - } - } - }; - - UploadProgress.prototype.dispatchEvent = function(event) { - var listeners = this.eventListeners[event.type] || []; - - for (var i = 0, listener; (listener = listeners[i]) != null; i++) { - listener(event); - } - }; - - function verifyState(xhr) { - if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { - throw new Error("INVALID_STATE_ERR"); - } - - if (xhr.sendFlag) { - throw new Error("INVALID_STATE_ERR"); - } - } - - // filtering to enable a white-list version of Sinon FakeXhr, - // where whitelisted requests are passed through to real XHR - function each(collection, callback) { - if (!collection) return; - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } - } - function some(collection, callback) { - for (var index = 0; index < collection.length; index++) { - if(callback(collection[index]) === true) return true; - } - return false; - } - // largest arity in XHR is 5 - XHR#open - var apply = function(obj,method,args) { - switch(args.length) { - case 0: return obj[method](); - case 1: return obj[method](args[0]); - case 2: return obj[method](args[0],args[1]); - case 3: return obj[method](args[0],args[1],args[2]); - case 4: return obj[method](args[0],args[1],args[2],args[3]); - case 5: return obj[method](args[0],args[1],args[2],args[3],args[4]); - } - }; - - FakeXMLHttpRequest.filters = []; - FakeXMLHttpRequest.addFilter = function(fn) { - this.filters.push(fn) - }; - var IE6Re = /MSIE 6/; - FakeXMLHttpRequest.defake = function(fakeXhr,xhrArgs) { - var xhr = new sinon.xhr.workingXHR(); - each(["open","setRequestHeader","send","abort","getResponseHeader", - "getAllResponseHeaders","addEventListener","overrideMimeType","removeEventListener"], - function(method) { - fakeXhr[method] = function() { - return apply(xhr,method,arguments); - }; - }); - - var copyAttrs = function(args) { - each(args, function(attr) { - try { - fakeXhr[attr] = xhr[attr] - } catch(e) { - if(!IE6Re.test(navigator.userAgent)) throw e; - } - }); - }; - - var stateChange = function() { - fakeXhr.readyState = xhr.readyState; - if(xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) { - copyAttrs(["status","statusText"]); - } - if(xhr.readyState >= FakeXMLHttpRequest.LOADING) { - copyAttrs(["responseText"]); - } - if(xhr.readyState === FakeXMLHttpRequest.DONE) { - copyAttrs(["responseXML"]); - } - if(fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr }); - }; - if(xhr.addEventListener) { - for(var event in fakeXhr.eventListeners) { - if(fakeXhr.eventListeners.hasOwnProperty(event)) { - each(fakeXhr.eventListeners[event],function(handler) { - xhr.addEventListener(event, handler); - }); - } - } - xhr.addEventListener("readystatechange",stateChange); - } else { - xhr.onreadystatechange = stateChange; - } - apply(xhr,"open",xhrArgs); - }; - FakeXMLHttpRequest.useFilters = false; - - function verifyRequestSent(xhr) { - if (xhr.readyState == FakeXMLHttpRequest.DONE) { - throw new Error("Request done"); - } - } - - function verifyHeadersReceived(xhr) { - if (xhr.async && xhr.readyState != FakeXMLHttpRequest.HEADERS_RECEIVED) { - throw new Error("No headers received"); - } - } - - function verifyResponseBodyType(body) { - if (typeof body != "string") { - var error = new Error("Attempted to respond to fake XMLHttpRequest with " + - body + ", which is not a string."); - error.name = "InvalidBodyException"; - throw error; - } - } - - sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { - async: true, - - open: function open(method, url, async, username, password) { - this.method = method; - this.url = url; - this.async = typeof async == "boolean" ? async : true; - this.username = username; - this.password = password; - this.responseText = null; - this.responseXML = null; - this.requestHeaders = {}; - this.sendFlag = false; - if(sinon.FakeXMLHttpRequest.useFilters === true) { - var xhrArgs = arguments; - var defake = some(FakeXMLHttpRequest.filters,function(filter) { - return filter.apply(this,xhrArgs) - }); - if (defake) { - return sinon.FakeXMLHttpRequest.defake(this,arguments); - } - } - this.readyStateChange(FakeXMLHttpRequest.OPENED); - }, - - readyStateChange: function readyStateChange(state) { - this.readyState = state; - - if (typeof this.onreadystatechange == "function") { - try { - this.onreadystatechange(); - } catch (e) { - sinon.logError("Fake XHR onreadystatechange handler", e); - } - } - - this.dispatchEvent(new sinon.Event("readystatechange")); - - switch (this.readyState) { - case FakeXMLHttpRequest.DONE: - this.dispatchEvent(new sinon.Event("load", false, false, this)); - this.dispatchEvent(new sinon.Event("loadend", false, false, this)); - this.upload.dispatchEvent(new sinon.Event("load", false, false, this)); - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", {loaded: 100, total: 100})); - } - break; - } - }, - - setRequestHeader: function setRequestHeader(header, value) { - verifyState(this); - - if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) { - throw new Error("Refused to set unsafe header \"" + header + "\""); - } - - if (this.requestHeaders[header]) { - this.requestHeaders[header] += "," + value; - } else { - this.requestHeaders[header] = value; - } - }, - - // Helps testing - setResponseHeaders: function setResponseHeaders(headers) { - this.responseHeaders = {}; - - for (var header in headers) { - if (headers.hasOwnProperty(header)) { - this.responseHeaders[header] = headers[header]; - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED); - } else { - this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED; - } - }, - - // Currently treats ALL data as a DOMString (i.e. no Document) - send: function send(data) { - verifyState(this); - - if (!/^(get|head)$/i.test(this.method)) { - if (this.requestHeaders["Content-Type"]) { - var value = this.requestHeaders["Content-Type"].split(";"); - this.requestHeaders["Content-Type"] = value[0] + ";charset=utf-8"; - } else { - this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; - } - - this.requestBody = data; - } - - this.errorFlag = false; - this.sendFlag = this.async; - this.readyStateChange(FakeXMLHttpRequest.OPENED); - - if (typeof this.onSend == "function") { - this.onSend(this); - } - - this.dispatchEvent(new sinon.Event("loadstart", false, false, this)); - }, - - abort: function abort() { - this.aborted = true; - this.responseText = null; - this.errorFlag = true; - this.requestHeaders = {}; - - if (this.readyState > sinon.FakeXMLHttpRequest.UNSENT && this.sendFlag) { - this.readyStateChange(sinon.FakeXMLHttpRequest.DONE); - this.sendFlag = false; - } - - this.readyState = sinon.FakeXMLHttpRequest.UNSENT; - - this.dispatchEvent(new sinon.Event("abort", false, false, this)); - - this.upload.dispatchEvent(new sinon.Event("abort", false, false, this)); - - if (typeof this.onerror === "function") { - this.onerror(); - } - }, - - getResponseHeader: function getResponseHeader(header) { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return null; - } - - if (/^Set-Cookie2?$/i.test(header)) { - return null; - } - - header = header.toLowerCase(); - - for (var h in this.responseHeaders) { - if (h.toLowerCase() == header) { - return this.responseHeaders[h]; - } - } - - return null; - }, - - getAllResponseHeaders: function getAllResponseHeaders() { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return ""; - } - - var headers = ""; - - for (var header in this.responseHeaders) { - if (this.responseHeaders.hasOwnProperty(header) && - !/^Set-Cookie2?$/i.test(header)) { - headers += header + ": " + this.responseHeaders[header] + "\r\n"; - } - } - - return headers; - }, - - setResponseBody: function setResponseBody(body) { - verifyRequestSent(this); - verifyHeadersReceived(this); - verifyResponseBodyType(body); - - var chunkSize = this.chunkSize || 10; - var index = 0; - this.responseText = ""; - - do { - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.LOADING); - } - - this.responseText += body.substring(index, index + chunkSize); - index += chunkSize; - } while (index < body.length); - - var type = this.getResponseHeader("Content-Type"); - - if (this.responseText && - (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) { - try { - this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText); - } catch (e) { - // Unable to parse XML - no biggie - } - } - - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.DONE); - } else { - this.readyState = FakeXMLHttpRequest.DONE; - } - }, - - respond: function respond(status, headers, body) { - this.status = typeof status == "number" ? status : 200; - this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; - this.setResponseHeaders(headers || {}); - this.setResponseBody(body || ""); - }, - - uploadProgress: function uploadProgress(progressEventRaw) { - if (supportsProgress) { - this.upload.dispatchEvent(new ProgressEvent("progress", progressEventRaw)); - } - }, - - uploadError: function uploadError(error) { - if (supportsCustomEvent) { - this.upload.dispatchEvent(new CustomEvent("error", {"detail": error})); - } - } - }); - - sinon.extend(FakeXMLHttpRequest, { - UNSENT: 0, - OPENED: 1, - HEADERS_RECEIVED: 2, - LOADING: 3, - DONE: 4 - }); - - // Borrowed from JSpec - FakeXMLHttpRequest.parseXML = function parseXML(text) { - var xmlDoc; - - if (typeof DOMParser != "undefined") { - var parser = new DOMParser(); - xmlDoc = parser.parseFromString(text, "text/xml"); - } else { - xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); - xmlDoc.async = "false"; - xmlDoc.loadXML(text); - } - - return xmlDoc; - }; - - FakeXMLHttpRequest.statusCodes = { - 100: "Continue", - 101: "Switching Protocols", - 200: "OK", - 201: "Created", - 202: "Accepted", - 203: "Non-Authoritative Information", - 204: "No Content", - 205: "Reset Content", - 206: "Partial Content", - 300: "Multiple Choice", - 301: "Moved Permanently", - 302: "Found", - 303: "See Other", - 304: "Not Modified", - 305: "Use Proxy", - 307: "Temporary Redirect", - 400: "Bad Request", - 401: "Unauthorized", - 402: "Payment Required", - 403: "Forbidden", - 404: "Not Found", - 405: "Method Not Allowed", - 406: "Not Acceptable", - 407: "Proxy Authentication Required", - 408: "Request Timeout", - 409: "Conflict", - 410: "Gone", - 411: "Length Required", - 412: "Precondition Failed", - 413: "Request Entity Too Large", - 414: "Request-URI Too Long", - 415: "Unsupported Media Type", - 416: "Requested Range Not Satisfiable", - 417: "Expectation Failed", - 422: "Unprocessable Entity", - 500: "Internal Server Error", - 501: "Not Implemented", - 502: "Bad Gateway", - 503: "Service Unavailable", - 504: "Gateway Timeout", - 505: "HTTP Version Not Supported" - }; - - sinon.useFakeXMLHttpRequest = function () { - sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) { - if (xhr.supportsXHR) { - global.XMLHttpRequest = xhr.GlobalXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = xhr.GlobalActiveXObject; - } - - delete sinon.FakeXMLHttpRequest.restore; - - if (keepOnCreate !== true) { - delete sinon.FakeXMLHttpRequest.onCreate; - } - }; - if (xhr.supportsXHR) { - global.XMLHttpRequest = sinon.FakeXMLHttpRequest; - } - - if (xhr.supportsActiveX) { - global.ActiveXObject = function ActiveXObject(objId) { - if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { - - return new sinon.FakeXMLHttpRequest(); - } - - return new xhr.GlobalActiveXObject(objId); - }; - } - - return sinon.FakeXMLHttpRequest; - }; - - sinon.FakeXMLHttpRequest = FakeXMLHttpRequest; - -})(typeof global === "object" ? global : this); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_xml_http_request.js - */ -/*jslint eqeqeq: false, onevar: false, regexp: false, plusplus: false*/ -/*global module, require, window*/ -/** - * The Sinon "server" mimics a web server that receives requests from - * sinon.FakeXMLHttpRequest and provides an API to respond to those requests, - * both synchronously and asynchronously. To respond synchronuously, canned - * answers have to be provided upfront. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof sinon == "undefined") { - var sinon = {}; -} - -sinon.fakeServer = (function () { - var push = [].push; - function F() {} - - function create(proto) { - F.prototype = proto; - return new F(); - } - - function responseArray(handler) { - var response = handler; - - if (Object.prototype.toString.call(handler) != "[object Array]") { - response = [200, {}, handler]; - } - - if (typeof response[2] != "string") { - throw new TypeError("Fake server response body should be string, but was " + - typeof response[2]); - } - - return response; - } - - var wloc = typeof window !== "undefined" ? window.location : {}; - var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host); - - function matchOne(response, reqMethod, reqUrl) { - var rmeth = response.method; - var matchMethod = !rmeth || rmeth.toLowerCase() == reqMethod.toLowerCase(); - var url = response.url; - var matchUrl = !url || url == reqUrl || (typeof url.test == "function" && url.test(reqUrl)); - - return matchMethod && matchUrl; - } - - function match(response, request) { - var requestUrl = request.url; - - if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) { - requestUrl = requestUrl.replace(rCurrLoc, ""); - } - - if (matchOne(response, this.getHTTPMethod(request), requestUrl)) { - if (typeof response.response == "function") { - var ru = response.url; - var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []); - return response.response.apply(response, args); - } - - return true; - } - - return false; - } - - function log(response, request) { - var str; - - str = "Request:\n" + sinon.format(request) + "\n\n"; - str += "Response:\n" + sinon.format(response) + "\n\n"; - - sinon.log(str); - } - - return { - create: function () { - var server = create(this); - this.xhr = sinon.useFakeXMLHttpRequest(); - server.requests = []; - - this.xhr.onCreate = function (xhrObj) { - server.addRequest(xhrObj); - }; - - return server; - }, - - addRequest: function addRequest(xhrObj) { - var server = this; - push.call(this.requests, xhrObj); - - xhrObj.onSend = function () { - server.handleRequest(this); - - if (server.autoRespond && !server.responding) { - setTimeout(function () { - server.responding = false; - server.respond(); - }, server.autoRespondAfter || 10); - - server.responding = true; - } - }; - }, - - getHTTPMethod: function getHTTPMethod(request) { - if (this.fakeHTTPMethods && /post/i.test(request.method)) { - var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); - return !!matches ? matches[1] : request.method; - } - - return request.method; - }, - - handleRequest: function handleRequest(xhr) { - if (xhr.async) { - if (!this.queue) { - this.queue = []; - } - - push.call(this.queue, xhr); - } else { - this.processRequest(xhr); - } - }, - - respondWith: function respondWith(method, url, body) { - if (arguments.length == 1 && typeof method != "function") { - this.response = responseArray(method); - return; - } - - if (!this.responses) { this.responses = []; } - - if (arguments.length == 1) { - body = method; - url = method = null; - } - - if (arguments.length == 2) { - body = url; - url = method; - method = null; - } - - push.call(this.responses, { - method: method, - url: url, - response: typeof body == "function" ? body : responseArray(body) - }); - }, - - respond: function respond() { - if (arguments.length > 0) this.respondWith.apply(this, arguments); - var queue = this.queue || []; - var requests = queue.splice(0); - var request; - - while(request = requests.shift()) { - this.processRequest(request); - } - }, - - processRequest: function processRequest(request) { - try { - if (request.aborted) { - return; - } - - var response = this.response || [404, {}, ""]; - - if (this.responses) { - for (var l = this.responses.length, i = l - 1; i >= 0; i--) { - if (match.call(this, this.responses[i], request)) { - response = this.responses[i].response; - break; - } - } - } - - if (request.readyState != 4) { - log(response, request); - - request.respond(response[0], response[1], response[2]); - } - } catch (e) { - sinon.logError("Fake server request processing", e); - } - }, - - restore: function restore() { - return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments); - } - }; -}()); - -if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon; -} - -/** - * @depend fake_server.js - * @depend fake_timers.js - */ -/*jslint browser: true, eqeqeq: false, onevar: false*/ -/*global sinon*/ -/** - * Add-on for sinon.fakeServer that automatically handles a fake timer along with - * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery - * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead, - * it polls the object for completion with setInterval. Dispite the direct - * motivation, there is nothing jQuery-specific in this file, so it can be used - * in any environment where the ajax implementation depends on setInterval or - * setTimeout. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function () { - function Server() {} - Server.prototype = sinon.fakeServer; - - sinon.fakeServerWithClock = new Server(); - - sinon.fakeServerWithClock.addRequest = function addRequest(xhr) { - if (xhr.async) { - if (typeof setTimeout.clock == "object") { - this.clock = setTimeout.clock; - } else { - this.clock = sinon.useFakeTimers(); - this.resetClock = true; - } - - if (!this.longestTimeout) { - var clockSetTimeout = this.clock.setTimeout; - var clockSetInterval = this.clock.setInterval; - var server = this; - - this.clock.setTimeout = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetTimeout.apply(this, arguments); - }; - - this.clock.setInterval = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetInterval.apply(this, arguments); - }; - } - } - - return sinon.fakeServer.addRequest.call(this, xhr); - }; - - sinon.fakeServerWithClock.respond = function respond() { - var returnVal = sinon.fakeServer.respond.apply(this, arguments); - - if (this.clock) { - this.clock.tick(this.longestTimeout || 0); - this.longestTimeout = 0; - - if (this.resetClock) { - this.clock.restore(); - this.resetClock = false; - } - } - - return returnVal; - }; - - sinon.fakeServerWithClock.restore = function restore() { - if (this.clock) { - this.clock.restore(); - } - - return sinon.fakeServer.restore.apply(this, arguments); - }; -}()); - -/** - * @depend ../sinon.js - * @depend collection.js - * @depend util/fake_timers.js - * @depend util/fake_server_with_clock.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global require, module*/ -/** - * Manages fake collections as well as fake utilities such as Sinon's - * timers and fake XHR implementation in one convenient object. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -if (typeof module !== 'undefined' && module.exports) { - var sinon = require("../sinon"); - sinon.extend(sinon, require("./util/fake_timers")); -} - -(function () { - var push = [].push; - - function exposeValue(sandbox, config, key, value) { - if (!value) { - return; - } - - if (config.injectInto && !(key in config.injectInto) ) { - config.injectInto[key] = value; - } else { - push.call(sandbox.args, value); - } - } - - function prepareSandboxFromConfig(config) { - var sandbox = sinon.create(sinon.sandbox); - - if (config.useFakeServer) { - if (typeof config.useFakeServer == "object") { - sandbox.serverPrototype = config.useFakeServer; - } - - sandbox.useFakeServer(); - } - - if (config.useFakeTimers) { - if (typeof config.useFakeTimers == "object") { - sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers); - } else { - sandbox.useFakeTimers(); - } - } - - return sandbox; - } - - sinon.sandbox = sinon.extend(sinon.create(sinon.collection), { - useFakeTimers: function useFakeTimers() { - this.clock = sinon.useFakeTimers.apply(sinon, arguments); - - return this.add(this.clock); - }, - - serverPrototype: sinon.fakeServer, - - useFakeServer: function useFakeServer() { - var proto = this.serverPrototype || sinon.fakeServer; - - if (!proto || !proto.create) { - return null; - } - - this.server = proto.create(); - return this.add(this.server); - }, - - inject: function (obj) { - sinon.collection.inject.call(this, obj); - - if (this.clock) { - obj.clock = this.clock; - } - - if (this.server) { - obj.server = this.server; - obj.requests = this.server.requests; - } - - return obj; - }, - - create: function (config) { - if (!config) { - return sinon.create(sinon.sandbox); - } - - var sandbox = prepareSandboxFromConfig(config); - sandbox.args = sandbox.args || []; - var prop, value, exposed = sandbox.inject({}); - - if (config.properties) { - for (var i = 0, l = config.properties.length; i < l; i++) { - prop = config.properties[i]; - value = exposed[prop] || prop == "sandbox" && sandbox; - exposeValue(sandbox, config, prop, value); - } - } else { - exposeValue(sandbox, config, "sandbox", value); - } - - return sandbox; - } - }); - - sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer; - - if (typeof module !== 'undefined' && module.exports) { - module.exports = sinon.sandbox; - } -}()); - -/** - * @depend ../sinon.js - * @depend stub.js - * @depend mock.js - * @depend sandbox.js - */ -/*jslint eqeqeq: false, onevar: false, forin: true, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Test function, sandboxes fakes - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function test(callback) { - var type = typeof callback; - - if (type != "function") { - throw new TypeError("sinon.test needs to wrap a test function, got " + type); - } - - return function () { - var config = sinon.getConfig(sinon.config); - config.injectInto = config.injectIntoThis && this || config.injectInto; - var sandbox = sinon.sandbox.create(config); - var exception, result; - var args = Array.prototype.slice.call(arguments).concat(sandbox.args); - - try { - result = callback.apply(this, args); - } catch (e) { - exception = e; - } - - if (typeof exception !== "undefined") { - sandbox.restore(); - throw exception; - } - else { - sandbox.verifyAndRestore(); - } - - return result; - }; - } - - test.config = { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }; - - if (commonJSModule) { - module.exports = test; - } else { - sinon.test = test; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend test.js - */ -/*jslint eqeqeq: false, onevar: false, eqeqeq: false*/ -/*global module, require, sinon*/ -/** - * Test case, sandboxes all test functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon) { - var commonJSModule = typeof module !== 'undefined' && module.exports; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon || !Object.prototype.hasOwnProperty) { - return; - } - - function createTest(property, setUp, tearDown) { - return function () { - if (setUp) { - setUp.apply(this, arguments); - } - - var exception, result; - - try { - result = property.apply(this, arguments); - } catch (e) { - exception = e; - } - - if (tearDown) { - tearDown.apply(this, arguments); - } - - if (exception) { - throw exception; - } - - return result; - }; - } - - function testCase(tests, prefix) { - /*jsl:ignore*/ - if (!tests || typeof tests != "object") { - throw new TypeError("sinon.testCase needs an object with test functions"); - } - /*jsl:end*/ - - prefix = prefix || "test"; - var rPrefix = new RegExp("^" + prefix); - var methods = {}, testName, property, method; - var setUp = tests.setUp; - var tearDown = tests.tearDown; - - for (testName in tests) { - if (tests.hasOwnProperty(testName)) { - property = tests[testName]; - - if (/^(setUp|tearDown)$/.test(testName)) { - continue; - } - - if (typeof property == "function" && rPrefix.test(testName)) { - method = property; - - if (setUp || tearDown) { - method = createTest(property, setUp, tearDown); - } - - methods[testName] = sinon.test(method); - } else { - methods[testName] = tests[testName]; - } - } - } - - return methods; - } - - if (commonJSModule) { - module.exports = testCase; - } else { - sinon.testCase = testCase; - } -}(typeof sinon == "object" && sinon || null)); - -/** - * @depend ../sinon.js - * @depend stub.js - */ -/*jslint eqeqeq: false, onevar: false, nomen: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Assertions matching the test spy retrieval interface. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ - -(function (sinon, global) { - var commonJSModule = typeof module !== "undefined" && module.exports; - var slice = Array.prototype.slice; - var assert; - - if (!sinon && commonJSModule) { - sinon = require("../sinon"); - } - - if (!sinon) { - return; - } - - function verifyIsStub() { - var method; - - for (var i = 0, l = arguments.length; i < l; ++i) { - method = arguments[i]; - - if (!method) { - assert.fail("fake is not a spy"); - } - - if (typeof method != "function") { - assert.fail(method + " is not a function"); - } - - if (typeof method.getCall != "function") { - assert.fail(method + " is not stubbed"); - } - } - } - - function failAssertion(object, msg) { - object = object || global; - var failMethod = object.fail || assert.fail; - failMethod.call(object, msg); - } - - function mirrorPropAsAssertion(name, method, message) { - if (arguments.length == 2) { - message = method; - method = name; - } - - assert[name] = function (fake) { - verifyIsStub(fake); - - var args = slice.call(arguments, 1); - var failed = false; - - if (typeof method == "function") { - failed = !method(fake); - } else { - failed = typeof fake[method] == "function" ? - !fake[method].apply(fake, args) : !fake[method]; - } - - if (failed) { - failAssertion(this, fake.printf.apply(fake, [message].concat(args))); - } else { - assert.pass(name); - } - }; - } - - function exposedName(prefix, prop) { - return !prefix || /^fail/.test(prop) ? prop : - prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); - } - - assert = { - failException: "AssertError", - - fail: function fail(message) { - var error = new Error(message); - error.name = this.failException || assert.failException; - - throw error; - }, - - pass: function pass(assertion) {}, - - callOrder: function assertCallOrder() { - verifyIsStub.apply(null, arguments); - var expected = "", actual = ""; - - if (!sinon.calledInOrder(arguments)) { - try { - expected = [].join.call(arguments, ", "); - var calls = slice.call(arguments); - var i = calls.length; - while (i) { - if (!calls[--i].called) { - calls.splice(i, 1); - } - } - actual = sinon.orderByFirstCall(calls).join(", "); - } catch (e) { - // If this fails, we'll just fall back to the blank string - } - - failAssertion(this, "expected " + expected + " to be " + - "called in order but were called as " + actual); - } else { - assert.pass("callOrder"); - } - }, - - callCount: function assertCallCount(method, count) { - verifyIsStub(method); - - if (method.callCount != count) { - var msg = "expected %n to be called " + sinon.timesInWords(count) + - " but was called %c%C"; - failAssertion(this, method.printf(msg)); - } else { - assert.pass("callCount"); - } - }, - - expose: function expose(target, options) { - if (!target) { - throw new TypeError("target is null or undefined"); - } - - var o = options || {}; - var prefix = typeof o.prefix == "undefined" && "assert" || o.prefix; - var includeFail = typeof o.includeFail == "undefined" || !!o.includeFail; - - for (var method in this) { - if (method != "export" && (includeFail || !/^(fail)/.test(method))) { - target[exposedName(prefix, method)] = this[method]; - } - } - - return target; - } - }; - - mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); - mirrorPropAsAssertion("notCalled", function (spy) { return !spy.called; }, - "expected %n to not have been called but was called %c%C"); - mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); - mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); - mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); - mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); - mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t"); - mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); - mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); - mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); - mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); - mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); - mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); - mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); - mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); - mirrorPropAsAssertion("threw", "%n did not throw exception%C"); - mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); - - if (commonJSModule) { - module.exports = assert; - } else { - sinon.assert = assert; - } -}(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global)); - -return sinon;}.call(typeof window != 'undefined' && window || {})); diff --git a/test/utils/stub_index_pattern.js b/test/utils/stub_index_pattern.js deleted file mode 100644 index 751e302b1bae0..0000000000000 --- a/test/utils/stub_index_pattern.js +++ /dev/null @@ -1,45 +0,0 @@ -define(function (require) { - return function (Private) { - var _ = require('lodash'); - var sinon = require('sinon/sinon'); - var IndexedArray = require('utils/indexed_array/index'); - var IndexPattern = require('components/index_patterns/_index_pattern'); - var fieldFormats = Private(require('registry/field_formats')); - var flattenHit = Private(require('components/index_patterns/_flatten_hit')); - var formatHit = require('components/index_patterns/_format_hit'); - var getComputedFields = require('components/index_patterns/_get_computed_fields'); - - var Field = Private(require('components/index_patterns/_field')); - - function StubIndexPattern(pattern, timeField, fields) { - this.id = pattern; - this.popularizeField = sinon.spy(); - this.timeFieldName = timeField; - this.getNonScriptedFields = sinon.spy(); - this.getScriptedFields = sinon.spy(); - this.metaFields = ['_id', '_type', '_source']; - this.fieldFormatMap = {}; - this.routes = IndexPattern.prototype.routes; - - this.toIndexList = _.constant([pattern]); - this.getComputedFields = _.bind(getComputedFields, this); - this.flattenHit = flattenHit(this); - this.formatHit = formatHit(this, fieldFormats.getDefaultInstance('string')); - this.formatField = this.formatHit.formatField; - - this._indexFields = function () { - this.fields = new IndexedArray({ - index: ['name'], - group: ['type'], - initialSet: fields.map(function (field) { - return new Field(this, field); - }, this) - }); - }; - - this._indexFields(); - } - - return StubIndexPattern; - }; -});