From 5a9dd93ee26564fe80ab7d3ac03a246ddf227b5a Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Wed, 5 Mar 2014 02:35:21 +0900 Subject: [PATCH] Add legend.positon - #48 --- c3.js | 224 ++++++++++++++++++++++++++++++++++++------------------ c3.min.js | 188 ++++++++++++++++++++++----------------------- 2 files changed, 243 insertions(+), 169 deletions(-) diff --git a/c3.js b/c3.js index 8d03f8f..6faed82 100644 --- a/c3.js +++ b/c3.js @@ -76,7 +76,7 @@ // legend var __legend_show = getConfig(['legend', 'show'], true), - __legend_item_width = getConfig(['legend', 'item', 'width'], 80), // TODO: auto + __legend_position = getConfig(['legend', 'position'], 'bottom'), __legend_item_onclick = getConfig(['legend', 'item', 'onclick'], function () {}); // axis @@ -173,8 +173,6 @@ var dragStart = null, dragging = false, cancelClick = false; - var legendHeight = __legend_show ? 40 : 0; - var color = generateColor(__data_colors, __color_pattern); var defaultTimeFormat = (function () { @@ -197,7 +195,7 @@ /*-- Set Chart Params --*/ - var margin, margin2, margin3, width, width2, height, height2, height3, currentWidth, currentHeight; + var margin, margin2, margin3, width, width2, height, height2, currentWidth, currentHeight, legendHeight, legendWidth; var radius, radiusExpanded, innerRadius, svgArc, svgArcExpanded, svgArcExpandedSub, pie; var xMin, xMax, yMin, yMax, subXMin, subXMax, subYMin, subYMax; var x, y, y2, subX, subY, subY2, xAxis, yAxis, yAxis2, subXAxis; @@ -211,14 +209,40 @@ main : function () { return "translate(" + margin.left + "," + margin.top + ")"; }, context : function () { return "translate(" + margin2.left + "," + margin2.top + ")"; }, legend : function () { return "translate(" + margin3.left + "," + margin3.top + ")"; }, - y2 : function () { return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 10 : 0) + ")"; }, + y2 : function () { return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 1 : 0) + ")"; }, x : function () { return "translate(0," + height + ")"; }, subx : function () { return "translate(0," + (__axis_rotated ? 0 : height2) + ")"; }, arc: function () { return "translate(" + width / 2 + "," + height / 2 + ")"; } }; + var isLegendRight = __legend_position === 'right'; + /*-- Define Functions --*/ + function transformMain() { + main.attr("transform", translate.main); + main.select('.x.axis').attr("transform", translate.x); + main.select('.y2.axis').attr("transform", translate.y2); + main.select('.chart-arcs').attr("transform", translate.arc); + } + function transformContext() { + if (__subchart_show) { + context.attr("transform", translate.context); + context.select('.x.axis').attr("transform", translate.subx); + } + } + function transformLegend(withTransition) { + var duration = withTransition !== false ? 250 : 0; + if (__legend_show) { + legend.transition().duration(duration).attr("transform", translate.legend); + } + } + function transformAll(withTransition) { + transformMain(withTransition); + transformContext(withTransition); + transformLegend(withTransition); + } + //-- Sizes --// // TODO: configurabale @@ -227,38 +251,43 @@ function updateSizes() { currentWidth = getCurrentWidth(); currentHeight = getCurrentHeight(); + legendHeight = getLegendHeight(); + legendWidth = getLegendWidth(); // for main margin = { - top: 0, - left: (__axis_rotated ? __subchart_size_height + rotated_padding_right : 0) + getCurrentPaddingLeft(), - bottom: 20 + (__axis_rotated ? 0 : __subchart_size_height) + legendHeight, - right: getCurrentPaddingRight() + top: __axis_rotated && __axis_y2_show ? 20 : 0, + right: getCurrentPaddingRight(), + bottom: 20 + (__axis_rotated ? 0 : __subchart_size_height) + (isLegendRight ? 0 : legendHeight), + left: (__axis_rotated ? __subchart_size_height + rotated_padding_right : 0) + getCurrentPaddingLeft() }; width = currentWidth - margin.left - margin.right; height = currentHeight - margin.top - margin.bottom; // for context margin2 = { - top: __axis_rotated ? margin.top : (currentHeight - __subchart_size_height - legendHeight), - left: __axis_rotated ? rotated_padding_left : margin.left, - bottom: 20 + legendHeight, - right: NaN + top: __axis_rotated ? margin.top : (currentHeight - __subchart_size_height - (isLegendRight ? 0 : legendHeight)), + right: NaN, + bottom: 20 + (isLegendRight ? 0 : legendHeight), + left: __axis_rotated ? rotated_padding_left : margin.left }; width2 = __axis_rotated ? margin.left - rotated_padding_left - rotated_padding_right : width; height2 = __axis_rotated ? height : currentHeight - margin2.top - margin2.bottom; // for legend margin3 = { - top: currentHeight - legendHeight, + top: isLegendRight ? margin.top : currentHeight - legendHeight, right: NaN, bottom: 0, - left: margin.left + left: isLegendRight ? currentWidth - legendWidth : 0 }; - height3 = currentHeight - margin3.top - margin3.bottom; // for arc updateRadius(); + + if (isLegendRight && hasArcType(c3.data.targets)) { + margin3.left = width / 2 + radiusExpanded; + } } function updateRadius() { radiusExpanded = height / 2; @@ -277,15 +306,21 @@ return h > 0 ? h : 320; } function getCurrentPaddingLeft() { - if (__padding_left) { + if (hasArcType(c3.data.targets)) { + return 0; + } else if (__padding_left) { return __padding_left; } else { return __axis_y_inner ? 1 : getDefaultPaddingWithAxisId('y'); } } function getCurrentPaddingRight() { - if (__padding_right) { + if (hasArcType(c3.data.targets)) { + return 0; + } else if (__padding_right) { return __padding_right; + } else if (isLegendRight) { + return legendWidth * (__axis_y2_show && !__axis_rotated ? 1.25 : 1); } else if (__axis_y2_show) { return __axis_y2_inner || __axis_rotated ? 1 : getDefaultPaddingWithAxisId('y2'); } else { @@ -302,7 +337,7 @@ return +d3.select(__bindto).style('height').replace('px', ''); // TODO: if rotated, use width } function getXAxisClipWidth() { - return width + 2 + margin.left + margin.right; + return width + 2; } function getXAxisClipHeight() { return 40; @@ -311,7 +346,7 @@ return margin.left + 20; } function getYAxisClipHeight() { - return height - margin.top + 2; + return height + 2; } function getEventRectWidth() { var base = __axis_rotated ? height : width, @@ -319,6 +354,12 @@ maxDataCount = getMaxDataCount(); return maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; } + function getLegendWidth() { + return __legend_show ? isLegendRight ? 150 : currentWidth : 0; + } + function getLegendHeight() { + return __legend_show ? isLegendRight ? currentHeight : 40 : 0; + } //-- Scales --// @@ -1613,13 +1654,12 @@ defs.append("clipPath") .attr("id", clipId) .append("rect") - .attr("y", margin.top) .attr("width", width) - .attr("height", height - margin.top); + .attr("height", height); defs.append("clipPath") .attr("id", "xaxis-clip") .append("rect") - .attr("x", -1 - margin.left) + .attr("x", -1) .attr("y", -20) .attr("width", getXAxisClipWidth) .attr("height", getXAxisClipHeight); @@ -1627,7 +1667,6 @@ .attr("id", "yaxis-clip") .append("rect") .attr("x", -margin.left + 1) - .attr("y", margin.top - 1) .attr("width", getYAxisClipWidth) .attr("height", getYAxisClipHeight); @@ -1818,7 +1857,9 @@ /*-- Legend Region --*/ - if (__legend_show) { updateLegend(c3.data.targets); } + if (__legend_show) { + updateLegend(c3.data.targets); + } // Set targets updateTargets(c3.data.targets); @@ -1848,7 +1889,7 @@ window.onresize = generateResize(); } if (window.onresize.add) { - window.onresize.add(resize); + window.onresize.add(updateAndRedraw); } } @@ -2121,7 +2162,7 @@ var withY, withSubchart, withTransition, withTransform, withUpdateXDomain, withUpdateOrgXDomain; var hideAxis = hasArcType(c3.data.targets); var drawBar, drawBarOnSub, xForText, yForText; - var duration; + var duration, durationForExit; options = isDefined(options) ? options : {}; withY = isDefined(options.withY) ? options.withY : true; @@ -2132,6 +2173,7 @@ withUpdateOrgXDomain = isDefined(options.withUpdateOrgXDomain) ? options.withUpdateOrgXDomain : false; duration = withTransition ? __transition_duration : 0; + durationForExit = isDefined(options.durationForExit) ? options.durationForExit : duration; if (withUpdateOrgXDomain) { x.domain(d3.extent(getXDomain(c3.data.targets))); @@ -2247,7 +2289,7 @@ .transition().duration(duration) .attr('d', drawBar) .style("opacity", 1); - mainBar.exit().transition().duration(duration) + mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); @@ -2266,7 +2308,7 @@ .attr('y', yForText) .style("fill-opacity", opacityForText); mainText.exit() - .transition().duration(duration) + .transition().duration(durationForExit) .style('fill-opacity', 0) .remove(); @@ -2443,6 +2485,9 @@ .style("fill-opacity", 0) .remove(); + // update legend + updateLegend(c3.data.targets, {withTransition: withTransition}); + // update fadein condition getTargetIds().forEach(function (id) { withoutFadeIn[id] = true; @@ -2487,7 +2532,11 @@ }; return callResizeFunctions; } - function resize() { + function updateAndRedraw(options) { + var withTransition, withTransform; + options = isDefined(options) ? options : {}; + withTransition = isDefined(options.withTransition) ? options.withTransition : false; + withTransform = isDefined(options.withTransform) ? options.withTransform : false; // Update sizes and scales updateSizes(); updateScales(); @@ -2500,22 +2549,15 @@ svg.select('#' + clipId).select('rect').attr('width', width).attr('height', height); svg.select('#xaxis-clip').select('rect').attr('width', getXAxisClipWidth); svg.select('.zoom-rect').attr('width', width).attr('height', height); - // Update main positions - main.select('.x.axis').attr("transform", translate.x); - main.select('.y2.axis').attr("transform", translate.y2); - main.select('.chart-arcs').attr("transform", translate.arc); - // Update context sizes and positions - if (__subchart_show) { - context.attr("transform", translate.context); - context.select('.x.axis').attr("transform", translate.subx); - } - // Update legend positions - if (__legend_show) { - legend.attr("transform", translate.legend); - updateLegend(c3.data.targets, {withTransition: false}); - } + // Update g positions + transformAll(withTransition); // Draw with new sizes & scales - redraw({withTransition: false, withUpdateXDomain: true}); + redraw({ + withTransition: withTransition, + withUpdateXDomain: true, + withTransform: withTransform, + durationForExit: 0 + }); } function updateTargets(targets) { @@ -2698,13 +2740,41 @@ function updateLegend(targets, options) { var ids = getTargetIds(targets), l; - var padding = width / 2 - __legend_item_width * Object.keys(targets).length / 2; + var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; + var item_height = 0, item_width = 0, paddingTop = 4, paddingRight = 30, margin, updateSizes; var withTransition; options = isUndefined(options) ? {} : options; - withTransition = isDefined(options.withTransition) ? options.withTransition : true; + if (isLegendRight) { + xForLegend = function () { return legendWidth * 0.2; }; + yForLegend = function (d, i) { return margin + item_height * i; }; + } else { + xForLegend = function (d, i) { return margin + item_width * i; }; + yForLegend = function () { return legendHeight * 0.2; }; + } + xForLegendText = function (d, i) { return xForLegend(d, i) + 14; }; + yForLegendText = function (d, i) { return yForLegend(d, i) + 9; }; + xForLegendRect = function (d, i) { return xForLegend(d, i) - 4; }; + yForLegendRect = function (d, i) { return yForLegend(d, i) - 7; }; + updateSizes = function (offsetWidth, offsetHeight) { + var width = Math.ceil((offsetWidth + paddingRight) / 10) * 10, + height = Math.ceil((offsetHeight + paddingTop) / 10) * 10; + if (width > item_width) { + item_width = width; + if (! isLegendRight) { + margin = (legendWidth - item_width * Object.keys(targets).length) / 2; + } + } + if (height > item_height) { + item_height = height; + if (isLegendRight) { + margin = (legendHeight - item_height * Object.keys(targets).length) / 2; + } + } + }; + // Define g for legend area l = legend.selectAll('.legend-item') .data(ids) @@ -2722,41 +2792,47 @@ revertLegend(); c3.revert(); }); + l.append('text') + .text(function (d) { return isDefined(__data_names[d]) ? __data_names[d] : d; }) + .each(function () { updateSizes(this.offsetWidth, this.offsetHeight); }) + .style("pointer-events", "none") + .attr('x', isLegendRight ? xForLegendText : -200) + .attr('y', isLegendRight ? -200 : yForLegend); l.append('rect') .attr("class", "legend-item-event") .style('fill-opacity', 0) - .attr('x', -200) - .attr('y', function () { return legendHeight / 2 - 16; }) - .attr('width', __legend_item_width) + .attr('x', isLegendRight ? xForLegendRect : -200) + .attr('y', isLegendRight ? -200 : yForLegendRect) + .attr('width', item_width + 14) .attr('height', 24); l.append('rect') .attr("class", "legend-item-tile") .style("pointer-events", "none") .style('fill', function (d) { return color(d); }) - .attr('x', -200) - .attr('y', function () { return legendHeight / 2 - 9; }) + .attr('x', isLegendRight ? xForLegendText : -200) + .attr('y', isLegendRight ? -200 : yForLegendText) .attr('width', 10) .attr('height', 10); - l.append('text') - .text(function (d) { return isDefined(__data_names[d]) ? __data_names[d] : d; }) - .style("pointer-events", "none") - .attr('x', -200) - .attr('y', function () { return legendHeight / 2; }); - legend.selectAll('rect.legend-item-event') + legend.selectAll('text') .data(ids) + .each(function () { updateSizes(this.offsetWidth, this.offsetHeight); }) .transition().duration(withTransition ? 250 : 0) - .attr('x', function (d, i) { return padding + __legend_item_width * i; }); + .attr('x', xForLegendText) + .attr('y', yForLegendText); - legend.selectAll('rect.legend-item-tile') + legend.selectAll('rect.legend-item-event') .data(ids) .transition().duration(withTransition ? 250 : 0) - .attr('x', function (d, i) { return padding + __legend_item_width * i; }); + .attr('x', xForLegendRect) + .attr('y', yForLegendRect); - legend.selectAll('text') + legend.selectAll('rect.legend-item-tile') .data(ids) .transition().duration(withTransition ? 250 : 0) - .attr('x', function (d, i) { return padding + __legend_item_width * i + 14; }); + .attr('x', xForLegend) + .attr('y', yForLegend); + } /*-- Event Handling --*/ @@ -2935,46 +3011,42 @@ c3.toLine = function (targets) { setTargetType(targets, 'line'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toSpline = function (targets) { setTargetType(targets, 'spline'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toBar = function (targets) { setTargetType(targets, 'bar'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toScatter = function (targets) { setTargetType(targets, 'scatter'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toArea = function (targets) { setTargetType(targets, 'area'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toAreaSpline = function (targets) { setTargetType(targets, 'area-spline'); - redraw(); + updateAndRedraw({withTransition: true}); }; c3.toPie = function (targets) { setTargetType(targets, 'pie'); - updateRadius(); - updateArc(); - redraw({withTransform: true}); + updateAndRedraw({withTransition: true, withTransform: true}); }; c3.toDonut = function (targets) { setTargetType(targets, 'donut'); - updateRadius(); - updateArc(); - redraw({withTransform: true}); + updateAndRedraw({withTransition: true, withTransform: true}); }; c3.groups = function (groups) { @@ -3024,7 +3096,7 @@ c3.resize = function (size) { __size_width = size ? size.width : null; __size_height = size ? size.height : null; - resize(); + updateAndRedraw(); }; c3.destroy = function () { diff --git a/c3.min.js b/c3.min.js index 687a5d3..8971f14 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,93 +1,95 @@ -(function(K){function Ad(){function O(d,e){d.attr("transform",function(d){return"translate("+(e(d)+ga)+", 0)"})}function w(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function z(d){var e=d[0];d=d[d.length-1];return ezc?zc:a}function Z(a){var b=!1;Ob(g.data.targets).forEach(function(c){b||c.data.id!==a.data.id||(b=!0,a=c)});return b?a:null}function Dd(){var a=e.svg.arc().outerRadius(Na).innerRadius(Db), -b=function(b,f){var k;return f?a(b):(k=Z(b))?a(k):"M 0 0"};b.centroid=a.centroid;return b}function sc(a){var b=e.svg.arc().outerRadius(Cb*(a?a:1)).innerRadius(Db);return function(a){return(a=Z(a))?b(a):"M 0 0"}}function wb(a){a=Z(a);var b,c;b="";a&&(b=ib.centroid(a),a=b[0],b=b[1],c=Math.sqrt(a*a+b*b),b="translate("+0.8*(a/c)*Na+","+0.8*(b/c)*Na+")");return b}function Ed(a){return Qd(a,(a.endAngle-a.startAngle)/(2*Math.PI))}function Ac(a,b){var c=p.selectAll(".chart-arc"+ka(a)),f=p.selectAll(".-arc").filter(function(b){return b.data.id!== -a});c.selectAll("path").transition().duration(50).attr("d",wc).transition().duration(100).attr("d",xc).each(function(a){Pb(a.data)});b||f.style("opacity",0.3)}function Qb(a){p.selectAll(".chart-arc"+ka(a)).selectAll("path").transition().duration(50).attr("d",ib);p.selectAll(".-arc").style("opacity",1)}function Rd(a){var b=Bc(a),c,f,k,d;if(0a?a:0}),c=1;c+a||(b[f][c]+=+a)});return e.max(Object.keys(b).map(function(a){return e.max(b[a])}))}function kb(a){var b=lb(function(b){return Y(b.id)===a}),c="y2"=== -a?Ud:Vd,f="y2"===a?Wd:Xd,c=c?c:Rd(b),f=f?f:Sd(b),k=0.22*Math.abs(f-c),d=k,e=k,h="y2"===a?Yd:Zd;h&&(c=Math.max(Math.abs(c),Math.abs(f)),f=c-h,c=h-c);"y"===a&&Pa&&(d=A(Pa.top)?Pa.top:k,e=A(Pa.bottom)?Pa.bottom:k);"y2"===a&&Qa&&(d=A(Qa.top)?Qa.top:k,e=A(Qa.bottom)?Qa.bottom:k);$(b,"bar")&&!Cc(b)&&(e=c);return[c-e,f+d]}function $d(a){return e.min(a,function(a){return e.min(a.values,function(a){return a.x})})}function ae(a){return e.max(a,function(a){return e.max(a.values,function(a){return a.x})})}function mb(a){var b= -[$d(a),ae(a)],c=b[0],f=b[1],b=Math.abs(b[0]-b[1]);a=ja?0:$(a,"bar")?b/(za()-1)/2:0.01*b;c=D?new Date(c.getTime()-a):c-a;f=D?new Date(f.getTime()+a):f+a;return[c,f]}function ya(a){return a[1]-a[0]}function be(a){for(var b=0;ba?0:a} -function Fc(a){return ta&&a===ta||ca&&de(ca,a)}function ee(a){return!Fc(a)}function fe(a){Object.keys(a).forEach(function(b){ca[b]=a[b]})}function ob(a){var b;a&&(b=Ra[a.id],a.name=b?b:a.id);return a}function Gc(a){var b=a[0],c={},f=[],k,d;for(k=1;kb&&(c=a,b=a.values.length)}):c=a?g.data.targets[0]:null;return c}function Ta(a){a=w(a)?g.data.targets:a;return a.map(function(a){return a.id})}function Kc(a){var b=Ta(),c;for(c=0;ca})}function Td(a){return Lc(a,function(a){return 0 -k&&(d-=c+30)),c=b[1]+15+fv[c].indexOf(k.id)))for(f=0;fb.value?-1:1)):a[0][0]+(a[2][0]-a[0][0])/2} -function De(a,b,c){return h?(a[0][0]+a[2][0]+0.6*c.offsetHeight)/2:a[2][1]+(0>b.value?c.offsetHeight:ua(b)?-3:-6)}function md(a,b){var c=a.__max__+1,f=c?1.2*T.tickOffset()/c:0,d=te(f,c,a,!!b),e=ue(!!b),h=ve(a,!!b),g=b?L:u;return function(a,b){var c=g(a.id)(0),l=h(a,b)||c;return[[d(a),l],[d(a),e(a)-(c-l)],[d(a)+f,e(a)-(c-l)],[d(a)+f,l]]}}function Ee(a,b,c,f){var d,e,g="M",l,m,n,p,r,q=[];if(z(f))for(d=0;d=e;e+=Fe)g+=f(a[d-1],a[d],e,n)}return g}function ac(a){var b;qb=e.select(xa);if(qb.empty())K.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{qb.html("");g.data.x={};g.data.targets=Sa(a);qa();Q();n.domain(e.extent(mb(g.data.targets)));B.domain(kb("y"));ba.domain(kb("y2")); -U.domain(n.domain());gb.domain(B.domain());hb.domain(ba.domain());aa=n.domain();G.scale(U);fa&&C.scale(n);p=e.select(xa).append("svg").attr("width",r+t+H).attr("height",q+m+pa).on("mouseenter",Ge).on("mouseleave",He);rb=p.append("defs");rb.append("clipPath").attr("id",bc).append("rect").attr("y",m).attr("width",r).attr("height",q-m);rb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-t).attr("y",-20).attr("width",ia).attr("height",X);rb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x", --t+1).attr("y",m-1).attr("width",Ka).attr("height",xb);l=p.append("g").attr("transform",J.main);F=Ga?p.append("g").attr("transform",J.context):null;Ha=Ia?p.append("g").attr("transform",J.legend):null;V=e.select(xa).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");l.append("g").attr("class","x axis").attr("clip-path",h?"":"url("+document.URL+"#xaxis-clip)").attr("transform",J.x).append("text").attr("class","-axis-x-label").attr("x", -r).attr("dy","-.5em").style("text-anchor","end").text(Ie);l.append("g").attr("class","y axis").attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":"").append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Je);Ab&&l.append("g").attr("class","y2 axis").attr("transform",J.y2);a=l.append("g").attr("clip-path",Ya).attr("class","grid");od&&a.append("g").attr("class","xgrids");cc&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(cc).enter().append("g").attr("class", -"xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"":"rotate(-90)").attr("dx",h?0:-m).attr("dy",-5).text(function(a){return a.text}));Ke&&a.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",h?0:-10).attr("x2",h?r:-10).attr("y1",h?-10:m).attr("y2",h?-10:q);pd&&a.append("g").attr("class","ygrids");dc&&(a=a.append("g").attr("class", -"ygrid-lines").selectAll("ygrid-line").data(dc).enter().append("g").attr("class","ygrid-line"),a.append("line").attr("class",function(a){return""+a["class"]}),a.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"rotate(-90)":"").attr("dx",h?0:-m).attr("dy",-5).text(function(a){return a.text}));l.append("g").attr("clip-path",Ya).attr("class","regions");l.append("g").attr("clip-path",Ya).attr("class","chart");l.select(".chart").append("g").attr("class", -"event-rects").style("fill-opacity",0).style("cursor",fa?h?"ns-resize":"ew-resize":null);l.select(".chart").append("g").attr("class","chart-bars");l.select(".chart").append("g").attr("class","chart-lines");l.select(".chart").append("g").attr("class","chart-arcs").attr("transform",J.arc).append("text").attr("class","chart-arcs-title").style("text-anchor","middle").text(Le);l.select(".chart").append("g").attr("class","chart-texts");if(fa)l.insert("rect",Me?null:"g.grid").attr("class","zoom-rect").attr("width", -r).attr("height",q).style("opacity",0).style("cursor",h?"ns-resize":"ew-resize").call(C).on("dblclick.zoom",null);null!==sb&&G.extent("function"!==typeof sb?sb:sb(mb()));Ga&&(F.append("g").attr("clip-path",Ya).attr("class","chart"),F.select(".chart").append("g").attr("class","chart-bars"),F.select(".chart").append("g").attr("class","chart-lines"),F.append("g").attr("clip-path",Ya).attr("class","x brush").call(G).selectAll("rect").attr(h?"width":"height",h?Bb:fb),F.append("g").attr("class","x axis").attr("transform", -J.subx).attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":""));Ia&&tb(g.data.targets);qd(g.data.targets);x({withTransform:!0,withUpdateXDomain:!0});if(Ne){if(D&&"string"===typeof Ja){Ja=sa(Ja);for(a=0;aUb(c,a)?p.select(".event-rect").style("cursor","pointer"):p.select(".event-rect").style("cursor",null))}).on("click",function(){var a, -c;E(g.data.targets)||(a=e.mouse(this),c=Xc(g.data.targets,a),100>Ub(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){td(this,c,c.index)}))}).call(e.behavior.drag().origin(Object).on("drag",function(){ud(e.mouse(this))}).on("dragstart",function(){vd(e.mouse(this))}).on("dragend",function(){wd()})).call(C).on("dblclick.zoom",null)}function td(a,b,c){var d=e.select(a),k=d.classed(na),g=!1,h;"circle"===a.nodeName?(g=fd(a,1.5*Xa),h=id):"rect"===a.nodeName&&(g=gd(a),h=kd);if(va|| -g)la&&ma(b)&&(d.classed(na,!k),h(!k,d,b,c)),Re(b,d)}function ud(a){var b,c,d,k,h,n,p;E(g.data.targets)||!la||fa&&!C.altDomain||(b=hc[0],c=hc[1],d=a[0],a=a[1],k=Math.min(b,d),h=Math.max(b,d),n=va?m:Math.min(c,a),p=va?q:Math.max(c,a),l.select(".dragarea").attr("x",k).attr("y",n).attr("width",h-k).attr("height",p-n),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ma(a)}).each(function(a,b){var c=e.select(this),d=c.classed(na),f=c.classed(ic),g,l,m,q;g=!1;"circle"===this.nodeName? -(g=1*c.attr("cx"),l=1*c.attr("cy"),q=id,g=ka.value?"end":"start":"middle"}).style("stroke","none").style("fill-opacity",0).text(function(a){return Tc(a.value)});c.style("fill-opacity",pe).transition().duration(s).attr("x",t).attr("y",a).style("fill-opacity",Qc);c.exit().transition().duration(s).style("fill-opacity",0).remove();l.selectAll(".-line").style("opacity",Aa).transition().duration(s).attr("d", -Ue).style("opacity",1);l.selectAll(".-area").style("opacity",0).transition().duration(s).attr("d",Ve).style("opacity",xd);c=l.selectAll(".-circles").selectAll(".-circle").data(we);c.enter().append("circle").attr("class",ne).style("opacity",0).attr("r",$b);c.style("opacity",Aa).transition().duration(s).style("opacity",qe).attr("cx",h?Fa:Ea).attr("cy",h?Ea:Fa);c.exit().remove();l.selectAll(".chart-arc").select(".-arc").attr("transform",u?"scale(0)":"").style("opacity",function(a){return a===this._current? -0:1}).transition().duration(s).attrTween("d",function(a){a=Z(a);if(!a)return function(){return"M 0 0"};var b=e.interpolate(this._current,a);this._current=b(0);return function(a){a=b(a);return dd(a.data)||Pb(a.data)?ib(a,!0):"M 0 0"}}).attr("transform",u?"scale(1)":"").style("opacity",1);l.selectAll(".chart-arc").select("text").attr("transform",wb).style("opacity",0).transition().duration(s).text(Ed).style("opacity",function(a){return dd(a.data)||Pb(a.data)?1:0});l.select(".chart-arcs-title").style("opacity", -$(g.data.targets,"donut")?1:0);Ga&&(null!==e.event&&"zoom"===e.event.type&&G.extent(n.orgDomain()).update(),k&&(F.select(".x.axis").style("opacity",v?0:1).transition().duration(h?s:0).call(Lb),G.empty()||G.extent(n.orgDomain()).update(),k=ld(d,!0),d=F.selectAll(".-bars").selectAll(".-bar").data(ed),d.enter().append("path").attr("d",k).style("stroke","none").style("fill",function(a){return I(a.id)}).attr("class",Oc),d.style("opacity",Aa).transition().duration(s).attr("d",k).style("opacity",1),d.exit().transition().duration(s).style("opacity", -0).remove(),F.selectAll(".-line").style("opacity",Aa).transition().duration(s).attr("d",We).style("opacity",1)));l.selectAll(".selected-circles").filter(function(a){return ua(a)}).selectAll("circle").remove();l.selectAll(".selected-circle").transition().duration(s).attr("cx",h?Fa:Ea).attr("cy",h?Ea:Fa);ca?(k=l.select(".event-rects").selectAll(".event-rect").data([0]),Qe(k.enter()),k.attr("x",0).attr("y",0).attr("width",r).attr("height",q)):(Sb?(p=function(a,b){var c=Jc(b),d=b"+c+""),g=a[d].name,e=Tc(a[d].value),c+=""+g+""+e+"");return c+""}),Ne=d(["tooltip","init","show"],!1),Ja=d(["tooltip","init","x"],0),rd=d(["tooltip","init","position"],{top:"0px",left:"50px"}),bc=xa.replace("#","")+"-clip",Ya="url("+document.URL+"#"+bc+")",D="timeseries"=== -nc,ja="categorized"===nc,Sb=!D&&(ta||ca),hc=null,Za=!1,gc=!1,ra=Ia?40:0,I=function(a,b){var c=[],d=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return d[c.indexOf(b)%d.length]}}($e,af),Nd=function(){var a=[[e.time.format("%Y/%-m/%-d"),function(){return!0}],[e.time.format("%-m/%-d"),function(a){return a.getMonth()}],[e.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}], -[e.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[e.time.format("%I %p"),function(a){return a.getHours()}],[e.time.format("%I:%M"),function(a){return a.getMinutes()}],[e.time.format(":%S"),function(a){return a.getSeconds()}],[e.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),r,Bb,q,fb,yb,wa,Na,Cb,Db,ib,wc,xc,Ob,Fb,Gb,Hb,Ib,Jb,Kb,n,B,ba,U,gb,hb,T,Mb,vc,Lb,Fd=h?"left":"bottom", -Hd=h?cb?"top":"bottom":cb?"right":"left",Jd=h?eb?"bottom":"top":eb?"left":"right",Gd=h?"left":"bottom",J={main:function(){return"translate("+t+","+m+")"},context:function(){return"translate("+qc+","+vb+")"},legend:function(){return"translate("+pc+","+oc+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"},x:function(){return"translate(0,"+q+")"},subx:function(){return"translate(0,"+(h?0:fb)+")"},arc:function(){return"translate("+r/2+","+q/2+")"}},uc=40,tc=20;Ob=e.layout.pie().value(function(a){return a.values.reduce(function(a, -c){return a+c.value},0)});var Ue=function(){var a=e.svg.line().x(h?function(a){return u(a.id)(a.value)}:Ca).y(h?Ca:function(a){return u(a.id)(a.value)});return function(b){var c=Xb(b.values),d;if(pb(b))return cd(b)?a.interpolate("cardinal"):a.interpolate("linear"),zd[b.id]?Ee(c,n,u(b.id),zd[b.id]):a(c);d=n(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),Ve=function(){var a;a=h?e.svg.area().x0(function(a){return u(a.id)(0)}).x1(function(a){return u(a.id)(a.value)}).y(Ca):e.svg.area().x(Ca).y0(function(a){return u(a.id)(0)}).y1(function(a){return u(a.id)(a.value)}); -return function(b){var c=Xb(b.values),d;if($([b],"area")||$([b],"area-spline"))return cd(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=n(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),We=function(){var a=e.svg.line().x(h?function(a){return L(a.id)(a.value)}:Sc).y(h?Sc:function(a){return L(a.id)(a.value)});return function(b){var c=Xb(b.values);return pb(b)?a(c):"M "+U(c[0].x)+" "+L(b.id)(c[0].value)}}(),G,C=function(){};G=e.svg.brush().on("brush",function(){x({withTransition:!1, -withY:!1,withSubchart:!1,withUpdateXDomain:!0})});G.update=function(){F&&F.select(".x.brush").call(this);return this};G.scale=function(a){return h?this.y(a):this.x(a)};fa&&(C=e.behavior.zoom().on("zoomstart",function(){C.altDomain=e.event.sourceEvent.altKey?n.orgDomain():null}).on("zoom",fa?Xe:null),C.scale=function(a){return h?this.y(a):this.x(a)},C.orgScaleExtent=function(){var a=yd?yd:[1,10];return[a[0],Math.max(za()/a[1],a[1])]},C.updateScaleExtent=function(){var a=ya(n.orgDomain())/ya(aa),b= -this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this});var p,rb,l,F,Ha,V,qb,aa,xd,Tb={};g.focus=function(a){var b=p.selectAll(ka(a)),c=b.filter(lc),b=b.filter(mc);g.revert();g.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);E(g.data.targets)&&Ac(a,!0);jc(a)};g.defocus=function(a){var b=p.selectAll(ka(a)),c=b.filter(lc),b=b.filter(mc);g.revert();c.classed("focused",!1).transition().duration(100).style("opacity", -0.3);b.transition().duration(100).style("opacity",0.3);E(g.data.targets)&&Qb(a);Ye(a)};g.revert=function(a){var b=p.selectAll(ka(a)),c=b.filter(lc),b=b.filter(mc);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);E(g.data.targets)&&Qb(a);kc()};g.show=function(a){p.selectAll(ka(a)).transition().style("opacity",1)};g.hide=function(a){p.selectAll(ka(a)).transition().style("opacity",0)};g.unzoom=function(){G.clear().update();x({withUpdateXDomain:!0})}; -g.load=function(a){"function"!==typeof a.done&&(a.done=function(){});a.xs&&fe(a.xs);"categories"in a&&ja&&(Oa=a.categories,T.categories(Oa));if("cacheIds"in a&&be(a.cacheIds))$a(ce(a.cacheIds),a.done);else if("data"in a)$a(Sa(a.data),a.done);else if("url"in a)e.csv(a.url,function(b,c){$a(Sa(c),a.done)});else if("rows"in a)$a(Sa(Gc(a.rows)),a.done);else if("columns"in a)$a(Sa(Hc(a.columns)),a.done);else throw Error("url or rows or columns is required.");};g.unload=function(a){g.data.targets=g.data.targets.filter(function(b){return b.id!== -a});p.selectAll(ka(a)).transition().style("opacity",0).remove();Ia&&(p.selectAll(".legend-item"+ub(a)).remove(),tb(g.data.targets));0b.classes.indexOf(a)})});return N};g.data.get=function(a){a=g.data.getAsTarget(a);return z(a)?a.values.map(function(a){return a.value}):void 0};g.data.getAsTarget=function(a){var b=lb(function(b){return b.id===a});return 0Ec?Ec:a}function na(a){var b=!1;Sb(f.data.targets).forEach(function(c){b|| +c.data.id!==a.data.id||(b=!0,a=c)});return b?a:null}function xa(){var a=e.svg.arc().outerRadius(Ra).innerRadius(Gb),b=function(b,g){var k;return g?a(b):(k=na(b))?a(k):"M 0 0"};b.centroid=a.centroid;return b}function vc(a){var b=e.svg.arc().outerRadius(jb*(a?a:1)).innerRadius(Gb);return function(a){return(a=na(a))?b(a):"M 0 0"}}function eb(a){a=na(a);var b,c;b="";a&&(b=mb.centroid(a),a=b[0],b=b[1],c=Math.sqrt(a*a+b*b),b="translate("+0.8*(a/c)*Ra+","+0.8*(b/c)*Ra+")");return b}function Cb(a){return Td(a, +(a.endAngle-a.startAngle)/(2*Math.PI))}function wc(a,b){var c=p.selectAll(".chart-arc"+ja(a)),g=p.selectAll(".-arc").filter(function(b){return b.data.id!==a});c.selectAll("path").transition().duration(50).attr("d",Bc).transition().duration(100).attr("d",Cc).each(function(a){Tb(a.data)});b||g.style("opacity",0.3)}function Ub(a){p.selectAll(".chart-arc"+ja(a)).selectAll("path").transition().duration(50).attr("d",mb);p.selectAll(".-arc").style("opacity",1)}function Ud(a){var b=Fc(a),c,g,k,d;if(0a?a:0}),c=1;c+a||(b[g][c]+=+a)});return e.max(Object.keys(b).map(function(a){return e.max(b[a])}))}function ob(a){var b=pb(function(b){return A(b.id)===a}),c="y2"===a?Xd:Yd,g="y2"===a?Zd:$d,c=c?c:Ud(b),g=g?g:Vd(b),k=0.22*Math.abs(g-c),d=k,e=k,f="y2"===a?ae:be;f&&(c=Math.max(Math.abs(c),Math.abs(g)),g=c-f,c=f-c);"y"===a&&Ta&&(d=F(Ta.top)?Ta.top:k,e=F(Ta.bottom)?Ta.bottom:k);"y2"===a&&Ua&&(d=F(Ua.top)?Ua.top:k,e=F(Ua.bottom)?Ua.bottom:k);Z(b,"bar")&&!Gc(b)&&(e=c);return[c-e,g+d]}function ce(a){return e.min(a, +function(a){return e.min(a.values,function(a){return a.x})})}function de(a){return e.max(a,function(a){return e.max(a.values,function(a){return a.x})})}function qb(a){var b=[ce(a),de(a)],c=b[0],g=b[1],b=Math.abs(b[0]-b[1]);a=ia?0:Z(a,"bar")?b/(Aa()-1)/2:0.01*b;c=C?new Date(c.getTime()-a):c-a;g=C?new Date(g.getTime()+a):g+a;return[c,g]}function za(a){return a[1]-a[0]}function ee(a){for(var b=0;ba?0:a}function Jc(a){return ua&&a===ua||ba&&ge(ba,a)}function he(a){return!Jc(a)}function ie(a){Object.keys(a).forEach(function(b){ba[b]=a[b]})}function sb(a){var b;a&&(b=Va[a.id],a.name=b?b:a.id);return a}function Kc(a){var b=a[0],c={},g=[],k,d;for(k=1;kb&&(c=a,b=a.values.length)}):c=a?f.data.targets[0]:null;return c}function Xa(a){a=w(a)?f.data.targets: +a;return a.map(function(a){return a.id})}function Oc(a){var b=Xa(),c;for(c=0;ca})} +function Wd(a){return Pc(a,function(a){return 0k&&(d-=c+30)),c=b[1]+15+gu[c].indexOf(k.id)))for(g=0;gb.value?-1:1)):a[0][0]+(a[2][0]-a[0][0])/2}function Ge(a,b,c){return h?(a[0][0]+a[2][0]+0.6*c.offsetHeight)/2:a[2][1]+(0>b.value?c.offsetHeight:va(b)?-3:-6)}function pd(a,b){var c=a.__max__+1,g=c?1.2*S.tickOffset()/c:0,d=we(g,c,a,!!b),e=xe(!!b),f=ye(a,!!b),h=b?H:t;return function(a,b){var c=h(a.id)(0), +l=f(a,b)||c;return[[d(a),l],[d(a),e(a)-(c-l)],[d(a)+g,e(a)-(c-l)],[d(a)+g,l]]}}function He(a,b,c,g){var d,e,f="M",l,n,m,p,q,s=[];if(y(g))for(d=0;d=e;e+=r)f+=g(a[d-1],a[d],e,m)}return f}function fc(a){var b;ub=e.select(ya);if(ub.empty())N.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); +else{ub.html("");f.data.x={};f.data.targets=Wa(a);pa();P();m.domain(e.extent(qb(f.data.targets)));D.domain(ob("y"));aa.domain(ob("y2"));T.domain(m.domain());kb.domain(D.domain());lb.domain(aa.domain());$=m.domain();J.scale(T);ea&&E.scale(m);p=e.select(ya).append("svg").attr("width",q+v+M).attr("height",r+n+oa).on("mouseenter",Ie).on("mouseleave",Je);vb=p.append("defs");vb.append("clipPath").attr("id",gc).append("rect").attr("width",q).attr("height",r);vb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", +-1).attr("y",-20).attr("width",ha).attr("height",X);vb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-v+1).attr("width",Ka).attr("height",Db);l=p.append("g").attr("transform",K.main);G=Ha?p.append("g").attr("transform",K.context):null;Ia=sa?p.append("g").attr("transform",K.legend):null;U=e.select(ya).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");l.append("g").attr("class","x axis").attr("clip-path",h?"":"url("+ +document.URL+"#xaxis-clip)").attr("transform",K.x).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(Ke);l.append("g").attr("class","y axis").attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":"").append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Le);fb&&l.append("g").attr("class","y2 axis").attr("transform",K.y2);a=l.append("g").attr("clip-path",bb).attr("class","grid"); +sd&&a.append("g").attr("class","xgrids");hc&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(hc).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"":"rotate(-90)").attr("dx",h?0:-n).attr("dy",-5).text(function(a){return a.text}));Me&&a.append("g").attr("class","xgrid-focus").append("line").attr("class", +"xgrid-focus").attr("x1",h?0:-10).attr("x2",h?q:-10).attr("y1",h?-10:n).attr("y2",h?-10:r);td&&a.append("g").attr("class","ygrids");ic&&(a=a.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(ic).enter().append("g").attr("class","ygrid-line"),a.append("line").attr("class",function(a){return""+a["class"]}),a.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"rotate(-90)":"").attr("dx",h?0:-n).attr("dy",-5).text(function(a){return a.text})); +l.append("g").attr("clip-path",bb).attr("class","regions");l.append("g").attr("clip-path",bb).attr("class","chart");l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ea?h?"ns-resize":"ew-resize":null);l.select(".chart").append("g").attr("class","chart-bars");l.select(".chart").append("g").attr("class","chart-lines");l.select(".chart").append("g").attr("class","chart-arcs").attr("transform",K.arc).append("text").attr("class","chart-arcs-title").style("text-anchor", +"middle").text(Ne);l.select(".chart").append("g").attr("class","chart-texts");if(ea)l.insert("rect",Oe?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",r).style("opacity",0).style("cursor",h?"ns-resize":"ew-resize").call(E).on("dblclick.zoom",null);null!==wb&&J.extent("function"!==typeof wb?wb:wb(qb()));Ha&&(G.append("g").attr("clip-path",bb).attr("class","chart"),G.select(".chart").append("g").attr("class","chart-bars"),G.select(".chart").append("g").attr("class","chart-lines"), +G.append("g").attr("clip-path",bb).attr("class","x brush").call(J).selectAll("rect").attr(h?"width":"height",h?Fb:ib),G.append("g").attr("class","x axis").attr("transform",K.subx).attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":""));sa&&xb(f.data.targets);ud(f.data.targets);V({withTransform:!0,withUpdateXDomain:!0});if(Pe){if(C&&"string"===typeof Ja){Ja=ta(Ja);for(a=0;aZb(c,a)?p.select(".event-rect").style("cursor","pointer"):p.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;B(f.data.targets)||(a=e.mouse(this),c=$c(f.data.targets,a),100>Zb(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){wd(this,c,c.index)}))}).call(e.behavior.drag().origin(Object).on("drag",function(){xd(e.mouse(this))}).on("dragstart",function(){yd(e.mouse(this))}).on("dragend", +function(){zd()})).call(E).on("dblclick.zoom",null)}function wd(a,b,c){var d=e.select(a),k=d.classed(ma),f=!1,h;"circle"===a.nodeName?(f=id(a,1.5*ab),h=ld):"rect"===a.nodeName&&(f=jd(a),h=nd);if(wa||f)ka&&la(b)&&(d.classed(ma,!k),h(!k,d,b,c)),Te(b,d)}function xd(a){var b,c,d,k,h,m,p;B(f.data.targets)||!ka||ea&&!E.altDomain||(b=mc[0],c=mc[1],d=a[0],a=a[1],k=Math.min(b,d),h=Math.max(b,d),m=wa?n:Math.min(c,a),p=wa?r:Math.max(c,a),l.select(".dragarea").attr("x",k).attr("y",m).attr("width",h-k).attr("height", +p-m),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return la(a)}).each(function(a,b){var c=e.select(this),d=c.classed(ma),g=c.classed(nc),f,l,rd,n;f=!1;"circle"===this.nodeName?(f=1*c.attr("cx"),l=1*c.attr("cy"),n=ld,f=ka.value?"end":"start":"middle"}).style("stroke","none").style("fill-opacity",0).text(function(a){return Yb(a.value)});c.style("fill-opacity", +se).transition().duration(s).attr("x",u).attr("y",v).style("fill-opacity",Uc);c.exit().transition().duration(a).style("fill-opacity",0).remove();l.selectAll(".-line").style("opacity",Ba).transition().duration(s).attr("d",We).style("opacity",1);l.selectAll(".-area").style("opacity",0).transition().duration(s).attr("d",Xe).style("opacity",Ad);a=l.selectAll(".-circles").selectAll(".-circle").data(ze);a.enter().append("circle").attr("class",qe).style("opacity",0).attr("r",ec);a.style("opacity",Ba).transition().duration(s).style("opacity", +te).attr("cx",h?Ga:Fa).attr("cy",h?Fa:Ga);a.exit().remove();l.selectAll(".chart-arc").select(".-arc").attr("transform",x?"scale(0)":"").style("opacity",function(a){return a===this._current?0:1}).transition().duration(s).attrTween("d",function(a){a=na(a);if(!a)return function(){return"M 0 0"};var b=e.interpolate(this._current,a);this._current=b(0);return function(a){a=b(a);return gd(a.data)||Tb(a.data)?mb(a,!0):"M 0 0"}}).attr("transform",x?"scale(1)":"").style("opacity",1);l.selectAll(".chart-arc").select("text").attr("transform", +eb).style("opacity",0).transition().duration(s).text(Cb).style("opacity",function(a){return gd(a.data)||Tb(a.data)?1:0});l.select(".chart-arcs-title").style("opacity",Z(f.data.targets,"donut")?1:0);Ha&&(null!==e.event&&"zoom"===e.event.type&&J.extent(m.orgDomain()).update(),k&&(G.select(".x.axis").style("opacity",w?0:1).transition().duration(h?s:0).call(Pb),J.empty()||J.extent(m.orgDomain()).update(),k=od(d,!0),d=G.selectAll(".-bars").selectAll(".-bar").data(hd),d.enter().append("path").attr("d", +k).style("stroke","none").style("fill",function(a){return I(a.id)}).attr("class",Sc),d.style("opacity",Ba).transition().duration(s).attr("d",k).style("opacity",1),d.exit().transition().duration(s).style("opacity",0).remove(),G.selectAll(".-line").style("opacity",Ba).transition().duration(s).attr("d",Ye).style("opacity",1)));l.selectAll(".selected-circles").filter(function(a){return va(a)}).selectAll("circle").remove();l.selectAll(".selected-circle").transition().duration(s).attr("cx",h?Ga:Fa).attr("cy", +h?Fa:Ga);ba?(k=l.select(".event-rects").selectAll(".event-rect").data([0]),Se(k.enter()),k.attr("x",0).attr("y",0).attr("width",q).attr("height",r)):(Wb?(p=function(a,b){var c=Nc(b),d=br&&(r=d,x||(s=(Qa-r*Object.keys(a).length)/2));g>q&&(q=g,x&&(s=(ra-q*Object.keys(a).length)/2))};d=Ia.selectAll(".legend-item").data(c).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+a}).style("cursor","pointer").on("click",function(a){af(a)}).on("mouseover", +function(a){oc(a);f.focus(a)}).on("mouseout",function(){pc();f.revert()});d.append("text").text(function(a){return y(Va[a])?Va[a]:a}).each(function(){u(this.offsetWidth,this.offsetHeight)}).style("pointer-events","none").attr("x",x?h:-200).attr("y",x?-200:m);d.append("rect").attr("class","legend-item-event").style("fill-opacity",0).attr("x",x?l:-200).attr("y",x?-200:p).attr("width",r+14).attr("height",24);d.append("rect").attr("class","legend-item-tile").style("pointer-events","none").style("fill", +function(a){return I(a)}).attr("x",x?h:-200).attr("y",x?-200:n).attr("width",10).attr("height",10);Ia.selectAll("text").data(c).each(function(){u(this.offsetWidth,this.offsetHeight)}).transition().duration(t?250:0).attr("x",h).attr("y",n);Ia.selectAll("rect.legend-item-event").data(c).transition().duration(t?250:0).attr("x",l).attr("y",p);Ia.selectAll("rect.legend-item-tile").data(c).transition().duration(t?250:0).attr("x",e).attr("y",m)}function yb(a){return a?"-"+a.replace(/\./g,"\\."):""}function ja(a){return".target"+ +yb(a)}function qc(a){return Oc(a.id)}function rc(a){return"data"in a&&Oc(a.data.id)}var f={data:{}},rb={},da="_expanded_",ma="_selected_",nc="_included_",ya=d(["bindto"],"#chart"),Pa=d(["size","width"],null),Hb=d(["size","height"],null),gb=d(["padding","left"],null),zc=d(["padding","right"],null),ea=d(["zoom","enabled"],!1),Bd=d(["zoom","extent"],null),Oe=d(["zoom","privileged"],!1),Ie=d(["onenter"],function(){}),Je=d(["onleave"],function(){}),Ue=d(["transition","duration"],350);if(!("data"in fa))throw Error("data is required in config"); +var ua=d(["data","x"],null),ba=d(["data","xs"],null),$b=d(["data","x_format"],"%Y-%m-%d"),je=d(["data","id_converter"],function(a){return a}),Va=d(["data","names"],{}),u=d(["data","groups"],[]),Dc=d(["data","axes"],{}),Mc=d(["data","type"],null),z=d(["data","types"],{}),Ca=d(["data","labels"],{}),Ea=d(["data","order"],null),Cd=d(["data","regions"],{}),bf=d(["data","colors"],{}),ka=d(["data","selection","enabled"],!1),wa=d(["data","selection","grouped"],!1),la=d(["data","selection","isselectable"], +function(){return!0}),Ha=d(["subchart","show"],!1),Eb=Ha?d(["subchart","size","height"],60):0,cf=d(["color","pattern"],null),sa=d(["legend","show"],!0),df=d(["legend","position"],"bottom"),af=d(["legend","item","onclick"],function(){}),h=d(["axis","rotated"],!1),sc=d(["axis","x","type"],"indexed"),Sa=d(["axis","x","categories"],[]),Pd=d(["axis","x","tick","centered"],!1),nb=d(["axis","x","tick","format"],null),Sd=d(["axis","x","tick","culling"],h||"categorized"===sc?!1:!0),Ec=d(["axis","x","tick", +"count"],10),wb=d(["axis","x","default"],null),Ke=d(["axis","x","label"],null),$d=d(["axis","y","max"],null),Yd=d(["axis","y","min"],null),be=d(["axis","y","center"],null),Le=d(["axis","y","label"],null),hb=d(["axis","y","inner"],!1),Rb=d(["axis","y","tick","format"],null),Ta=d(["axis","y","padding"],null),Ld=d(["axis","y","ticks"],10),fb=d(["axis","y2","show"],!1),Zd=d(["axis","y2","max"],null),Xd=d(["axis","y2","min"],null),ae=d(["axis","y2","center"],null),Ib=d(["axis","y2","inner"],!1),Nd=d(["axis", +"y2","tick","format"],null),Ua=d(["axis","y2","padding"],null),Od=d(["axis","y2","ticks"],10),sd=d(["grid","x","show"],!1),Ve=d(["grid","x","type"],"tick"),hc=d(["grid","x","lines"],null),td=d(["grid","y","show"],!1),ic=d(["grid","y","lines"],null),ec=d(["point","show"],!0)?d(["point","r"],2.5):0,Me=d(["point","focus","line","enabled"],!0),jc=d(["point","focus","expand","enabled"],!0),kc=d(["point","focus","expand","r"],jc?4:ec),ab=d(["point","focus","select","r"],8),Te=d(["point","onclick"],function(){}), +Ce=d(["point","onselected"],function(){}),De=d(["point","onunselected"],function(){}),Td=d(["arc","label","format"],function(a,b){return(100*b).toFixed(1)+"%"}),Ne=d(["arc","title"],""),O=d(["regions"],[]),bd=d(["tooltip","enabled"],!0),Dd=d(["tooltip","format","title"],null),Ed=d(["tooltip","format","value"],null),cd=d(["tooltip","contents"],function(a,b,c,d){b=Dd?Dd:b;c=Ed?Ed:c;var e,f,h,l;for(f=0;f"+ +e+""),l=a[f].name,h=c(a[f].value),e+=""+l+""+h+"");return e+""}),Pe=d(["tooltip","init","show"],!1),Ja=d(["tooltip","init","x"],0),vd=d(["tooltip","init","position"],{top:"0px",left:"50px"}),gc=ya.replace("#","")+"-clip",bb="url("+document.URL+"#"+gc+")",C="timeseries"===sc,ia="categorized"===sc,Wb=!C&&(ua||ba),mc=null,cb=!1,lc=!1,I=function(a, +b){var c=[],d=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return d[c.indexOf(b)%d.length]}}(bf,cf),Qd=function(){var a=[[e.time.format("%Y/%-m/%-d"),function(){return!0}],[e.time.format("%-m/%-d"),function(a){return a.getMonth()}],[e.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[e.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[e.time.format("%I %p"), +function(a){return a.getHours()}],[e.time.format("%I:%M"),function(a){return a.getMinutes()}],[e.time.format(":%S"),function(a){return a.getSeconds()}],[e.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),q,Fb,r,ib,Oa,qa,ra,Qa,Ra,jb,Gb,mb,Bc,Cc,Sb,Jb,Kb,Lb,Mb,Nb,Ob,m,D,aa,T,kb,lb,S,Qb,Ac,Pb,Id=h?"left":"bottom",Kd=h?hb?"top":"bottom":hb?"right":"left",Md=h?Ib?"bottom":"top":Ib?"left":"right",Jd=h?"left": +"bottom",K={main:function(){return"translate("+v+","+n+")"},context:function(){return"translate("+Ma+","+Ab+")"},legend:function(){return"translate("+zb+","+tc+")"},y2:function(){return"translate("+(h?0:q)+","+(h?1:0)+")"},x:function(){return"translate(0,"+r+")"},subx:function(){return"translate(0,"+(h?0:ib)+")"},arc:function(){return"translate("+q/2+","+r/2+")"}},x="right"===df,yc=40,xc=20;Sb=e.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var We=function(){var a= +e.svg.line().x(h?function(a){return t(a.id)(a.value)}:Da).y(h?Da:function(a){return t(a.id)(a.value)});return function(b){var c=bc(b.values),d;if(tb(b))return fd(b)?a.interpolate("cardinal"):a.interpolate("linear"),Cd[b.id]?He(c,m,t(b.id),Cd[b.id]):a(c);d=m(c[0].x);b=t(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),Xe=function(){var a;a=h?e.svg.area().x0(function(a){return t(a.id)(0)}).x1(function(a){return t(a.id)(a.value)}).y(Da):e.svg.area().x(Da).y0(function(a){return t(a.id)(0)}).y1(function(a){return t(a.id)(a.value)}); +return function(b){var c=bc(b.values),d;if(Z([b],"area")||Z([b],"area-spline"))return fd(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=m(c[0].x);b=t(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),Ye=function(){var a=e.svg.line().x(h?function(a){return H(a.id)(a.value)}:Wc).y(h?Wc:function(a){return H(a.id)(a.value)});return function(b){var c=bc(b.values);return tb(b)?a(c):"M "+T(c[0].x)+" "+H(b.id)(c[0].value)}}(),J,E=function(){};J=e.svg.brush().on("brush",function(){V({withTransition:!1, +withY:!1,withSubchart:!1,withUpdateXDomain:!0})});J.update=function(){G&&G.select(".x.brush").call(this);return this};J.scale=function(a){return h?this.y(a):this.x(a)};ea&&(E=e.behavior.zoom().on("zoomstart",function(){E.altDomain=e.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ea?Ze:null),E.scale=function(a){return h?this.y(a):this.x(a)},E.orgScaleExtent=function(){var a=Bd?Bd:[1,10];return[a[0],Math.max(Aa()/a[1],a[1])]},E.updateScaleExtent=function(){var a=za(m.orgDomain())/za($),b=this.orgScaleExtent(); +this.scaleExtent([b[0]*a,b[1]*a]);return this});var p,vb,l,G,Ia,U,ub,$,Ad,Xb={};f.focus=function(a){var b=p.selectAll(ja(a)),c=b.filter(qc),b=b.filter(rc);f.revert();f.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(f.data.targets)&&wc(a,!0);oc(a)};f.defocus=function(a){var b=p.selectAll(ja(a)),c=b.filter(qc),b=b.filter(rc);f.revert();c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity", +0.3);B(f.data.targets)&&Ub(a);$e(a)};f.revert=function(a){var b=p.selectAll(ja(a)),c=b.filter(qc),b=b.filter(rc);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(f.data.targets)&&Ub(a);pc()};f.show=function(a){p.selectAll(ja(a)).transition().style("opacity",1)};f.hide=function(a){p.selectAll(ja(a)).transition().style("opacity",0)};f.unzoom=function(){J.clear().update();V({withUpdateXDomain:!0})};f.load=function(a){"function"!== +typeof a.done&&(a.done=function(){});a.xs&&ie(a.xs);"categories"in a&&ia&&(Sa=a.categories,S.categories(Sa));if("cacheIds"in a&&ee(a.cacheIds))db(fe(a.cacheIds),a.done);else if("data"in a)db(Wa(a.data),a.done);else if("url"in a)e.csv(a.url,function(b,c){db(Wa(c),a.done)});else if("rows"in a)db(Wa(Kc(a.rows)),a.done);else if("columns"in a)db(Wa(Lc(a.columns)),a.done);else throw Error("url or rows or columns is required.");};f.unload=function(a){f.data.targets=f.data.targets.filter(function(b){return b.id!== +a});p.selectAll(ja(a)).transition().style("opacity",0).remove();sa&&(p.selectAll(".legend-item"+yb(a)).remove(),xb(f.data.targets));0b.classes.indexOf(a)})});return O};f.data.get=function(a){a=f.data.getAsTarget(a);return y(a)?a.values.map(function(a){return a.value}): +void 0};f.data.getAsTarget=function(a){var b=pb(function(b){return b.id===a});return 0