-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBasicPlotManagerPC.java
More file actions
2385 lines (2081 loc) · 73.9 KB
/
Copy pathBasicPlotManagerPC.java
File metadata and controls
2385 lines (2081 loc) · 73.9 KB
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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Rev 0.1
*
* PlotManager can only manage one chart at a time. Use multiple plot managers to manage multiple charts
*/
package com.shimmerresearch.guiUtilities.plot;
import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.IAxis;
import info.monitorenter.gui.chart.IAxis.AxisTitle;
import info.monitorenter.gui.chart.IAxisLabelFormatter;
import info.monitorenter.gui.chart.IAxisScalePolicy;
import info.monitorenter.gui.chart.IRangePolicy;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.ITracePainter;
import info.monitorenter.gui.chart.ITracePoint2D;
import info.monitorenter.gui.chart.axis.AAxis;
import info.monitorenter.gui.chart.axis.AxisLinear;
import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyAutomaticBestFit;
import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyManualTicks;
import info.monitorenter.gui.chart.labelformatters.ALabelFormatter;
import info.monitorenter.gui.chart.labelformatters.LabelFormatterAutoUnits;
import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate;
import info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber;
import info.monitorenter.gui.chart.labelformatters.LabelFormatterSimple;
import info.monitorenter.gui.chart.labelformatters.LabelFormatterUnit;
import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport;
import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded;
import info.monitorenter.gui.chart.traces.Trace2DLtd;
import info.monitorenter.gui.chart.traces.painters.TracePainterDisc;
import info.monitorenter.gui.chart.traces.painters.TracePainterFill;
import info.monitorenter.gui.chart.traces.painters.TracePainterLine;
import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar;
import info.monitorenter.util.Range;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.collections.buffer.CircularFifoBuffer;
import com.shimmerresearch.driver.FormatCluster;
import com.shimmerresearch.driver.ObjectCluster;
import com.shimmerresearch.driverUtilities.FftCalculateDetails;
import com.shimmerresearch.driverUtilities.UtilShimmer;
import com.shimmerresearch.driverUtilities.ChannelDetails.CHANNEL_AXES;
import com.shimmerresearch.guiUtilities.AbstractPlotManager;
public class BasicPlotManagerPC extends AbstractPlotManager {
protected String mEventMarkerCheck="";
int mXAxisLimit = 500;
double mXAxisTimeDuration = 5;
//public List<ITrace2D> mListofTraces = new ArrayList<ITrace2D>();
public List<ITrace2D> mListofTraces = Collections.synchronizedList(new ArrayList<ITrace2D>());
public HashMap<String, CircularFifoBuffer> mMapOfCirculurBufferedTraceDataPoints = new HashMap<String, CircularFifoBuffer>();
//public HashMap<String, ArrayList< Point2D.Double>> mMapofPoints = new HashMap<String, ArrayList< Point2D.Double>>();
public HashMap<String,Integer> mMapofDefaultXAxisSizes = new HashMap<String,Integer>();
int numberOfRowPropertiestoCheck = 2;
boolean mClearGraphatLimit = false;
Chart2D mChart = null;
public int mWindowSize = 0;
public HashMap<String,Double> mMapofHalfWindowSize = new HashMap<String,Double>();
public static float DEFAULT_LINE_THICKNESS=2;
protected double mCurrentXValue = 0;
protected boolean mIsPlotPaused = false;
public boolean mIsLegendLabelsPainted = true;
public boolean mIsScaleLabelsPainted = true;
public boolean mIsAxisLabelsPainted = true;
public boolean mIsGridOn = false;
public boolean mIsHRVisible = false;
public boolean mEnablePCTS = true;
public boolean mSetTraceName = true;
private boolean mIsDebugMode = false;
private boolean mIsTraceDataBuffered = false;
protected boolean isFirstPointOnFillTrace = true;
protected boolean isSingleEventMarkerTest = true;
public PlotCustomFeature pcf=null;
private String mTitle = "";
//private AAxis<IAxisScalePolicy> yAxisLeft;
private AAxis<IAxisScalePolicy> yAxisRight;
private IAxis< ? > xAxis;
//Mark test code
private CHANNEL_AXES mXAisType = CHANNEL_AXES.TIME;
transient protected Timer mTimerCalculateFft;
private int mTimerPeriodCalculateFft = 1000;
private int mTimerDelayCalculateFft = 1000;
public LinkedHashMap<String, FftCalculateDetails> mMapOfFftsToPlot = new LinkedHashMap<String, FftCalculateDetails>();
private boolean mIsFftShowingDc = true;
private int mFftOverlapPercent = 0;
public HashMap<String, Double> mMapOfLastDataPoints = new HashMap<String, Double>();
private TimeZone timeZone = Calendar.getInstance().getTimeZone();
private UtilShimmer utilShimmer = new UtilShimmer(this.getClass().getSimpleName(), true);
/** Scale type options */
public enum SCALE_SETTING{
AUTO,
FIXED,
CUSTOM
}
// --- Constructors START
/**Constructor Used by API examples
*
*/
public BasicPlotManagerPC(){
mMapofXAxisGeneratedValue.clear();
initializeAxesForTimeBig();
}
/**Constructor Used by Consensys
* @param propertiestoPlot Sets the properties to plot
* @param limit Sets the X axis limit for the series
* @param chart the XYPlot in main UI thread so the series can be added
* @throws Exception
*/
public BasicPlotManagerPC(List<String[]> propertiestoPlot, int limit, Chart2D chart) throws Exception {
mXAxisLimit = limit;
mChart = chart;
mChart.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); // Dec 2016: RM put this in as the default cursor for jchart2d is cross-hair
mChart.getAxisY().setFormatter(new LabelFormatterNumber());
if(propertiestoPlot!=null){
for (int i=0;i<propertiestoPlot.size();i++){
addSignal(propertiestoPlot.get(i),chart);
}
}
initializeAxesForTimeBig();
// for(int j = 0; j< propertiestoPlot.size(); j++){
// for(int l = 0 ; l < propertiestoPlot.get(j).length;l++){
// utilShimmer.consolePrintLn(""+propertiestoPlot.get(j)[l]);
// }
// }
}
// --- Constructors END
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignal(String[] signal, Chart2D chart) throws Exception{
return this.addSignal(signal, chart, mXAxisLimit);
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignalAsBarPlot(String[] signal, Chart2D chart, int windowSize) throws Exception{
return this.addSignalAsBarPlot(signal, chart, mXAxisLimit, windowSize);
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @param usePaintIndividualPointsOnly No plot line generated only markers for data points, if true
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignal(String[] signal, Chart2D chart, boolean usePaintIndividualPointsOnly) throws Exception{
ITrace2D trace = this.addSignal(signal, chart);
if (usePaintIndividualPointsOnly){
trace.setTracePainter(new TracePainterDisc(4));
}
return trace;
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @param plotMaxSize Max Number of Data point on the plot
* @return
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignalAsBarPlot(String [] signal, Chart2D chart, int plotMaxSize, int windowSize) throws Exception{
ITrace2D trace;
if (!checkIfPropertyExist(signal)){
trace = addBarTrace(chart, plotMaxSize);
String name = addSignalCommon(chart, trace, signal, plotMaxSize);
if (windowSize!=0){
double mhalf = ((double)windowSize)/2.0;
mMapofHalfWindowSize.put(name, mhalf);
}
}
else {
throw new Exception("Error: " + joinChannelStringArray(signal) +" Signal/Property already exist.");
}
return trace;
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @param plotMaxSize Max Number of Data point on the plot
* @return
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignal(String[] signal, Chart2D chart, int plotMaxSize) throws Exception{
ITrace2D trace;
if (!checkIfPropertyExist(signal)){
if(mDefaultLineStyle==PLOT_LINE_STYLE.CONTINUOUS
|| mDefaultLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS){
trace = addNormalTraceLeft(chart, plotMaxSize);
if(mDefaultLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS){
trace.setTracePainter(new TracePainterDisc(4));
}
}
else if(mDefaultLineStyle==PLOT_LINE_STYLE.BAR){
trace = addBarTrace(chart, plotMaxSize);
}
else{
trace = addNormalTraceLeft(chart, plotMaxSize);
}
addSignalCommon(chart, trace, signal, plotMaxSize);
setTraceSize(trace, plotMaxSize);
}
else {
throw new Exception("Error: " + joinChannelStringArray(signal) +" Signal/Property already exist.");
}
// printListOfTraces();
return trace;
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param chart Chart from UI thread
* @param plotMaxSize Max Number of Data point on the plot
* @return
* @throws Exception if signal already exist in plotmanager
*/
public ITrace2D addSignalUsingRightYAxis(String[] signal, Chart2D chart, int plotMaxSize, String title, int minRange, int maxRange) throws Exception{
ITrace2D trace;
if (!checkIfPropertyExist(signal)){
yAxisRight = createRightYAxis(chart);
chart.setAxisYRight(yAxisRight, 0);
trace = addNormalTraceRight(chart, plotMaxSize);
addSignalCommon(chart, trace, signal, plotMaxSize);
setTraceSize(trace, plotMaxSize);
}
else {
throw new Exception("Error: " + joinChannelStringArray(signal) +" Signal/Property already exist.");
}
return trace;
}
private AAxis<IAxisScalePolicy> createRightYAxis(Chart2D chart) {
//AAxis<IAxisScalePolicy> yAxisRight;
AAxis<IAxisScalePolicy> yAxisRight = new AxisLinear<IAxisScalePolicy>();
// yAxisRight.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisRight.setAxisScalePolicy(new AxisScalePolicyAutomaticBestFit());
yAxisRight.setFormatter(new LabelFormatterNumber());
//yAxisRight.setMinorTickSpacing(10);
//yAxisRight.setStartMajorTick(true);
yAxisRight.setPaintGrid(false);
//yAxisRight.setAxisTitle(new IAxis.AxisTitle(title));
//IRangePolicy rangePolicy = new RangePolicyFixedViewport(new Range(minRange,maxRange));
//yRightAxis.setRangePolicy(rangePolicy);
return yAxisRight;
}
private String addSignalCommon(Chart2D chart, ITrace2D trace, String[] signal, int plotMaxSize) {
mListofTraces.add(trace);
//super.addSignalGenerateRandomColor(signal);
super.addSignalUseDefaultColors(signal);
int i = mListOfTraceColorsCurrentlyUsed.size()-1;
int [] colorrgbaray = mListOfTraceColorsCurrentlyUsed.get(i);
Color color = new Color(colorrgbaray[0], colorrgbaray[1], colorrgbaray[2]);
mListofTraces.get(i).setColor(color);
String traceName = joinChannelStringArray(signal);
//utilShimmer.consolePrintErrLn("TRACE NAME: " +name);
if(mSetTraceName) {
mListofTraces.get(i).setName(traceName);
} else {
mListofTraces.get(i).setName("");
}
mChart=chart;
mMapofDefaultXAxisSizes.put(traceName, plotMaxSize);
if(isXAxisFrequency()){
// mMapOfFftsToPlot.put(traceName, new FftCalculateDetails(signal[0], signal, samplingRate));
FftCalculateDetails fftCalculateDetails = new FftCalculateDetails(signal[0], signal);
fftCalculateDetails.setFftOverlapPercent(mFftOverlapPercent);
mMapOfFftsToPlot.put(traceName, fftCalculateDetails);
}
return traceName;
}
private ITrace2D addNormalTraceLeft(Chart2D chart, int plotMaxSize) {
ITrace2D trace = createNormalTrace(plotMaxSize);
chart.addTrace(trace);
return trace;
}
private ITrace2D addNormalTraceRight(Chart2D chart, int plotMaxSize) {
ITrace2D trace = createNormalTrace(plotMaxSize);
chart.addTrace(trace,chart.getAxisX(),yAxisRight);
return trace;
}
private ITrace2D addBarTrace(Chart2D chart, int plotMaxSize) {
ITrace2D trace = createBarTrace(chart, plotMaxSize);
chart.addTrace(trace);
return trace;
}
private ITrace2D createNormalTrace(int plotMaxSize) {
Trace2DLtd trace = new Trace2DLtdMonotonicX(plotMaxSize); //DEV-896: monotonic-X trace avoids O(n) minX rescans per sample
BasicStroke stroke = ((BasicStroke)trace.getStroke());
BasicStroke newStroke = new BasicStroke(DEFAULT_LINE_THICKNESS,stroke.getEndCap(),stroke.getLineJoin(),stroke.getMiterLimit(),stroke.getDashArray(),stroke.getDashPhase());
trace.setStroke(newStroke);
return trace;
}
private ITrace2D createBarTrace(Chart2D chart, int plotMaxSize) {
ITrace2D trace = new Trace2DLtdMonotonicX(plotMaxSize); //DEV-896: monotonic-X trace avoids O(n) minX rescans per sample
trace.setTracePainter(new TracePainterVerticalBar(chart));
return trace;
}
/** Adds a signal to the chart. The chart is referenced internally, for use in removing signals. Color is assigned randomly
* @param signal Signal to plot
* @param plotMaxSize Max Number of Data point on the plot
* @throws Exception if signal already exist in plotmanager
*/
private ITrace2D addSignalToExistingChartInternal(String[] signal, int plotMaxSize, Color color) throws Exception{
if (!checkIfPropertyExist(signal)){
ITrace2D trace = new Trace2DLtdMonotonicX(plotMaxSize); //DEV-896: monotonic-X trace avoids O(n) minX rescans per sample
mChart.addTrace(trace);
mListofTraces.add(trace);
super.addSignalGenerateRandomColor(signal);
int i = mListOfTraceColorsCurrentlyUsed.size()-1;
int [] colorrgbaray = mListOfTraceColorsCurrentlyUsed.get(i);
mListofTraces.get(i).setColor(color);
String name = joinChannelStringArray(signal);
if(mSetTraceName) {
mListofTraces.get(i).setName(name);
} else {
mListofTraces.get(i).setName("");
}
return trace;
}
else {
throw new Exception("Error: " + joinChannelStringArray(signal) +" Signal/Property already exist.");
}
}
public void addTrace2D(ITrace2D trace, String[] signal, int plotMaxSize){
mChart.addTrace(trace);
mListofTraces.add(trace);
setTraceSize(trace, plotMaxSize);
String name = joinChannelStringArray(signal);
mMapofDefaultXAxisSizes.put(name, plotMaxSize);
super.addSignal(signal);
}
// public void addXAxis(String[] key){
// super.addXAxis(key);
// }
public Chart2D getChart(){
return mChart;
}
/**Removes all traces, colours, and signal names from plot manager, and clears Chart2D
* @param chart the Chart to be cleared
*/
public void removeAllSignals(){
mCurrentXValue=0;
super.removeAllSignals();
if (mChart!=null){
try {
mChart.removeAllTraces();
mChart.removeAll();
}
catch (Exception e){
e.printStackTrace();
}
}
mListofTraces.clear();
mMapofXAxisGeneratedValue.clear();
mMapofDefaultXAxisSizes.clear();
mMapOfFftsToPlot.clear();
mMapOfLastDataPoints.clear();
}
/**Removes signal from plotmanager and chart.
*
* @param signal Signal to be removed
*/
private void removeSignalInternal(String[] signal){
synchronized(mListofPropertiestoPlot){
Iterator <String[]> entries = mListofPropertiestoPlot.iterator();
int i = 0;
while (entries.hasNext()) {
String[] prop = entries.next();
boolean found = true;
for (int p=0;p<numberOfRowPropertiestoCheck;p++){
if (!prop[p].equals(signal[p])){
found = false;
// utilShimmer.consolePrintLn("SIGNAL NOT FOUND: " + joinChannelStringArray(signal));
break;
}
}
if (found){
String traceName = joinChannelStringArray(signal);
removeSignalCommon(traceName);
//utilShimmer.consolePrintErrLn("mChart.removeTrace: " +mListofTraces.get(i));
mChart.removeTrace(mListofTraces.get(i));
mListofTraces.remove(i);
super.removeSignal(i);
}
i++;
}
}
}
private void removeSignalCommon(String traceName) {
mMapOfFftsToPlot.remove(traceName);
mMapOfLastDataPoints.remove(traceName);
}
/**Removes signal from plotmanager and chart.
*
* @param signal Signal to be removed
*/
public void removeSignal(String[] signal){
synchronized(mListofPropertiestoPlot){
for (int i=0;i<mListofPropertiestoPlot.size();i++){
String[] prop = mListofPropertiestoPlot.get(i);
boolean found = true;
for (int p=0;p<numberOfRowPropertiestoCheck;p++){
if (!prop[p].equals(signal[p])){
found = false;
// utilShimmer.consolePrintLn("SIGNAL NOT FOUND: " + joinChannelStringArray(signal));
break;
}
}
if (found){
String traceName = joinChannelStringArray(signal);
mMapofDefaultXAxisSizes.remove(traceName);
mListofTraces.get(i).removeAllPoints(); // added this line for ConsensysGQ as we keep hold the trace for the single HR and GSR plot
removeSignalCommon(traceName);
mChart.removeTrace(mListofTraces.get(i));
mListofTraces.remove(i);
super.removeSignal(i);
}
}
}
}
public void setTitle(String title) {
mTitle = title;
}
public String getTitle() {
return mTitle;
}
public void setYAxisLabel(String label){
setYAxisLabel(label, null);
}
public void setYAxisLabel(String label, Font font){
IAxis<?> y = mChart.getAxisY();
AxisTitle axisTitle = new AxisTitle(label);
if(font != null){
axisTitle.setTitleFont(font);
}
y.setAxisTitle(axisTitle);
}
public void setXAxisLabel(String label){
setXAxisLabel(label, null);
}
public void setXAxisLabel(String label, Font font){
IAxis<?> x = mChart.getAxisX();
AxisTitle axisTitle = new AxisTitle(label);
if(font != null){
axisTitle.setTitleFont(font);
}
x.setAxisTitle(axisTitle);
}
public void setXAxisRange(double minX,double maxY){
IAxis<?> x = mChart.getAxisX();
x.setRangePolicy(new RangePolicyFixedViewport(new Range(minX, maxY)));
}
public void setXAxisRangeBasedOnXDuration(){
setXAxisRange(mCurrentXValue-(mXAxisTimeDuration*1000), mCurrentXValue);
}
/** Makes the graph initially fill from right rather then the left.
* @param samplingRate
*/
public void setXAxisRangeBasedOnXDurationSubtractSingleSamplingRate(double samplingRate){
double minTime = mCurrentXValue-(mXAxisTimeDuration*1000);
double samplingDurationInMs = (1/samplingRate)*1000;
minTime=minTime+samplingDurationInMs;
setXAxisRange(minTime, mCurrentXValue);
}
public void setYAxisRange(double miny,double maxy){
IAxis<?> yAxisLeft = mChart.getAxisY();
yAxisLeft.setRangePolicy(new RangePolicyFixedViewport(new Range(miny, maxy)));
}
public void setYAxisMajorTickSpacing(double tickSpacing){
try {
IAxis<IAxisScalePolicy> yAxisLeft = (IAxis<IAxisScalePolicy>)mChart.getAxisY();
yAxisLeft.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisLeft.setMajorTickSpacing(tickSpacing);
}
catch(Exception e) {
e.printStackTrace();
}
}
public void setYAxisMinorTickSpacing(double tickSpacing){
try {
IAxis<IAxisScalePolicy> yAxisLeft = (IAxis<IAxisScalePolicy>)mChart.getAxisY();
yAxisLeft.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisLeft.setMinorTickSpacing(tickSpacing);
}
catch(Exception e) {
e.printStackTrace();
}
}
public void setYAxisTickSize(double miny, double maxy){
IAxis<?> yAxisLeft = mChart.getAxisY();
yAxisLeft.setRangePolicy(new RangePolicyFixedViewport(new Range(miny, maxy)));
}
/**
* @return the mXAxisLimit
*/
public int getXAxisLimit() {
return mXAxisLimit;
}
/**
* @param xAxisLimit the mXAxisLimit to set
*/
public void setXAxisLimit(int xAxisLimit) {
this.mXAxisLimit = xAxisLimit;
}
public void initializeAxes(int pxWidth) {
if(isXAxisTime()){
if (pxWidth<300){
initializeAxesForTimeSmall();
}
else if (pxWidth<600){
initializeAxesForTimeMedium();
}
else {
initializeAxesForTimeBig();
}
}
else if(isXAxisFrequency()){
initializeAxesAutoUnits();
setXAxisLabel("Freq (Hz)", null);
// setYAxisLabel("Power (dB)");
// setXAxisRange(0, 100);
} else if (isXAxisValue()){
initializeAxesAutoUnits();
}
}
public void initializeAxesForTimeBig(){
initializeAxesForTime("HH:mm:ss");
}
public void initializeAxesForTimeMedium(){
initializeAxesForTime("mm:ss");
}
public void initializeAxesForTimeSmall(){
initializeAxesForTime("ss");
}
public void initializeAxesAutoUnits(){
initializeAxesCommon(new LabelFormatterAutoUnits());
}
private void initializeAxesForTime(String format){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
simpleDateFormat.setTimeZone(timeZone);
initializeAxesCommon(new LabelFormatterDate(simpleDateFormat));
}
private void initializeAxesCommon(IAxisLabelFormatter xAxisLblFormatter){
if (mEnablePCTS && mChart!=null){
xAxis = mChart.getAxisX();
xAxis.setFormatter(xAxisLblFormatter);
// //mChart.setRequestedRepaint(true);
//
// // JC: the yAxis code seems to be legacy code which no longer does anything (20 Jan 2015)
// // RM: we need to create the yAxis so we can set the range
// yAxisLeft = new AxisLinear<IAxisScalePolicy>();
//
// //yAxisRight = new AxisLinear<IAxisScalePolicy>();
//// NumberFormat format = new DecimalFormat("#");
//// format.setMaximumIntegerDigits(3);
//// yAxis.setFormatter(new LabelFormatterNumber(format));
// if(mChart != null){
// if(yAxisLeft != null){
// //TODO the below line throws a NullPointerException sometimes! Don't know why (RM)
//
// try{
// mChart.setAxisYLeft(yAxisLeft, 0);
// }
// catch(Exception e){
// // RM Double.Nan was causing a non critical exception here
// //e.printStackTrace();
// }
// }
// }
}
}
public void setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
}
public void clearTimeZone() {
this.timeZone = TimeZone.getTimeZone("GMT");
}
//change color
public void changeTraceColor(String traceName,int[] colorArray){
int index = getTraceIndexFromName(traceName);
if(index!=-1){
mListOfTraceColorsCurrentlyUsed.set(index, colorArray);
mListofTraces.get(index).setColor(new Color(colorArray[0],colorArray[1],colorArray[2]));
}
}
public int getIndex(String name){
int index=0;
synchronized(mListofPropertiestoPlot){
Iterator <String[]> entries = mListofPropertiestoPlot.iterator();
while (entries.hasNext()) {
String n = joinChannelStringArray(entries.next());
if (n.equals(name)){
return index;
}
index++;
}
}
return -1;
}
private int getTraceIndexFromName(String traceName) {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
int i=0;
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
if(trace.getName().equals(traceName)) {
return i;
}
}
i++;
}
return -1;
}
}
public ITrace2D getTraceFromName(String traceName) {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
if(trace.getName().equals(traceName)) {
return trace;
}
}
}
return null;
}
}
public void changeTraceColor(int index,int[] colorArray){
//change color
mListOfTraceColorsCurrentlyUsed.set(index, colorArray);
mListofTraces.get(index).setColor(new Color(colorArray[0],colorArray[1],colorArray[2]));
}
public void changeAllTraceColor(int[] colorArray){
//change color
synchronized(mListOfTraceColorsCurrentlyUsed){
Iterator <int[]> entries = mListOfTraceColorsCurrentlyUsed.iterator();
while (entries.hasNext()) {
int[] i = entries.next();
i = colorArray;
}
}
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
trace.setColor(new Color(colorArray[0],colorArray[1],colorArray[2]));
}
}
}
}
public Color getTraceColour(String traceName){
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
if(trace.getName().equals(traceName)) {
return trace.getColor();
}
}
}
return Color.white;
}
}
public void setTraceThickness(String traceName, float thickness) {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
if(trace.getName().equals(traceName)) {
BasicStroke stroke = ((BasicStroke)trace.getStroke());
BasicStroke newstroke = new BasicStroke(thickness,stroke.getEndCap(),stroke.getLineJoin(),stroke.getMiterLimit(),stroke.getDashArray(),stroke.getDashPhase());
trace.setStroke(newstroke);
}
}
}
}
}
public void setAllTraceThickness(float thickness) {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
BasicStroke stroke = ((BasicStroke)trace.getStroke());
BasicStroke newstroke = new BasicStroke(thickness,stroke.getEndCap(),stroke.getLineJoin(),stroke.getMiterLimit(),stroke.getDashArray(),stroke.getDashPhase());
trace.setStroke(newstroke);
}
}
}
}
public void increaseAllTraceThickness() {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
BasicStroke stroke = ((BasicStroke)trace.getStroke());
BasicStroke newstroke = new BasicStroke(stroke.getLineWidth()+1,stroke.getEndCap(),stroke.getLineJoin(),stroke.getMiterLimit(),stroke.getDashArray(),stroke.getDashPhase());
trace.setStroke(newstroke);
}
}
}
}
public void reduceAllTraceThickness(){
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
BasicStroke stroke = ((BasicStroke)trace.getStroke());
if (stroke.getLineWidth()>=1){
BasicStroke newstroke = new BasicStroke(stroke.getLineWidth()-1,stroke.getEndCap(),stroke.getLineJoin(),stroke.getMiterLimit(),stroke.getDashArray(),stroke.getDashPhase());
trace.setStroke(newstroke);
}
}
}
}
}
public float getTraceThickness(String traceName) {
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
if(trace.getName().equals(traceName)) {
BasicStroke stroke = ((BasicStroke)trace.getStroke());
return stroke.getLineWidth();
}
}
}
return -1;
}
}
// public void changeAllTraceStyle(TRACE_STYLE style) {
// synchronized(mListofTraces){
// Iterator <ITrace2D> entries = mListofTraces.iterator();
// while (entries.hasNext()) {
// ITrace2D trace = entries.next();
// changeTraceStyle(trace, style);
// }
// }
// }
//
// public void changeTraceStyle(int index, TRACE_STYLE style) {
// ITrace2D trace = mListofTraces.get(index);
// changeTraceStyle(trace, style);
// }
//
// private void changeTraceStyle(ITrace2D trace, TRACE_STYLE style) {
// if(trace != null){
// BasicStroke strokeOld = ((BasicStroke)trace.getStroke());
// BasicStroke strokeNew = null;
// if (TRACE_STYLE.DASHED == style){
// float dash1[] = {10.0f};
// strokeNew = new BasicStroke(strokeOld.getLineWidth(),
// BasicStroke.CAP_BUTT,
// BasicStroke.JOIN_MITER,
// 10.0f, dash1, 0.0f);
// }
// else if (TRACE_STYLE.DOTTED == style){
// float dash1[] = {3.0f};
// strokeNew = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1,2}, 0);
// /*new BasicStroke(stroke.getLineWidth(),
// BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND,
// 3.0f, dash1, 0.0f);
// */
// }
// else if (TRACE_STYLE.CONTINUOUS == style){
// strokeNew = new BasicStroke(strokeOld.getLineWidth());
// }
//
// if(strokeNew!=null) {
// trace.setStroke(strokeNew);
// }
// }
// }
@Override
public void setTraceLineStyleAll(PLOT_LINE_STYLE lineStyle) {
mDefaultLineStyle = lineStyle;
synchronized(mListofTraces){
Iterator <ITrace2D> entries = mListofTraces.iterator();
while (entries.hasNext()) {
ITrace2D trace = entries.next();
if(trace != null){
setTraceLineStyle(trace, mDefaultLineStyle);
}
}
}
}
public void setTraceLineStyle(String traceName, PLOT_LINE_STYLE plotLineStyle) {
ITrace2D trace = getTraceFromName(traceName);
if(trace!=null){
setTraceLineStyle(trace, plotLineStyle);
}
}
public void setTraceLineStyle(ITrace2D trace, PLOT_LINE_STYLE selectedLineStyle) {
//Defaults
trace.setTracePainter(new TracePainterLine());
trace.setStroke(new BasicStroke());
if(selectedLineStyle==PLOT_LINE_STYLE.CONTINUOUS
|| selectedLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS
|| selectedLineStyle==PLOT_LINE_STYLE.DASHED
|| selectedLineStyle==PLOT_LINE_STYLE.DOTTED
|| selectedLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS){
BasicStroke strokeOld = ((BasicStroke)trace.getStroke());
BasicStroke strokeNew = null;
if(selectedLineStyle==PLOT_LINE_STYLE.CONTINUOUS
|| selectedLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS){
strokeNew = new BasicStroke(
// strokeOld.getLineWidth(),
DEFAULT_LINE_THICKNESS,
strokeOld.getEndCap(),
strokeOld.getLineJoin(),
strokeOld.getMiterLimit(),
strokeOld.getDashArray(),
strokeOld.getDashPhase());
trace.setStroke(strokeNew);
if(selectedLineStyle==PLOT_LINE_STYLE.INDIVIDUAL_POINTS){
trace.setTracePainter(new TracePainterDisc(4));
}
}
else if (selectedLineStyle==PLOT_LINE_STYLE.DASHED){
float dash1[] = {10.0f};
strokeNew = new BasicStroke(strokeOld.getLineWidth(),
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,
10.0f, dash1, 0.0f);
trace.setStroke(strokeNew);
}
else if (selectedLineStyle==PLOT_LINE_STYLE.DOTTED){
// float dash1[] = {3.0f};
strokeNew = new BasicStroke(
1,
// strokeOld.getLineWidth(),
// DEFAULT_LINE_THICKNESS,
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1,2}, 0);
/*new BasicStroke(stroke.getLineWidth(),
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND,
3.0f, dash1, 0.0f);
*/
trace.setStroke(strokeNew);
}
}
else if(selectedLineStyle==PLOT_LINE_STYLE.BAR){
trace.setTracePainter(new TracePainterVerticalBar(mChart));
}
else if(selectedLineStyle==PLOT_LINE_STYLE.FILL){
trace.setTracePainter(new TracePainterFill(mChart));
}
}
/** Set the scale type on the y-axis.
* @param scaleSetting
* @param xAxisMin
* @param xAxisMax
* @param yAxisMin
* @param yAxisMax
*/
public void setYAxisScale(boolean isLeftYAxis, SCALE_SETTING scaleSetting, Object yAxisMin, Object yAxisMax){
double yMin = 0;
double yMax = 0;
if(!mListofTraces.isEmpty()) {
if(scaleSetting == SCALE_SETTING.AUTO) {
// yMin = (double) yAxisMin;
// yMax = (double) yAxisMax;