
    rh                   ,   S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SSKJrJrJrJr  SSKJr  \
R"                  " S	5      r " S
 S\R&                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\R>                  5      r  " S" S#\R>                  5      r!\"S$:X  a  SSKr\RF                  " \ 5        gg)%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                  
   \ rS rSr% SrSrSrS\S'   SrS\S	'   S
r	S\S'   S r
S rS rS r\S 5       r\R                   S 5       rS rS rS"S jrS#S jrS$S jr\S$S j5       rS rS rS rS rS rS%S jrS rS%S  jrS!r g)&Graph-   a  
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yz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                   [        5       nUR                  U l        S U l        S U l        S U l        0 U l        U R                   H$  n0 U R
                  U'   S U R
                  U   S'   M&     SU l        0 U l        U R                   H  nSU R                  U'   M     SU l	        S U l
        SU l        SU l        SU l        SU l        U R                  U l        SU l        S	U l        / S
QU l        SU l        SSS.U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l         U RB                   H  nXQ;   d  M
  [E        XX   5        M     g )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         R/home/james-whalen/.local/lib/python3.13/site-packages/music21/graph/primitives.py__init__Graph.__init__   sm   !#88	 	--BDIIbM%)DIIbM'"   	#% }}G05D$$W- % 
#, %.""$
00  )	:!"#-5*+3($)!" ++B~(,/ ,    c                    [        U S5      (       a4  U R                  b&  U R                  R                  U R                  5        ggg)zM
Matplotlib Figure objects need to be explicitly closed when no longer used.
r9   N)hasattrr9   r7   closerB   s    rH   __del__Graph.__del__   s6     4""t{{'>HHNN4;;' (?"rK   c                @    U R                   R                  5       nUS	 U$ )zS
The wrapper to matplotlib.pyplot stored as self.plt cannot be pickled/deepcopied.
r7   )__dict__copy)rB   states     rH   __getstate__Graph.__getstate__   s"     ""$%LrK   c                p    U R                   R                  U5        [        5       nUR                  U l        g N)rS   updater   r7   )rB   rU   rD   s      rH   __setstate__Graph.__setstate__   s'    U#!#88rK   c                    U R                   $ )zc
returns or sets what should happen when the graph is created (see docs above)
default is 'write'.
)r?   rO   s    rH   r   Graph.doneAction   s     rK   c                8    US;   a  Xl         g [        SU 35      e)N)showr6   Nzno such done action: )r?   r   )rB   actions     rH   r   r^      s$    ,,% #8!ABBrK   c                    [        U R                  U R                  [        U R                  5      -     5      nU =R                  S-  sl        U$ )a  
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   	nextColorGraph.nextColor   sA    & T[[!5!5DKK8H!HIJ!rK   c                    Uc  gXR                   ;  a  [        SU S35      e/ n/ nU H'  u  pVUR                  U5        UR                  U5        M)     X44U R                   U   S'   g)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   setTicksGraph.setTicks   ss    : =))# #4WI^!LMM	!LEU#MM%  " '0&7		'7#rK   c                    [        U5      n[        XC-  5      n/ nUS::  a  Sn[        SUS-   U5       H  nUR                  Xw /5        M     UR	                  5         U R                  X&5      $ )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?
rc      r   )maxroundr-   rj   sortrp   )rB   unsortedDatarF   	dataStepsmaxDatatickSteptickListr   s           rH   setIntegerTicksFromDataGraph.setIntegerTicksFromData!  sk     l#,-q=Hq'A+x0AOOQ#K( 1}}W//rK   c                    XR                   ;  a  [        SU 35      eUS:w  a  US   US   -
  nXC-  nOSnUS   U-
  US   U-   4U R                  U   S'   SU R                  U'   g)a  
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   rc   r-   TN)r   r   r;   r=   )rB   rF   
valueRangepaddingFraction
totalRangeshifts         rH   setAxisRangeGraph.setAxisRange9  s     --' #8	!BCCa#AA6J0EE'1!}u'<'1!}u'<'>		'7# -1  )rK   c                    XR                   ;  a  [        SU 35      eU(       a+  SU R                  U   ;   a  U R                  U   S   (       a  g X R                  U   S'   g )Nr   ro   )r   r   r;   )rB   rF   ro   conditionals       rH   setAxisLabelGraph.setAxisLabelS  sW    --' #8	!BCC7dii&88TYYw=OPW=X&+		'7#rK   c                   U R                   R                  5        HL  u  p#US;   a  U(       a  UR                  S5        M%  M'  US;   a  UR                  S5        M@  [        SU 35      e   [	        U R                  5       U R                  5       -   5       H;  u  pEU(       a  UR                  S5        M  US-  S:X  d  M*  UR                  S5        M=     g)	z
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: Frs   rc   N)spinesitems	set_color
ValueError	enumerateget_xticklinesget_yticklinesset_visible)r:   
leftBottomlocspineilines         rH   hideAxisSpinesGraph.hideAxisSpines[  s     "....0JC((OOF+  ((' #;C5!ABB 1 !!7!7!9G<R<R<T!TUGA  'Q!  '	 VrK   c                   [         R                  S[        U5      -   5        UR                  nUR	                  [        U R                  5      5        U R                   H  nU R                  X5        M     U R                  (       a/  UR                  U R                  U R                  U R                  S9  U R                   H0  nX@R                  ;  a  M  UR                  X@R                  U   S9  M2     U R                  U R                   5        U R"                  R%                  U R&                  S   5        U R"                  R)                  U R&                  S   5        g)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)r;   r   r   rc   N)environLocal
printDebugreprpatchset_facecolorr	   r   r   applyFormattingToOneAxisr&   	set_titler'   r   r$   tick_params	applyGridr:   r9   set_figwidthr   set_figheight)rB   r:   rectr;   thisAxisNames        rH   applyFormattingGraph.applyFormattingw  s	    	 =W MN}}8D$<$<=> MMD))'8 " ::djj43E3Edoo^ !MML??2\//,:WX *
 	t||$ 	  !34!!$//!"45rK   c                \   U R                   (       aB  U R                  b5  UR                  S5        UR                  SS[        U R                  5      S9  U R                  (       a  UR
                  R                  S5        U R                  (       a  UR                  R                  S5        gg)zA
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   Graph.applyGrid  st    
 993!!$'LLWHT^^4LLM>>MMu%>>MMu% rK   c           
        U R                   U   nUS;  a  gSU;   a?  US   b9  SU-   S-   n[        U R                  5      S:X  a  US-  n[        X5      nU" US   6   SU;   a7  US   b1  [        USU-   S-   5      nU" US   U R                  U R
                  S	9  S
U;   a#  US
   b  [        USU-   S
-   5      nU" US
   5         [        USU-   S-   5      n[        USU-   S-   5      n[        USU-   S-   5      n	SU;  a0  U	b-  U" 5       n
U" U
5        U	" U
U R                  U R
                  S	9  U$ US   u  pUb  U" U5        US:X  aI  UR                  UU R                  U R
                  U R                  U R                  U R                  SS9  U$ US:X  a)  UR                  UU R                  U R
                  SSS9  U$ [        U	5      (       a  U	" UU R                  U R
                  S	9  U$ ! [         a
    SnSnSn	 GNf = f)a<  
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   3dro   r   scaleget_ri   
ticklabelsr   g{Gz)r   r   horizontalalignmentverticalalignmentrotationr   r   r   r5   r   r   r   r   )r;   rd   r   getattrr!   r   AttributeErrorr%   set_xticklabelsr(   r*   r)   set_yticklabelscallable)rB   r:   r;   thisAxisrangeFuncNamethisRangeFuncsetLabelFunctiongetTickFunctionsetTickFunctionsetTickLabelFunctionri   valuesrm   s                rH   r   Graph.applyFormattingToOneAxis  sl    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.NF*'s{''151B1B/3<@<^<^:>:Z:Z151H1H*/ ( 1(  ''151B1B/3<C:B	 ( D  .//$V.2.?.?,0OO= M  	("O"O#' 		(s   6G- -H Hc                   [        5       nUR                  nUR                  U R                  S9U l        U R                  R	                  SSS5      U l        SU l        U R                  U R
                  5        U R                  U R
                  U R                  S9  U R                  U R
                  5        U R                  5         g)z
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
)	facecolorrc   r   )r   N)r   r7   r9   r   add_subplotr:   r@   renderSubplotr   r>   r   callDoneActionrB   rD   r7   s      rH   processGraph.process  s     "#hh
 jj4+E+EjF{{..q!Q7 4<<( 	DLLT5N5NOT\\*rK   c                    g)z9
Calls the subclass specific information to get the data
N r   s     rH   r   Graph.renderSubplot  s     	rK   Nc                    U R                   S:X  a  U R                  5         gU R                   S:X  a  U R                  U5        gU R                   c  gg)z9
Implement the desired doneAction, after data processing
r`   r6   N)r   r`   r6   )rB   fps     rH   r   Graph.callDoneAction  sB     ??f$IIK__'JJrN__$ %rK   c                8    U R                   R                  5         g)z
Calls the show() method of the matplotlib plot.
For most matplotlib back ends, this will open
a GUI window with the desired graph.
N)r9   r`   rO   s    rH   r`   
Graph.show(  s     	rK   c                   Uc  [         R                  S5      nU R                  nUc  SnU R                  R	                  UUS9  [
        R                  " 5       SLa  [        5       R                  USS9  gU R                  $ )zQ
Writes the graph to a file. If no file path is given, a temporary file is used.
N.png,  )r   Tpng)fmt)	r   getTempFiler   r9   savefigr   runningInNotebookr   launch)rB   r   r   s      rH   r6   Graph.write0  s|     :))&1Bhh;CB !$ 	 	%
 ##%T1N!!"%!0;;rK   )r@   r?   r   r;   r=   r   r   r   r   r8   r   r9   r   r   r<   r>   r   r    r!   r"   r#   r7   r:   r$   r%   r&   r'   r(   r)   r*   )r      )皙?)FrY   )!__name__
__module____qualname____firstlineno____doc__	graphTyper   __annotations__r   r+   rI   rP   rV   r[   propertyr   setterrf   rp   r|   r   r   staticmethodr   r   r   r   r   r   r   r`   r6   __static_attributes__r   rK   rH   r   r   -   s    4j I *Ho*/5,5-/ 0:0x(
     C C.*8X0014, ( (6#6R& IV6	rK   r   c                  j   ^  \ rS rSr% SrSSS.rS\S'   Sr\R                  S-   r	U 4S	 jr
S
 rSrU =r$ )GraphNetworkxGraphiF  zf
Grid a networkx graph -- which is a graph of nodes and edges.
Requires the optional networkx module.
z'An instance of a networkx graph object.:bool to hide the left and bottom axis spines; default True)networkxGraphr>   dict[str, str]	_DOC_ATTRnetworkxc                   > S U l         SU l        [        TU ]  " S0 UD6  [	        5       nSU;  a  SU l        g UR                  b"   UR                  R                  5       nX0l         g g ! [         a     g f = f)NTr&   zNetwork Plotr   )	r  r>   superrI   r   r&   r  r   	NameError)rB   rC   rD   g	__class__s       rH   rI   GraphNetworkxGraph.__init__Z  s|    !$(!$8$!#("'DJ]]&MM'')
 &'" '  s    A( (
A54A5c                   [        5       nUR                  n0 n0 nU R                  R                  SS9 H!  u  pgUS   XF'   US   S   S-   US   S   4XV'   M#     UR	                  U R                  USUSS	S
9  U R                  R                  SS9 HH  u  pn
[        R                  SXU
4/5        X4/nUR                  U R                  XKSU
S   SU
S   US9  MJ     UR                  U R                  UU R                  U R                  SUS9  U R                  SS5        U R                  SS5        U R                  S/ 5        U R                  S/ 5        SU l        g )NT)r8   posr   g      ?rc   r   z#605C7F      ?)	node_sizerE   
node_colorr   r   rs   stylez#666666weight)edgelistwidthr  
edge_colorr   rE   r1   )	font_sizefont_family
font_colorrE   r    r   F)r   r  r  nodesdraw_networkx_nodesedgesr   r   draw_networkx_edgesdraw_networkx_labelsr!   r   r   rp   r<   )rB   r:   rD   r  posNodesposNodeLabelsnIdnDatauvdr  s               rH   r    GraphNetworkxGraph.renderSubplotq  s   !#== ,,222=JC!%LHM"',q/E"95<?!KM > 	$$T%7%7/2w9\_ 	% 	a ++11t1<IQ1##%9A!9$EF xH((););X/0'
4=Qx[U\ ) ^ = 	%%d&8&8-040B0B26//i)0 	& 	2 	#r"#r"c2c2	rK   )r<   r>   r  r&   r   r   r   r   r   r  r   r   r   r+   rI   r   r   __classcell__r
  s   @rH   r   r   F  sK     G \!I~ 
 I 55 9 .* *rK   r   c                  l   ^  \ rS rSr% SrSS0rS\S'   SrSr\	R                  S	-   r
U 4S
 jrS rSrU =r$ )GraphColorGridi  a}  
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>   r  r  r  r   )	   r   r>   c                4   > SU l         [        TU ]  " S0 UD6  g )NTr   )r>   r  rI   rB   rC   r
  s     rH   rI   GraphColorGrid.__init__  s    $(!$8$rK   c                N   U R                   R                  SS9  [        U R                  5      n[	        U5       GH  nU R                  U   n/ n/ n/ n[        U5       H;  u  pUR                  US-   5        UR                  U	5        UR                  S5        M=     U R                   R                  USX#-
  5      n
U
R                  UUSUSSSS9  U
R                  R                  5        H8  u  pUR                  S5        UR                  S5        UR                  S5        M:     [        U
R                  5       U
R                  5       -   5       H  u  pUR!                  S5        M     U
R#                  / 5        U
R%                  / 5        U
R'                  S	/[        U
R)                  5       5      -  5        U
R+                  S	/[        U
R-                  5       5      -  5        U
R/                  S
[        U R                  U   5      /5        U
R1                  5       R!                  S5        U
R3                  5       R!                  S5        GM     US:  a  U R                   R                  S
S9  OU R                   R                  SS9  SnU R5                  SUS
5        SU l        g )N333333?r   r  rc   333333?r1   F)r   	linewidth	edgecolorantialiasedr  r   r2   )hspacer   r   rc   r   )r9   subplots_adjustrd   r8   r-   r   rj   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   thisRowDatarl   heights	subColorsj	thisColorrE   
unused_locr   r   axisRangeNumberss                  rH   r   GraphColorGrid.renderSubplot  sF    	###.tyy>xA))A,KIGI )+ 6  U+  +q! !7 ((1hlCB FF9" &$  & &(YY__%6!
##C(	*"	 &7 %R%6%6%82;L;L;N%NO  ' PMM"MM"tc"*<*<*>&??@tc"*<*<*>&??@KKC		!-./ LLN&&u-LLN&&u-] !d b=KK''q'1KK''s'3!#/3 	rK   )r<   r>   )r   r   r   r   r   r  r   r   r   r   r+   rI   r   r   r(  r)  s   @rH   r+  r+    sN    & 	 \!I~  I 558QQ%H HrK   r+  c                  r   ^  \ rS rSr% SrSS0rS\S'   SrSr\	R                  S	-   r
U 4S
 jrS rS rSrU =r$ )GraphColorGridLegendi  a  
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 = []
>>> data.append(('Major', [('C#', '#00AA55'), ('D-', '#5600FF'), ('G#', '#2B00FF')]))
>>> data.append(('Minor', [('C#', '#004600'), ('D-', '#00009b'), ('G#', '#00009B')]))
>>> g.data = data
>>> g.process()

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

r>   r  r  r  colorGridLegend)         ?r-  c                P   > SU l         [        TU ]  " S0 UD6  SU;  a  SU l        g g )NTr&   Legendr   )r>   r  rI   r&   r/  s     rH   rI   GraphColorGridLegend.__init__$  s/    $(!$8$("!DJ #rK   c                   [        U R                  5       H,  u  p#US   nUS   nU R                  U R                  X$U5        M.     U R	                  SSS5        UR                  5       UR                  5       -   n[        U5       H  u  pxUR                  S5        M     U R                  R                  SSSS	9  U R                  S
S5        U R                  SS5        U R                  S
/ 5        U R                  S/ 5        g )Nr   rc   r   r9  FrR  g      ?r.   )r8  r   r   r   r  )r   r8   makeOneRowOfGraphr9   r   r   r   r   r:  r   rp   )	rB   r:   r   rowLabelAndDatarowLabelrowDataallTickLinesrI  r   s	            rH   r   "GraphColorGridLegend.renderSubplot,  s    "+DII"6A&q)H%a(G""4;;WE #7
 	#vq)--/'2H2H2JJ .GAU# / 	##3D#E#r"#r"c2c2rK   c           	         / n/ n/ n[        U5       H>  u  pUR                  SU-   5        UR                  U	S   5        UR                  S5        M@     [        U R                  5      SUS-   4n
UR                  " U
6 nSnUR                  XVXSSS9  UR                  R                  5        H%  nUR                  S5        UR                  S5        M'     UR                  5       UR                  5       -   n[        U5       H  u  pUR                  S5        M     UR                  S/5        UR                  U/U R                  U R                   SS	S
9  UR#                  [%        [        U5      5       Vs/ s H  nUS-   PM
     sn5        U VVs/ s H  u  nn['        U5      PM     nnnUR)                  UU R                  U R                   S	S	SS9  UR+                  S[        U5      S-   /5        U$ s  snf s  snnf )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: >
g      ?rc   r4  r1   )r   r5  r6  Fr  r   r5   r   gٿ)r   r   r   r   r   )r   rj   rd   r8   r   r;  r   r   r<  r   r   r   r   r?  r   r%   r   r>  r-   r
   r   rB  )rB   r9   rowIndexrY  rZ  rl   rG  rH  rI  oneColorMapping	posTriplerE   r  spineArtistr[  r   r   unused_ysubstitutedAccidentalLabelss                      rH   rW  &GraphColorGridLegend.makeOneRowOfGraphC  s   . 		"+G"4AS1W%_Q/0NN1 #5 ^Q15	+ 
y5ST]^ 99++-K%%c*!!), . ((*R->->-@@ .GAU# / 	se
H:$($5$5"&///6-5	 	 	7 	eCL&9:&9q1u&9:; @G'H?F8 (@'B?F 	$ 'H
'&&?? (& 	 	 	S#g,,-.	 ;'Hs   6G5G:)r>   r&   )r   r   r   r   r   r  r   r   r   r   r+   rI   r   rW  r   r(  r)  s   @rH   rO  rO    sS    ( 	 \!I~  "I  558QQ".M MrK   rO  c                     ^  \ rS rSr% SrSSS.rS\S'   SrS	r\	R                  S-   r
U 4S
 jr\S 5       rSS jrSrU =r$ )GraphHorizontalBari  aj  
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 entertwined:
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 informmation 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      c                ^   > SU l         SU l        [        TU ]  " S0 UD6  SU;  a  SU l        g g )Nr   rs   r   333333?r   ri  rj  r  rI   r   r/  s     rH   rI   GraphHorizontalBar.__init__  s5    $8$("DJ #rK   c                :    U R                   U R                  S-  -
  $ Nrs   rh  rO   s    rH   	barHeightGraphHorizontalBar.barHeight      }}a00rK   c                   U R                   R                  SS9  Sn[        5       n/ n/ n/ nSnU R                   GH}  n[	        U5      S:X  a  Uu  p0 nOUu  pnUR                  U	5        UR                  SU R                  5       5      nU
(       a  [	        U
S   5      S:H  nU(       a  UnU
nO:U
 Vs/ s H  nUS   R                  SU5      PM     nnU
 Vs/ s H  nUS S PM
     nnX R                  -   U R                  4nUR                  UUUU R                  S9  U
 H^  n[	        U5      S:  a	  US S u  nnO[        S[	        U5       SU 35      eUU-   nUU4 H  nUU;  d  M  UR                  U5        M     M`     UR                  X R                  S	-  -   U	/5        X R                  -  nUS
-  nGM     SnSnU(       a  [        U5      n[!        U5      nUU-
  nU R#                  SS[	        U5      U R                  -  45        U R#                  SUU45        U R%                  SU5        SU R&                  S   ;   a  U R&                  S   S   (       d  [)        U[+        US-  5      -   5      nUS:X  a  S
n[-        [)        [.        R0                  " U5      5      [+        [.        R2                  " U5      5      U5       H  nUR                  UU /5        M     U R%                  SU5        g g g s  snf s  snf )Nr2  r3  r   rs   r   )
facecolorsr   z"Points must be length 2 or 3, not z: r  rc           r   r   ri   r3   )r9   r:  setr8   rd   rj   getrf   rj  rt  broken_barhr   r   addri  minrt   r   rp   r;   intru   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    GraphHorizontalBar.renderSubplot  s   ###."%%IID4yA~"$&!15..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;<MM!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   2K5K:)r   ri  rj  )returnNoner   r   r   r   r   r  r   r   r   r   r+   rI   r   rt  r   r   r(  r)  s   @rH   rf  rf    sj    'R I!I~   I 55 9 
 1 1L' L'rK   rf  c                  ~   ^  \ rS rSr% SrSSS.rS\S'   SrS	r\	R                  S-   r
U 4S
 jr\S 5       rS rSrU =r$ )GraphHorizontalBarWeightedi&  z
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.
rg  z Space around the bars, default 2rh  r  r  horizontalBarWeightedrl  c                ^   > SU l         SU l        [        TU ]  " S0 UD6  SU;  a  SU l        g g )Nr         ?r   rc   r   rp  r/  s     rH   rI   #GraphHorizontalBarWeighted.__init__:  s7    $8$ ("DJ #rK   c                :    U R                   U R                  S-  -
  $ rs  rh  rO   s    rH   rt  $GraphHorizontalBarWeighted.barHeightL  rv  rK   c           
     v   U R                   R                  SS9  Sn/ n/ n/ nSn[        U R                  5      U l        U R                  R	                  5         U R                   GH  u  pxUR                  U5        / n	/ n
/ n/ n[        U5       GHS  u  pmSnS nSnU R                  5       nU R                  nSn[        U5      S:X  a  Uu  pnOD[        U5      S:X  a  Uu  pnnO.[        U5      S:X  a  Uu  pnnnO[        U5      S:X  a  Uu  pnnnn[        U5      nU	R                  X45        UR                  U5        UR                  U5        X;  a  UR                  U5        X-   U;  a  UR                  X-   5        U R                  U-  nU R                  U-
  S	-  nU R                  SU-
  -  S	-  nX R                  -   U-   UU-  -   nU
R                  UU45        GMV     [        U	5       H"  u  nnUR                  U/X   X   X   X   S
9  M$     UR                  X R                  S	-  -   U/5        X R                  -  nUS-  nGM     [        U5      n[!        U5      nUU-
  nU R#                  SS[        U5      U R                  -  4SS9  U R#                  SUU4SS9  U R%                  SU5        g )Nr2  r3  r   rc   r   rm  rQ  r   r  )rx  r   r6  r   皙?)r   r   g{Gz?)r9   r:  listr8   reverserj   r   rf   r   rd   r	   rt  rj  r|  ri  r~  rt   r   rp   )rB   r:   r  r  r  r  r   r  r  xRangesyRangesalphasr   r8   r   spanheightScalarr   r   yShifthyAdjust
yShiftUnit	adjustedYr  r  r  s                              rH   r   (GraphHorizontalBarWeighted.renderSubplotP  s   ###. O			99KCKKGGFF$V, (

t9>,0)A\Y!^370A\5Y!^:>7A\5%Y!^BF?A\5% y)e$e$#NN1%HW,NN18,
 NN\1>>A-4!^^q</?@3F
 ;;.8J<OP		1~.G -J 'w/	6 ##VH$+J/5y*0).4i	 $ 9 0 MM4--#"55s;<MM!DFAq %t 7|7|
 	#3t9t}}#<=tT#d|TBc6"rK   )r   ri  r8   rj  r  r)  s   @rH   r  r  &  sg     I4!I~ 
 (I 55 9 
$ 1 1Q# Q#rK   r  c                  ~   ^  \ rS rSr% SrSSS.rS\S'   SrS	r\	R                  S-   r
U 4S
 jr\S 5       rS rSrU =r$ )GraphScatterWeightedi  aW  
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)rQ  rQ  c                ^   > SU l         SU l        [        TU ]  " S0 UD6  SU;  a  SU l        g g )Ng      ?r  r   ro  r   )r  r  r  rI   r   r/  s     rH   rI   GraphScatterWeighted.__init__  s7    $8$("DJ #rK   c                4    U R                   U R                  -
  $ rY   r  rO   s    rH   rangeDiameter"GraphScatterWeighted.rangeDiameter  s    $"2"222rK   c                   [        5       nUR                  nU R                  R                  SSS9  U R                   Vs/ s H  oDS   PM	     nnU R                   Vs/ s H  oDS   PM	     nnU R                   Vs/ s H  oDS   PM	     nn/ nU R                   H+  n[        U5      S:  a  US   n	O0 n	UR                  U	5        M-     [        U5      n
[        U5      n[        X-
  5      n[        U5      n[        U5      n[        X-
  5      n[        U5      n[        U5      n[        UU-
  5      nSnSnX:  a  X-  nO	X:  a  X-  n/ nU H^  nUS:X  a  UR                  SS/5        M  US:w  a	  UU-
  U-  nOSnU R                  U R                  U-  -   nUR                  UU/5        M`     [        [        U R                  5      5       H  nUU   nUU   nUU   u  nnUU   n	UU-  nUU-  nUR                  " SUU4UUS.U	D6nUR                  U5        UR                  UR                   5        UR#                  U R$                  5        UR'                  U R)                  5       5        UU   S:  d  M  UUS-  S	U-  -   -   n US
-   n!UR+                  U U![-        UU   5      SSSSS9  M     U R/                  SX45        U R/                  SX45        g s  snf s  snf s  snf )Nr2  r   r   rc   rs   r   r  )xyr  heightr  r   r   baseliner   )sizevahamultialignmentr   r   r   )r   patchesr9   r:  r8   rd   rj   rt   r~  floatr  r  r-   Ellipse
add_artistset_clip_boxbboxr=  r   r   rf   textstrr   )"rB   r:   rD   r  r%  xListyListzListformatDictList
formatDictr  r  r  yMaxyMinr  zMaxzMinzRangexDistortyDistortzNormr   scalarscaledr   r   r   unused_zScalarr  r  e	adjustedXr  s"                                     rH   r   "GraphScatterWeighted.renderSubplot  s   !#,, 	##d#;  $yy)y!1y)#yy)y!1y)#yy)y!1y)A1vzqT

!!*-  5z5zt{#5z5zt{#5z5ztd{#
 ?H_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 	#|,#|,k *))s   KK;K#)r   r  r  )r   r   r   r   r   r  r   r   r   r   r+   rI   r   r  r   r   r(  r)  s   @rH   r  r    sc     KJ!I~ 
 "I 558VV 3 3]- ]-rK   r  c                  "    \ rS rSrSrSrS rSrg)GraphScatteri6  a(  
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           
     <   U R                   R                  SS9  / n/ nSnU R                   HI  n[        U5      S:  a  [	        S5      eUS   nUS   nUR                  U5        UR                  U5        MK     UR                  5         UR                  5         U R                   H  nUS   nUS   nU R                  nU R                  5       n	U R                  n
U R                  n[        U5      S:  a1  US   nSU;   a  US   n	S	U;   a  US	   nS
U;   a  US
   n
SU;   a  US   nUR                  XgXXS9  US-  nM     U R                  S   (       d  U R                  SUS   US   45        U R                  S   (       d  U R                  SUS   US   45        g g )Nr2  r3  r   rs   z1Need at least two points for a graph data object!rc   r   r   r"   r   r#   )r"   r   r   r#   r   r   )r9   r:  r8   rd   r   rj   rv   r"   rf   r   r#   plotr=   r   )rB   r:   xValuesyValuesr   rowr   r   r"   r   r   r#   displayDatas                rH   r   GraphScatter.renderSubplotF  s   ###.99C3x!|$%XYYAAAANN1NN1  	99CAAAA[[FNN$EJJEJ3x1}!!fk)'0E{*(2Fk)'0E;.!,\!:JLLfL^FA' * '',cGAJ#<='',cGAJ#<= -rK   r   N)r   r   r   r   r   r   r   r   r   rK   rH   r  r  6  s     I)>rK   r  c                  v   ^  \ rS rSr% SrSS0rS\S'   Sr\R                  S-   r	S	S	S
.SU 4S jjjr
S rSrU =r$ )GraphHistogramir  a  
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   c               6   > Xl         [        TU ]  " SSU0UD6  g )Nr   r   )r  r  rI   )rB   r  r   rC   r
  s       rH   rI   GraphHistogram.__init__  s     1u11rK   c                \   U R                   R                  SS9  / n/ nU R                  n[        U R                  S   5      nU R
                  nU R                   H>  n[        U5      S:  a  Uu  pn
OUu  pUR                  U5        UR                  U	5        M@     UR                  X#XFUS9  g )Nr2  r3  r   rs   r  r   r   )
r9   r:  r  r	   r   r   r8   rd   rj   r;  )rB   r:   r   r   r  r   r   pointabunused_formatDicts              rH   r   GraphHistogram.renderSubplot  s    ###.==Q(

YYE5zA~*/''HHQKHHQK  	AUCrK   )r  r  r   r  r'  r)  s   @rH   r  r  r  sS    , 	 !I~  I 55E,/ 2 2D DrK   r  c                  Z   ^  \ rS rSrSrSr\R                  S-   rU 4S jrS r	S r
SrU =r$ )	GraphGroupedVerticalBari  aw  
Graph the count of on or more elements in vertical bars

Data set 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groupLabelHeightc                P   > SU l         SU l        SU l        [        TU ]  " S0 UD6  g )Nrc   ry  r   )r  r  r  r  rI   r/  s     rH   rI    GraphGroupedVerticalBar.__init__  s*     #$8$rK   c                   U H|  nUR                  5       UR                  5       S-  -   nUR                  5       nUR                  UU[	        [        XPR                  5      5      SSU R                  U R                  S9  M~     g )Nrs   r5   r   )r  r  r   r   )	get_x	get_width
get_heightr  r  ru   r  r%   r   )rB   r:   rectsr   r  r  s         rH   	labelBars!GraphGroupedVerticalBar.labelBars  ss    D

(81(<=I__&FLLU6+;+;<=$$"&"3"3 $  1 rK   c           	        [        5       nUR                  nSn/ nU R                   H)  u  pg[        U5      n[	        UR                  5       5      n  O   U R                  nX-  n	/ n
/ n[        U R                  5       HT  u  nu  pgU
R                  U5        UR                  [	        UR                  5       5       Vs/ s H  oU   PM	     sn5        MV     / n[        U5       H  n/ n[        U
5       H  u  nnUR                  UU   U   5        M     / nU
 H  nUR                  UX-  -   5        M     UR                  UUU	SU R                  5       S9nUR                  U5        M     / nU H)  nU R                  UU5        UR                  US   5        M+     UR                  R                  U R                  U R                   S9nUR#                  UUUS9  g s  snf )Nrc   r  r  r   )r  r   )prop)r   
matplotlibr8   rd   sortedr  r  r   rj   r-   r;  rf   r  font_managerFontPropertiesr%   r   legend)rB   r:   rD   r  barsPerGroup	subLabelsunused_ar  r  
widthShiftxValsyBundlesr   r  r  yValsrI  r   xValsShiftedr   r   	fontPropss                         rH   r   %GraphGroupedVerticalBar.renderSubplot  s   !#__
	  99KHq6Lqvvx(I	 % ==,
 )$)) 4A}LLOOOvaffh/?@/?sV/?@A !5
 |$AE!%(1Xa[^, ) L##A$89  ;;|$%/%(%)^^%5	  7D
 LL %" DNN7D)MM$q'"  ++::@Q@QBF// ; S	vyy97 As   <G
)r  r  r  )r   r   r   r   r   r   r   r+   rI   r  r   r   r(  r)  s   @rH   r  r    s9    $ %I 55 98 8%11: 1:rK   r  c                  L   ^  \ rS rSrSrSrSrSS.SU 4S jjjrS rS	 r	S
r
U =r$ )Graph3DBarsi
  a  
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()

3DBarsr   r  )r   c               J   > [         TU ]  " SSU0UD6  SU;  a
  / SQU l        g g )Nr   r   )z#ff0000z#00ff00z#6666ffr   )r  rI   r   )rB   r   rC   r
  s      rH   rI   Graph3DBars.__init__$  s,    1u118#;DK $rK   c                (   [        5       nUR                  nUR                  5       U l        U R                  R                  SSSSS9U l        U R                  U R                  5        U R                  U R                  5        U R                  5         g )Nrc   r   )
projection)r   r7   r9   r   r:   r   r   r   r   s      rH   r   Graph3DBars.process)  so    !#hhjjl{{..q!Q4.H4<<(T\\*rK   c                   0 nU R                    H:  n[        U5      S:  a  Uu  pEpgOUu  pEnXR;  a  / X%'   X%   R                  XF45        M<     [        UR	                  5       5      nUR                  5         / n	/ n
U HK  n[        [        X+   5      5       H.  nX+   U   u  pFU	R                  U5        U
R                  U5        M0     MM     U R                  S   S   c&  [        U
5      [        U
5      4U R                  S   S'   U R                  S   S   c&  [        U	5      [        U	5      4U R                  S   S'   U R                  S   S   c&  [        U5      [        U5      4U R                  S   S'   [        U
5      [        U
5      -
  S-  n[        U5      [        U5      -
  S-  nU R                    H  n[        U5      S:X  a  Uu  pEn0 nO![        U5      S:  a  Uu  pEnnO[        S5      eSU;   a  US   nOU R                  5       nUR                  XMS	-  -
  X^S	-  -
  S
XUUU R                  S9  M     U R                  SSSS9  U R                  SSSS9  U R                  SSSS9  g )Nr   r   r-   r   r      z,Cannot plot a point with fewer than 3 valuesr   rs   r   )r   r   T)r   )r8   rd   rj   r  r  rv   r-   r;   r~  rt   r   rf   bar3dr   r   )rB   r:   yDictr  r   r   r   r  r  zValsr  r  r   barWidthbarDepth	dataPointr  r   s                     rH   r   Graph3DBars.renderSubplot5  s^   YYE5zA~-2*a*a~HOOQF#  UZZ\"

C3uz?+z!}QQ ,  99S>'"*&)%j#e*&<DIIcN7#99S>'"*&)%j#e*&<DIIcN7#99S>'"*&)%j#e*&<DIIcN7#JU+r1JU+r1I9~"#a
Y!#&/#a$%STT*$"7+(MM!!|,aa<.@!"a % $

  , #& 	#s5#s5#s5rK   )r   r9   r:   )r   r  )r   r   r   r   r   r   r   rI   r   r   r   r(  r)  s   @rH   r  r  
  s0    , IH), < <

96 96rK   r  c                      \ rS rSrS rSrg)Testiq  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr.  globals)rB   r.  s     rH   testCopyAndDeepcopyTest.testCopyAndDeepcopys  s    7D')$rK   r   N)r   r   r   r   r1  r   r   rK   rH   r,  r,  q  s    %rK   r,  c                  R    \ rS rSrSrS rS rS rS rS r	S r
SS
 jrS rS rSrg	)TestExternalix  Tc                p   [        S SSS9n[        S5       Vs/ s H  o"X"-  4PM
     nnX1l        UR                  5         [	        S SS9n[        S5       Vs/ s H#  o"[
        R                  " [        S5      5      4PM%     nnX1l        UR                  5         [        S SS	S
S/S9n/ n[        SS5       HX  n[        S5       Vs/ s H.  o"[
        R                  " [        SU-  SUS-   -  5      5      U4PM0     nnUR                  U5        MZ     X1l        UR                  5         Ag s  snf s  snf s  snf )Nzx to x*xrc   )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  r	  )r   r&   r   r   rm  r3   )	r  r-   r8   r   r  randomchoicer  extend)rB   r  r   r8   r   qs         rH   	testBasicTestExternal.testBasic{  s   D
!D$)"I.IqAE
I.			d2QR7<RyAy!FMM%),-yA			4%S%('*Cj2 q!AMRSUYWYV]]5aq1u#>?CYAWKKN  			) /
 B Xs   D)*D.5D3c                J   / nS H|  n/ n[        S5       HV  n[        R                  " [        S5      5      nU[        R                  " [        S5      5      -   nUR                  XV45        MX     UR                  X#/5        M~     [	        S S9nXl        UR                  5         g )N)
r  r  re   r%  r  fr	  r  r   rI  r3      r6  r   )r-   r8  r9  rj   rf  r8   r   )rB   r8   ro   r  r   startendr  s           rH   testBrokenHorizontal!TestExternal.testBrokenHorizontal  s    GEF2YeCj1fmmE"I66ul+  KK( H $/			rK   c                x   / n[        S5       Ht  n[        R                  " [        S5      5      n[        R                  " [        S5      5      n[        R                  " [        SS5      5      nUR                  X4U/5        Mv     U R                  (       a  SnOS n[        US9nXl        UR                  5         g )Nr6  r#  rc   r6   rA  )r-   r8  r9  rj   r`   r  r8   r   )rB   r8   r   r   r   r   r   r  s           rH   testScatterWeighted TestExternal.testScatterWeighted  s    rAeBi(AeBi(AeArl+AKKq	"	  99 JJ J7			rK   c                R   / n[        SS5       HT  n[        S5       Vs/ s H*  o3[        R                  " [        SUS-   -  5      5      U4PM,     nnUR                  U5        MV     [        SS/4SSS	/4S
S/4/4[
        / SQ4[        [        S5       Vs/ s H  o3X3-  4PM
     sn4[        [        S5       Vs/ s H#  o3[        R                  " [        S5      5      4PM%     sn4[        U4[        S/ SQ4S/ SQ4/4[        / SQSS// SQ/4/nU H  u  pgU" SS9nXxl        UR                  5         UR                  R                  S-   n	[        [         R#                  5       U	-  5      n
[         R%                  SU
/5        UR'                  U
5        M     gs  snf s  snf s  snf )z
Write a graphic file for all graphs,
naming them after the appropriate class.
This is used to generate documentation samples.
rc   rm  r#  r3   Chopin)  '   	Schumanns)rK  .   )i  M   Brahms)i)  @   ))         )r3   rR  r2   )rm  rR  rQ  )rS     x   r6  r7  Major))Cz#00AA55)Dz#5600FF)Gz#2B00FFMinor))rX  z#004600)rY  z#00009b)rZ  z#00009B)z#8968CDz#96CDCDz#CD4F39z#FFD600z#FF5600)z#201a2bz#8f73bfz#a080d5z#6495EDz#FF83FANrA  r   writing fp:)r-   r8  r9  r:  rf  r  r  r  r  rO  r+  r8   r   r
  r   r  r   getRootTempDirr   r6   )rB   data3DPolygonBarsr   r   r;  graphClassesgraphClassNamer8   objfnr   s              rH   x_test_writeAllGraphs"TestExternal.x_test_writeAllGraphs  s    q!AEJ2YOYV]]5q1u#67;YAO$$Q'   -./02EFG-./1
 "EG"'),)Q!%j),.5:2Y?Y&--b	*+Y?A+,!NONOS ?()4U  #
2 %1 N D1CHKKM''&0B\002R78B##]B$78IIbM %1= P -?s   1FF
:*F$c                    [        S S9n/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/nX!l        UR                  5         UR                  R                  S-   n[        [        R                  5       U-  5      nUR                  U5        g )	NrA  )#525252#5f5f5f#797979#858585#727272#6c6c6c#8c8c8crl  rk  #999999rm  rh  rk  rg  rf  z#464646#3f3f3frn  #4c4c4cro  rh  rh  ro  ro  rf  rg  rh  ri  rj  rk  )rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rh  rk  rg  rg  ri  rh  rh  rh  rh  rh  rh  ri  #929292rm  )rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rl  rl  rl  ri  rh  ri  rp  rm  )rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  rl  rp  rm  )
rm  rm  rm  rm  rm  rm  rm  rm  rm  rm  )rm  rm  rm  rm  rm  r   )	r+  r8   r   r
  r   r  r   r]  r6   )rB   r  r8   rb  r   s        rH   x_test_writeGraphColorGrid'TestExternal.x_test_writeGraphColorGrid  sy    d+S
^'2=G%I& 			[[!!F*,,.34	rK   c                   / n[        SS9n[        S5       Vs/ s H  o3X3-  4PM
     nnXBl        UR                  US/5        [        SSSS9n[        S5       Vs/ s H  o3X3-  4PM
     nnXBl        UR                  US/5        [	        SS9n[        S5       Vs/ s H#  o3[
        R                  " [        S	5      5      4PM%     nnXBl        UR                  US
/5        [        SS9n/ n[        SS5       HT  n[        S5       Vs/ s H*  o3[
        R                  " [        SUS-   -  5      5      U4PM,     nnUR                  U5        MV     XBl        UR                  US/5        [        SSSS/ SQS9nXGl        UR                  US/5        U Hb  u  pUR                  5         U	S-   n
[        [        R                  5       U
-  5      n[        R                  SU/5        UR                  U5        Md     gs  snf s  snf s  snf s  snf )z&
Write graphing examples for the docs
NrA  r6  zgraphing-01zExponential Graphrc   )r&   r   r   zgraphing-02r7  zgraphing-03rm  r#  r3   zgraphing-04zRandom Datar  r.   )r  rr	  )r&   r   r'  r   r   zgraphing-05r   r\  )r  r-   r8   rj   r  r8  r9  r  r:  r   r  r   r]  r   r6   )rB   postr  r   r8   r   r;  r  ra  namerb  r   s               rH   x_test_writeGraphingDocs%TestExternal.x_test_writeGraphingDocs  s    D)$)"I.IqAE
I.Q&'2!M$)"I.IqAE
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   G9G>*H1HNc                    SSK Jn  UR                  5       nUR                  5       n[	        USS9nXEl        UR                  5         g )Nr   )discreter   )r   r   )music21.analysisrz  KrumhanslSchmucklersolutionLegendrO  r8   r   )rB   r   rz  ksr8   r  s         rH   testColorGridLegend TestExternal.testColorGridLegend+  s;    -))+  " JC@			rK   c                    [        S S9n[        S5       Vs/ s H  nSU 3SSSS.4PM     nnX1l        UR                  5         g s  snf )NrA  r3   r;  r   rs   rc   )r  r  re   )r  r-   r8   r   )rB   r	  r   r8   s       rH   testGraphVerticalBar!TestExternal.testGraphVerticalBar5  sJ    #t4?DRyIy!3qc!!!45yI			 Js   Ac                f    [        5       nUR                  b  [        S S9nUR                  5         g g )NrA  )r   r  r   r   )rB   rD   r  s      rH   testGraphNetworkxGraph#TestExternal.testGraphNetworkxGraph;  s,    !#==$"d3AIIK %rK   r   rY   )r   r   r   r   r`   r<  rD  rG  rc  rq  rw  r  r  r  r   r   rK   rH   r4  r4  x  s6    D0 /b:*XrK   r4  __main__)$r   
__future__r   r  r8  unittestmusic21r   music21.converter.subConvertersr   r   music21.graph.utilitiesr   r   r	   r
   r   Environmentr   ProtoM21Objectr   r   r+  rO  rf  r  r  r  r  r  r  TestCaser,  r4  r   mainTestr   rK   rH   <module>r     s1   #     8 ' '
 &&'9:VG"" VrU UpgU gTH5 HVP' P'f{# {#TC-5 C-L9>5 9>x6DU 6Dr\:e \:~d6% d6N%8 %I8$$ IX zT rK   