diff --git a/Makefile b/Makefile index fd158ca..a49f0c9 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,23 @@ JS_FILES = \ src/core.js \ src/tooltip.js \ src/utils.js \ - src/models/legend.js \ src/models/axis.js \ src/models/bar.js \ - src/models/pie.js \ + src/models/cumulativeLine.js \ + src/models/legend.js \ src/models/line.js \ + src/models/linePlusBar.js \ src/models/lineWithFocus.js \ src/models/lineWithLegend.js \ - src/models/cumulativeLine.js \ + src/models/pie.js \ src/models/scatter.js \ src/models/scatterWithLegend.js \ src/models/sparkline.js \ src/models/stackedArea.js \ src/models/stackedAreaWithLegend.js \ + src/charts/cumulativeLineChartDaily.js \ src/charts/lineChart.js \ src/charts/lineChartDaily.js \ - src/charts/cumulativeLineChartDaily.js \ src/outro.js JS_COMPILER = \ diff --git a/nv.d3.js b/nv.d3.js index d8cffb6..77bf8d1 100644 --- a/nv.d3.js +++ b/nv.d3.js @@ -250,114 +250,6 @@ nv.utils.windowSize = function() { }; -nv.models.legend = function() { - var margin = {top: 5, right: 0, bottom: 5, left: 10}, - width = 400, - height = 20, - color = d3.scale.category10().range(), - dispatch = d3.dispatch('legendClick', 'legendMouseover', 'legendMouseout'); - - function chart(selection) { - selection.each(function(data) { - - var wrap = d3.select(this).selectAll('g.legend').data([data]); - var gEnter = wrap.enter().append('g').attr('class', 'legend').append('g'); - - - var g = wrap.select('g') - .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); - - - var series = g.selectAll('.series') - .data(function(d) { return d }); - var seriesEnter = series.enter().append('g').attr('class', 'series') - .on('mouseover', function(d,i) { - dispatch.legendMouseover(d,i); - }) - .on('mouseout', function(d,i) { - dispatch.legendMouseout(d,i); - }) - .on('click', function(d,i) { - dispatch.legendClick(d,i); - }); - seriesEnter.append('circle') - .style('fill', function(d,i) { return d.color || color[i % 20] }) - .style('stroke', function(d,i) { return d.color || color[i % 20] }) - .style('stroke-width', 2) - .attr('r', 5); - seriesEnter.append('text') - .text(function(d) { return d.key }) - .attr('text-anchor', 'start') - .attr('dy', '.32em') - .attr('dx', '8'); - series.classed('disabled', function(d) { return d.disabled }); - series.exit().remove(); - - - var ypos = 5, - newxpos = 5, - maxwidth = 0, - xpos; - series - .attr('transform', function(d, i) { - var length = d3.select(this).select('text').node().getComputedTextLength() + 28; - xpos = newxpos; - - if (width < margin.left + margin.right + xpos + length) { - newxpos = xpos = 5; - ypos += 20; - } - - newxpos += length; - if (newxpos > maxwidth) maxwidth = newxpos; - - return 'translate(' + xpos + ',' + ypos + ')'; - }); - - //position legend as far right as possible within the total width - g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); - - //update height value if calculated larger than current - //Asuming legend is always horizontal for now, removing if clause because this does not let legend shrink after expanding - //TODO: allow legend to be horizontal or vertical, instead of definign height/width define one, and maybe call it maxHeight/maxWidth - //if (height < margin.top + margin.bottom + ypos + 15) - height = margin.top + margin.bottom + ypos + 15; - - }); - - return chart; - } - - - chart.dispatch = dispatch; - - chart.margin = function(_) { - if (!arguments.length) return margin; - margin = _; - return chart; - }; - - chart.width = function(_) { - if (!arguments.length) return width; - width = _; - return chart; - }; - - chart.height = function(_) { - if (!arguments.length) return height; - height = _; - return chart; - }; - - chart.color = function(_) { - if (!arguments.length) return color; - color = _; - return chart; - }; - - return chart; -} - nv.models.axis = function() { var domain = [0,1], //just to have something to start with, maybe I dont need this range = [0,1], @@ -717,267 +609,403 @@ nv.models.bar = function() { return chart; } -nv.models.pie = function() { - var margin = {top: 20, right: 20, bottom: 20, left: 20}, - width = 500, - height = 500, - animate = 2000, - radius = Math.min(width-(margin.right+margin.left), height-(margin.top+margin.bottom)) / 2, - label ='label', - field ='y', - id = Math.floor(Math.random() * 10000), //Create semi-unique ID in case user doesn't select one - color = d3.scale.category20(), - showLabels = true, - donut = false, - title = ''; +nv.models.cumulativeLine = function() { + var margin = {top: 30, right: 20, bottom: 30, left: 60}, + getWidth = function() { return 960 }, + getHeight = function() { return 500 }, + color = d3.scale.category10().range(), + dotRadius = function() { return 2.5 }, + getX = function(d) { return d.x }, + getY = function(d) { return d.y }, + id = Math.floor(Math.random() * 10000); //Create semi-unique ID incase user doesn't select one - var lastWidth = 0, - lastHeight = 0; + var x = d3.scale.linear(), + dx = d3.scale.linear(), + y = d3.scale.linear(), + xAxis = nv.models.axis().scale(x).orient('bottom'), + yAxis = nv.models.axis().scale(y).orient('left'), + legend = nv.models.legend().height(30), + lines = nv.models.line(), + dispatch = d3.dispatch('tooltipShow', 'tooltipHide'), + index = {i: 0, x: 0}; - var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'tooltipShow', 'tooltipHide'); + var indexDrag = d3.behavior.drag() + .on('dragstart', dragStart) + .on('drag', dragMove) + .on('dragend', dragEnd); + + function dragStart(d,i) {} + + function dragMove(d,i) { + d.x += d3.event.dx; + d.i = Math.round(dx.invert(d.x)); + + //d3.transition(d3.select('.chart-' + id)).call(chart); + d3.select(this).attr("transform", "translate(" + dx(d.i) + ",0)"); + } + + function dragEnd(d,i) { + d3.transition(d3.select('.chart-' + id)).call(chart); + } + function chart(selection) { selection.each(function(data) { + var width = getWidth(), + height = getHeight(), + availableWidth = width - margin.left - margin.right, + availableHeight = height - margin.top - margin.bottom; - var svg = d3.select(this) - .on("click", function(d,i) { - dispatch.chartClick({ - data: d, - index: i, - pos: d3.event, - id: id - }); - }); + var series = indexify(index.i, data); + var seriesData = series + .filter(function(d) { return !d.disabled }) + .map(function(d) { return d.values }); + x .domain(d3.extent(d3.merge(seriesData), function(d) { return d.x } )) + .range([0, width - margin.left - margin.right]); - var background = svg.selectAll('svg.margin').data([data]); - var parent = background.enter(); - parent.append("text") - .attr("class", "title") - .attr("dy", ".91em") - .attr("text-anchor", "start") - .text(title); - parent.append('svg') - .attr('class','margin') - .attr('x', margin.left) - .attr('y', margin.top) - .style('overflow','visible'); + dx .domain([0, data[0].values.length - 1]) //Assumes all series have same length + .range([0, width - margin.left - margin.right]) + .clamp(true); - var wrap = background.selectAll('g.wrap').data([data]); - wrap.exit().remove(); - var wEnter = wrap.enter(); + y .domain(d3.extent(d3.merge(seriesData), function(d) { return d.y } )) + .range([height - margin.top - margin.bottom, 0]); - wEnter - .append('g') - .attr('class', 'wrap') - .attr('id','wrap-'+id) - .append('g') - .attr('class', 'pie'); + lines + .width(width - margin.left - margin.right) + .height(height - margin.top - margin.bottom) + .color(data.map(function(d,i) { + return d.color || color[i % 10]; + }).filter(function(d,i) { return !data[i].disabled })) - wrap - .attr('width', width) //-(margin.left+margin.right)) - .attr('height', height) //-(margin.top+margin.bottom)) - .attr("transform", "translate(" + radius + "," + radius + ")"); + var wrap = d3.select(this).classed('chart-' + id, true).selectAll('g.wrap').data([series]); + var gEnter = wrap.enter().append('g').attr('class', 'wrap d3cumulativeLine').append('g'); + gEnter.append('g').attr('class', 'x axis'); + gEnter.append('g').attr('class', 'y axis'); + gEnter.append('g').attr('class', 'linesWrap'); + gEnter.append('g').attr('class', 'legendWrap'); - var arc = d3.svg.arc() - .outerRadius((radius-(radius / 5))); + //TODO: margins should be adjusted based on what components are used: axes, axis labels, legend + margin.top = legend.height(); - if (donut) arc.innerRadius(radius / 2); + var g = wrap.select('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); - // Setup the Pie chart and choose the data element - var pie = d3.layout.pie() - .value(function (d) { return d[field]; }); + legend.width(width/2 - margin.right); - var slices = background.select('.pie').selectAll(".slice") - .data(pie); + g.select('.legendWrap') + .datum(data) + .attr('transform', 'translate(' + (width/2 - margin.left) + ',' + (-margin.top) +')') + .call(legend); - slices.exit().remove(); - var ae = slices.enter().append("svg:g") - .attr("class", "slice") - .on('mouseover', function(d,i){ - d3.select(this).classed('hover', true); - dispatch.tooltipShow({ - label: d.data[label], - value: d.data[field], - data: d.data, - index: i, - pos: [d3.event.pageX, d3.event.pageY], - id: id - }); + var linesWrap = g.select('.linesWrap') + .datum(series.filter(function(d) { return !d.disabled })) - }) - .on('mouseout', function(d,i){ - d3.select(this).classed('hover', false); - dispatch.tooltipHide({ - label: d.data[label], - value: d.data[field], - data: d.data, - index: i, - id: id - }); - }) - .on('click', function(d,i) { - dispatch.elementClick({ - label: d.data[label], - value: d.data[field], - data: d.data, - index: i, - pos: d3.event, - id: id - }); - d3.event.stopPropagation(); - }) - .on('dblclick', function(d,i) { - dispatch.elementDblClick({ - label: d.data[label], - value: d.data[field], - data: d.data, - index: i, - pos: d3.event, - id: id - }); - d3.event.stopPropagation(); - }); - var paths = ae.append("svg:path") - .attr('class','path') - .attr("fill", function(d, i) { return color(i); }); - //.attr('d', arc); + d3.transition(linesWrap).call(lines); - slices.select('.path') - .attr('d', arc) - .transition() - .ease("bounce") - .duration(animate) - .attrTween("d", tweenPie); - if (showLabels) { - // This does the normal label - ae.append("text"); + var indexLine = linesWrap.selectAll('.indexLine') + .data([index]); + indexLine.enter().append('rect').attr('class', 'indexLine') + .attr('width', 3) + .attr('x', -2) + .attr('fill', 'red') + .attr('fill-opacity', .5) + .call(indexDrag) - slices.select("text") - .transition() - .duration(animate) - .ease('bounce') - .attr("transform", function(d) { - d.outerRadius = radius + 10; // Set Outer Coordinate - d.innerRadius = radius + 15; // Set Inner Coordinate - return "translate(" + arc.centroid(d) + ")"; - }) - .attr("text-anchor", "middle") //center the text on it's origin - .style("font", "bold 12px Arial") - .text(function(d, i) { return d.data[label]; }); - } + indexLine + .attr("transform", function(d) { return "translate(" + dx(d.i) + ",0)" }) + .attr('height', height - margin.top - margin.bottom) - // Computes the angle of an arc, converting from radians to degrees. - function angle(d) { - var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90; - return a > 90 ? a - 180 : a; - } + xAxis + .domain(x.domain()) + .range(x.range()) + .ticks( width / 100 ) + .tickSize(-(height - margin.top - margin.bottom), 0); + + g.select('.x.axis') + .attr('transform', 'translate(0,' + y.range()[0] + ')'); + d3.transition(g.select('.x.axis')) + .call(xAxis); + + yAxis + .domain(y.domain()) + .range(y.range()) + .ticks( height / 36 ) + .tickSize(-(width - margin.right - margin.left), 0); + d3.transition(g.select('.y.axis')) + .call(yAxis); - function tweenPie(b) { - b.innerRadius = 0; - var i = d3.interpolate({startAngle: 0, endAngle: 0}, b); - return function(t) { - return arc(i(t)); - }; + + // ********** EVENT LISTENERS ********** + + legend.dispatch.on('legendClick', function(d,i) { + d.disabled = !d.disabled; + + if (!data.filter(function(d) { return !d.disabled }).length) { + data.map(function(d) { + d.disabled = false; + wrap.selectAll('.series').classed('disabled', false); + return d; + }); } + selection.transition().call(chart); + }); + + /* + legend.dispatch.on('legendMouseover', function(d, i) { + d.hover = true; + selection.transition().call(chart) + }); + + legend.dispatch.on('legendMouseout', function(d, i) { + d.hover = false; + selection.transition().call(chart) + }); + */ + + lines.dispatch.on('pointMouseover.tooltip', function(e) { + dispatch.tooltipShow({ + point: e.point, + series: e.series, + pos: [e.pos[0] + margin.left, e.pos[1] + margin.top], + seriesIndex: e.seriesIndex, + pointIndex: e.pointIndex + }); + }); + + lines.dispatch.on('pointMouseout.tooltip', function(e) { + dispatch.tooltipHide(e); + }); + }); return chart; } + + + // ********** FUNCTIONS ********** + + /* Normalize the data according to an index point. */ + function indexify(idx, data) { + return data.map(function(line, i) { + var v = getY(line.values[idx], idx); + + return { + key: line.key, + values: line.values.map(function(point, pointIndex) { + return {'x': getX(point, pointIndex), 'y': (getY(point, pointIndex) - v) / (1 + v) }; + }), + disabled: line.disabled, + hover: line.hover + /* + if (v < -.9) { + //if a series loses more than 100%, calculations fail.. anything close can cause major distortion (but is mathematically currect till it hits 100) + } + */ + }; + }); + }; + + + + + // ********** PUBLIC ACCESSORS ********** + + chart.dispatch = dispatch; + + chart.x = function(_) { + if (!arguments.length) return getX; + getX = _; + //lines.x(_); + return chart; + }; + + chart.y = function(_) { + if (!arguments.length) return getY; + getY = _; + //lines.y(_); + return chart; + }; + chart.margin = function(_) { if (!arguments.length) return margin; margin = _; return chart; }; + /* chart.width = function(_) { if (!arguments.length) return width; - if (margin.left + margin.right + 20 > _) { - width = margin.left + margin.right + 20; // Min width - } else { - width = _; - } - radius = Math.min(width-(margin.left+margin.right), height-(margin.top+margin.bottom)) / 2; + width = _; return chart; }; chart.height = function(_) { if (!arguments.length) return height; - if (margin.top + margin.bottom + 20 > _) { - height = margin.top + margin.bottom + 20; // Min height - } else { - height = _; - } - radius = Math.min(width-(margin.left+margin.right), height-(margin.top+margin.bottom)) / 2; + height = _; return chart; }; + */ - chart.animate = function(_) { - if (!arguments.length) return animate; - animate = _; + chart.width = function(_) { + if (!arguments.length) return getWidth; + getWidth = d3.functor(_); return chart; }; - chart.labelField = function(_) { - if (!arguments.length) return (label); - label = _; - return chart; + chart.height = function(_) { + if (!arguments.length) return getHeight; + getHeight = d3.functor(_); + return chart; }; - chart.dataField = function(_) { - if (!arguments.length) return (field); - field = _; + chart.dotRadius = function(_) { + if (!arguments.length) return dotRadius; + dotRadius = d3.functor(_); + lines.dotRadius = _; + return chart; + }; + + + // Expose the x-axis' tickFormat method. + //chart.xAxis = {}; + //d3.rebind(chart.xAxis, xAxis, 'tickFormat'); + chart.xAxis = xAxis; + + // Expose the y-axis' tickFormat method. + //chart.yAxis = {}; + //d3.rebind(chart.yAxis, yAxis, 'tickFormat'); + chart.yAxis = yAxis; + + + return chart; +} + +nv.models.legend = function() { + var margin = {top: 5, right: 0, bottom: 5, left: 10}, + width = 400, + height = 20, + color = d3.scale.category10().range(), + dispatch = d3.dispatch('legendClick', 'legendMouseover', 'legendMouseout'); + + function chart(selection) { + selection.each(function(data) { + + var wrap = d3.select(this).selectAll('g.legend').data([data]); + var gEnter = wrap.enter().append('g').attr('class', 'legend').append('g'); + + + var g = wrap.select('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); + + + var series = g.selectAll('.series') + .data(function(d) { return d }); + var seriesEnter = series.enter().append('g').attr('class', 'series') + .on('mouseover', function(d,i) { + dispatch.legendMouseover(d,i); + }) + .on('mouseout', function(d,i) { + dispatch.legendMouseout(d,i); + }) + .on('click', function(d,i) { + dispatch.legendClick(d,i); + }); + seriesEnter.append('circle') + .style('fill', function(d,i) { return d.color || color[i % 20] }) + .style('stroke', function(d,i) { return d.color || color[i % 20] }) + .style('stroke-width', 2) + .attr('r', 5); + seriesEnter.append('text') + .text(function(d) { return d.key }) + .attr('text-anchor', 'start') + .attr('dy', '.32em') + .attr('dx', '8'); + series.classed('disabled', function(d) { return d.disabled }); + series.exit().remove(); + + + var ypos = 5, + newxpos = 5, + maxwidth = 0, + xpos; + series + .attr('transform', function(d, i) { + var length = d3.select(this).select('text').node().getComputedTextLength() + 28; + xpos = newxpos; + + if (width < margin.left + margin.right + xpos + length) { + newxpos = xpos = 5; + ypos += 20; + } + + newxpos += length; + if (newxpos > maxwidth) maxwidth = newxpos; + + return 'translate(' + xpos + ',' + ypos + ')'; + }); + + //position legend as far right as possible within the total width + g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); + + //update height value if calculated larger than current + //Asuming legend is always horizontal for now, removing if clause because this does not let legend shrink after expanding + //TODO: allow legend to be horizontal or vertical, instead of definign height/width define one, and maybe call it maxHeight/maxWidth + //if (height < margin.top + margin.bottom + ypos + 15) + height = margin.top + margin.bottom + ypos + 15; + + }); + return chart; - }; + } - chart.showLabels = function(_) { - if (!arguments.length) return (showLabels); - showLabels = _; - return chart; - }; - chart.donut = function(_) { - if (!arguments.length) return (donut); - donut = _; - return chart; - }; + chart.dispatch = dispatch; - chart.title = function(_) { - if (!arguments.length) return (title); - title = _; - return chart; + chart.margin = function(_) { + if (!arguments.length) return margin; + margin = _; + return chart; }; - chart.id = function(_) { - if (!arguments.length) return id; - id = _; - return chart; + chart.width = function(_) { + if (!arguments.length) return width; + width = _; + return chart; }; - chart.dispatch = dispatch; - - + chart.height = function(_) { + if (!arguments.length) return height; + height = _; + return chart; + }; + chart.color = function(_) { + if (!arguments.length) return color; + color = _; return chart; + }; + + return chart; } //TODO: consider adding axes // -How to deal with time vs generic linear, vs any other scale? @@ -1230,45 +1258,289 @@ nv.models.line = function() { return chart; }; - chart.yDomain = function(_) { - if (!arguments.length) return yDomain; - yDomain = _; + chart.yDomain = function(_) { + if (!arguments.length) return yDomain; + yDomain = _; + return chart; + }; + + chart.interactive = function(_) { + if (!arguments.length) return interactive; + interactive = _; + return chart; + }; + + chart.clipEdge = function(_) { + if (!arguments.length) return clipEdge; + clipEdge = _; + return chart; + }; + + chart.clipVoronoi= function(_) { + if (!arguments.length) return clipVoronoi; + clipVoronoi = _; + return chart; + }; + + chart.dotRadius = function(_) { + if (!arguments.length) return dotRadius; + dotRadius = d3.functor(_); + return chart; + }; + + chart.color = function(_) { + if (!arguments.length) return color; + color = _; + return chart; + }; + + chart.id = function(_) { + if (!arguments.length) return id; + id = _; + return chart; + }; + + + return chart; +} + +nv.models.linePlusBar = function() { + var margin = {top: 30, right: 60, bottom: 50, left: 60}, + getWidth = function() { return 960 }, + getHeight = function() { return 500 }, + dotRadius = function() { return 2.5 }, + getX = function(d) { return d.x }, + getY = function(d) { return d.y }, + color = d3.scale.category10().range(), + dispatch = d3.dispatch('tooltipShow', 'tooltipHide'); + + var x = d3.scale.linear(), + y1 = d3.scale.linear(), + y2 = d3.scale.linear(), + xAxis = nv.models.axis().scale(x).orient('bottom'), + yAxis1 = nv.models.axis().scale(y1).orient('left'), + yAxis2 = nv.models.axis().scale(y2).orient('right'), + legend = nv.models.legend().height(30), + lines = nv.models.line(), + bars = nv.models.historicalBar(); + + + function chart(selection) { + selection.each(function(data) { + var width = getWidth(), + height = getHeight(), + availableWidth = width - margin.left - margin.right, + availableHeight = height - margin.top - margin.bottom; + + var series1 = data.filter(function(d) { return !d.disabled && !d.bar }) + .map(function(d) { + return d.values.map(function(d,i) { + return { x: getX(d,i), y: getY(d,i) } + }) + }); + + var series2 = data.filter(function(d) { return !d.disabled && d.bar }) + .map(function(d) { + return d.values.map(function(d,i) { + return { x: getX(d,i), y: getY(d,i) } + }) + }); + + x .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x } )) + .range([0, availableWidth]); + + y1 .domain(d3.extent(d3.merge(series1), function(d) { return d.y } )) + .range([availableHeight, 0]); + + y2 .domain(d3.extent(d3.merge(series2), function(d) { return d.y } )) + .range([availableHeight, 0]); + + lines + .width(availableWidth) + .height(availableHeight) + .color(data.map(function(d,i) { + return d.color || color[i % 10]; + }).filter(function(d,i) { return !data[i].disabled && !data[i].bar })) + + bars + .width(availableWidth) + .height(availableHeight) + .color(data.map(function(d,i) { + return d.color || color[i % 10]; + }).filter(function(d,i) { return !data[i].disabled && data[i].bar })) + + + var wrap = d3.select(this).selectAll('g.wrap').data([data]); + var gEnter = wrap.enter().append('g').attr('class', 'wrap d3linePlusBar').append('g'); + + gEnter.append('g').attr('class', 'x axis'); + gEnter.append('g').attr('class', 'y1 axis'); + gEnter.append('g').attr('class', 'y2 axis'); + gEnter.append('g').attr('class', 'barsWrap'); + gEnter.append('g').attr('class', 'linesWrap'); + gEnter.append('g').attr('class', 'legendWrap'); + + + legend.dispatch.on('legendClick', function(d,i) { + d.disabled = !d.disabled; + + if (!data.filter(function(d) { return !d.disabled }).length) { + data.map(function(d) { + d.disabled = false; + wrap.selectAll('.series').classed('disabled', false); + return d; + }); + } + + selection.transition().call(chart); + }); + + + lines.dispatch.on('pointMouseover.tooltip', function(e) { + dispatch.tooltipShow({ + point: e.point, + series: e.series, + pos: [e.pos[0] + margin.left, e.pos[1] + margin.top], + seriesIndex: e.seriesIndex, + pointIndex: e.pointIndex + }); + }); + + lines.dispatch.on('pointMouseout.tooltip', function(e) { + dispatch.tooltipHide(e); + }); + + + + bars.dispatch.on('elementMouseover.tooltip', function(e) { + dispatch.tooltipShow({ + point: e.point, + series: e.series, + pos: [e.pos[0] + margin.left, e.pos[1] + margin.top], + seriesIndex: e.seriesIndex, + pointIndex: e.pointIndex + }); + }); + + bars.dispatch.on('elementMouseout.tooltip', function(e) { + dispatch.tooltipHide(e); + }); + + + + //TODO: margins should be adjusted based on what components are used: axes, axis labels, legend + margin.top = legend.height(); + + var g = wrap.select('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); + + + legend.width(width/2 - margin.right); + + g.select('.legendWrap') + .datum(data) + .attr('transform', 'translate(' + (width/2 - margin.left) + ',' + (-margin.top) +')') + .call(legend); + + + var barsData = data.filter(function(d) { return !d.disabled && d.bar }); + + var barsWrap = g.select('.barsWrap') + .datum(barsData.length ? barsData : [{values:[]}]) + //.datum(data.filter(function(d) { return !d.disabled && d.bar })) + + var linesWrap = g.select('.linesWrap') + .datum(data.filter(function(d) { return !d.disabled && !d.bar })) + + + d3.transition(barsWrap).call(bars); + d3.transition(linesWrap).call(lines); + + + xAxis + .domain(x.domain()) + .range(x.range()) + .ticks( width / 100 ) + .tickSize(-availableHeight, 0); + + g.select('.x.axis') + .attr('transform', 'translate(0,' + y1.range()[0] + ')'); + d3.transition(g.select('.x.axis')) + .call(xAxis); + + yAxis1 + .domain(y1.domain()) + .range(y1.range()) + .ticks( height / 36 ) + .tickSize(-availableWidth, 0); + + d3.transition(g.select('.y1.axis')) + .call(yAxis1); + + yAxis2 + .domain(y2.domain()) + .range(y2.range()) + .ticks( height / 36 ) + .tickSize(series1.length ? 0 : -availableWidth, 0); // Show the y2 rules only if y1 has none + + g.select('.y2.axis') + .attr('transform', 'translate(' + x.range()[1] + ',0)'); + + d3.transition(g.select('.y2.axis')) + .call(yAxis2); + + }); + + return chart; + } + + chart.dispatch = dispatch; + chart.legend = legend; + chart.lines = lines; + chart.bars = bars; + chart.xAxis = xAxis; + chart.yAxis1 = yAxis1; + chart.yAxis2 = yAxis2; + + //d3.rebind(chart, lines, 'interactive'); + //consider rebinding x and y as well + + chart.x = function(_) { + if (!arguments.length) return getX; + getX = _; + lines.x(_); + return chart; + }; + + chart.y = function(_) { + if (!arguments.length) return getY; + getY = _; + lines.y(_); return chart; }; - chart.interactive = function(_) { - if (!arguments.length) return interactive; - interactive = _; + chart.margin = function(_) { + if (!arguments.length) return margin; + margin = _; return chart; }; - chart.clipEdge = function(_) { - if (!arguments.length) return clipEdge; - clipEdge = _; + chart.width = function(_) { + if (!arguments.length) return getWidth; + getWidth = d3.functor(_); return chart; }; - chart.clipVoronoi= function(_) { - if (!arguments.length) return clipVoronoi; - clipVoronoi = _; + chart.height = function(_) { + if (!arguments.length) return getHeight; + getHeight = d3.functor(_); return chart; }; chart.dotRadius = function(_) { if (!arguments.length) return dotRadius; dotRadius = d3.functor(_); - return chart; - }; - - chart.color = function(_) { - if (!arguments.length) return color; - color = _; - return chart; - }; - - chart.id = function(_) { - if (!arguments.length) return id; - id = _; + lines.dotRadius = _; return chart; }; @@ -1831,242 +2103,191 @@ nv.models.lineWithLegend = function() { return chart; } -nv.models.cumulativeLine = function() { - var margin = {top: 30, right: 20, bottom: 30, left: 60}, - getWidth = function() { return 960 }, - getHeight = function() { return 500 }, - color = d3.scale.category10().range(), - dotRadius = function() { return 2.5 }, - getX = function(d) { return d.x }, - getY = function(d) { return d.y }, - id = Math.floor(Math.random() * 10000); //Create semi-unique ID incase user doesn't select one - - var x = d3.scale.linear(), - dx = d3.scale.linear(), - y = d3.scale.linear(), - xAxis = nv.models.axis().scale(x).orient('bottom'), - yAxis = nv.models.axis().scale(y).orient('left'), - legend = nv.models.legend().height(30), - lines = nv.models.line(), - dispatch = d3.dispatch('tooltipShow', 'tooltipHide'), - index = {i: 0, x: 0}; - - - var indexDrag = d3.behavior.drag() - .on('dragstart', dragStart) - .on('drag', dragMove) - .on('dragend', dragEnd); - - function dragStart(d,i) {} - - function dragMove(d,i) { - d.x += d3.event.dx; - d.i = Math.round(dx.invert(d.x)); +nv.models.pie = function() { + var margin = {top: 20, right: 20, bottom: 20, left: 20}, + width = 500, + height = 500, + animate = 2000, + radius = Math.min(width-(margin.right+margin.left), height-(margin.top+margin.bottom)) / 2, + label ='label', + field ='y', + id = Math.floor(Math.random() * 10000), //Create semi-unique ID in case user doesn't select one + color = d3.scale.category20(), + showLabels = true, + donut = false, + title = ''; - //d3.transition(d3.select('.chart-' + id)).call(chart); - d3.select(this).attr("transform", "translate(" + dx(d.i) + ",0)"); - } + var lastWidth = 0, + lastHeight = 0; - function dragEnd(d,i) { - d3.transition(d3.select('.chart-' + id)).call(chart); - } + var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'tooltipShow', 'tooltipHide'); function chart(selection) { selection.each(function(data) { - var width = getWidth(), - height = getHeight(), - availableWidth = width - margin.left - margin.right, - availableHeight = height - margin.top - margin.bottom; - - var series = indexify(index.i, data); - - var seriesData = series - .filter(function(d) { return !d.disabled }) - .map(function(d) { return d.values }); - - x .domain(d3.extent(d3.merge(seriesData), function(d) { return d.x } )) - .range([0, width - margin.left - margin.right]); - - dx .domain([0, data[0].values.length - 1]) //Assumes all series have same length - .range([0, width - margin.left - margin.right]) - .clamp(true); - - y .domain(d3.extent(d3.merge(seriesData), function(d) { return d.y } )) - .range([height - margin.top - margin.bottom, 0]); - - - lines - .width(width - margin.left - margin.right) - .height(height - margin.top - margin.bottom) - .color(data.map(function(d,i) { - return d.color || color[i % 10]; - }).filter(function(d,i) { return !data[i].disabled })) - - - var wrap = d3.select(this).classed('chart-' + id, true).selectAll('g.wrap').data([series]); - var gEnter = wrap.enter().append('g').attr('class', 'wrap d3cumulativeLine').append('g'); - - gEnter.append('g').attr('class', 'x axis'); - gEnter.append('g').attr('class', 'y axis'); - gEnter.append('g').attr('class', 'linesWrap'); - gEnter.append('g').attr('class', 'legendWrap'); - - - - //TODO: margins should be adjusted based on what components are used: axes, axis labels, legend - margin.top = legend.height(); - - var g = wrap.select('g') - .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); - - - legend.width(width/2 - margin.right); - - g.select('.legendWrap') - .datum(data) - .attr('transform', 'translate(' + (width/2 - margin.left) + ',' + (-margin.top) +')') - .call(legend); - - - var linesWrap = g.select('.linesWrap') - .datum(series.filter(function(d) { return !d.disabled })) - - - d3.transition(linesWrap).call(lines); - - - var indexLine = linesWrap.selectAll('.indexLine') - .data([index]); - indexLine.enter().append('rect').attr('class', 'indexLine') - .attr('width', 3) - .attr('x', -2) - .attr('fill', 'red') - .attr('fill-opacity', .5) - .call(indexDrag) - indexLine - .attr("transform", function(d) { return "translate(" + dx(d.i) + ",0)" }) - .attr('height', height - margin.top - margin.bottom) + var svg = d3.select(this) + .on("click", function(d,i) { + dispatch.chartClick({ + data: d, + index: i, + pos: d3.event, + id: id + }); + }); - xAxis - .domain(x.domain()) - .range(x.range()) - .ticks( width / 100 ) - .tickSize(-(height - margin.top - margin.bottom), 0); - g.select('.x.axis') - .attr('transform', 'translate(0,' + y.range()[0] + ')'); - d3.transition(g.select('.x.axis')) - .call(xAxis); + var background = svg.selectAll('svg.margin').data([data]); + var parent = background.enter(); + parent.append("text") + .attr("class", "title") + .attr("dy", ".91em") + .attr("text-anchor", "start") + .text(title); + parent.append('svg') + .attr('class','margin') + .attr('x', margin.left) + .attr('y', margin.top) + .style('overflow','visible'); - yAxis - .domain(y.domain()) - .range(y.range()) - .ticks( height / 36 ) - .tickSize(-(width - margin.right - margin.left), 0); + var wrap = background.selectAll('g.wrap').data([data]); + wrap.exit().remove(); + var wEnter = wrap.enter(); - d3.transition(g.select('.y.axis')) - .call(yAxis); + wEnter + .append('g') + .attr('class', 'wrap') + .attr('id','wrap-'+id) + .append('g') + .attr('class', 'pie'); + wrap + .attr('width', width) //-(margin.left+margin.right)) + .attr('height', height) //-(margin.top+margin.bottom)) + .attr("transform", "translate(" + radius + "," + radius + ")"); - // ********** EVENT LISTENERS ********** - legend.dispatch.on('legendClick', function(d,i) { - d.disabled = !d.disabled; - if (!data.filter(function(d) { return !d.disabled }).length) { - data.map(function(d) { - d.disabled = false; - wrap.selectAll('.series').classed('disabled', false); - return d; - }); - } + var arc = d3.svg.arc() + .outerRadius((radius-(radius / 5))); - selection.transition().call(chart); - }); + if (donut) arc.innerRadius(radius / 2); - /* - legend.dispatch.on('legendMouseover', function(d, i) { - d.hover = true; - selection.transition().call(chart) - }); - legend.dispatch.on('legendMouseout', function(d, i) { - d.hover = false; - selection.transition().call(chart) - }); - */ + // Setup the Pie chart and choose the data element + var pie = d3.layout.pie() + .value(function (d) { return d[field]; }); - lines.dispatch.on('pointMouseover.tooltip', function(e) { - dispatch.tooltipShow({ - point: e.point, - series: e.series, - pos: [e.pos[0] + margin.left, e.pos[1] + margin.top], - seriesIndex: e.seriesIndex, - pointIndex: e.pointIndex - }); - }); + var slices = background.select('.pie').selectAll(".slice") + .data(pie); - lines.dispatch.on('pointMouseout.tooltip', function(e) { - dispatch.tooltipHide(e); - }); + slices.exit().remove(); + var ae = slices.enter().append("svg:g") + .attr("class", "slice") + .on('mouseover', function(d,i){ + d3.select(this).classed('hover', true); + dispatch.tooltipShow({ + label: d.data[label], + value: d.data[field], + data: d.data, + index: i, + pos: [d3.event.pageX, d3.event.pageY], + id: id + }); - }); + }) + .on('mouseout', function(d,i){ + d3.select(this).classed('hover', false); + dispatch.tooltipHide({ + label: d.data[label], + value: d.data[field], + data: d.data, + index: i, + id: id + }); + }) + .on('click', function(d,i) { + dispatch.elementClick({ + label: d.data[label], + value: d.data[field], + data: d.data, + index: i, + pos: d3.event, + id: id + }); + d3.event.stopPropagation(); + }) + .on('dblclick', function(d,i) { + dispatch.elementDblClick({ + label: d.data[label], + value: d.data[field], + data: d.data, + index: i, + pos: d3.event, + id: id + }); + d3.event.stopPropagation(); + }); - return chart; - } + var paths = ae.append("svg:path") + .attr('class','path') + .attr("fill", function(d, i) { return color(i); }); + //.attr('d', arc); + slices.select('.path') + .attr('d', arc) + .transition() + .ease("bounce") + .duration(animate) + .attrTween("d", tweenPie); + if (showLabels) { + // This does the normal label + ae.append("text"); - // ********** FUNCTIONS ********** + slices.select("text") + .transition() + .duration(animate) + .ease('bounce') + .attr("transform", function(d) { + d.outerRadius = radius + 10; // Set Outer Coordinate + d.innerRadius = radius + 15; // Set Inner Coordinate + return "translate(" + arc.centroid(d) + ")"; + }) + .attr("text-anchor", "middle") //center the text on it's origin + .style("font", "bold 12px Arial") + .text(function(d, i) { return d.data[label]; }); + } - /* Normalize the data according to an index point. */ - function indexify(idx, data) { - return data.map(function(line, i) { - var v = getY(line.values[idx], idx); - return { - key: line.key, - values: line.values.map(function(point, pointIndex) { - return {'x': getX(point, pointIndex), 'y': (getY(point, pointIndex) - v) / (1 + v) }; - }), - disabled: line.disabled, - hover: line.hover - /* - if (v < -.9) { - //if a series loses more than 100%, calculations fail.. anything close can cause major distortion (but is mathematically currect till it hits 100) + // Computes the angle of an arc, converting from radians to degrees. + function angle(d) { + var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90; + return a > 90 ? a - 180 : a; } - */ - }; - }); - }; - // ********** PUBLIC ACCESSORS ********** - chart.dispatch = dispatch; + function tweenPie(b) { + b.innerRadius = 0; + var i = d3.interpolate({startAngle: 0, endAngle: 0}, b); + return function(t) { + return arc(i(t)); + }; + } - chart.x = function(_) { - if (!arguments.length) return getX; - getX = _; - //lines.x(_); - return chart; - }; - chart.y = function(_) { - if (!arguments.length) return getY; - getY = _; - //lines.y(_); + }); + return chart; - }; + } chart.margin = function(_) { if (!arguments.length) return margin; @@ -2074,52 +2295,75 @@ nv.models.cumulativeLine = function() { return chart; }; - /* chart.width = function(_) { if (!arguments.length) return width; - width = _; + if (margin.left + margin.right + 20 > _) { + width = margin.left + margin.right + 20; // Min width + } else { + width = _; + } + radius = Math.min(width-(margin.left+margin.right), height-(margin.top+margin.bottom)) / 2; return chart; }; chart.height = function(_) { if (!arguments.length) return height; - height = _; + if (margin.top + margin.bottom + 20 > _) { + height = margin.top + margin.bottom + 20; // Min height + } else { + height = _; + } + radius = Math.min(width-(margin.left+margin.right), height-(margin.top+margin.bottom)) / 2; return chart; }; - */ - chart.width = function(_) { - if (!arguments.length) return getWidth; - getWidth = d3.functor(_); + chart.animate = function(_) { + if (!arguments.length) return animate; + animate = _; return chart; }; - chart.height = function(_) { - if (!arguments.length) return getHeight; - getHeight = d3.functor(_); - return chart; + chart.labelField = function(_) { + if (!arguments.length) return (label); + label = _; + return chart; }; - chart.dotRadius = function(_) { - if (!arguments.length) return dotRadius; - dotRadius = d3.functor(_); - lines.dotRadius = _; + chart.dataField = function(_) { + if (!arguments.length) return (field); + field = _; return chart; }; + chart.showLabels = function(_) { + if (!arguments.length) return (showLabels); + showLabels = _; + return chart; + }; - // Expose the x-axis' tickFormat method. - //chart.xAxis = {}; - //d3.rebind(chart.xAxis, xAxis, 'tickFormat'); - chart.xAxis = xAxis; + chart.donut = function(_) { + if (!arguments.length) return (donut); + donut = _; + return chart; + }; - // Expose the y-axis' tickFormat method. - //chart.yAxis = {}; - //d3.rebind(chart.yAxis, yAxis, 'tickFormat'); - chart.yAxis = yAxis; + chart.title = function(_) { + if (!arguments.length) return (title); + title = _; + return chart; + }; + chart.id = function(_) { + if (!arguments.length) return id; + id = _; + return chart; + }; - return chart; + chart.dispatch = dispatch; + + + + return chart; } nv.models.scatter = function() { @@ -3158,11 +3402,12 @@ nv.models.stackedAreaWithLegend = function() { return chart; } -// This is an attempt to make an extremely easy to use chart that is ready to go, -// basically the chart models with the extra glue... Queuing, tooltips, automatic resize, etc. -// I may make these more specific, like 'time series line with month end data points', etc. -// or may make yet another layer of abstraction... common settings. -nv.charts.line = function() { +// This technique works AS IS for month end data points +// In fact, this works for any series where each value is evenly spaced, +// and every series starts at the same value and is 1 to 1 +// In other words, values at the same index, need to have the same x value +// for all series +nv.charts.cumulativeLineChartDaily = function() { var selector = null, data = [], duration = 500, @@ -3172,14 +3417,16 @@ nv.charts.line = function() { }; - var graph = nv.models.lineWithLegend(), + var graph = nv.models.cumulativeLine() + .x(function(d,i) { return i }), showTooltip = function(e) { var offsetElement = document.getElementById(selector.substr(1)), left = e.pos[0] + offsetElement.offsetLeft, top = e.pos[1] + offsetElement.offsetTop, formatX = graph.xAxis.tickFormat(), formatY = graph.yAxis.tickFormat(), - x = formatX(graph.x()(e.point)), + x = formatX(graph.x()(e, e.pointIndex)), + //x = formatX(graph.x()(e.point)), y = formatY(graph.y()(e.point)), content = tooltip(e.series.key, x, y, e, graph); @@ -3187,8 +3434,14 @@ nv.charts.line = function() { }; //setting component defaults - graph.xAxis.tickFormat(d3.format(',r')); - graph.yAxis.tickFormat(d3.format(',.2f')); + //graph.xAxis.tickFormat(d3.format(',r')); + graph.xAxis.tickFormat(function(d) { + //return d3.time.format('%x')(new Date(d)) + return d3.time.format('%x')(new Date(data[0].values[d].x)) + }); + + //graph.yAxis.tickFormat(d3.format(',.2f')); + graph.yAxis.tickFormat(d3.format(',.2%')); //TODO: consider a method more similar to how the models are built @@ -3321,7 +3574,7 @@ nv.charts.line = function() { // basically the chart models with the extra glue... Queuing, tooltips, automatic resize, etc. // I may make these more specific, like 'time series line with month end data points', etc. // or may make yet another layer of abstraction... common settings. -nv.charts.lineChartDaily = function() { +nv.charts.line = function() { var selector = null, data = [], duration = 500, @@ -3331,16 +3584,14 @@ nv.charts.lineChartDaily = function() { }; - var graph = nv.models.lineWithLegend() - .x(function(d,i) { return i }), + var graph = nv.models.lineWithLegend(), showTooltip = function(e) { var offsetElement = document.getElementById(selector.substr(1)), left = e.pos[0] + offsetElement.offsetLeft, top = e.pos[1] + offsetElement.offsetTop, formatX = graph.xAxis.tickFormat(), formatY = graph.yAxis.tickFormat(), - x = formatX(graph.x()(e, e.pointIndex)), - //x = formatX(graph.x()(e.point)), + x = formatX(graph.x()(e.point)), y = formatY(graph.y()(e.point)), content = tooltip(e.series.key, x, y, e, graph); @@ -3348,15 +3599,8 @@ nv.charts.lineChartDaily = function() { }; //setting component defaults - //graph.xAxis.tickFormat(d3.format(',r')); - graph.xAxis.tickFormat(function(d) { - //return d3.time.format('%x')(new Date(d)) - //log(d, data[0].values[d]); - return d3.time.format('%x')(new Date(data[0].values[d].x)) - }); - - //graph.yAxis.tickFormat(d3.format(',.2f')); - graph.yAxis.tickFormat(d3.format(',.2%')); + graph.xAxis.tickFormat(d3.format(',r')); + graph.yAxis.tickFormat(d3.format(',.2f')); //TODO: consider a method more similar to how the models are built @@ -3485,12 +3729,11 @@ nv.charts.lineChartDaily = function() { }; -// This technique works AS IS for month end data points -// In fact, this works for any series where each value is evenly spaced, -// and every series starts at the same value and is 1 to 1 -// In other words, values at the same index, need to have the same x value -// for all series -nv.charts.cumulativeLineChartDaily = function() { +// This is an attempt to make an extremely easy to use chart that is ready to go, +// basically the chart models with the extra glue... Queuing, tooltips, automatic resize, etc. +// I may make these more specific, like 'time series line with month end data points', etc. +// or may make yet another layer of abstraction... common settings. +nv.charts.lineChartDaily = function() { var selector = null, data = [], duration = 500, @@ -3500,7 +3743,7 @@ nv.charts.cumulativeLineChartDaily = function() { }; - var graph = nv.models.cumulativeLine() + var graph = nv.models.lineWithLegend() .x(function(d,i) { return i }), showTooltip = function(e) { var offsetElement = document.getElementById(selector.substr(1)), @@ -3520,6 +3763,7 @@ nv.charts.cumulativeLineChartDaily = function() { //graph.xAxis.tickFormat(d3.format(',r')); graph.xAxis.tickFormat(function(d) { //return d3.time.format('%x')(new Date(d)) + //log(d, data[0].values[d]); return d3.time.format('%x')(new Date(data[0].values[d].x)) }); diff --git a/nv.d3.min.js b/nv.d3.min.js index f5172f6..65d881d 100644 --- a/nv.d3.min.js +++ b/nv.d3.min.js @@ -1,2 +1,2 @@ -(function(){function b(a,b){var c=[31,28,31,30,31,30,31,31,30,31,30,31];return a!=2?c[a-1]:b%4!=0?c[1]:b%100==0&&b%400!=0?c[1]:c[1]+1}function c(a,b,c){return function(d,e,f){var g=a(d),h=[];g1)while(gl+k&&(o=l-h-5);break;case"w":n=b[0]+e,o=b[1]-h/2,n+i>j&&(n=b[0]-i-e),ol+k&&(o=l-h-5);break;case"n":n=b[0]-i/2,o=b[1]+e,nj&&(n=j-i-5),o+h>l+k&&(o=b[1]-h-e);break;case"s":n=b[0]-i/2,o=b[1]-h-e,nj&&(n=j-i-5),l>o&&(o=b[1]+20)}return f.style.left=n+"px",f.style.top=o+"px",f.style.opacity=1,f},b.cleanup=function(){var a=document.getElementsByClassName("nvtooltip"),b=[];while(a.length)b.push(a[0]),a[0].style.transitionDelay="0 !important",a[0].style.opacity=0,a[0].className="nvtooltip-pending-removal";setTimeout(function(){while(b.length){var a=b.pop();a.parentNode.removeChild(a)}},500)}}(),a.utils.windowSize=function(){var a={width:640,height:480};return document.body&&document.body.offsetWidth&&(a.width=document.body.offsetWidth,a.height=document.body.offsetHeight),document.compatMode=="CSS1Compat"&&document.documentElement&&document.documentElement.offsetWidth&&(a.width=document.documentElement.offsetWidth,a.height=document.documentElement.offsetHeight),window.innerWidth&&window.innerHeight&&(a.width=window.innerWidth,a.height=window.innerHeight),a},a.models.legend=function(){function f(g){return g.each(function(f){var g=d3.select(this).selectAll("g.legend").data([f]),h=g.enter().append("g").attr("class","legend").append("g"),i=g.select("g").attr("transform","translate("+a.left+","+a.top+")"),j=i.selectAll(".series").data(function(a){return a}),k=j.enter().append("g").attr("class","series").on("mouseover",function(a,b){e.legendMouseover(a,b)}).on("mouseout",function(a,b){e.legendMouseout(a,b)}).on("click",function(a,b){e.legendClick(a,b)});k.append("circle").style("fill",function(a,b){return a.color||d[b%20]}).style("stroke",function(a,b){return a.color||d[b%20]}).style("stroke-width",2).attr("r",5),k.append("text").text(function(a){return a.key}).attr("text-anchor","start").attr("dy",".32em").attr("dx","8"),j.classed("disabled",function(a){return a.disabled}),j.exit().remove();var l=5,m=5,n=0,o;j.attr("transform",function(c,d){var e=d3.select(this).select("text").node().getComputedTextLength()+28;return o=m,bn&&(n=m),"translate("+o+","+l+")"}),i.attr("transform","translate("+(b-a.right-n)+","+a.top+")"),c=a.top+a.bottom+l+15}),f}var a={top:5,right:0,bottom:5,left:10},b=400,c=20,d=d3.scale.category10().range(),e=d3.dispatch("legendClick","legendMouseover","legendMouseout");return f.dispatch=e,f.margin=function(b){return arguments.length?(a=b,f):a},f.width=function(a){return arguments.length?(b=a,f):b},f.height=function(a){return arguments.length?(c=a,f):c},f.color=function(a){return arguments.length?(d=a,f):d},f},a.models.axis=function(){function g(h){return h.each(function(g){e.domain(a).range(b),f.orient(c);var h=d3.select(this).selectAll("text.axislabel").data([d||null]);switch(c){case"top":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0),h.attr("x",b[1]/2);break;case"right":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(90)").attr("y",-40),h.attr("x",-b[0]/2);break;case"bottom":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",25),h.attr("x",b[1]/2);break;case"left":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(-90)").attr("y",-40),h.attr("x",-b[0]/2)}h.exit().remove(),h.text(function(a){return a}),d3.transition(d3.select(this)).call(f),d3.select(this).selectAll("line.tick").filter(function(a){return!parseFloat(Math.round(a*1e5)/1e6)}).classed("zero",!0)}),g}var a=[0,1],b=[0,1],c="bottom",d=!1,e=d3.scale.linear(),f=d3.svg.axis().scale(e);return g.orient=function(a){return arguments.length?(c=a,g):c},g.domain=function(b){return arguments.length?(a=b,g):a},g.range=function(a){return arguments.length?(b=a,g):b},g.scale=function(a){return arguments.length?(e=a,f.scale(e),g):e},g.axisLabel=function(a){return arguments.length?(d=a,g):d},d3.rebind(g,f,"ticks","tickSubdivide","tickSize","tickPadding","tickFormat"),g},a.models.bar=function(){function q(r){return r.each(function(q){l.domain(q.map(function(a,b){return a[e]})).rangeRoundBands([0,b-a.left-a.right],.1);var r=d3.min(q,function(a){return a[j]}),s=d3.max(q,function(a){return a[j]}),t=Math.max(-r,s),u=-t;r>=0&&(u=0),m.domain([u,t]).range([c-a.top-a.bottom,0]).nice(),n.ticks(b/100),o.ticks(c/36).tickSize(-(b-a.right-a.left),0);var v=d3.select(this).on("click",function(a,b){p.chartClick({data:a,index:b,pos:d3.event,id:h})}),w=v.selectAll("g.wrap").data([q]),z=w.enter();z.append("text").attr("class","title").attr("dy",".91em").attr("text-anchor","start").text(k),z=z.append("g").attr("class","wrap").attr("id","wrap-"+h).append("g"),z.append("g").attr("class","x axis"),z.append("g").attr("class","y axis"),z.append("g").attr("class","bars"),w.attr("width",b).attr("height",c);var A=w.select("g").attr("transform","translate("+a.left+","+a.top+")"),B=w.select(".bars").selectAll(".bar").data(function(a){return a});B.exit().remove();var C=B.enter().append("svg:rect").attr("class",function(a){return a[j]<0?"bar negative":"bar positive"}).attr("fill",function(a,b){return i(b)}).attr("x",0).on("mouseover",function(a,b){d3.select(this).classed("hover",!0),p.tooltipShow({label:a[e],value:a[j],data:a,index:b,pos:[d3.event.pageX,d3.event.pageY],id:h})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),p.tooltipHide({label:a[e],value:a[j],data:a,index:b,id:h})}).on("click",function(a,b){p.elementClick({label:a[e],value:a[j],data:a,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}).on("dblclick",function(a,b){p.elementDblClick({label:a[e],value:a[j],data:a,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()});B.attr("class",function(a){return a[j]<0?"bar negative":"bar positive"}).attr("transform",function(a,b){return"translate("+l(a[e])+",0)"}).attr("width",l.rangeBand).order().transition().duration(d).attr("y",function(a){return m(Math.max(0,a[j]))}).attr("height",function(a){return Math.abs(m(a[j])-m(0))}),A.select(".x.axis").attr("transform","translate(0,"+m.range()[0]+")").call(n),f&&A.select(".x.axis").selectAll("text").attr("text-anchor","start").attr("transform",function(a){return"rotate(35)translate("+this.getBBox().height/2+","+"0"+")"}),g||(A.select(".x.axis").selectAll("text").attr("fill","rgba(0,0,0,0)"),A.select(".x.axis").selectAll("line").attr("style","opacity: 0")),A.select(".y.axis").call(o)}),q}var a={top:20,right:10,bottom:80,left:60},b=960,c=500,d=500,e="label",f=!0,g=!0,h=Math.floor(Math.random()*1e4),i=d3.scale.category20(),j="y",k="",l=d3.scale.ordinal(),m=d3.scale.linear(),n=d3.svg.axis().scale(l).orient("bottom"),o=d3.svg.axis().scale(m).orient("left"),p=d3.dispatch("chartClick","elementClick","elementDblClick","tooltipShow","tooltipHide");return q.margin=function(b){return arguments.length?(a=b,q):a},q.width=function(c){return arguments.length?(a.left+a.right+20>c?b=a.left+a.right+20:b=c,q):b},q.height=function(b){return arguments.length?(a.top+a.bottom+20>b?c=a.top+a.bottom+20:c=b,q):c},q.animate=function(a){return arguments.length?(d=a,q):d},q.labelField=function(a){return arguments.length?(e=a,q):e},q.dataField=function(a){return arguments.length?(j=a,q):j},q.id=function(a){return arguments.length?(h=a,q):h},q.rotatedLabel=function(a){return arguments.length?(f=a,q):f},q.showLabels=function(a){return arguments.length?(g=a,q):g},q.title=function(a){return arguments.length?(k=a,q):k},q.xaxis={},d3.rebind(q.xaxis,n,"tickFormat"),q.yaxis={},d3.rebind(q.yaxis,o,"tickFormat"),q.dispatch=p,q},a.models.pie=function(){function p(m){return m.each(function(m){function y(a){var b=(a.startAngle+a.endAngle)*90/Math.PI-90;return b>90?b-180:b}function z(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return t(b(a))}}var n=d3.select(this).on("click",function(a,b){o.chartClick({data:a,index:b,pos:d3.event,id:h})}),p=n.selectAll("svg.margin").data([m]),q=p.enter();q.append("text").attr("class","title").attr("dy",".91em").attr("text-anchor","start").text(l),q.append("svg").attr("class","margin").attr("x",a.left).attr("y",a.top).style("overflow","visible");var r=p.selectAll("g.wrap").data([m]);r.exit().remove();var s=r.enter();s.append("g").attr("class","wrap").attr("id","wrap-"+h).append("g").attr("class","pie"),r.attr("width",b).attr("height",c).attr("transform","translate("+e+","+e+")");var t=d3.svg.arc().outerRadius(e-e/5);k&&t.innerRadius(e/2);var u=d3.layout.pie().value(function(a){return a[g]}),v=p.select(".pie").selectAll(".slice").data(u);v.exit().remove();var w=v.enter().append("svg:g").attr("class","slice").on("mouseover",function(a,b){d3.select(this).classed("hover",!0),o.tooltipShow({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:[d3.event.pageX,d3.event.pageY],id:h})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),o.tooltipHide({label:a.data[f],value:a.data[g],data:a.data,index:b,id:h})}).on("click",function(a,b){o.elementClick({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}).on("dblclick",function(a,b){o.elementDblClick({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}),x=w.append("svg:path").attr("class","path").attr("fill",function(a,b){return i(b)});v.select(".path").attr("d",t).transition().ease("bounce").duration(d).attrTween("d",z),j&&(w.append("text"),v.select("text").transition().duration(d).ease("bounce").attr("transform",function(a){return a.outerRadius=e+10,a.innerRadius=e+15,"translate("+t.centroid(a)+")"}).attr("text-anchor","middle").style("font","bold 12px Arial").text(function(a,b){return a.data[f]}))}),p}var a={top:20,right:20,bottom:20,left:20},b=500,c=500,d=2e3,e=Math.min(b-(a.right+a.left),c-(a.top+a.bottom))/2,f="label",g="y",h=Math.floor(Math.random()*1e4),i=d3.scale.category20(),j=!0,k=!1,l="",m=0,n=0,o=d3.dispatch("chartClick","elementClick","elementDblClick","tooltipShow","tooltipHide");return p.margin=function(b){return arguments.length?(a=b,p):a},p.width=function(d){return arguments.length?(a.left+a.right+20>d?b=a.left+a.right+20:b=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2,p):b},p.height=function(d){return arguments.length?(a.top+a.bottom+20>d?c=a.top+a.bottom+20:c=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2,p):c},p.animate=function(a){return arguments.length?(d=a,p):d},p.labelField=function(a){return arguments.length?(f=a,p):f},p.dataField=function(a){return arguments.length?(g=a,p):g},p.showLabels=function(a){return arguments.length?(j=a,p):j},p.donut=function(a){return arguments.length?(k=a,p):k},p.title=function(a){return arguments.length?(l=a,p):l},p.id=function(a){return arguments.length?(h=a,p):h},p.dispatch=o,p},a.models.line=function(){function s(i){return i.each(function(i){var k=i.map(function(a){return a.values.map(function(a,b){return{x:g(a,b),y:h(a,b)}})}),s=b-a.left-a.right,t=c-a.top-a.bottom;q=q||n,r=r||o,n.domain(l||d3.extent(d3.merge(k),function(a){return a.x})).range([0,s]),o.domain(m||d3.extent(d3.merge(k),function(a){return a.y})).range([t,0]);var u=d3.select(this).selectAll("g.d3line").data([i]),v=u.enter().append("g").attr("class","d3line"),w=v.append("g");w.append("g").attr("class","lines"),w.append("g").attr("class","point-clips").append("clipPath").attr("id","voronoi-clip-path-"+f),w.append("g").attr("class","point-paths");var z=u.select("g").attr("transform","translate("+a.left+","+a.top+")");v.append("defs").append("clipPath").attr("id","chart-clip-path-"+f).append("rect"),u.select("#chart-clip-path-"+f+" rect").attr("width",s).attr("height",t),w.attr("clip-path",j?"url(#chart-clip-path-"+f+")":"");var A=d3.merge(i.map(function(a,b){return a.values.map(function(a,c){return[n(g(a,c))*(Math.random()/1e12+1),o(h(a,c))*(Math.random()/1e12+1),b,c]})})),B=u.select("#voronoi-clip-path-"+f).selectAll("circle").data(A);B.enter().append("circle").attr("r",25),B.exit().remove(),B.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),u.select(".point-paths").attr("clip-path","url(#voronoi-clip-path-"+f+")");var C=d3.geom.voronoi(A).map(function(a,b){return{data:a,series:A[b][2],point:A[b][3]}}),D=u.select(".point-paths").selectAll("path").data(C);D.enter().append("path").attr("class",function(a,b){return"path-"+b}).style("fill-opacity",0),D.exit().remove(),D.attr("d",function(a){return"M"+a.data.join(",")+"Z"}).on("mouseover",function(b){var c=i[b.series],d=c.values[b.point];p.pointMouseover({point:d,series:c,pos:[n(g(d,b.point))+a.left,o(h(d,b.point))+a.top],seriesIndex:b.series,pointIndex:b.point})}).on("mouseout",function(a,b){p.pointMouseout({point:i[a.series].values[a.point],series:i[a.series],seriesIndex:a.series,pointIndex:a.point})}),p.on("pointMouseover.point",function(a){u.select(".series-"+a.seriesIndex+" .point-"+a.pointIndex).classed("hover",!0)}),p.on("pointMouseout.point",function(a){u.select(".series-"+a.seriesIndex+" .point-"+a.pointIndex).classed("hover",!1)});var E=u.select(".lines").selectAll(".line").data(function(a){return a},function(a){return a.key});E.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(E.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),E.attr("class",function(a,b){return"line series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return e[b%10]}).style("stroke",function(a,b){return e[b%10]}),d3.transition(E).style("stroke-opacity",1).style("fill-opacity",.5);var F=E.selectAll("path").data(function(a,b){return[a.values]});F.enter().append("path").attr("d",d3.svg.line().x(function(a,b){return q(g(a,b))}).y(function(a,b){return r(h(a,b))})),d3.transition(E.exit().selectAll("path")).attr("d",d3.svg.line().x(function(a,b){return n(g(a,b))}).y(function(a,b){return o(h(a,b))})).remove(),d3.transition(F).attr("d",d3.svg.line().x(function(a,b){return n(g(a,b))}).y(function(a,b){return o(h(a,b))}));var G=E.selectAll("circle.point").data(function(a){return a.values});G.enter().append("circle").attr("cx",function(a,b){return q(g(a,b))}).attr("cy",function(a,b){return r(h(a,b))}),d3.transition(G.exit()).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).remove(),d3.transition(E.exit().selectAll("circle.point")).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).remove(),G.attr("class",function(a,b){return"point point-"+b}),d3.transition(G).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).attr("r",d),q=n.copy(),r=o.copy()}),s}var a={top:0,right:0,bottom:0,left:0},b=960,c=500,d=function(){return 2.5},e=d3.scale.category10().range(),f=Math.floor(Math.random()*1e4),g=function(a){return a.x},h=function(a){return a.y},i=!0,j=!1,k=!0,l,m,n=d3.scale.linear(),o=d3.scale.linear(),p=d3.dispatch("pointMouseover","pointMouseout"),q,r;return s.dispatch=p,s.x=function(a){return arguments.length?(g=a,s):g},s.y=function(a){return arguments.length?(h=a,s):h},s.margin=function(b){return arguments.length?(a=b,s):a},s.width=function(a){return arguments.length?(b=a,s):b},s.height=function(a){return arguments.length?(c=a,s):c},s.xDomain=function(a){return arguments.length?(l=a,s):l},s.yDomain=function(a){return arguments.length?(m=a,s):m},s.interactive=function(a){return arguments.length?(i=a,s):i},s.clipEdge=function(a){return arguments.length?(j=a,s):j},s.clipVoronoi=function(a){return arguments.length?(k=a,s):k},s.dotRadius=function(a){return arguments.length?(d=d3.functor(a),s):d},s.color=function(a){return arguments.length?(e=a,s):e},s.id=function(a){return arguments.length?(f=a,s):f},s},a.models.lineWithFocus=function(){function z(a){return a.each(function(h){function G(){H(),D.call(v),l.select(".x.axis").call(q),l.select(".y.axis").call(r)}function H(){var a=y.empty()?p.domain():d3.extent(d3.merge(seriesData).filter(function(a){return j(a)>=y.extent()[0]&&j(a)<=y.extent()[1]}),k);typeof a[0]=="undefined"&&(a=p.domain()),m.domain(y.empty()?o.domain():y.extent()),n.domain(a),v.xDomain(m.domain()),v.yDomain(n.domain())}seriesData=h.filter(function(a){return!a.disabled}).map(function(a){return a.values}),o.domain(d3.extent(d3.merge(seriesData),j)).range([0,d-b.left-b.right]),p.domain(d3.extent(d3.merge(seriesData),k)).range([g-c.top-c.bottom,0]),m.domain(y.empty()?o.domain():y.extent()).range([0,d-b.left-b.right]),n.domain(p.domain()).range([f-b.top-b.bottom,0]),y.on("brush",G),v.width(d-b.left-b.right).height(f-b.top-b.bottom).color(h.map(function(a,b){return a.color||i[b%10]}).filter(function(a,b){return!h[b].disabled})),w.width(d-b.left-b.right).height(g-c.top-c.bottom).color(h.map(function(a,b){return a.color||i[b%10]}).filter(function(a,b){return!h[b].disabled})),H();var l=d3.select(this).selectAll("g.wrap").data([h]),A=l.enter().append("g").attr("class","wrap d3lineWithFocus").append("g");A.append("g").attr("class","focus"),A.append("g").attr("class","context"),A.append("g").attr("class","legendWrap");var B=l.select("g");u.width(d/2-b.right),B.select(".legendWrap").datum(h).attr("transform","translate("+(d/2-b.left)+",0)").call(u),b.top=u.height();var C=B.select(".focus").attr("transform","translate("+b.left+","+b.top+")");A.select(".focus").append("g").attr("class","x axis"),A.select(".focus").append("g").attr("class","y axis"),A.select(".focus").append("g").attr("class","focusLines");var D=C.select(".focusLines").datum(h.filter(function(a){return!a.disabled}));d3.transition(D).call(v),q.domain(m.domain()).range(m.range()).ticks(d/100).tickSize(-(f-b.top-b.bottom),0),C.select(".x.axis").attr("transform","translate(0,"+n.range()[0]+")"),d3.transition(B.select(".x.axis")).call(q),r.domain(n.domain()).range(n.range()).ticks(e/36).tickSize(-(d-b.right-b.left),0),d3.transition(B.select(".y.axis")).call(r);var E=B.select(".context").attr("transform","translate("+c.left+","+f+")");A.select(".context").append("g").attr("class","x2 axis"),A.select(".context").append("g").attr("class","y2 axis"),A.select(".context").append("g").attr("class","contextLines"),A.select(".context").append("g").attr("class","x brush").attr("class","x brush").call(y).selectAll("rect").attr("y",-5).attr("height",g+4);var F=E.select(".contextLines").datum(h.filter(function(a){return!a.disabled}));d3.transition(F).call(w),s.domain(o.domain()).range(o.range()).ticks(d/100).tickSize(-(g-c.top-c.bottom),0),E.select(".x2.axis").attr("transform","translate(0,"+p.range()[0]+")"),d3.transition(E.select(".x2.axis")).call(s),t.domain(p.domain()).range(p.range()).ticks((g-c.top-c.bottom)/24).tickSize(-(d-c.right-c.left),0),E.select(".y2.axis"),d3.transition(E.select(".y2.axis")).call(t),u.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,h.filter(function(a){return!a.disabled}).length||h.map(function(a){return a.disabled=!1,l.selectAll(".series").classed("disabled",!1),a}),a.transition().call(z)}),v.dispatch.on("pointMouseover.tooltip",function(a){x.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),v.dispatch.on("pointMouseout.tooltip",function(a){x.tooltipHide(a)})}),z}var b={top:30,right:20,bottom:30,left:60},c={top:0,right:20,bottom:20,left:60},d=960,e=500,f=400,g=100,h=function(){return 2.5},i=d3.scale.category10().range(),j=function(a){return a.x},k=function(a){return a.y},l=Math.floor(Math.random()*1e4),m=d3.scale.linear(),n=d3.scale.linear(),o=d3.scale.linear(),p=d3.scale.linear(),q=a.models.axis().scale(m).orient("bottom"),r=a.models.axis().scale(n).orient("left"),s=a.models.axis().scale(o).orient("bottom"),t=a.models.axis().scale(p).orient("left"),u=a.models.legend().height(30),v=a.models.line().clipEdge(!0),w=a.models.line().dotRadius(.1).interactive(!1),x=d3.dispatch("tooltipShow","tooltipHide"),y=d3.svg.brush().x(o);return z.dispatch=x,z.x=function(a){return arguments.length?(j=a,v.x(a),w.x(a),z):j},z.y=function(a){return arguments.length?(k=a,v.y(a),w.y(a),z):k},z.margin=function(a){return arguments.length?(b=a,z):b},z.width=function(a){return arguments.length?(d=a,z):d},z.height=function(a){return arguments.length?(e=a,f=a-g,z):e},z.contextHeight=function(a){return arguments.length?(g=a,f=e-a,z):g},z.dotRadius=function(a){return arguments.length?(h=d3.functor(a),v.dotRadius=a,z):h},z.id=function(a){return arguments.length?(l=a,z):l},z.xTickFormat=function(a){return arguments.length?(q.tickFormat(a),s.tickFormat(a),z):m.tickFormat()},z.yTickFormat=function(a){return arguments.length?(r.tickFormat(a),t.tickFormat(a),z):n.tickFormat()},z.xAxis=q,z.yAxis=r,z},a.models.lineWithLegend=function(){function p(a){return a.each(function(e){var q=c(),r=d(),s=q-b.left-b.right,t=r-b.top-b.bottom,u=e.filter(function(a){return!a.disabled}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})});j.domain(d3.extent(d3.merge(u),function(a){return a.x})).range([0,s]),k.domain(d3.extent(d3.merge(u),function(a){return a.y})).range([t,0]),o.width(s).height(t).color(e.map(function(a,b){return a.color||h[b%10]}).filter(function(a,b){return!e[b].disabled}));var v=d3.select(this).selectAll("g.wrap").data([e]),w=v.enter().append("g").attr("class","wrap d3lineWithLegend").append("g");w.append("g").attr("class","x axis"),w.append("g").attr("class","y axis"),w.append("g").attr("class","linesWrap"),w.append("g").attr("class","legendWrap"),n.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,e.filter(function(a){return!a.disabled}).length||e.map(function(a){return a.disabled=!1,v.selectAll(".series").classed("disabled",!1),a}),a.transition().call(p)}),o.dispatch.on("pointMouseover.tooltip",function(a){i.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),o.dispatch.on("pointMouseout.tooltip",function(a){i.tooltipHide(a)}),b.top=n.height();var z=v.select("g").attr("transform","translate("+b.left+","+b.top+")");n.width(q/2-b.right),z.select(".legendWrap").datum(e).attr("transform","translate("+(q/2-b.left)+","+ -b.top+")").call(n);var A=z.select(".linesWrap").datum(e.filter(function(a){return!a.disabled}));d3.transition(A).call(o),l.domain(j.domain()).range(j.range()).ticks(q/100).tickSize(-t,0),z.select(".x.axis").attr("transform","translate(0,"+k.range()[0]+")"),d3.transition(z.select(".x.axis")).call(l),m.domain(k.domain()).range(k.range()).ticks(r/36).tickSize(-s,0),d3.transition(z.select(".y.axis")).call(m)}),p}var b={top:30,right:20,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=function(){return 2.5},f=function(a){return a.x},g=function(a){return a.y},h=d3.scale.category10().range(),i=d3.dispatch("tooltipShow","tooltipHide"),j=d3.scale.linear(),k=d3.scale.linear(),l=a.models.axis().scale(j).orient("bottom"),m=a.models.axis().scale(k).orient("left"),n=a.models.legend().height(30),o=a.models.line();return p.dispatch=i,p.legend=n,p.xAxis=l,p.yAxis=m,d3.rebind(p,o,"interactive"),p.x=function(a){return arguments.length?(f=a,o.x(a),p):f},p.y=function(a){return arguments.length?(g=a,o.y(a),p):g},p.margin=function(a){return arguments.length?(b=a,p):b},p.width=function(a){return arguments.length?(c=d3.functor(a),p):c},p.height=function(a){return arguments.length?(d=d3.functor(a),p):d},p.dotRadius=function(a){return arguments.length?(e=d3.functor(a),o.dotRadius=a,p):e},p},a.models.cumulativeLine=function(){function t(a,b){}function u(a,b){a.x+=d3.event.dx,a.i=Math.round(k.invert(a.x)),d3.select(this).attr("transform","translate("+k(a.i)+",0)")}function v(a,b){d3.transition(d3.select(".chart-"+i)).call(w)}function w(a){return a.each(function(f){var g=c(),h=d(),t=g-b.left-b.right,u=h-b.top-b.bottom,v=x(r.i,f),z=v.filter(function(a){return!a.disabled}).map(function(a){return a.values});j.domain(d3.extent(d3.merge(z),function(a){return a.x})).range([0,g-b.left-b.right]),k.domain([0,f[0].values.length-1]).range([0,g-b.left-b.right]).clamp(!0),l.domain(d3.extent(d3.merge(z),function(a){return a.y})).range([h-b.top-b.bottom,0]),p.width(g-b.left-b.right).height(h-b.top-b.bottom).color(f.map(function(a,b){return a.color||e[b%10]}).filter(function(a,b){return!f[b].disabled}));var A=d3.select(this).classed("chart-"+i,!0).selectAll("g.wrap").data([v]),B=A.enter().append("g").attr("class","wrap d3cumulativeLine").append("g");B.append("g").attr("class","x axis"),B.append("g").attr("class","y axis"),B.append("g").attr("class","linesWrap"),B.append("g").attr("class","legendWrap"),b.top=o.height();var C=A.select("g").attr("transform","translate("+b.left+","+b.top+")");o.width(g/2-b.right),C.select(".legendWrap").datum(f).attr("transform","translate("+(g/2-b.left)+","+ -b.top+")").call(o);var D=C.select(".linesWrap").datum(v.filter(function(a){return!a.disabled}));d3.transition(D).call(p);var E=D.selectAll(".indexLine").data([r]);E.enter().append("rect").attr("class","indexLine").attr("width",3).attr("x",-2).attr("fill","red").attr("fill-opacity",.5).call(s),E.attr("transform",function(a){return"translate("+k(a.i)+",0)"}).attr("height",h-b.top-b.bottom),m.domain(j.domain()).range(j.range()).ticks(g/100).tickSize(-(h-b.top-b.bottom),0),C.select(".x.axis").attr("transform","translate(0,"+l.range()[0]+")"),d3.transition(C.select(".x.axis")).call(m),n.domain(l.domain()).range(l.range()).ticks(h/36).tickSize(-(g-b.right-b.left),0),d3.transition(C.select(".y.axis")).call(n),o.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,f.filter(function(a){return!a.disabled}).length||f.map(function(a){return a.disabled=!1,A.selectAll(".series").classed("disabled",!1),a}),a.transition().call(w)}),p.dispatch.on("pointMouseover.tooltip",function(a){q.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),p.dispatch.on("pointMouseout.tooltip",function(a){q.tooltipHide(a)})}),w}function x(a,b){return b.map(function(b,c){var d=h(b.values[a],a);return{key:b.key,values:b.values.map(function(a,b){return{x:g(a,b),y:(h(a,b)-d)/(1+d)}}),disabled:b.disabled,hover:b.hover}})}var b={top:30,right:20,bottom:30,left:60},c=function(){return 960},d=function(){return 500},e=d3.scale.category10().range(),f=function(){return 2.5},g=function(a){return a.x},h=function(a){return a.y},i=Math.floor(Math.random()*1e4),j=d3.scale.linear(),k=d3.scale.linear(),l=d3.scale.linear(),m=a.models.axis().scale(j).orient("bottom"),n=a.models.axis().scale(l).orient("left"),o=a.models.legend().height(30),p=a.models.line(),q=d3.dispatch("tooltipShow","tooltipHide"),r={i:0,x:0},s=d3.behavior.drag().on("dragstart",t).on("drag",u).on("dragend",v);return w.dispatch=q,w.x=function(a){return arguments.length?(g=a,w):g},w.y=function(a){return arguments.length?(h=a,w):h},w.margin=function(a){return arguments.length?(b=a,w):b},w.width=function(a){return arguments.length?(c=d3.functor(a),w):c},w.height=function(a){return arguments.length?(d=d3.functor(a),w):d},w.dotRadius=function(a){return arguments.length?(f=d3.functor(a),p.dotRadius=a,w):f},w.xAxis=m,w.yAxis=n,w},a.models.scatter=function(){function r(s){return s.each(function(r){var s=r.map(function(a){return a.values}),t=b-a.left-a.right,u=c-a.top-a.bottom;n=n||f,o=o||g,p=p||h,r=r.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a}),f.domain(d3.extent(d3.merge(s).map(i).concat(l))).range([0,t]),g.domain(d3.extent(d3.merge(s).map(j).concat(m))).range([u,0]),h.domain(d3.extent(d3.merge(s),k)).range([2,10]);var v=d3.merge(r.map(function(a,b){return a.values.map(function(a,c){return[f(i(a))*(Math.random()/1e12+1),g(j(a))*(Math.random()/1e12+1),b,c]})})),w=d3.select(this).selectAll("g.d3scatter").data([r]),A=w.enter().append("g").attr("class","d3scatter").append("g");A.append("g").attr("class","groups"),A.append("g").attr("class","point-clips").append("clipPath").attr("id","voronoi-clip-path-"+e),A.append("g").attr("class","point-paths"),A.append("g").attr("class","distribution");var B=w.select("g").attr("transform","translate("+a.left+","+a.top+")"),C=w.select("#voronoi-clip-path-"+e).selectAll("circle").data(v);C.enter().append("circle").attr("r",25),C.exit().remove(),C.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),w.select(".point-paths").attr("clip-path","url(#voronoi-clip-path-"+e+")");var D=d3.geom.voronoi(v).map(function(a,b){return{data:a,series:v[b][2],point:v[b][3]}}),E=w.select(".point-paths").selectAll("path").data(D);E.enter().append("path").attr("class",function(a,b){return"path-"+b}),E.exit().remove(),E.attr("d",function(a){return"M"+a.data.join(",")+"Z"}).on("mouseover",function(b){q.pointMouseover({point:r[b.series].values[b.point],series:r[b.series],pos:[f(i(r[b.series].values[b.point]))+a.left,g(j(r[b.series].values[b.point]))+a.top],seriesIndex:b.series,pointIndex:b.point})}).on("mouseout",function(a,b){q.pointMouseout({point:r[a.series].values[a.point],series:r[a.series],seriesIndex:a.series,pointIndex:a.point})});var F=w.select(".groups").selectAll(".group").data(function(a){return a},function(a){return a.key});F.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(F.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),F.attr("class",function(a,b){return"group series-"+b}).classed("hover",function(a){return a.hover&&!a.disabled}),d3.transition(F).style("fill",function(a,b){return d[b%10]}).style("stroke",function(a,b){return d[b%10]}).style("stroke-opacity",1).style("fill-opacity",.5);var G=F.selectAll("circle.point").data(function(a){return a.values});G.enter().append("circle").attr("cx",function(a){return n(i(a))}).attr("cy",function(a){return o(j(a))}).attr("r",function(a){return p(k(a))}),d3.transition(F.exit().selectAll("circle.point")).attr("cx",function(a){return f(i(a))}).attr("cy",function(a){return g(j(a))}).attr("r",function(a){return h(k(a))}).remove(),G.attr("class",function(a,b){return"point point-"+b}),d3.transition(G).attr("cx",function(a){return f(i(a))}).attr("cy",function(a){return g(j(a))}).attr("r",function(a){return h(k(a))});var H=F.selectAll("line.distX").data(function(a){return a.values});H.enter().append("line").attr("x1",function(a){return n(i(a))}).attr("x2",function(a){return n(i(a))}),d3.transition(F.exit().selectAll("line.distX")).attr("x1",function(a){return f(i(a))}).attr("x2",function(a){return f(i(a))}).remove(),H.attr("class",function(a,b){return"distX distX-"+b}).attr("y1",g.range()[0]).attr("y2",g.range()[0]+8),d3.transition(H).attr("x1",function(a){return f(i(a))}).attr("x2",function(a){return f(i(a))});var I=F.selectAll("line.distY").data(function(a){return a.values});I.enter().append("line").attr("y1",function(a){return o(j(a))}).attr("y2",function(a){return o(j(a))}),d3 -.transition(F.exit().selectAll("line.distY")).attr("y1",function(a){return g(j(a))}).attr("y2",function(a){return g(j(a))}).remove(),I.attr("class",function(a,b){return"distY distY-"+b}).attr("x1",f.range()[0]).attr("x2",f.range()[0]-8),d3.transition(I).attr("y1",function(a){return g(j(a))}).attr("y2",function(a){return g(j(a))}),q.on("pointMouseover.point",function(b){w.select(".series-"+b.seriesIndex+" .point-"+b.pointIndex).classed("hover",!0),w.select(".series-"+b.seriesIndex+" .distX-"+b.pointIndex).attr("y1",b.pos[1]-a.top),w.select(".series-"+b.seriesIndex+" .distY-"+b.pointIndex).attr("x1",b.pos[0]-a.left)}),q.on("pointMouseout.point",function(a){w.select(".series-"+a.seriesIndex+" circle.point-"+a.pointIndex).classed("hover",!1),w.select(".series-"+a.seriesIndex+" .distX-"+a.pointIndex).attr("y1",g.range()[0]),w.select(".series-"+a.seriesIndex+" .distY-"+a.pointIndex).attr("x1",f.range()[0])}),n=f.copy(),o=g.copy(),p=h.copy()}),r}var a={top:0,right:0,bottom:0,left:0},b=960,c=500,d=d3.scale.category10().range(),e=Math.floor(Math.random()*1e5),f=d3.scale.linear(),g=d3.scale.linear(),h=d3.scale.sqrt(),i=function(a){return a.x},j=function(a){return a.y},k=function(a){return a.size},l=[],m=[],n,o,p,q=d3.dispatch("pointMouseover","pointMouseout");return r.dispatch=q,r.margin=function(b){return arguments.length?(a=b,r):a},r.width=function(a){return arguments.length?(b=a,r):b},r.height=function(a){return arguments.length?(c=a,r):c},r.x=function(a){return arguments.length?(i=d3.functor(a),r):i},r.y=function(a){return arguments.length?(j=d3.functor(a),r):j},r.size=function(a){return arguments.length?(k=d3.functor(a),r):k},r.forceX=function(a){return arguments.length?(l=a,r):l},r.forceY=function(a){return arguments.length?(m=a,r):m},r.color=function(a){return arguments.length?(d=a,r):d},r.id=function(a){return arguments.length?(e=a,r):e},r},a.models.scatterWithLegend=function(){function w(a){return a.each(function(f){var g=f.filter(function(a){return!a.disabled}).map(function(a){return a.values});q.domain(d3.extent(d3.merge(g).map(k).concat(n))).range([0,c-b.left-b.right]),r.domain(d3.extent(d3.merge(g).map(l).concat(o))).range([d-b.top-b.bottom,0]),v.width(c-b.left-b.right).height(d-b.top-b.bottom).color(f.map(function(a,b){return a.color||j[b%20]}).filter(function(a,b){return!f[b].disabled})),s.ticks(c/100).tickSize(-(d-b.top-b.bottom),0),t.ticks(d/36).tickSize(-(c-b.right-b.left),0);var h=d3.select(this).selectAll("g.wrap").data([f]),i=h.enter().append("g").attr("class","wrap d3scatterWithLegend").append("g");i.append("g").attr("class","legendWrap"),i.append("g").attr("class","x axis"),i.append("g").attr("class","y axis"),i.append("g").attr("class","scatterWrap"),u.dispatch.on("legendClick",function(b,c,d){b.disabled=!b.disabled,f.filter(function(a){return!a.disabled}).length||f.map(function(a){return a.disabled=!1,h.selectAll(".series").classed("disabled",!1),a}),a.transition(e).call(w)}),v.dispatch.on("pointMouseover.tooltip",function(a){p.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),v.dispatch.on("pointMouseout.tooltip",function(a){p.tooltipHide(a)}),u.width(c/2-b.right),h.select(".legendWrap").datum(f).attr("transform","translate("+(c/2-b.left)+","+ -u.height()+")").call(u),b.top=u.height();var m=h.select("g").attr("transform","translate("+b.left+","+b.top+")"),z=h.select(".scatterWrap").datum(f.filter(function(a){return!a.disabled}));d3.transition(z).call(v),s.domain(q.domain()).range(q.range()).ticks(c/100).tickSize(-(d-b.top-b.bottom),0),m.select(".x.axis").attr("transform","translate(0,"+r.range()[0]+")"),d3.transition(m.select(".x.axis")).call(s),t.domain(r.domain()).range(r.range()).ticks(d/36).tickSize(-(c-b.right-b.left),0),d3.transition(m.select(".y.axis")).call(t)}),w}var b={top:30,right:20,bottom:50,left:60},c=960,d=500,e=500,f=!0,g=!0,h=!1,i=!1,j=d3.scale.category10().range(),k=function(a){return a.x},l=function(a){return a.y},m=function(a){return a.size},n=[],o=[],p=d3.dispatch("tooltipShow","tooltipHide"),q=d3.scale.linear(),r=d3.scale.linear(),s=a.models.axis().scale(q).orient("bottom").tickPadding(10),t=a.models.axis().scale(r).orient("left").tickPadding(10),u=a.models.legend().height(30),v=a.models.scatter();return w.dispatch=p,w.margin=function(a){return arguments.length?(b=a,w):b},w.width=function(a){return arguments.length?(c=a,w):c},w.height=function(a){return arguments.length?(d=a,w):d},w.forceX=function(a){return arguments.length?(n=a,v.forceX(a),w):n},w.forceY=function(a){return arguments.length?(o=a,v.forceY(a),w):o},w.animate=function(a){return arguments.length?(e=a,w):e},w.xAxis=s,w.yAxis=t,w},a.models.sparkline=function(){function h(d){return d.each(function(d){f.domain(d3.extent(d,function(a){return a.x})).range([0,b-a.left-a.right]),g.domain(d3.extent(d,function(a){return a.y})).range([c-a.top-a.bottom,0]);var h=d3.select(this).selectAll("svg").data([d]),i=h.enter().append("svg").append("g");i.append("g").attr("class","sparkline").attr("transform","translate("+a.left+","+a.top+")").style("stroke",function(a,b){return a.color||e[b*2%20]}),h.attr("width",b).attr("height",c);var j=i.select(".sparkline").selectAll("path").data(function(a){return[a]});j.enter().append("path"),j.exit().remove(),j.attr("d",d3.svg.line().x(function(a){return f(a.x)}).y(function(a){return g(a.y)}));var k=i.select(".sparkline").selectAll("circle.point").data(function(a){return a.filter(function(a){return g.domain().indexOf(a.y)!=-1})});k.enter().append("circle").attr("class","point"),k.exit().remove(),k.attr("cx",function(a){return f(a.x)}).attr("cy",function(a){return g(a.y)}).attr("r",2).style("stroke",function(a,b){return a.y==g.domain()[0]?"#d62728":"#2ca02c"}).style("fill",function(a,b){return a.y==g.domain()[0]?"#d62728":"#2ca02c"})}),h}var a={top:3,right:3,bottom:3,left:3},b=200,c=20,d=!0,e=d3.scale.category20().range(),f=d3.scale.linear(),g=d3.scale.linear();return h.margin=function(b){return arguments.length?(a=b,h):a},h.width=function(a){return arguments.length?(b=a,h):b},h.height=function(a){return arguments.length?(c=a,h):c},h.animate=function(a){return arguments.length?(d=a,h):d},h},a.models.stackedArea=function(){function q(a){return a.each(function(a){var h=JSON.parse(JSON.stringify(a)),m=h.map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})}),q=c-b.left-b.right,r=d-b.top-b.bottom;h=d3.layout.stack().offset(i).order(j).values(function(a){return a.values}).y(g)(h),o.domain(k||d3.extent(d3.merge(m),function(a){return a.x})).range([0,q]),p.domain(l||[0,d3.max(h,function(a){return d3.max(a.values,function(a){return a.y0+a.y})})]).range([r,0]),n.width(q).height(r).xDomain(o.domain()).yDomain(p.domain()).x(f).y(function(a){return a.y+a.y0}).color(a.map(function(a,b){return a.color||e[b%10]}).filter(function(b,c){return!a[c].disabled}));var s=d3.select(this).selectAll("g.d3stackedarea").data([h]),t=s.enter().append("g").attr("class","d3stackedarea").append("g");t.append("g").attr("class","areaWrap"),t.append("g").attr("class","linesWrap");var u=s.select("g").attr("transform","translate("+b.left+","+b.top+")"),v=u.select(".linesWrap").datum(h.filter(function(a){return!a.disabled}));d3.transition(v).call(n);var w=d3.svg.area().x(function(a,b){return o(f(a,b))}).y0(function(a){return p(a.y0)}).y1(function(a){return p(a.y+a.y0)}),z=d3.svg.area().x(function(a,b){return o(f(a,b))}).y0(function(a){return p(a.y0)}).y1(function(a){return p(a.y0)}),A=u.select(".areaWrap").selectAll("path.area").data(function(a){return a});A.enter().append("path").attr("class","area"),d3.transition(A.exit()).attr("d",function(a,b){return z(a.values,b)}).remove(),A.style("fill",function(a,b){return e[b%10]}).style("stroke",function(a,b){return e[b%10]}),d3.transition(A).attr("d",function(a,b){return w(a.values,b)})}),q}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=d3.scale.category10().range(),f=function(a){return a.x},g=function(a){return a.y},h="stack",i="zero",j="default",k,l,m=d3.dispatch("tooltipShow","tooltipHide"),n=a.models.line(),o=d3.scale.linear(),p=d3.scale.linear();return q.x=function(a){return arguments.length?(f=d3.functor(a),q):f},q.y=function(a){return arguments.length?(g=d3.functor(a),q):g},q.margin=function(a){return arguments.length?(b=a,q):b},q.width=function(a){return arguments.length?(c=a,q):c},q.height=function(a){return arguments.length?(d=a,q):d},q.color=function(a){return arguments.length?(e=a,q):e},q.offset=function(a){return arguments.length?(i=a,q):i},q.order=function(a){return arguments.length?(j=a,q):j},q.style=function(a){if(!arguments.length)return h;h=a;switch(h){case"stack":i="zero",j="default";break;case"stream":i="wiggle",j="inside-out";break;case"expand":i="expand",j="default"}return q},q.dispatch=m,n.dispatch.on("pointMouseover.tooltip",function(a){m.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),n.dispatch.on("pointMouseout.tooltip",function(a){m.tooltipHide(a)}),q},a.models.stackedAreaWithLegend=function(){function r(a){return a.each(function(e){var f=c(),s=d(),t=f-b.left-b.right,u=s-b.top-b.bottom,v=e.filter(function(a){return!a.disabled}).reduce(function(a,b,c){return b.values.forEach(function(b,d){c||(a[d]={x:j(b.x,d),y:0}),a[d].y+=k(b)}),a},[]);h.domain(d3.extent(d3.merge(v),function(a){return a.x})).range([0,t]),i.domain(p.offset()=="zero"?[0,d3.max(v,function(a){return a.y})]:[0,1]).range([u,0]),p.width(t).height(u);var w=d3.select(this).selectAll("g.wrap").data([e]),z=w.enter().append("g").attr("class","wrap d3stackedWithLegend").append("g");z.append("g").attr("class","x axis"),z.append("g").attr("class","y axis"),z.append("g").attr("class","stackedWrap"),z.append("g").attr("class","legendWrap"),z.append("g").attr("class","controlsWrap"),n.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,b.disabled?b.values.map(function(a){return a._y=a.y,a.y=0,a}):b.values.map(function(a){return a.y=a._y,a}),e.filter(function(a){return!a.disabled}).length||e.map(function(a){return a.disabled=!1,a.values.map(function(a){return a.y=a._y,a}),a}),a.transition().call(r)}),o.dispatch.on("legendClick",function(b,c){if(!b.disabled)return;q=q.map(function(a){return a.disabled=!0,a}),b.disabled=!1;switch(b.key){case"Stacked":p.style("stack");break;case"Stream":p.style("stream");break;case"Expanded":p.style("expand")}a.transition().call(r)}),p.dispatch.on("tooltipShow",function(a){if(!Math.round(k(a.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;g.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),p.dispatch.on("tooltipHide",function(a){g.tooltipHide(a)}),b.top=n.height();var A=w.select("g").attr("transform","translate("+b.left+","+b.top+")");n.width(f/2-b.right),A.select(".legendWrap").datum(e).attr("transform","translate("+(f/2-b.left)+","+ -b.top+")").call(n),o.width(280).color(["#444","#444","#444"]),A.select(".controlsWrap").datum(q).attr("transform","translate(0,"+ -b.top+")").call(o);var B=A.select(".stackedWrap").datum(e);d3.transition(B).call(p),l.domain(h.domain()).range(h.range()).ticks(f/100).tickSize(-u,0),A.select(".x.axis").attr("transform","translate(0,"+u+")"),d3.transition(A.select(".x.axis")).call(l),m.domain(i.domain()).range(i.range()).ticks(p.offset()=="wiggle"?0:s/36).tickSize(-t,0).tickFormat(p.offset()=="zero"?d3.format(",.2f"):d3.format("%")),d3.transition(A.select(".y.axis")).call(m)}),r}var b={top:30,right:20,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=function(){return 2.5},f=d3.scale.category10().range(),g=d3.dispatch("tooltipShow","tooltipHide"),h=d3.scale.linear(),i=d3.scale.linear(),j=function(a){return a.x},k=function(a){return a.y},l=a.models.axis().scale(h).orient("bottom"),m=a.models.axis().scale(i).orient("left"),n=a.models.legend().height(30),o=a.models.legend().height(30),p=a.models.stackedArea(),q=[{key:"Stacked"},{key:"Stream",disabled:!0},{key:"Expanded",disabled:!0}];return r.dispatch=g,r.x=function(a){return arguments.length?(j=d3.functor(a),p.x(j),r):j},r.y=function(a){return arguments.length?(k=d3.functor(a),p.y(k),r):k},r.margin=function(a){return arguments.length?(b=a,r):b},r.width=function(a){return arguments.length?(c=d3.functor(a),r):c},r.height=function(a){return arguments.length?(d=d3.functor(a),r):d},r.dotRadius=function(a){return arguments.length?(e=d3.functor(a),p.dotRadius=a,r):e},r.stacked=p,r.xAxis=l,r.yAxis=m,r},a.charts.line=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.lineWithLegend(),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c.point)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(d3.format(",r")),f.yAxis.tickFormat(d3.format(",.2f")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h},a.charts.lineChartDaily=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.lineWithLegend().x(function(a,b){return b}),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointIndex)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(function(a){return d3.time.format("%x")(new Date(c[0].values[a].x))}),f.yAxis.tickFormat(d3.format(",.2%")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h},a.charts.cumulativeLineChartDaily=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.cumulativeLine().x(function(a,b){return b}),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointIndex)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(function(a){return d3.time.format("%x")(new Date(c[0].values[a].x))}),f.yAxis.tickFormat(d3.format(",.2%")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h}})(); \ No newline at end of file +(function(){function b(a,b){var c=[31,28,31,30,31,30,31,31,30,31,30,31];return a!=2?c[a-1]:b%4!=0?c[1]:b%100==0&&b%400!=0?c[1]:c[1]+1}function c(a,b,c){return function(d,e,f){var g=a(d),h=[];g1)while(gl+k&&(o=l-h-5);break;case"w":n=b[0]+e,o=b[1]-h/2,n+i>j&&(n=b[0]-i-e),ol+k&&(o=l-h-5);break;case"n":n=b[0]-i/2,o=b[1]+e,nj&&(n=j-i-5),o+h>l+k&&(o=b[1]-h-e);break;case"s":n=b[0]-i/2,o=b[1]-h-e,nj&&(n=j-i-5),l>o&&(o=b[1]+20)}return f.style.left=n+"px",f.style.top=o+"px",f.style.opacity=1,f},b.cleanup=function(){var a=document.getElementsByClassName("nvtooltip"),b=[];while(a.length)b.push(a[0]),a[0].style.transitionDelay="0 !important",a[0].style.opacity=0,a[0].className="nvtooltip-pending-removal";setTimeout(function(){while(b.length){var a=b.pop();a.parentNode.removeChild(a)}},500)}}(),a.utils.windowSize=function(){var a={width:640,height:480};return document.body&&document.body.offsetWidth&&(a.width=document.body.offsetWidth,a.height=document.body.offsetHeight),document.compatMode=="CSS1Compat"&&document.documentElement&&document.documentElement.offsetWidth&&(a.width=document.documentElement.offsetWidth,a.height=document.documentElement.offsetHeight),window.innerWidth&&window.innerHeight&&(a.width=window.innerWidth,a.height=window.innerHeight),a},a.models.axis=function(){function g(h){return h.each(function(g){e.domain(a).range(b),f.orient(c);var h=d3.select(this).selectAll("text.axislabel").data([d||null]);switch(c){case"top":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0),h.attr("x",b[1]/2);break;case"right":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(90)").attr("y",-40),h.attr("x",-b[0]/2);break;case"bottom":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",25),h.attr("x",b[1]/2);break;case"left":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(-90)").attr("y",-40),h.attr("x",-b[0]/2)}h.exit().remove(),h.text(function(a){return a}),d3.transition(d3.select(this)).call(f),d3.select(this).selectAll("line.tick").filter(function(a){return!parseFloat(Math.round(a*1e5)/1e6)}).classed("zero",!0)}),g}var a=[0,1],b=[0,1],c="bottom",d=!1,e=d3.scale.linear(),f=d3.svg.axis().scale(e);return g.orient=function(a){return arguments.length?(c=a,g):c},g.domain=function(b){return arguments.length?(a=b,g):a},g.range=function(a){return arguments.length?(b=a,g):b},g.scale=function(a){return arguments.length?(e=a,f.scale(e),g):e},g.axisLabel=function(a){return arguments.length?(d=a,g):d},d3.rebind(g,f,"ticks","tickSubdivide","tickSize","tickPadding","tickFormat"),g},a.models.bar=function(){function q(r){return r.each(function(q){l.domain(q.map(function(a,b){return a[e]})).rangeRoundBands([0,b-a.left-a.right],.1);var r=d3.min(q,function(a){return a[j]}),s=d3.max(q,function(a){return a[j]}),t=Math.max(-r,s),u=-t;r>=0&&(u=0),m.domain([u,t]).range([c-a.top-a.bottom,0]).nice(),n.ticks(b/100),o.ticks(c/36).tickSize(-(b-a.right-a.left),0);var v=d3.select(this).on("click",function(a,b){p.chartClick({data:a,index:b,pos:d3.event,id:h})}),w=v.selectAll("g.wrap").data([q]),z=w.enter();z.append("text").attr("class","title").attr("dy",".91em").attr("text-anchor","start").text(k),z=z.append("g").attr("class","wrap").attr("id","wrap-"+h).append("g"),z.append("g").attr("class","x axis"),z.append("g").attr("class","y axis"),z.append("g").attr("class","bars"),w.attr("width",b).attr("height",c);var A=w.select("g").attr("transform","translate("+a.left+","+a.top+")"),B=w.select(".bars").selectAll(".bar").data(function(a){return a});B.exit().remove();var C=B.enter().append("svg:rect").attr("class",function(a){return a[j]<0?"bar negative":"bar positive"}).attr("fill",function(a,b){return i(b)}).attr("x",0).on("mouseover",function(a,b){d3.select(this).classed("hover",!0),p.tooltipShow({label:a[e],value:a[j],data:a,index:b,pos:[d3.event.pageX,d3.event.pageY],id:h})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),p.tooltipHide({label:a[e],value:a[j],data:a,index:b,id:h})}).on("click",function(a,b){p.elementClick({label:a[e],value:a[j],data:a,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}).on("dblclick",function(a,b){p.elementDblClick({label:a[e],value:a[j],data:a,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()});B.attr("class",function(a){return a[j]<0?"bar negative":"bar positive"}).attr("transform",function(a,b){return"translate("+l(a[e])+",0)"}).attr("width",l.rangeBand).order().transition().duration(d).attr("y",function(a){return m(Math.max(0,a[j]))}).attr("height",function(a){return Math.abs(m(a[j])-m(0))}),A.select(".x.axis").attr("transform","translate(0,"+m.range()[0]+")").call(n),f&&A.select(".x.axis").selectAll("text").attr("text-anchor","start").attr("transform",function(a){return"rotate(35)translate("+this.getBBox().height/2+","+"0"+")"}),g||(A.select(".x.axis").selectAll("text").attr("fill","rgba(0,0,0,0)"),A.select(".x.axis").selectAll("line").attr("style","opacity: 0")),A.select(".y.axis").call(o)}),q}var a={top:20,right:10,bottom:80,left:60},b=960,c=500,d=500,e="label",f=!0,g=!0,h=Math.floor(Math.random()*1e4),i=d3.scale.category20(),j="y",k="",l=d3.scale.ordinal(),m=d3.scale.linear(),n=d3.svg.axis().scale(l).orient("bottom"),o=d3.svg.axis().scale(m).orient("left"),p=d3.dispatch("chartClick","elementClick","elementDblClick","tooltipShow","tooltipHide");return q.margin=function(b){return arguments.length?(a=b,q):a},q.width=function(c){return arguments.length?(a.left+a.right+20>c?b=a.left+a.right+20:b=c,q):b},q.height=function(b){return arguments.length?(a.top+a.bottom+20>b?c=a.top+a.bottom+20:c=b,q):c},q.animate=function(a){return arguments.length?(d=a,q):d},q.labelField=function(a){return arguments.length?(e=a,q):e},q.dataField=function(a){return arguments.length?(j=a,q):j},q.id=function(a){return arguments.length?(h=a,q):h},q.rotatedLabel=function(a){return arguments.length?(f=a,q):f},q.showLabels=function(a){return arguments.length?(g=a,q):g},q.title=function(a){return arguments.length?(k=a,q):k},q.xaxis={},d3.rebind(q.xaxis,n,"tickFormat"),q.yaxis={},d3.rebind(q.yaxis,o,"tickFormat"),q.dispatch=p,q},a.models.cumulativeLine=function(){function t(a,b){}function u(a,b){a.x+=d3.event.dx,a.i=Math.round(k.invert(a.x)),d3.select(this).attr("transform","translate("+k(a.i)+",0)")}function v(a,b){d3.transition(d3.select(".chart-"+i)).call(w)}function w(a){return a.each(function(f){var g=c(),h=d(),t=g-b.left-b.right,u=h-b.top-b.bottom,v=x(r.i,f),z=v.filter(function(a){return!a.disabled}).map(function(a){return a.values});j.domain(d3.extent(d3.merge(z),function(a){return a.x})).range([0,g-b.left-b.right]),k.domain([0,f[0].values.length-1]).range([0,g-b.left-b.right]).clamp(!0),l.domain(d3.extent(d3.merge(z),function(a){return a.y})).range([h-b.top-b.bottom,0]),p.width(g-b.left-b.right).height(h-b.top-b.bottom).color(f.map(function(a,b){return a.color||e[b%10]}).filter(function(a,b){return!f[b].disabled}));var A=d3.select(this).classed("chart-"+i,!0).selectAll("g.wrap").data([v]),B=A.enter().append("g").attr("class","wrap d3cumulativeLine").append("g");B.append("g").attr("class","x axis"),B.append("g").attr("class","y axis"),B.append("g").attr("class","linesWrap"),B.append("g").attr("class","legendWrap"),b.top=o.height();var C=A.select("g").attr("transform","translate("+b.left+","+b.top+")");o.width(g/2-b.right),C.select(".legendWrap").datum(f).attr("transform","translate("+(g/2-b.left)+","+ -b.top+")").call(o);var D=C.select(".linesWrap").datum(v.filter(function(a){return!a.disabled}));d3.transition(D).call(p);var E=D.selectAll(".indexLine").data([r]);E.enter().append("rect").attr("class","indexLine").attr("width",3).attr("x",-2).attr("fill","red").attr("fill-opacity",.5).call(s),E.attr("transform",function(a){return"translate("+k(a.i)+",0)"}).attr("height",h-b.top-b.bottom),m.domain(j.domain()).range(j.range()).ticks(g/100).tickSize(-(h-b.top-b.bottom),0),C.select(".x.axis").attr("transform","translate(0,"+l.range()[0]+")"),d3.transition(C.select(".x.axis")).call(m),n.domain(l.domain()).range(l.range()).ticks(h/36).tickSize(-(g-b.right-b.left),0),d3.transition(C.select(".y.axis")).call(n),o.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,f.filter(function(a){return!a.disabled}).length||f.map(function(a){return a.disabled=!1,A.selectAll(".series").classed("disabled",!1),a}),a.transition().call(w)}),p.dispatch.on("pointMouseover.tooltip",function(a){q.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),p.dispatch.on("pointMouseout.tooltip",function(a){q.tooltipHide(a)})}),w}function x(a,b){return b.map(function(b,c){var d=h(b.values[a],a);return{key:b.key,values:b.values.map(function(a,b){return{x:g(a,b),y:(h(a,b)-d)/(1+d)}}),disabled:b.disabled,hover:b.hover}})}var b={top:30,right:20,bottom:30,left:60},c=function(){return 960},d=function(){return 500},e=d3.scale.category10().range(),f=function(){return 2.5},g=function(a){return a.x},h=function(a){return a.y},i=Math.floor(Math.random()*1e4),j=d3.scale.linear(),k=d3.scale.linear(),l=d3.scale.linear(),m=a.models.axis().scale(j).orient("bottom"),n=a.models.axis().scale(l).orient("left"),o=a.models.legend().height(30),p=a.models.line(),q=d3.dispatch("tooltipShow","tooltipHide"),r={i:0,x:0},s=d3.behavior.drag().on("dragstart",t).on("drag",u).on("dragend",v);return w.dispatch=q,w.x=function(a){return arguments.length?(g=a,w):g},w.y=function(a){return arguments.length?(h=a,w):h},w.margin=function(a){return arguments.length?(b=a,w):b},w.width=function(a){return arguments.length?(c=d3.functor(a),w):c},w.height=function(a){return arguments.length?(d=d3.functor(a),w):d},w.dotRadius=function(a){return arguments.length?(f=d3.functor(a),p.dotRadius=a,w):f},w.xAxis=m,w.yAxis=n,w},a.models.legend=function(){function f(g){return g.each(function(f){var g=d3.select(this).selectAll("g.legend").data([f]),h=g.enter().append("g").attr("class","legend").append("g"),i=g.select("g").attr("transform","translate("+a.left+","+a.top+")"),j=i.selectAll(".series").data(function(a){return a}),k=j.enter().append("g").attr("class","series").on("mouseover",function(a,b){e.legendMouseover(a,b)}).on("mouseout",function(a,b){e.legendMouseout(a,b)}).on("click",function(a,b){e.legendClick(a,b)});k.append("circle").style("fill",function(a,b){return a.color||d[b%20]}).style("stroke",function(a,b){return a.color||d[b%20]}).style("stroke-width",2).attr("r",5),k.append("text").text(function(a){return a.key}).attr("text-anchor","start").attr("dy",".32em").attr("dx","8"),j.classed("disabled",function(a){return a.disabled}),j.exit().remove();var l=5,m=5,n=0,o;j.attr("transform",function(c,d){var e=d3.select(this).select("text").node().getComputedTextLength()+28;return o=m,bn&&(n=m),"translate("+o+","+l+")"}),i.attr("transform","translate("+(b-a.right-n)+","+a.top+")"),c=a.top+a.bottom+l+15}),f}var a={top:5,right:0,bottom:5,left:10},b=400,c=20,d=d3.scale.category10().range(),e=d3.dispatch("legendClick","legendMouseover","legendMouseout");return f.dispatch=e,f.margin=function(b){return arguments.length?(a=b,f):a},f.width=function(a){return arguments.length?(b=a,f):b},f.height=function(a){return arguments.length?(c=a,f):c},f.color=function(a){return arguments.length?(d=a,f):d},f},a.models.line=function(){function s(i){return i.each(function(i){var k=i.map(function(a){return a.values.map(function(a,b){return{x:g(a,b),y:h(a,b)}})}),s=b-a.left-a.right,t=c-a.top-a.bottom;q=q||n,r=r||o,n.domain(l||d3.extent(d3.merge(k),function(a){return a.x})).range([0,s]),o.domain(m||d3.extent(d3.merge(k),function(a){return a.y})).range([t,0]);var u=d3.select(this).selectAll("g.d3line").data([i]),v=u.enter().append("g").attr("class","d3line"),w=v.append("g");w.append("g").attr("class","lines"),w.append("g").attr("class","point-clips").append("clipPath").attr("id","voronoi-clip-path-"+f),w.append("g").attr("class","point-paths");var z=u.select("g").attr("transform","translate("+a.left+","+a.top+")");v.append("defs").append("clipPath").attr("id","chart-clip-path-"+f).append("rect"),u.select("#chart-clip-path-"+f+" rect").attr("width",s).attr("height",t),w.attr("clip-path",j?"url(#chart-clip-path-"+f+")":"");var A=d3.merge(i.map(function(a,b){return a.values.map(function(a,c){return[n(g(a,c))*(Math.random()/1e12+1),o(h(a,c))*(Math.random()/1e12+1),b,c]})})),B=u.select("#voronoi-clip-path-"+f).selectAll("circle").data(A);B.enter().append("circle").attr("r",25),B.exit().remove(),B.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),u.select(".point-paths").attr("clip-path","url(#voronoi-clip-path-"+f+")");var C=d3.geom.voronoi(A).map(function(a,b){return{data:a,series:A[b][2],point:A[b][3]}}),D=u.select(".point-paths").selectAll("path").data(C);D.enter().append("path").attr("class",function(a,b){return"path-"+b}).style("fill-opacity",0),D.exit().remove(),D.attr("d",function(a){return"M"+a.data.join(",")+"Z"}).on("mouseover",function(b){var c=i[b.series],d=c.values[b.point];p.pointMouseover({point:d,series:c,pos:[n(g(d,b.point))+a.left,o(h(d,b.point))+a.top],seriesIndex:b.series,pointIndex:b.point})}).on("mouseout",function(a,b){p.pointMouseout({point:i[a.series].values[a.point],series:i[a.series],seriesIndex:a.series,pointIndex:a.point})}),p.on("pointMouseover.point",function(a){u.select(".series-"+a.seriesIndex+" .point-"+a.pointIndex).classed("hover",!0)}),p.on("pointMouseout.point",function(a){u.select(".series-"+a.seriesIndex+" .point-"+a.pointIndex).classed("hover",!1)});var E=u.select(".lines").selectAll(".line").data(function(a){return a},function(a){return a.key});E.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(E.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),E.attr("class",function(a,b){return"line series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return e[b%10]}).style("stroke",function(a,b){return e[b%10]}),d3.transition(E).style("stroke-opacity",1).style("fill-opacity",.5);var F=E.selectAll("path").data(function(a,b){return[a.values]});F.enter().append("path").attr("d",d3.svg.line().x(function(a,b){return q(g(a,b))}).y(function(a,b){return r(h(a,b))})),d3.transition(E.exit().selectAll("path")).attr("d",d3.svg.line().x(function(a,b){return n(g(a,b))}).y(function(a,b){return o(h(a,b))})).remove(),d3.transition(F).attr("d",d3.svg.line().x(function(a,b){return n(g(a,b))}).y(function(a,b){return o(h(a,b))}));var G=E.selectAll("circle.point").data(function(a){return a.values});G.enter().append("circle").attr("cx",function(a,b){return q(g(a,b))}).attr("cy",function(a,b){return r(h(a,b))}),d3.transition(G.exit()).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).remove(),d3.transition(E.exit().selectAll("circle.point")).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).remove(),G.attr("class",function(a,b){return"point point-"+b}),d3.transition(G).attr("cx",function(a,b){return n(g(a,b))}).attr("cy",function(a,b){return o(h(a,b))}).attr("r",d),q=n.copy(),r=o.copy()}),s}var a={top:0,right:0,bottom:0,left:0},b=960,c=500,d=function(){return 2.5},e=d3.scale.category10().range(),f=Math.floor(Math.random()*1e4),g=function(a){return a.x},h=function(a){return a.y},i=!0,j=!1,k=!0,l,m,n=d3.scale.linear(),o=d3.scale.linear(),p=d3.dispatch("pointMouseover","pointMouseout"),q,r;return s.dispatch=p,s.x=function(a){return arguments.length?(g=a,s):g},s.y=function(a){return arguments.length?(h=a,s):h},s.margin=function(b){return arguments.length?(a=b,s):a},s.width=function(a){return arguments.length?(b=a,s):b},s.height=function(a){return arguments.length?(c=a,s):c},s.xDomain=function(a){return arguments.length?(l=a,s):l},s.yDomain=function(a){return arguments.length?(m=a,s):m},s.interactive=function(a){return arguments.length?(i=a,s):i},s.clipEdge=function(a){return arguments.length?(j=a,s):j},s.clipVoronoi=function(a){return arguments.length?(k=a,s):k},s.dotRadius=function(a){return arguments.length?(d=d3.functor(a),s):d},s.color=function(a){return arguments.length?(e=a,s):e},s.id=function(a){return arguments.length?(f=a,s):f},s},a.models.linePlusBar=function(){function s(a){return a.each(function(e){var t=c(),u=d(),v=t-b.left-b.right,w=u-b.top-b.bottom,y=e.filter(function(a){return!a.disabled&&!a.bar}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})}),z=e.filter(function(a){return!a.disabled&&a.bar}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})});j.domain(d3.extent(d3.merge(y.concat(z)),function(a){return a.x})).range([0,v]),k.domain(d3.extent(d3.merge(y),function(a){return a.y})).range([w,0]),l.domain(d3.extent(d3.merge(z),function(a){return a.y})).range([w,0]),q.width(v).height(w).color(e.map(function(a,b){return a.color||h[b%10]}).filter(function(a,b){return!e[b].disabled&&!e[b].bar})),r.width(v).height(w).color(e.map(function(a,b){return a.color||h[b%10]}).filter(function(a,b){return!e[b].disabled&&e[b].bar}));var A=d3.select(this).selectAll("g.wrap").data([e]),B=A.enter().append("g").attr("class","wrap d3linePlusBar").append("g");B.append("g").attr("class","x axis"),B.append("g").attr("class","y1 axis"),B.append("g").attr("class","y2 axis"),B.append("g").attr("class","barsWrap"),B.append("g").attr("class","linesWrap"),B.append("g").attr("class","legendWrap"),p.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,e.filter(function(a){return!a.disabled}).length||e.map(function(a){return a.disabled=!1,A.selectAll(".series").classed("disabled",!1),a}),a.transition().call(s)}),q.dispatch.on("pointMouseover.tooltip",function(a){i.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),q.dispatch.on("pointMouseout.tooltip",function(a){i.tooltipHide(a)}),r.dispatch.on("elementMouseover.tooltip",function(a){i.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),r.dispatch.on("elementMouseout.tooltip",function(a){i.tooltipHide(a)}),b.top=p.height();var C=A.select("g").attr("transform","translate("+b.left+","+b.top+")");p.width(t/2-b.right),C.select(".legendWrap").datum(e).attr("transform","translate("+(t/2-b.left)+","+ -b.top+")").call(p);var D=e.filter(function(a){return!a.disabled&&a.bar}),E=C.select(".barsWrap").datum(D.length?D:[{values:[]}]),F=C.select(".linesWrap").datum(e.filter(function(a){return!a.disabled&&!a.bar}));d3.transition(E).call(r),d3.transition(F).call(q),m.domain(j.domain()).range(j.range()).ticks(t/100).tickSize(-w,0),C.select(".x.axis").attr("transform","translate(0,"+k.range()[0]+")"),d3.transition(C.select(".x.axis")).call(m),n.domain(k.domain()).range(k.range()).ticks(u/36).tickSize(-v,0),d3.transition(C.select(".y1.axis")).call(n),o.domain(l.domain()).range(l.range()).ticks(u/36).tickSize(y.length?0:-v,0),C.select(".y2.axis").attr("transform","translate("+j.range()[1]+",0)"),d3.transition(C.select(".y2.axis")).call(o)}),s}var b={top:30,right:60,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=function(){return 2.5},f=function(a){return a.x},g=function(a){return a.y},h=d3.scale.category10().range(),i=d3.dispatch("tooltipShow","tooltipHide"),j=d3.scale.linear(),k=d3.scale.linear(),l=d3.scale.linear(),m=a.models.axis().scale(j).orient("bottom"),n=a.models.axis().scale(k).orient("left"),o=a.models.axis().scale(l).orient("right"),p=a.models.legend().height(30),q=a.models.line(),r=a.models.historicalBar();return s.dispatch=i,s.legend=p,s.lines=q,s.bars=r,s.xAxis=m,s.yAxis1=n,s.yAxis2=o,s.x=function(a){return arguments.length?(f=a,q.x(a),s):f},s.y=function(a){return arguments.length?(g=a,q.y(a),s):g},s.margin=function(a){return arguments.length?(b=a,s):b},s.width=function(a){return arguments.length?(c=d3.functor(a),s):c},s.height=function(a){return arguments.length?(d=d3.functor(a),s):d},s.dotRadius=function(a){return arguments.length?(e=d3.functor(a),q.dotRadius=a,s):e},s},a.models.lineWithFocus=function(){function z(a){return a.each(function(h){function G(){H(),D.call(v),l.select(".x.axis").call(q),l.select(".y.axis").call(r)}function H(){var a=y.empty()?p.domain():d3.extent(d3.merge(seriesData).filter(function(a){return j(a)>=y.extent()[0]&&j(a)<=y.extent()[1]}),k);typeof a[0]=="undefined"&&(a=p.domain()),m.domain(y.empty()?o.domain():y.extent()),n.domain(a),v.xDomain(m.domain()),v.yDomain(n.domain())}seriesData=h.filter(function(a){return!a.disabled}).map(function(a){return a.values}),o.domain(d3.extent(d3.merge(seriesData),j)).range([0,d-b.left-b.right]),p.domain(d3.extent(d3.merge(seriesData),k)).range([g-c.top-c.bottom,0]),m.domain(y.empty()?o.domain():y.extent()).range([0,d-b.left-b.right]),n.domain(p.domain()).range([f-b.top-b.bottom,0]),y.on("brush",G),v.width(d-b.left-b.right).height(f-b.top-b.bottom).color(h.map(function(a,b){return a.color||i[b%10]}).filter(function(a,b){return!h[b].disabled})),w.width(d-b.left-b.right).height(g-c.top-c.bottom).color(h.map(function(a,b){return a.color||i[b%10]}).filter(function(a,b){return!h[b].disabled})),H();var l=d3.select(this).selectAll("g.wrap").data([h]),A=l.enter().append("g").attr("class","wrap d3lineWithFocus").append("g");A.append("g").attr("class","focus"),A.append("g").attr("class","context"),A.append("g").attr("class","legendWrap");var B=l.select("g");u.width(d/2-b.right),B.select(".legendWrap").datum(h).attr("transform","translate("+(d/2-b.left)+",0)").call(u),b.top=u.height();var C=B.select(".focus").attr("transform","translate("+b.left+","+b.top+")");A.select(".focus").append("g").attr("class","x axis"),A.select(".focus").append("g").attr("class","y axis"),A.select(".focus").append("g").attr("class","focusLines");var D=C.select(".focusLines").datum(h.filter(function(a){return!a.disabled}));d3.transition(D).call(v),q.domain(m.domain()).range(m.range()).ticks(d/100).tickSize(-(f-b.top-b.bottom),0),C.select(".x.axis").attr("transform","translate(0,"+n.range()[0]+")"),d3.transition(B.select(".x.axis")).call(q),r.domain(n.domain()).range(n.range()).ticks(e/36).tickSize(-(d-b.right-b.left),0),d3.transition(B.select(".y.axis")).call(r);var E=B.select(".context").attr("transform","translate("+c.left+","+f+")");A.select(".context").append("g").attr("class","x2 axis"),A.select(".context").append("g").attr("class","y2 axis"),A.select(".context").append("g").attr("class","contextLines"),A.select(".context").append("g").attr("class","x brush").attr("class","x brush").call(y).selectAll("rect").attr("y",-5).attr("height",g+4);var F=E.select(".contextLines").datum(h.filter(function(a){return!a.disabled}));d3.transition(F).call(w),s.domain(o.domain()).range(o.range()).ticks(d/100).tickSize(-(g-c.top-c.bottom),0),E.select(".x2.axis").attr("transform","translate(0,"+p.range()[0]+")"),d3.transition(E.select(".x2.axis")).call(s),t.domain(p.domain()).range(p.range()).ticks((g-c.top-c.bottom)/24).tickSize(-(d-c.right-c.left),0),E.select(".y2.axis"),d3.transition(E.select(".y2.axis")).call(t),u.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,h.filter(function(a){return!a.disabled}).length||h.map(function(a){return a.disabled=!1,l.selectAll(".series").classed("disabled",!1),a}),a.transition().call(z)}),v.dispatch.on("pointMouseover.tooltip",function(a){x.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),v.dispatch.on("pointMouseout.tooltip",function(a){x.tooltipHide(a)})}),z}var b={top:30,right:20,bottom:30,left:60},c={top:0,right:20,bottom:20,left:60},d=960,e=500,f=400,g=100,h=function(){return 2.5},i=d3.scale.category10().range(),j=function(a){return a.x},k=function(a){return a.y},l=Math.floor(Math.random()*1e4),m=d3.scale.linear(),n=d3.scale.linear(),o=d3.scale.linear(),p=d3.scale.linear(),q=a.models.axis().scale(m).orient("bottom"),r=a.models.axis().scale(n).orient("left"),s=a.models.axis().scale(o).orient("bottom"),t=a.models.axis().scale(p).orient("left"),u=a.models.legend().height(30),v=a.models.line().clipEdge(!0),w=a.models.line().dotRadius(.1).interactive(!1),x=d3.dispatch("tooltipShow","tooltipHide"),y=d3.svg.brush().x(o);return z.dispatch=x,z.x=function(a){return arguments.length?(j=a,v.x(a),w.x(a),z):j},z.y=function(a){return arguments.length?(k=a,v.y(a),w.y(a),z):k},z.margin=function(a){return arguments.length?(b=a,z):b},z.width=function(a){return arguments.length?(d=a,z):d},z.height=function(a){return arguments.length?(e=a,f=a-g,z):e},z.contextHeight=function(a){return arguments.length?(g=a,f=e-a,z):g},z.dotRadius=function(a){return arguments.length?(h=d3.functor(a),v.dotRadius=a,z):h},z.id=function(a){return arguments.length?(l=a,z):l},z.xTickFormat=function(a){return arguments.length?(q.tickFormat(a),s.tickFormat(a),z):m.tickFormat()},z.yTickFormat=function(a){return arguments.length?(r.tickFormat(a),t.tickFormat(a),z):n.tickFormat()},z.xAxis=q,z.yAxis=r,z},a.models.lineWithLegend=function(){function p(a){return a.each(function(e){var q=c(),r=d(),s=q-b.left-b.right,t=r-b.top-b.bottom,u=e.filter(function(a){return!a.disabled}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})});j.domain(d3.extent(d3.merge(u),function(a){return a.x})).range([0,s]),k.domain(d3.extent(d3.merge(u),function(a){return a.y})).range([t,0]),o.width(s).height(t).color(e.map(function(a,b){return a.color||h[b%10]}).filter(function(a,b){return!e[b].disabled}));var v=d3.select(this).selectAll("g.wrap").data([e]),w=v.enter().append("g").attr("class","wrap d3lineWithLegend").append("g");w.append("g").attr("class","x axis"),w.append("g").attr("class","y axis"),w.append("g").attr("class","linesWrap"),w.append("g").attr("class","legendWrap"),n.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,e.filter(function(a){return!a.disabled}).length||e.map(function(a){return a.disabled=!1,v.selectAll(".series").classed("disabled",!1),a}),a.transition().call(p)}),o.dispatch.on("pointMouseover.tooltip",function(a){i.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),o.dispatch.on("pointMouseout.tooltip",function(a){i.tooltipHide(a)}),b.top=n.height();var z=v.select("g").attr("transform","translate("+b.left+","+b.top+")");n.width(q/2-b.right),z.select(".legendWrap").datum(e).attr("transform","translate("+(q/2-b.left)+","+ -b.top+")").call(n);var A=z.select(".linesWrap").datum(e.filter(function(a){return!a.disabled}));d3.transition(A).call(o),l.domain(j.domain()).range(j.range()).ticks(q/100).tickSize(-t,0),z.select(".x.axis").attr("transform","translate(0,"+k.range()[0]+")"),d3.transition(z.select(".x.axis")).call(l),m.domain(k.domain()).range(k.range()).ticks(r/36).tickSize(-s,0),d3.transition(z.select(".y.axis")).call(m)}),p}var b={top:30,right:20,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=function(){return 2.5},f=function(a){return a.x},g=function(a){return a.y},h=d3.scale.category10().range(),i=d3.dispatch("tooltipShow","tooltipHide"),j=d3.scale.linear(),k=d3.scale.linear(),l=a.models.axis().scale(j).orient("bottom"),m=a.models.axis().scale(k).orient("left"),n=a.models.legend().height(30),o=a.models.line();return p.dispatch=i,p.legend=n,p.xAxis=l,p.yAxis=m,d3.rebind(p,o,"interactive"),p.x=function(a){return arguments.length?(f=a,o.x(a),p):f},p.y=function(a){return arguments.length?(g=a,o.y(a),p):g},p.margin=function(a){return arguments.length?(b=a,p):b},p.width=function(a){return arguments.length?(c=d3.functor(a),p):c},p.height=function(a){return arguments.length?(d=d3.functor(a),p):d},p.dotRadius=function(a){return arguments.length?(e=d3.functor(a),o.dotRadius=a,p):e},p},a.models.pie=function(){function p(m){return m.each(function(m){function y(a){var b=(a.startAngle+a.endAngle)*90/Math.PI-90;return b>90?b-180:b}function z(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return t(b(a))}}var n=d3.select(this).on("click",function(a,b){o.chartClick({data:a,index:b,pos:d3.event,id:h})}),p=n.selectAll("svg.margin").data([m]),q=p.enter();q.append("text").attr("class","title").attr("dy",".91em").attr("text-anchor","start").text(l),q.append("svg").attr("class","margin").attr("x",a.left).attr("y",a.top).style("overflow","visible");var r=p.selectAll("g.wrap").data([m]);r.exit().remove();var s=r.enter();s.append("g").attr("class","wrap").attr("id","wrap-"+h).append("g").attr("class","pie"),r.attr("width",b).attr("height",c).attr("transform","translate("+e+","+e+")");var t=d3.svg.arc().outerRadius(e-e/5);k&&t.innerRadius(e/2);var u=d3.layout.pie().value(function(a){return a[g]}),v=p.select(".pie").selectAll(".slice").data(u);v.exit().remove();var w=v.enter().append("svg:g").attr("class","slice").on("mouseover",function(a,b){d3.select(this).classed("hover",!0),o.tooltipShow({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:[d3.event.pageX,d3.event.pageY],id:h})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),o.tooltipHide({label:a.data[f],value:a.data[g],data:a.data,index:b,id:h})}).on("click",function(a,b){o.elementClick({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}).on("dblclick",function(a,b){o.elementDblClick({label:a.data[f],value:a.data[g],data:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}),x=w.append("svg:path").attr("class","path").attr("fill",function(a,b){return i(b)});v.select(".path").attr("d",t).transition().ease("bounce").duration(d).attrTween("d",z),j&&(w.append("text"),v.select("text").transition().duration(d).ease("bounce").attr("transform",function(a){return a.outerRadius=e+10,a.innerRadius=e+15,"translate("+t.centroid(a)+")"}).attr("text-anchor","middle").style("font","bold 12px Arial").text(function(a,b){return a.data[f]}))}),p}var a={top:20,right:20,bottom:20,left:20},b=500,c=500,d=2e3,e=Math.min(b-(a.right+a.left),c-(a.top+a.bottom))/2,f="label",g="y",h=Math.floor(Math.random()*1e4),i=d3.scale.category20(),j=!0,k=!1,l="",m=0,n=0,o=d3.dispatch("chartClick","elementClick","elementDblClick","tooltipShow","tooltipHide");return p.margin=function(b){return arguments.length?(a=b,p):a},p.width=function(d){return arguments.length?(a.left+a.right+20>d?b=a.left+a.right+20:b=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2,p):b},p.height=function(d){return arguments.length?(a.top+a.bottom+20>d?c=a.top+a.bottom+20:c=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2,p):c},p.animate=function(a){return arguments.length?(d=a,p):d},p.labelField=function(a){return arguments.length?(f=a,p):f},p.dataField=function(a){return arguments.length?(g=a,p):g},p.showLabels=function(a){return arguments.length?(j=a, +p):j},p.donut=function(a){return arguments.length?(k=a,p):k},p.title=function(a){return arguments.length?(l=a,p):l},p.id=function(a){return arguments.length?(h=a,p):h},p.dispatch=o,p},a.models.scatter=function(){function r(s){return s.each(function(r){var s=r.map(function(a){return a.values}),t=b-a.left-a.right,u=c-a.top-a.bottom;n=n||f,o=o||g,p=p||h,r=r.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a}),f.domain(d3.extent(d3.merge(s).map(i).concat(l))).range([0,t]),g.domain(d3.extent(d3.merge(s).map(j).concat(m))).range([u,0]),h.domain(d3.extent(d3.merge(s),k)).range([2,10]);var v=d3.merge(r.map(function(a,b){return a.values.map(function(a,c){return[f(i(a))*(Math.random()/1e12+1),g(j(a))*(Math.random()/1e12+1),b,c]})})),w=d3.select(this).selectAll("g.d3scatter").data([r]),A=w.enter().append("g").attr("class","d3scatter").append("g");A.append("g").attr("class","groups"),A.append("g").attr("class","point-clips").append("clipPath").attr("id","voronoi-clip-path-"+e),A.append("g").attr("class","point-paths"),A.append("g").attr("class","distribution");var B=w.select("g").attr("transform","translate("+a.left+","+a.top+")"),C=w.select("#voronoi-clip-path-"+e).selectAll("circle").data(v);C.enter().append("circle").attr("r",25),C.exit().remove(),C.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),w.select(".point-paths").attr("clip-path","url(#voronoi-clip-path-"+e+")");var D=d3.geom.voronoi(v).map(function(a,b){return{data:a,series:v[b][2],point:v[b][3]}}),E=w.select(".point-paths").selectAll("path").data(D);E.enter().append("path").attr("class",function(a,b){return"path-"+b}),E.exit().remove(),E.attr("d",function(a){return"M"+a.data.join(",")+"Z"}).on("mouseover",function(b){q.pointMouseover({point:r[b.series].values[b.point],series:r[b.series],pos:[f(i(r[b.series].values[b.point]))+a.left,g(j(r[b.series].values[b.point]))+a.top],seriesIndex:b.series,pointIndex:b.point})}).on("mouseout",function(a,b){q.pointMouseout({point:r[a.series].values[a.point],series:r[a.series],seriesIndex:a.series,pointIndex:a.point})});var F=w.select(".groups").selectAll(".group").data(function(a){return a},function(a){return a.key});F.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(F.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),F.attr("class",function(a,b){return"group series-"+b}).classed("hover",function(a){return a.hover&&!a.disabled}),d3.transition(F).style("fill",function(a,b){return d[b%10]}).style("stroke",function(a,b){return d[b%10]}).style("stroke-opacity",1).style("fill-opacity",.5);var G=F.selectAll("circle.point").data(function(a){return a.values});G.enter().append("circle").attr("cx",function(a){return n(i(a))}).attr("cy",function(a){return o(j(a))}).attr("r",function(a){return p(k(a))}),d3.transition(F.exit().selectAll("circle.point")).attr("cx",function(a){return f(i(a))}).attr("cy",function(a){return g(j(a))}).attr("r",function(a){return h(k(a))}).remove(),G.attr("class",function(a,b){return"point point-"+b}),d3.transition(G).attr("cx",function(a){return f(i(a))}).attr("cy",function(a){return g(j(a))}).attr("r",function(a){return h(k(a))});var H=F.selectAll("line.distX").data(function(a){return a.values});H.enter().append("line").attr("x1",function(a){return n(i(a))}).attr("x2",function(a){return n(i(a))}),d3.transition(F.exit().selectAll("line.distX")).attr("x1",function(a){return f(i(a))}).attr("x2",function(a){return f(i(a))}).remove(),H.attr("class",function(a,b){return"distX distX-"+b}).attr("y1",g.range()[0]).attr("y2",g.range()[0]+8),d3.transition(H).attr("x1",function(a){return f(i(a))}).attr("x2",function(a){return f(i(a))});var I=F.selectAll("line.distY").data(function(a){return a.values});I.enter().append("line").attr("y1",function(a){return o(j(a))}).attr("y2",function(a){return o(j(a))}),d3.transition(F.exit().selectAll("line.distY")).attr("y1",function(a){return g(j(a))}).attr("y2",function(a){return g(j(a))}).remove(),I.attr("class",function(a,b){return"distY distY-"+b}).attr("x1",f.range()[0]).attr("x2",f.range()[0]-8),d3.transition(I).attr("y1",function(a){return g(j(a))}).attr("y2",function(a){return g(j(a))}),q.on("pointMouseover.point",function(b){w.select(".series-"+b.seriesIndex+" .point-"+b.pointIndex).classed("hover",!0),w.select(".series-"+b.seriesIndex+" .distX-"+b.pointIndex).attr("y1",b.pos[1]-a.top),w.select(".series-"+b.seriesIndex+" .distY-"+b.pointIndex).attr("x1",b.pos[0]-a.left)}),q.on("pointMouseout.point",function(a){w.select(".series-"+a.seriesIndex+" circle.point-"+a.pointIndex).classed("hover",!1),w.select(".series-"+a.seriesIndex+" .distX-"+a.pointIndex).attr("y1",g.range()[0]),w.select(".series-"+a.seriesIndex+" .distY-"+a.pointIndex).attr("x1",f.range()[0])}),n=f.copy(),o=g.copy(),p=h.copy()}),r}var a={top:0,right:0,bottom:0,left:0},b=960,c=500,d=d3.scale.category10().range(),e=Math.floor(Math.random()*1e5),f=d3.scale.linear(),g=d3.scale.linear(),h=d3.scale.sqrt(),i=function(a){return a.x},j=function(a){return a.y},k=function(a){return a.size},l=[],m=[],n,o,p,q=d3.dispatch("pointMouseover","pointMouseout");return r.dispatch=q,r.margin=function(b){return arguments.length?(a=b,r):a},r.width=function(a){return arguments.length?(b=a,r):b},r.height=function(a){return arguments.length?(c=a,r):c},r.x=function(a){return arguments.length?(i=d3.functor(a),r):i},r.y=function(a){return arguments.length?(j=d3.functor(a),r):j},r.size=function(a){return arguments.length?(k=d3.functor(a),r):k},r.forceX=function(a){return arguments.length?(l=a,r):l},r.forceY=function(a){return arguments.length?(m=a,r):m},r.color=function(a){return arguments.length?(d=a,r):d},r.id=function(a){return arguments.length?(e=a,r):e},r},a.models.scatterWithLegend=function(){function w(a){return a.each(function(f){var g=f.filter(function(a){return!a.disabled}).map(function(a){return a.values});q.domain(d3.extent(d3.merge(g).map(k).concat(n))).range([0,c-b.left-b.right]),r.domain(d3.extent(d3.merge(g).map(l).concat(o))).range([d-b.top-b.bottom,0]),v.width(c-b.left-b.right).height(d-b.top-b.bottom).color(f.map(function(a,b){return a.color||j[b%20]}).filter(function(a,b){return!f[b].disabled})),s.ticks(c/100).tickSize(-(d-b.top-b.bottom),0),t.ticks(d/36).tickSize(-(c-b.right-b.left),0);var h=d3.select(this).selectAll("g.wrap").data([f]),i=h.enter().append("g").attr("class","wrap d3scatterWithLegend").append("g");i.append("g").attr("class","legendWrap"),i.append("g").attr("class","x axis"),i.append("g").attr("class","y axis"),i.append("g").attr("class","scatterWrap"),u.dispatch.on("legendClick",function(b,c,d){b.disabled=!b.disabled,f.filter(function(a){return!a.disabled}).length||f.map(function(a){return a.disabled=!1,h.selectAll(".series").classed("disabled",!1),a}),a.transition(e).call(w)}),v.dispatch.on("pointMouseover.tooltip",function(a){p.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),v.dispatch.on("pointMouseout.tooltip",function(a){p.tooltipHide(a)}),u.width(c/2-b.right),h.select(".legendWrap").datum(f).attr("transform","translate("+(c/2-b.left)+","+ -u.height()+")").call(u),b.top=u.height();var m=h.select("g").attr("transform","translate("+b.left+","+b.top+")"),z=h.select(".scatterWrap").datum(f.filter(function(a){return!a.disabled}));d3.transition(z).call(v),s.domain(q.domain()).range(q.range()).ticks(c/100).tickSize(-(d-b.top-b.bottom),0),m.select(".x.axis").attr("transform","translate(0,"+r.range()[0]+")"),d3.transition(m.select(".x.axis")).call(s),t.domain(r.domain()).range(r.range()).ticks(d/36).tickSize(-(c-b.right-b.left),0),d3.transition(m.select(".y.axis")).call(t)}),w}var b={top:30,right:20,bottom:50,left:60},c=960,d=500,e=500,f=!0,g=!0,h=!1,i=!1,j=d3.scale.category10().range(),k=function(a){return a.x},l=function(a){return a.y},m=function(a){return a.size},n=[],o=[],p=d3.dispatch("tooltipShow","tooltipHide"),q=d3.scale.linear(),r=d3.scale.linear(),s=a.models.axis().scale(q).orient("bottom").tickPadding(10),t=a.models.axis().scale(r).orient("left").tickPadding(10),u=a.models.legend().height(30),v=a.models.scatter();return w.dispatch=p,w.margin=function(a){return arguments.length?(b=a,w):b},w.width=function(a){return arguments.length?(c=a,w):c},w.height=function(a){return arguments.length?(d=a,w):d},w.forceX=function(a){return arguments.length?(n=a,v.forceX(a),w):n},w.forceY=function(a){return arguments.length?(o=a,v.forceY(a),w):o},w.animate=function(a){return arguments.length?(e=a,w):e},w.xAxis=s,w.yAxis=t,w},a.models.sparkline=function(){function h(d){return d.each(function(d){f.domain(d3.extent(d,function(a){return a.x})).range([0,b-a.left-a.right]),g.domain(d3.extent(d,function(a){return a.y})).range([c-a.top-a.bottom,0]);var h=d3.select(this).selectAll("svg").data([d]),i=h.enter().append("svg").append("g");i.append("g").attr("class","sparkline").attr("transform","translate("+a.left+","+a.top+")").style("stroke",function(a,b){return a.color||e[b*2%20]}),h.attr("width",b).attr("height",c);var j=i.select(".sparkline").selectAll("path").data(function(a){return[a]});j.enter().append("path"),j.exit().remove(),j.attr("d",d3.svg.line().x(function(a){return f(a.x)}).y(function(a){return g(a.y)}));var k=i.select(".sparkline").selectAll("circle.point").data(function(a){return a.filter(function(a){return g.domain().indexOf(a.y)!=-1})});k.enter().append("circle").attr("class","point"),k.exit().remove(),k.attr("cx",function(a){return f(a.x)}).attr("cy",function(a){return g(a.y)}).attr("r",2).style("stroke",function(a,b){return a.y==g.domain()[0]?"#d62728":"#2ca02c"}).style("fill",function(a,b){return a.y==g.domain()[0]?"#d62728":"#2ca02c"})}),h}var a={top:3,right:3,bottom:3,left:3},b=200,c=20,d=!0,e=d3.scale.category20().range(),f=d3.scale.linear(),g=d3.scale.linear();return h.margin=function(b){return arguments.length?(a=b,h):a},h.width=function(a){return arguments.length?(b=a,h):b},h.height=function(a){return arguments.length?(c=a,h):c},h.animate=function(a){return arguments.length?(d=a,h):d},h},a.models.stackedArea=function(){function q(a){return a.each(function(a){var h=JSON.parse(JSON.stringify(a)),m=h.map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})}),q=c-b.left-b.right,r=d-b.top-b.bottom;h=d3.layout.stack().offset(i).order(j).values(function(a){return a.values}).y(g)(h),o.domain(k||d3.extent(d3.merge(m),function(a){return a.x})).range([0,q]),p.domain(l||[0,d3.max(h,function(a){return d3.max(a.values,function(a){return a.y0+a.y})})]).range([r,0]),n.width(q).height(r).xDomain(o.domain()).yDomain(p.domain()).x(f).y(function(a){return a.y+a.y0}).color(a.map(function(a,b){return a.color||e[b%10]}).filter(function(b,c){return!a[c].disabled}));var s=d3.select(this).selectAll("g.d3stackedarea").data([h]),t=s.enter().append("g").attr("class","d3stackedarea").append("g");t.append("g").attr("class","areaWrap"),t.append("g").attr("class","linesWrap");var u=s.select("g").attr("transform","translate("+b.left+","+b.top+")"),v=u.select(".linesWrap").datum(h.filter(function(a){return!a.disabled}));d3.transition(v).call(n);var w=d3.svg.area().x(function(a,b){return o(f(a,b))}).y0(function(a){return p(a.y0)}).y1(function(a){return p(a.y+a.y0)}),z=d3.svg.area().x(function(a,b){return o(f(a,b))}).y0(function(a){return p(a.y0)}).y1(function(a){return p(a.y0)}),A=u.select(".areaWrap").selectAll("path.area").data(function(a){return a});A.enter().append("path").attr("class","area"),d3.transition(A.exit()).attr("d",function(a,b){return z(a.values,b)}).remove(),A.style("fill",function(a,b){return e[b%10]}).style("stroke",function(a,b){return e[b%10]}),d3.transition(A).attr("d",function(a,b){return w(a.values,b)})}),q}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=d3.scale.category10().range(),f=function(a){return a.x},g=function(a){return a.y},h="stack",i="zero",j="default",k,l,m=d3.dispatch("tooltipShow","tooltipHide"),n=a.models.line(),o=d3.scale.linear(),p=d3.scale.linear();return q.x=function(a){return arguments.length?(f=d3.functor(a),q):f},q.y=function(a){return arguments.length?(g=d3.functor(a),q):g},q.margin=function(a){return arguments.length?(b=a,q):b},q.width=function(a){return arguments.length?(c=a,q):c},q.height=function(a){return arguments.length?(d=a,q):d},q.color=function(a){return arguments.length?(e=a,q):e},q.offset=function(a){return arguments.length?(i=a,q):i},q.order=function(a){return arguments.length?(j=a,q):j},q.style=function(a){if(!arguments.length)return h;h=a;switch(h){case"stack":i="zero",j="default";break;case"stream":i="wiggle",j="inside-out";break;case"expand":i="expand",j="default"}return q},q.dispatch=m,n.dispatch.on("pointMouseover.tooltip",function(a){m.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),n.dispatch.on("pointMouseout.tooltip",function(a){m.tooltipHide(a)}),q},a.models.stackedAreaWithLegend=function(){function r(a){return a.each(function(e){var f=c(),s=d(),t=f-b.left-b.right,u=s-b.top-b.bottom,v=e.filter(function(a){return!a.disabled}).reduce(function(a,b,c){return b.values.forEach(function(b,d){c||(a[d]={x:j(b.x,d),y:0}),a[d].y+=k(b)}),a},[]);h.domain(d3.extent(d3.merge(v),function(a){return a.x})).range([0,t]),i.domain(p.offset()=="zero"?[0,d3.max(v,function(a){return a.y})]:[0,1]).range([u,0]),p.width(t).height(u);var w=d3.select(this).selectAll("g.wrap").data([e]),z=w.enter().append("g").attr("class","wrap d3stackedWithLegend").append("g");z.append("g").attr("class","x axis"),z.append("g").attr("class","y axis"),z.append("g").attr("class","stackedWrap"),z.append("g").attr("class","legendWrap"),z.append("g").attr("class","controlsWrap"),n.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,b.disabled?b.values.map(function(a){return a._y=a.y,a.y=0,a}):b.values.map(function(a){return a.y=a._y,a}),e.filter(function(a){return!a.disabled}).length||e.map(function(a){return a.disabled=!1,a.values.map(function(a){return a.y=a._y,a}),a}),a.transition().call(r)}),o.dispatch.on("legendClick",function(b,c){if(!b.disabled)return;q=q.map(function(a){return a.disabled=!0,a}),b.disabled=!1;switch(b.key){case"Stacked":p.style("stack");break;case"Stream":p.style("stream");break;case"Expanded":p.style("expand")}a.transition().call(r)}),p.dispatch.on("tooltipShow",function(a){if(!Math.round(k(a.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;g.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),p.dispatch.on("tooltipHide",function(a){g.tooltipHide(a)}),b.top=n.height();var A=w.select("g").attr("transform","translate("+b.left+","+b.top+")");n.width(f/2-b.right),A.select(".legendWrap").datum(e).attr("transform","translate("+(f/2-b.left)+","+ -b.top+")").call(n),o.width(280).color(["#444","#444","#444"]),A.select(".controlsWrap").datum(q).attr("transform","translate(0,"+ -b.top+")").call(o);var B=A.select(".stackedWrap").datum(e);d3.transition(B).call(p),l.domain(h.domain()).range(h.range()).ticks(f/100).tickSize(-u,0),A.select(".x.axis").attr("transform","translate(0,"+u+")"),d3.transition(A.select(".x.axis")).call(l),m.domain(i.domain()).range(i.range()).ticks(p.offset()=="wiggle"?0:s/36).tickSize(-t,0).tickFormat(p.offset()=="zero"?d3.format(",.2f"):d3.format("%")),d3.transition(A.select(".y.axis")).call(m)}),r}var b={top:30,right:20,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=function(){return 2.5},f=d3.scale.category10().range(),g=d3.dispatch("tooltipShow","tooltipHide"),h=d3.scale.linear(),i=d3.scale.linear(),j=function(a){return a.x},k=function(a){return a.y},l=a.models.axis().scale(h).orient("bottom"),m=a.models.axis().scale(i).orient("left"),n=a.models.legend().height(30),o=a.models.legend().height(30),p=a.models.stackedArea(),q=[{key:"Stacked"},{key:"Stream",disabled:!0},{key:"Expanded",disabled:!0}];return r.dispatch=g,r.x=function(a){return arguments.length?(j=d3.functor(a),p.x(j),r):j},r.y=function(a){return arguments.length?(k=d3.functor(a),p.y(k),r):k},r.margin=function(a){return arguments.length?(b=a,r):b},r.width=function(a){return arguments.length?(c=d3.functor(a),r):c},r.height=function(a){return arguments.length?(d=d3.functor(a),r):d},r.dotRadius=function(a){return arguments.length?(e=d3.functor(a),p.dotRadius=a,r):e},r.stacked=p,r.xAxis=l,r.yAxis=m,r},a.charts.cumulativeLineChartDaily=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.cumulativeLine().x(function(a,b){return b}),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointIndex)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(function(a){return d3.time.format("%x")(new Date(c[0].values[a].x))}),f.yAxis.tickFormat(d3.format(",.2%")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h},a.charts.line=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.lineWithLegend(),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c.point)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(d3.format(",r")),f.yAxis.tickFormat(d3.format(",.2f")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h},a.charts.lineChartDaily=function(){function h(){return!b||!c.length?h:(d3.select(b).select("svg").datum(c).transition().duration(d).call(f),h)}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"

"+a+"

"+"

"+c+" at "+b+"

"},f=a.models.lineWithLegend().x(function(a,b){return b}),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointIndex)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};return f.xAxis.tickFormat(function(a){return d3.time.format("%x")(new Date(c[0].values[a].x))}),f.yAxis.tickFormat(d3.format(",.2%")),h.build=function(){return!b||!c.length?h:(a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");return f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f),f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}}),h)},h.data=function(a){return arguments.length?(c=a,h):c},h.selector=function(a){return arguments.length?(b=a,h):b},h.duration=function(a){return arguments.length?(d=a,h):d},h.tooltip=function(a){return arguments.length?(e=a,h):e},h.xTickFormat=function(a){return arguments.length?(f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.xAxis.tickFormat()},h.yTickFormat=function(a){return arguments.length?(f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a)),h):f.yAxis.tickFormat()},h.xAxisLabel=function(a){return arguments.length?(f.xAxis.axisLabel(a),h):f.xAxis.axisLabel()},h.yAxisLabel=function(a){return arguments.length?(f.yAxis.axisLabel(a),h):f.yAxis.axisLabel()},d3.rebind(h,f,"x","y"),h.graph=f,h}})(); \ No newline at end of file