forked from krispo/chart-grid-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartGridControl.vb
More file actions
1268 lines (1028 loc) · 48.6 KB
/
Copy pathChartGridControl.vb
File metadata and controls
1268 lines (1028 loc) · 48.6 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
Public Class ChartGridControl
Public IsEmptyControl As Boolean = True
Public Date_detail As EDateInterval
Private CalendStop As Boolean
Public Enum EDateInterval
Hour = 0
Day = 1
WeekOfYear = 2
Month = 3
Year = 4
End Enum
' ---
Public SeriesList As New List(Of CSeries) ' A set of series objects
Public Date_first As Date
Public Date_last As Date
' --- Operation buffer
Public OpBuffer As New COperationBuffer()
Private FormatStr As String() = {"dd.MM.yyyy; HH", "dd.MM.yyyy", "dd.MM.yyyy", "MM.yyyy", "yyyy"}
Private old_val As Double?
Private MouseX, MouseY As Integer
Private forceToolTipNotDisplay As Boolean = False
Public WithEvents myPane As GraphPane
Private ShowCellCheckState As CheckState = CheckState.Unchecked
Dim dimention As Integer = 0
Dim Dates_str() As String
Public Structure ZedgraphCurve
Public List As PointPairList
Public Curve As LineItem
End Structure
Private Structure CurvePar
Public L_CanMove As Boolean
Public Series As CSeries
Public ColumnID As Integer
Public InternalID As Byte
Public ReadOnly Property RowID As Integer
Get
Return Series.ShiftFromObjectTopCases()
End Get
End Property
End Structure
Private RangeForDateInterval() As Integer = {1200, 500, 400, 400, 400} ' hour, day, week, month, year
Public Curves As New List(Of ZedgraphCurve)
Private wf As New WaitF
' --- Delegates
Public Delegate Sub AddColumnDelegate(ByVal s1 As String, ByVal s2 As String)
Public Delegate Sub InsertRowDelegate(ByVal rowIndex As Integer, ByVal count As Integer)
Public Delegate Sub AddTextDelegate(ByVal s As String)
Public Delegate Sub WaitFDelegate()
' --- Constructor
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
'InitializeGraph()
'ZG1.Invalidate()
End Sub
' ==== DATAGRID
' --- Expand limits(how many to up, how many to down)
Public Sub ExpandRows(ByVal top As Integer, ByVal bottom As Integer)
Dim cnt As Integer
If top > 0 Then
Dim InsertRow As New InsertRowDelegate(AddressOf Me.DGV1.Rows.Insert)
Me.DGV1.Invoke(InsertRow, New Object() {0, top})
For cnt = 1 To top
DGV1.Item(0, cnt - 1).Value = Dates(cnt - 1).ToString(FormatStr(Date_detail)) ' CurDate
Next
End If
If bottom > 0 Then
Dim old_numberOfRows As Integer = DGV1.RowCount
Dim new_numberOfRows As Integer = NumberOfCases
Me.DGV1.Invoke(Sub() Me.DGV1.RowCount = new_numberOfRows)
For cnt = 1 To bottom
Me.DGV1.Item(0, old_numberOfRows + cnt - 1).Value = Dates(old_numberOfRows + cnt - 1).ToString(FormatStr(Date_detail))
Next
End If
End Sub
' ---- manual correction of series, syncronization
Private Sub DGV1_CellBeginEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DGV1.CellBeginEdit
If ((e.RowIndex) < Curves(e.ColumnIndex - 1).Curve.Tag.RowID) Or ((e.RowIndex) > Curves(e.ColumnIndex - 1).Curve.Tag.RowID + Curves(e.ColumnIndex - 1).Curve.Tag.Series.NumberOfCases - 1) Or (Not Curves(e.ColumnIndex - 1).Curve.Tag.L_CanMove) Then
e.Cancel = True
Exit Sub
End If
'DGV1.Item(e.ColumnIndex, e.RowIndex).Style.Format = "F2"
If IsNothing(DGV1.Item(e.ColumnIndex, e.RowIndex).Value) Then
old_val = Nothing
Else
old_val = CDbl(DGV1.Item(e.ColumnIndex, e.RowIndex).Value)
End If
End Sub
' --- cell editing (manual)
Private Sub DGV1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellEndEdit
Dim new_val As Double?
Dim ok As Boolean = True
If IsNothing(DGV1.Item(e.ColumnIndex, e.RowIndex).Value) Then
new_val = Nothing
Else
Try
new_val = CDbl(DGV1.Item(e.ColumnIndex, e.RowIndex).Value)
Catch ex As Exception
MessageBox.Show(ParentForm, "Input error!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
DGV1.Item(e.ColumnIndex, e.RowIndex).Value = old_val
ok = False
Exit Sub
End Try
End If
'DGV1.Item(e.ColumnIndex, e.RowIndex).Style.Format = "F2"
For i = 0 To Curves.Count - 1
If Curves(i).Curve.Tag.ColumnID = e.ColumnIndex Then
Curves(i).List.Item(e.RowIndex - Curves(i).Curve.Tag.RowID).Y = new_val.GetValueOrDefault(PointPairBase.Missing)
' -- add to opBuffer
Dim op As New COperationBuffer.StrOperation
op.Series = Curves(i).Curve.Tag.Series
op.SeriesInternalId = Curves(i).Curve.Tag.InternalID
op.CaseId = e.RowIndex - Curves(i).Curve.Tag.RowID
op.savedValue = Curves(i).Curve.Tag.Series.S_RowObject.Value(e.RowIndex - Curves(i).Curve.Tag.RowID, Curves(i).Curve.Tag.InternalID)
Dim opList As New List(Of COperationBuffer.StrOperation)
opList.Add(op)
OpBuffer.Push(opList)
'change value in the common structure
Curves(i).Curve.Tag.Series.S_RowObject.Value(e.RowIndex - Curves(i).Curve.Tag.RowID, Curves(i).Curve.Tag.InternalID) = new_val
Curves(i).Curve.Tag.Series.S_Update = True
Exit For
End If
Next
ZG1.Invalidate()
End Sub
' --- Set CurDate
Private Sub DGV1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellDoubleClick
If e.ColumnIndex > 0 Then
Exit Sub
End If
CurDate.Value = Dates(e.RowIndex)
End Sub
' --- Paste
Private Sub Paste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteMI.Click
Dim SelectedCell As Windows.Forms.DataGridViewCell = DGV1.SelectedCells.Item(0)
If ((SelectedCell.RowIndex) < Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.RowID) Or ((SelectedCell.RowIndex) > Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.RowID + Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.Series.NumberOfCases - 1) Or (Not Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.L_CanMove) Then
Exit Sub ' can not edit
End If
Dim fromClipBoard As IDataObject
fromClipBoard = Clipboard.GetDataObject
Dim str As String
str = Clipboard.GetText()
If fromClipBoard IsNot Nothing Then
Dim s As String
s = Clipboard.GetText()
Dim sReader As System.IO.StringReader
sReader = New System.IO.StringReader(s)
Dim tempDbl As Double?, tempStr As String, a() As String
Dim fin As Boolean = False
Dim CurRow = SelectedCell.RowIndex
Try
Dim opList As New List(Of COperationBuffer.StrOperation)
Do While (Not fin) And (CurRow <= Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.RowID + Curves(SelectedCell.ColumnIndex - 1).Curve.Tag.Series.NumberOfCases - 1)
tempStr = sReader.ReadLine()
If tempStr IsNot Nothing Then
If tempStr <> "" Then
a = tempStr.Split(vbTab)
tempDbl = CDbl(a(0))
Else
tempDbl = Nothing
End If
DGV1.Item(SelectedCell.ColumnIndex, CurRow).Value = tempDbl
' update
For i = 0 To Curves.Count - 1
If Curves(i).Curve.Tag.ColumnID = SelectedCell.ColumnIndex Then
Curves(i).List.Item(CurRow - Curves(i).Curve.Tag.RowID).Y = tempDbl.GetValueOrDefault(PointPair.Missing)
' -- add to opBuffer
Dim op As New COperationBuffer.StrOperation
op.Series = Curves(i).Curve.Tag.Series
op.SeriesInternalId = Curves(i).Curve.Tag.InternalID
op.CaseId = CurRow - Curves(i).Curve.Tag.RowID
op.savedValue = Curves(i).Curve.Tag.Series.S_RowObject.Value(CurRow - Curves(i).Curve.Tag.RowID, Curves(i).Curve.Tag.InternalID)
opList.Add(op)
'change value in the common structure
Curves(i).Curve.Tag.Series.S_RowObject.Value(CurRow - Curves(i).Curve.Tag.RowID, Curves(i).Curve.Tag.InternalID) = tempDbl
Curves(i).Curve.Tag.Series.S_Update = True
Exit For
End If
Next
CurRow += 1
Else
fin = True
End If
Loop
' -- add to opBuffer
OpBuffer.Push(opList)
ZG1.Invalidate()
Catch ex As InvalidCastException
MessageBox.Show(ParentForm, "Data format is not valid in the buffer...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
' --- Copy
Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyMI.Click
If DGV1.GetCellCount(DataGridViewElementStates.Selected) > 0 Then
Try
Clipboard.SetDataObject(DGV1.GetClipboardContent)
Catch ex As Exception
MessageBox.Show(Me, "The data can not be copied. Try again.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
End Sub
' --- Undo
Private Sub UndoOp()
Dim opList As List(Of COperationBuffer.StrOperation) = OpBuffer.Pop
If opList Is Nothing Then
Exit Sub
End If
Dim op As COperationBuffer.StrOperation
Dim opEnum As List(Of COperationBuffer.StrOperation).Enumerator = opList.GetEnumerator
While opEnum.MoveNext
op = opEnum.Current
If op.Series IsNot Nothing Then
For i = 0 To Curves.Count - 1
If Curves(i).Curve.Tag.Series.Equals(op.Series) AndAlso Curves(i).Curve.Tag.InternalID = op.SeriesInternalId Then
Curves(i).List.Item(op.CaseId).Y = op.savedValue
DGV1(Curves(i).Curve.Tag.ColumnID, op.CaseId + Curves(i).Curve.Tag.RowID).Value = op.savedValue
'change value in the common structure
Curves(i).Curve.Tag.Series.S_RowObject.Value(op.CaseId, op.SeriesInternalId) = op.savedValue
Curves(i).Curve.Tag.Series.S_Update = True
Exit For
End If
Next
End If
End While
opEnum.Dispose()
ZG1.Invalidate()
End Sub
' --- run Undo
Private Sub UndoMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoMI.Click, UndoMI_copy.Click
Me.UndoOp()
End Sub
' --- Undo menu is active?
Private Sub DGVContMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles DGVContMenu.Opening
UndoMI.Enabled = OpBuffer.HasOperations
End Sub
Private Sub ShowCellMI_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowCellMI.CheckStateChanged
ShowCellCheckState = ShowCellMI.CheckState
End Sub
' ======== CHART
' --- Graphics Initialization
Public Sub InitializeGraph()
' Get Graph Pane
myPane = ZG1.GraphPane
myPane.CurveList.Clear()
' !!! Move points via the Left mouse button + Shift
ZG1.EditButtons = MouseButtons.Left
ZG1.EditModifierKeys = Keys.Shift
' !!! Horizontal moving...
'ZG1.IsEnableHEdit = True
' !!! Vertical moving...
'ZG1.IsEnableVEdit = True
'ZG1.Cursor = Cursors.Default
' !!! Move chart via the Left mouse button
ZG1.PanButtons = MouseButtons.Left
ZG1.PanModifierKeys = Keys.None
' !!! Zoom chart via the Left mouse button + Ctrl
ZG1.ZoomButtons = MouseButtons.Left
ZG1.ZoomModifierKeys = Keys.Control
' !!! Select curve via the Left mouse button + Alt
ZG1.SelectButtons = MouseButtons.Left
ZG1.SelectModifierKeys = Keys.Alt
ZG1.LinkButtons = MouseButtons.Left
ZG1.LinkModifierKeys = Keys.L
ZG1.ZoomButtons2 = MouseButtons.Left
ZG1.ZoomModifierKeys2 = Keys.Z
'!!! Turn off context menu
'ZG1.IsShowContextMenu = False
' !!! Turn on Tooltips
ZG1.IsShowPointValues = True
' !!! Allow curve selection
ZG1.IsEnableSelection = True
' !!! Turn off zooming
' ZG1.IsEnableZoom = false
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' !!! Set font size for various elements
Dim labelsXfontSize As Integer = 6
Dim labelsYfontSize As Integer = 6
Dim titleXFontSize As Integer = 25
Dim titleYFontSize As Integer = 20
Dim legendFontSize As Integer = 8
Dim mainTitleFontSize As Integer = 30
' !!! Axis visibility
myPane.XAxis.IsVisible = True
myPane.X2Axis.IsVisible = True
myPane.YAxis.IsVisible = True
' !!! Set font size for axis labels
myPane.XAxis.Scale.FontSpec.Size = labelsXfontSize
myPane.X2Axis.Scale.FontSpec.Size = labelsXfontSize
myPane.YAxis.Scale.FontSpec.Size = labelsYfontSize
' !!! Title visibility
myPane.XAxis.Title.IsVisible = False
myPane.X2Axis.Title.IsVisible = False
myPane.YAxis.Title.IsVisible = False
' !!! Set font size for axis titles
myPane.XAxis.Title.FontSpec.Size = titleXFontSize
myPane.X2Axis.Title.FontSpec.Size = titleXFontSize
myPane.YAxis.Title.FontSpec.Size = titleYFontSize
' !!! Title text
'myPane.XAxis.Title.Text = "X Value"
'myPane.X2Axis.Title.Text = "X2 Value"
'myPane.YAxis.Title.Text = "Y Value"
' !!! Set font size for legend
myPane.Legend.FontSpec.Size = legendFontSize
'myPane.Legend.IsHStack = True
myPane.Legend.IsVisible = True
' !!! Settings for main title
myPane.Title.FontSpec.Size = mainTitleFontSize
myPane.Title.FontSpec.IsUnderline = True
myPane.Title.IsVisible = False
'myPane.Title.Text = "My Test Graph"
' !!! Scaling fonts while changing size of chart
'myPane.IsFontsScaled = False
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' !!! Change axis font slope. The angle is given in degree for X axis.
myPane.XAxis.Scale.FontSpec.Angle = 90
' For the Y axis: 0 degree means title be parallel to axis Y
'myPane.YAxis.Scale.FontSpec.Angle = 120
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' !!! Set Date type for the X axes
myPane.XAxis.Type = AxisType.Date
myPane.X2Axis.Type = AxisType.Date
' !!! Set X axes format
' http://msdn.microsoft.com/ru-ru/library/system.globalization.datetimeformatinfo.aspx
myPane.XAxis.Scale.Format = FormatStr(Date_detail)
myPane.XAxis.Scale.FormatAuto = False
myPane.X2Axis.Scale.Format = "dd.MM.yyyy"
myPane.X2Axis.Scale.FormatAuto = False
' !!! Set Y axis numerical format
' http://msdn.microsoft.com/ru-ru/library/system.globalization.numberformatinfo.aspx
myPane.YAxis.Scale.Format = "F2"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' !!! Anothe settings: tics, units, steps,...
' !!! Major X axis
'myPane.XAxis.Scale.MajorUnit = DateUnit.Hour
'myPane.XAxis.Scale.MajorStep = 3
'myPane.XAxis.MajorTic.Size = 2
'myPane.XAxis.MajorTic.IsOutside = False
' !!! Minor X axis
'myPane.XAxis.Scale.MinorUnit = DateUnit.Hour
'myPane.XAxis.Scale.MinorStep = 1
'myPane.XAxis.MinorTic.Size = 1
'myPane.XAxis.MinorTic.IsOutside = False
' ''myPane.XAxis.Scale = True
''myPane.XAxis.MinorTic.IsInside = False
''myPane.XAxis.MinorTic.IsOpposite = False
''myPane.XAxis.MinorTic.IsOutside = False
' !!! Major X2 axis
'myPane.X2Axis.Scale.MajorUnit = DateUnit.Day
'myPane.X2Axis.Scale.MajorStep = 1
'myPane.X2Axis.MajorTic.Size = 2
'myPane.X2Axis.MajorTic.IsOutside = False
' !!! Minor X2 axis
''myPane.X2Axis.Scale.MinorUnit = DateUnit.Hour
''myPane.X2Axis.Scale.MinorStep = 1
''myPane.X2Axis.MinorTic.Size = 1
'myPane.X2Axis.MinorTic.IsInside = False
'myPane.X2Axis.MinorTic.IsOpposite = False
'myPane.X2Axis.MinorTic.IsOutside = False
' !!! Major Y axis
'myPane.YAxis.Scale.MajorUnit = 1
'myPane.YAxis.Scale.MajorStep = 200
'myPane.YAxis.MajorTic.Size = 2
'myPane.YAxis.MajorTic.IsOutside = False
' !!! Minor Y axis
'myPane.YAxis.Scale.MinorUnit = 1
'myPane.YAxis.Scale.MinorStep = 100
'myPane.YAxis.MinorTic.Size = 1
'myPane.YAxis.MinorTic.IsOutside = False
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' !!! Turn on Grid
' !!! Major X,X2 axis
myPane.XAxis.MajorGrid.IsVisible = True
myPane.X2Axis.MajorGrid.IsVisible = True
' Set intervals for dash line: - - - - - - -
myPane.XAxis.MajorGrid.DashOn = 10
myPane.X2Axis.MajorGrid.DashOn = 10
myPane.XAxis.MajorGrid.DashOff = 0
myPane.X2Axis.MajorGrid.DashOff = 0
' !!! Major Y axis
myPane.YAxis.MajorGrid.IsVisible = True
myPane.YAxis.MajorGrid.IsZeroLine = False
' Set intervals for dash line: - - - - - - -
myPane.YAxis.MajorGrid.DashOn = 10
myPane.YAxis.MajorGrid.DashOff = 0
' !!! Minor X,X2 axis
myPane.XAxis.MinorGrid.IsVisible = False
myPane.X2Axis.MinorGrid.IsVisible = False
myPane.XAxis.MinorGrid.DashOn = 10
myPane.XAxis.MinorGrid.DashOff = 0
' !!! Minor Y axis
myPane.YAxis.MinorGrid.IsVisible = False
myPane.YAxis.MinorGrid.DashOn = 10
myPane.YAxis.MinorGrid.DashOff = 0
' !!! Set Grid color
myPane.XAxis.MajorGrid.Color = Color.LightGray
myPane.X2Axis.MajorGrid.Color = Color.FromArgb(0, 255, 255) 'Color.Aquamarine
myPane.YAxis.MajorGrid.Color = Color.LightGray
myPane.XAxis.MinorGrid.Color = Color.LightGray
myPane.YAxis.MinorGrid.Color = Color.LightGray
' !!! Set Grid width
myPane.X2Axis.MajorGrid.PenWidth = 2
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Scaling
myPane.YAxis.Scale.MaxAuto = True
myPane.YAxis.Scale.MinAuto = True
End Sub
' --- chart editing (manual)
Private Function ZG1_PointEditEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal pane As ZedGraph.GraphPane, ByVal curve As ZedGraph.CurveItem, ByVal iPt As System.Int32) As System.String Handles ZG1.PointEditEvent
DGV1(curve.Tag.ColumnID, iPt + curve.Tag.RowID).Value = curve(iPt).Y
DGV1(curve.Tag.ColumnID, iPt + curve.Tag.RowID).Selected = True
DGV1.FirstDisplayedScrollingRowIndex = iPt + curve.Tag.RowID
DGV1.FirstDisplayedScrollingColumnIndex = curve.Tag.ColumnID
' -- add to opBuffer
Dim op As New COperationBuffer.StrOperation
op.Series = curve.Tag.Series
op.SeriesInternalId = curve.Tag.InternalID
op.CaseId = iPt
op.savedValue = curve.Tag.Series.S_RowObject.Value(iPt, curve.Tag.InternalID)
Dim opList As New List(Of COperationBuffer.StrOperation)
opList.Add(op)
OpBuffer.Push(opList)
'change value in the common structure
curve.Tag.Series.S_RowObject.Value(iPt, curve.Tag.InternalID) = curve(iPt).Y
curve.Tag.Series.S_Update = True
Return ""
End Function
' --- Set limits for Date axes
Public Sub SetGrDateLimits(ByVal minD As Date, ByVal maxD As Date)
Dim xmin_limit As Double = New XDate(minD)
Dim xmax_limit As Double = New XDate(maxD) '(Dates(Dates.Length - 1))
' !!! Set limits for X, X2 axes
myPane.XAxis.Scale.Min = xmin_limit
myPane.XAxis.Scale.Max = xmax_limit
myPane.X2Axis.Scale.Min = xmin_limit
myPane.X2Axis.Scale.Max = xmax_limit
myPane.AxisChange()
' Me.CustomAxisChangeHandler(myPane)
ZG1.Invalidate()
End Sub
' --- Set limits for Y axis
Public Sub SetGrValueLimits(ByVal minV As Double, ByVal maxV As Double)
' !!! Set limits for Y axis
myPane.YAxis.Scale.Min = minV
myPane.YAxis.Scale.Max = maxV
myPane.AxisChange()
' Me.CustomAxisChangeHandler(myPane)
ZG1.Invalidate()
End Sub
' <summary>
' PointValueEvent handler.
' Return string for tooltip.
' </summary>
' <param name="sender">Message Sender</param>
' <param name="pane">Chart panel</param>
' <param name="curve">The Curve near cursor placed</param>
' <param name="iPt">Point number in the curve</param>
' <returns>String to be displayed</returns>
Private Function ZG1_PointValueEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal pane As ZedGraph.GraphPane, ByVal curve As ZedGraph.CurveItem, ByVal iPt As System.Int32) As System.String Handles ZG1.PointValueEvent
' Get the nearest point
Dim point As PointPair = curve(iPt)
Dim d As Date = Date.FromOADate(point.X)
Dim result As String = curve.Label.Text + ": " + point.Y.ToString("F2") + vbCrLf + vbCrLf + CreateDateString(d)
If ShowCellCheckState = CheckState.Checked Then
DGV1.ClearSelection()
DGV1(curve.Tag.ColumnID, iPt + curve.Tag.RowID).Selected = True
Dim case_ As Integer = iPt + curve.Tag.RowID
If (Not DGV1.Item(Math.Min(curve.Tag.ColumnID + 1, DGV1.ColumnCount - 1), Math.Min(case_ + 1, DGV1.RowCount - 1)).Displayed) Then
DGV1.FirstDisplayedCell = DGV1.Item(Math.Min(curve.Tag.ColumnID + 1, DGV1.ColumnCount - 1), Math.Min(case_ + 1, DGV1.RowCount - 1))
ElseIf (Not DGV1.Item(Math.Max(curve.Tag.ColumnID - 1, 1), Math.Max(case_ - 1, 0)).Displayed) Then
DGV1.FirstDisplayedCell = DGV1.Item(Math.Max(curve.Tag.ColumnID - 1, 1), Math.Max(case_ - 1, 0))
End If
End If
If curve.Tag.L_CanMove Then
ZG1.IsEnableVEdit = True
Else
ZG1.IsEnableVEdit = False
End If
Return result
End Function
' --- fix tooltip blinking
Private Sub ZG1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ZG1.MouseMove
If MouseX <> e.X Or MouseY <> e.Y Then
EnableToolTip(False)
MouseX = e.X
MouseY = e.Y
Else
DisableToolTip(False)
End If
End Sub
' --- remove the last element from contextmenu - By default
Private Sub ZG1_ContextMenuBuilder(ByVal sender As ZedGraph.ZedGraphControl, ByVal menuStrip As System.Windows.Forms.ContextMenuStrip, ByVal mousePt As System.Drawing.Point, ByVal objState As ZedGraph.ZedGraphControl.ContextMenuObjectState) Handles ZG1.ContextMenuBuilder
menuStrip.Items.RemoveAt(7)
menuStrip.Items.Add(ShowCellMI)
ShowCellMI.CheckState = ShowCellCheckState
menuStrip.Items.Add(UndoMI_copy)
UndoMI_copy.Enabled = OpBuffer.HasOperations
End Sub
Public Sub DisableToolTip(ByVal force As Boolean)
If force Then
forceToolTipNotDisplay = True
Else
If forceToolTipNotDisplay Then Exit Sub
End If
ZG1.IsShowPointValues = False
End Sub
Public Sub EnableToolTip(ByVal force As Boolean)
If force Then
forceToolTipNotDisplay = False
Else
If forceToolTipNotDisplay Then Exit Sub
End If
ZG1.IsShowPointValues = True
End Sub
' --- Handle scaling
Private Sub CustomAxisChangeHandler(ByVal pane As ZedGraph.GraphPane) Handles myPane.AxisChangeEvent
Dim i As Short = 0
While (Range(Date_interval(Date_detail + i)) > RangeForDateInterval(Date_detail + i)) _
And (Date_detail + i <= 2)
i += 1
End While
If Range(Date_interval(Date_detail + i)) <= RangeForDateInterval(Date_detail + i) Then
' Major Units for X axis
myPane.XAxis.Scale.MajorUnit = convertDateInterval(Date_detail + i)
myPane.XAxis.Scale.MinorUnit = myPane.XAxis.Scale.MajorUnit
' Major Units for X2 axis
myPane.X2Axis.Scale.MajorUnit = myPane.XAxis.Scale.MajorUnit - 1
myPane.X2Axis.Scale.MajorStep = 1
Else
myPane.XAxis.Scale.MajorUnit = DateUnit.Year
myPane.XAxis.Scale.MinorUnit = DateUnit.Year
myPane.X2Axis.Scale.MajorUnit = DateUnit.Year
myPane.X2Axis.Scale.MajorStepAuto = True
If Range(DateInterval.Year) <= RangeForDateInterval(4) Then
myPane.XAxis.Scale.MajorStep = 1
myPane.XAxis.Scale.MinorStep = 1
Else
myPane.XAxis.Scale.MajorStepAuto = True
myPane.XAxis.Scale.MinorStepAuto = True
End If
End If
' !!! X
myPane.XAxis.MajorTic.Size = 2
myPane.XAxis.MajorTic.IsOutside = False
'myPane.XAxis.Scale.MinorStep = 1 '0.25
myPane.XAxis.MinorTic.Size = 1
myPane.XAxis.MinorTic.IsOutside = False
''myPane.XAxis.Scale = True
'myPane.XAxis.MinorTic.IsInside = False
'myPane.XAxis.MinorTic.IsOpposite = False
'myPane.XAxis.MinorTic.IsOutside = False
' !!! X2
myPane.X2Axis.MajorTic.Size = 2
myPane.X2Axis.MajorTic.IsOutside = False
'myPane.X2Axis.Scale.MinorUnit = DateUnit.Hour
'myPane.X2Axis.Scale.MinorStep = 1
'myPane.X2Axis.MinorTic.Size = 1
myPane.X2Axis.MinorTic.IsInside = False
myPane.X2Axis.MinorTic.IsOpposite = False
myPane.X2Axis.MinorTic.IsOutside = False
' !!! Y
myPane.YAxis.Scale.MajorUnit = 1
'myPane.YAxis.Scale.MajorStep = 200
myPane.YAxis.Scale.MajorStepAuto = True
myPane.YAxis.MajorTic.Size = 2
myPane.YAxis.MajorTic.IsOutside = False
myPane.YAxis.Scale.MinorUnit = 1
'myPane.YAxis.Scale.MinorStep = 100
myPane.YAxis.Scale.MinorStepAuto = True
myPane.YAxis.MinorTic.Size = 1
myPane.YAxis.MinorTic.IsOutside = False
Me.UpdateCalendar()
End Sub
' --- update Calendar on graph scroll
Private Function ZG1_MouseUpEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal e As System.Windows.Forms.MouseEventArgs) As System.Boolean Handles ZG1.MouseUpEvent
If e.Button = Windows.Forms.MouseButtons.Left And (Control.ModifierKeys <> Keys.Shift) And (Control.ModifierKeys <> Keys.Control) Then
Me.UpdateCalendar()
End If
Return False
End Function
Private Sub UpdateCalendar()
' --- update Calendar
RemoveHandler CurDate.ValueChanged, AddressOf CurDate_ValueChanged
CurDate.Value = CurrentDate 'DGV1_SelectionChanged(Me, New System.EventArgs)
AddHandler CurDate.ValueChanged, AddressOf CurDate_ValueChanged
End Sub
Private Sub ZG1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ZG1.KeyDown
If e.KeyCode = Keys.H Then
ZG1.IsEnableVZoom = False
End If
If e.KeyCode = Keys.V Then
ZG1.IsEnableHZoom = False
End If
End Sub
Private Sub ZG1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ZG1.KeyUp
ZG1.IsEnableVZoom = True
ZG1.IsEnableHZoom = True
End Sub
' --- Convert DateInterval into ZedGraph.DateUnit
Private Function convertDateInterval(ByVal Date_detail As EDateInterval) As ZedGraph.DateUnit
Dim unit As DateUnit
Select Case Date_detail
Case EDateInterval.Hour
unit = DateUnit.Hour
myPane.XAxis.Scale.MajorStep = 3
myPane.XAxis.Scale.MinorStep = 1
Case EDateInterval.Day
unit = DateUnit.Day
myPane.XAxis.Scale.MajorStep = 1
myPane.XAxis.Scale.MinorStep = 1
Case EDateInterval.WeekOfYear
unit = DateUnit.Day
myPane.XAxis.Scale.MajorStep = 7
myPane.XAxis.Scale.MinorStep = 1
Case EDateInterval.Month
unit = DateUnit.Month
myPane.XAxis.Scale.MajorStep = 1
myPane.XAxis.Scale.MinorStep = 0.25
End Select
Return unit
End Function
' --- Zoom limitation
Private Sub ZG1_ZoomEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal oldState As ZedGraph.ZoomState, ByVal newState As ZedGraph.ZoomState) Handles ZG1.ZoomEvent
Dim extr As Integer = 200000
If (myPane.XAxis.Scale.Min < -extr) Then
myPane.XAxis.Scale.Min = -extr
End If
If (myPane.XAxis.Scale.Max > extr) Then
myPane.XAxis.Scale.Max = extr
End If
If (myPane.X2Axis.Scale.Min < -extr) Then
myPane.X2Axis.Scale.Min = -extr
End If
If (myPane.X2Axis.Scale.Max > extr) Then
myPane.X2Axis.Scale.Max = extr
End If
If (myPane.YAxis.Scale.Min < -extr) Then
myPane.YAxis.Scale.Min = -extr
End If
If (myPane.YAxis.Scale.Max > extr) Then
myPane.YAxis.Scale.Max = extr
End If
End Sub
' ===== SERIES
' --- add series to control
Public Sub AddSeriesToControl(ByRef Series As CSeries) 'ByVal Series As CSeries,
Dim Tag As New CurvePar
Tag.Series = Series
Dim NumberOfCurves As Integer = Curves.Count
Dim cnt As Integer
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim SeriesObj As CData = Series.S_RowObject
Dim CurvesItem(SeriesObj.NumberOfRows - 1) As ZedgraphCurve
For i = 0 To SeriesObj.NumberOfRows - 1
CurvesItem(i).List = New PointPairList
Dim ColumnAdd As New AddColumnDelegate(AddressOf DGV1.Columns.Add)
DGV1.Invoke(ColumnAdd, New Object() {SeriesObj.L_Description(i).L_Label, SeriesObj.L_Description(i).L_Label})
DGV1.Columns(DGV1.Columns.Count - 1).DefaultCellStyle.Format = "F2"
DGV1.Columns(DGV1.Columns.Count - 1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DGV1.Columns(DGV1.Columns.Count - 1).Width = 60
DGV1.Columns(DGV1.Columns.Count - 1).SortMode = DataGridViewColumnSortMode.NotSortable
Next
Dim Shift As Integer = Series.ShiftFromObjectTopCases
For cnt = 0 To SeriesObj.ParentSeries.NumberOfCases - 1
For i = 0 To SeriesObj.NumberOfRows - 1
'If Not SeriesObj.Value(cnt, i) = vbNull Then
If Not IsNothing(SeriesObj.Value(cnt, i)) Then
DGV1.Item(NumberOfCurves + 1 + i, cnt + Shift).Value = SeriesObj.Value(cnt, i)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
CurvesItem(i).List.Add(New XDate(Dates(cnt + Shift)), DGV1.Item(NumberOfCurves + 1 + i, cnt + Shift).Value)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
CurvesItem(i).List.Add(New XDate(Dates(cnt + Shift)), PointPairBase.Missing)
End If
Next
Next
For i = 0 To SeriesObj.NumberOfRows - 1
CurvesItem(i).Curve = myPane.AddCurve("", CurvesItem(i).List, Color.Black)
Tag.ColumnID = NumberOfCurves + 1 + i
CurvesItem(i).Curve.Tag = Tag
Curves.Add(CurvesItem(i))
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SetCurveParameters_FromStructureToCurve(Series)
End Sub
' --- remove series from control
Public Sub RemoveSeriesFromControl(ByVal SeriesID As Integer)
For i = Curves.Count - 1 To 0 Step -1
If Curves(i).Curve.Tag.Series.SeriesID = SeriesID Then
myPane.CurveList.Remove(Curves(i).Curve)
Curves.RemoveAt(i)
DGV1.Columns.RemoveAt(i + 1)
End If
Next
'Curves.Count has already another value
For i = 0 To Curves.Count - 1
Curves(i).Curve.Tag.ColumnID = i + 1
Next
ZG1.Invalidate()
End Sub
' --- add settings
Public Sub SetCurveParameters_FromStructureToCurve(ByRef Series As CSeries)
Dim L As CSeries.StrLDescription
For i = 0 To Curves.Count - 1
If Curves(i).Curve.Tag.Series.SeriesID = Series.SeriesID Then
L = Series.S_RowObject.L_Description(Curves(i).Curve.Tag.InternalID)
Curves(i).Curve.IsVisible = L.L_IsVisible
Curves(i).Curve.Label.Text = L.L_Label
Curves(i).Curve.Line.Color = L.L_Color
Curves(i).Curve.Line.Width = L.L_Width
Curves(i).Curve.Line.Style = L.L_Style
Curves(i).Curve.Symbol.Type = L.L_Symbol
Curves(i).Curve.Symbol.Size = L.L_SymbolSize
Curves(i).Curve.Symbol.IsVisible = L.L_IsVisibleSymbol
Curves(i).Curve.Tag.L_CanMove = L.L_CanMove
Curves(i).Curve.Symbol.Border.Color = Curves(i).Curve.Line.Color
Curves(i).Curve.Label.IsVisible = Curves(i).Curve.IsVisible
'to fill symbol
'Curves(i).Curve.Symbol.Fill.Type = FillType.Solid
'Curves(i).Curve.Symbol.Fill.Color = Curves(i).Curve.Color
End If
Next
ZG1.Invalidate()
End Sub
'======= GENERAL ====================================================================================================================
' --- Add series
Private Sub AddSeries(ByRef NewSeries As CSeries)
Me.DisableToolTip(True) 'Turn off tooltip handler - otherwise exception "For each" arise
SeriesList.Add(NewSeries)
If IsEmptyControl Then
Me.Date_first = NewSeries.Date_first
Me.Date_last = NewSeries.Date_last
Me.Date_detail = NewSeries.Date_detail
Dim ToEnd As Integer = NewSeries.NumberOfCases
Me.ExpandRows(0, ToEnd)
IsEmptyControl = False
Else
' Need to expand DGV1
Dim ToEnd As Integer = DateDiff(Date_interval, ClearDate(Me.Date_last), ClearDate(NewSeries.Date_last), FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1)
Dim ToStart As Integer = -1 * DateDiff(Date_interval, ClearDate(Me.Date_first), ClearDate(NewSeries.Date_first), FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1)
If ToEnd > 0 Then
Me.Date_last = NewSeries.Date_last
End If
If ToStart > 0 Then
Me.Date_first = NewSeries.Date_first
End If
Me.ExpandRows(ToStart, ToEnd)
End If
Me.AddSeriesToControl(NewSeries)
Me.EnableToolTip(True) ' Turn on tooltip handler
Me.AddOperationDescr("--- """ + NewSeries.S_RowObject.Name + """ is added.")
GC.Collect()
End Sub
' --- Remove series
Public Sub RemoveSeries(ByVal SeriesID As Integer)
Me.RemoveSeriesFromControl(SeriesID)
Dim name As String = SeriesList(SeriesID).S_RowObject.Name
SeriesList.RemoveAt(SeriesID)
Me.AddOperationDescr("--- """ + name + """ is removed.")
If SeriesList.Count = 0 Then
Me.DGV1.Invoke(Sub() Me.DGV1.RowCount = 0)
IsEmptyControl = True
DGV1.Enabled = False
Me.AddOperationDescr("--- Control is cleared.")
End If
GC.Collect()
End Sub
' -- Add operation description
Public Sub AddOperationDescr(ByVal oper As String)
Dim t_S As String
Dim t As Date = Now
t_S = t.Hour.ToString("D2") + ":" + t.Minute.ToString("D2") + ":" + t.Second.ToString("D2") + " "
Dim add_T As New ChartGridControl.AddTextDelegate(AddressOf Me.TB_Log.AppendText)
Me.TB_Log.Invoke(add_T, New Object() {t_S + oper + vbCrLf})
End Sub
'===========================================================================================================================
Public Sub B_Settings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_Settings.Click
Dim csd As New ChartSettingsDialog(Me)
csd.ShowDialog()
End Sub
Private Sub CurDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurDate.ValueChanged
If SeriesList.Count <> 0 Then
If CalendStop Then Exit Sub
CalendStop = True
Select Case Date_interval
Case EDateInterval.Day
If CurDate.Value.Hour <> 0 Then
CurDate.Value = DateAdd(DateInterval.Hour, (-1) * CurDate.Value.Hour, CurDate.Value)
End If
Case EDateInterval.WeekOfYear