
    3j
                   L   d Z ddlmZ ddlZddlZddlZddlZddlZej                  rddl
ZddlZddlmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlmZ  ej0                  d	      Z G d
 dej4                        Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d de      Z$ G d dejJ                        Z& G d  d!ejJ                        Z'e(d"k(  rddlZ ejR                  e&       yy)#a  
Object definitions for graphing and plotting :class:`~music21.stream.Stream` objects.

The :class:`~music21.graph.primitives.Graph` object subclasses primitive,
abstract fundamental graphing archetypes using the matplotlib library.

From the highest level to the lowest level of usage, ways of graphing are as follows:

    1. streamObj.plot('graphName')
    2. graph.plot.Class(streamObj).run()
    3. plotter = graph.primitives.Class(); plotter.data = ...; plotter.process()
    4. Use matplotlib directly to create your graph.
    )annotationsN)common)SubConverter)environment)getExtendedModulesGraphExceptiongetColoraccidentalLabelToUnicode)prebasezgraph.primitivesc                  `   e Zd ZU dZdZdZded<   dZded<   d	Zded
<   d dZ	d dZ
d!dZd"dZed#d       Zej                  d$d       Zd%dZ	 	 	 	 	 	 d&dZ	 	 d'	 	 	 	 	 	 	 d(dZ	 d)	 	 	 	 	 	 	 d*dZd+d,dZed+d-d       Zd.dZd.dZ	 	 	 	 	 	 d/dZd dZd.dZd0d1dZd dZ	 d0	 	 	 d2dZy)3Grapha  
    A music21.graph.primitives.Graph is an object that represents a visual graph or
    plot, automating the creation and configuration of this graph in matplotlib.
    It is a low-level object that most music21 users do not need to call directly;
    yet, as most graphs will take keyword arguments that specify the
    look of graphs, they are important to know about.

    The keyword arguments can be provided for configuration are:

    *    doneAction (see below)
    *    alpha (which describes how transparent elements of the graph are)
    *    dpi
    *    colorBackgroundData
    *    colorBackgroundFigure
    *    colorGrid,
    *    title (a string)
    *    figureSize (a tuple of two ints)
    *    colors (a list of colors to cycle through)
    *    tickFontSize
    *    tickColors (a dict of 'x': '#color', 'y': '#color')
    *    titleFontSize
    *    labelFontSize
    *    fontFamily
    *    hideXGrid
    *    hideYGrid
    *    xTickLabelRotation
    *    marker
    *    markersize

    Graph objects do not manipulate Streams or other music21 data; they only
    manipulate raw data formatted for each Graph subclass, hence it is
    unlikely that users will call this class directly.

    The `doneAction` argument determines what happens after the graph
    has been processed. Currently, there are three options, 'write' creates
    a file on disk (this is the default), while 'show' opens an
    interactive GUI browser.  The
    third option, None, does the processing but does not write any output.

    figureSize:

        A two-element iterable.

        Scales all graph components but because of matplotlib limitations
        (esp. on 3d graphs) no all labels scale properly.

        defaults to .figureSizeDefault

    >>> a = graph.primitives.Graph(title='a graph of some data to be given soon', tickFontSize=9)
    >>> a.data = [[0, 2], [1, 3]]
    >>> a.graphType
    'genericGraph'
    genericGraphxytuple[str, ...]axisKeys)   r   ztuple[int | float, ...]figureSizeDefault)alphacolorBackgroundDatacolorBackgroundFigure	colorGridcolors
doneActiondpi
figureSize
fontFamily	hideXGrid	hideYGridlabelFontSizemarker
markersize
tickColorstickFontSizetitletitleFontSizexTickLabelHorizontalAlignmentxTickLabelRotationxTickLabelVerticalAlignmentkeywordConfigurablesc                   t               }|j                  | _        d | _        d | _        d | _        i | _        | j                  D ]#  }i | j
                  |<   d | j
                  |   d<   % d| _        i | _        | j                  D ]  }d| j                  |<    d| _	        d | _
        d| _        d| _        d| _        d| _        | j                  | _        d| _        d	| _        g d
| _        d| _        ddd| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _         | jB                  D ]  }||v stE        | |||           y )NrangeTF皙?z#ffffffz#ddddddzMusic21 Graphor   )z#605c7fz#5c7f60z#988969z#628297z#ad776dz#80a364   #000000r      
   serifr   centerwrite)#r   pltdatafiguresubplotaxisr   gridaxisRangeHasBeenSetr   r   r   r   r   r&   r   r   r"   r#   r   r%   r$   r'   r!   r   r   r    r)   r(   r*   hideLeftBottomSpines_doneAction_dataColorIndexr+   setattr)selfkeywordsextmaxaxisKeykws         E/DATA/.local/lib/python3.12/site-packages/music21/graph/primitives.py__init__zGraph.__init__   ss   !#88!%	7;48 &(	--BDIIbM%)DIIbM'"   	46 }}G05D$$W- %  
#(1 *3"')
373I3I "
 "#09	*J"$"$&$$'(2:*08(*/!'.$%++BX~b(2,/ ,    c                    t        | d      r3| j                  &| j                  j                  | j                         yyy)z]
        Matplotlib Figure objects need to be explicitly closed when no longer used.
        r9   N)hasattrr9   r7   closerB   s    rH   __del__zGraph.__del__   s3     4"t{{'>HHNN4;;' (?"rJ   c                @    | j                   j                         }|d= |S )zc
        The wrapper to matplotlib.pyplot stored as self.plt cannot be pickled/deepcopied.
        r7   )__dict__copy)rB   states     rH   __getstate__zGraph.__getstate__   s"     ""$%LrJ   c                p    | j                   j                  |       t               }|j                  | _        y N)rQ   updater   r7   )rB   rS   rD   s      rH   __setstate__zGraph.__setstate__   s'    U#!#88rJ   c                    | j                   S )z{
        returns or sets what should happen when the graph is created (see docs above)
        default is 'write'.
        )r?   rN   s    rH   r   zGraph.doneAction   s     rJ   c                6    |dv r|| _         y t        d|       )N)showr6   Nzno such done action: )r?   r   )rB   actions     rH   r   zGraph.doneAction   s&    ,,%D #8!ABBrJ   c                    t        | j                  | j                  t        | j                        z           }| xj                  dz  c_        |S )ah  
        Utility function that cycles through the colors of self.colors.

        >>> g = graph.primitives.Graph()
        >>> g.colors = ['#605c7f', '#5c7f60', '#715c7f']

        >>> g.nextColor()
        '#605c7f'

        >>> g.nextColor()
        '#5c7f60'

        >>> g.nextColor()
        '#715c7f'

        >>> g.nextColor()
        '#605c7f'
           )r	   r   r@   len)rB   cs     rH   	nextColorzGraph.nextColor   sA    & T[[!5!5DKK8H!HIJ!rJ   c                    |y|| j                   vrt        d| d      g }g }|D ]'  \  }}|j                  |       |j                  |       ) ||f| j                   |   d<   y)a|  
        Set the tick-labels for a given graph or plot's axisKey
        (generally 'x', and 'y') with a set of pairs

        Pairs are iterables of positions and labels.

        N.B. -- both 'x' and 'y' ticks have to be set in
        order to get matplotlib to display either (and presumably 'z' for 3D graphs).

        >>> g = graph.primitives.GraphHorizontalBar()
        >>> g.axis['x']['ticks']
        Traceback (most recent call last):
        KeyError: 'ticks'
        >>> g.axis['x']
        {'range': None}

        >>> g.setTicks('x', [(0, 'a'), (1, 'b')])
        >>> g.axis['x']['ticks']
        ([0, 1], ['a', 'b'])

        >>> g.setTicks('m', [('a', 'b')])
        Traceback (most recent call last):
        music21.graph.utilities.GraphException: Cannot find key 'm' in self.axis

        >>> g.setTicks('x', [])
        >>> g.axis['x']['ticks']
        ([], [])
        NzCannot find key 'z' in self.axisticks)r;   r   append)rB   rF   pairs	positionslabelsvaluelabels          rH   setTickszGraph.setTicks   sy    > =$))# #4WI^!LMM	!LE5U#MM%  " '0&7		'7#rJ   c                    t        t        |            }t        ||z        }g }|dk  rd}t        d|dz   |      D ]  }|j	                  || f        | j                  ||       y)a  
        Set the ticks for an axis (usually 'y') given unsorted data.

        Data steps shows how many ticks to make from the data.

        >>> g = graph.primitives.GraphHorizontalBar()
        >>> g.setIntegerTicksFromData([10, 5, 3, 8, 20, 11], dataSteps=4)
        >>> g.axis['y']['ticks']
        ([0, 5, 10, 15, 20], ['0', '5', '10', '15', '20'])

        TODO: should this not also use min? instead of always starting from zero?
        r^      r   N)intmaxroundr-   rd   rj   )rB   unsortedDatarF   	dataStepsmaxDatatickSteptickListr   s           rH   setIntegerTicksFromDatazGraph.setIntegerTicksFromData)  sj      c,'(9,-*,q=Hq'A+x0AOOQ1#K( 1gx(rJ   c                    || j                   vrt        d|       |dk7  r|d   |d   z
  }||z  }nd}|d   |z
  |d   |z   f| j                  |   d<   d| j                  |<   y)aM  
        Set the range for the axis for a given axis key
        (generally, 'x', or 'y')

        ValueRange is a two-element tuple of the lowest
        number and the highest.

        By default, there is a padding of 10% of the range
        in either direction.  Set paddingFraction = 0 to
        eliminate this shift
        No such axis exists: r   r^   r-   TN)r   r   r;   r=   )rB   rF   
valueRangepaddingFraction
totalRangeshifts         rH   setAxisRangezGraph.setAxisRangeC  s     $--' #8	!BCCa#AA6J0EE'1!}u'<'1!}u'<'>		'7# -1  )rJ   c                    || j                   vrt        d|       |r$d| j                  |   v r| j                  |   d   ry || j                  |   d<   y )Nrw   ri   )r   r   r;   )rB   rF   ri   conditionals       rH   setAxisLabelzGraph.setAxisLabel`  s[    $--' #8	!BCC7dii&88TYYw=OPW=X&+		'7#rJ   c                   | j                   j                         D ]A  \  }}|dv r|s|j                  d       |dv r|j                  d       5t        d|        t	        | j                         | j                         z         D ]3  \  }}|r|j                  d       |dz  dk(  s#|j                  d       5 y)	a  
        Remove the right and top spines from the diagram.

        If leftBottom is True, remove the left and bottom spines as well.

        Spines are removed by setting their colors to 'none' and every other
        tick line set_visible to False.
        leftbottomnone)righttopzunknown spine location: Frl   r^   N)spinesitems	set_color
ValueError	enumerateget_xticklinesget_yticklinesset_visible)r:   
leftBottomlocspineilines         rH   hideAxisSpineszGraph.hideAxisSpinesh  s     "....0JC((OOF+ ((' #;C5!ABB 1 !!7!7!9G<R<R<T!TUGAt  'Q!  '	 VrJ   c                >   t         j                  dt        |      z          |j                  }|j	                  t        | j                               | j                  D ]  }| j                  ||        | j                  r2|j                  | j                  | j                  | j                         | j                  D ]V  }|| j                  vr|j                  t        j                   t        j"                  d   |      | j                  |          X | j%                  |       | j&                  t)        d      | j&                  J | j&                  j+                  | j,                  d          | j&                  j/                  | j,                  d          y)	z
        Apply formatting to the Subplot (Axes) container and Figure instance.

        ax should be an AxesSubplot object or
        an Axes3D object or something similar.
        zcalling applyFormatting on fontsizefamily)bothr   r   )r;   r   Nz>Cannot apply formatting without a figure; call process() firstr   r^   )environLocal
printDebugreprpatchset_facecolorr	   r   r   applyFormattingToOneAxisr&   	set_titler'   r   r$   tick_paramstcastLiteral	applyGridr9   r   set_figwidthr   set_figheight)rB   r:   rectr;   thisAxisNames        rH   applyFormattingzGraph.applyFormatting  sL    	 =W MN}}8D$<$<=> MMD))'48 " ::djj43E3Edoo^ !MML4??2VVAII&67F|4   6 * 	w ;;]^^{{&&&  !34!!$//!"45rJ   c                B   | j                   rD| j                  8|j                  d       |j                  ddt        | j                               | j                  r|j
                  j                  d       | j                  r|j                  j                  d       yy)zQ
        Apply the Grid to the subplot such that it goes below the data.
        NTmajor)whichcolorF)r<   r   set_axisbelowr	   r    yaxisr   xaxisrB   r:   s     rH   r   zGraph.applyGrid  st    
 993!!$'LLWHT^^4LLM>>MMu%>>MMu% rJ   c           	        | j                   |   }|dvryd|v r>|d   9d|z   dz   }t        | j                        dk(  r|dz  }t        ||      } ||d     d|v r9|d   4t        |d|z   dz         } ||d   | j                  | j
                  	       d
|v r"|d
   t        |d|z   d
z         } ||d
          	 t        |d|z   dz         }t        |d|z   dz         }t        |d|z   dz         }	d|vr2|	0 |       }
 ||
        |	|
| j                  | j
                  	       |S |d   \  }}| ||       |dk(  rL|j                  || j                  | j
                  | j                  | j                  | j                  d       |S |dk(  r,|j                  || j                  | j
                  dd       |S t        |	      r |	|| j                  | j
                  	       |S # t        $ r
 d}d}d}	Y w xY w)al  
        Given a matplotlib.Axes object (a subplot) and a string of
        'x', 'y', or 'z', set the Axes object's xlim (or ylim or zlim or xlim3d, etc.) from
        self.axis[axis]['range'], Set the label from self.axis[axis]['label'],
        the scale, the ticks, and the ticklabels.

        Returns the matplotlib Axis object that has been modified
        r   r   zNr-   set_lim   3dri   r   scaleget_rc   
ticklabelsr   g{Gz)r   r   horizontalalignmentverticalalignmentrotationr   r   r   r5   r   r   r   r   )r;   r_   r   getattrr!   r   AttributeErrorr%   set_xticklabelsr(   r*   r)   set_yticklabelscallable)rB   r:   r;   thisAxisrangeFuncNamethisRangeFuncsetLabelFunctiongetTickFunctionsetTickFunctionsetTickLabelFunctionrc   valuesrg   s                rH   r   zGraph.applyFormattingToOneAxis  sm    99T?&h8G#4#@"TME1M4==!Q&%#G];M8G,-h8G#4#@&w0GHXg.&*&8&8R h8G#4#@&w0GHXg./	(%gv}w/FGO%gv}w/FGO#*7FTML4P#Q  ("';'G#%EE" *.*;*;(,98 1 &g.NFF*'s{''151B1B/3<@<^<^:>:Z:Z151H1H*/ ( 1(  ''151B1B/3<C:B	 ( D  ./$V.2.?.?,0OO= M  	("O"O#' 		(s   ;6G' 'G:9G:c                   t               }|j                  }|j                  | j                        | _        | j                  j	                  ddd      | _        d| _        | j                  | j
                         | j                  | j
                  | j                         | j                  | j
                         | j                          y)a  
        Creates the figure and subplot, calls renderSubplot to get the
        subclass specific information on the data, runs hideAxisSpines,
        applyFormatting, and then calls the done action.  Returns None,
        but the subplot is available at self.subplot
        )	facecolorr^   r   )r   N)r   r7   r9   r   add_subplotr:   r@   renderSubplotr   r>   r   callDoneActionrB   rD   r7   s      rH   processzGraph.process  s     "#hh
 jj4+E+EjF{{..q!Q7 4<<( 	DLLT5N5NOT\\*rJ   c                     y)zI
        Calls the subclass specific information to get the data
        N r   s     rH   r   zGraph.renderSubplot*  s     	rJ   Nc                    | j                   dk(  r| j                          y| j                   dk(  r| j                  |       y| j                   yy)zI
        Implement the desired doneAction, after data processing
        r[   r6   N)r   r[   r6   )rB   fps     rH   r   zGraph.callDoneAction1  sB     ??f$IIK__'JJrN__$ %rJ   c                    | j                   t        d      | j                   J | j                   j                          y)z
        Calls the show() method of the matplotlib plot.
        For most matplotlib back ends, this will open
        a GUI window with the desired graph.
        Nz8Cannot show graph without a figure; call process() first)r9   r   r[   rN   s    rH   r[   z
Graph.show<  s:     ;;WXX{{&&&rJ   c                r   | j                   t        d      | j                   J |t        j                  d      }| j                  }|d}| j                   j                  ||       t        j                         s/t               j                  t        j                  |      d       y| j                   S )za
        Writes the graph to a file. If no file path is given, a temporary file is used.
        Nz9Cannot write graph without a figure; call process() first.png,  )r   png)fmt)r9   r   r   getTempFiler   savefigr   runningInNotebookr   launchpathlibPath)rB   r   r   s      rH   r6   zGraph.writeG  s     ;;XYY{{&&&:))&1Bhh;CB !$ 	 	%
 '')N!!',,r"2!>;;rJ   returnNone)r   dict)rS   r   r   r   )r   
str | None)r\   r   r   r   )r   str)rF   r   re   z%t.Iterable[t.Sequence[object]] | Noner   r   )r      )rp   zt.Sequence[int | float]rF   r   rq   rm   r   r   )皙?)rF   r   rx   ztuple[int | float, int | float]ry   floatr   r   )F)rF   r   ri   r   r~   boolr   r   )r:   matplotlib.axes.Axesr   r   r   r   r:   r   r   r   )r:   r   r;   r   r   zdict | NonerV   )r   r   r   r   )r   zstr | pathlib.Path | Noner   zmatplotlib.figure.Figure | None)__name__
__module____qualname____doc__	graphTyper   __annotations__r   r+   rI   rO   rT   rX   propertyr   setterra   rj   ru   r|   r   staticmethodr   r   r   r   r   r   r   r[   r6   r   rJ   rH   r   r   2   so   4j I *Ho*/5,5-/ 0;0z(
     C C.,8,8=,8BF,8` 0312).E)),) ,/) 8<): /21!1!@1 ',1 7;1:, ( (6(6\& K*>K'*K/:KZ6		 /3+2rJ   r   c                  p     e Zd ZU dZddiZded<   dZdZej                  dz   Z	d	ed
<   d fdZ
ddZ xZS )GraphColorGrida  
    Grid of discrete colored "blocks" to visualize results of a windowed analysis routine.

    Data is provided as a list of lists of colors, where colors are specified as a hex triplet,
    or the common HTML color codes, and based on analysis-specific mapping of colors to results.

    >>> #_DOCS_SHOW g = graph.primitives.GraphColorGrid()
    >>> g = graph.primitives.GraphColorGrid(doneAction=None) #_DOCS_HIDE
    >>> data = [['#55FF00', '#9b0000', '#009b00'],
    ...         ['#FFD600', '#FF5600'],
    ...         ['#201a2b', '#8f73bf', '#a080d5', '#403355', '#999999']]
    >>> g.data = data
    >>> g.process()

    .. image:: images/GraphColorGrid.*
        :width: 600
    r>   :bool to hide the left and bottom axis spines; default Truedict[str, str]	_DOC_ATTRr   )	   r   r>   r   r+   c                2    d| _         t        |   di | y )NTr   )r>   superrI   rB   rC   	__class__s     rH   rI   zGraphColorGrid.__init__}  s    $(!$8$rJ   c           
        | j                   t        d      | j                   J | j                  t        d      | j                  J | j                   j                  d       t	        | j                        }t        |      D ]  }| j                  |   }g }g }g }t        |      D ];  \  }}	|j                  |dz          |j                  |	       |j                  d       = | j                   j                  |d||z
        }
|
j                  ||d|ddd	
       |
j                  j                         D ]8  \  }}|j                  d       |j                  d       |j                  d       : t        |
j                         |
j!                         z         D ]  \  }}|j#                  d	        |
j%                  g        |
j'                  g        |
j)                  dgt	        |
j+                               z         |
j-                  dgt	        |
j/                               z         |
j1                  dt	        | j                  |         f       |
j3                         j#                  d	       |
j5                         j#                  d	        |dkD  r| j                   j                  d       n| j                   j                  d       d}| j7                  d|d       d	| _        y )N<Cannot render subplot without a figure; call process() firstJCannot render subplot without data; set self.data before calling process()333333?r         ?r^   333333?r1   F)r   	linewidth	edgecolorantialiased r   r2   )hspacer   r   r^   r   )r9   r   r8   subplots_adjustr_   r-   r   rd   r   barr   r   set_linewidthr   	set_alphar   r   r   
set_xticks
set_yticksr   get_yticklabelsr   get_xticklabelsset_xlim	get_xaxis	get_yaxisr|   r<   )rB   r:   rowCountr   thisRowDatarf   heights	subColorsj	thisColorrE   
unused_locr   r   axisRangeNumberss                  rH   r   zGraphColorGrid.renderSubplot  s   ;;[\\{{&&&99 F G Gyy$$$ 	###.tyy>xA))A,KIGI )+ 69  U+  +q! !7 ((1hlCB FF9" &$  & &(YY__%6!
E##C(	*"	 &7 %R%6%6%82;L;L;N%NO4  ' PMM"MM"tc"*<*<*>&??@tc"*<*<*>&??@KKC		!-./ LLN&&u-LLN&&u-] !d b=KK''q'1KK''s'3!#/3 	rJ   r   r   )r   r   r   r   r   r   r   r   r   r+   rI   r   __classcell__r  s   @rH   r   r   c  sM    $ 	 \!I~  I,1,F,FIb,b/b%PrJ   r   c                       e Zd ZU dZddiZded<   dZdZej                  dz   Z	d	ed
<   d fdZ
ddZ	 	 	 	 	 	 	 	 	 	 ddZ xZS )GraphColorGridLegenda  
    Grid of discrete colored "blocks" where each block can be labeled

    Data is provided as a list of lists of colors, where colors are specified as a hex triplet,
    or the common HTML color codes, and based on analysis-specific mapping of colors to results.

    >>> #_DOCS_SHOW g = graph.primitives.GraphColorGridLegend()
    >>> g = graph.primitives.GraphColorGridLegend(doneAction=None) #_DOCS_HIDE
    >>> data = [
    ...         ('Major', [('C#', '#00aa55'), ('D-', '#5600ff'), ('G#', '#2b00ff')]),
    ...         ('Minor', [('C#', '#004600'), ('D-', '#00009b'), ('G#', '#00009b')])
    ... ]
    >>> g.data = data
    >>> g.process()

    .. image:: images/GraphColorGridLegend.*
        :width: 600

    r>   r   r   r   colorGridLegend)         ?r   r   r+   c                J    d| _         t        |   di | d|vrd| _        y y )NTr&   Legendr   )r>   r  rI   r&   r  s     rH   rI   zGraphColorGridLegend.__init__  s/    $(!$8$("!DJ #rJ   c                   | j                   t        d      | j                   J | j                  t        d      | j                  J t        | j                        D ]-  \  }}|d   }|d   }| j	                  | j                   |||       / | j                  ddd       |j                         |j                         z   }t        |      D ]  \  }}|j                  d        | j                   j                  dd	d
       | j                  dd       | j                  dd       | j                  dg        | j                  dg        y )Nr  r  r   r^   r   r  Fr+  g      ?r.   )r  r   r   r   r  )r9   r   r8   r   makeOneRowOfGraphr|   r   r   r   r  r   rj   )	rB   r:   r   rowLabelAndDatarowLabelrowDataallTickLinesr!  r   s	            rH   r   z"GraphColorGridLegend.renderSubplot  sC   ;;[\\{{&&&99 F G Gyy$$$"+DII"6A&q)H%a(G""4;;8WE #7
 	#vq)--/'2H2H2JJ .GAtU# / 	##3D#E#r"#r"c2c2rJ   c                L   | j                   t        d      | j                   J g }g }g }t        |      D ]>  \  }}	|j                  d|z          |j                  |	d          |j                  d       @ t	        | j                         d|dz   f}
 |j
                  |
 }d}|j                  ||||dd       |j                  j                         D ]$  }|j                  d       |j                  d       & |j                         |j                         z   }t        |      D ]  \  }}|j                  d        |j                  dg       |j                  |g| j                   | j"                  d	d
       |j%                  t'        t	        |            D cg c]  }|dz   	 c}       |D cg c]  \  }}t)        |       }}}|j+                  || j                   | j"                  d
d
d       |j-                  dt	        |      dz   f       |S c c}w c c}}w )a  
        Makes a subplot for one row of data (such as for the Major label)
        and returns a matplotlib.axes.AxesSubplot instance representing the subplot.

        Here we create an axis with a part of Scriabin's mapping of colors
        to keys in Prometheus: The Poem of Fire.

        >>> import matplotlib.pyplot

        >>> colorLegend = graph.primitives.GraphColorGridLegend()
        >>> rowData = [('C', '#ff0000'), ('G', '#ff8800'), ('D', '#ffff00'),
        ...            ('A', '#00ff00'), ('E', '#4444ff')]
        >>> colorLegend.data = [['Scriabin Mapping', rowData]]

        >>> fig = matplotlib.pyplot.figure()
        >>> subplot = colorLegend.makeOneRowOfGraph(fig, 0, 'Scriabin Mapping', rowData)
        >>> subplot
        <Axes: >
        zOCannot create row of graph without data; set self.data before calling process()      ?r^   r  r1   )r   r  r  Fr
  r   r5   r   gٿ)r   r   r   r   r   )r8   r   r   rd   r_   r   r  r   r   r  r   r   r   r   r  r   r%   r   r  r-   r
   r   r  )rB   r9   rowIndexr1  r2  rf   r  r   r!  oneColorMapping	posTriplerE   widthspineArtistr3  r   r   unused_ysubstitutedAccidentalLabelss                      rH   r/  z&GraphColorGridLegend.makeOneRowOfGraph  s<   2 99 F G Gyy$$$ 		"+G"4AS1W%_Q/0NN1 #5 ^Q15	V+ 
y'5	ST]^ 99++-K%%c*!!), . ((*R->->-@@ .GAtU# / 	se
H:$($5$5"&///6-5	 	 	7 	eCL&9:&9q1u&9:; ;B'C:A;1h (@'B:A 	$ 'C
'&&?? (& 	 	 	S#g,,-.	 ;'Cs   H7H r   r   )
r9   zmatplotlib.figure.Figurer6  rm   r1  r   r2  zlist[tuple[str, str]]r   r   )r   r   r   r   r   r   r   r   r   r+   rI   r   r/  r%  r&  s   @rH   r(  r(    s    ( 	 \!I~  "I ,1,F,FIb,b/b"<U":U$'U %(U $9	U >R	UrJ   r(  c                       e Zd ZU dZdddZded<   dZdZej                  dz   Z	d	ed
<   d fdZ
ed        ZddZ xZS )GraphHorizontalBara  
    Numerous horizontal bars in discrete channels, where bars
    can be incomplete and/or overlap.

    Data provided is a list of pairs, where the first value becomes the key,
    the second value is a list of x-start, x-length values.

    Note how the second element in each data point is the length, so
    subtracting death year from birth year gives the appropriate length.

    Example: Plot the life-span of four composers whose lives were intertwined:
    Chopin, Robert and Clara Schumann, and Brahms.

    >>> a = graph.primitives.GraphHorizontalBar()
    >>> a.doneAction = None #_DOCS_HIDE
    >>> data = [('Chopin', [(1810, 1849-1810)]),
    ...         ('Schumanns', [(1810, 1856-1810), (1819, 1896-1819)]),
    ...         ('Brahms', [(1833, 1897-1833)])]
    >>> a.data = data
    >>> a.process()

    .. image:: images/GraphHorizontalBar.*
        :width: 600

    Data is a list of tuples in the form, where each entry represents a space on the
    Y axis:

        * Label
        * List of tuples of numeric data where each tuple has two or three elements:
            * Start x-position
            * Length of bar
            * Optional: dictionary of format information about this point.
        * Optional: dictionary of format information for all points at this level.
          (this will be overridden by any information for the particular point)

    To make an equally spaced plot, like in a Pitch Space plot, leave empty data in the form:

        `('', [], {})`

    2Amount of vertical space each bar takes; default 8zj
            Vertical space above and below the bars, default 2 (= total4 space between bars)
            barSpacemarginr   r   horizontalBarr3      r   r+   c                X    d| _         d| _        t        |   di | d|vrd| _        y y )Nr   rl   r   333333?r   rA  rB  r  rI   r   r  s     rH   rI   zGraphHorizontalBar.__init__  s5    $8$("DJ #rJ   c                :    | j                   | j                  dz  z
  S Nrl   r@  rN   s    rH   	barHeightzGraphHorizontalBar.barHeight      }}a00rJ   c                P   | j                   t        d      | j                   J | j                  t        d      | j                  J | j                   j                  d       d}t	               }g }g }g }d}| j                  D ]k  }t        |      dk(  r|\  }	}
i }n|\  }	}
}|j                  |	       |j                  d| j                               }|
rt        |
d         dk(  }|r|}|
}n4|
D cg c]  }|d   j                  d|       }}|
D cg c]  }|d d 	 }}|| j                  z   | j                  f}|j                  |||| j                         |
D ]W  }t        |      dk\  r	|d d \  }}nt        d	t        |       d
|       ||z   }||fD ]  }||vs|j                  |        Y |j                  || j                  dz  z   |	g       || j                  z  }|dz  }n d}d}|rt        |      }t!        |      }||z
  }| j#                  ddt        |      | j                  z  f       | j#                  d||f       | j%                  d|       d| j&                  d   v r| j&                  d   d   st)        |t+        |dz        z         }|dk(  rd}t-        t)        t/        j0                  |            t+        t/        j2                  |            |      D ]  }|j                  || g        | j%                  d|       y y y c c}w c c}w )Nr  r  r  r	  r   rl   r   )
facecolorsr   z"Points must be length 2 or 3, not z: r
  r^           r   r   rc   r3   )r9   r   r8   r  setr_   rd   getra   rB  rK  broken_barhr   addrA  minrn   r|   rj   r;   rm   ro   r-   mathfloorceil)rB   r:   yPosxPointsyTicksxTickskeysr   infokeypointsfullRowFormatDict	faceColoruniformFormatPerRowrowFaceColorspositionPointspyRangexStartxLenxEndr   xMinxMaxxRange	rangeSteps                             rH   r   z GraphHorizontalBar.renderSubplot  sO   ;;[\\{{&&&99 F G Gyy$$$###."%%IID4yA~"V$&!15.V.KK *--gt~~7GHI'*6!9~':#&$-M%+NKQ$R6aQqTXXgy%A6M$R5;%<VaeVN%<,..* ##N$*/<*.** $ 6  A1v{'(!u(+McRSfXUWXYWZ)[\\!D=D$d^G+#KKN ,   MM4$--#"55s;<DMM!DFAU X w<Dw<D 	#3t9t}}#<=>#d|,c6" diin$TYYs^G-DD5"#556IA~	3tzz$/0 41$& qQCk*& MM#v& .E$O %S%<s   6LL#r   r   r   r   r   r   r   r   r   r   r   r+   rI   r   rK  r   r%  r&  s   @rH   r>  r>  n  sl    'R I!I~   I,1,F,F J -/ 
 1 1S'rJ   r>  c                       e Zd ZU dZdddZded<   dZdZej                  dz   Z	d	ed
<   d fdZ
ed        ZddZ xZS )GraphHorizontalBarWeightedz
    Numerous horizontal bars in discrete channels,
    where bars can be incomplete and/or overlap, and
    can have different heights and colors within their
    respective channel.
    r?  z Space around the bars, default 2r@  r   r   horizontalBarWeightedrD  r   r+   c                X    d| _         d| _        t        |   di | d|vrd| _        y y )Nr         ?r   r^   r   rH  r  s     rH   rI   z#GraphHorizontalBarWeighted.__init__  s7    !$8$ ("DJ #rJ   c                :    | j                   | j                  dz  z
  S rJ  r@  rN   s    rH   rK  z$GraphHorizontalBarWeighted.barHeight.  rL  rJ   c           
     F   | j                   t        d      | j                   J | j                  t        d      | j                  J | j                   j                  d       d}g }g }g }d}t	        | j                        | _        | j                  j                          | j                  D ]  \  }}|j                  |       g }	g }
g }g }t        |      D ]h  \  }}d}d }d}| j                         }| j                  }d}t        |      dk(  r|\  }}}nDt        |      dk(  r|\  }}}}n.t        |      d	k(  r	|\  }}}}}nt        |      d
k(  r	|\  }}}}}}t        |      }|t        d|       |J |	j                  ||f       |j                  |       |j                  |       ||vr|j                  |       ||z   |vr|j                  ||z          | j                  |z  }| j                  |z
  dz  }| j                  d|z
  z  dz  }|| j                  z   |z   ||z  z   }|
j                  ||f       k t        |	      D ](  \  }}|j                  |g|
|   ||   ||   ||          * |j                  || j                  dz  z   |g       || j                  z  }|dz  } t!        |      }t#        |      }| j%                  ddt        |      | j                  z  fd       | j%                  d||fd       | j'                  d|       y )Nr  r  r  r	  r   r^   r   rE  r*  r   zLData point must have at least 3 elements (x, span, heightScalar, ...); got: r
  )rN  r   r  r   皙?)ry   r   g{Gz?)r9   r   r8   r  listreverserd   r   ra   r   r_   r	   rK  rB  rR  rA  rT  rn   r|   rj   )rB   r:   rX  rY  rZ  r\  r   r^  r_  xRangesyRangesalphasr   r8   r   spanheightScalarr   r   yShifthyAdjust
yShiftUnit	adjustedYrl  rj  rk  s                              rH   r   z(GraphHorizontalBarWeighted.renderSubplot2  s`   ;;[\\{{&&&99 F G Gyy$$$###. O			99KCKKGGFF$V,4 (

t9>,0)At\Y!^370At\5Y!^:>7At\5%Y!^BF?At\5% <$ (KKO&&R S S'''4y)e$e$G#NN1%HW,NN1t8,
 NN\1>>A-4!^^q</?@3F
 4;;.8J<OP		1~.O -R 'w/	6 ##VH$+AJ/5ay*0).4Qi	 $ 9 0 MM4$--#"55s;<DMM!DFAy %| 7|7|
 	#3t9t}}#<=tT#d|TBc6"rJ   r   r   rn  r&  s   @rH   rp  rp    si     I4!I~ 
 (I,1,F,F J -/ 
$ 1 1[#rJ   rp  c                       e Zd ZU dZdddZded<   dZdZej                  dz   Z	d	ed
<   d fdZ
ed        ZddZ xZS )GraphScatterWeighteda  
    A scatter plot where points are scaled in size to
    represent the number of values stored within.

    >>> g = graph.primitives.GraphScatterWeighted()
    >>> g.doneAction = None #_DOCS_HIDE
    >>> data = [(23, 15, 234), (10, 23, 12), (4, 23, 5), (15, 18, 120)]
    >>> g.data = data
    >>> g.process()

    .. image:: images/GraphScatterWeighted.*
        :width: 600

    z1the maximum diameter of any ellipse, default 1.25z1the minimum diameter of any ellipse, default 0.25maxDiameterminDiameterr   r   scatterWeighted)r*  r*  r   r+   c                X    d| _         d| _        t        |   di | d|vrd| _        y y )Ng      ?rs  r   rG  r   )r  r  r  rI   r   r  s     rH   rI   zGraphScatterWeighted.__init__  s7    "&"&$8$("DJ #rJ   c                4    | j                   | j                  z
  S rV   r  rN   s    rH   rangeDiameterz"GraphScatterWeighted.rangeDiameter  s    $"2"222rJ   c           
     X   | j                   t        d      | j                   J | j                  t        d      | j                  J t               }|j                  }| j                   j                  dd       | j                  D cg c]  }|d   	 }}| j                  D cg c]  }|d   	 }}| j                  D cg c]  }|d   	 }}g }| j                  D ])  }t        |      dkD  r|d   }	ni }	|j                  |	       + t        |      }
t        |      }t        |
|z
        }t        |      }t        |      }t        ||z
        }t        |      }t        |      }t        ||z
        }d	}d	}||kD  r||z  }n
||kD  r||z  }g }|D ]Z  }|dk(  r|j                  ddg       |dk7  r	||z
  |z  }nd
}| j                  | j                  |z  z   }|j                  ||g       \ t        t        | j                              D ]  }||   }||   }||   \  }}||   }	||z  }||z  } |j                  d||f||d|	}|j                  |       |j!                  |j"                         |j%                  | j&                         |j)                  | j+                                ||   dkD  s||d
z  d|z  z   z   } |dz   }!|j-                  | |!t/        ||         dddd        | j1                  d||f       | j1                  d||
f       y c c}w c c}w c c}w )Nr  r  r  r   r   r^   rl   r   r5  r
  )xyr9  heightrv  r   r   baseliner   )sizevahamultialignmentr   r   r   )r9   r   r8   r   patchesr  r_   rd   rn   rT  r   r  r  r-   Ellipse
add_artistset_clip_boxbboxr  r   r   ra   textr   r|   )"rB   r:   rD   r  dxListyListzListformatDictList
formatDictrk  rj  rl  yMaxyMinrf  zMaxzMinzRangexDistortyDistortzNormr   scalarscaledr   r   r   unused_zScalarr9  r  e	adjustedXr  s"                                     rH   r   z"GraphScatterWeighted.renderSubplot  sX   ;;[\\{{&&&99 F G Gyy$$$!#,, 	##d#;  $yy)y!1y)#yy)y!1y)#yy)y!1y)A1vzqT

!!*-  5z5ztd{#5z5ztd{#5z5ztd{#
 F?Hf_H AAvaV$ Q;$h&0F F))T-?-?&-HIff-.  s499~&AaAaA %aA~'*JLE\FTAq6vTTAq!NN7<<(KK

#OODNN,-
 Qx!|
 %#+$/!BC	H	Y& q]"# * &,2  49 'H 	#d|,#d|,k *))s   L(L"L'r   r   )r   r   r   r   r   r   r   r   r   r+   rI   r   r  r   r%  r&  s   @rH   r  r    si     KJ!I~ 
 "I,1,F,F J& -&/ & 3 3d-rJ   r  c                      e Zd ZdZdZddZy)GraphScatteraP  
    Graph two parameters in a scatter plot.
    Data representation is a list of points of values.

    >>> g = graph.primitives.GraphScatter()
    >>> g.doneAction = None #_DOCS_HIDE
    >>> data = [(x, x * x) for x in range(50)]
    >>> g.data = data
    >>> g.process()

    .. image:: images/GraphScatter.*
        :width: 600
    scatterc           	     l   | j                   t        d      | j                   J | j                  t        d      | j                  J | j                   j                  d       g }g }d}| j                  D ]  }t	        |      dk  rt        d      |d   }|d   }|j                  |       |j                  |       | j                  }| j                         }	| j                  }
| j                  }t	        |      d	k\  r)|d   }d
|v r|d
   }	d|v r|d   }d|v r|d   }
d|v r|d   }|j                  ||||	|
|       |dz  } | j                  d   s&| j                  dt        |      t        |      f       | j                  d   s'| j                  dt        |      t        |      f       y y )Nr  r  r  r	  r   rl   z1Need at least two points for a graph data object!r^   r   r   r"   r   r#   )r"   r   r   r#   r   r   )r9   r   r8   r  r_   r   rd   r"   ra   r   r#   plotr=   r|   rT  rn   )rB   r:   xValuesyValuesr   rowr   r   r"   r   r   r#   displayDatas                rH   r   zGraphScatter.renderSubplot:  s   ;;[\\{{&&&99 F G Gyy$$$###.99C3x!|$%XYYAAAANN1NN1[[FNN$EJJEJ3x1}!!fk)'0E{*(2Fk)'0E;.!,\!:JLLAfES]L^FA/ 2 '',cCL#g,#?@'',cCL#g,#?@ -rJ   Nr   )r   r   r   r   r   r   r   rJ   rH   r  r  *  s     I*ArJ   r  c                  t     e Zd ZU dZddiZded<   dZej                  dz   Zded	<   d
d
dd fdZ	ddZ
 xZS )GraphHistograma  
    Graph the count of a single element.

    Data set is simply a list of x and y pairs, where there
    is only one of each x value, and y value is the count or magnitude
    of that value

    >>> import random
    >>> g = graph.primitives.GraphHistogram()
    >>> g.doneAction = None #_DOCS_HIDE
    >>> g.graphType
    'histogram'

    >>> data = [(x, random.choice(range(30))) for x in range(50)]
    >>> g.data = data
    >>> g.process()

    .. image:: images/GraphHistogram.*
        :width: 600
    binWidthz
            Size of each bin; if the bins are equally spaced at intervals of 1,
            then 0.8 is a good default to allow a little space. 1.0 will give no
            space.
            r   r   	histogram)r  r   r+   皙?)r  r   c               6    || _         t        |   dd|i| y )Nr   r   )r  r  rI   )rB   r  r   rC   r  s       rH   rI   zGraphHistogram.__init__  s     1u11rJ   c                   | j                   t        d      | j                   J | j                  t        d      | j                  J | j                   j                  d       g }g }| j                  }t        | j                  d         }| j                  }| j                  D ]>  }t        |      dkD  r|\  }}	}
n|\  }}	|j                  |       |j                  |	       @ |j                  |||||       y )Nr  r  r  r	  r   rl   r9  r   r   )r9   r   r8   r  r  r	   r   r   r_   rd   r  )rB   r:   r   r   r  r   r   pointabunused_formatDicts              rH   r   zGraphHistogram.renderSubplot  s    ;;[\\{{&&&99 F G Gyy$$$###.==Q(

YYE5zA~*/'1'1HHQKHHQK  	AqUCrJ   )r  r   r   r   r   )r   r   r   r   r   r   r   r   r+   rI   r   r%  r&  s   @rH   r  r  g  sM    * 	 !I~  I,1,F,F,V/V,/ 2DrJ   r  c                  b     e Zd ZU dZdZej                  dz   Zded<   d	 fdZd
dZ	d
dZ
 xZS )GraphGroupedVerticalBara  
    Graph the count of one or more elements in vertical bars.

    The `.data` is simply a list of x and y pairs, where there
    is only one of each x value, and y value is a list of values.

    >>> from collections import OrderedDict
    >>> g = graph.primitives.GraphGroupedVerticalBar()
    >>> g.doneAction = None #_DOCS_HIDE
    >>> lengths = OrderedDict( [('a', 3), ('b', 2), ('c', 1)] )
    >>> data = [('bar' + str(x), lengths) for x in range(3)]
    >>> data
    [('bar0', OrderedDict([('a', 3), ('b', 2), ('c', 1)])),
     ('bar1', OrderedDict([('a', 3), ('b', 2), ('c', 1)])),
     ('bar2', OrderedDict([('a', 3), ('b', 2), ('c', 1)]))]
    >>> g.data = data
    >>> g.process()
    groupedVerticalBar)r  roundDigitsgroupLabelHeightr   r+   c                N    d| _         d| _        d| _        t        |   di | y )Nr^   rO  r   )r  r  r  r  rI   r  s     rH   rI   z GraphGroupedVerticalBar.__init__  s*    %& !'*$8$rJ   c                   |D ]  }|j                         |j                         dz  z   }|j                         }|j                  ||t	        t        || j                              dd| j                  | j                          y )Nrl   r5   r   )r  r  r   r   )	get_x	get_width
get_heightr  r   ro   r  r%   r   )rB   r:   rectsr   r  r  s         rH   	labelBarsz!GraphGroupedVerticalBar.labelBars  su    D

(81(<=I__&FLLU64+;+;<=$$"&"3"3 $  1 rJ   c           	     
   | j                   t        d      | j                   J t               }|j                  }d}g }| j                   D ]*  \  }}t	        |      }t        |j                               } n | j                  }||z  }	g }
g }t        | j                         D ]R  \  }\  }}|
j                  |       |j                  t        |j                               D cg c]  }||   	 c}       T g }t        |      D ]  }g }t        |
      D ]  \  }}|j                  ||   |           g }|
D ]  }|j                  ||	|z  z           |j                  |||	d| j                               }|j                  |        g }|D ](  }| j                  ||       |j                  |d          * |j                  j                  | j                   | j"                        }|j%                  |||       y c c}w )Nr  r^   r  r  r   )r  r   )prop)r8   r   r   
matplotlibr_   sortedr\  r  r   rd   r-   r  ra   r  font_managerFontPropertiesr%   r   legend)rB   r:   rD   r  barsPerGroup	subLabelsunused_ar  r  
widthShiftxValsyBundlesr   r^  r  yValsr!  _xxValsShiftedr   r   r   	fontPropss                          rH   r   z%GraphGroupedVerticalBar.renderSubplot  s   99 F G Gyy$$$!#__
	  99KHaq6Lqvvx(I	 % ==,
 )$)) 4A}!LLOOOvaffh/?@/?QsV/?@A !5
 |$AE"5)2Xa[^, * L##Aa$89  ;;|$%/%(%)^^%5	  7D
 LL %" DNN7D)MM$q'"  ++::@Q@QBF// ; S	vyy97 As   #H 
r   r   )r   r   r   r   r   r   r+   r   rI   r  r   r%  r&  s   @rH   r  r    s<    $ %I,1,F,F J8 -8/ 8%15:rJ   r  c                  P     e Zd ZdZdZdZdddd	 	 	 	 	 d
 fdZddZdd	Z xZ	S )Graph3DBarsa  
    Graph multiple parallel bar graphs in 3D.

    Data definition:
    A list of lists where the inner list of
    (x, y, z) coordinates.

    For instance, a graph where the x values increase
    (left to right), the y values increase in a step
    pattern (front to back), and the z values decrease
    (top to bottom):

    >>> g = graph.primitives.Graph3DBars()
    >>> g.doneAction = None #_DOCS_HIDE
    >>> data = []
    >>> for i in range(1, 10 + 1):
    ...    q = [i, i//2, 10 - i]
    ...    data.append(q)
    >>> g.data = data
    >>> g.process()

    When creating the graph these keyword arguments can be used (in addition to any
    such as `colors` that all Graph classes can use).

    * ``alpha`` -- opacity of each bar, from 0.0 (transparent) to 1.0 (opaque).
      Defaults to 0.8.
    * ``barWidth`` -- width of each bar along the x-axis.  When ``None``
      (default) the width is computed automatically.
      Individual data points may also override this
      via a ``'barWidth'`` key in their per-point format dict.
    * ``barDepth`` -- depth of each bar along the y-axis.  When ``None``
      (default) the depth is computed automatically.
      Individual data points may also override this
      via a ``'barDepth'`` key in their per-point format dict.
    3DBarsr   r  N)r   barWidthbarDepthc               `    t        |   dd|i| || _        || _        d|vr
g d| _        y y )Nr   r   )z#ff0000z#00ff00z#6666ffr   )r  rI   r  r  r   )rB   r   r  r  rC   r  s        rH   rI   zGraph3DBars.__init__0  s<     	1u11(0(08#;DK $rJ   c                .   t               }|j                  }|j                         | _        | j                  j                  dddd      | _        | j                  | j                         | j                  | j                         | j                          y )Nr^   r   )
projection)r   r7   r9   r   r:   r   r   r   r   s      rH   r   zGraph3DBars.process<  so    !#hhjjl{{..q!Q4.H4<<(T\\*rJ   c                   | j                   t        d      | j                   J g }g }g }| j                   D ]D  }|d   |d   |d   }}}|j                  |       |j                  |       |j                  |       F t        |      t	        |      }
}	t        |      t	        |      }}t        |      t	        |      }}| j
                  d   d   |	|
f| j
                  d   d<   | j
                  d   d   ||f| j
                  d   d<   | j
                  d   d   ||f| j
                  d   d<   | j                  | j                  n|
|	z
  d	z  }| j                  | j                  n||z
  d	z  }| j                   D ]  }t        |      d
k(  r	|\  }}}i }n!t        |      dk(  r|\  }}}}nt        d      d|v r|d   }n| j                         }d|v r|d   }d|v r|d   }|j                  ||dz  z
  ||dz  z
  d||||| j                          | j                  ddd       | j                  ddd       | j                  ddd       y )Nr  r   r^   rl   r   r-   r   r      r   rE  z/Cannot plot a point unless it has 3 or 4 valuesr   r  r  )r   r   T)r~   )r8   r   rd   rT  rn   r;   r  r  r_   r   ra   bar3dr   r   )rB   r:   r  r  zValsr  r   r   r   rj  rk  r  r  r  r  r  r  	dataPointr  r   s                       rH   r   zGraph3DBars.renderSubplotH  s   99 F G Gyy$$$YYEAha%(!qALLOLLOLLO	  ZUdZUdZUd99S>'"*&*DjDIIcN7#99S>'"*&*DjDIIcN7#99S>'"*&*DjDIIcN7#$(MM$=4==D4KSUCU$(MM$=4==D4KSUCUI9~"#1a
Y1$&/#1a$%VWW*$"7+(Z'%j1Z'%j1MM!x!|,a8a<.@!"Ha % $

  ,' #0 	#s5#s5#s5rJ   )r   r   r  float | int | Noner  r  r   r   )
r   r   r   r   r   r   rI   r   r   r%  r&  s   @rH   r  r  	  sK    "F IH !$,0,0	
<
< *
< *	
<
76rJ   r  c                      e Zd Zd Zy)Testc                2    ddl m}  || t                      y )Nr   )testCopyAll)music21.test.commonTestr  globals)rB   r  s     rH   testCopyAndDeepcopyzTest.testCopyAndDeepcopy  s    7D')$rJ   N)r   r   r   r  r   rJ   rH   r  r    s    %rJ   r  c                  B    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zy)TestExternalTc                v   t        d dd      }t        d      D cg c]	  }|||z  f }}||_        |j                          t	        d d      }t        d      D cg c]"  }|t        j                  t        d            f$ }}||_        |j                          t        d dd	d
dg      }g }t        dd      D ]T  }t        d      D cg c]-  }|t        j                  t        d|z  d|dz   z              |f/ }}|j                  |       V ||_        |j                          ~y c c}w c c}w c c}w )Nzx to x*xr^   )r   r&   r   2   z50 x with random(30) y counts)r   r&      z,50 x with random values increase by 10 per xr  r  g)r   r&   r   r   rE  r3   )	r  r-   r8   r   r  randomchoicer  extend)rB   r  r   r8   r   qs         rH   	testBasiczTestExternal.testBasic  s$   D
!D$)"I.IqAE
I.			d2QR7<RyAy!FMM%),-yA			4L! #Sz+ q!AMRSUYWY!V]]5aq1u#>?CYAWKKN  			) /
 B Xs   D,'D12D6c                J   g }dD ]y  }g }t        d      D ]T  }t        j                  t        d            }|t        j                  t        d            z   }|j                  ||f       V |j                  ||g       { t	        d       }||_        |j                          y )N)
r  r  r`   r  r  fr  r  r   r!  r3      r  r   )r-   r  r  rd   r>  r8   r   )rB   r8   ri   r_  r   startendr  s           rH   testBrokenHorizontalz!TestExternal.testBrokenHorizontal  s    GEF2YeCj1fmmE"I66ucl+  KK( H $/			rJ   c                n   g }t        d      D ]q  }t        j                  t        d            }t        j                  t        d            }t        j                  t        dd            }|j                  |||g       s | j                  rd}nd }t        |      }||_        |j                          y )Nr  r  r^   r6   r  )r-   r  r  rd   r[   r  r8   r   )rB   r8   r   r   r   r   r   r  s           rH   testScatterWeightedz TestExternal.testScatterWeighted  s    rAeBi(AeBi(AeArl+AKKAq	"	  99 JJ J7			rJ   c                F   g }t        dd      D ]P  }t        d      D cg c])  }|t        j                  t        d|dz   z              |f+ }}|j                  |       R t        ddgfddd	gfd
dgfgft
        g dft        t        d      D cg c]	  }|||z  f c}ft        t        d      D cg c]"  }|t        j                  t        d            f$ c}ft        |ft        dg dfdg dfgft        g dddgg dgfg}|D ]  \  }} |d      }||_        |j                          |j                  j                  dz   }	t        t         j#                         |	z        }
t         j%                  d|
g       |j'                  |
        yc c}w c c}w c c}w )z
        Write a graphic file for all graphs,
        naming them after the appropriate class.
        This is used to generate documentation samples.
        r^   rE  r  r3   Chopin)  '   	Schumanns)r
  .   )i  M   Brahms)i)  @   ))         )r3   r  r2   )rE  r  r*  )r     x   r  r  Major))Cz#00AA55)Dz#5600FF)Gz#2B00FFMinor))r  z#004600)r  z#00009b)r  z#00009B)z#8968CDz#96CDCDz#CD4F39z#FFD600z#FF5600)z#201a2bz#8f73bfz#a080d5z#6495EDz#FF83FANr  r   writing fp:)r-   r  r  r  r>  r  r  r  r  r(  r   r8   r   r  r   r   r   getRootTempDirr   r6   )rB   data3DPolygonBarsr   r   r  graphClassesgraphClassNamer8   objfnr   s              rH   x_test_writeAllGraphsz"TestExternal.x_test_writeAllGraphs  s    q!AEJ2YOY!V]]5q1u#67;YAO$$Q'   -./02EFG-./1
 "EG"'),)Qq!a%j),.5:2Y?Yq&--b	*+Y?A+,!NONOS ?()4U  #
2 %1 ND D1CCHKKM''&0B\002R78B##]B$78IIbM %1= P -?s   .FF
4'Fc                   t        d       }g dg dg dg dg dg dg}||_        |j                          |j                  j                  dz   }t        t        j                         |z        }|j                  |       y )	Nr  )#525252#5f5f5f#797979#858585#727272#6c6c6c#8c8c8cr*  r)  #999999r+  r&  r)  r%  r$  z#464646#3f3f3fr,  #4c4c4cr-  r&  r&  r-  r-  r$  r%  r&  r'  r(  r)  )r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r&  r)  r%  r%  r'  r&  r&  r&  r&  r&  r&  r'  #929292r+  )r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r*  r*  r*  r'  r&  r'  r.  r+  )r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  r*  r.  r+  )
r+  r+  r+  r+  r+  r+  r+  r+  r+  r+  )r+  r+  r+  r+  r+  r   )	r   r8   r   r  r   r   r   r  r6   )rB   r  r8   r!  r   s        rH   x_test_writeGraphColorGridz'TestExternal.x_test_writeGraphColorGrid  s{    d+S
^'2=G%I& 			[[!!F*,,.34	rJ   c                ,   g }t        d      }t        d      D cg c]	  }|||z  f }}||_        |j                  |dg       t        ddd      }t        d      D cg c]	  }|||z  f }}||_        |j                  |dg       t	        d      }t        d      D cg c]"  }|t        j                  t        d	            f$ }}||_        |j                  |d
g       t        d      }g }t        dd      D ]P  }t        d      D cg c])  }|t        j                  t        d|dz   z              |f+ }}|j                  |       R ||_        |j                  |dg       t        ddddg d      }||_        |j                  |dg       |D ]b  \  }}	|j                          |	dz   }
t        t        j                         |
z        }t        j                  d|g       |j                  |       d yc c}w c c}w c c}w c c}w )z6
        Write graphing examples for the docs
        Nr  r  zgraphing-01zExponential Graphr^   )r&   r   r   zgraphing-02r  zgraphing-03rE  r  r3   zgraphing-04zRandom Datar  r.   )r  rr  )r&   r   r  r   r   zgraphing-05r   r  )r  r-   r8   rd   r  r  r  r  r  r   r   r   r  r   r6   )rB   postr  r   r8   r   r  r  r   namer!  r   s               rH   x_test_writeGraphingDocsz%TestExternal.x_test_writeGraphingDocs  s    D)$)"I.IqAE
I.Q&'2!M$)"I.IqAE
I.Q&'d+7<RyAy!FMM%),-yAQ&'4(q!AEJ2YOY!V]]5q1u#67;YAOKKN  Q&'m!!$#'.	0
 Q&'ICKKMB\002R78B##]B$78IIbM = /
 /
 B Ps   H!H$'H.HNc                    ddl m} |j                         }|j                         }t	        |d      }||_        |j                          y )Nr   )discreter   )r   r   )music21.analysisr6  KrumhanslSchmucklersolutionLegendr(  r8   r   )rB   r   r6  ksr8   r  s         rH   testColorGridLegendz TestExternal.testColorGridLegend<  s=    -))+  " JC@			rJ   c                    t        d       }t        d      D cg c]  }d| ddddf }}||_        |j                          y c c}w )Nr  r3   r  r   rl   r^   )r  r  r`   )r  r-   r8   r   )rB   r  r   r8   s       rH   testGraphVerticalBarz!TestExternal.testGraphVerticalBarF  sL    #t4?DRyIy!3qc!!!45yI			 Js   ArV   )r   r   r   r[   r  r  r  r"  r/  r4  r;  r=  r   rJ   rH   r  r    s1    D0 /b:*XrJ   r  __main__)*r   
__future__r   rU  r   r  typingr   unittestTYPE_CHECKINGmatplotlib.axesr  matplotlib.figuremusic21r   music21.converter.subConvertersr   r   music21.graph.utilitiesr   r   r	   r
   r   Environmentr   ProtoM21Objectr   r   r(  r>  rp  r  r  r  r  r  TestCaser  r  r   mainTestr   rJ   rH   <module>rL     s;   #     ??  8 ' '
 &{&&'9:nG"" nbnU nbW5 WtW' W'tE# E#hK-5 K-\:A5 :Az<DU <D~`:e `:Fv6% v6r%8 %A8$$ AH zGT rJ   