/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.ml_bundle_jsonpfunction=window.ml_bundle_jsonpfunction||[]).push([[16],{136:function(e,t,n){"use strict";n.d(t,"c",(function(){return h})),n.d(t,"a",(function(){return j})),n.d(t,"b",(function(){return S}));var i=n(7),a=n(39),o=n.n(a),s=n(46),r=n.n(s);const{duration:c}=o.a;var u=n(41),l=n(13),d=n(69),b=n(43);const m=r.a.unitsDesc,f=m.indexOf("w"),p=function(){const e=[[c(500,"ms"),c(100,"ms")],[c(5,"second"),c(1,"second")],[c(10,"second"),c(5,"second")],[c(15,"second"),c(10,"second")],[c(30,"second"),c(15,"second")],[c(1,"minute"),c(30,"second")],[c(5,"minute"),c(1,"minute")],[c(10,"minute"),c(5,"minute")],[c(15,"minute"),c(10,"minute")],[c(30,"minute"),c(10,"minute")],[c(1,"hour"),c(30,"minute")],[c(2,"hour"),c(1,"hour")],[c(4,"hour"),c(2,"hour")],[c(6,"hour"),c(4,"hour")],[c(8,"hour"),c(6,"hour")],[c(12,"hour"),c(8,"hour")],[c(24,"hour"),c(12,"hour")],[c(2,"d"),c(1,"d")],[c(4,"d"),c(2,"d")],[c(1,"week"),c(4,"d")],[c(1,"month"),c(1,"week")],[c(1,"year"),c(1,"month")],[1/0,c(1,"year")]].slice(0).reverse();function t(e,t,n){return function(i,a){const s=function(i,a){const s=a/i;let r;for(let i=0;in){if(e===1/0)return t;const i=e.asMilliseconds(),a=t.asMilliseconds();return Math.abs(i-n)<=Math.abs(a)?e:t}}),!0),lessThan:t(e,(function(e,t,n){if(t=1&&Math.floor(i)===i){if(t<=f)continue;return{value:i,unit:n,expression:i+n}}}const t=e.as("ms");return{value:t,unit:"ms",expression:t+"ms"}}(e);e.esValue=n.value,e.esUnit=n.unit,e.expression=n.expression,e.overflow=t>e&&o.a.duration(e-t);const i=o.a.normalizeUnits(n.unit);return 1===n.value?e.description=i:e.description=`${n.value} ${i}s`,e}function g(e){return e&&"isValid"in e&&e.isValid()}function S(e,t,n=!1){const i=t.asMilliseconds(),a=Math.floor(e.min.valueOf()/i)*i;let s=Math.ceil(e.max.valueOf()/i)*i;return!1===n&&(s-=1),{min:o()(a),max:o()(s)}}j.prototype.setBarTarget=function(e){this.barTarget=e},j.prototype.setMaxBars=function(e){this.maxBars=e},j.prototype.setBounds=function(e){if(!e)return this.clearBounds();let t;t=Object(i.isPlainObject)(e)?[e.min,e.max]:Array.isArray(e)?e:[];const n=Object(i.sortBy)(t.map(Object(i.ary)(o.a,1)),Number);if(2!==n.length||!n.every(g))throw this.clearBounds(),new Error("invalid bounds set: "+e);if(this._lb=n.shift(),this._ub=n.pop(),this.getDuration().asSeconds()<0)throw new TypeError("Intervals must be positive")},j.prototype.clearBounds=function(){this._lb=this._ub=null},j.prototype.hasBounds=function(){return g(this._ub)&&g(this._lb)},j.prototype.getBounds=function(){if(this.hasBounds())return{min:this._lb,max:this._ub}},j.prototype.getDuration=function(){if(this.hasBounds())return o.a.duration(this._ub-this._lb,"ms")},j.prototype.setInterval=function(e){this.originalInterval=e;let t=e;if(t&&"auto"!==t){if(Object(i.isString)(t)&&(e=t,t=Object(u.a)(t),0==+t&&(t=null)),!o.a.isDuration(t))throw new TypeError('"'+e+'" is not a valid interval.');this._i=t}else this._i="auto"},j.prototype.getInterval=function(){const e=this,t=e.getDuration();return O(function(n){if(!e.hasBounds())return n;const a=e.maxBars;let o;return t/n>a?(o=p.lessThan(a,t),+o==+n?n:(O(n,t),Object(i.assign)(o,{preScaled:n,scale:n/o,scaled:!0}))):n}(function(){const n=e._i;return o.a.isDuration(n)?n:p.near(e.barTarget,t)}()),t)},j.prototype.getIntervalToNearestMultiple=function(e){const t=this.getInterval(),n=t.asSeconds(),i=n%e;if(0===i)return t;let a=i>e/2?n+e-i:n-i;a=0===a?e:a;const s=o.a.duration(a,"seconds");O(s,this.getDuration());const r=t.preScaled;return void 0!==r&&r=0;n--){const i=t[n];if(!i[0]||e>=o.a.duration(i[0]))return i[1]}return this._timeBucketsConfig.dateFormat},j.prototype.getScaledDateFormatter=function(){return new(Object(l.e)().getType(b.FIELD_FORMAT_IDS.DATE))({pattern:this.getScaledDateFormat()},this._timeBucketsConfig)}},256:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var i=n(29),a=n.n(i),o=n(11),s=n(2),r=n(21);function c(e,t,n,i){const c=a()(t.pipe(Object(o.map)((e=>e.executionContext)))),u=Object(s.useMemo)((()=>{const e={type:"visualization",name:n,id:i};return{...c,child:e}}),[c,i]);Object(r.useExecutionContext)(e,u)}},257:function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(67),a=n(69);function o(e,t,n){const o=null!=e?e:[],s=null!=t?t:Object(a.getDefaultQuery)(),r=["kuery"===s.language?Object(i.toElasticsearchQuery)(Object(i.fromKueryExpression)(s.query)):Object(i.luceneStringToDsl)(s.query)],c=[];for(const e of o){if(e.meta.disabled||void 0!==n&&e.meta.controlledBy===n)continue;const{meta:{negate:t,type:i,key:a}}=e;let o=e.query;void 0===o&&"exists"===i&&(o={exists:{field:a}}),o&&(t?c.push(o):r.push(o))}return{bool:{must:r,must_not:c}}}},258:function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(10),a=n(11),o=n(7),s=n(41);function r(e,t,n){return e.pipe(Object(a.pluck)("jobIds"),Object(a.distinctUntilChanged)(o.isEqual),Object(a.switchMap)((e=>t.getJobs$(e))),Object(a.map)((e=>e.map((e=>{var t;const n=Object(s.a)(e.analysis_config.bucket_span);return{id:e.job_id,selected:!0,bucketSpanSeconds:n.asSeconds(),modelPlotEnabled:!0===(null===(t=e.model_plot_config)||void 0===t?void 0:t.enabled)}})))),Object(a.catchError)((e=>{var t;return n(null!==(t=e.body)&&void 0!==t?t:e),Object(i.of)(void 0)})))}},685:function(e,t,n){"use strict";n.r(t),n.d(t,"EmbeddableSwimLaneContainer",(function(){return T}));var i=n(2),a=n(28),o=n(15),s=n(4),r=n(252),c=n(256),u=n(10),l=n(11),d=n(69),b=n(72),m=n(136),f=n(117),p=n(192),h=n(257),j=n(59),O=n(258);var g=n(187),S=n(123),v={name:"hdjpxu",styles:"width:100%;padding:8px"},_={name:"1d3w5wq",styles:"width:100%"},y={name:"1hcx8jb",styles:"padding:0"};const T=({id:e,embeddableContext:t,embeddableInput$:n,services:T,refresh:E,onInputChange:x,onOutputChange:w,onRenderComplete:M,onLoading:I,onError:B})=>{Object(c.a)(T[0].executionContext,n,S.b,e);const[A,R]=Object(i.useState)(0),[C,k]=Object(i.useState)(1),[{},{uiActions:D,charts:G}]=T,[F,L]=Object(i.useState)(),[P,U,N,H,W,q,V]=function(e,t,n,a,o,s,r){const[{uiSettings:c},,{anomalyTimelineService:g,anomalyDetectorService:S}]=a,[v,_]=Object(i.useState)(),[y,T]=Object(i.useState)(),[E,x]=Object(i.useState)(),[w,M]=Object(i.useState)(),[I,B]=Object(i.useState)(!1),A=Object(i.useMemo)((()=>new u.Subject),[]),R=Object(i.useMemo)((()=>Object(O.a)(e,S,x).pipe(Object(l.shareReplay)(1))),[]),C=Object(i.useMemo)((()=>Object(u.combineLatest)([R,A,e.pipe(Object(l.pluck)("timeRange"))]).pipe(Object(l.skipWhile)((([e,t])=>!Array.isArray(e)||!t)),Object(l.tap)((([,,e])=>{g.setTimeRange(e)})),Object(l.map)((([e,t])=>g.getSwimlaneBucketInterval(e,t))),Object(l.distinctUntilChanged)(((e,t)=>e.asSeconds()===t.asSeconds())))),[]),k=Object(i.useMemo)((()=>new u.Subject),[]),D=Object(i.useMemo)((()=>new u.Subject),[]),G=Object(i.useMemo)((()=>new m.a({"histogram:maxBars":c.get(d.UI_SETTINGS.HISTOGRAM_MAX_BARS),"histogram:barTarget":c.get(d.UI_SETTINGS.HISTOGRAM_BAR_TARGET),dateFormat:c.get("dateFormat"),"dateFormat:scaled":c.get("dateFormat:scaled")})),[]);return Object(i.useEffect)((()=>{const i=Object(u.combineLatest)([R,e,C,k,D.pipe(Object(l.startWith)(void 0),Object(l.distinctUntilChanged)(((e,t)=>void 0===e&&t===f.i))),n.pipe(Object(l.startWith)(null))]).pipe(Object(l.tap)(B.bind(null,!0)),Object(l.debounceTime)(500),Object(l.tap)((()=>{r.onLoading()})),Object(l.switchMap)((([e,n,i,a,o])=>{if(!e)return Object(u.of)(void 0);const{viewBy:s,swimlaneType:r,perPage:c,filters:d,query:m,viewMode:O}=n;let S;y||T(r);try{(d||m)&&(S=Object(h.a)(d,m,j.CONTROLLED_BY_SWIM_LANE_FILTER))}catch(e){return x(e),Object(u.of)(void 0)}return Object(u.from)(g.loadOverallData(e,void 0,i)).pipe(Object(l.switchMap)((n=>{const{earliest:d,latest:m}=n;var h;return n&&r===f.h.VIEW_BY?(void 0===o&&M(null!=c?c:f.i),O===b.ViewMode.EDIT&&o!==c&&t({perPage:o}),Object(u.from)(g.loadViewBySwimlane([],{earliest:d,latest:m},e,s,Object(p.c)(v)?v.cardinality:f.a,null!==(h=null!=o?o:c)&&void 0!==h?h:f.i,a,void 0,S,i)).pipe(Object(l.map)((e=>({...e,earliest:d,latest:m}))))):Object(u.of)(n)})))})),Object(l.catchError)((e=>(x(e.body),Object(u.of)(void 0))))).subscribe((e=>{void 0!==e&&(x(null),_(e),B(!1))}));return()=>{i.unsubscribe()}}),[]),Object(i.useEffect)((()=>{k.next(s)}),[s]),Object(i.useEffect)((()=>{void 0!==w&&D.next(w)}),[w]),Object(i.useEffect)((()=>{A.next(o)}),[o]),Object(i.useEffect)((()=>{E&&r.onError(E)}),[E]),Object(i.useEffect)((()=>{v&&r.onRenderComplete()}),[v]),[y,v,null!=w?w:f.i,M,G,I,E]}(n,x,E,T,A,C,{onRenderComplete:M,onError:B,onLoading:I});Object(i.useEffect)((()=>{w({perPage:N,fromPage:C,interval:null==U?void 0:U.interval})}),[N,C,U]);const $=Object(i.useCallback)((e=>{L(e),e&&D.getTrigger(g.a).exec({embeddable:t,data:e,updateCallback:L.bind(null,void 0)})}),[U,N,C,L]);return V?Object(s.jsx)(a.EuiCallOut,{title:Object(s.jsx)(o.FormattedMessage,{id:"xpack.ml.swimlaneEmbeddable.errorMessage",defaultMessage:"Unable to load the ML swim lane data"}),color:"danger",iconType:"warning",css:_},Object(s.jsx)("p",null,V.message)):Object(s.jsx)("div",{css:v,"data-test-subj":"mlAnomalySwimlaneEmbeddableWrapper"},Object(s.jsx)(p.b,{id:e,"data-test-subj":`mlSwimLaneEmbeddable_${t.id}`,timeBuckets:W,swimlaneData:U,swimlaneType:P,fromPage:C,perPage:N,swimlaneLimit:Object(p.c)(U)?U.cardinality:void 0,onResize:R,selection:F,onCellsSelection:$,onPaginationChange:e=>{e.fromPage&&k(e.fromPage),e.perPage&&(k(1),H(e.perPage))},isLoading:q,yAxisWidth:{max:r.c},noDataWarning:Object(s.jsx)(a.EuiEmptyPrompt,{titleSize:"xxs",css:y,title:Object(s.jsx)("h2",null,Object(s.jsx)(o.FormattedMessage,{id:"xpack.ml.swimlaneEmbeddable.noDataFound",defaultMessage:"No anomalies found"}))}),chartsService:G}))};t.default=T}}]);