File: vtkPVXYChartView.cxx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (847 lines) | stat: -rw-r--r-- 26,041 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
/*=========================================================================

  Program:   ParaView
  Module:    vtkPVXYChartView.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkPVXYChartView.h"

#include "vtkAnnotationLink.h"
#include "vtkAxis.h"
#include "vtkChartBox.h"
#include "vtkChartLegend.h"
#include "vtkChartParallelCoordinates.h"
#include "vtkChartWarning.h"
#include "vtkChartXY.h"
#include "vtkCommand.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkCSVExporter.h"
#include "vtkDoubleArray.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPVPlotTime.h"
#include "vtkStringArray.h"
#include "vtkTextProperty.h"
#include "vtkXYChartRepresentation.h"

#include <string>
#include <sstream>

class vtkPVXYChartView::vtkInternals
{
public:
  // Keeps track of custom labels for each of the axis.
  vtkNew<vtkDoubleArray> CustomLabelPositions[4];
  bool UseCustomLabels[4];
  vtkInternals()
    {
    this->UseCustomLabels[0] = this->UseCustomLabels[1]
      = this->UseCustomLabels[2] = this->UseCustomLabels[3] = false;

    this->AxisRanges[0][0] =
      this->AxisRanges[1][0] =
      this->AxisRanges[2][0] =
      this->AxisRanges[3][0] = 0.0;
    this->AxisRanges[0][1] =
      this->AxisRanges[1][1] =
      this->AxisRanges[2][1] =
      this->AxisRanges[3][1] = 6.66;
    }

  double AxisRanges[4][2];
};


vtkStandardNewMacro(vtkPVXYChartView);

//----------------------------------------------------------------------------
vtkPVXYChartView::vtkPVXYChartView()
{
  this->Internals = new vtkInternals();

  this->Chart = NULL;
  this->InternalTitle = NULL;
  this->PlotTime = vtkPVPlotTime::New();
  this->HideTimeMarker = false;

  // Use the buffer id - performance issues are fixed.
  this->ContextView->GetScene()->SetUseBufferId(true);
  this->LogScaleWarningLabel = NULL;
}

//----------------------------------------------------------------------------
vtkPVXYChartView::~vtkPVXYChartView()
{
  if (this->Chart)
    {
    this->Chart->Delete();
    this->Chart = NULL;
    }
  if (LogScaleWarningLabel)
    {
    this->LogScaleWarningLabel->Delete();
    this->LogScaleWarningLabel = NULL;
    }
  this->PlotTime->Delete();
  this->PlotTime = NULL;

  this->SetInternalTitle(NULL);

  delete this->Internals;
}

//----------------------------------------------------------------------------
vtkAbstractContextItem* vtkPVXYChartView::GetContextItem()
{
  return this->GetChart();
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetSelection(
  vtkChartRepresentation* repr, vtkSelection* selection)
{
  (void)repr;

  if (this->Chart)
    {
    // we don't support multiple selection for now.
    this->Chart->GetAnnotationLink()->SetCurrentSelection(selection);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetChartType(const char *type)
{
  if (this->Chart)
    {
    this->Chart->Delete();
    this->Chart = NULL;
    }
  if (LogScaleWarningLabel)
    {
    this->LogScaleWarningLabel->Delete();
    this->LogScaleWarningLabel = NULL;
    }

  // Construct the correct type of chart
  if (strcmp(type, "Line") == 0 || strcmp(type, "Bar") == 0
    || strcmp(type, "Bag") == 0 || strcmp(type, "FunctionalBag") == 0
    || strcmp(type, "Area") == 0)
    {
    this->Chart = vtkChartXY::New();
    }
  else if (strcmp(type, "Box") == 0)
    {
    this->Chart = vtkChartBox::New();
    }
  else if (strcmp(type, "ParallelCoordinates") == 0)
    {
    this->Chart = vtkChartParallelCoordinates::New();
    }

  if (this->Chart)
    {
    // Default to empty axis titles
    this->SetAxisTitle(0, "");
    this->SetAxisTitle(1, "");
    this->Chart->AddPlot(this->PlotTime);

    this->Chart->AddObserver(vtkCommand::SelectionChangedEvent,
      this, &vtkPVXYChartView::SelectionChanged);
    this->ContextView->GetScene()->AddItem(this->Chart);

    // setup the annotation link.
    // Unlike vtkScatterPlotMatrix, vtkChart doesn't have valid annotation link
    // setup on creation, so create one.
    if (!this->Chart->GetAnnotationLink())
      {
      vtkNew<vtkAnnotationLink> annLink;
      this->Chart->SetAnnotationLink(annLink.GetPointer());
      }

    // Set up a warning for when log-scaling is requested on negative values
    this->LogScaleWarningLabel = vtkChartWarning::New();
    this->LogScaleWarningLabel->SetLabel(
      "WARNING!\n"
      "One or more plot series crosses or contains\n"
      "an axis origin. Use the View Options menu to\n"
      "turn off log-scaling or specify a valid axis\n"
      "range; or scroll the view; or remove the line\n"
      "series from the chart in the Properties Tab."
      );
    this->LogScaleWarningLabel->SetVisible(1);
    this->LogScaleWarningLabel->SetDimensions(150, 150, 150, 150);
    this->Chart->AddItem(this->LogScaleWarningLabel);

    // setup default mouse actions
    this->Chart->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::LEFT_BUTTON);
    this->Chart->SetActionToButton(vtkChart::ZOOM_AXIS, vtkContextMouseEvent::RIGHT_BUTTON);

    // set default selection mode
    this->Chart->SetSelectionMode(vtkContextScene::SELECTION_DEFAULT);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitle(const char* title)
{
  if (this->Chart)
    {
    std::string tmp(title);
    if (tmp.find("${TIME}") != std::string::npos)
      {
      this->SetInternalTitle(title);
      }
    else
      {
      this->Chart->SetTitle(title);
      this->SetInternalTitle(NULL);
      }
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleFont(const char* family, int pointSize,
                                         bool bold, bool italic)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetFontFamilyAsString(family);
    this->Chart->GetTitleProperties()->SetFontSize(pointSize);
    this->Chart->GetTitleProperties()->SetBold(static_cast<int>(bold));
    this->Chart->GetTitleProperties()->SetItalic(static_cast<int>(italic));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleFontFamily(const char* family)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetFontFamilyAsString(family);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleFontSize(int pointSize)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetFontSize(pointSize);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleBold(bool bold)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetBold(static_cast<int>(bold));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleItalic(bool italic)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetItalic(static_cast<int>(italic));
    }
}


//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleColor(double red, double green, double blue)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetColor(red, green, blue);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTitleAlignment(int alignment)
{
  if (this->Chart)
    {
    this->Chart->GetTitleProperties()->SetJustification(alignment);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendFontFamily(const char* family)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetLegend()->GetLabelProperties();
    prop->SetFontFamilyAsString(family);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendFontSize(int pointSize)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetLegend()->GetLabelProperties();
    prop->SetFontSize(pointSize);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendBold(bool bold)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetLegend()->GetLabelProperties();
    prop->SetBold(static_cast<int>(bold));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendItalic(bool italic)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetLegend()->GetLabelProperties();
    prop->SetItalic(static_cast<int>(italic));
    }
}


//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendVisibility(int visible)
{
  if (this->Chart)
    {
    this->Chart->SetShowLegend(visible? true : false);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendLocation(int location)
{
  if (this->Chart)
    {
    vtkChartLegend *legend = this->Chart->GetLegend();
    legend->SetInline(location < 4);
    switch(location)
      {
      case 0: // TOP-LEFT
        legend->SetHorizontalAlignment(vtkChartLegend::LEFT);
        legend->SetVerticalAlignment(vtkChartLegend::TOP);
        break;
      case 1: // TOP-RIGHT
        legend->SetHorizontalAlignment(vtkChartLegend::RIGHT);
        legend->SetVerticalAlignment(vtkChartLegend::TOP);
        break;
      case 2: // BOTTOM-RIGHT
        legend->SetHorizontalAlignment(vtkChartLegend::RIGHT);
        legend->SetVerticalAlignment(vtkChartLegend::BOTTOM);
        break;
      case 3: // BOTTOM-LEFT
        legend->SetHorizontalAlignment(vtkChartLegend::LEFT);
        legend->SetVerticalAlignment(vtkChartLegend::BOTTOM);
        break;
      case 4: // LEFT
        legend->SetHorizontalAlignment(vtkChartLegend::LEFT);
        legend->SetVerticalAlignment(vtkChartLegend::CENTER);
        break;
      case 5: // TOP
        legend->SetHorizontalAlignment(vtkChartLegend::CENTER);
        legend->SetVerticalAlignment(vtkChartLegend::TOP);
        break;
      case 6: // RIGHT
        legend->SetHorizontalAlignment(vtkChartLegend::RIGHT);
        legend->SetVerticalAlignment(vtkChartLegend::CENTER);
        break;
      case 7: // BOTTOM
        legend->SetHorizontalAlignment(vtkChartLegend::CENTER);
        legend->SetVerticalAlignment(vtkChartLegend::BOTTOM);
        break;
      case 8: // CUSTOM
        legend->SetHorizontalAlignment(vtkChartLegend::CUSTOM);
        legend->SetVerticalAlignment(vtkChartLegend::CUSTOM);
        break;
      default:
        break;
      }
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetLegendPosition(int x, int y)
{
  if (this->Chart)
    {
    this->Chart->GetLegend()->SetPoint(vtkVector2f(x, y));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetGridVisibility(int index, bool visible)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->SetGridVisible(visible);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisColor(int index, double red, double green,
                                         double blue)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->GetPen()->SetColorF(red, green, blue);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetGridColor(int index, double red, double green,
                                         double blue)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->GetGridPen()->SetColorF(red, green, blue);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelVisibility(int index, bool visible)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->SetLabelsVisible(visible);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelFont(int index, const char* family,
                                        int pointSize, bool bold,
                                        bool italic)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetLabelProperties();
    prop->SetFontFamilyAsString(family);
    prop->SetFontSize(pointSize);
    prop->SetBold(static_cast<int>(bold));
    prop->SetItalic(static_cast<int>(italic));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelFontFamily(int index, const char* family)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetLabelProperties();
    prop->SetFontFamilyAsString(family);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelFontSize(int index, int pointSize)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetLabelProperties();
    prop->SetFontSize(pointSize);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelBold(int index, bool bold)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetLabelProperties();
    prop->SetBold(static_cast<int>(bold));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelItalic(int index, bool italic)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetLabelProperties();
    prop->SetItalic(static_cast<int>(italic));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelColor(int index, double red,
                                              double green, double blue)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->GetLabelProperties()->SetColor(red, green,
                                                                blue);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelNotation(int index, int notation)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->SetNotation(notation);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelPrecision(int index, int precision)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->SetPrecision(precision);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisRangeMinimum(int index, double min)
{
  // cache for later use.
  this->Internals->AxisRanges[index][0] = min;

  if (this->Chart)
    {
    vtkAxis* axis = this->Chart->GetAxis(index);
    if (axis->GetBehavior() == vtkAxis::FIXED)
      {
      // change only if axes behavior is indeed "FIXED" i.e.
      // SetAxisUseCustomRange(...) was set to true for this axis.
      if (axis->GetUnscaledMinimum() != min)
        {
        axis->SetUnscaledMinimum(min);
        }
      }
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisRangeMaximum(int index, double max)
{
  // cache for later use.
  this->Internals->AxisRanges[index][1] = max;

  if (this->Chart)
    {
    vtkAxis* axis = this->Chart->GetAxis(index);
    if (axis->GetBehavior() == vtkAxis::FIXED)
      {
      // change only if axes behavior is indeed "FIXED" i.e.
      // SetAxisUseCustomRange(...) was set to true for this axis.
      if (axis->GetUnscaledMaximum() != max)
        {
        axis->SetUnscaledMaximum(max);
        }
      }
    }
}


//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisUseCustomRange(int index, bool useCustomRange)
{
  if (this->Chart)
    {
    vtkAxis* axis = this->Chart->GetAxis(index);
    if (useCustomRange && (axis->GetBehavior() != vtkAxis::FIXED))
      {
      axis->SetBehavior(vtkAxis::FIXED);
      axis->SetUnscaledMinimum(this->Internals->AxisRanges[index][0]);
      axis->SetUnscaledMaximum(this->Internals->AxisRanges[index][1]);
      }
    else if (!useCustomRange && (axis->GetBehavior() != vtkAxis::AUTO))
      {
      axis->SetBehavior(vtkAxis::AUTO);
      // set to some value so we notice when this gets used.
      axis->SetMinimum(0.0);
      axis->SetMaximum(6.66);
      }
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLogScale(int index, bool logScale)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->SetLogScale(logScale);
    this->Chart->Update();
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitle(int index, const char* title)
{
  if (this->Chart && this->Chart->GetAxis(index))
    {
    this->Chart->GetAxis(index)->SetTitle(title);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleFont(int index, const char* family,
                                             int pointSize, bool bold,
                                             bool italic)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetTitleProperties();
    prop->SetFontFamilyAsString(family);
    prop->SetFontSize(pointSize);
    prop->SetBold(static_cast<int>(bold));
    prop->SetItalic(static_cast<int>(italic));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleFontFamily(int index, const char* family)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetTitleProperties();
    prop->SetFontFamilyAsString(family);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleFontSize(int index, int pointSize)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetTitleProperties();
    prop->SetFontSize(pointSize);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleBold(int index, bool bold)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetTitleProperties();
    prop->SetBold(static_cast<int>(bold));
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleItalic(int index, bool italic)
{
  if (this->Chart)
    {
    vtkTextProperty *prop = this->Chart->GetAxis(index)->GetTitleProperties();
    prop->SetItalic(static_cast<int>(italic));
    }
}


//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisTitleColor(int index, double red,
                                              double green, double blue)
{
  if (this->Chart)
    {
    this->Chart->GetAxis(index)->GetTitleProperties()->SetColor(red, green,
                                                                blue);
    }
}


//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisUseCustomLabels(int index, bool use_custom_labels)
{
  if (index >= 0 && index < 4)
    {
    this->Internals->UseCustomLabels[index] = use_custom_labels;
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabelsNumber(int axis, int n)
{
  if (axis >=0 && axis < 4)
    {
    this->Internals->CustomLabelPositions[axis]->SetNumberOfTuples(n);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetAxisLabels(int axis, int i, double value)
{
  if (axis >=0 && axis < 4)
    {
    this->Internals->CustomLabelPositions[axis]->SetValue(i, value);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTooltipNotation(int notation)
{
  for(int i = 0; i < this->Chart->GetNumberOfPlots(); i++)
    {
    this->Chart->GetPlot(i)->SetTooltipNotation(notation);
    }
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SetTooltipPrecision(int precision)
{
  for(int i = 0; i < this->Chart->GetNumberOfPlots(); i++)
    {
    this->Chart->GetPlot(i)->SetTooltipPrecision(precision);
    }
}

//----------------------------------------------------------------------------
vtkChart* vtkPVXYChartView::GetChart()
{
  return this->Chart;
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::Render(bool interactive)
{
  if (!this->Chart)
    {
    return;
    }
  if (this->InternalTitle)
    {
    std::ostringstream new_title;
    std::string title(this->InternalTitle);
    size_t pos = title.find("${TIME}");
    if (pos != std::string::npos)
      {
      // The string was found - replace it and set the chart title.
      new_title << title.substr(0, pos)
                << this->GetViewTime()
                << title.substr(pos + strlen("${TIME}"));
      this->Chart->SetTitle(new_title.str().c_str());
      }
    }

  this->PlotTime->SetTime(this->GetViewTime());
  this->PlotTime->SetTimeAxisMode(vtkPVPlotTime::NONE);

  // Decide if time is being shown on any of the axis.
  // Iterate over all visible representations and check is they have the array
  // named "Time" on either of the axes.
  int num_reprs = this->GetNumberOfRepresentations();
  for (int cc=0; (this->HideTimeMarker == false) && (cc < num_reprs); cc++)
    {
    vtkXYChartRepresentation * repr = vtkXYChartRepresentation::SafeDownCast(
      this->GetRepresentation(cc));
    if (repr && repr->GetVisibility())
      {
      if (repr->GetXAxisSeriesName() &&
        strcmp(repr->GetXAxisSeriesName(), "Time") == 0)
        {
        this->PlotTime->SetTimeAxisMode(vtkPVPlotTime::X_AXIS);
        break;
        }
      }
    }

  // For now we only handle X-axis time. If needed we can add support for Y-axis.
  this->Superclass::Render(interactive);
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::SelectionChanged()
{
  this->InvokeEvent(vtkCommand::SelectionChangedEvent);
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::Update()
{
  this->Superclass::Update();

  // At this point, all representations must have updated which series are
  // visible, etc. So we can now recalculate the axes bounds to pick a good
  // value.
  if (this->Chart == NULL)
    {
    return;
    }

  // handle custom labels. We specify custom labels in here since vtkAxis will
  // discard the custom labels when the mode was set to not use custom labels,
  // so we need to provide the labels each time to the chart.
  for (int axis=0; axis < 4 && axis < this->Chart->GetNumberOfAxes(); axis++)
    {
    vtkAxis* chartAxis= this->Chart->GetAxis(axis);
    if(!chartAxis)
      {
      continue;
      }
    if (this->Internals->UseCustomLabels[axis])
      {
      vtkSmartPointer<vtkDoubleArray> ticks =
        this->Internals->CustomLabelPositions[axis].GetPointer();
      if (chartAxis->GetLogScaleActive())
        {
        vtkNew<vtkDoubleArray> logTicks;
        logTicks->DeepCopy(ticks.GetPointer());
        double* p = logTicks->GetPointer(0);
        for (vtkIdType i = 0; i <= logTicks->GetMaxId(); ++i, ++p)
          {
          *p = log10(fabs(*p));
          }
        ticks = logTicks.GetPointer();
        }
      chartAxis->SetCustomTickPositions(ticks.GetPointer());
      }
    else
      {
      chartAxis->SetCustomTickPositions(NULL);
      }
    chartAxis->Update();
    }

  // This will recompute the bounds for each of the axes as appropriate.
  // Note, this doesn't happen immediately. vtkChartXY recomputes the bounds
  // on the subsequent "paint" or the next time vtkPVXYChartView::Render()
  // is called.
  this->Chart->RecalculateBounds();


  // Things to remember:
  // When any property on the chart representations change, including series
  // visibility, color, etc., the view is marked "dirty" and hence this
  // vtkPVXYChartView::Update(), would indeed get called before the next Render.
  // Representations' RequestData may not get called, however since the
  // representations use 'update-supression' mechanisms (unless the
  // representations called MarkModified on itself).
  // In short, if anything changes on representation: data or display properties,
  // or anything changes on the view, this method will be called.
  // We still cannot update the axes ranges here since vtkChartXY doesn't update
  // axes range until paint.
  // Also, when new data arrays show up in the representation's input,
  // the ServerManager sets up default series visibilities, and that code
  // excutes in "PostUpdate". Hence, we don't trigger
  // vtkChartRepresentation::PrepareForRendering() here, instead wait for the
  // subsequent render call.
}

//----------------------------------------------------------------------------
void vtkPVXYChartView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}