From 67883ff9331df41e1bc98cfa0e9a3f82b1efda94 Mon Sep 17 00:00:00 2001 From: brozelle Date: Wed, 24 Jan 2018 16:05:50 -0500 Subject: [PATCH] Added Filtering by Bucket when clicking on marker --- package.json | 26 ++++++++++++++++++++++++-- public/kbn_dotplot_controller.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a84a287..0dff414 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "version": "kibana" }, "authors": [ - "David Moreno Lumbreras " + "David Moreno Lumbreras " ], "license": "Apache-2.0", "repository": { @@ -15,6 +15,28 @@ "dependencies": { "plotly.js": "1.29.3", "randomcolor": "0.5.0" - + }, + "scripts": { + "lint": "eslint **/*.js", + "start": "plugin-helpers start", + "test:server": "plugin-helpers test:server", + "test:browser": "plugin-helpers test:browser", + "build": "plugin-helpers build", + "postinstall": "plugin-helpers postinstall", + "gather-info": "node gather-info.js" + }, + "devDependencies": { + "@elastic/eslint-config-kibana": "^0.14.0", + "@elastic/eslint-import-resolver-kibana": "^0.9.0", + "@elastic/plugin-helpers": "^7.1.3", + "babel-eslint": "^8.0.2", + "eslint": "^4.11.0", + "eslint-plugin-babel": "^4.1.1", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-jest": "^21.3.2", + "eslint-plugin-mocha": "^4.9.0", + "eslint-plugin-prefer-object-spread": "^1.2.1", + "eslint-plugin-react": "^7.0.1", + "expect.js": "^0.3.1" } } diff --git a/public/kbn_dotplot_controller.js b/public/kbn_dotplot_controller.js index d3fe849..c256118 100644 --- a/public/kbn_dotplot_controller.js +++ b/public/kbn_dotplot_controller.js @@ -94,7 +94,7 @@ module.controller('KbnDotplotVisController', function ($scope, $element, Private var step = max - min var chartDiff = chartMax - chartMin } - console.log(resp) + //console.log(resp) var dataParsed = resp.tables[0].rows.map(function(bucket) { //If two buckets selected @@ -155,7 +155,32 @@ module.controller('KbnDotplotVisController', function ($scope, $element, Private data = data.concat(dataParsed[i]) } - Plotly.newPlot('dotplot-graph', data, layout, {showLink: false}) + var dotplot = document.getElementById('dotplot-graph'); + + Plotly.newPlot('dotplot-graph', data, layout, {showLink: false}); + + dotplot.on('plotly_click', function(data){ + var name=''; + for(var i=0; i < data.points.length; i++){ + name = data.points[i].data.name; + }; + + if (name != null && name.length > 0) { + var fieldAggName = $scope.vis.aggs.bySchemaName['field'][0].params.field.displayName; + if($scope.vis.aggs.bySchemaName['field'][1]){ + fieldAggName = $scope.vis.aggs.bySchemaName['field'][1].params.field.displayName; + } + var match = {}; + match[fieldAggName] = { "query": name, "type": "phrase" }; + var filters = [ + { + "query": { "match": match }, + meta: { index: $scope.vis.indexPattern.id, negate: false, disabled: false } + } + ]; + $scope.vis.API.queryFilter.addFilters(filters); + } + }) } });