import{r as t,f as l,h as i,c as s,e as o}from"./p-5da71329.js";import{c as e,i as a}from"./p-bfd527b9.js";const n="application/vnd.plotly.v1+json";const c=".sc-stencila-image-plotly-default-h{display:block}.sc-stencila-image-plotly-default-h.imgHidden.sc-stencila-image-plotly-default-s>picture>:not(.js-plotly-plot){display:none}";const r=".sc-stencila-image-plotly-material-h{display:block}.sc-stencila-image-plotly-material-h.imgHidden.sc-stencila-image-plotly-material-s>picture>:not(.js-plotly-plot){display:none}";const d="https://cdn.plot.ly/plotly-latest.min.js";let p;let h=class{constructor(i){t(this,i);this.plotlyLoad=l(this,"stencila-plotly-load",7);this.plotIsRendered=false;this.renderPlot=()=>{var t,l,i;const{data:s,layout:o=this.layout,config:a=this.config}=(t=this.getPlotContent())!==null&&t!==void 0?t:{};if(!s)return;this.plotContainer=(l=this.plotContainer)!==null&&l!==void 0?l:e(this.el);(i=window.Plotly)===null||i===void 0?void 0:i.react(this.plotContainer,s,o,a).then((()=>{if(!this.plotIsRendered){this.plotIsRendered=true}})).catch((t=>{console.error("Failed to render plot",t)}))};this.getPlotContent=()=>{if(this.data){return{data:this.data,layout:this.layout,config:this.config}}const t=this.el.querySelector(`[type="${n}"]`);if(t){try{const l=t.textContent;const i=JSON.parse(l!==null&&l!==void 0?l:"");return Array.isArray(i)?{data:i}:i}catch(l){console.error("Could not parse plot data")}}return undefined}}onPlotlyLoad(){if(!this.plotIsRendered){this.renderPlot()}}componentWillLoad(){if(!this.plotIsRendered&&p){this.renderPlot()}else{a({src:d,onLoad:()=>{p=true;this.plotlyLoad.emit()}})}}componentShouldUpdate(t,l,i){if(i==="plotIsRendered"&&l===t){return false}return true}componentWillUpdate(){this.renderPlot()}render(){return i(o,{class:{imgHidden:this.plotIsRendered}})}get el(){return s(this)}};h.style={default:c,material:r};export{h as stencila_image_plotly};
//# sourceMappingURL=p-c87f548f.entry.js.map