(()=>{function e(c,e,i,a,d,t){c.onRealtimeAlarmFn=function(e){c.onAlarm=e},c.onRealtimeEventFn=function(e){c.onEvent=e};var n,o=200;function l(){var e,i,t,n;c.child&&c.child.config&&(e=(t=c.child.config).interval,t=t.realtime,e)&&(e!==a.custom.id||t)&&(e===a.custom.id&&t?(t=new Date(c.child.config.dateFrom),t=new Date(c.child.config.dateTo)-t,n=moment(),c.child.config.dateTo=n.toDate(),c.child.config.dateFrom=n.subtract(t,"milliseconds").toDate()):(i=e,(n=_.find(a.intervals,function(e){return e.id===i})||{}).qty&&(c.child.config.dateFrom=moment().subtract(n.qty,n.unit).toDate(),c.child.config.dateTo=moment().toDate())))}function r(){var e=i.height();_.isUndefined(_.get(n,"height"))||(e-=n.height),c.dataPointsGraphHeight=_.max([o,e])}function g(){e(function(){c.$broadcast("dashboardResize")},500)}function s(e,i){c.alarmsEventsTimeline=c.alarmsEventsTimeline||{},c.alarmsEventsTimeline.displayedDateFrom=e,c.alarmsEventsTimeline.displayedDateTo=i}function h(e){return _(e).map(function(e){return e.__target.id}).uniq().value().join(",")}c.isLoading=!1,c.widgetControlsPreset={dashboard:["liveTime","historyTime","autoRefresh","aggregation"],config:["autoRefresh"],view_and_config:["liveTime","historyTime","autoRefresh","aggregation"]},c.onUpdateDates=function(e,i,t){var n,a,o;!1===c.child.config.updateDates||(n=t===d.onDragEnd,a="dashboard"===c.child.config.displayMode,!t&&a&&c.viewRealtime)||(a&&n?(t=e instanceof Date?e.toISOString():e,a=i instanceof Date?i.toISOString():i,o={dateFrom:t,dateTo:a,interval:"custom"},window.dispatchEvent(new CustomEvent("UPDATE_GLOBAL_CONTEXT_HISTORY",{detail:{type:"UPDATE_GLOBAL_CONTEXT_HISTORY",payload:{dateTimeContext:o,isAutoRefreshEnabled:!1,aggregation:c.child.config.aggregation||null,source:"widget"},timestamp:Date.now()}})),c.viewRealtime=!1,c.child.config=Object.assign({},c.child.config,{dateFrom:t,dateTo:a,dateTimeContext:o,isAutoRefreshEnabled:!1,interval:"custom",realtime:!1,refreshOption:"history"})):c.viewRealtime&&n?(c.viewRealtime=!1,c.child.config=Object.assign({},c.child.config,{dateFrom:e,dateTo:i,isAutoRefreshEnabled:!1,realtime:!1})):(c.child.config.dateFrom=e,c.child.config.dateTo=i))},c.onUpdateDisplayedDates=s,c.onLoading=function(e){c.isLoading=e},c.onConfigChange=function(e){var e=e.context,e={dateTimeContext:e.dateTimeContext,refreshOption:e.refreshOption,isAutoRefreshEnabled:e.isAutoRefreshEnabled,refreshInterval:e.refreshInterval,aggregation:e.aggregation},i=Object.assign({},c.child.config,e);e.dateTimeContext&&(i.dateFrom=e.dateTimeContext.dateFrom,i.dateTo=e.dateTimeContext.dateTo,i.interval=e.dateTimeContext.interval);var e="live"===i.refreshOption,t=!1!==i.isAutoRefreshEnabled;i.realtime=e&&t,c.child.config=i,c.viewRealtime=i.realtime},c.onRefresh=function(){l()},c.onLinkedChange=function(){g()},c.onBoxChanged=function(e){c.chartBox=e},c.onTimelinesChartSizeChanged=function(e){n=e,r(),g()},c.dataPointsGraphHeight=i.height(),c.viewRealtime=c.child&&c.child.config&&c.child.config.realtime,c.child&&c.child.config&&(t=t.migrateWidgetConfig(c.child.config),Object.assign(c.child.config,t)),c.dashboardChild=c.dashboardChildForLegacy,c.onRealtimeToggle=function(){c.viewRealtime=!c.viewRealtime},c.recalculate=l,l(),c.$watch("child.config.datapoints",function(e){e=h(e);c.channel=e?"/measurements/".concat(e):""}),c.$watch("child.config.alarmsEventsConfigs",function(e){e=h(e);c.alarmsChannel=e?"/alarms/".concat(e):"",c.eventsChannel=e?"/events/".concat(e):""}),c.$watchCollection(["child.config.dateFrom","child.config.dateTo"],function(){s(c.child.config.dateFrom,c.child.config.dateTo)}),c.$watch("child.config.realtime",function(){c.viewRealtime=c.child&&c.child.config&&c.child.config.realtime}),c.$on("dashboardResize",function(e){(e.targetScope!==c?g:r)()})}e.$inject=["$scope","$timeout","$element","INTERVAL_CONSTANTS","X_AXIS_CONSTANTS","c8yWidgetConfigMigrationService"],angular.module("c8y.cockpit.dataPointExplorer").controller("DataPointWidgetCtrl",e)})();