+L iMddlZddlmZddlZddlZddlZddlmZddlm Z m Z ddl m Z m Z edZdZdZd Z d d Z d d Zy)N)Path) get_module)validate_coerce_fig_to_dictplotly_cdn_url) _get_jconfig get_plotlyjsjsonct|tr|jd}tj|j }dt j|jdzS)z4Generate SHA256 hash for SRI (Subresource Integrity)utf-8zsha256-) isinstancestrencodehashlibsha256digestbase64 b64encodedecode)content sha256_hashs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/io/_html.py_generate_sri_hashrsR'3..)..)002K v'' 4;;GD DDzWzc 0 ddlm} t|| } | xstt j }| | j dg}| | j di}| j ddr| | j dg}nd}t|}|jdd| j di}| j dij d ij di}|j d |j d |}|j d |j d | } t|t|d z} t|t|d z}|j d ds|j ddr#dj|j dd}n8|jdd|jdd|jd dd}d}|rEt|tt fs|g}|D]'}|dj|j#d|z })d}d}|rEdj||}|r0|rdt$j'|z}nd}dj||}t$j'|}dj|||||||}|}t|tr|j)}d}|d k(r6t+} t-| }!d!jt.t1|!"}nv|d#k(rd$jt.%}nZt|tr)|j3d&rd'jt.|(}n!|rd)jt.t+*}|}"t|tr|j)}d+}#|d k(r|#jd,-t4z}$nnt|tr+|j3d&r|#j|"-t4z}$n3|sd}$n.td.jt7|t9|/d0j|$||||||1j;}%|rd2j|%3S|%S#ttf$rY.wxYw#ttf$rY*wxYw)4a  Convert a figure to an HTML string representation. Parameters ---------- fig: Figure object or dict representing a figure config: dict or None (default None) Plotly.js figure config options auto_play: bool (default=True) Whether to automatically start the animation sequence on page load if the figure contains frames. Has no effect if the figure does not contain frames. include_plotlyjs: bool or string (default True) Specifies how the plotly.js library is included/loaded in the output div string. If True, a script tag containing the plotly.js source code (~3MB) is included in the output. HTML files generated with this option are fully self-contained and can be used offline. If 'cdn', a script tag that references the plotly.js CDN is included in the output. The url used is versioned to match the bundled plotly.js. HTML files generated with this option are about 3MB smaller than those generated with include_plotlyjs=True, but they require an active internet connection in order to load the plotly.js library. If 'directory', a script tag is included that references an external plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. If False, no script tag referencing plotly.js is included. This is useful when the resulting div string will be placed inside an HTML document that already loads plotly.js. This option is not advised when full_html=True as it will result in a non-functional html file. include_mathjax: bool or string (default False) Specifies how the MathJax.js library is included in the output html div string. MathJax is required in order to display labels with LaTeX typesetting. If False, no script tag referencing MathJax.js will be included in the output. If 'cdn', a script tag that references a MathJax CDN location will be included in the output. HTML div strings generated with this option will be able to display LaTeX typesetting as long as internet access is available. If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML div string to an alternative CDN. post_script: str or list or None (default None) JavaScript snippet(s) to be included in the resulting div just after plot creation. The string(s) may include '{plot_id}' placeholders that will then be replaced by the `id` of the div element that the plotly.js figure is associated with. One application for this script is to install custom plotly.js event handlers. full_html: bool (default True) If True, produce a string containing a complete HTML document starting with an tag. If False, produce a string containing a single
element. animation_opts: dict or None (default None) dict of custom animation parameters to be passed to the function Plotly.animate in Plotly.js. See https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js for available options. Has no effect if the figure does not contain frames, or auto_play is False. default_width, default_height: number or str (default '100%') The default figure width/height to use if the provided figure does not specify its own layout.width/layout.height property. May be specified in pixels as an integer (e.g. 500), or as a css width style string (e.g. '500px', '100%'). validate: bool (default True) True if the figure should be validated before being converted to JSON, False otherwise. div_id: str (default None) If provided, this is the value of the id attribute of the div tag. If None, the id attribute is a UUID. Returns ------- str Representation of figure as an HTML div string r)to_json_plotlydatalayoutframesN responsiveTtemplatewidthheightpxshowLinkFshowSendToCloudzG window.PLOTLYENV.BASE_URL='{plotly_platform_url}';plotlyServerURLzhttps://plot.ly)plotly_platform_urllinkTextzX.then(function(){{ {post_script} }})z {plot_id}) post_scriptzn.then(function(){{ Plotly.addFrames('{id}', {frames}); }}))idrz, zx.then(function(){{ Plotly.animate('{id}', null{animation_opts}); }}))r+animation_optsa0 if (document.getElementById("{id}")) {{ Plotly.newPlot( "{id}", {data}, {layout}, {config} ){then_addframes}{then_animate}{then_post_script} }})r+rrconfigthen_addframes then_animatethen_post_scriptcdnz {win_config} ) win_configcdn_url integrity directoryzV {win_config} )r2z.jszN {win_config} )r2urlzS {win_config} )r2plotlyjsz8 z?https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js)r6zInvalid value of type {typ} received as the include_mathjax argument Received value: {val} include_mathjax may be specified as False, 'cdn', or a string ending with '.js' )typvalaF
{mathjax_script} {load_plotlyjs}
)mathjax_script load_plotlyjsr+r!r" base_url_linescriptzM {div} )div)plotly.io.jsonrrr uuiduuid4getr setdefaultfloat ValueError TypeErrorformatpopr listtuplereplace_jsondumpslowerrr_window_plotly_configrendswith_mathjax_configtypereprstrip)&figr- auto_playinclude_plotlyjsinclude_mathjaxr* full_htmlr, default_widthdefault_heightvalidatediv_idrfig_dict plotdividjdatajlayoutjframes layout_dict template_dict div_width div_heightr<r0psr.r/animation_opts_argjconfigr=include_plotlyjs_origr;plotlyjs_contentsri_hashinclude_mathjax_origmathjax_templater:plotly_html_divs& rto_htmlrp#sL.+39H+#djjl+I 8<<3 4EX\\(B78G||Hd# h!;<& !F lD),,x,KLL2.22:rBFFxQSTM):):7M)RSI=+<+%&67 ,"$    [ ( /0  $c */?/H/H/O /5JK   /,.I  +/3')//1<%  # #V $    OS )o.F.Fu.M  # #(< # = O   4(d?.CD    &%# # eg%( 6o6 &  'g  "     "   s$7 Q, R,Q?>Q?RRct||||||||| | | |  }t|tr t|}nt|tr|}nd}||j |dn|j ||A|r?|dk(r:|j dz }|js|j td|:|r7| r4|jj}tj|yyyy)a Write a figure to an HTML file representation Parameters ---------- fig: Figure object or dict representing a figure file: str or writeable A string representing a local file path or a writeable object (e.g. a pathlib.Path object or an open file descriptor) config: dict or None (default None) Plotly.js figure config options auto_play: bool (default=True) Whether to automatically start the animation sequence on page load if the figure contains frames. Has no effect if the figure does not contain frames. include_plotlyjs: bool or string (default True) Specifies how the plotly.js library is included/loaded in the output div string. If True, a script tag containing the plotly.js source code (~3MB) is included in the output. HTML files generated with this option are fully self-contained and can be used offline. If 'cdn', a script tag that references the plotly.js CDN is included in the output. The url used is versioned to match the bundled plotly.js. HTML files generated with this option are about 3MB smaller than those generated with include_plotlyjs=True, but they require an active internet connection in order to load the plotly.js library. If 'directory', a script tag is included that references an external plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. If `file` is a string to a local file path and `full_html` is True, then the plotly.min.js bundle is copied into the directory of the resulting HTML file. If a file named plotly.min.js already exists in the output directory then this file is left unmodified and no copy is performed. HTML files generated with this option can be used offline, but they require a copy of the plotly.min.js bundle in the same directory. This option is useful when many figures will be saved as HTML files in the same directory because the plotly.js source code will be included only once per output directory, rather than once per output file. If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. If False, no script tag referencing plotly.js is included. This is useful when the resulting div string will be placed inside an HTML document that already loads plotly.js. This option is not advised when full_html=True as it will result in a non-functional html file. include_mathjax: bool or string (default False) Specifies how the MathJax.js library is included in the output html div string. MathJax is required in order to display labels with LaTeX typesetting. If False, no script tag referencing MathJax.js will be included in the output. If 'cdn', a script tag that references a MathJax CDN location will be included in the output. HTML div strings generated with this option will be able to display LaTeX typesetting as long as internet access is available. If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML div string to an alternative CDN. post_script: str or list or None (default None) JavaScript snippet(s) to be included in the resulting div just after plot creation. The string(s) may include '{plot_id}' placeholders that will then be replaced by the `id` of the div element that the plotly.js figure is associated with. One application for this script is to install custom plotly.js event handlers. full_html: bool (default True) If True, produce a string containing a complete HTML document starting with an tag. If False, produce a string containing a single
element. animation_opts: dict or None (default None) dict of custom animation parameters to be passed to the function Plotly.animate in Plotly.js. See https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js for available options. Has no effect if the figure does not contain frames, or auto_play is False. default_width, default_height: number or str (default '100%') The default figure width/height to use if the provided figure does not specify its own layout.width/layout.height property. May be specified in pixels as an integer (e.g. 500), or as a css width style string (e.g. '500px', '100%'). validate: bool (default True) True if the figure should be validated before being converted to JSON, False otherwise. auto_open: bool (default True) If True, open the saved file in a web browser after saving. This argument only applies if `full_html` is True. div_id: str (default None) If provided, this is the value of the id attribute of the div tag. If None, the id attribute is a UUID. Returns ------- None ) r-rVrWrXr*rYr,rZr[r\r]Nr r5z plotly.min.js)encoding) rpr r r write_textwriteparentexistsrabsoluteas_uri webbrowseropen)rUfiler-rVrWrXr*rYr,r\rZr[ auto_openr]html_strpath bundle_pathr6s r write_htmlr`sr )'%#% H $Dz D$   '* 8 I*:k*IkkO3 !!#  " "<>G " D I)mmo$$&+4Ir) NTTFNTN100%rTN) NTTFNTNTrrFN)r@pathlibrryrr_plotly_utils.optional_importsrplotly.io._utilsrrplotly.offline.offlinerrrLrrOrQrprrrrs  5H=6E      z@   er