Skip to content

Commit

Permalink
#49 resolved. category based sparklines.
Browse files Browse the repository at this point in the history
  • Loading branch information
itayw committed Mar 25, 2014
1 parent 27589fb commit cd13149
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
49 changes: 26 additions & 23 deletions lib/viz/Sparkline.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ var Sparkline = module.exports = function (options, callback) {
self.realtimeQueries.push(message.realtime);

var series = self._super.makeChartTimelineSeries(message.dimensions, message.metrics, message.documents);
console.log(series);
if (!self.chartDrawn) {
var chartOptions = joolaio.common.extend({
title: {
text: null
},
chart: {
marginTop: 0,
marginBottom: 0,
marginBottom: (message.dimensions[0].datatype === 'date' ? 0 : 20),
marginLeft: 0,
marginRight: 0,
spacingTop: 0,
Expand All @@ -77,9 +78,9 @@ var Sparkline = module.exports = function (options, callback) {
},
series: series,
xAxis: {
type: 'datetime',
type: (message.dimensions[0].datatype === 'date' ? 'datetime' : 'category'),
labels: {
enabled: false
enabled: (message.dimensions[0].datatype !== 'date')
}
},
yAxis: {
Expand Down Expand Up @@ -123,35 +124,37 @@ var Sparkline = module.exports = function (options, callback) {
else if (self.options.query.realtime) {
//we're dealing with realtime
series.forEach(function (ser, serIndex) {
console.log(ser.data);

ser.data.forEach(function (datapoint) {
var found = false;
self.chart.series[serIndex].points.forEach(function (point) {
var nameBased = false;
self.chart.series[serIndex].points.forEach(function (point, pIndex) {
if (point) {
if (point.x.getTime() == datapoint.x.getTime()) {
var y = self.chart.series[serIndex].data[self.chart.series[serIndex].data.length - 1].y;
found = true;
if (y != datapoint.y)
self.chart.series[serIndex].data[self.chart.series[serIndex].data.length - 1].update(datapoint.y);
if (datapoint.x) {
if (point.x.getTime() == datapoint.x.getTime()) {
var y = self.chart.series[serIndex].data[pIndex].y;
found = true;
if (y != datapoint.y)
self.chart.series[serIndex].data[pIndex].update(datapoint.y);
}
}
else {
nameBased = true;
if (point.name == datapoint.name) {
var y = self.chart.series[serIndex].data[pIndex].y;
found = true;
if (y != datapoint.y)
self.chart.series[serIndex].data[pIndex].update(datapoint.y);
}
}
}
});
if (!found) {
self.chart.series[serIndex].addPoint({x: datapoint.x, y: datapoint.y}, true, true);
if (nameBased)
self.chart.series[serIndex].addPoint({name: datapoint.name, y: datapoint.y}, true);
else
self.chart.series[serIndex].addPoint({x: datapoint.x, y: datapoint.y}, true, true);
}
});

return;
ser.data.splice(0, ser.data.length - 1);

var point = self.chart.series[serIndex].points[self.chart.series[serIndex].points.length - 1];
if (point) {
if (point.x.getTime() == ser.data[0].x.getTime())
self.chart.series[serIndex].data[self.chart.series[serIndex].data.length - 1].update(ser.data[0].y);
else
self.chart.series[serIndex].addPoint({x: ser.data[0].x, y: ser.data[0].y}, true, true);
}
});
}
});
Expand Down
35 changes: 23 additions & 12 deletions lib/viz/_proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,30 @@ proto.makeChartTimelineSeries = function (dimensions, metrics, documents) {
};

documents.forEach(function (document) {
var x = new Date(document.fvalues[dimensions[0].key]);
/*if (exist) {
var _date = new Date(document.fvalues.timestamp);
console.log(_date, _date, fixOffset(_date));
x = fixOffset(_date);
}*/

console.log(x,document.values[metrics[index].key])
var x = document.fvalues[dimensions[0].key];
var nameBased = true;
if (dimensions[0].datatype === 'date') {
x = new Date(document.fvalues[dimensions[0].key]);
nameBased = false;
}

series[index].data.push({
x: x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
});
/*if (exist) {
var _date = new Date(document.fvalues.timestamp);
console.log(_date, _date, fixOffset(_date));
x = fixOffset(_date);
}*/

if (nameBased) {
series[index].data.push({
name: x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
});
} else {
series[index].data.push({
x: x,
y: document.values[metrics[index].key] ? document.values[metrics[index].key] : 0
});
}
});
});

Expand Down

0 comments on commit cd13149

Please sign in to comment.