Skip to content

Commit

Permalink
restored visualize app to it's previous working state, now backed by …
Browse files Browse the repository at this point in the history
…savedObject
  • Loading branch information
Spencer Alger committed Apr 15, 2014
1 parent b403ec3 commit 6900921
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 124 deletions.
15 changes: 8 additions & 7 deletions src/kibana/apps/visualize/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ define(function (require) {

$scope.refreshFields = function () {
$scope.fields = null;
vis.dataSource.clearFieldCache().then(getFields, notify.error);
vis.searchSource.clearFieldCache().then(getFields, notify.error);
};

function getFields() {
return vis.dataSource.getFields()
return vis.searchSource.getFields()
.then(function (fieldsHash) {
// create a sorted list of the fields for display purposes
$scope.fields = _(fieldsHash)
Expand All @@ -49,8 +49,8 @@ define(function (require) {
$scope.visConfigCategories = visConfigCategories;

$scope.$on('change:config.defaultIndex', function () {
if (!vis.dataSource.get('index')) {
vis.dataSource.index(config.get('defaultIndex'));
if (!vis.searchSource.get('index')) {
vis.searchSource.index(config.get('defaultIndex'));
getFields();
}
});
Expand All @@ -73,7 +73,8 @@ define(function (require) {
if (!config.dimension) {
// use the global aggregation if we don't have any dimensions
config.dimension = [{
agg: 'global'
agg: 'global',
aggParams: {}
}];
}

Expand All @@ -100,7 +101,7 @@ define(function (require) {
notify.log('config', config);
notify.log('aggs', dsl.aggs);

vis.dataSource.aggs(dsl.aggs);
vis.searchSource.aggs(dsl.aggs);
notify.event('update data source', true);
};

Expand All @@ -109,7 +110,7 @@ define(function (require) {
*********/
$scope.doVisualize = function () {
updateDataSource();
vis.dataSource.fetch();
vis.searchSource.fetch();
};
$scope.doSave = function () {
updateDataSource();
Expand Down
21 changes: 0 additions & 21 deletions src/kibana/apps/visualize/controllers/wizard.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/kibana/apps/visualize/directives/config_controlls.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
define(function (require) {
var app = require('modules').get('app/visualize');
var _ = require('lodash');
var aggs = require('../saved_visualizations/_aggs');

var templates = {
orderAndSize: require('text!../partials/controls/order_and_size.html'),
interval: require('text!../partials/controls/interval.html'),
globalLocal: require('text!../partials/controls/global_local.html')
};

app.directive('visConfigControls', function ($compile, visConfigCategories, aggs) {
app.directive('visConfigControls', function ($compile, visConfigCategories) {
return {
restrict: 'E',
scope: {
Expand Down
52 changes: 5 additions & 47 deletions src/kibana/apps/visualize/directives/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(function (require) {
function VisualizationDirective(createNotifier) {
return {
restrict: 'E',
template: '<div class="chart"></div>',
template: '<pre class="chart">{{ data | json }}</pre>',
scope: {
vis: '='
},
Expand All @@ -15,55 +15,13 @@ define(function (require) {
location: vis.type + ' visualization'
});

function renderData(data, $el) {
var splitBy, splits, inherit;

if (data.rows) {
splits = data.rows;
splitBy = 'height';
inherit = 'width';
}
else if (data.columns) {
splits = data.columns;
splitBy = 'width';
inherit = 'height';
}

if (splitBy && splits && inherit) {
var splitSize = $el[splitBy]() / splits.length;
var charts = splits.map(function (splitData) {
// create the element that will contain this splits data
var $splitEl = $(document.createElement('div'));

// set the height and width
$splitEl[splitBy](splitSize);
$splitEl[inherit]('100%');

// append it to the parent
$el.append($splitEl);

// render the splits data into the new $el
return renderData(splitData, $splitEl);
});
return charts;
}
else {
// we can ignore splits completely now
var chart = new k4d3.Chart($el.get(0), {
type: 'histogram'
});
chart.render(data);
return chart;
}
}

vis.dataSource.onResults().then(function onResults(resp) {
vis.searchSource.onResults().then(function onResults(resp) {
notify.event('render visualization');
$el.html('');
renderData(vis.buildChartDataFromResponse(resp), $el);
$scope.data = vis.buildChartDataFromResponse(resp);
notify.event('render visualization', true);

return vis.dataSource.onResults(onResults);
window.canvasVisSource = vis.searchSource;
return vis.searchSource.onResults().then(onResults);
}).catch(notify.fatal);
}
};
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions src/kibana/apps/visualize/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
define(function (require) {
require('css!./styles/main.css');

require('./controllers/wizard');
require('./controllers/editor');

require('./directives/config_category');
Expand All @@ -10,13 +9,13 @@ define(function (require) {

require('routes')
.when('/visualize', {
template: require('text!./wizard.html')
redirectTo: '/visualize/histogram'
})
.when('/visualize/:type/:id?', {
template: require('text!./editor.html'),
template: require('text!./index.html'),
resolve: {
vis: function ($route, savedVis) {
return savedVis.get($route.current.params.type, $route.current.params.id);
vis: function ($route, savedVisualizations) {
return savedVisualizations.get($route.current.params.type, $route.current.params.id);
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/apps/visualize/saved_visualizations/_aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ define(function (require) {
}
},
makeLabel: function (params) {
var order = _.find(aggs.params.order.options, { val: params.order._count });
var agg = aggs.byName.terms;
var order = _.find(agg.params.order.options, { val: params.order._count });
return order.display + ' ' + params.size + ' ' + params.field;
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
define(function (require) {

var converters = require('./resp_converters/index');
var aggs = require('./_aggs');

// private functionality for Vis.buildChartDataFromResp()
return function (createNotifier, aggs) {
return function (createNotifier) {
var notify = createNotifier();

return function (resp) {
Expand Down Expand Up @@ -151,6 +152,13 @@ define(function (require) {
};

if (resp.aggregations) {
if (!configs.length) {
configs.push({
categoryName: 'metric',
agg: aggs.byName.count.name,
label: aggs.byName.count.display
});
}
splitAndFlatten(chartData, resp.aggregations);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ define(function (require) {
field: config.field
};

// copy over the row if this is a split
if (config.categoryName === 'split') {
// copy over other properties based ont he category
switch (config.categoryName) {
case 'split':
validated.row = !!config.row;
break;
case 'group':
validated.global = !!config.global;
break;
}

// this function will move valus from config.* to validated.aggParams.* when they are
Expand Down
44 changes: 32 additions & 12 deletions src/kibana/apps/visualize/saved_visualizations/_saved_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,47 @@ define(function (require) {

var configCats = require('./_config_categories');
var aggs = require('./_aggs');
var typeDefs = require('./_type_defs');

require('services/root_search');

var module = require('modules').get('kibana/services');

module.factory('Vis', function (config, $injector, SavedObject, rootSearch, Promise, savedSearches) {
function Vis(id) {
module.factory('SavedVis', function (config, $injector, SavedObject, rootSearch, Promise, savedSearches) {
function SavedVis(type, id) {
var typeDef = typeDefs.byName[type];
if (!typeDef) throw new Error('Unknown visualization type: "' + type + '"');

SavedObject.call(this, {
type: 'visualization',

id: id,

mapping: {
stateJSON: 'string',
savedSearchId: 'string'
savedSearchId: 'string',
typeName: 'string',
},

defaults: {
stateJSON: '[]'
stateJSON: '{}',
typeName: type,
},

searchSource: true,

afterESResp: function setVisState(resp) {
afterESResp: function setVisState() {
var vis = this;
var state = {};

if (vis.stateJSON) try { state = JSON.parse(vis.stateJSON); } catch (e) {}

var parent = vis.savedSearch;
if (!parent || parent.id !== vis.savedSearchId) {
// returns a promise
parent = savedSearches.get(vis.savedSearchId);
var parent = rootSearch;
if (vis.savedSearchId) {
if (!vis.savedSearch || vis.savedSearch.id !== vis.savedSearchId) {
// returns a promise
parent = savedSearches.get(vis.savedSearchId);
}
}

configCats.forEach(function (category) {
Expand All @@ -53,7 +61,11 @@ define(function (require) {
return Promise.cast(parent)
.then(function (parent) {
vis.savedSearch = parent;
vis.searchSource.inherits(vis.savedSearch);

vis.searchSource
.inherits(vis.savedSearch)
.size(0);

vis._fillConfigsToMinimum();
// get and cache the field list
return vis.searchSource.getFields();
Expand Down Expand Up @@ -85,6 +97,14 @@ define(function (require) {
// satify the min count for each category
configCats.fetchOrder.forEach(function (category) {
var myCat = vis[category.name];

if (!myCat) {

myCat = _.defaults(typeDef.config[category.name] || {}, category.defaults);
myCat.configs = [];
vis[category.name] = myCat;
}

if (myCat.configs.length < myCat.min) {
_.times(myCat.min - myCat.configs.length, function () {
vis.addConfig(category.name);
Expand All @@ -107,8 +127,8 @@ define(function (require) {
*/
this.buildChartDataFromResponse = $injector.invoke(require('./_build_chart_data'));
}
inherits(Vis, SavedObject);
inherits(SavedVis, SavedObject);

return Vis;
return SavedVis;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ define(function (require) {
// index of y-axis
var iY = _.findIndex(columns, { categoryName: 'metric'});

// when we don't have an x-axis, just push everything into '_all'
if (iX === -1) {
iX = columns.push({
label: ''
}) - 1;
}

chart.xAxisLabel = columns[iX].label;
chart.yAxisLabel = columns[iY].label;

Expand Down Expand Up @@ -38,7 +45,7 @@ define(function (require) {
}

s.values.push({
x: row[iX],
x: row[iX] || '_all',
y: row[iY === -1 ? row.length - 1 : iY] // y-axis value
});
});
Expand Down
23 changes: 0 additions & 23 deletions src/kibana/apps/visualize/wizard.html

This file was deleted.

Loading

0 comments on commit 6900921

Please sign in to comment.