Skip to content

Commit

Permalink
Merge pull request #162 from joola/feature/#161
Browse files Browse the repository at this point in the history
#161 changes to support new results format.
  • Loading branch information
itayw committed Jan 25, 2015
2 parents 7b644d4 + e26d7e2 commit 5222919
Show file tree
Hide file tree
Showing 14 changed files with 13,732 additions and 8,863 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addons:
sauce_connect:
username: joola-io
access_key: 8ac80e3d-093f-4292-aa48-95f5656b0785

before_script:
- npm install -g grunt-cli

Expand Down
18,104 changes: 10,941 additions & 7,163 deletions build/release/joola.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/release/joola.min.css

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions build/release/joola.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/release/joola.min.js.map

Large diffs are not rendered by default.

4,303 changes: 2,683 additions & 1,620 deletions build/temp/joola.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/temp/meta.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "joola.sdk",
"preferGlobal": false,
"version": "0.8.1",
"version": "0.8.2-develop",
"author": "Joola <[email protected]>",
"description": "joola's software development kit (SDK)",
"engine": "node >= 0.10.x",
Expand Down
5 changes: 4 additions & 1 deletion src/lib/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ api.getJSON = function (options, objOptions, callback) {
joola.io.socket.emit(routeID, objOptions);
joola.events.emit('rpc:start', 1);
joola.events.emit('bandwidth', lengthInUtf8Bytes(JSON.stringify(objOptions)));
if (objOptions && (objOptions.realtime || (objOptions.options && Array.isArray(objOptions.options) && objOptions.options.length > 0 && objOptions.options[0].realtime))) {
var shouldOn = objOptions && (objOptions.realtime || (objOptions.options && Array.isArray(objOptions.options) && objOptions.options.length > 0 && objOptions.options[0].realtime));
if (objOptions && objOptions.options && objOptions.options.realtime)
shouldOn = true;
if (shouldOn) {
joola.io.socket.on(routeID + ':done', processResponse);
}
else {
Expand Down
53 changes: 30 additions & 23 deletions src/lib/viz/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ var Canvas = module.exports = function (options, callback) {
};

this.prepareQuery = function (query, dates) {
var _query;
if (!dates)
dates = {};
var _query = ce.extend({}, query);
if (Array.isArray(query))
_query = [ce.extend({}, query[0])];
else {
_query = ce.extend({}, query);
_query = [_query];
}
if (self.options.query) {
_query = joola.common._extend(ce.clone(self.options.query), _query);
_query[0] = joola.common._extend(ce.clone(self.options.query), _query[0]);
}
if (!Array.isArray(_query))
_query = [_query];

if (_query[0].dimensions && _query[0].dimensions.length > 0 && _query[0].dimensions && _query[0].dimensions.length > 0) {
_query[0].dimensions.forEach(function (dimension, i) {
var key;
Expand Down Expand Up @@ -122,6 +127,7 @@ var Canvas = module.exports = function (options, callback) {
cquery.interval = self.options.datepicker._interval;
_query = [_query[0], cquery];
}

return _query;
};

Expand All @@ -139,7 +145,6 @@ var Canvas = module.exports = function (options, callback) {
filters.push(filter);
}
});
console.log('build filter', filters);
return filters;
};

Expand Down Expand Up @@ -204,7 +209,6 @@ var Canvas = module.exports = function (options, callback) {
break;
case 'bartable':
new joola.viz.BarTable(viz).on('select', function (point, dimensionkey) {
console.log('selected');
if (Array.isArray(point))
point = point[0];
var filter = self.buildFilter(point, dimensionkey);
Expand Down Expand Up @@ -263,7 +267,6 @@ var Canvas = module.exports = function (options, callback) {
break;
case 'bartable':
new joola.viz.BarTable(viz).on('select', function (point, dimensionkey) {
console.log('selected');
if (Array.isArray(point))
point = point[0];
var filter = self.buildFilter(point, dimensionkey);
Expand Down Expand Up @@ -340,23 +343,25 @@ var Canvas = module.exports = function (options, callback) {
//here we go
joola.viz.initialize(self, options || {});

self.draw();
joola.viz.onscreen.push(self);
if (!self.options.canvas) {
var elem = $$(self.options.$container).parent();
if (elem.attr('jio-type') == 'canvas') {
self.options.canvas = $$(elem).Canvas();
self.draw(null, function (err, ref) {
if (err)
return callback(err);
joola.viz.onscreen.push(self);
if (!self.options.canvas) {
var elem = $$(self.options.$container).parent();
if (elem.attr('jio-type') == 'canvas') {
self.options.canvas = $$(elem).Canvas();
}
}
if (self.options.canvas) {
self.options.canvas.addVisualization(self);
}
}
if (self.options.canvas) {
self.options.canvas.addVisualization(self);
}

//wrap up
self.initialized = true;
if (typeof callback === 'function')
return callback(null, self);

//wrap up
self.initialized = true;
if (typeof callback === 'function')
return callback(null, ref);
});
return self;
};

Expand All @@ -377,7 +382,9 @@ joola.events.on('core.init.finish', function () {
result = new joola.viz.Canvas(options, function (err, canvas) {
if (err)
throw new Error('Failed to initialize canvas.', err);
canvas.draw(options, callback);
//canvas.draw(options, callback);
if (callback)
return callback(null, canvas);
}).options.$container;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viz/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var DatePicker = module.exports = function (options, callback) {
if (options.fromdate)
this.base_fromdate = new Date(options.fromdate);
else
this.base_fromdate = self.addDays(this.base_todate, -30);
this.base_fromdate = self.addDays(this.base_todate, -90);

if (this.base_fromdate < this.min_date) {
this.base_fromdate = new Date();//this.min_date.fixDate(true, false);
Expand Down
11 changes: 11 additions & 0 deletions src/lib/viz/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,11 @@ var Table = module.exports = function (options, callback) {
var $td = $$('<td class="metricbox metric"></td>');
$metric_tr.append($td);
var _query = ce.clone(self.options.query);

_query.forEach(function (q) {
delete q.sort;
delete q.order;
delete q.orderby;
q.dimensions = [];
q.metrics = [m];
if (!q.filter)
Expand Down Expand Up @@ -728,6 +732,13 @@ var Table = module.exports = function (options, callback) {
self.options.pickers.add_metric.css = 'table-picker';
self.options.pickers.add_metric.container = $add_metric_picker.get(0);
self.options.pickers.add_metric.caption = self.options.pickers.add_metric.caption || 'Add metric...';
self.options.query[0].metrics.forEach(function (m, i) {
if (typeof m !== 'object')
m = {key: m};
m.collection = m.collection || self.options.query[0].collection;
self.options.query[0].metrics[i] = m;
});
console.log(self.options.query[0].metrics);
self.options.pickers.add_metric.disabled = self.options.query[0].metrics;
self.add_metric_picker = new joola.viz.MetricPicker(self.options.pickers.add_metric).on('change', function (metric) {
self.options.query.forEach(function (q) {
Expand Down
74 changes: 40 additions & 34 deletions src/lib/viz/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ var Timeline = module.exports = function (options, callback) {

var checkExists = function (timestampDimension, documents, date) {
return _.find(documents, function (document) {
if (!document.values[timestampDimension.key])
if (!document[timestampDimension.key])
return;

try {
var _date = new Date(date);
var _basedate = new Date(document.values[timestampDimension.key]);
var _basedate = new Date(document[timestampDimension.key]);

switch (interval) {
case 'month':
Expand All @@ -206,8 +206,8 @@ var Timeline = module.exports = function (options, callback) {
var fill = function (resultRow, row, timestampDimension) {
Object.keys(resultRow).forEach(function (key) {
if (key !== timestampDimension.key) {
row.values[key] = 0;
row.fvalues[key] = 0;
row[key] = 0;
//row.fvalues[key] = 0;
}
});
};
Expand All @@ -216,12 +216,12 @@ var Timeline = module.exports = function (options, callback) {
if (result.documents.length === 0) {
result.documents.push({values: {}, fvalues: {}});
result.dimensions.forEach(function (d) {
result.documents[0].values[d.name] = null;
result.documents[0].fvalues[d.name] = null;
result.documents[0][d.name] = null;
//result.documents[0].fvalues[d.name] = null;
});
result.metrics.forEach(function (m) {
result.documents[0].values[m.name] = null;
result.documents[0].fvalues[m.name] = null;
result.documents[0][m.name] = null;
//result.documents[0].fvalues[m.name] = null;
});
}

Expand All @@ -239,8 +239,8 @@ var Timeline = module.exports = function (options, callback) {
interval = interval === 'ddate' ? 'day' : (interval || 'day');
if (!query.timeframe) {
query.timeframe = {};
query.timeframe.start = result.documents[result.documents.length - 1].values.timestamp;
query.timeframe.end = result.documents[0].values.timestamp;
query.timeframe.start = result.documents[result.documents.length - 1].timestamp;
query.timeframe.end = result.documents[0].timestamp;
}

var counter = 0;
Expand Down Expand Up @@ -270,9 +270,9 @@ var Timeline = module.exports = function (options, callback) {
if (!exists) {
//_d.setHours(_d.getHours() + (offset * -1));
exists = {values: {}, fvalues: {}};
exists.values[timestampDimension.key] = _d.toISOString();
exists.fvalues[timestampDimension.key] = _d.toISOString();
fill(result.documents[0].values, exists, timestampDimension);
exists[timestampDimension.key] = _d.toISOString();
//exists.fvalues[timestampDimension.key] = _d.toISOString();
fill(result.documents[0], exists, timestampDimension);
}
fixed.push(exists);
}
Expand Down Expand Up @@ -301,30 +301,30 @@ var Timeline = module.exports = function (options, callback) {
color: joola.colors[seriesIndex]
};
documents.forEach(function (document, docIndex) {
var x = document.fvalues[dimensions[0].key];
var x = document[dimensions[0].key];
var nameBased = true;
if (dimensions[0].datatype === 'date') {
x = new Date(document.fvalues[dimensions[0].key]);
x = new Date(document[dimensions[0].key]);
nameBased = false;
}

if (nameBased) {
series[seriesIndex].data.push({
name: x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
y: document[metrics[index].key] ? document[metrics[index].key] : 0
});
}
else {
if (seriesIndex === 0) {
series[seriesIndex].data.push({
x: x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
y: document[metrics[index].key] ? document[metrics[index].key] : 0
});
}
else {
series[seriesIndex].data.push({
x: series[0].data[docIndex].x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
y: document[metrics[index].key] ? document[metrics[index].key] : 0
});
}
}
Expand Down Expand Up @@ -375,6 +375,7 @@ var Timeline = module.exports = function (options, callback) {

this.draw = function (options, callback) {
self.chartOptions = joola.common._mixin({}, self.options.chart);
self.options.$container.empty();
self.options.$container.append(self.options.template || self.template());
self.options.$container.find('.caption').text(self.options.caption || '');

Expand Down Expand Up @@ -607,23 +608,25 @@ var Timeline = module.exports = function (options, callback) {
//we call the core initialize option
joola.viz.initialize(self, options || {});

self.draw();
joola.viz.onscreen.push(self);
if (!self.options.canvas) {
var elem = $$(self.options.$container).parent();
if (elem.attr('jio-type') == 'canvas') {
self.options.canvas = $$(elem).Canvas();
self.draw(null, function (err, ref) {
if (err)
return callback(err);
joola.viz.onscreen.push(self);
if (!self.options.canvas) {
var elem = $$(self.options.$container).parent();
if (elem.attr('jio-type') == 'canvas') {
self.options.canvas = $$(elem).Canvas();
}
}
if (self.options.canvas) {
self.options.canvas.addVisualization(self);
}
}
if (self.options.canvas) {
self.options.canvas.addVisualization(self);
}

//wrap up
self.initialized = true;
if (typeof callback === 'function')
return callback(null, self);

//wrap up
self.initialized = true;
if (typeof callback === 'function')
return callback(null, ref);
});
return self;
};

Expand Down Expand Up @@ -657,7 +660,10 @@ joola.events.on('core.init.finish', function () {
result = new joola.viz.Timeline(options, function (err, timeline) {
if (err)
throw err;
timeline.draw(options, callback);
//timeline.draw(options, callback);
if (callback)
return callback(null, timeline);

}).options.$container;
}
else {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/viz/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ viz.initialize = function (self, options, callback) {
}
}
if (self.options.query) {
//console.log('qqq', self.options.query);
viz.fetch(self, self.options.query, function () {
if (callback && typeof callback === 'function')
return callback(null, self);
Expand Down Expand Up @@ -195,12 +196,12 @@ viz.fetch = function (context, query, callback) {
};
var key = '';
message.dimensions.forEach(function (d) {
key += doc.raw.values[d.key];
doc.dimensions[d.key] = doc.raw.values[d.key];
key += doc.raw[d.key];
doc.dimensions[d.key] = doc.raw[d.key];
doc.meta[d.key] = d;
});
message.metrics.forEach(function (m) {
doc.metrics[m.key] = doc.raw.values[m.key];
doc.metrics[m.key] = doc.raw[m.key];
doc.meta[m.key] = m;
});
doc.key = joola.common.hash(key);
Expand Down

0 comments on commit 5222919

Please sign in to comment.