+L idddlZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZddlmZmZddlmZej*dZej*d Z dd lmZmZGd d eZGd deZGddeZ GddeZ!GddeZ"Gdde"Z#Gdde"Z$Gdde"Z%Gdde"Z&dZ'dZ(Gdd eZ)Gd!d"e)Z*Gd#d$e)Z+Gd%d&e)Z,Gd'd(e)Z-Gd)d*eZ.Gd+d,e.Z/Gd-d.eZ0d8d/Z1Gd0d1e0Z2Gd2d3e0Z3Gd4d5e)Z4Gd6d7e0Z5y#e$r dd lmZmZYwxYw)9N)isdir)optional_imports)to_jsonto_image write_image write_html)plotly_cdn_url) _get_jconfig get_plotlyjs)!return_figure_from_figure_or_datazIPython.displayIPython)BaseHTTPRequestHandler HTTPServerc"eZdZdZdZdZdZy) BaseRendererz& Base class for all renderers cyNselfs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/io/_base_renderers.pyactivatezBaseRenderer.activates c tjj}t|jj }djjjdjfd|DjS#t $rGtjj}|jDcgc] }|dk7s | ncc}w}}YwxYw)Nrz{cls}({attrs}) {doc}z, c3\K|]#}dj|j|%yw)z{}={!r}N)format__dict__).0krs r z(BaseRenderer.__repr__..+s'UaI,,Q a0@AUs),)clsattrsdoc)inspect signature__init__list parameterskeysAttributeError getargspecargsr __class____name__join__doc__)rinit_sig init_argsargspecas` r__repr__zBaseRenderer.__repr__ s A((7HX005578I '--''))U9UU .   A((7G$+LL@qAK@@I@ As$AB6C CCCCc*tt|Sr)hashreprrs r__hash__zBaseRenderer.__hash__/sDJrN)r. __module__ __qualname__r0rr5r9rrrrrs    rrceZdZdZdZy)MimetypeRendererz0 Base class for all mime type renderers ctrNotImplementedError)rfig_dicts r to_mimebundlezMimetypeRenderer.to_mimebundle9 !##rNr.r:r;r0rBrrrr=r=4s $rr=ceZdZdZdZy) JsonRendererz Renderer to display figures as JSON hierarchies. This renderer is compatible with JupyterLab and VSCode. mime type: 'application/json' cLtjt|dd}d|iS)NFvalidate remove_uidszapplication/json)jsonloadsr)rrAvalues rrBzJsonRenderer.to_mimebundleEs$ 78eOP"E**rNrDrrrrFrF=s +rrFceZdZdZddZdZy)PlotlyRendererz Renderer to display figures using the plotly mime type. This renderer is compatible with VSCode and nteract. mime type: 'application/vnd.plotly.v1+json' Nc8|rt||_yi|_yr)dictconfig)rrRs rr&zPlotlyRenderer.__init__Ss&,d6l " rct|j}|r||d<tjt |dd}d|iS)NrRFrHzapplication/vnd.plotly.v1+json)r rRrKrLr)rrArRjson_compatible_fig_dicts rrBzPlotlyRenderer.to_mimebundleVsFdkk* !'HX #':: Hu% @$  12JKKrrr.r:r;r0r&rBrrrrOrOKs5 LrrOc*eZdZdZ ddZdZy) ImageRendererz3 Base class for all static image renderers Ncf||_||_||_||_||_||_||_yr mime_type b64_encoderwidthheightscaleengine)rrZr[rr\r]r^r_s rr&zImageRenderer.__init__hs5#$     rc *t||j|j|j|jd|j }|j r%tj|jd}n|jd}|j|iS)NF)rr\r]r^rIr_utf8) rrr\r]r^r_r[base64 b64encodedecoderZ)rrA image_bytes image_strs rrBzImageRenderer.to_mimebundlezsx ;;**;;**;;  ??((5< {win_config} {mathjax_config} z.js) win_configmathjax_config plotly_cdnz )scriptrrT)raw) ripython_display ValueErrorrr-r.r_window_plotly_config_mathjax_configr rstripr display_html)rrs rrzHtmlRenderer.activate s   " NUU NN33V ~~ F4#2-/66u=    F'>4#2     ( (T ( :I rc pddlm}d}dg}|jrWt|jtt fs|j |jn|j|j|||j|j|j|||j|jddd }d |iS) Nrto_htmlra var gd = document.getElementById('{plot_id}'); var x = new MutationObserver(function (mutations, observer) {{ var display = window.getComputedStyle(gd).display; if (!display || display === 'none') {{ console.log([gd, 'removed!']); Plotly.purge(gd); observer.disconnect(); }} }}); // Listen for the removal of the full notebook cells var notebookContainer = gd.closest('#notebook-container'); if (notebookContainer) {{ x.observe(notebookContainer, {childList: true}); }} // Listen for the clearing of the current output cell var outputEl = gd.closest('.output'); if (outputEl) {{ x.observe(outputEl, {childList: true}); }} 100% F rRrrinclude_mathjaxrrr default_widthdefault_heightrI text/html) plotly.iorr isinstancer'tupleappendextendrRrrrr)rrArrrhtmls rrBzHtmlRenderer.to_mimebundle0s%  6   d..u >""4#3#34""4#3#34 ;;nn!22+#nn..   T""r)FFFNFNNT)r.r:r;r0r&rrBrrrrrs2N(%;N5#rrc0eZdZdZ dfd ZxZS)NotebookRenderera Renderer to display interactive figures in the classic Jupyter Notebook. This renderer is also useful for notebooks that will be converted to HTML using nbconvert/nbviewer as it will produce standalone HTML files that include interactive figures. This renderer automatically performs global notebook initialization when activated. mime type: 'text/html' c <tt| |dd|||||y)NFTrrrrRrrrr)rlrr&)rrrRrrrrr-s rr&zNotebookRenderer.__init__us2 .#)- / r)FNFNNFrorqs@rrrhs&   rrc&eZdZdZ dfd ZxZS)KaggleRendereraF Renderer to display interactive figures in Kaggle Notebooks. Same as NotebookRenderer but with connected=True so that the plotly.js bundle is loaded from a CDN rather than being embedded in the notebook. This renderer is enabled by default when running in a Kaggle notebook. mime type: 'text/html' c <tt| ddd||||dyNTFr)rlrr&rrRrrrr-s rr&zKaggleRenderer.__init__s1 nd,#)" - rNFNNrorqs@rrr NR   rrc&eZdZdZ dfd ZxZS) AzureRendereraE Renderer to display interactive figures in Azure Notebooks. Same as NotebookRenderer but with connected=True so that the plotly.js bundle is loaded from a CDN rather than being embedded in the notebook. This renderer is enabled by default when running in an Azure notebook. mime type: 'text/html' c <tt| ddd||||dyr)rlrr&rs rr&zAzureRenderer.__init__s1 mT+#)" , rrrorqs@rrrrrrc&eZdZdZ dfd ZxZS) ColabRendererz Renderer to display interactive figures in Google Colab Notebooks. This renderer is enabled by default when running in a Colab notebook. mime type: 'text/html' c :tt| ddd||||y)NTFrrrrRrrr)rlrr&rs rr&zColabRenderer.__init__s. mT+#) , rrrorqs@rrrsNR   rrc6eZdZdZ ddZdZdZdZy)IFrameRenderera Renderer to display interactive figures using an IFrame. HTML representations of Figures are saved to an `iframe_figures/` directory and iframe HTML elements that reference these files are inserted into the notebook. With this approach, neither plotly.js nor the figure data are embedded in the notebook, so this is a good choice for notebooks that contain so many large figures that basic operations (like saving and opening) become very slow. Notebooks using this renderer will display properly when exported to HTML as long as the `iframe_figures/` directory is placed in the same directory as the exported html file. Note that the HTML files in `iframe_figures/` are numbered according to the IPython cell execution count and so they will start being overwritten each time the kernel is restarted. This directory may be deleted whenever the kernel is restarted and it will be automatically recreated. mime type: 'text/html' NcX||_||_||_||_||_||_yr)rRrrrrhtml_directory)rrRrrrrrs rr&zIFrameRenderer.__init__s2 "&, 0,rcdddlm}d}|jdi}|jddrt|d|zdz}nd}|jd dr |d |z}ntd |zdz}|j } t j |j||||j|j|jd d|j|jdd d d j|||j!|}d|iS#t$rt|jsYwxYw)Nr)rlayoutr\Fpxrr]rr) rRrrr auto_openrrrrrIz )r\r]srcr)rrgetstrbuild_filenameosmakedirsrOSErrorrrRrrrrr build_url) rrAr iframe_bufferr iframe_width iframe_heightfilename iframe_htmls rrBzIFrameRenderer.to_mimebundles@( h+ ::gu %vg>?$FL!L ::h &"8,}qA!DqHTUK5;;''[<   K s1A,, A:9A:c|Srrrrs rrzIFrameRenderer.build_urlBsr)NFNNTiframe_figures)r.r:r;r0r&rBrrrrrrrs02'- 7*r rrceZdZdZdZdZy)CoCalcRendererrcdj|jtj}txjdz c_|S)Nz${dirname}/figure_{render_count}.html)r render_countr)rrr _render_countrs rrzCoCalcRenderer.build_filenameIsA9@@''n6R6RA  $$)$rc&dj|S)Nz{filename}?fullscreen=kiosk)r)rrs rrzCoCalcRenderer.build_urlQs,33X3FFrN)r.r:r;rrrrrrrrFsMGrrceZdZdZdZy)ExternalRenderera Base class for external renderers. ExternalRenderer subclasses do not display figures inline in a notebook environment, but render figures by some external means (e.g. a separate browser tab). Unlike MimetypeRenderer subclasses, ExternalRenderer subclasses are not invoked when a figure is asked to display itself in the notebook. Instead, they are invoked when the plotly.io.show function is called on a figure. ctrr?)rfigs rrenderzExternalRenderer.renderarCrN)r.r:r;r0rrrrrrUs  $rrcttrjdd}|tjd}nMt|t s|f}|D]} tj|}|n|tdt|zGfddt}td|}|jd|jz|||jy#tj $rYwxYw) ae Display html in a web browser without creating a temp file. Instantiates a trivial http server and uses the webbrowser module to open a URL to retrieve html from that server. Parameters ---------- html: str HTML string to display using, new, autoraise: See docstrings in webbrowser.get and webbrowser.open raNz#Can't locate a browser with key in ceZdZfdZdZy)3open_html_in_browser..OneShotRequestHandlerc|jd|jdd|jd}tdt |D]#}|j j |||z%y)Nz Content-typerir) send_response send_header end_headersrangelenwfilewrite)r bufferSizeirs rdo_GETz:open_html_in_browser..OneShotRequestHandler.do_GETsk   s #   ^[ 9    $J1c$i4 ;   a!j.!9: ;rcyrr)rrr,s r log_messagez?open_html_in_browser..OneShotRequestHandler.log_messages rN)r.r:r;rr)rsrOneShotRequestHandlerrs  ; rr)z 127.0.0.1rzhttp://127.0.0.1:%s)new autoraise) rrencode webbrowserrrErrorrrropen server_porthandle_request)rusingrrbrowser browser_keyrservers` ropen_html_in_browserres${{6"G }..&%'HE  K $..5&'  ?BSZOP P  6 (*? @F LL 2 22y 3##  sCC/.C/c,eZdZdZ ddZdZy)BrowserRenderera Renderer to display interactive figures in an external web browser. This renderer will open a new browser window or tab when the plotly.io.show function is called on a figure. This renderer has no ipython/jupyter dependencies and is a good choice for use in environments that do not support the inline display of interactive figures. mime type: 'text/html' Ncf||_||_||_||_||_||_||_yr)rRrrrrrr)rrRrrrrrrs rr&zBrowserRenderer.__init__s7 " "&,rc ddlm}|||j|jdd|jd|j ddd }t ||j|j|jy)NrrTrrFr) rrrRrrrrrrrrrArrs rrzBrowserRenderer.renders`% ;;nn!!((.. !   T4::txxHr)NFNrTNN)r.r:r;r0r&rrrrrrs)  -$Irrc4eZdZ ddZedZdZy)DatabricksRendererNcX||_||_||_||_||_d|_yr)rRrrrr _displayHTML)rrRrrrrs rr&zDatabricksRenderer.__init__s2 "&, 0 rc\ddl}|j|j|jD]U}t |j j tfddDs7|j j d|_n|j td|jS)Nrc3&K|]}|v ywrr)rv global_namess rr z1DatabricksRenderer.displayHTML..sVQqL(Vs) displayHTMLdisplaysparkrz Unable to detect the Databricks displayHTML function. The 'databricks' renderer is only supported when called from within the Databricks notebook environment.) r$r getouterframes currentframesetframe f_globalsallEnvironmentError)rr$rrs @rrzDatabricksRenderer.displayHTMLs    $///0D0D0D0FG "5;;#8#89 V2UVV(- (=(=m(LD%    (&J    rc ddlm}|||j|j|jd|j d|j ddd }|j|y)NrrrTrFr)rrrRrrrrrrs rrzDatabricksRenderer.rendersZ% ;;nn!22!((.. !   r)NFNNr)r.r:r;r&propertyrrrrrr r s1 !!!*rr c0eZdZ dfd ZdZxZS)SphinxGalleryHtmlRendererc :tt| |dd||||y)NFr)rlrr&)rrrRrrrr-s rr&z"SphinxGalleryHtmlRenderer.__init__ s/ '7#) 8 rc ddlm}|jrd}d}nd}d}|||j|j|||j |j ddd }d |iS) NrrrTrrF) rRrrrrrrrrIr)rrrrRrrr)rrArrrrs rrBz'SphinxGalleryHtmlRenderer.to_mimebundlesi% >>$ #O# #O ;;nn-+nn..   T""r)TNFNN)r.r:r;r&rBrprqs@rrr s  $#rrceZdZdZy)SphinxGalleryOrcaRendererc\tj} |dj}tj j |\}}|dz}|dz}t|d}t||d} t||y#t$r |dd}YgwxYw#ttf$r tdwxYw) Nrz.htmlz.pngTr)filera6orca and psutil are required to use the `sphinx-gallery-orca` renderer. See https://plotly.com/python/static-image-export/ for instructions on how to install orca. Alternatively, you can use the `sphinx-gallery` renderer (note that png thumbnails can only be generated with the `sphinx-gallery-orca` renderer).) r$stackrrrpathsplitextr rrr ImportError) rrAr&r filename_root_ filename_html filename_pngfigures rrz SphinxGalleryOrcaRenderer.render9s  #Qx((H77++H5 q%/ $v- 28TB xme L   - #Qx{H #K( 7  sA9, B9B  B B+N)r.r:r;rrrrr"r"8srr")NrT)6rbrKrr$ros.pathrplotlyrrrrrrplotly.io._utilsr plotly.offline.offliner r plotly.toolsr get_modulerr http.serverrrr)BaseHTTPServerobjectrr=rFrOrWrirtrxr|rrrrrrrrrrrrr rr"rrrr8s  #@@+=:-"--.?@ %  % %i 0B>  6 8$|$ +# +L%L0'+$'+T - , - , = , - 03Bw##w#t | D \ 6 L 6 L .l%l^ G^ G $| $ 6r/I&/Id8)8v*# *#Z 0KBAABs&E E.-E.