mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[discover] updated to use new Vis class
This commit is contained in:
parent
a60aa669b4
commit
b482d0e2cf
6 changed files with 46 additions and 45 deletions
|
@ -567,23 +567,24 @@ define(function (require) {
|
|||
// we shouldn't have a vis, delete it
|
||||
if (!$scope.opts.timefield && $scope.vis) {
|
||||
$scope.vis.destroy();
|
||||
$scope.searchSource.set('aggs', undefined);
|
||||
delete $scope.vis;
|
||||
}
|
||||
// we shouldn't have one, or already do, return whatever we already have
|
||||
if (!$scope.opts.timefield || $scope.vis) return Promise.resolve($scope.vis);
|
||||
|
||||
var vis = new Vis({
|
||||
searchSource: $scope.searchSource,
|
||||
// TODO: a legit way to update the index pattern
|
||||
$scope.vis = new Vis($scope.searchSource.get('index'), {
|
||||
type: 'histogram',
|
||||
listeners: {
|
||||
onClick: function (e) {
|
||||
click: function (e) {
|
||||
console.log(e);
|
||||
timefilter.time.from = moment(e.point.x);
|
||||
timefilter.time.to = moment(e.point.x + e.data.ordered.interval);
|
||||
timefilter.time.mode = 'absolute';
|
||||
$scope.$apply();
|
||||
},
|
||||
onBrush: function (e) {
|
||||
brush: function (e) {
|
||||
var from = moment(e.range[0]);
|
||||
var to = moment(e.range[1]);
|
||||
|
||||
|
@ -595,40 +596,35 @@ define(function (require) {
|
|||
$scope.$apply();
|
||||
}
|
||||
},
|
||||
config: {
|
||||
metric: {
|
||||
configs: [{
|
||||
agg: 'count',
|
||||
}]
|
||||
aggs: [
|
||||
{
|
||||
type: 'count',
|
||||
schema: 'metric'
|
||||
},
|
||||
segment: {
|
||||
configs: [{
|
||||
agg: 'date_histogram',
|
||||
{
|
||||
type: 'date_histogram',
|
||||
schema: 'segment',
|
||||
params: {
|
||||
field: $scope.opts.timefield,
|
||||
interval: $state.interval,
|
||||
min_doc_count: 0,
|
||||
}]
|
||||
},
|
||||
group: { configs: [] },
|
||||
split: { configs: [] },
|
||||
}
|
||||
interval: 'auto'
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
$scope.searchSource.aggs(function () {
|
||||
return $scope.vis.aggs.toDSL();
|
||||
});
|
||||
|
||||
// stash this promise so that other calls to setupVisualization will have to wait
|
||||
loadingVis = vis.init()
|
||||
.then(function () {
|
||||
// expose the vis so that the visualize directive can get started
|
||||
$scope.vis = vis;
|
||||
|
||||
// wait for visualize directive to emit that it's ready before resolving
|
||||
return new Promise(function (resolve) {
|
||||
$scope.$on('ready:vis', resolve);
|
||||
loadingVis = new Promise(function (resolve) {
|
||||
$scope.$on('ready:vis', function () {
|
||||
resolve($scope.vis);
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
.finally(function () {
|
||||
// clear the loading flag
|
||||
loadingVis = null;
|
||||
return vis;
|
||||
});
|
||||
|
||||
return loadingVis;
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<div class="spinner large"> </div>
|
||||
</div>
|
||||
|
||||
<visualize vis="vis" es-resp="mergedEsResp"></visualize>
|
||||
<visualize vis="vis" es-resp="mergedEsResp" search-source="searchSource"></visualize>
|
||||
</div>
|
||||
|
||||
<div class="discover-table"
|
||||
|
|
|
@ -89,12 +89,15 @@ define(function (require) {
|
|||
{
|
||||
name: 'extended_bounds',
|
||||
default: {},
|
||||
write: function (selection, output) {
|
||||
var bounds = timefilter.getBounds();
|
||||
output.params.extended_bounds = {
|
||||
min: bounds.min,
|
||||
max: bounds.max
|
||||
};
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* markdown
|
||||
|
||||
### Formatting a value
|
||||
To format a response value, you need to get ahold of the field list, which is usually available at `indexPattern.fields` or `indexPattern.fieldsByName`. When the indexPattern is not available, call `courier.getFieldsFor`. Each field object has a `format` property*, which is an object detailed in [_field_formats.js](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/components/index_patterns/_field_formats.js).
|
||||
To format a response value, you need to get ahold of the field list, which is usually available at `indexPattern.fields`. When the indexPattern is not available, call `courier.getFieldsFor`. Each field object has a `format` property*, which is an object detailed in [_field_formats.js](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/components/index_patterns/_field_formats.js).
|
||||
|
||||
Once you have the field that a response value came from, pass the value to `field.format.convert(value)` and a formatted string representation of the field will be returned.
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ define(function (require) {
|
|||
stack.push(key);
|
||||
var flattenKey = stack.join('.');
|
||||
|
||||
if (self.fieldsByName[flattenKey]) {
|
||||
if (self.fields.byName[flattenKey]) {
|
||||
flatObj[flattenKey] = obj[key];
|
||||
} else if (_.isObject(obj[key])) {
|
||||
flattenObj(obj[key]);
|
||||
|
|
|
@ -4,13 +4,15 @@ define(function (require) {
|
|||
describe('IndexPattern#flattenSearchResponse()', function () {
|
||||
|
||||
var indexPattern = {
|
||||
fieldsByName: {
|
||||
'message': { type: 'string' },
|
||||
'geo.coordinates': { type: 'geo_point' },
|
||||
'geo.dest': { type: 'string' },
|
||||
'geo.src': { type: 'string' },
|
||||
'bytes': { type: 'number' },
|
||||
'@timestamp': { type: 'date' }
|
||||
fields: {
|
||||
byName: {
|
||||
'message': { type: 'string' },
|
||||
'geo.coordinates': { type: 'geo_point' },
|
||||
'geo.dest': { type: 'string' },
|
||||
'geo.src': { type: 'string' },
|
||||
'bytes': { type: 'number' },
|
||||
'@timestamp': { type: 'date' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue