-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArrayVisualizerToolControl.xaml.cs
More file actions
868 lines (747 loc) · 29.6 KB
/
ArrayVisualizerToolControl.xaml.cs
File metadata and controls
868 lines (747 loc) · 29.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ArrayVisualizerControls;
using ArrayVisualizerExt.ArrayLoaders;
using ArrayVisualizerExt.TypeParsers;
using EnvDTE;
using EnvDTE80;
using LinqLib.Array;
using Microsoft.VisualStudio.Shell;
using Syncfusion.Linq;
using Syncfusion.Windows.Chart;
using Expression = EnvDTE.Expression;
namespace ArrayVisualizerExt
{
public partial class ArrayVisualizerToolControl : IDisposable
{
#region Fields
private readonly DTE2 _dte;
private List<ExpressionInfo> _expressions;
private DebuggerEvents _debugerEvents;
private ArrayControl _arrCtl;
private Chart _chartCtl;
private Array _data;
//private Type undelyingExpressionType;
private int[] _dimensions;
private IArrayLoader _arrayLoader;
private ParsersCollection _parsers;
private Exception _lastLoadException;
private readonly HashSet<Type> _loadedParsers;
private bool _arraysPending;
private bool _toolActive;
private DisplayMode _displayMode;
private string _lastSelectedArray;
#endregion
#region Constructor
public ArrayVisualizerToolControl()
{
InitializeComponent();
_dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
_loadedParsers = new HashSet<Type>();
LoadSettings();
SetDebugEvents();
_toolActive = true;
_arraysPending = true;
ShowArrays();
}
#endregion
#region Debugger Events
private void SetDebugEvents()
{
_debugerEvents = _dte.Events.DebuggerEvents;
_debugerEvents.OnEnterBreakMode += DebuggerEvents_OnEnterBreakMode;
_debugerEvents.OnEnterDesignMode += debugerEvents_OnEnterDesignMode;
_debugerEvents.OnEnterRunMode += debugerEvents_OnEnterRunMode;
}
private void debugerEvents_OnEnterRunMode(dbgEventReason reason)
{
SaveSettings();
_arraysPending = false;
ClearVisualizer();
}
private void debugerEvents_OnEnterDesignMode(dbgEventReason reason)
{
SaveSettings();
_arraysPending = false;
ClearVisualizer();
}
private void DebuggerEvents_OnEnterBreakMode(dbgEventReason reason, ref dbgExecutionAction executionAction)
{
_arraysPending = true;
ShowArrays();
}
public void ToolActivated()
{
_toolActive = true;
ShowArrays();
}
public void ToolDeactivated()
{
_toolActive = false;
}
#endregion
#region Other Events
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
TextBox textBox = sender as TextBox;
if (textBox != null)
{
string text = textBox.Text + e.Text;
bool ok = double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out var temp);
e.Handled = !ok;
}
}
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
e.Handled = true;
}
private void rotateButton_Click(object sender, RoutedEventArgs e)
{
RotateAxis r = RotateAxis.RotateNone;
int angle = (int) angelComboBox.SelectedItem;
switch ((string) axisComboBox.SelectedItem)
{
case "X":
r = RotateAxis.RotateX;
break;
case "Y":
r = RotateAxis.RotateY;
break;
case "Z":
r = RotateAxis.RotateZ;
break;
case "A":
r = RotateAxis.RotateA;
break;
}
int[] dims = _arrCtl.Data.GetDimensions();
switch (_arrCtl.Data.Rank)
{
case 2:
Reset((_arrCtl.Data.AsEnumerable<object>().ToArray(dims[0], dims[1])).Rotate(angle));
break;
case 3:
Reset((_arrCtl.Data.AsEnumerable<object>().ToArray(dims[0], dims[1], dims[2])).Rotate(r, angle));
break;
case 4:
Reset((_arrCtl.Data.AsEnumerable<object>().ToArray(dims[0], dims[1], dims[2], dims[3])).Rotate(r,
angle));
break;
}
}
private void arraysListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
ExpressionInfo expressionInfo = (ExpressionInfo) e.AddedItems[0];
LoadResults result = LoadArray(expressionInfo.Expression, false);
SetupControls(expressionInfo);
switch (result)
{
case LoadResults.LargeArray:
LargeArrayHandler largeArrayHandler =
new LargeArrayHandler(expressionInfo.Expression.DataMembers.Count, 2000, 40000);
largeArrayHandler.LoadArrayRequest += largeArrayHandler_LoadArrayRequest;
mainPanel.Children.Add(largeArrayHandler);
break;
case LoadResults.NotSupported:
break;
case LoadResults.Exception:
Label errorLabel = new Label
{
Content =
$"Error rendering array '{expressionInfo.Name}'\r\n\r\n'{_lastLoadException.Message}'"
};
mainPanel.Children.Clear();
mainPanel.Children.Add(errorLabel);
break;
}
}
}
private void resetButton_Click(object sender, RoutedEventArgs e)
{
Reset(_data);
}
private void supportlabel_MouseUp(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("http://bit.ly/155n1RK");
}
private void gridLinesType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetGridLines();
}
private void arrCtl_CellClick(object sender, CellClickEventArgs e)
{
Array values = new DefaultParser(_arrayLoader).GetValues((Expression) e.Data);
Color color = ((SolidColorBrush) mainPanel.Background).Color;
((ArrayControl) sender).ShowArrayPopup((UIElement) e.Source, values, e.ToolTipPrefix, color);
}
private void largeArrayHandler_LoadArrayRequest(object sender, RoutedEventArgs e)
{
if (arraysListBox.SelectedItems.Count == 1)
{
ExpressionInfo expressionInfo = (ExpressionInfo) arraysListBox.SelectedItem;
LoadArray(expressionInfo.Expression, true);
SetupControls(expressionInfo);
}
}
private void VisualizerTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Equals(e.OriginalSource, VisualizerTab))
{
ExpressionInfo expressionInfo = (ExpressionInfo) arraysListBox.SelectedItem;
SetupControls(expressionInfo);
}
}
private void chartType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetChartType();
}
private void lineType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetChartLineStroke();
}
private void syncFusionLabel_MouseUp(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("http://bit.ly/Wq50dg");
}
private void applyButton_Click(object sender, RoutedEventArgs e)
{
if (_arrCtl != null)
Reset(_arrCtl.Data);
}
private void Parser_CheckedChanged(object sender, RoutedEventArgs e)
{
CheckBox chkControl = (CheckBox) sender;
Type parserType = Type.GetType((string) chkControl.Tag);
if (parserType != null)
if (chkControl.IsChecked.HasValue && chkControl.IsChecked.Value)
_loadedParsers.Add(parserType);
else
_loadedParsers.Remove(parserType);
_arraysPending = true;
ShowArrays();
}
private void GridSplitter_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
double width = MainGrid.ColumnDefinitions[0].Width.Value;
if (width > 212.01 || width < 11.99)
MainGrid.ColumnDefinitions[0].Width = new GridLength(212, GridUnitType.Pixel);
else
MainGrid.ColumnDefinitions[0].Width = new GridLength(360, GridUnitType.Pixel);
}
#endregion
#region Methods
private void ClearVisualizer()
{
if (arraysListBox.SelectedValue != null)
_lastSelectedArray = ((ExpressionInfo) arraysListBox.SelectedValue).FullName;
arraysListBox.ItemsSource = null;
arraysListBox.Items.Clear();
mainPanel.Children.Clear();
rotateGrid.IsEnabled = false;
}
private void LoadScopeArrays()
{
ClearVisualizer();
_expressions = new List<ExpressionInfo>();
if (_dte.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
{
foreach (Expression expression in _dte.Debugger.CurrentStackFrame.Locals)
_expressions.AddRange(_arrayLoader.GetArrays(string.Empty, expression, _parsers, 0));
arraysListBox.ItemsSource = _expressions.OrderBy(a => a.SectionCode).ThenBy(a => a.Name);
arraysListBox.DisplayMemberPath = "FullName";
}
if (!string.IsNullOrEmpty(_lastSelectedArray))
{
foreach (ExpressionInfo item in arraysListBox.Items)
{
if (item.FullName == _lastSelectedArray)
arraysListBox.SelectedItem = item;
}
}
}
private LoadResults LoadArray(Expression expression, bool ignoreArraySize)
{
_lastLoadException = null;
_data = null;
try
{
if (expression.Value != "null")
{
object[] values = null;
foreach (ITypeParser parser in _parsers.Where(p => p.IsExpressionTypeSupported(expression)))
{
_dimensions = parser.GetDimensions(expression);
int count = parser.GetMembersCount(expression);
if (ignoreArraySize || count <= 2000)
values = parser.GetValues(expression);
else
return LoadResults.LargeArray;
break;
}
switch (_dimensions.Length)
{
case 1:
_data = values.ToArray(_dimensions[0]);
break;
case 2:
_data = values.ToArray(_dimensions[0], _dimensions[1]);
break;
case 3:
_data = values.ToArray(_dimensions[0], _dimensions[1], _dimensions[2]);
break;
case 4:
_data = values.ToArray(_dimensions[0], _dimensions[1], _dimensions[2], _dimensions[3]);
break;
default:
return LoadResults.NotSupported;
}
}
}
catch (Exception ex)
{
_lastLoadException = ex;
return LoadResults.Exception;
}
return LoadResults.Success;
}
private void SetupArrayControl(ExpressionInfo expressionInfo)
{
if (_arrCtl != null && _arrCtl.Tag == expressionInfo)
return;
SetRotationOptions(_dimensions.Length);
ArrayControl newArrCtl = ArrayControl.GetArrayControl(_dimensions.Length);
if (newArrCtl == null)
return;
else
_arrCtl = newArrCtl;
_arrCtl.Formatter = formatterTextBox.Text;
_arrCtl.CaptionBuilder = GetCaptionBuilder(_arrCtl.Formatter);
_arrCtl.CellHeight = GetCellSize(cellHeightTextBox.Text, 40);
_arrCtl.CellWidth = GetCellSize(cellWidthTextBox.Text, 60);
_arrCtl.LeftBracket = _arrayLoader.LeftBracket;
_arrCtl.RightBracket = _arrayLoader.RightBracket;
_arrCtl.CellClick += arrCtl_CellClick;
_arrCtl.SetControlData(_data);
_arrCtl.Padding = new Thickness(8);
_arrCtl.Width += 16;
_arrCtl.Height += 16;
_arrCtl.Tag = expressionInfo;
}
private static Func<object, string, string> GetCaptionBuilder(string formatter)
{
if (!string.IsNullOrEmpty(formatter))
switch (formatter[0])
{
case 'D':
case 'd':
case 'X':
case 'x':
return IntegralCaptionBuilder;
}
return DefaultCaptionBuilder;
}
private static int GetCellSize(string text, int defaultValue)
{
if (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out var value))
return (int) value;
return defaultValue;
}
private void SetupChartControl(ExpressionInfo expressionInfo)
{
IEnumerable<double> chartData = null;
int dimenstionsCount = _dimensions.Length;
try
{
if ((dimenstionsCount == 1 || dimenstionsCount == 2) && _data != null)
{
chartData = ConvertToDoubles(_data);
chartTab.IsEnabled = chartData.Any();
}
else
chartTab.IsEnabled = false;
}
finally
{
if (!chartTab.IsEnabled)
{
if (VisualizerTab.SelectedIndex == 1)
dataTab.IsSelected = true;
}
else
{
if (_chartCtl == null || _chartCtl.Tag != expressionInfo)
{
if (_chartCtl != null)
_chartCtl.Dispose();
_chartCtl = new Chart();
ChartArea area = new ChartArea();
if (dimenstionsCount == 1)
area.Series.Add(GetSeries(GetSelectedChartType(), chartData));
else //2 dims
{
double[] chartDataFlat = chartData.ToArray();
for (int i = 0; i < _dimensions[0]; i++)
area.Series.Add(GetSeries(GetSelectedChartType(),
chartDataFlat.Skip(i * _dimensions[1]).Take(_dimensions[1])));
}
_chartCtl.Areas.Add(area);
SetChartLineStroke();
SetChartStackModeOptions();
SetGridLines();
_chartCtl.Tag = expressionInfo;
}
}
}
}
private ChartTypes GetSelectedChartType()
{
switch ((string) ((ComboBoxItem) chartType.SelectedItem).Content)
{
case "Line":
return ChartTypes.Line;
case "Bar":
return ChartTypes.Bar;
case "Stack Bar":
return ChartTypes.StackingBar;
case "Stack Bar 100":
return ChartTypes.StackingBar100;
case "Column":
return ChartTypes.Column;
case "Stack Column":
return ChartTypes.StackingColumn;
case "Stack Column 100":
return ChartTypes.StackingColumn100;
case "Area":
return ChartTypes.Area;
case "Stack Area":
return ChartTypes.StackingArea;
case "Stack Area 100":
return ChartTypes.StackingArea100;
case "Spline":
return ChartTypes.Spline;
case "Spline Area":
return ChartTypes.SplineArea;
default:
throw new NotImplementedException();
}
}
private static RangeCalculationMode GetSelectedChartCalculationMode(ChartTypes selectedChartType)
{
switch (selectedChartType)
{
case ChartTypes.Line:
case ChartTypes.Area:
case ChartTypes.Spline:
case ChartTypes.SplineArea:
case ChartTypes.StackingArea:
case ChartTypes.StackingArea100:
return RangeCalculationMode.ConsistentAcrossChartTypes;
case ChartTypes.Bar:
case ChartTypes.Column:
case ChartTypes.StackingBar:
case ChartTypes.StackingBar100:
case ChartTypes.StackingColumn:
case ChartTypes.StackingColumn100:
return RangeCalculationMode.AdjustAcrossChartTypes;
default:
throw new NotImplementedException();
}
}
private static IEnumerable<double> ConvertToDoubles(IEnumerable array)
{
foreach (object item in array)
{
if (double.TryParse(item.ToString(), NumberStyles.Any, CultureInfo.CurrentCulture, out var value))
yield return value;
else
yield break;
}
}
private static ChartSeries GetSeries(ChartTypes seriesChartType, IEnumerable<double> chartData)
{
ChartSeries chartSeries = new ChartSeries(seriesChartType);
chartSeries.Data = new ChartData.VisualizerPointsCollection(chartData);
return chartSeries;
}
private void SetRotationOptions(int dimensions)
{
angelComboBox.Items.Clear();
angelComboBox.Items.Add(90);
angelComboBox.Items.Add(180);
angelComboBox.Items.Add(270);
axisComboBox.Items.Clear();
axisComboBox.Items.Add("X");
axisComboBox.Items.Add("Y");
axisComboBox.Items.Add("Z");
switch (dimensions)
{
case 1:
axisComboBox.Visibility = Visibility.Hidden;
angelComboBox.Visibility = Visibility.Hidden;
break;
case 2:
axisComboBox.Visibility = Visibility.Hidden;
angelComboBox.Visibility = Visibility.Visible;
break;
case 3:
axisComboBox.Visibility = Visibility.Visible;
angelComboBox.Visibility = Visibility.Visible;
break;
case 4:
angelComboBox.Items.Add(360);
angelComboBox.Items.Add(450);
axisComboBox.Items.Add("A");
axisComboBox.Visibility = Visibility.Visible;
angelComboBox.Visibility = Visibility.Visible;
break;
default:
return;
}
angelComboBox.SelectedItem = 90;
axisComboBox.SelectedItem = "Z";
rotateGrid.IsEnabled = dimensions != 1;
}
private void ShowArrays()
{
if (_dte.Mode == vsIDEMode.vsIDEModeDebug && _dte.Debugger.CurrentStackFrame != null)
{
if (_arraysPending && _toolActive)
{
_arraysPending = false;
string language = _dte.Debugger.CurrentStackFrame.Language;
switch (language)
{
case "C#":
_arrayLoader = new CsArrayLoader();
break;
case "F#":
_arrayLoader = new FsArrayLoader();
break;
case "Basic":
_arrayLoader = new VbArrayLoader();
break;
//case "C++":
// arrayLoader = new CppArrayLoader();
// break;
default:
_arrayLoader = GetLanguageLoader();
if (_arrayLoader != null)
break;
ClearVisualizer();
Label msg = new Label
{
Content = $"Sorry, currently {language} is not supported."
};
mainPanel.Children.Add(msg);
return;
}
_parsers = new ParsersCollection(_arrayLoader, _loadedParsers);
LoadScopeArrays();
}
}
}
private static IArrayLoader GetLanguageLoader()
{
return null; // Todo, try to load from dlls in bin folder
}
private static string DefaultCaptionBuilder(object captionData, string formatter)
{
Expression exp = captionData as Expression;
string text;
if (exp == null)
text = (captionData ?? "").ToString();
else
text = (exp.Value ?? "");
if (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out var number))
text = number.ToString(formatter, CultureInfo.CurrentCulture);
return text;
}
private static string IntegralCaptionBuilder(object captionData, string formatter)
{
Expression exp = captionData as Expression;
string text;
if (exp == null)
text = (captionData ?? "").ToString();
else
text = (exp.Value ?? "");
if (long.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out var number))
text = number.ToString(formatter, CultureInfo.CurrentCulture);
return text;
}
private void SetupControls(ExpressionInfo expressionInfo)
{
if (_data == null || arraysListBox.SelectedIndex == -1)
return;
if (VisualizerTab.SelectedIndex == 0)
_displayMode = DisplayMode.Array;
else if (VisualizerTab.SelectedIndex == 1)
_displayMode = DisplayMode.Chart;
switch (_displayMode)
{
case DisplayMode.Array:
SetupArrayControl(expressionInfo);
SetupChartControl(expressionInfo);
ShowElement(_arrCtl);
break;
case DisplayMode.Chart:
SetupChartControl(expressionInfo);
if (chartTab.IsEnabled)
ShowElement(_chartCtl);
else
{
_displayMode = DisplayMode.Array;
SetupControls(expressionInfo);
}
break;
}
}
private void ShowElement(Control control)
{
if (mainPanel != null)
mainPanel.Children.Clear();
if (mainPanel != null && (control != null && !mainPanel.Children.Contains(control)))
mainPanel.Children.Add(control);
}
private void SetChartType()
{
if (_chartCtl != null && _chartCtl.Areas.Any())
{
ChartTypes selectedChartType = GetSelectedChartType();
RangeCalculationMode calculationMode = GetSelectedChartCalculationMode(selectedChartType);
foreach (ChartArea area in _chartCtl.Areas)
{
area.PrimaryAxis.RangeCalculationMode = calculationMode;
foreach (var item in area.Series)
item.Type = selectedChartType;
}
}
}
private void SetGridLines()
{
bool seconday = gridLinesType.SelectedIndex == 1 || gridLinesType.SelectedIndex == 3;
bool primary = gridLinesType.SelectedIndex == 2 || gridLinesType.SelectedIndex == 3;
if (_chartCtl != null && _chartCtl.Areas.Any())
foreach (ChartArea area in _chartCtl.Areas)
{
ChartArea.SetShowGridLines(area.PrimaryAxis, primary);
ChartArea.SetShowGridLines(area.SecondaryAxis, seconday);
}
}
private void SetChartLineStroke()
{
float thickness = 1;
switch (lineThickness.SelectedIndex)
{
case 0:
thickness = 1;
break;
case 1:
thickness = 1.5f;
break;
case 2:
thickness = 2f;
break;
case 3:
thickness = 3f;
break;
}
if (_chartCtl != null && _chartCtl.Areas.Any())
{
foreach (ChartArea area in _chartCtl.Areas)
foreach (var item in area.Series)
item.StrokeThickness = thickness;
}
}
private void Reset(Array defaultData)
{
if (_arrCtl != null)
{
_arrCtl.Formatter = formatterTextBox.Text;
_arrCtl.CaptionBuilder = GetCaptionBuilder(_arrCtl.Formatter);
_arrCtl.CellHeight = double.Parse(cellHeightTextBox.Text, CultureInfo.CurrentCulture);
_arrCtl.CellWidth = double.Parse(cellWidthTextBox.Text, CultureInfo.CurrentCulture);
_arrCtl.SetControlData(defaultData);
_arrCtl.Padding = new Thickness(8);
_arrCtl.Width += 16;
_arrCtl.Height += 16;
}
}
private void SetChartStackModeOptions()
{
if (_dimensions == null)
return;
bool chart3D = _dimensions.Length == 2;
((ComboBoxItem) chartType.Items[2]).IsEnabled = chart3D;
((ComboBoxItem) chartType.Items[3]).IsEnabled = chart3D;
((ComboBoxItem) chartType.Items[5]).IsEnabled = chart3D;
((ComboBoxItem) chartType.Items[6]).IsEnabled = chart3D;
((ComboBoxItem) chartType.Items[8]).IsEnabled = chart3D;
((ComboBoxItem) chartType.Items[9]).IsEnabled = chart3D;
if (!((ComboBoxItem) chartType.SelectedItem).IsEnabled)
chartType.SelectedItem = chartType.Items[0];
}
private void SaveSettings()
{
Properties.Settings ds = Properties.Settings.Default;
ds.CellWidth = cellWidthTextBox.Text;
ds.CellHeight = cellHeightTextBox.Text;
ds.CellFormatter = formatterTextBox.Text;
ds.LoadSharpDX = SharpDXParserCheckBox.IsChecked.GetValueOrDefault();
ds.LoadFSharpMatrix = FSharpParserCheckBox.IsChecked.GetValueOrDefault();
ds.SplitterPosition = MainGrid.ColumnDefinitions[0].Width.Value;
ds.Save();
}
private void LoadSettings()
{
Properties.Settings ds = Properties.Settings.Default;
cellWidthTextBox.Text = ds.CellWidth;
cellHeightTextBox.Text = ds.CellHeight;
formatterTextBox.Text = ds.CellFormatter;
SharpDXParserCheckBox.IsChecked = ds.LoadSharpDX;
FSharpParserCheckBox.IsChecked = ds.LoadFSharpMatrix;
MainGrid.ColumnDefinitions[0].Width = new GridLength(ds.SplitterPosition, GridUnitType.Pixel);
}
#endregion
private enum DisplayMode
{
Array,
Chart
}
private enum LoadResults
{
Success,
LargeArray,
NotSupported,
Exception
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~ArrayVisualizerToolControl()
{
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && _chartCtl != null)
{
_chartCtl.Dispose();
_chartCtl = null;
}
}
#endregion
}
}