/*! 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([[15],{145:function(e,t,a){"use strict";a.d(t,"b",(function(){return i})),a.d(t,"a",(function(){return s}));var o=a(39),n=a.n(o);const r=3;function i(e,t,a,o){return Array.isArray(e)?1===e.length?s(e[0],t,a,o):`[${e.map((e=>s(e,t,void 0,o)))}]`:s(e,t,a,o)}function s(e,t,a,o){if(null==e)return"";if("time_of_week"===t){const t=void 0!==o&&void 0!==o.timestamp?new Date(o.timestamp):new Date,a=n()(t).unix()%n.a.duration(1,"week").asSeconds(),r=n.a.duration(a,"seconds"),i=n.a.utc(t).subtract(r).startOf("day").add(e,"s");return n()(i.valueOf()).format("ddd HH:mm")}if("time_of_day"===t){const t=void 0!==o&&void 0!==o.timestamp?new Date(o.timestamp):new Date,a=n.a.utc(t).startOf("day").add(e,"s");return n()(a.valueOf()).format("HH:mm")}if(void 0!==a)return a.convert(e,"text");{const t=Math.abs(e);if(t>=1e4||t===Math.floor(t))return void 0!==a?a.convert(e,"text"):Number(e.toFixed(0));if(t>=10)return Number(e.toFixed(1));{let t;return t=e>0?Math.pow(10,r-Math.floor(Math.log(e)/Math.LN10)-1):Math.pow(10,r-Math.floor(Math.log(-1*e)/Math.LN10)-1),Math.round(e*t)/t}}}},256:function(e,t,a){"use strict";a.d(t,"a",(function(){return c}));var o=a(29),n=a.n(o),r=a(11),i=a(2),s=a(21);function c(e,t,a,o){const c=n()(t.pipe(Object(r.map)((e=>e.executionContext)))),l=Object(i.useMemo)((()=>{const e={type:"visualization",name:a,id:o};return{...c,child:e}}),[c,o]);Object(s.useExecutionContext)(e,l)}},257:function(e,t,a){"use strict";a.d(t,"a",(function(){return r}));var o=a(67),n=a(69);function r(e,t,a){const r=null!=e?e:[],i=null!=t?t:Object(n.getDefaultQuery)(),s=["kuery"===i.language?Object(o.toElasticsearchQuery)(Object(o.fromKueryExpression)(i.query)):Object(o.luceneStringToDsl)(i.query)],c=[];for(const e of r){if(e.meta.disabled||void 0!==a&&e.meta.controlledBy===a)continue;const{meta:{negate:t,type:o,key:n}}=e;let r=e.query;void 0===r&&"exists"===o&&(r={exists:{field:n}}),r&&(t?c.push(r):s.push(r))}return{bool:{must:s,must_not:c}}}},258:function(e,t,a){"use strict";a.d(t,"a",(function(){return s}));var o=a(10),n=a(11),r=a(7),i=a(41);function s(e,t,a){return e.pipe(Object(n.pluck)("jobIds"),Object(n.distinctUntilChanged)(r.isEqual),Object(n.switchMap)((e=>t.getJobs$(e))),Object(n.map)((e=>e.map((e=>{var t;const a=Object(i.a)(e.analysis_config.bucket_span);return{id:e.job_id,selected:!0,bucketSpanSeconds:a.asSeconds(),modelPlotEnabled:!0===(null===(t=e.model_plot_config)||void 0===t?void 0:t.enabled)}})))),Object(n.catchError)((e=>{var t;return a(null!==(t=e.body)&&void 0!==t?t:e),Object(o.of)(void 0)})))}},682:function(e,t,a){"use strict";a.r(t),a.d(t,"EmbeddableAnomalyChartsContainer",(function(){return k}));var o=a(2),n=a.n(o),r=a(28),i=a(15),s=a(7),c=a(75),l=a(29),u=a.n(l),d=a(98),b=a(256),m=a(10),j=a(11),f=a(124),h=a(117),O=a(257),g=a(258);var v=a(100),p=a.n(v),x=a(6),y=a(351),E=a(153),M=a(4);const S=x.i18n.translate("xpack.ml.explorer.charts.dashboardTooManyBucketsDescription",{defaultMessage:"This selection contains too many buckets to be displayed. You should shorten the time range of the view."}),w=({id:e,chartsData:t,showCharts:a,severity:o,setSeverity:s,mlLocator:c,timeBuckets:l,timefilter:u,onSelectEntity:d,showSelectedInterval:b,chartsService:m,timeRange:j})=>Object(M.jsx)(n.a.Fragment,null,Object(M.jsx)(r.EuiFlexGroup,{id:e,direction:"row",gutterSize:"l",responsive:!0},Object(M.jsx)(r.EuiFlexItem,{grow:!1},Object(M.jsx)(E.b,{severity:o,onChange:s}))),Object(M.jsx)(r.EuiSpacer,{size:"m"}),Array.isArray(t.seriesToPlot)&&0===t.seriesToPlot.length&&void 0===t.errorMessages&&Object(M.jsx)(r.EuiText,{textAlign:"center","data-test-subj":"mlNoMatchingAnomaliesMessage"},Object(M.jsx)("h4",null,Object(M.jsx)(i.FormattedMessage,{id:"xpack.ml.explorer.noMatchingAnomaliesFoundTitle",defaultMessage:"No matching anomalies found"}))),a&&Object(M.jsx)(y.a,p()({},t,{severity:o.val,mlLocator:c,timeBuckets:l,timefilter:u,timeRange:j,onSelectEntity:d,tooManyBucketsCalloutMsg:S,showSelectedInterval:b,chartsService:m})));var T=a(1),A=a(136),_=a(253),C=a(123);const k=({id:e,embeddableContext:t,embeddableInput:a,services:n,refresh:l,onInputChange:v,onOutputChange:p,onRenderComplete:x,onError:y,onLoading:S})=>{var k;Object(b.a)(n[0].executionContext,a,C.a,e);const[R,I]=Object(o.useState)(0),[L,D]=Object(o.useState)(Object(E.c)(null!==(k=t.getInput().severityThreshold)&&void 0!==k?k:d.g.WARNING)),[F,N]=Object(o.useState)(),[{uiSettings:B},{data:G,share:q,uiActions:z,charts:H}]=n,{timefilter:$}=G.query.timefilter,P=Object(o.useMemo)((()=>q.url.locators.get(T.a)),[q]),U=Object(o.useMemo)((()=>new A.a({"histogram:maxBars":B.get(c.UI_SETTINGS.HISTOGRAM_MAX_BARS),"histogram:barTarget":B.get(c.UI_SETTINGS.HISTOGRAM_BAR_TARGET),dateFormat:B.get("dateFormat"),"dateFormat:scaled":B.get("dateFormat:scaled")})),[]),W=u()(a);Object(o.useEffect)((()=>{v({severityThreshold:L.val}),p({severity:L.val,entityFields:F})}),[L,F]);const{chartsData:Q,isLoading:V,error:X}=function(e,t,a,n,r,i,s){const[,,{anomalyDetectorService:c,anomalyExplorerService:l}]=n,[u,d]=Object(o.useState)(),[b,v]=Object(o.useState)(),[p,x]=Object(o.useState)(!1),y=Object(o.useMemo)((()=>new m.Subject),[]),E=Object(o.useMemo)((()=>new m.Subject),[]);return Object(o.useEffect)((()=>{const t=Object(m.combineLatest)([Object(g.a)(e,c,v),e,y.pipe(Object(j.skipWhile)((e=>!e))),E,a.pipe(Object(j.startWith)(null))]).pipe(Object(j.tap)(x.bind(null,!0)),Object(j.debounceTime)(500),Object(j.tap)((()=>{s.onLoading()})),Object(j.switchMap)((([e,t,a,o])=>{var n,r;if(!e)return Object(m.of)(void 0);const{maxSeriesToPlot:i,timeRange:s,filters:c,query:u}=t,d=h.g;let b;l.setTimeRange(s);try{(c||u)&&(b=Object(O.a)(c,u))}catch(e){return v(e),Object(m.of)(void 0)}const j=l.getTimeBounds(),g={lanes:[h.g],times:[null===(n=j.min)||void 0===n?void 0:n.unix(),null===(r=j.max)||void 0===r?void 0:r.unix()],type:h.h.OVERALL},p=Object(f.i)(g,d),x=Object(f.j)(g,e),y=Object(f.k)(g,j);return l.getAnomalyData$(x,a,y.earliestMs,y.latestMs,b,p,null!=o?o:0,i)})),Object(j.catchError)((e=>(v(e.body),Object(m.of)(void 0))))).subscribe((e=>{void 0!==e&&(v(null),d(e),x(!1),s.onRenderComplete())}));return()=>{t.unsubscribe()}}),[]),Object(o.useEffect)((()=>{y.next(r)}),[r]),Object(o.useEffect)((()=>{E.next(i)}),[i]),Object(o.useEffect)((()=>{b&&s.onError(b)}),[b]),{chartsData:u,isLoading:p,error:b}}(a,0,l,n,R,L.val,{onRenderComplete:x,onError:y,onLoading:S}),Y=Object(o.useRef)(),J=Object(o.useCallback)(Object(s.throttle)((e=>{V||(Y.current=e.height),Math.abs(R-e.width)>20&&I(e.width)}),500),[!V,R]),K=Object(o.useMemo)((()=>V?Y.current:void 0),[V]);if(X)return Object(M.jsx)(r.EuiCallOut,{title:Object(M.jsx)(i.FormattedMessage,{id:"xpack.ml.anomalyChartsEmbeddable.errorMessage",defaultMessage:"Unable to load the ML anomaly explorer data"}),color:"danger",iconType:"warning",style:{width:"100%"}},Object(M.jsx)("p",null,X.message));const Z=(e,a,o)=>{const n=[{fieldName:e,fieldValue:a,operation:o}];N(n),z.getTrigger(_.a).exec({embeddable:t,data:n})};return Object(M.jsx)(r.EuiResizeObserver,{onResize:J},(a=>Object(M.jsx)("div",{id:`mlAnomalyExplorerEmbeddableWrapper-${e}`,style:{width:"100%",overflowY:"auto",overflowX:"hidden",padding:"8px",height:K},"data-test-subj":`mlExplorerEmbeddable_${t.id}`,ref:a},V&&Object(M.jsx)(r.EuiText,{textAlign:"center",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%,-50%)"}},Object(M.jsx)(r.EuiLoadingChart,{size:"xl",mono:!0,"data-test-subj":"mlAnomalyExplorerEmbeddableLoadingIndicator"})),void 0!==Q&&!1===V&&Object(M.jsx)(w,{id:e,showCharts:!0,chartsData:Q,severity:L,setSeverity:D,mlLocator:P,timeBuckets:U,timefilter:$,onSelectEntity:Z,showSelectedInterval:!1,chartsService:H,timeRange:null==W?void 0:W.timeRange}))))};t.default=k}}]);