'''
This  is  a  macro  in  Paraview  to  generate  flow  rate  vs.  time  plot.'''
# trace generated using paraview version 5.8.1
#
# To ensure correct image size when batch processing, please search 
# for and uncomment the line `# renderView*.ViewSize = [*,*]`

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

import  matplotlib.pyplot  as  plt
import  numpy  as  np

# find source
extractSelection1 = FindSource('ExtractSelection1')

# destroy extractSelection1
Delete(extractSelection1)
del extractSelection1

# find source
progFilterLoadFlux = FindSource('ProgFilterLoadFlux')

# create a new 'Extract Selection'
extractSelection1 = ExtractSelection(Input=progFilterLoadFlux)
quartileChartView1 = FindViewOrCreate('QuartileChartView1', viewtype='QuartileChartView')

plotDataOverTime1  =  FindSource('PlotDataOverTime1')

##  added
colors = plt.cm.jet(np.linspace(0,1,len(range(1+int(servermanager.Fetch(FindSource('ProgFilterLoadFlux')).GetPointData().GetArray('SectionID').GetValueRange()[-1])))))
myID_list  =  FindSource('ExtractSelection1').Selection.IDs[1::2]
my_secID_list  =  [int(servermanager.Fetch(FindSource('ProgFilterLoadFlux')).GetPointData().GetArray('SectionID').GetValue(int(_)))  for  _  in  myID_list]
my_colors_list  =  [colors[int(secID)]  for  secID  in  my_secID_list]
my_RGB_list  =  [my_colors_list[_][0:3]  for  _  in  range(len(my_colors_list))]


plotDataOverTime1Display = Show(plotDataOverTime1, quartileChartView1, 'QuartileChartRepresentation')

plotDataOverTime1Display.CompositeDataSetIndex =\
                            FindSource('ExtractSelection1').Selection.IDs[1::2]
plotDataOverTime1Display.SeriesVisibility = ['Flux (id=' + \
            str(myID-1) +')' for myID in FindSource('ExtractSelection1').Selection.IDs[1::2]]

forest  =  ([[['Flux (id=' + \
            str(myID-1) +')'], [str(my_RGB_list[ID_index][0])],[str(my_RGB_list[ID_index][1])],[str(my_RGB_list[ID_index][2])]]  for ID_index,  myID in enumerate(FindSource('ExtractSelection1').Selection.IDs[1::2])])
pile  =  []
for  tree  in  forest:
    for  leaf  in  tree:
        pile.append(leaf[0])

plotDataOverTime1Display.SeriesColor = pile

print('Barva:')
print(pile)

#### uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).
