Commit f08835b0 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas

data updated without normalized values and with initial stats on hexagons

Option for building the colorscale upon all combinations or only the one selected
Values are normalized on-the-fly instead of readed from file
parent 576b4682
......@@ -112,11 +112,14 @@
</div>
<script type="text/javascript">
var sameScaleForEveryCombination = false;
var zoom = 10;
var center = [3.4, 45.7];
var hexagonAlpha = 0.7;
var cult_code = '0';
var dataset_column='0_11111';
var dataset_surf_max=0;
var cult_code=0;
// https://www.d3indepth.com/scales/
var linearScale = d3.scaleLinear().domain([0, 1.0]).range(['#fff', "#008080"]);
......@@ -140,22 +143,28 @@
var rects = svg.selectAll(".rects").data(d3.range(50)).enter()
.append("rect").attr("x", 20).attr("width", 45).attr("y", (d,i)=>i*3)
.attr("height", 3).attr("fill", d=>linearScale4(d/50));
// looking for the maximum of the scores for the current cultural (for all combinations of indicators)
// FIXME it can be done at the init of the page for all cultural
// FIXME the normalization can be omitted in the geojson (for lighter file) and computed with this max and this loop
var max=0;
$(d3.range(32)).each(function(i,e){
col = cult_code + '_' + (e >>> 0).toString(2).padStart(5, '0');
dataset_surf_max=0;
if (sameScaleForEveryCombination) {
// looking for the maximum of the scores for the current cultural (for all combinations of criteria)
$(d3.range(32)).each(function(i,e){
col = cult_code + '_' + (e >>> 0).toString(2).padStart(5, '0');
hexagonsSource.forEachFeature(function(feat) {
dataset_surf_max = Math.max(dataset_surf_max, Math.abs(feat.get(col)));
});
})
} else {
// looking for the maximum of the scores for the current cultural and the current combinations of criteria
hexagonsSource.forEachFeature(function(feat) {
max = Math.max(max, Math.abs(feat.get(col)));
dataset_surf_max = Math.max(dataset_surf_max, Math.abs(feat.get(dataset_column)));
});
})
}
console.log('MAX ',dataset_surf_max);
// determining the sign of the scores
var sum=0;
hexagonsSource.forEachFeature(function(feat) { sum += feat.get(dataset_column);});
// filling the labels of the colorscale
$('#colorscale .minimum').text('0 ha');
var label = (max/10000).toFixed(2)+' ha';
var label = (dataset_surf_max/10000).toFixed(2)+' ha';
if (sum<0) {
label = '-' + label;
}
......@@ -165,9 +174,8 @@
dataset_column = cult_code + '_' + ($('#switch0')[0].checked + 0) + ($('#switch1')[0].checked + 0)
+ ($('#switch2')[0].checked + 0) + ($('#switch3')[0].checked + 0) + ($('#switch4')[0].checked + 0);
//+ $("#resilience")[0].innerText + $("#productivite")[0].innerText + $("#biodiversite")[0].innerText + $("#social")[0].innerText
console.log(dataset_column)
hexagonsSource.changed();
drawColorScale();
hexagonsSource.changed();
}
<!-- Map init -->
function styleFunction(feature, resolution) {
......@@ -178,15 +186,14 @@
console.log('Loaded');
drawColorScale();
}
var level = feature.get(dataset_column+'_norm');
var level = feature.get(dataset_column) / dataset_surf_max;
return new ol.style.Style({
stroke: new ol.style.Stroke({
width: 0,
color: '#0006'
}),
fill: new ol.style.Fill({
color: linearScale4(level)//.replace('rgb(','rgba(').replace(')',',' + hexagonAlpha + ')')
// color: d3.interpolateGreens(level)
color: linearScale4(Math.abs(level))
})
});
}
......@@ -196,6 +203,7 @@
});
var hexagons = new ol.layer.Vector({
title:'Réallocation',
//projection: 'EPSG:2154',
source: hexagonsSource,
style: styleFunction
});
......@@ -356,9 +364,15 @@
var surf = feature.get(dataset_column);
var sign = '';
if (surf>0) sign='+';
var surfNorm = feature.get(dataset_column+'_norm');
//console.log(dataset_column+ ': '+(surf/10000).toFixed(2)+' ha / '+surfNorm.toFixed(2)+' norm')
contentHexagon = '<code> ' +sign+ (surf/10000).toFixed(2) + ' ha</code>';
contentHexagon = '<code> ' +sign+ (surf/10000).toFixed(2) + ' ha</code><br>';
var nbexpl = feature.get(dataset_column+'_nb_expl');
if (typeof nbexpl !== 'undefined') {
nbexpl = nbexpl.toFixed(1);
if (surf<0) nbexpl = nbexpl.substr(1); // temporary fix for data
contentHexagon += 'Nb exploitant(e)s concerné(e)s : <code>' + nbexpl + '</code>';
} else {
console.log('Error for nbexpl. Key = ',dataset_column);
}
} else if (layer === epci) {
contentEPCI = feature.get('NOM_EPCI') + '<br/>';
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment