(()=>{function t(t,o,e){var r,i,l,c,d,s,m,h,u,p,g,n,a,f=this,v={},x={top:20,right:0,bottom:10,left:0},y=30,D="10px",b=10,A=100,F=!1,T=!1,w=function(){g=g||setTimeout(function(){var t,e,n,a;g=null,F&&(d=d||o.find("svg")[0],s=s||d3.select("body").append("div").classed("c8y-timelines-chart-tooltip",!0).style("opacity",0),n=0<c.length?$(d).width()-x.left-x.right:0,a=0<c.length?c.length*y:0,t=0<c.length?n+x.left+x.right:0,e=0<c.length?a+x.top+x.bottom:0,t===v.totalWidth&&e===v.totalHeight||f.onSizeChanged({$size:{width:t,height:e}}),v={chartWidth:0<n?n:0,chartHeight:0<a?a:0,totalWidth:0<t?t:0,totalHeight:0<e?e:0},d3.select(d).attr({width:v.totalWidth,height:v.totalHeight}),m=m||d3.select(d).append("defs").append("svg:clipPath").attr("id","chart-clip-".concat(r)).append("svg:rect").attr("id","clip-rect".concat(r)).attr("x",0).attr("y",-15).attr("width",v.chartWidth).attr("height",v.chartHeight),d3.select("#clip-rect".concat(r)).attr("width",v.chartWidth).attr("height",v.chartHeight),(h=h||d3.select(d).append("g").classed("chart",!0)).attr("transform",C(x.left,x.top)),u=d3.time.scale().domain([moment(i).toDate(),moment(l).toDate()]).range([0,v.chartWidth]),p=d3.svg.axis().scale(u).orient("bottom").ticks(0),n=h.selectAll("g.timeline").data(c),(a=n.enter().append("g").classed("timeline",!0)).append("g").classed("axis",!0),a.append("text").classed("axis-label",!0).attr("text-anchor","start").attr("x",0).attr("y",0).attr("transform",C(0,-10)).style("font-size",D),n.exit().remove(),h.selectAll("text.axis-label").data(c).text(function(t){return t.label}),h.selectAll("g.timeline").attr("transform",function(t,e){return C(0,e*y)}),h.selectAll("g.axis").call(p),h.selectAll("g.timeline").data(c).each(function(t){var e,n,a;e=this,n=t,T&&d3.select(e).selectAll("g.event").remove(),t=d3.select(e).selectAll("g.event").data(function(){return n.events}),(a=d3.select(e).selectAll(".diamond").data(function(){return n.events})).attr("d",d3.svg.symbol().type("diamond").size(function(){return A})).attr("transform",function(t){return C(u(moment(t.date).toDate()),0)}).attr("fill",function(){return n.color}),a.exit().remove(),(a=d3.select(e).selectAll(".rect").data(function(){return n.events})).attr("x",function(t){return u(moment(t.dateFrom).toDate())}).attr("width",function(t){return _.max([1,u(moment(i).add(moment(t.dateTo).diff(t.dateFrom)).toDate())])}).style("fill",function(){return n.color}),a.exit().remove(),t.enter().append("g").classed("event",!0).attr("clip-path","url(#chart-clip-".concat(r,")")).each(function(t){t.date?d3.select(this).append("g").append("path").attr("class","diamond").attr("d",d3.svg.symbol().type("diamond").size(function(){return A})).attr("transform",C(u(moment(t.date).toDate()),0)).attr("fill",function(){return n.color}):d3.select(this).append("rect").attr("class","rect").attr("x",function(t){return u(moment(t.dateFrom).toDate())}).attr("y",0).attr("width",function(t){return _.max([1,u(moment(i).add(moment(t.dateTo).diff(t.dateFrom)).toDate())])}).attr("height",b).attr("transform",C(0,-5)).style("fill",function(){return n.color})}).on("mouseover",function(t){s.transition().duration(200).style("opacity",.9);var e=s.html(_.isFunction(t.tooltip)?t.tooltip():t.tooltip).node().getBoundingClientRect().width,n=h.select("g.timeline").node().getBoundingClientRect().width;s.html(_.isFunction(t.tooltip)?t.tooltip():t.tooltip).style("left","".concat(n-e<d3.event.offsetX?d3.event.pageX-e:d3.event.pageX,"px")).style("top","".concat(d3.event.pageY-28,"px"))}).on("mouseout",function(){s.transition().duration(500).style("opacity",0)})}),T=!1)},300)};function C(t,e){return"translate(".concat(t,", ").concat(e,")")}e.has("ngZone")&&(n=e.get("ngZone"),a=w,w=function(){return n.runOutsideAngular(a)}),_.assign(f,{$onInit:function(){r=String(Math.random()).substr(2),i=_.cloneDeep(f.dateFrom),l=_.cloneDeep(f.dateTo),c=_.cloneDeep(f.data),t.$on("c8yTimelinesChart::render",w),t.$on("dashboardResize",w),window.addEventListener("resize",w),F=!0,w()},$onChanges:function(t){t.dateFrom&&(i=_.cloneDeep(t.dateFrom.currentValue));t.dateTo&&(l=_.cloneDeep(t.dateTo.currentValue));t.data&&(c=_.cloneDeep(t.data.currentValue));t.chartBox&&(t=t.chartBox.currentValue,_.assign(x,{left:t&&t.leftSpace||0,right:t&&t.rightSpace||0}));w()},$doCheck:function(){var t=!1;_.isEqual(c,f.data)||(c=_.cloneDeep(f.data),t=T=!0);moment(i).isSame(f.dateFrom)||(i=_.cloneDeep(f.dateFrom),t=!0);moment(l).isSame(f.dateTo)||(l=_.cloneDeep(f.dateTo),t=!0);t&&w()},$onDestroy:function(){s&&s.remove()}})}t.$inject=["$scope","$element","$injector"],angular.module("c8y.ui").component("c8yTimelinesChart",{bindings:{dateFrom:"<",dateTo:"<",data:"<timelines",chartBox:"<",onSizeChanged:"&"},templateUrl:":::PLUGIN_PATH:::/ui/components/timelinesChart.html",controller:t,controllerAs:"vm"})})();