...
 
Commits (16)
......@@ -70,6 +70,8 @@ router.get('/show/:id', async (req, res) => {
const debate = await getJSON(`http://localhost:3000/api/debates/${id}`);
const contributions = await getJSON(`http://localhost:3000/api/contributions/${id}`);
const syntheses = await getJSON(`http://localhost:3000/api/syntheses/${id}`);
const stats = await getJSON(`http://localhost:3000/api/contributions/${id}/stat/stat`);
res.render(
'pages/debate/debate', {
......@@ -77,6 +79,7 @@ router.get('/show/:id', async (req, res) => {
debate: debate,
contributions: contributions,
syntheses: syntheses,
stats: stats
},
);
});
......
.line {
fill: none;
stroke: steelblue;
stroke-width: 2px;
}
.node circle {
fill: #fff;
stroke-width: 1.5px;
......
var data=[
{ "date":"01-01-2019",
"count":7
},
{ "date":"02-02-2019",
"count":5
},
{ "date":"03-02-2019",
"count":1
},
{ "date":"10-02-2019",
"count":6
},
{ "date":"20-02-2019",
"count":5
},
{ "date":"21-02-2019",
"count":3
},
{ "date":"22-02-2019",
"count":6
},
]
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// parse the date / time
var parseTime = d3.timeParse("%d-%m-%Y");
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
var bisect = d3.bisector(function (data) {
return data.date;
}).right;
createLine(stats);
function createLine(data){
// define the line
var valueline = d3.line()
.x(function(d) { console.log("x", x(d.date)); return x(d.date); })
.y(function(d) { console.log("y", y(d.count)); return y(d.count); })
.curve(d3.curveMonotoneX)
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
$("#affTreeMap").append('<svg width="672" id="stat" height="372"></svg>')
var svg = d3.select("#stat")
// .attr("width", width + margin.left + margin.right)
// .attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.bottom + ") scale(0.6,0.45)")
// format the data
data.forEach(function(d) {
// d.date = parseTime(d.date);
d.date = parseTime(d._id.day+"-"+d._id.month+"-"+d._id.year)
d.count = +d.count;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.count; })]);
// Add the valueline path.
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
// Add the X Axis
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// Add the Y Axis
svg.append("g")
.call(d3.axisLeft(y));
svg
.append("g")
.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("r", 4.5)
.attr("class", "plot")
.attr("cx", function(d) { console.log(d.date); return x(d.date); })
.attr("cy", function(d) { console.log(d.count); return y(d.count); })
.style("fill", "white")
.style("stroke", "blue")
.on("click", handleCircle)
$(svg).css({
'pointer-events' : 'auto'
})
function handleCircle(d){
var x= d.date;
var y= d.count;
var month = d.date.getMonth() <10 ? "0"+d.date.getMonth().toString() : d.date.getMonth().toString();
var day = d.date.getDay() <10 ? "0"+d.date.getDay().toString() : d.date.getDay().toString();
console.log( d.date.getMonth()<10, d.date.getFullYear()+"-"+month+"-"+day);
$("#dateValue").val(d.date.getFullYear()+"-"+month+"-"+day)
//$("#end").click();
}
}
\ No newline at end of file
......@@ -21,8 +21,9 @@ function createGraph(data){
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g")
.attr("transform", "translate(" + (width / 2 + 40) + "," + (height /3) + ")");
.attr("transform", "translate(" + ($("#affTreeMap").width()/2) + "," + ($("#affTreeMap").height()/4) + ")");
console.log($("#affTreeMap").width()/4)
var stratify = d3.stratify()
.id(function(d) { return d._id; })
......@@ -60,8 +61,8 @@ function createGraph(data){
.attr("transform", function(d) { return "translate(" + project(d.x, d.y) + ")"; })
node.append("circle")
.attr("r", 4.5)
.style('fill', function(d) { return color(d.data.type)})
.attr("r", 6)
.style('fill', function(d) { return d.data.synthese? "grey" : color(d.data.type)})
.style("stroke", function(d) { return d.data.parent==""? "#8da0cb" : null})
.on('click', click)
.on("mouseover", handleMouseOver)
......@@ -238,6 +239,21 @@ $("#end").click(function(){
});
})
$("#end").click(function(){
$.ajax({
type: 'GET',
url: '/api/contributions/'+debateJSON._id+'/'+$("#dateValue").val(),
dataType: 'text',
}).done(function(response) {
data=JSON.parse(response);
data.push({"_id" : debate._id, "parent" : "", "name" : debate.question, "value":""})
console.log(data);
$("svg").empty();
createGraph(data);
});
})
function project(x, y) {
var angle = (x - 90) / 180 * Math.PI, radius = y/2;
......@@ -336,48 +352,48 @@ else{
function handleMouseOut(d) {
div.transition()
.duration(500)
.style("opacity", 0);
div.transition()
.duration(500)
.style("opacity", 0);
}
function update(source) {
var duration=700,
temp=d3.selectAll("path.link"),
treeData = tree(root);
temp=d3.selectAll("path.link"),
treeData = tree(root);
var nodes = treeData.descendants(),
links = treeData.descendants().slice(1);
links = treeData.descendants().slice(1);
var link = g.selectAll('newLink')
.data(links, function(d) {
return d.id;
});
.data(links, function(d) {
return d.id;
});
/* ==== Màj des arcs ===== */
// Calcul des coordonnées :
var linkEnter = link.enter().
append('path').
attr("class", "link").
attr("stroke-width", 2).
style("stroke", "#8da0cb").
attr("d", function(d, i) {
return "M" + project(d.x, d.y)
+ "C" + project(d.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, d.parent.y);
});
// Suppression des anciens arcs :
temp.attr("fill-opacity", 1)
.attr("stroke-opacity", 1)
.transition()
.duration(700)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.remove();
append('path').
attr("class", "link").
attr("stroke-width", 2).
style("stroke", "#8da0cb").
attr("d", function(d, i) {
return "M" + project(d.x, d.y)
+ "C" + project(d.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, d.parent.y);
});
// Suppression des anciens arcs :
temp.attr("fill-opacity", 1)
.attr("stroke-opacity", 1)
.transition()
.duration(700)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.remove();
/* ==== Màj des noeuds ===== */
......@@ -389,13 +405,13 @@ function update(source) {
var nodeEnter = node.enter().
append('g')
append('g')
.attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
.attr("transform", function(d) { return "translate(" + project(d.x, d.y) + ")"; })
nodeEnter.append('circle')
.attr("r", 4.5)
.attr("r", 6)
.style('fill', function(d) {return color(d.data.type)})
.on('click', click)
.on("mouseover", handleMouseOver)
......@@ -403,22 +419,22 @@ function update(source) {
var nodeUpdate = nodeEnter.merge(node);
nodeUpdate.transition().
duration(duration)
duration(duration)
.attr("transform", function(d) { return "translate(" + project(d.x, d.y) + ")"; })
nodeUpdate.select('circle.node')
.attr("r", 4.5)
.attr("r", 6)
.attr('cursor', 'pointer');
// Suppression des anciens noeuds :
var nodeExit = node.exit()
.attr("fill-opacity", 1)
.attr("stroke-opacity", 1)
.transition()
.duration(500)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.remove();
.attr("fill-opacity", 1)
.attr("stroke-opacity", 1)
.transition()
.duration(500)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.remove();
nodeExit.select('circle').attr('r', 0);
nodes.forEach(function(d){
d.x0 = d.x;
......
<html>
<head>
<meta charset="UTF-8">
......@@ -159,13 +161,15 @@
const debate = <%- JSON.stringify(debate) %>;
const definitions = <%- JSON.stringify(debate.definitions) %>;
const sources = <%- JSON.stringify(debate.sources) %>;
var stats = <%- JSON.stringify(stats) %>;
console.log("stats", stats);
</script>
<script type="text/javascript" src="/static/javascript/menuDebat.js"></script>
<script type="text/javascript" src="/static/javascript/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript" src="/static/javascript/d3.v4.min.js"></script>
<script type="text/javascript" src="/static/javascript/line.js"></script>
<script type="text/javascript" src="/static/javascript/radialTreeMap.js"></script>
<script type="text/javascript" src="/static/javascript/dragndrop.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
......