
    i                        S r SSKJr  SSKJr  SSKJrJr  SSKJrJ	r	  SSK
JrJr  SS	KJr  \	(       a  SS
KJr  SR%                  / SQ5      rSSS jjrSS jrSSSSSS.             SS jjrg)z9Functions to visualize :class:`~.ExecutionSpans` objects.    )annotations)cycle)datetime	timedelta)IterableTYPE_CHECKING   )ExecutionSpanExecutionSpans   )plotly_module)Figurez<br>)z<b>{name}[{idx}]</b>zA<b>&nbsp;&nbsp;&nbsp;Start:</b> {span.start:%Y-%m-%d %H:%M:%S.%f}z?<b>&nbsp;&nbsp;&nbsp;Stop:</b> {span.stop:%Y-%m-%d %H:%M:%S.%f}z7<b>&nbsp;&nbsp;&nbsp;Duration:</b> {span.duration:.4g}sz*<b>&nbsp;&nbsp;&nbsp;Size:</b> {span.size}z,<b>&nbsp;&nbsp;&nbsp;Pub Indexes:</b> {idxs}c           	         [        U R                  =n5      U::  a  [        U5      $ SSR                  [	        [        US U 5      5       S3$ )N[z, z, ...])lenpub_idxsstrjoinmap)spanlimitidxss      o/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/visualization/draw_execution_spans.py	_get_idxsr   (   sH    
4== 4!U*4y499Sd6El345V<<    c                D    U(       a  S[        [        U 5      5       S3$ S$ )N<> )hexid)spansmultiples     r   _get_idr$   /   s!    $,Qs2e9~a 4"4r   NF   )namescommon_startnormalize_y
line_widthshow_legendc                  ^ [        S5      n[        S5      R                  R                  nUR                  5       n/ n	U c  Uc  SOUnO1Uc  SOUn[	        U [
        5      (       a  U /n	OU	R                  U 5        U	R                  U4S jT[        U	5      S  5       5        [        T[        U5      U	5       GH?  u  pnU
(       d  M  [        [        U
5      S S9n[        5       nU(       a-  US	   S
   R                  R                  SS9nU[        SS
S
S9-
  nU(       a  [!        S U
 5       5      OS
nSn/ n/ n/ nU H  u  nnUUR"                  U-  -  n[$        R'                  UU[)        U5      US9nUR                  UR                  U-
  UR*                  U-
  S/5        UR                  UUS/5        UR                  U/S-  5        M     UR-                  UR/                  UUSX;S.USUS95        GMB     UR1                  SSS.USSSSS.SSSSS .S!9  U(       a  UR3                  S"S#S$9  OUR3                  S%S&9  U(       a  UR5                  S'S(9  U$ ))aN  Draw one or more :class:`~.ExecutionSpans` on a bar plot.

Args:
    spans: One or more :class:`~.ExecutionSpans`.
    names: Name or names to assign to respective ``spans``.
    common_start: Whether to shift all collections of spans so that their first span's start is
        at :math:`t=0`.
    normalize_y: Whether to display the y-axis units as a percentage of work complete, rather
        than cumulative shots completed.
    line_width: The thickness of line segments.
    show_legend: Whether to show a legend. By default, this choice is automatic.

Returns:
    A plotly figure.
z.graph_objectsz.colorsNFTc              3  Z   >#    U  H   nS [        U[        T5      S:  5       3v   M"     g7f)r   r   N)r$   r   ).0single_spanr"   s     r   	<genexpr>'draw_execution_spans.<locals>.<genexpr>[   s/      2K c%jl;<=2s   (+c                    U S   $ )Nr    )xs    r   <lambda>&draw_execution_spans.<locals>.<lambda>f   s    QqTr   )keyr   r   )tzinfoi  )yearmonthdayc              3  8   #    U  H  oR                   v   M     g 7f)N)size)r-   r   s     r   r/   r0   q   s     <|t|s   g        )r   idxr   name   lines)widthcolortext)r3   ymodelinerC   	hoverinfor>   Timedate)titletypebottomg{Gz?rightgGz?)yanchorrD   xanchorr3   F      )lrtb)xaxis
showlegendlegendmarginzCompleted Workloadz.0%)rJ   
tickformatzShots Completed)rJ   z%H:%M:%S.%f)rZ   )r   qualitativePlotlyr   
isinstancer   extendr   zipr   sorted	enumerater   startreplacer   sumr<   HOVER_TEMPLATEformatr   stop	add_traceScatterupdate_layoutupdate_yaxesupdate_xaxes)r&   r'   r(   r)   r*   r"   gocolorsfig	all_namessingle_spansrB   r>   sorted_spansoffsetfirst_start
total_sizey_valuex_datay_data	text_datar=   r   rC   s        `                  r   draw_execution_spansrz   3   s   . 
'	(B9%1188F
))+C I}*2e)1d{eS!!IU#   Y!12  &)fy%I!T i5>J 'q/!,22::$:GK 8QA#FFF ALS<|<<QR
	%ICtyy:--G!((d)D/X\(]DMM4::.		F0BDIJMM7GT23dVaZ( & 	JJ):   
	
= &JV /#$7Nbr3	   3F01M2Jr   )
   )r   r
   r   intreturnr   )r"   r   r#   boolr}   r   )r"   r   r&   zstr | Iterable[str] | Noner'   r~   r(   r~   r)   r|   r*   r~   r}   PlotlyFigure)__doc__
__future__r   	itertoolsr   r   r   typingr   r   execution_spanr
   r   utilsr   plotly.graph_objectsr   r   r   re   r   r$   rz   r2   r   r   <module>r      s    @ "  ( * :  ; 	=5 )-hh%h h 	h
 h h hr   