Commit c5f37f63 authored by ninon's avatar ninon

add graph line stat

parent d2f891d4
......@@ -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,10 @@ function createGraph(data){
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g")
.attr("transform", "translate(" + (width / 2 - 45) + "," + (height /3 + 10) + ")");
.attr("transform", "translate(" + ($("#affTreeMap").width()/2) + "," + ($("#affTreeMap").height()/4) + ")");
// .attr("transform", "translate(" + (width / 2 - 45) + "," + (height /3 + 10) + ")");
console.log($("#affTreeMap").width()/4)
var stratify = d3.stratify()
.id(function(d) { return d._id; })
......
......@@ -159,13 +159,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>
......
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