(()=>{function t(e,s,t,n){var r=t.getD3Locales().timeFormat.multi([[".%L",function(t){return t.getMilliseconds()}],[":%S",function(t){return t.getSeconds()}],["%H:%M",function(t){return t.getMinutes()}],["%H:%M",function(t){return t.getHours()}],["%a %d",function(t){return t.getDay()&&1!==t.getDate()}],["%b %d",function(t){return 1!==t.getDate()}],["%B",function(t){return t.getMonth()}],["%Y",function(){return!0}]]);function a(t){(this.chart=t).addItem(this)}return a.prototype={scale:function(){var t=this,e=t.chart.box();return d3.time.scale().domain([t._from,t._to]).range([e.rangeMin,e.rangeMax])},axis:function(){return d3.svg.axis().scale(this.scale()).orient("bottom").ticks(6).tickFormat(r)},canRender:function(){return!(!this._from||!this._to)},updateDates:function(t,e,n){var r=this,t=moment(t).milliseconds(0),e=moment(e).milliseconds(0);t.isSame(r._from)&&e.isSame(r._to)||(r._from=t.toDate(),r._to=e.toDate(),n&&r.onUpdateDates&&r.onUpdateDates(r._from,r._to),r._xDragStart)||r.chart.render()},getDebouncePreference:function(){var t=this,e=moment(t._to).diff(moment(t._from),"seconds");return t.debounceTime!==e?{debounceTime:(t.debounceTime=e)||200,reset:!0}:{debounceTime:e||200,reset:!1}},render:function(){var t,e=this,n=e.axis(),r=e.el,a=e.chart.box(),o=e.chart.margins,a=a.height-o.b;r||(t=e.chart.svg,e.el=t.append("g").attr({class:"xaxis axis",transform:s.translate(o.l,a)}).style({"pointer-events":"all",cursor:"ew-resize"}),(r=e.el).boxHover=r.append("rect").attr({class:"recthover",height:19,fill:"rgba(255,255,255,0.01)",transform:s.translate(o.l,0)}),e.drag=d3.behavior.drag(),t=e.drag,r.call(t),r.boxHover.call(t),e.addEvents()),r.boxHover.attr("width",function(){return e.chart.box().axisXwidth}),e.canRender()&&r.call(n).attr({transform:s.translate(o.l,a)})},onMouseDown:function(){var e=this;return function(){d3.event.sourceEvent.stopPropagation(),e._scale=e.scale();var t=e._scale;e._xDragStart=t.invert(d3.mouse(e.el.node())[0]),e.__from=e._from,e.__to=e._to,e.el.select("path").style("stroke","#CCC")}},onDragEnd:function(){var t=this;return function(){d3.event.sourceEvent.stopPropagation(),_.isUndefined(t._xDragStart)||(t.chart.render(),t.el.select("path").style("stroke",""),t.onUpdateDates&&(t.onUpdateDates(t._from,t._to,n.onDragEnd),e.$apply())),delete t._xDragStart}},updateScaleOnDrag:function(t){var e=this,n=e._scale,n=moment(n.invert(t)).diff(e._xDragStart);e.updateDates(moment(e.__from).subtract(n,"ms"),moment(e.__to).subtract(n,"ms")),e.render()},onDrag:function(){var e=this;return function(){d3.event.sourceEvent.stopPropagation();var t=e.el.node();_.isUndefined(e._xDragStart)||e.updateScaleOnDrag(d3.mouse(t)[0])}},addEvents:function(){this.drag.on("dragstart",this.onMouseDown()).on("drag",this.onDrag()).on("dragend",this.onDragEnd())}},a}t.$inject=["$rootScope","c8yChartCommon","c8yLocales","X_AXIS_CONSTANTS"],angular.module("c8y.core.measurements2").factory("c8yAxisX",t).constant("X_AXIS_CONSTANTS",{onDragEnd:"onDragEnd"})})();