This commit is contained in:
Stuart Lynn 2015-09-08 18:07:54 -04:00
parent 6b0e946e41
commit 17f2c2aee0
4 changed files with 238 additions and 70 deletions

12
dist/torque.full.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2807,6 +2807,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
var bb = thisValue.bbox;
var xy = this._map.latLngToContainerPoint([bb[1].lat, bb[1].lon]);
if(xy.x < xf && xy.y < yf){
console.log("just before sum value ", this.Value.value)
sum += thisValue.value;
}
}
@ -3181,7 +3182,19 @@ var Profiler = require('../profiler');
// reserve memory for all the dates
var timeIndex = new Int32Array(maxDateSlots + 1); //index-size
var timeCount = new Int32Array(maxDateSlots + 1);
var renderData = new (this.options.valueDataType || type)(dates);
var val_keys = []
if(rows.length>0){
val_keys = Object.keys(rows[0]).filter(function(k){return (k.indexOf("vals__uint8") > -1) })
}
r
var renderData = []
val_keys.forEach(function(key,index){
renderData[index] = new (this.options.valueDataType || type)(dates);
}.bind(this))
var renderDataPos = new Uint32Array(dates);
prof_mem.inc(
@ -3208,15 +3221,28 @@ var Profiler = require('../profiler');
}
var dates = row.dates__uint16;
var vals = row.vals__uint8;
var val_keys = Object.keys(row).filter(function(k){return (k.indexOf("vals__uint8") > -1) })
var val_arr = []
val_keys.forEach(function(key){
var i = key.match(/vals__uint8_(\d+)/)[1]
val_arr[i] = row[key];
})
if (!this.options.cumulative) {
for (var j = 0, len = dates.length; j < len; ++j) {
var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []);
if(this.options.cumulative) {
vals[j] += prev_val;
}
prev_val = vals[j];
rr.push([r, vals[j]]);
//Stuart: Not sure I understand why this is here?
// if(this.options.cumulative) {
// vals[j] += prev_val;
// }
// prev_val = vals[j];
var all_vals = []
val_arr.forEach(function(vals){
all_vals.push(vals[j])
})
rr.push([r, all_vals]);
}
} else {
var valByDate = {}
@ -3245,6 +3271,7 @@ var Profiler = require('../profiler');
}
// for each timeslot search active buckets
var renderDataIndex = 0;
var timeSlotIndex = 0;
@ -3254,10 +3281,13 @@ var Profiler = require('../profiler');
var slotRows = rowsPerSlot[i]
if(slotRows) {
for (var r = 0; r < slotRows.length; ++r) {
var rr = slotRows[r];
++c;
renderDataPos[renderDataIndex] = rr[0]
renderData[renderDataIndex] = rr[1];
rr[1].forEach(function(rrr,index){
renderData[index][renderDataIndex] = rrr;
})
++renderDataIndex;
}
}
@ -3346,7 +3376,6 @@ var Profiler = require('../profiler');
subdomains = [null]; // no subdomain
}
var url;
if (options.no_cdn) {
url = this._host();
@ -3363,6 +3392,7 @@ var Profiler = require('../profiler');
},
getTileData: function(coord, zoom, callback) {
if(!this._ready) {
this._tileQueue.push([coord, zoom, callback]);
} else {
@ -3394,9 +3424,18 @@ var Profiler = require('../profiler');
var column_conv = this.options.column;
var agg_columns;
if(this.options.countby.indexOf(";") > 0){
agg_columns = this.options.countby.split(";")
}
else{
agg_columns = [this.options.countby]
}
if(this.options.is_time) {
column_conv = format("date_part('epoch', {column})", this.options);
}
console.log("columns are ", this.options.countby)
var sql = "" +
"WITH " +
@ -3406,8 +3445,13 @@ var Profiler = require('../profiler');
", CDB_XYZ_Extent({x}, {y}, {zoom}) as ext " +
")," +
"cte AS ( "+
" SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g" +
", {countby} c" +
" SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g"
agg_columns.forEach(function(col,index){
sql = sql + ", "+col+" c"+index
}.bind(this))
sql = sql +
", floor(({column_conv} - {start})/{step}) d" +
" FROM ({_sql}) i, par p " +
" WHERE i.the_geom_webmercator && p.ext " +
@ -3415,14 +3459,20 @@ var Profiler = require('../profiler');
") " +
"" +
"SELECT (st_x(g)-st_xmin(p.ext))/p.res x__uint8, " +
" (st_y(g)-st_ymin(p.ext))/p.res y__uint8," +
" array_agg(c) vals__uint8," +
" array_agg(d) dates__uint16" +
" (st_y(g)-st_ymin(p.ext))/p.res y__uint8"
agg_columns.forEach(function(col,index){
sql = sql + ", array_agg(c"+index+") vals__uint8_"+index
}.bind(this))
sql = sql +
", array_agg(d) dates__uint16" +
// the tile_size where are needed because the overlaps query in cte subquery includes the points
// in the left and bottom borders of the tile
" FROM cte, par p where (st_y(g)-st_ymin(p.ext))/p.res < tile_size and (st_x(g)-st_xmin(p.ext))/p.res < tile_size GROUP BY x__uint8, y__uint8";
var query = format(sql, this.options, {
zoom: zoom,
x: coord.x,
@ -3431,6 +3481,8 @@ var Profiler = require('../profiler');
_sql: this.getSQL()
});
console.log("sql is ", query)
var self = this;
this.sql(query, function (data) {
if (data) {
@ -3551,7 +3603,7 @@ var Profiler = require('../profiler');
"layers": [{
"type": "cartodb",
"options": {
"cartocss_version": "2.1.1",
"cartocss_version": "2.1.1",
"cartocss": "#layer {}",
"sql": this.getSQL()
}
@ -4100,7 +4152,7 @@ var Profiler = require('../profiler');
this.options.cartocss = c;
},*/
setSteps: function(steps, opt) {
setSteps: function(steps, opt) {
opt = opt || {};
if (this.options.steps !== steps) {
this.options.steps = steps;
@ -4205,10 +4257,12 @@ var Profiler = require('../profiler');
.replace('{s}', subdomains[index])
var extra = this._extraParams();
torque.net.get( url + (extra ? "?" + extra: ''), function (data) {
prof_fetch_time.end();
if (data && data.responseText) {
var rows = JSON.parse(data.responseText);
console.log("tile data ", rows)
callback(self.proccessTile(rows, coord, zoom));
} else {
Profiler.metric('torque.provider.windshaft.tile.error').inc();
@ -4349,7 +4403,7 @@ var Profiler = require('../profiler');
}]
};
}
if(this.options.stat_tag){
allParams["stat_tag"] = this.options.stat_tag;
}
@ -4399,9 +4453,9 @@ var Profiler = require('../profiler');
},{"../":10,"../profiler":17}],22:[function(require,module,exports){
var TAU = Math.PI*2;
// min value to render a line.
// min value to render a line.
// it does not make sense to render a line of a width is not even visible
var LINEWIDTH_MIN_VALUE = 0.05;
var LINEWIDTH_MIN_VALUE = 0.05;
var MAX_SPRITE_RADIUS = 255;
function renderPoint(ctx, st) {
@ -4473,6 +4527,21 @@ var Profiler = require('../profiler');
}
}
function renderVector(ctx,img,st){
var markerWidth = st['maker-width']
var direction = st['vector-direction']
var mag = st['vector-mag']
var lineWidth = st['marker-line-width']
var strokeStyle = st['marker-line-color']
ctx.lineWidth = lineWidth
ctx.strokeStyle = strokeStyle
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();
}
function renderSprite(ctx, img, st) {
if(img.complete){
@ -4557,7 +4626,7 @@ var Filters = require('./torque_filters');
this.TILE_SIZE = 256;
this._style = null;
this._gradients = {};
this._forcePoints = false;
}
@ -4612,9 +4681,21 @@ var Filters = require('./torque_filters');
generateSprite: function(shader, value, shaderVars) {
var self = this;
var prof = Profiler.metric('torque.renderer.point.generateSprite').start();
var st = shader.getStyle({
value: value
}, shaderVars);
var values = {}
if(value.length ==0){
values["value"] = value[0]
}
else{
value.forEach(function(val,index){
values["value"+index] = val;
})
}
var st = shader.getStyle(values, shaderVars);
if(this._style === null || this._style !== st){
this._style = st;
}
@ -4665,7 +4746,7 @@ var Filters = require('./torque_filters');
i.src = canvas.toDataURL();
return i;
}
return canvas;
},
@ -4693,7 +4774,7 @@ var Filters = require('./torque_filters');
}
}
}
prof.end(true);
return callback && callback(null);
@ -4737,7 +4818,7 @@ var Filters = require('./torque_filters');
},
//
// renders a tile in the canvas for key defined in
// renders a tile in the canvas for key defined in
// the torque tile
//
_renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars) {
@ -4760,7 +4841,7 @@ var Filters = require('./torque_filters');
var pixelIndex = tile.timeIndex[key];
for(var p = 0; p < activePixels; ++p) {
var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p];
var c = tile.renderData.map(function(a){return a[pixelIndex + p]});
if (c) {
var sp = sprites[c];
if (sp === undefined) {
@ -4774,7 +4855,7 @@ var Filters = require('./torque_filters');
}
}
}
prof.end(true);
},
@ -4816,6 +4897,7 @@ var Filters = require('./torque_filters');
// return the value for x, y (tile coordinates)
// null for no value
getValueFor: function(tile, step, px, py) {
// console.log('getting value for tile ', tile, step, px, py)
var mercator = new torque.Mercator();
var res = this.options.resolution;
var res2 = res >> 1;
@ -4826,13 +4908,15 @@ var Filters = require('./torque_filters');
var pixelIndex = tile.timeIndex[step];
for(var p = 0; p < activePixels; ++p) {
var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p];
var c = [tile.renderData[0][pixelIndex + p], tile.renderData[1][pixelIndex + p]]
// console.log("tile.renderData ", tile.renderData[pixelIndex + p] )
if (c) {
var x = tile.x[posIdx];
var y = tileMax - tile.y[posIdx];
var dx = px + res2 - x;
var dy = py + res2 - y;
if (dx >= 0 && dx < res && dy >= 0 && dy < res) {
// console.log('returning value ', c, " from ", tile.renderData[pixelIndex + p])
return {
value: c,
bbox: mercator.tilePixelBBox(
@ -4925,7 +5009,7 @@ var Filters = require('./torque_filters');
}
gradient = {};
var colorize = this._style['image-filters'].args;
var increment = 1/colorize.length;
for (var i = 0; i < colorize.length; i++){
var key = increment * i + increment;
@ -13932,7 +14016,7 @@ module.exports={
"url": "https://github.com/cartodb/carto",
"repository": {
"type": "git",
"url": "http://github.com/cartodb/carto.git"
"url": "git+ssh://git@github.com/cartodb/carto.git"
},
"author": {
"name": "CartoDB",
@ -14003,7 +14087,7 @@ module.exports={
"bugs": {
"url": "https://github.com/cartodb/carto/issues"
},
"homepage": "https://github.com/cartodb/carto",
"homepage": "https://github.com/cartodb/carto#readme",
"_id": "carto@0.15.1-cdb1",
"_shasum": "62534c2975cbee073f10c6c14a0c7e889c9469e7",
"_resolved": "https://github.com/CartoDB/carto/archive/master.tar.gz",

4
dist/torque.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2814,6 +2814,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
var bb = thisValue.bbox;
var xy = this._map.latLngToContainerPoint([bb[1].lat, bb[1].lon]);
if(xy.x < xf && xy.y < yf){
console.log("just before sum value ", this.Value.value)
sum += thisValue.value;
}
}
@ -3188,7 +3189,19 @@ var Profiler = require('../profiler');
// reserve memory for all the dates
var timeIndex = new Int32Array(maxDateSlots + 1); //index-size
var timeCount = new Int32Array(maxDateSlots + 1);
var renderData = new (this.options.valueDataType || type)(dates);
var val_keys = []
if(rows.length>0){
val_keys = Object.keys(rows[0]).filter(function(k){return (k.indexOf("vals__uint8") > -1) })
}
r
var renderData = []
val_keys.forEach(function(key,index){
renderData[index] = new (this.options.valueDataType || type)(dates);
}.bind(this))
var renderDataPos = new Uint32Array(dates);
prof_mem.inc(
@ -3215,15 +3228,28 @@ var Profiler = require('../profiler');
}
var dates = row.dates__uint16;
var vals = row.vals__uint8;
var val_keys = Object.keys(row).filter(function(k){return (k.indexOf("vals__uint8") > -1) })
var val_arr = []
val_keys.forEach(function(key){
var i = key.match(/vals__uint8_(\d+)/)[1]
val_arr[i] = row[key];
})
if (!this.options.cumulative) {
for (var j = 0, len = dates.length; j < len; ++j) {
var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []);
if(this.options.cumulative) {
vals[j] += prev_val;
}
prev_val = vals[j];
rr.push([r, vals[j]]);
//Stuart: Not sure I understand why this is here?
// if(this.options.cumulative) {
// vals[j] += prev_val;
// }
// prev_val = vals[j];
var all_vals = []
val_arr.forEach(function(vals){
all_vals.push(vals[j])
})
rr.push([r, all_vals]);
}
} else {
var valByDate = {}
@ -3252,6 +3278,7 @@ var Profiler = require('../profiler');
}
// for each timeslot search active buckets
var renderDataIndex = 0;
var timeSlotIndex = 0;
@ -3261,10 +3288,13 @@ var Profiler = require('../profiler');
var slotRows = rowsPerSlot[i]
if(slotRows) {
for (var r = 0; r < slotRows.length; ++r) {
var rr = slotRows[r];
++c;
renderDataPos[renderDataIndex] = rr[0]
renderData[renderDataIndex] = rr[1];
rr[1].forEach(function(rrr,index){
renderData[index][renderDataIndex] = rrr;
})
++renderDataIndex;
}
}
@ -3353,7 +3383,6 @@ var Profiler = require('../profiler');
subdomains = [null]; // no subdomain
}
var url;
if (options.no_cdn) {
url = this._host();
@ -3370,6 +3399,7 @@ var Profiler = require('../profiler');
},
getTileData: function(coord, zoom, callback) {
if(!this._ready) {
this._tileQueue.push([coord, zoom, callback]);
} else {
@ -3401,9 +3431,18 @@ var Profiler = require('../profiler');
var column_conv = this.options.column;
var agg_columns;
if(this.options.countby.indexOf(";") > 0){
agg_columns = this.options.countby.split(";")
}
else{
agg_columns = [this.options.countby]
}
if(this.options.is_time) {
column_conv = format("date_part('epoch', {column})", this.options);
}
console.log("columns are ", this.options.countby)
var sql = "" +
"WITH " +
@ -3413,8 +3452,13 @@ var Profiler = require('../profiler');
", CDB_XYZ_Extent({x}, {y}, {zoom}) as ext " +
")," +
"cte AS ( "+
" SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g" +
", {countby} c" +
" SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g"
agg_columns.forEach(function(col,index){
sql = sql + ", "+col+" c"+index
}.bind(this))
sql = sql +
", floor(({column_conv} - {start})/{step}) d" +
" FROM ({_sql}) i, par p " +
" WHERE i.the_geom_webmercator && p.ext " +
@ -3422,14 +3466,20 @@ var Profiler = require('../profiler');
") " +
"" +
"SELECT (st_x(g)-st_xmin(p.ext))/p.res x__uint8, " +
" (st_y(g)-st_ymin(p.ext))/p.res y__uint8," +
" array_agg(c) vals__uint8," +
" array_agg(d) dates__uint16" +
" (st_y(g)-st_ymin(p.ext))/p.res y__uint8"
agg_columns.forEach(function(col,index){
sql = sql + ", array_agg(c"+index+") vals__uint8_"+index
}.bind(this))
sql = sql +
", array_agg(d) dates__uint16" +
// the tile_size where are needed because the overlaps query in cte subquery includes the points
// in the left and bottom borders of the tile
" FROM cte, par p where (st_y(g)-st_ymin(p.ext))/p.res < tile_size and (st_x(g)-st_xmin(p.ext))/p.res < tile_size GROUP BY x__uint8, y__uint8";
var query = format(sql, this.options, {
zoom: zoom,
x: coord.x,
@ -3438,6 +3488,8 @@ var Profiler = require('../profiler');
_sql: this.getSQL()
});
console.log("sql is ", query)
var self = this;
this.sql(query, function (data) {
if (data) {
@ -3558,7 +3610,7 @@ var Profiler = require('../profiler');
"layers": [{
"type": "cartodb",
"options": {
"cartocss_version": "2.1.1",
"cartocss_version": "2.1.1",
"cartocss": "#layer {}",
"sql": this.getSQL()
}
@ -4107,7 +4159,7 @@ var Profiler = require('../profiler');
this.options.cartocss = c;
},*/
setSteps: function(steps, opt) {
setSteps: function(steps, opt) {
opt = opt || {};
if (this.options.steps !== steps) {
this.options.steps = steps;
@ -4212,10 +4264,12 @@ var Profiler = require('../profiler');
.replace('{s}', subdomains[index])
var extra = this._extraParams();
torque.net.get( url + (extra ? "?" + extra: ''), function (data) {
prof_fetch_time.end();
if (data && data.responseText) {
var rows = JSON.parse(data.responseText);
console.log("tile data ", rows)
callback(self.proccessTile(rows, coord, zoom));
} else {
Profiler.metric('torque.provider.windshaft.tile.error').inc();
@ -4356,7 +4410,7 @@ var Profiler = require('../profiler');
}]
};
}
if(this.options.stat_tag){
allParams["stat_tag"] = this.options.stat_tag;
}
@ -4406,9 +4460,9 @@ var Profiler = require('../profiler');
},{"../":10,"../profiler":17}],22:[function(require,module,exports){
var TAU = Math.PI*2;
// min value to render a line.
// min value to render a line.
// it does not make sense to render a line of a width is not even visible
var LINEWIDTH_MIN_VALUE = 0.05;
var LINEWIDTH_MIN_VALUE = 0.05;
var MAX_SPRITE_RADIUS = 255;
function renderPoint(ctx, st) {
@ -4480,6 +4534,21 @@ var Profiler = require('../profiler');
}
}
function renderVector(ctx,img,st){
var markerWidth = st['maker-width']
var direction = st['vector-direction']
var mag = st['vector-mag']
var lineWidth = st['marker-line-width']
var strokeStyle = st['marker-line-color']
ctx.lineWidth = lineWidth
ctx.strokeStyle = strokeStyle
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();
}
function renderSprite(ctx, img, st) {
if(img.complete){
@ -4564,7 +4633,7 @@ var Filters = require('./torque_filters');
this.TILE_SIZE = 256;
this._style = null;
this._gradients = {};
this._forcePoints = false;
}
@ -4619,9 +4688,21 @@ var Filters = require('./torque_filters');
generateSprite: function(shader, value, shaderVars) {
var self = this;
var prof = Profiler.metric('torque.renderer.point.generateSprite').start();
var st = shader.getStyle({
value: value
}, shaderVars);
var values = {}
if(value.length ==0){
values["value"] = value[0]
}
else{
value.forEach(function(val,index){
values["value"+index] = val;
})
}
var st = shader.getStyle(values, shaderVars);
if(this._style === null || this._style !== st){
this._style = st;
}
@ -4672,7 +4753,7 @@ var Filters = require('./torque_filters');
i.src = canvas.toDataURL();
return i;
}
return canvas;
},
@ -4700,7 +4781,7 @@ var Filters = require('./torque_filters');
}
}
}
prof.end(true);
return callback && callback(null);
@ -4744,7 +4825,7 @@ var Filters = require('./torque_filters');
},
//
// renders a tile in the canvas for key defined in
// renders a tile in the canvas for key defined in
// the torque tile
//
_renderTile: function(tile, key, frame_offset, sprites, shader, shaderVars) {
@ -4767,7 +4848,7 @@ var Filters = require('./torque_filters');
var pixelIndex = tile.timeIndex[key];
for(var p = 0; p < activePixels; ++p) {
var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p];
var c = tile.renderData.map(function(a){return a[pixelIndex + p]});
if (c) {
var sp = sprites[c];
if (sp === undefined) {
@ -4781,7 +4862,7 @@ var Filters = require('./torque_filters');
}
}
}
prof.end(true);
},
@ -4823,6 +4904,7 @@ var Filters = require('./torque_filters');
// return the value for x, y (tile coordinates)
// null for no value
getValueFor: function(tile, step, px, py) {
// console.log('getting value for tile ', tile, step, px, py)
var mercator = new torque.Mercator();
var res = this.options.resolution;
var res2 = res >> 1;
@ -4833,13 +4915,15 @@ var Filters = require('./torque_filters');
var pixelIndex = tile.timeIndex[step];
for(var p = 0; p < activePixels; ++p) {
var posIdx = tile.renderDataPos[pixelIndex + p];
var c = tile.renderData[pixelIndex + p];
var c = [tile.renderData[0][pixelIndex + p], tile.renderData[1][pixelIndex + p]]
// console.log("tile.renderData ", tile.renderData[pixelIndex + p] )
if (c) {
var x = tile.x[posIdx];
var y = tileMax - tile.y[posIdx];
var dx = px + res2 - x;
var dy = py + res2 - y;
if (dx >= 0 && dx < res && dy >= 0 && dy < res) {
// console.log('returning value ', c, " from ", tile.renderData[pixelIndex + p])
return {
value: c,
bbox: mercator.tilePixelBBox(
@ -4932,7 +5016,7 @@ var Filters = require('./torque_filters');
}
gradient = {};
var colorize = this._style['image-filters'].args;
var increment = 1/colorize.length;
for (var i = 0; i < colorize.length; i++){
var key = increment * i + increment;