Skip to content

Commit 76313ba

Browse files
committed
Merge pull request #1719 from Vizzuality/disposable/master-develop-june10
Disposable/master develop june10
2 parents ccb10bf + 7b73cc4 commit 76313ba

File tree

214 files changed

+4907
-1804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+4907
-1804
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
269 KB
Loading
391 KB
Loading

app/assets/images/logo-wri.png

7.79 KB
Loading

app/assets/images/[email protected]

13.7 KB
Loading

app/assets/images/svg-icons/more.svg

+1
Loading

app/assets/images/svg-map/control-legend.svg

+1
Loading

app/assets/images/svg-map/control-locate.svg

+1
Loading

app/assets/images/svg-map/tab-settings.svg

+1
Loading

app/assets/images/svg-map/tab-share.svg

100755100644
+1-6
Loading

app/assets/javascripts/abstract/layer/CanvasJSONLayerClass.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define([
2424
init: function(layer, options, map) {
2525
this.tiles = {};
2626
this.layer = layer;
27+
this.top_date = (((this.layer.maxdate.year() - this.layer.mindate.year()) * 12) + this.layer.maxdate.month()) - 2;
2728
this._super(layer, options, map);
2829
this.getDates();
2930
this.cartoSQL = new cartodb.SQL({
@@ -80,7 +81,8 @@ define([
8081
zoom: zoom,
8182
height: this.tileSize.height,
8283
cells: this.preCacheMonths(data.rows, coord, zoom,
83-
zoomDiff)
84+
zoomDiff),
85+
top_date : data.top_date
8486
};
8587

8688
//set unique id
@@ -118,13 +120,13 @@ define([
118120
cy1: ((y + 1) * 256) >> zoom_diff,
119121
z: pixel_zoom
120122
});
121-
122123
return sql;
123124
},
124125

125126
_render: function(tile) {
126127
var month = this.endMonth || -BASE_MONTH + MAX_MONTHS;
127128
var month_start = this.startMonth || 0;
129+
var month_change = this.top_date;
128130
var w = tile.canvas.width;
129131
var ctx = tile.ctx;
130132
var cells = tile.cells;
@@ -140,18 +142,20 @@ define([
140142
// render cells
141143
var len = cells.length;
142144
var pixel_size = cells.size;
143-
var index, index0, mul;
145+
var index, index0, index1,mul;
144146
var previous = [];
145147
for (var i = 0; i < len; ++i) {
146148
mul = MAX_MONTHS * i;
147149
index = mul + month;
148150
index0 = mul + month_start;
151+
index1 = mul + month_change;
149152
// set pixel by hand faster than doing fill rect (below)
150153
if (cells.deforestation[index] - cells.deforestation[index0] > 0) {
151154
ctx.fillStyle = '#F69';
152-
// if (month > 85 && cells.month[i] > 180) {
153-
// ctx.fillStyle = '#F10022';
154-
// }
155+
ctx.fillRect(xc[i], yc[i], pixel_size, pixel_size);
156+
}
157+
if (cells.deforestation[index] - cells.deforestation[index1] > 0) {
158+
ctx.fillStyle = 'rgb(233, 189, 21)';
155159
ctx.fillRect(xc[i], yc[i], pixel_size, pixel_size);
156160
}
157161
}
@@ -161,20 +165,18 @@ define([
161165
var row,
162166
xcoords,
163167
ycoords,
164-
deforestation,
165-
month;
168+
deforestation;
166169

167170
if (typeof(ArrayBuffer) !== 'undefined') {
168171
xcoords = new Uint8Array(new ArrayBuffer(rows.length));
169172
ycoords = new Uint8Array(new ArrayBuffer(rows.length));
170-
// month = new Uint8Array(new ArrayBuffer(rows.length));
171173
deforestation = new Uint8Array(new ArrayBuffer(rows.length * MAX_MONTHS)); // 256 months
172174
} else {
173175
// fallback
174176
xcoords = [];
175177
ycoords = [];
176178
deforestation = [];
177-
// month = [];
179+
178180
// array buffer set by default to 0
179181
// fucking javascript arrays are not
180182
for (var r = 0; r < rows.length * MAX_MONTHS; ++r) {
@@ -195,7 +197,6 @@ define([
195197
for (var j = 0; j < row.sd.length; ++j) {
196198
var base = base_idx + row.sd[j] - BASE_MONTH;
197199
deforestation[base] = row.se[j];
198-
// month[i] = row.sd[j];
199200
}
200201
}
201202

@@ -210,7 +211,6 @@ define([
210211
xcoords: xcoords,
211212
ycoords: ycoords,
212213
deforestation: deforestation,
213-
// month : month,
214214
size: 1 << zoom_diff
215215
};
216216
},

app/assets/javascripts/abstract/layer/CartoDBLayerClass.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ define([
5555
},
5656

5757
updateTiles: function() {
58-
this.cdbLayer.setQuery(this.getQuery());
58+
if (this.cdbLayer) {
59+
this.cdbLayer.setQuery(this.getQuery());
60+
}
5961
},
6062

6163
/**

app/assets/javascripts/abstract/timeline/TimelineBtnClass.js

+61-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ define([
1010
'backbone',
1111
'moment',
1212
'd3',
13-
], function(_, Backbone, moment, d3) {
13+
'text!templates/timelineBtn-mobile.handlebars'
14+
15+
], function(_, Backbone, moment, d3, tplMobile) {
1416

1517
'use strict';
1618

1719
var TimelineBtnClass = Backbone.View.extend({
1820

1921
className: 'timeline-btn',
2022

23+
templateMobile: Handlebars.compile(tplMobile),
24+
2125
defaults: {
2226
dateRange: [moment([2001]), moment()],
2327
width: 1000,
@@ -26,6 +30,10 @@ define([
2630
tipsy: true
2731
},
2832

33+
events: {
34+
'change .select-date' : 'setSelects'
35+
},
36+
2937
initialize: function(layer, currentDate) {
3038
_.bindAll(this, '_onClickTick', '_selectDate');
3139
this.layer = layer;
@@ -46,13 +54,58 @@ define([
4654
this.svg = {};
4755
this.xscale = {};
4856

49-
this.render(_.bind(function() {
50-
this._selectDate({
51-
start: this.currentDate[0],
52-
end: this.currentDate[1]
53-
});
54-
}, this));
5557

58+
enquire.register("screen and (min-width:"+window.gfw.config.GFW_MOBILE+"px)", {
59+
match: _.bind(function(){
60+
this.render(_.bind(function() {
61+
this._selectDate({
62+
start: this.currentDate[0],
63+
end: this.currentDate[1]
64+
});
65+
}, this));
66+
},this)
67+
});
68+
enquire.register("screen and (max-width:"+window.gfw.config.GFW_MOBILE+"px)", {
69+
match: _.bind(function(){
70+
this.renderMobile();
71+
},this)
72+
});
73+
74+
75+
},
76+
77+
renderMobile: function(){
78+
this.$timeline = $('.timeline-container');
79+
this.$el.html(this.templateMobile({name:this.layer.title}));
80+
this.$timeline.html('').append(this.el);
81+
82+
this.$selects = $('.select-date');
83+
this.$from = $('#from-timeline');
84+
85+
this.fillSelects();
86+
},
87+
88+
fillSelects: function(){
89+
var options = '';
90+
var currentIndex = this.data.length - 1;
91+
var currentDate = this.currentDate;
92+
var dformat = 'DD-MM-YYYY';
93+
_.each(this.data, function(label, i){
94+
options += '<option value="'+i+'">'+label.label+'</option>';
95+
if (label.start.format(dformat) == currentDate[0].format(dformat) && label.end.format(dformat) == currentDate[1].format(dformat)) {
96+
currentIndex = i;
97+
}
98+
});
99+
this.$from.html(options).val(currentIndex);
100+
this.setSelects();
101+
102+
},
103+
104+
setSelects: function(){
105+
var index = this.$from[0].selectedIndex;
106+
var $dateButton = $('#'+this.$from.attr('id')+'-button');
107+
$dateButton.text(this.data[index].label);
108+
this._updateCurrentDate([this.data[index].start,this.data[index].end]);
56109
},
57110

58111
/**
@@ -61,7 +114,7 @@ define([
61114
render: function(callback) {
62115
var self = this;
63116
this.$timeline = $('.timeline-container');
64-
this.$timeline.append(this.el);
117+
this.$timeline.html('').append(this.el);
65118

66119
// SVG options
67120
var margin = {top: 0, right: 15, bottom: 0, left: 15};

0 commit comments

Comments
 (0)