Skip to content

Commit

Permalink
Merge branch 'master' into fix/elastic#1903
Browse files Browse the repository at this point in the history
  • Loading branch information
stormpython committed Nov 25, 2014
2 parents e54e641 + e244fd9 commit 7cdc6af
Show file tree
Hide file tree
Showing 31 changed files with 1,778 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/kibana/components/agg_response/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ define(function (require) {
var groupMap = chartData.splits || (chartData.splits = {});

result.buckets.forEach(function (bucket) {
var bucketId = bucket.key + (col.field ? ': ' + col.field.name : '');
var bucketId = bucket.key + (col.field ? ': ' + col.field.displayName : '');
var group = groupMap[bucketId];

if (!group) {
Expand Down Expand Up @@ -167,7 +167,7 @@ define(function (require) {
}

if (config.field) {
config.label = config.field.name;
config.label = config.field.displayName;
return;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ define(function (require) {
// record the the depth
var depth = item.depth - 1;

// Using the aggConfig determin what the field name is. If the aggConfig
// Using the aggConfig determine what the field name is. If the aggConfig
// doesn't exist (which means it's an _all agg) then use the level for
// the field name
var col = item.aggConfig;
var field = (col && col.params && col.params.field && col.params.field.name)
var field = (col && col.params && col.params.field && col.params.field.displayName)
|| (col && col.label)
|| ('level ' + item.depth);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define(function (require) {
var agg = firstAgg._next;
var split = buildSplit(agg, metric, bucket[agg.id]);
// Since splits display labels we need to set it.
split.label = bucket.key + ': ' + firstAgg.params.field.name;
split.label = bucket.key + ': ' + firstAgg.params.field.displayName;
split.tooltipFormatter = tooltipFormatter(raw.columns);
return split;
});
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
title: 'Histogram',
ordered: {},
makeLabel: function (aggConfig) {
return aggConfig.params.field.name;
return aggConfig.params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
name: 'range',
title: 'Range',
makeLabel: function (aggConfig) {
return aggConfig.params.field.name + ' ranges';
return aggConfig.params.field.displayName + ' ranges';
},
params: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(function (require) {
name: 'significant_terms',
title: 'Significant Terms',
makeLabel: function (aggConfig) {
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.name;
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
title: 'Terms',
makeLabel: function (aggConfig) {
var params = aggConfig.params;
return params.order.display + ' ' + params.size + ' ' + params.field.name;
return params.order.display + ' ' + params.size + ' ' + params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/controls/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
required
ng-model="params.field"
ng-options="
field as field.name group by field.type for field in aggConfig.vis.indexPattern.fields.raw
field as field.displayName group by field.type for field in aggConfig.vis.indexPattern.fields.raw
| fieldType: aggParam.filterFieldTypes
| filter: { indexed: true }
| orderBy: ['type', 'name']
Expand Down
10 changes: 5 additions & 5 deletions src/kibana/components/agg_types/metric_aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(function (require) {
name: 'avg',
title: 'Average',
makeLabel: function (aggConfig) {
return 'Average ' + aggConfig.params.field.name;
return 'Average ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -28,7 +28,7 @@ define(function (require) {
name: 'sum',
title: 'Sum',
makeLabel: function (aggConfig) {
return 'Sum of ' + aggConfig.params.field.name;
return 'Sum of ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -41,7 +41,7 @@ define(function (require) {
name: 'min',
title: 'Min',
makeLabel: function (aggConfig) {
return 'Min ' + aggConfig.params.field.name;
return 'Min ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -54,7 +54,7 @@ define(function (require) {
name: 'max',
title: 'Max',
makeLabel: function (aggConfig) {
return 'Max ' + aggConfig.params.field.name;
return 'Max ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -67,7 +67,7 @@ define(function (require) {
name: 'cardinality',
title: 'Unique count',
makeLabel: function (aggConfig) {
return 'Unique count of ' + aggConfig.params.field.name;
return 'Unique count of ' + aggConfig.params.field.displayName;
},
params: [
{
Expand Down
20 changes: 14 additions & 6 deletions src/kibana/components/index_patterns/_index_pattern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function (require) {
return function IndexPatternFactory(Private, timefilter, configFile, Notifier) {
return function IndexPatternFactory(Private, timefilter, configFile, Notifier, shortDotsFilter) {
var _ = require('lodash');
var angular = require('angular');
var errors = require('errors');
Expand Down Expand Up @@ -95,11 +95,19 @@ define(function (require) {
field.count = field.count || 0;

// non-enumerable type so that it does not get included in the JSON
Object.defineProperty(field, 'format', {
enumerable: false,
get: function () {
var formatName = self.customFormats && self.customFormats[field.name];
return formatName ? fieldFormats.byName[formatName] : fieldFormats.defaultByType[field.type];
Object.defineProperties(field, {
format: {
enumerable: false,
get: function () {
var formatName = self.customFormats && self.customFormats[field.name];
return formatName ? fieldFormats.byName[formatName] : fieldFormats.defaultByType[field.type];
}
},
displayName: {
enumerable: false,
get: function () {
return shortDotsFilter(field.name);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions src/kibana/components/index_patterns/index_patterns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand Down
16 changes: 16 additions & 0 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,16 @@ define(function (require) {
* @returns {Number} Y stack max value
*/
Data.prototype.getYStackMax = function (series) {
var isOrdered = (this.data.ordered && this.data.ordered.date);
var minDate = isOrdered ? this.data.ordered.min : undefined;
var maxDate = isOrdered ? this.data.ordered.max : undefined;

return d3.max(this.stackData(series), function (data) {
return d3.max(data, function (d) {
if (isOrdered) {
return (d.x >= minDate && d.x <= maxDate) ? d.y0 + d.y : undefined;
}

return d.y0 + d.y;
});
});
Expand All @@ -281,8 +289,16 @@ define(function (require) {
* @returns {Number} Y domain max value
*/
Data.prototype.getYMax = function (series) {
var isOrdered = (this.data.ordered && this.data.ordered.date);
var minDate = isOrdered ? this.data.ordered.min : undefined;
var maxDate = isOrdered ? this.data.ordered.max : undefined;

return d3.max(series, function (data) {
return d3.max(data, function (d) {
if (isOrdered) {
return (d.x >= minDate && d.x <= maxDate) ? d.y : undefined;
}

return d.y;
});
});
Expand Down
16 changes: 14 additions & 2 deletions src/kibana/components/vislib/lib/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,23 @@ define(function (require) {
var brush = d3.svg.brush()
.x(xScale)
.on('brushend', function brushEnd() {

// Assumes data is selected at the chart level
// In this case, the number of data objects should always be 1
var data = d3.select(this).data()[0];
var isTimeSeries = (data.ordered && data.ordered.date);

// Allows for brushing on d3.scale.ordinal()
var selected = xScale.domain().filter(function (d) {
return (brush.extent()[0] <= xScale(d)) && (xScale(d) <= brush.extent()[1]);
});
var range = isTimeSeries ? brush.extent() : selected;

return dispatch.brush({
range: brush.extent(),
range: range,
config: attr,
e: d3.event,
data: d3.event.sourceEvent.target.__data__
data: data
});
});

Expand Down
17 changes: 12 additions & 5 deletions src/kibana/components/vislib/visualizations/area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,19 @@ define(function (require) {
* @param element {D3.UpdateSelection} SVG circles
* @returns {D3.Selection} circles with event listeners attached
*/
AreaChart.prototype.addCircleEvents = function (element) {
AreaChart.prototype.addCircleEvents = function (element, svg) {
var events = this.events;
var isBrushable = (typeof events.dispatch.on('brush') === 'function');
var brush = isBrushable ? events.addBrushEvent(svg) : undefined;
var hover = events.addHoverEvent();
var click = events.addClickEvent();
var attachedEvents = element.call(hover).call(click);

if (isBrushable) {
attachedEvents.call(brush);
}

return element
.call(events.addHoverEvent())
.call(events.addClickEvent());
return attachedEvents;
};

/**
Expand Down Expand Up @@ -310,7 +317,7 @@ define(function (require) {
circles = self.addCircles(svg, layers);

// add click and hover events to circles
self.addCircleEvents(circles);
self.addCircleEvents(circles, svg);

// chart base line
var line = svg.append('line')
Expand Down
17 changes: 12 additions & 5 deletions src/kibana/components/vislib/visualizations/line_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ define(function (require) {
* @param element{D3.UpdateSelection} Reference to SVG circle
* @returns {D3.Selection} SVG circles with event listeners attached
*/
LineChart.prototype.addCircleEvents = function (element) {
LineChart.prototype.addCircleEvents = function (element, svg) {
var events = this.events;
var isBrushable = (typeof events.dispatch.on('brush') === 'function');
var brush = isBrushable ? events.addBrushEvent(svg) : undefined;
var hover = events.addHoverEvent();
var click = events.addClickEvent();
var attachedEvents = element.call(hover).call(click);

return element
.call(events.addHoverEvent())
.call(events.addClickEvent());
if (isBrushable) {
attachedEvents.call(brush);
}

return attachedEvents;
};

/**
Expand Down Expand Up @@ -255,7 +262,7 @@ define(function (require) {
self.addClipPath(svg, width, height);
lines = self.addLines(svg, data.series);
circles = self.addCircles(svg, layers);
self.addCircleEvents(circles);
self.addCircleEvents(circles, svg);

var line = svg
.append('line')
Expand Down
64 changes: 42 additions & 22 deletions src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ define(function (require) {
}
});

app.controller('discover', function ($scope, config, courier, $route, $window, Notifier, AppState, timefilter, Promise, Private, kbnUrl, highlightTags) {
app.controller('discover', function ($scope, config, courier, $route, $window, Notifier,
AppState, timefilter, Promise, Private, kbnUrl, highlightTags) {

var Vis = Private(require('components/vis/vis'));
var docTitle = Private(require('components/doc_title/doc_title'));
Expand Down Expand Up @@ -508,6 +509,7 @@ define(function (require) {
_.defaults(field, currentState[field.name]);
// clone the field and add it's display prop
var clone = _.assign({}, field, {
displayName: field.displayName, // this is a getter, so we need to copy it over manually
format: field.format, // this is a getter, so we need to copy it over manually
display: columnObjects[field.name] || false,
rowCount: $scope.rows ? $scope.rows.fieldCounts[field.name] : 0
Expand All @@ -522,37 +524,55 @@ define(function (require) {
}

// TODO: On array fields, negating does not negate the combination, rather all terms
$scope.filterQuery = function (field, value, operation) {
value = _.isArray(value) ? value : [value];
$scope.filterQuery = function (field, values, operation) {
values = _.isArray(values) ? values : [values];

var indexPattern = $scope.searchSource.get('index');
indexPattern.popularizeField(field, 1);

// Grap the filters from the searchSource and ensure it's an array
var filters = _.flatten([$state.filters], true);

_.each(value, function (clause) {
var previous = _.find(filters, function (item) {
if (item && item.query) {
return item.query.match[field].query === clause;
} else if (item && item.exists && field === '_exists_') {
return item.exists.field === clause;
} else if (item && item.missing && field === '_missing_') {
return item.missing.field === clause;
_.each(values, function (value) {
var existing = _.find(filters, function (filter) {
if (!filter) return;

if (field === '_exists_' && filter.exists) {
return filter.exists.field === value;
}
});
if (!previous) {
var filter;
if (field === '_exists_') {
filter = { exists: { field: clause } };
} else if (field === '_missing_') {
filter = { missing: { field: clause } };
} else {
filter = { query: { match: {} } };
filter.negate = operation === '-';
filter.query.match[field] = { query: clause, type: 'phrase' };

if (field === '_missing_' && filter.missing) {
return filter.missing.field === value;
}

if (filter.query) {
return filter.query.match[field] && filter.query.match[field].query === value;
}
});

if (existing) return;

switch (field) {
case '_exists_':
filters.push({
exists: {
field: value
}
});
break;
case '_missing_':
filters.push({
missing: {
field: value
}
});
break;
default:
var filter = { query: { match: {} } };
filter.negate = operation === '-';
filter.query.match[field] = { query: value, type: 'phrase' };
filters.push(filter);
break;
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/kibana/plugins/discover/directives/table_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ define(function (require) {
var _ = require('lodash');
var module = require('modules').get('app/discover');

require('filters/short_dots');

module.directive('kbnTableHeader', function () {
var headerHtml = require('text!plugins/discover/partials/table_header.html');
return {
Expand Down
Loading

0 comments on commit 7cdc6af

Please sign in to comment.