Charts Js
Charts Js
function pathMonth(t) {
var n = weekday === "weekday" ? 5 : 7;
var d = Math.max(0, Math.min(n, countDay(t)));
var w = timeWeek.count(d3.utcYear(t), t);
if ( d === 0 ) {
return 'M' + w * cellSize + ',0V' + n * cellSize;
} else if ( d === n ) {
return 'M' + (w + 1) * cellSize + ',0V' + n * cellSize;
} else {
return 'M' + (w + 1) * cellSize + ',0V' + d * cellSize + 'H' + w * cellSize +
'V' + n * cellSize;
}
}
year.append("text")
.attr("x", -5)
.attr("y", -6)
.attr("font-weight", "bold")
.attr("text-anchor", "end")
.attr("fill", "#fff")
.text(function(d) { return d.key; });
year.append("g")
.attr("text-anchor", "end")
.selectAll("text")
.data((weekday === "weekday" ? d3.range(2, 7) : d3.range(7)).map(function(i)
{ return new Date(1995, 0, i);}))
.join("text")
.attr("x", -5)
.attr("y", function(d) { return (countDay(d) + 0.5) * cellSize; })
.attr("fill", "#fff")
.text(formatDay);
el.parent().append(tooltip);
}
year.append("g")
.selectAll("rect")
.data(function(d) { return d.values; })
.join("rect")
.attr("width", cellSize - 1)
.attr("height", cellSize - 1)
.attr("x", function(d) { return timeWeek.count(d3.utcYear(d.date), d.date) *
cellSize + 0.5; })
.attr("y", function(d) { return countDay(d.date) * cellSize + 0.5; })
.attr("fill", function(d) {
if ( d.selector == selectedDate ) {
dateEl = $(this);
return 'red';
} else {
return color(d.value);
}
})
.attr('stroke', 'black')
.attr('stroke-opacity', '0')
.on("mouseover", function(d) {
$(this).attr('stroke-opacity', '0.8')
var textHelper = d.value == 1 ? ' document on ' : ' documents on ';
tooltip.html(d.value + textHelper + formatTooltip(d.date))
.css("opacity", .9)
.css("left", (d3.event.pageX - 60 + "px"))
.css("top", (d3.event.pageY - 50 + $('#stats_chart').scrollTop()) + "px");
})
.on("mouseout", function(d) {
$(this).attr('stroke-opacity', '0');
tooltip.css("opacity", 0);
})
.on("click", function(d) {
var element = el.parent();
if ( element.hasClass('activeFilter') ) {
var existingDate = new Date(element.attr('data-date'));
if ( new Date(d.selector).getTime() == existingDate.getTime() ) {
element.removeClass('activeFilter');
element.removeAttr('data-type');
element.removeAttr('data-date');
$(this).attr("fill", color(d.value));
dateEl = null;
} else {
if ( !! dateEl ) {
dateEl.attr('fill', color(d.value));
}
element.attr('data-date', d.selector);
dateEl = $(this);
$(this).attr('fill', 'red');
}
} else {
element.addClass('activeFilter');
element.attr('data-type', type);
element.attr('data-date', d.selector);
$(this).attr('fill', 'red');
dateEl = $(this);
}
kleissner.frontendChanges.onToggleFilter();
});
month.append("text")
.attr("x", function(d) { return timeWeek.count(d3.utcYear(d),
timeWeek.ceil(d)) * cellSize + 2; })
.attr("y", -5)
.attr("fill", "#fff")
.text(formatMonth);
}
var g = svg.append("g")
.attr("transform", 'translate(' + width / 2 + ', ' + width / 2 + ')');
g.selectAll("path")
.data(arcs)
.enter().append("path")
.attr("fill", function(d) { return color(d.data.name); })
.attr("d", arc);
/*text.append("tspan")
.attr("x", 0)
.attr("y", "-0.7em")
.style("font-weight", "bold")
.text(function(d) { return d.data.name; });
text.append("tspan")
.attr("x", 0)
.attr("y", "0.7em")
.attr("fill-opacity", 0.7)
.text(function(d) {
return Math.round(d.data.value/total * 10000) / 100 + '%';
});*/
var x = d3.scaleBand()
.domain(data.map(function(d) { return d.name; }))
.range([margin.left, width - margin.right])
.padding(0.1)
var y = d3.scaleLinear()
.domain([0, d3.max(data, function(d) { return d.value;} )]).nice()
.range([height - margin.bottom, margin.top])
svg.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", function(d) { return x(d.name); })
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return y(0) - y(d.value); })
.attr("width", x.bandwidth());
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);