/** Adds a simple marker with the average visit duration */ function updateActiveVendorChart(closestActiveClient, chartObj) { chartObj = chartObj || {}; var update = chartObj.svg ? true : false; var dMarkerRadius = 32; var dMarkerStrokeWidth = 3; // Match with CSS var chartWidth = 400, chartHeight = 150, xPos = 40, yPosStart = chartHeight, yPosEnd = 0, // Start / End are for the animation lineHeight = 28, bottomOffset = lineHeight; // bottomOffset = lineHeight * 2; var durationSvg = chartObj.svg = (chartObj.svg || d3.select('.activeVendorChart').append('svg') .attr('width', chartWidth) .attr('height', chartHeight)); // Add a group for the marker elements in the animation start state var markerG = chartObj.group = (chartObj.group || 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 if(!update) { 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)); } var img = chartObj.img = (chartObj.img || 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)); var imgUrl = 'laptop.svg'; if(closestActiveClient.vendor === 'Apple') imgUrl = 'apple.svg'; if(androidVendors.indexOf(closestActiveClient.vendor) !== -1) imgUrl = 'android.svg'; img.attr('href', imgUrl); return chartObj; }