time scale is linear now
getCategories is not random anymore :-/
This commit is contained in:
parent
e91a29aec2
commit
dacef123f8
@ -22,7 +22,6 @@ var internal = function (options) {
|
|||||||
[Number.MAX_VALUE, Number.MAX_VALUE],
|
[Number.MAX_VALUE, Number.MAX_VALUE],
|
||||||
[Number.MIN_VALUE, Number.MIN_VALUE]
|
[Number.MIN_VALUE, Number.MIN_VALUE]
|
||||||
];
|
];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -34,46 +33,111 @@ internal.prototype = {
|
|||||||
this.timestampType = "number";
|
this.timestampType = "number";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
time = new Date(Date.parse(time));
|
||||||
if (this.timestampType === undefined) {
|
if (this.timestampType === undefined) {
|
||||||
this.timestampType = "date";
|
this.timestampType = "date";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.points.push({lat: parseFloat(lat), lon: parseFloat(lon), time: time, value: parseFloat(value) || value});
|
this.points.push({lat: parseFloat(lat), lon: parseFloat(lon), time: time, value: parseFloat(value) || value});
|
||||||
},
|
},
|
||||||
getBounds: function() {
|
getBounds: function () {
|
||||||
return this.options.bounds;
|
return this.options.bounds;
|
||||||
},
|
},
|
||||||
|
getCategories: function () {
|
||||||
|
if (!this.options.countby) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var checkCategoryExists = function (category) {
|
||||||
|
return category.name == self.points[i].value;
|
||||||
|
};
|
||||||
|
|
||||||
|
var categories = [];
|
||||||
|
for (var i = 0; i < this.points.length; i++) {
|
||||||
|
if (!categories.some(checkCategoryExists)) {
|
||||||
|
var randomColor = 0x1000000 + Math.floor(Math.random() * 0xffffff);
|
||||||
|
randomColor = "#" + randomColor.toString(16).slice(1, 7);
|
||||||
|
categories.push({
|
||||||
|
value: this.points[i].value,
|
||||||
|
name: this.points[i].value,
|
||||||
|
color: randomColor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
},
|
||||||
|
setOptions: function(opt) {
|
||||||
|
var refresh = false;
|
||||||
|
|
||||||
|
if (opt.resolution !== undefined && opt.resolution !== this.options.resolution) {
|
||||||
|
this.options.resolution = opt.resolution;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt.steps !== undefined && opt.steps !== this.options.steps) {
|
||||||
|
this.setSteps(opt.steps, { silent: true });
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt.column !== undefined && opt.column !== this.options.column) {
|
||||||
|
this.options.column = opt.column;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt.countby !== undefined && opt.countby !== this.options.countby) {
|
||||||
|
this.options.countby = opt.countby;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt.data_aggregation !== undefined) {
|
||||||
|
var c = opt.data_aggregation === 'cumulative';
|
||||||
|
if (this.options.cumulative !== c) {
|
||||||
|
this.options.cumulative = c;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (refresh) {
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
return refresh;
|
||||||
|
},
|
||||||
setReady: function (ready) {
|
setReady: function (ready) {
|
||||||
if (ready == false) {
|
if (ready == false) {
|
||||||
this._ready = false;
|
this._ready = false;
|
||||||
} else {
|
} else {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
this.options.data_steps = this.points.length;
|
||||||
|
|
||||||
this.points.sort(function (point1, point2) {
|
this.points.sort(function (point1, point2) {
|
||||||
if (self.timestampType == "number") {
|
return point1.time - point2.time;
|
||||||
return point1.time - point2.time;
|
|
||||||
} else {
|
|
||||||
if (typeof(point1.time) == "string") {
|
|
||||||
return new Date(point1.time) - new Date(point2.time);
|
|
||||||
} else {
|
|
||||||
return point1.time - point2.time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.timestampType == "date") {
|
if (this.timestampType == "number") {
|
||||||
this.timestamps = {}; // {date: timestamp_id}
|
this.options.start = this.points[0].time;
|
||||||
var timestampIdx = 0;
|
this.options.end = this.points[this.points.length - 1].time;
|
||||||
for (var i = 0; i < this.points.length; i++) {
|
} else {
|
||||||
var point = this.points[i];
|
this.options.start = this.points[0].time.getTime();
|
||||||
this.timestamps[point.time] || (this.timestamps[point.time] = timestampIdx++);
|
this.options.end = this.points[this.points.length - 1].time.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.timestamps = {}; // {date: timestamp_id}
|
||||||
|
for (var i = 0; i < this.points.length; i++) {
|
||||||
|
var point = this.points[i];
|
||||||
|
if ((this.options.end - this.options.start) != 0) {
|
||||||
|
this.timestamps[point.time] || (this.timestamps[point.time] = parseInt(this.getSteps() * (point.time - this.options.start) / (this.options.end - this.options.start)));
|
||||||
|
} else {
|
||||||
|
this.timestamps[point.time] || (this.timestamps[point.time] = 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.timestampType == "number") {
|
|
||||||
this.maxTimestamp = this.points[this.points.length - 1].time;
|
this.maxTimestamp = this.timestamps[this.points[this.points.length - 1].time];
|
||||||
} else {
|
|
||||||
this.maxTimestamp = this.timestamps[this.points[this.points.length - 1].time];
|
|
||||||
}
|
|
||||||
this._ready = true;
|
this._ready = true;
|
||||||
this._processQueue();
|
this._processQueue();
|
||||||
this.options.ready && this.options.ready();
|
this.options.ready && this.options.ready();
|
||||||
@ -166,14 +230,9 @@ internal.prototype = {
|
|||||||
x[pointIdx] = xInTile;
|
x[pointIdx] = xInTile;
|
||||||
y[pointIdx] = yInTile;
|
y[pointIdx] = yInTile;
|
||||||
|
|
||||||
var pointTimestamp;
|
var pointTimestamp = this.timestamps[point.time];
|
||||||
if (this.timestampType == 'date') {
|
|
||||||
pointTimestamp = this.timestamps[point.time];
|
|
||||||
} else {
|
|
||||||
pointTimestamp = point.time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.cumulative) {
|
if (this.options.cumulative && this.maxTimestamp > 0) {
|
||||||
if (accumulatedValues[xInTile] === undefined) {
|
if (accumulatedValues[xInTile] === undefined) {
|
||||||
accumulatedValues[xInTile] = [];
|
accumulatedValues[xInTile] = [];
|
||||||
}
|
}
|
||||||
@ -229,16 +288,25 @@ internal.prototype = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getKeySpan: function () {
|
getKeySpan: function () {
|
||||||
return {
|
return {
|
||||||
start: this.options.start * 1000,
|
start: this.options.start,
|
||||||
end: this.options.end * 1000,
|
end: this.options.end,
|
||||||
step: this.options.step,
|
step: this.options.step || ((this.options.end - this.options.start) / this.getSteps()),
|
||||||
steps: this.options.steps,
|
steps: this.getSteps(),
|
||||||
columnType: this.timestampType
|
columnType: this.timestampType
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getSteps: function () {
|
getSteps: function () {
|
||||||
return this.options.steps;
|
return this.options.steps;
|
||||||
|
},
|
||||||
|
setSteps: function(steps, opt) {
|
||||||
|
opt = opt || {};
|
||||||
|
if (this.options.steps !== steps) {
|
||||||
|
this.options.steps = steps;
|
||||||
|
this.options.step = (this.options.end - this.options.start) / this.getSteps();
|
||||||
|
this.options.step = this.options.step || 1;
|
||||||
|
if (!opt.silent) this.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user