-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2796e77
commit 3ffdc35
Showing
24 changed files
with
1,349 additions
and
1,423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default function (kibana) { | ||
|
||
return new kibana.Plugin({ | ||
uiExports: { | ||
visTypes: ['plugins/choropleth/choropleth_vis'] | ||
} | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "choropleth", | ||
"version": "kibana" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.choropleth-vis { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/core_plugins/choropleth/public/choropleth_controller.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div ng-controller="KbnChoroplethController" class="choropleth-vis"> | ||
|
||
</div> |
98 changes: 98 additions & 0 deletions
98
src/core_plugins/choropleth/public/choropleth_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import uiModules from 'ui/modules'; | ||
import _ from 'lodash'; | ||
import AggConfigResult from 'ui/vis/agg_config_result'; | ||
import KibanaMap from 'ui/vis_maps/kibana_map.js'; | ||
import FilterBarFilterBarClickHandlerProvider from 'ui/filter_bar/filter_bar_click_handler'; | ||
import colorramps from 'ui/vislib/components/color/colormaps'; | ||
|
||
const module = uiModules.get('kibana/choropleth', ['kibana']); | ||
module.controller('KbnChoroplethController', function ($scope, $element, Private, getAppState, tilemapSettings) { | ||
|
||
const containerNode = $element[0]; | ||
const kibanaMap = new KibanaMap(containerNode); | ||
const url = tilemapSettings.getUrl(); | ||
const options = tilemapSettings.getTMSOptions(); | ||
kibanaMap.setBaseLayer({ | ||
baseLayerType: 'tms', | ||
options: { url, ...options } | ||
}); | ||
|
||
const filterBarClickHandler = Private(FilterBarFilterBarClickHandlerProvider); | ||
|
||
kibanaMap.on('choropleth:select', function (event) { | ||
const appState = getAppState(); | ||
const clickHandler = filterBarClickHandler(appState); | ||
const aggs = $scope.vis.aggs.getResponseAggs(); | ||
const aggConfigResult = new AggConfigResult(aggs[0], false, event, event); | ||
clickHandler({ point: { aggConfigResult: aggConfigResult } }); | ||
}); | ||
|
||
$scope.$watch('esResponse', async function (response) { | ||
|
||
|
||
const termAggId = _.first(_.pluck($scope.vis.aggs.bySchemaName.segment, 'id')); | ||
|
||
let results; | ||
if (!response || !response.aggregations) { | ||
results = []; | ||
} else { | ||
const metricsAgg = _.first($scope.vis.aggs.bySchemaName.metric); | ||
const buckets = response.aggregations[termAggId].buckets; | ||
results = buckets.map((bucket) => { | ||
return { | ||
term: bucket.key, | ||
value: getValue(metricsAgg, bucket) | ||
}; | ||
}); | ||
} | ||
|
||
|
||
|
||
const options = $scope.vis.params; | ||
// if (!options.selectedLayer.url || !options.selectedJoinField) { | ||
// console.log('invalid selection');//todo: fix this | ||
// return; | ||
// } | ||
|
||
if (!options.selectedJoinField) { | ||
options.selectedJoinField = options.selectedLayer.fields[0]; | ||
} | ||
|
||
kibanaMap.setChoroplethLayer(options.selectedLayer.url, options.selectedJoinField); | ||
kibanaMap.setChoroplethMetrics(results); | ||
kibanaMap.resize(); | ||
|
||
}); | ||
|
||
$scope.$watch('vis.params', (options) => { | ||
if (!options.selectedJoinField) { | ||
options.selectedJoinField = options.selectedLayer.fields[0]; | ||
} | ||
kibanaMap.setChoroplethLayer(options.selectedLayer.url, options.selectedJoinField); | ||
kibanaMap.setChoroplethColorRamp(colorramps[options.colorSchema]); | ||
kibanaMap.resize(); | ||
}); | ||
|
||
$scope.$watch(getContainerSize, _.debounce(() => { | ||
kibanaMap.resize(); | ||
}, 500, { trailing: true }), true); | ||
|
||
function getContainerSize() { | ||
return { width: $element.width(), height: $element.height() }; | ||
} | ||
|
||
}); | ||
|
||
|
||
function getValue(metricsAgg, bucket) { | ||
let size = metricsAgg.getValue(bucket); | ||
if (typeof size !== 'number' || isNaN(size)) { | ||
try { | ||
size = bucket[1].values[0].value;//lift out first value (e.g. median aggregations return as array) | ||
} catch (e) { | ||
size = 1;//punt | ||
} | ||
} | ||
return size; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'plugins/choropleth/choropleth.less'; | ||
import 'plugins/choropleth/choropleth_controller'; | ||
import 'plugins/choropleth/choropleth_vis_params'; | ||
import TemplateVisTypeTemplateVisTypeProvider from 'ui/template_vis_type/template_vis_type'; | ||
import VisSchemasProvider from 'ui/vis/schemas'; | ||
import choroplethTemplate from 'plugins/choropleth/choropleth_controller.html'; | ||
import visTypes from 'ui/registry/vis_types'; | ||
import colorramps from 'ui/vislib/components/color/colormaps'; | ||
import vectorMaps from 'plugins/choropleth/vector_maps'; | ||
|
||
visTypes.register(function ChoroplethProvider(Private) { | ||
const TemplateVisType = Private(TemplateVisTypeTemplateVisTypeProvider); | ||
const Schemas = Private(VisSchemasProvider); | ||
|
||
return new TemplateVisType({ | ||
name: 'choropleth', | ||
title: 'Vector Map', | ||
implementsRenderComplete: true, | ||
description: 'Show metrics on a thematic map. Darker colors represent higher values.', | ||
icon: 'fa-globe', | ||
template: choroplethTemplate, | ||
params: { | ||
defaults: { | ||
colorSchema: 'Yellow to Red', | ||
selectedLayer: vectorMaps.Countries, | ||
selectedJoinField: vectorMaps.Countries.fields[0] | ||
}, | ||
colorSchemas: Object.keys(colorramps), | ||
vectorMaps: vectorMaps, | ||
editor: '<choropleth-vis-params></choropleth-vis-params>' | ||
}, | ||
schemas: new Schemas([ | ||
{ | ||
group: 'metrics', | ||
name: 'metric', | ||
title: '', | ||
min: 1, | ||
max: 1, | ||
aggFilter: ['!std_dev', '!percentiles', '!percentile_ranks'], | ||
defaults: [ | ||
{ schema: 'metric', type: 'count' } | ||
] | ||
}, | ||
{ | ||
group: 'buckets', | ||
name: 'segment', | ||
icon: 'fa fa-globe', | ||
title: 'shape field', | ||
min: 1, | ||
max: 1, | ||
aggFilter: ['terms'] | ||
} | ||
]) | ||
}); | ||
}); | ||
|
||
|
46 changes: 46 additions & 0 deletions
46
src/core_plugins/choropleth/public/choropleth_vis_params.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="form-group"> | ||
<div class="kuiSideBarFormRow"> | ||
<label class="kuiSideBarFormRow__label" for="colorSchema"> | ||
Color Schema | ||
</label> | ||
<div class="kuiSideBarFormRow__control"> | ||
<select | ||
id="colorSchema" | ||
class="kuiSelect kuiSideBarSelect" | ||
ng-model="vis.params.colorSchema" | ||
ng-options="mode for mode in vis.type.params.colorSchemas" | ||
></select> | ||
</div> | ||
</div> | ||
<div class="kuiSideBarFormRow"> | ||
<label class="kuiSideBarFormRow__label" for="vectorMap"> | ||
Vector map | ||
</label> | ||
<div class="kuiSideBarFormRow__control"> | ||
<select | ||
id="vectorMap" | ||
class="kuiSelect kuiSideBarSelect" | ||
ng-model="vis.params.selectedLayer" | ||
ng-options="layer for (layer, meta) in vis.type.params.vectorMaps" | ||
></select> | ||
</div> | ||
</div> | ||
|
||
<div class="kuiSideBarFormRow"> | ||
<label class="kuiSideBarFormRow__label" for="joinField"> | ||
Join on field | ||
</label> | ||
<div class="kuiSideBarFormRow__control"> | ||
<select id="joinField" | ||
ng-model="vis.params.selectedJoinField" | ||
ng-options="field for field in vis.params.selectedLayer.fields" | ||
ng-init="vis.params.selectedJoinField=vis.params.selectedLayer.fields[0]" | ||
> | ||
<option value=''>Select</option></select> | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
|
||
</div> |
13 changes: 13 additions & 0 deletions
13
src/core_plugins/choropleth/public/choropleth_vis_params.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import uiModules from 'ui/modules'; | ||
import choroplethVisParamsTemplate from 'plugins/choropleth/choropleth_vis_params.html'; | ||
|
||
uiModules.get('kibana/choropleth') | ||
.directive('choroplethVisParams', function () { | ||
return { | ||
restrict: 'E', | ||
template: choroplethVisParamsTemplate, | ||
link: function ($scope, $element) { | ||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const vectorMaps = { | ||
'Countries': { | ||
url: '../plugins/choropleth/data/world_countries.geojson', | ||
fields: ['iso'] | ||
}, | ||
'States': { | ||
url: '../plugins/choropleth/data/us_states.geojson', | ||
fields: ['NAME'] | ||
} | ||
}; | ||
|
||
// const vectorMaps = { | ||
// 'Countries': ['iso'], | ||
// 'States': ['name', 'abbr'] | ||
// }; | ||
// | ||
// const vectorMaps = [{ | ||
// name: 'Countries', | ||
// url: '../plugins/choropleth/data/world_countries.geojson', | ||
// fields: ['iso'] | ||
// }, | ||
// { | ||
// name: 'States', | ||
// url: '../plugins/choropleth/data/us_states.geojson', | ||
// fields: ['name', 'abbr'] | ||
// }]; | ||
|
||
|
||
export default vectorMaps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import _ from 'lodash'; | ||
|
||
export default function () { | ||
|
||
return function ($state) { | ||
if (!_.isObject($state)) throw new Error('pushFilters requires a state object'); | ||
return function (filter, negate, index, filterId) { | ||
// Hierarchical and tabular data set their aggConfigResult parameter | ||
// differently because of how the point is rewritten between the two. So | ||
// we need to check if the point.orig is set, if not use try the point.aggConfigResult | ||
const filters = _.clone($state.filters || []); | ||
let position = -1; | ||
if (filterId) { | ||
filters.forEach((filter, ind) => { | ||
if (filterId === filter.meta._id) { | ||
position = ind; | ||
} | ||
}); | ||
|
||
if (position > -1) { | ||
const pendingFilter = { meta: { negate: negate, index: index, _id: filterId } }; | ||
_.extend(pendingFilter, filter); | ||
filters[position] = pendingFilter; | ||
$state.filters = filters; | ||
return false; | ||
} | ||
} | ||
|
||
const pendingFilter = { meta: { negate: negate, index: index, _id: filterId } }; | ||
_.extend(pendingFilter, filter); | ||
filters.push(pendingFilter); | ||
$state.filters = filters; | ||
return true; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.