UNPKG

interpolated-charts

Version:

Configurable d3 v4 charts with interpolation and missing data range

1 lines 24.4 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("d3")):"function"==typeof define&&define.amd?define(["d3"],e):"object"==typeof exports?exports["interpolated-charts"]=e(require("d3")):t["interpolated-charts"]=e(t.d3)}(window,function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)n.d(r,a,function(e){return t[e]}.bind(null,a));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=2)}([function(e,n){e.exports=t},function(t,e,n){},function(t,e,n){"use strict";n.r(e);var r=n(0),a=["#6aedc7","#39c2c9","#ffce00","#ffa71a","#f866b9","#998ce3"];function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:a,e=0,n={};function r(){var n=t[e];return e=(e+1)%t.length,n}return{next:function(t){return{value:arguments.length?n[t]=n[t]||r():r(),done:!1}},schema:function(n){return arguments.length?(t=n,e=0,this):t}}}var i=function(t,e,n,r,a){var o=t.getBBox();if(e<o.x||o.x+o.width<e)return{};var i=0,c=t.getTotalLength();if("number"==typeof a){var u=a-20,s=a+20;t.getPointAtLength(u).x<e&&(i=u),t.getPointAtLength(s).x>e&&(c=s)}for(var l=(i+c)/2,d=0,h=t.getPointAtLength(l);d<n&&Math.abs(h.x-e)>r;)l=(i+c)/2,(h=t.getPointAtLength(l)).x<e?i=l:c=l,d++;return{y:h.y,pathLength:l}};var c=function(){var t,e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;function r(t){e=Date.now(),t()}return{call:function(a){var o=Date.now()-e;if(e&&o<n)return t&&clearTimeout(t),void(t=setTimeout(r.bind(null,a),n-o));r(a)},clear:function(){t&&clearTimeout(t)}}};function u(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var s={chartMouseEnter:"chartMouseEnter",chartMouseLeave:"chartMouseLeave",chartMouseMove:"chartMouseMove",chartMouseClick:"chartMouseClick"};function l(){var t,e,n,a,l,d,h,f,p=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},v=p.width,m=void 0===v?700:v,g=p.height,x=void 0===g?500:g,y=p.margin,M=void 0===y?{top:20,right:30,bottom:40,left:40}:y,b=p.maxTimeRangeDifferenceToDraw,k=void 0===b?1296e5:b,A=p.xAxisTimeFormat,w=p.yAxisValueFormat,T=p.curve,D=void 0===T?r.curveBasis:T,F=p.interpolationMaxIterationCount,C=void 0===F?25:F,j=p.interpolationAccuracy,L=void 0===j?.005:j,S=p.mouseMoveTimeTreshold,E=void 0===S?20:S,O=p.xAxisDateFrom,W=p.xAxisDateTo,B=o(),H=c(E),V=r.dispatch(s.chartMouseEnter,s.chartMouseLeave,s.chartMouseMove,s.chartMouseClick);function P(o){o.each(function(o){e=P.chartWidth(),n=P.chartHeight(),function(e){t||(t=r.select(e).append("svg").classed("line-chart",!0),function(){var e=t.append("g").classed("container-group",!0).attr("transform","translate(".concat(M.left,", ").concat(M.top,")"));e.append("g").classed("grid-container",!0),e.append("g").classed("x-axis-container",!0),e.append("g").classed("y-axis-container",!0),e.append("g").classed("data-lines-container",!0),e.append("g").classed("metadata-container",!0)}());t.attr("width",m).attr("height",x)}(this),function(t){f=t.map(function(t){return t.color=t.color||B.next().value,t.segregatedData=function(t){var e=[];return t.forEach(function(t,n,r){if(0!==n&&n!==r.length-1){var a=function(t,e){return t.date-e.date>k};a(r[n],r[n-1])&&e.push(null),e.push(r[n]),a(r[n+1],r[n])&&e.push(null)}else e.push(r[n])}),e}(t.data),t.chartDiapasons=function(t){if(!Array.isArray(t)||!t.length)return[];var e=[];return t.reduce(function(t,n){return n.date-t.date<k&&e.push({from:t.date,to:n.date}),n}),e}(t.data),t})}(o),function(){var t,a=(t=[]).concat.apply(t,u(f.map(function(t){return t.data}))),o=a.map(function(t){return t.date}),i=a.map(function(t){return t.value}),c=O||r.min(o),s=W||r.max(o),l=r.min(i),p=r.max(i);d=r.scaleTime().domain([c,s]).range([0,e]);var v=.05*(p-l);h=r.scaleLinear().domain([l-v,p+v]).range([n,0])}(),function(){a=r.axisBottom(d),A&&a.tickFormat(A);l=r.axisLeft(h),w&&l.tickFormat(w)}(),t.select(".x-axis-container").append("g").classed("x-axis",!0).attr("transform","translate(0, ".concat(n,")")).call(a),t.select(".y-axis-container").append("g").classed("y-axis",!0).call(l),t.select(".grid-container").selectAll(".horizontal-grid-line").data(h.ticks()).enter().append("line").classed("horizontal-grid-line",!0).attr("x1",0).attr("x2",e).attr("y1",function(t){return h(t)}).attr("y2",function(t){return h(t)}),t.select(".grid-container").selectAll(".vertical-grid-line").data(d.ticks()).enter().append("line").classed("vertical-grid-line",!0).attr("x1",function(t){return d(t)}).attr("x2",function(t){return d(t)}).attr("y1",0).attr("y2",n),function(){var e=r.line().curve(D).defined(function(t){return t}).x(function(t){return d(t.date)}).y(function(t){return h(t.value)}),n=t.select(".data-lines-container").selectAll(".line").data(f.reverse());n.enter().append("path").classed("line",!0).style("stroke-width",2).style("fill","none").merge(n).style("stroke",function(t){return t.color}).attr("d",function(t){return e(t.segregatedData)}),n.exit().remove()}(),function(){var a=t.append("rect").style("fill","white").attr("width",e).attr("height",n).attr("transform","translate(".concat(M.left,", ").concat(M.top,")")).attr("x",0).attr("y",0);a.transition().duration(1e3).ease(r.easeQuadInOut).attr("x",e).on("end",function(){return a.remove()})}(),t.on("mousemove",I),t.on("mouseenter",z),t.on("mouseleave",_),t.on("click",R)})}function I(){var t=r.mouse(this);H.call(function(t){var e=Q.apply(void 0,u(t));V.call(s.chartMouseMove,this,e)}.bind(this,t))}function R(){var t=Q.apply(void 0,u(r.mouse(this)));V.call(s.chartMouseClick,this,t)}function z(){V.call.apply(V,[s.chartMouseEnter].concat(u(r.mouse(this))))}function _(){H.clear(),V.call.apply(V,[s.chartMouseLeave].concat(u(r.mouse(this))))}function Q(r,a){var o=function(t,e,n){return Math.min(Math.max(t,e),n)};r=o(r-M.left,0,e),a=o(a-M.top,0,n);var c=function(e){var n=[],r=d.invert(e);return t.selectAll(".line").each(function(t){var a=t.data.reduce(function(t,e){return!e||Math.abs(t.date-r)<Math.abs(e.date-r)?t:e});if(t.chartDiapasons.some(function(t){return t.from<=r&&r<=t.to})){var o=i(this,e,C,L,Y[t.name]),c=o.y,u=o.pathLength;a.x=d(a.date),a.y=h(a.value),a.interpolatedX=e,a.interpolatedY=c,a.interpolatedDate=d.invert(e),a.interpolatedValue=h.invert(c),a.name=t.name,a.color=t.color,n.push(a),Y[t.name]=u}}),n.reverse()}(r);return{x:r,y:a,selectedDate:d.invert(r),data:c}}var Y={};return P.width=function(t){return arguments.length?(m=t,this):m},P.height=function(t){return arguments.length?(x=t,this):x},P.margin=function(t){return arguments.length?(M=t,this):M},P.on=function(){return V.on.apply(V,arguments),this},P.maxTimeRangeDifferenceToDraw=function(t){return arguments.length?(k=t,this):k},P.xAxisTimeFormat=function(t){return arguments.length?(A=t,this):A},P.yAxisValueFormat=function(t){return arguments.length?(w=t,this):w},P.curve=function(t){return arguments.length?(D=t,this):D},P.interpolationMaxIterationCount=function(t){return arguments.length?(C=t,this):C},P.interpolationAccuracy=function(t){return arguments.length?(L=t,this):L},P.mouseMoveTimeTreshold=function(t){return arguments.length?(E=t,H.clear(),H=c(E),this):E},P.chartHeight=function(){return x-M.top-M.bottom},P.chartWidth=function(){return m-M.left-M.right},P}function d(t,e){return new Date(t.getTime()+e)}function h(t,e){return new Date((t.getTime()+e.getTime())/2)}function f(t,e,n){return Math.min(Math.max(t,e),n)}function p(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var v={chartMouseEnter:"chartMouseEnter",chartMouseLeave:"chartMouseLeave",chartMouseMove:"chartMouseMove",chartMouseClick:"chartMouseClick"};function m(){var t,e,n,a,i,c,u,s,l,m,g,x,y=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},M=y.width,b=void 0===M?700:M,k=y.height,A=void 0===k?500:k,w=y.margin,T=void 0===w?{top:20,right:30,bottom:40,left:40}:w,D=y.setStackWidth,F=void 0===D?function(t,e){return t/e-20}:D,C=y.maxTimeRangeDifferenceToDraw,j=void 0===C?1296e5:C,L=y.stackTimeDiapason,S=void 0===L?864e5:L,E=y.xAxisTimeFormat,O=y.yAxisValueFormat,W=y.xAxisDateFrom,B=y.xAxisDateTo,H=y.yAxisValueFrom,V=y.yAxisValueTo,P=[],I=o(),R=r.dispatch(v.chartMouseEnter,v.chartMouseLeave,v.chartMouseMove,v.chartMouseClick);function z(o){o.each(function(o){e=z.chartWidth(),n=z.chartHeight(),function(e){t||(t=r.select(e).append("svg").classed("bar-chart",!0),function(){var e=t.append("g").classed("container-group",!0).attr("transform","translate(".concat(T.left,", ").concat(T.top,")"));e.append("g").classed("grid-container",!0),e.append("g").classed("x-axis-container",!0),e.append("g").classed("y-axis-container",!0),e.append("g").classed("data-bar-container",!0),e.append("g").classed("metadata-container",!0)}());t.attr("width",b).attr("height",A)}(this),function(t){var n=[].concat.apply([],t.map(function(t){return t.data})).map(function(t){return t.date});s=W||r.min(n);var a=B||r.max(n),o=0;l=s;var i=function(){var e=l;l=d(l,S);var n=h(e,l);o++;var r={dataSum:0,dateFrom:e,dateTo:l,date:n,data:[]},a=t.map(function(t){return{name:t.name,color:t.color||I.next(t.name),data:t.data.filter(function(t){return e<=t.date&&t.date<l})}}).reduce(function(t,r){var a={name:r.name,value:r.data.reduce(function(t,e){return"number"==typeof e.value?t+e.value:t},null),previousValueSum:t.dataSum,color:r.color,date:n,dateFrom:e,dateTo:l};return t.dataSum+=a.value,t.data.push(a),t},r);P.push(a)};do{i()}while(l<a);m=r.max(P.map(function(t){return r.sum(t.data,function(t){return t.value})})),g=F(e,o),x=Math.round(e/o)}(o),function(){c=r.scaleTime().domain([s,l]).range([0,e]);var t=H||0,a="number"==typeof V?V:1.05*m;u=r.scaleLinear().domain([t,a]).range([n,0])}(),function(){a=r.axisBottom(c),E&&a.tickFormat(E);i=r.axisLeft(u),O&&i.tickFormat(O)}(),t.select(".x-axis-container").append("g").classed("x-axis",!0).attr("transform","translate(0, ".concat(n,")")).call(a),t.select(".y-axis-container").append("g").classed("y-axis",!0).call(i),t.select(".grid-container").selectAll(".horizontal-grid-line").data(u.ticks()).enter().append("line").classed("horizontal-grid-line",!0).attr("x1",0).attr("x2",e).attr("y1",function(t){return u(t)}).attr("y2",function(t){return u(t)}),t.select(".grid-container").selectAll(".vertical-grid-line").data(c.ticks()).enter().append("line").classed("vertical-grid-line",!0).attr("x1",function(t){return c(t)}).attr("x2",function(t){return c(t)}).attr("y1",0).attr("y2",n),function(){var e=t.select(".data-bar-container").selectAll(".bar").data(P).enter().append("g");e.append("rect").classed("stack-background",!0).attr("x",function(t){return c(t.date)}).attr("y",0).attr("width",x).attr("height",n).attr("transform","translate(-".concat(x/2,", 0)")),e.selectAll(".stack").data(function(t){return t.data}).enter().append("rect").classed("stack",!0).attr("class","bar").attr("x",function(t){return c(t.date)}).attr("y",function(t){return u(t.value+t.previousValueSum)}).attr("width",g).attr("height",function(t){return Math.max(n-u(t.value),0)}).attr("transform","translate(-".concat(g/2,", 0)")).attr("fill",function(t){return t.color})}(),function(){var a=t.append("rect").style("fill","white").attr("width",e).attr("height",n).attr("transform","translate(".concat(T.left,", ").concat(T.top,")")).attr("x",0).attr("y",0);a.transition().duration(1e3).ease(r.easeQuadInOut).attr("x",e).on("end",function(){return a.remove()})}(),t.on("mousemove",_),t.on("mouseenter",Y),t.on("mouseleave",q),t.on("click",Q)})}function _(){var t=X.apply(void 0,p(r.mouse(this)));R.call(v.chartMouseMove,this,t)}function Q(){var t=X.apply(void 0,p(r.mouse(this)));R.call(v.chartMouseClick,this,t)}function Y(){R.call.apply(R,[v.chartMouseEnter].concat(p(r.mouse(this))))}function q(){R.call.apply(R,[v.chartMouseLeave].concat(p(r.mouse(this))))}function X(t,r){t=f(t-T.left,0,e),r=f(r-T.top,0,n);for(var a=function(t){var e=c.invert(t);return P.find(function(t){return t.dateFrom<=e&&e<=t.dateTo}).data}(t),o=c.invert(t),i=s,u=d(i,S);o>u;)u=d(i=u,S);return{x:t,y:r,selectedDate:o,diapasonStart:i,diapasonEnd:u,data:a}}return z.width=function(t){return arguments.length?(b=t,this):b},z.height=function(t){return arguments.length?(A=t,this):A},z.margin=function(t){return arguments.length?(T=t,this):T},z.setStackWidth=function(t){return arguments.length?(F=t,this):F},z.on=function(){return R.on.apply(R,arguments),this},z.maxTimeRangeDifferenceToDraw=function(t){return arguments.length?(j=t,this):j},z.stackTimeDiapason=function(t){return arguments.length?(S=t,this):S},z.xAxisTimeFormat=function(t){return arguments.length?(E=t,this):E},z.yAxisValueFormat=function(t){return arguments.length?(O=t,this):O},z.xAxisDateFrom=function(t){return arguments.length?(W=t,this):W},z.xAxisDateTo=function(t){return arguments.length?(B=t,this):B},z.yAxisValueFrom=function(t){return arguments.length?(H=t,this):H},z.curve=function(t){return arguments.length?(V=t,this):V},z.chartHeight=function(){return A-T.top-T.bottom},z.chartWidth=function(){return b-T.left-T.right},z}function g(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var x={chartMouseEnter:"chartMouseEnter",chartMouseLeave:"chartMouseLeave",chartMouseMove:"chartMouseMove",chartMouseClick:"chartMouseClick"};function y(){var t,e,n,a,i,u,s,l=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},f=l.width,p=void 0===f?700:f,v=l.height,m=void 0===v?120:v,y=l.margin,M=void 0===y?{top:20,right:30,bottom:40,left:40}:y,b=l.marginBetweenStacks,k=void 0===b?0:b,A=l.backgroundColor,w=void 0===A?"#CCCCCC":A,T=l.maxTimeRangeDifferenceToDraw,D=void 0===T?1296e5:T,F=l.xAxisTimeFormat,C=l.mouseMoveTimeTreshold,j=void 0===C?20:C,L=l.xAxisDateFrom,S=l.xAxisDateTo,E=o(),O=c(j),W=r.dispatch(x.chartMouseEnter,x.chartMouseLeave,x.chartMouseMove,x.chartMouseClick);function B(o){o.each(function(o){e=B.chartWidth(),n=B.chartHeight(),function(e){t||(t=r.select(e).append("svg").classed("stack-bar",!0),function(){var e=t.append("g").classed("container-group",!0).attr("transform","translate(".concat(M.left,", ").concat(M.top,")"));e.append("g").classed("background-container",!0),e.append("g").classed("x-axis-container",!0),e.append("g").classed("data-stacks-container",!0),e.append("g").classed("metadata-container",!0)}());t.attr("width",p).attr("height",m)}(this),function(t){var e=t.length;a=(n-(e-1)*k)/e,s=t.map(function(t){return function(t){var e=t.data,n=t.backgroundColor,a=t.name;if(!Array.isArray(e)||!e.length)return{chartDiapasons:[],backgroundColor:n,name:a};var o=function(t,e,n){return{color:t.color||E.next("".concat(t.name,"-").concat(t.value)).value,value:t.value,from:e||t.date,to:n||t.date}},i=e.sort(function(t,e){return t.date-e.date}),c=[],u=o(i[0],d(i[0].date,-D),i[0].date);c.push(u),i.length>1&&i.reduce(function(t,e){var n=h(t.date,e.date),a=r.min([d(t.date,D),n]),i=r.max([d(e.date,-D),n]),u=o(t,t.date,a),s=o(e,i,e.date);return c.push(u,s),e});var s=i[i.length-1],l=o(s,s.date,d(s.date,D));return c.push(l),{chartDiapasons:c,backgroundColor:n,name:a}}(t)})}(o),function(){var t=[].concat.apply([],s.map(function(t){return t.chartDiapasons}).filter(function(t){return t})).map(function(t){return[t.from,t.to]}),n=[].concat.apply([],t),a=L||r.min(n),o=S||r.max(n);u=r.scaleTime().domain([a,o]).range([0,e])}(),i=r.axisBottom(u),F&&i.tickFormat(F),t.select(".background-container").append("rect").attr("x",0).attr("y",0).attr("width",e).attr("height",n).attr("fill",w).classed("background",!0),t.select(".x-axis-container").append("g").classed("x-axis",!0).attr("transform","translate(0, ".concat(n,")")).call(i),function(){var n=t.select(".data-stacks-container").selectAll(".stack-holder").data(s),r=function(t){return R(Math.trunc(u(t)),0,e)},o=n.enter().append("g").classed("stack-holder",!0).merge(n).attr("transform",function(t,e){return"translate(0, ".concat(e*(a+k),")")}).attr("width",e).attr("height",a);o.append("rect").attr("x",0).attr("y",0).attr("width",e).attr("height",a).style("fill",function(t){return t.backgroundColor}),o.selectAll(".stack-holder").data(function(t){return t.chartDiapasons}).enter().append("rect").classed("stack-diapason",!0).attr("x",function(t){return r(t.from)}).attr("y",function(){return 0}).style("fill",function(t){return t.color}).attr("width",function(t){return R(Math.ceil(u(t.to)-u(t.from)),0,e-r(t.from))}).attr("height",a),n.exit().remove()}(),function(){var a=t.append("rect").style("fill","white").attr("width",e).attr("height",n).attr("transform","translate(".concat(M.left,", ").concat(M.top,")")).attr("x",0).attr("y",0);a.transition().duration(1e3).ease(r.easeQuadInOut).attr("x",e).on("end",function(){return a.remove()})}(),t.on("mousemove",H),t.on("mouseenter",P),t.on("mouseleave",I),t.on("click",V)})}function H(){var t=r.mouse(this);O.call(function(t){var e=z.apply(void 0,g(t));W.call(x.chartMouseMove,this,e)}.bind(this,t))}function V(){var t=z.apply(void 0,g(r.mouse(this)));W.call(x.chartMouseClick,this,t)}function P(){W.call.apply(W,[x.chartMouseEnter].concat(g(r.mouse(this))))}function I(){O.clear(),W.call.apply(W,[x.chartMouseLeave].concat(g(r.mouse(this))))}function R(t,e,n){return Math.min(Math.max(t,e),n)}function z(t,r){t=R(t-M.left,0,e),r=R(r-M.top,0,n);var a=function(t){var e=u.invert(t),n=[];return s.forEach(function(t){var r={name:t.name,interpolatedDate:e},a=t.chartDiapasons.find(function(t){return t.from<=e&&e<=t.to});a&&Object.assign(r,a),n.push(r)}),n}(t);return{x:t,y:r,selectedDate:u.invert(t),data:a}}return B.width=function(t){return arguments.length?(p=t,this):p},B.height=function(t){return arguments.length?(m=t,this):m},B.margin=function(t){return arguments.length?(M=t,this):M},B.marginBetweenStacks=function(t){return arguments.length?(k=t,this):k},B.backgroundColor=function(t){return arguments.length?(w=t,this):w},B.on=function(){return W.on.apply(W,arguments),this},B.maxTimeRangeDifferenceToDraw=function(t){return arguments.length?(D=t,this):D},B.xAxisTimeFormat=function(t){return arguments.length?(F=t,this):F},B.mouseMoveTimeTreshold=function(t){return arguments.length?(j=t,O.clear(),O=c(j),this):j},B.chartHeight=function(){return m-M.top-M.bottom},B.chartWidth=function(){return p-M.left-M.right},B.xAxisDateFrom=function(t){return arguments.length?(L=t,this):L},B.xAxisDateTo=function(t){return arguments.length?(S=t,this):S},B}var M=function(){var t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).height,n=void 0===e?440:e;function a(e){e.each(function(){!function(e){t||(t=r.select(e).append("g").classed("divider-container",!0)),t.append("line").classed("divider",!0).attr("y1",0).attr("y2",n)}(this)})}return a.remove=function(){return t.style("display","none"),this},a.show=function(){return t.style("display","block"),this},a.update=function(e){var n=e.x;return t.select(".divider").attr("x1",n).attr("x2",n),this},a.height=function(t){return arguments.length?(n=t,this):n},a};var b=function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.cx,a=void 0===n?function(t){return t.interpolatedX||t.x}:n,o=e.cy,i=void 0===o?function(t){return t.interpolatedY||t.y}:o,c=e.radius,u=void 0===c?function(){return 5}:c,s=e.fill,l=void 0===s?function(){return"white"}:s,d=e.stroke,h=void 0===d?function(t){return t.color||"red"}:d,f=e.strokeWidth,p=void 0===f?function(){return 2}:f,v=e.sort,m=void 0===v?function(){return 0}:v;function g(e){e.each(function(){!function(e){t||(t=r.select(e).append("g").classed("marker-container",!0))}(this)})}return g.remove=function(){return t.selectAll(".marker").remove(),this},g.show=function(e){var n=e.data,r=t.selectAll(".marker").data(n.slice().sort(m).reverse());return r.enter().append("circle").classed("marker",!0).merge(r).attr("cx",function(t){return a(t)}).attr("cy",function(t){return i(t)}).attr("r",function(t){return u(t)}).style("fill",function(t){return l(t)}).style("stroke",function(t){return h(t)}).style("stroke-width",function(t){return p(t)}),r.exit().remove(),this},g.cx=function(t){return arguments.length?(a=t,this):a},g.cy=function(t){return arguments.length?(i=t,this):i},g.radius=function(t){return arguments.length?(u=t,this):u},g.fill=function(t){return arguments.length?(l=t,this):l},g.stroke=function(t){return arguments.length?(h=t,this):h},g.strokeWidth=function(t){return arguments.length?(p=t,this):p},g.sort=function(t){return arguments.length?(m=t,this):m},g};var k=function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.chartHeight,a=void 0===n?440:n,o=e.chartWidth,i=void 0===o?700:o,c=e.tooltipWidth,u=void 0===c?220:c,s=e.horizontalMouseMargin,l=void 0===s?40:s,d=e.verticalBorderMargin,h=void 0===d?10:d,f=e.headerFormatter,p=void 0===f?function(t){return r.timeFormat("%Y-%d-%m %H:%M:%S")(t)}:f,v=e.topicFormatter,m=void 0===v?function(t){return t.name}:v,g=e.valueFormatter,x=void 0===g?function(t){return r.format(".1f")(t.interpolatedValue)}:g,y=e.sort,M=void 0===y?function(){return 0}:y;function b(e){e.each(function(){!function(e){t||(t=r.select(e).append("g").classed("tooltip-container",!0))}(this)})}return b.remove=function(){return t.select(".tooltip").remove(),this},b.show=function(e){var n=e.x,r=e.y,o=e.selectedDate,c=e.data;b.remove(),t.append("g").classed("tooltip",!0).append("rect").attr("width",u);var s=function(t,e,n){var r=t.append("xhtml:div").append("div").classed("tooltip-container",!0);r.append("div").classed("tooltip-header",!0).append("p").html(p(e,n)),r.append("hr");var a=r.selectAll(".topic").data(n.slice().sort(M)).enter().append("div").classed("topic",!0);a.append("div").classed("circle",!0).style("background-color",function(t){return t.color}),a.append("div").classed("topic-name",!0).html(function(t){return m(t)}),a.append("div").classed("topic-value",!0).html(function(t){return x(t)});var o=r.node().getBoundingClientRect().height;return{div:r,divHeight:o}}(t.select(".tooltip").append("foreignObject").classed("foreign-object",!0).attr("width",u),o,c).divHeight;t.select(".tooltip foreignObject").attr("height",s),t.select(".tooltip rect").attr("height",s);var d=n>i/2?n-u-l:n+l,f=r+s>a-h?a-s-h:r;return t.select(".tooltip").attr("transform","translate(".concat(d,", ").concat(f,")")),this},b.chartHeight=function(t){return arguments.length?(a=t,this):a},b.chartWidth=function(t){return arguments.length?(i=t,this):i},b.tooltipWidth=function(t){return arguments.length?(u=t,this):u},b.horizontalMouseMargin=function(t){return arguments.length?(l=t,this):l},b.verticalBorderMargin=function(t){return arguments.length?(h=t,this):h},b.headerFormatter=function(t){return arguments.length?(p=t,this):p},b.topicFormatter=function(t){return arguments.length?(m=t,this):m},b.valueFormatter=function(t){return arguments.length?(x=t,this):x},b.sort=function(t){return arguments.length?(M=t,this):M},b};n(1);n.d(e,"line",function(){return l}),n.d(e,"bar",function(){return m}),n.d(e,"stackBar",function(){return y}),n.d(e,"chartEvents",function(){return s}),n.d(e,"verticalDivider",function(){return M}),n.d(e,"markers",function(){return b}),n.d(e,"tooltip",function(){return k})}])});