/** Adds a simple marker with the average visit duration */ function drawDurationChart(durationMeanSec) { var dMarkerRadius = 32; var dMarkerStrokeWidth = 3; // Match with CSS var chartWidth = 150, chartHeight = 150, xPos = 40, yPosStart = chartHeight, yPosEnd = 0, // Start / End are for the animation lineHeight = 28, bottomOffset = lineHeight; // bottomOffset = lineHeight * 2; var durationSvg = d3.select('.durationChart').append('svg') .attr('width', chartWidth) .attr('height', chartHeight); // Add a group for the marker elements in the animation start state var markerG = durationSvg.append('g') .attr('class', 'marker duration') .attr('transform', 'translate(' + xPos + ', ' + yPosStart + ')') .attr('opacity', 0); // Animate the group to appear with opacity and translate animation markerG .transition() .duration(1000) .attr('transform', 'translate(' + xPos + ', ' + yPosEnd + ')') .attr('opacity', 1); // The marker elements are now relative positioned to the group markerG.append('path') // The marker line .attr('d', 'M' + dMarkerRadius + ',' + (chartHeight - bottomOffset - yPosStart) + 'L' + dMarkerRadius + ',' + (chartHeight-yPosStart)) .transition() .duration(1000) .attr('d', 'M' + dMarkerRadius + ',' + (chartHeight - bottomOffset - yPosEnd) + 'L' + dMarkerRadius + ',' + (dMarkerRadius*2)); markerG.append('path') .attr('class', 'marker-bg hexagon') .attr('d', hexagon(dMarkerRadius, dMarkerRadius, dMarkerRadius - dMarkerStrokeWidth / 2)); markerG.append('image') .attr('width', '' + dMarkerRadius * 2 * 0.6) .attr('height', '' + dMarkerRadius * 2 * 0.6) .attr('x', '' + dMarkerRadius * 2 * 0.2) .attr('y', '' + dMarkerRadius * 2 * 0.2) .attr('href', 'clock-o.svg'); // markerG.append('text') // .attr('x', dMarkerRadius) // .attr('y', chartHeight - bottomOffset + lineHeight) // .text('Duration'); markerG.append('text') .attr('x', dMarkerRadius) .attr('y', chartHeight - bottomOffset + lineHeight) // .attr('y', chartHeight - bottomOffset + lineHeight * 2) .text('∅ ' + d3.format('.1f')(durationMeanSec) + ' s'); }