(window.expressionLegacyMetricVis_bundle_jsonpfunction=window.expressionLegacyMetricVis_bundle_jsonpfunction||[]).push([[1],{19:function(e,t,r){"use strict";var n,i=function(){var e={};return function(t){if(void 0===e[t]){var r=document.querySelector(t);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}e[t]=r}return e[t]}}(),o=[];function a(e){for(var t=-1,r=0;r{const{style:t,metric:r,onFilter:n,labelConfig:i,colorFullBackground:a,autoScale:s}=e,c=l()("legacyMtrVis__container",{"legacyMtrVis__container--light":r.lightText,"legacyMtrVis__container-isfilterable":n,"legacyMtrVis__container-isfull":!s&&a});Object(o.useLayoutEffect)((()=>{var t;null===(t=e.renderComplete)||void 0===t||t.call(e)}),[e]);const p=Object(d.jsx)("div",{className:c,style:s&&a?{}:{backgroundColor:r.bgColor}},Object(d.jsx)("div",{"data-test-subj":"metric_value",className:"legacyMtrVis__value",style:{...t.spec,...r.color?{color:r.color}:{}},dangerouslySetInnerHTML:{__html:r.value}}),i.show&&Object(d.jsx)("div",{"data-test-subj":"metric_label",style:{...i.style.spec,order:"top"===i.position?-1:2}},r.label));return n?Object(d.jsx)("button",{style:{display:"block"},onClick:()=>n(),title:u.i18n.translate("expressionLegacyMetricVis.filterTitle",{defaultMessage:"Click to filter by field"})},p):p};var f=r(14);const m=e=>{var t;const r=null!==(t=e.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*?(,\s*(\d+)\s*)?\)/))&&void 0!==t?t:[];return r?{red:parseFloat(r[1]),green:parseFloat(r[2]),blue:parseFloat(r[3]),opacity:r[5]?parseFloat(r[5]):void 0}:null},h=(e="")=>{const t=m(e);if(!t)return!1;const{red:r,green:n,blue:i,opacity:o}=t;return Object(f.isColorDark)(r,n,i)&&0!==o},b=(e,t,r="text")=>"number"==typeof e&&isNaN(e)?"-":t.convert(e,r);var g=r(17),v=r(18);const y=Object(d.css)({display:"flex",justifyContent:"center",alignItems:"center",maxWidth:"100%",maxHeight:"100%",overflow:"hidden",lineHeight:v.euiThemeVars.euiLineHeight},"","");r(22);const x=(w=p,e=>{const{autoScaleParams:t,renderComplete:r}=e,n=function(e){if(function(e){return!!e.autoScaleParams}(e)){const{autoScaleParams:t,renderComplete:r,...n}=e;return n}return e}(e),[i,a]=Object(o.useState)(0),[s,c]=Object(o.useState)(!1),l=Object(o.useRef)(null),u=Object(o.useRef)(null),p=Object(f.useResizeObserver)(l.current),m=Object(o.useMemo)((()=>Object(g.throttle)((()=>{const e=function(e,t,r=.3){if(!e||!t)return 1;const n=e.clientWidth/t.clientWidth,i=e.clientHeight/t.clientHeight;return Math.max(Math.min(1,Math.min(n,i)),r)}({clientHeight:p.height,clientWidth:p.width},u.current,null==t?void 0:t.minScale);i!==e&&a(e),p.height&&p.width&&c(!0)}))),[p,a,i,t]);return Object(o.useEffect)((()=>{m()}),[m]),Object(o.useLayoutEffect)((()=>{s&&(null==r||r())}),[r,s]),Object(d.jsx)("div",{ref:l,style:null==t?void 0:t.containerStyles,css:y},Object(d.jsx)("div",{ref:u,style:{transform:`scale(${i||0})`,...p.width&&i&&null!=t&&t.autoScaleMetricAlignment&&"center"!==(null==t?void 0:t.autoScaleMetricAlignment)?{position:"relative",[t.autoScaleMetricAlignment]:(1-i)*p.width*i*-1}:{}}},Object(d.jsx)(w,n)))});var w;class metric_component_MetricVisComponent extends o.Component{constructor(...e){super(...e),i()(this,"filterColumn",((e,t)=>{const{dimensions:r}=this.props.visParams,n=this.props.visData;let i=r.bucket?Object(a.getAccessor)(r.bucket):t;"object"==typeof i&&"id"in i&&(i=n.columns.indexOf(i)),this.props.fireEvent({name:"filter",data:{data:[{table:n,column:i,row:e}]}})})),i()(this,"isAutoScaleWithColorizingContainer",(()=>this.props.visParams.metric.autoScale&&this.props.visParams.metric.colorFullBackground)),i()(this,"renderMetric",((e,t,r)=>{var n,i;const o=void 0!==this.props.visParams.dimensions.bucket,a=this.props.visParams.metric.autoScale?x:p;return Object(d.jsx)(a,{autoScaleParams:this.isAutoScaleWithColorizingContainer()?{containerStyles:{backgroundColor:e.bgColor,minHeight:"100%",minWidth:"100%"},...null!==(n=this.props.visParams.metric)&&void 0!==n&&n.autoScaleMetricAlignment?{autoScaleMetricAlignment:null===(i=this.props.visParams.metric)||void 0===i?void 0:i.autoScaleMetricAlignment}:{}}:void 0,key:t,metric:e,style:this.props.visParams.metric.style,onFilter:o||this.props.filterable[t]?()=>this.filterColumn(e.rowIndex,e.colIndex):void 0,autoScale:this.props.visParams.metric.autoScale,colorFullBackground:this.props.visParams.metric.colorFullBackground,labelConfig:this.props.visParams.metric.labels,renderComplete:r.length-1===t?this.props.renderComplete:void 0})}))}getColor(e,t){var r,n;return null===(r=Object(s.b)().get("custom"))||void 0===r||null===(n=r.getColorForValue)||void 0===n?void 0:n.call(r,e,t,{min:t.rangeMin,max:t.rangeMax})}processTableGroups(e){const{metric:t,dimensions:r}=this.props.visParams,{percentageMode:n,style:i,palette:o}=t,{stops:c=[]}=null!=o?o:{},l=c[0],u=c[c.length-1];let d,p;if(r.bucket){const t=Object(a.getColumnByAccessor)(r.bucket,e.columns);d=null==t?void 0:t.id,p=Object(s.a)().deserialize(Object(a.getFormatByAccessor)(r.bucket,e.columns))}return r.metrics.reduce(((t,r)=>{const f=Object(a.getColumnByAccessor)(r,null==e?void 0:e.columns),g=null==e?void 0:e.columns.indexOf(f),v=Object(s.a)().deserialize(Object(a.getFormatByAccessor)(r,e.columns));return[...t,...e.rows.map(((e,t)=>{var r,a,s;let y=f.name,x=e[f.id];const w=o?this.getColor(x,o):void 0;n&&c.length&&(x=(x-l)/(u-l));const M=b(x,v,"html");d&&(y=`${b(e[d],p)} - ${y}`);const _=(e=>{const t=m(e),{opacity:r}=null!=t?t:{};return!t||t&&0!==r})(null!=w?w:"");return{label:y,value:M,color:_&&null!==(r=i.labelColor)&&void 0!==r&&r?w:void 0,bgColor:_&&null!==(a=i.bgColor)&&void 0!==a&&a?w:void 0,lightText:_&&null!==(s=i.bgColor)&&void 0!==s&&s&&h(w),rowIndex:t,colIndex:g}}))]}),[])}render(){let e;return this.props.visData&&(e=this.processTableGroups(this.props.visData).map(this.renderMetric)),e}}}}]);