/[cits3200i]/branches/gps-running-clean-r116/HighScorePlugin/Source/HighScoreViewer.cs


UCC Code Repository

Contents of /branches/gps-running-clean-r116/HighScorePlugin/Source/HighScoreViewer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations) (download)
Sun Sep 5 15:48:34 2010 UTC (11 years, 3 months ago) by rvvs89
File size: 32242 byte(s)
Branching a local copy of the HEAD revision of the gps-running project on Google Code.
We will probably have to use this project as a template for our own plugins if we want to support SportTracks 2.1.
1 /*
2 Copyright (C) 2007, 2008 Kristian Bisgaard Lassen
3 Copyright (C) 2010 Kristian Helkjaer Lassen
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 using System;
20 using System.Collections.Generic;
21 using System.ComponentModel;
22 using System.Drawing;
23 using System.Data;
24 using System.Text;
25 using System.Windows.Forms;
26 using System.Reflection;
27 using System.Collections;
28
29 using ZoneFiveSoftware.Common.Data.Fitness;
30 using ZoneFiveSoftware.Common.Visuals;
31 using ZoneFiveSoftware.Common.Visuals.Fitness;
32 using ZoneFiveSoftware.Common.Visuals.Chart;
33 using GpsRunningPlugin.Properties;
34 using GpsRunningPlugin.Util;
35
36 namespace GpsRunningPlugin.Source
37 {
38 public partial class HighScoreViewer : UserControl
39 {
40 private readonly Form popupForm;
41 private readonly bool includeLocationAndDate, showDialog;
42 private GoalParameter domain, image;
43 private bool upperBound;
44 private IDictionary<GoalParameter, IDictionary<GoalParameter, IDictionary<bool, DataTable>>> cachedTables;
45 private IDictionary<DataTable, String> tableFormat;
46 private IDictionary<GoalParameter, IDictionary<GoalParameter, IDictionary<bool, IList<Result>>>> cachedResults;
47 private String speedUnit;
48
49 private IList<IActivity> activities = new List<IActivity>();
50 public IList<IActivity> Activities
51 {
52 set
53 {
54 //Make sure activities is not null
55 if (null == value) { activities.Clear(); }
56 else { activities = value; }
57 if (popupForm != null)
58 {
59 if (activities.Count > 1)
60 popupForm.Text = Resources.HSV + " " + String.Format(StringResources.OfManyActivities, activities.Count);
61 else if (activities.Count == 1)
62 popupForm.Text = Resources.HSV + " " + StringResources.OfOneActivity;
63 else
64 popupForm.Text = Resources.HSV + " " + StringResources.OfNoActivities;
65 }
66 resetCachedResults();
67 if (activities.Count > 0)
68 {
69 showResults();
70 }
71 }
72 }
73
74 public HighScoreViewer(IList<IActivity> activities, bool includeLocationAndDate, bool showDialog)
75 {
76 InitializeComponent();
77 InitControls();
78
79 Plugin.GetApplication().SystemPreferences.PropertyChanged += new PropertyChangedEventHandler(SystemPreferences_PropertyChanged);
80 dataGrid.CellContentDoubleClick += new DataGridViewCellEventHandler(selectedRow_DoubleClick);
81
82 this.showDialog = showDialog;
83 this.includeLocationAndDate = includeLocationAndDate;
84
85 domainBox.DropDownStyle = ComboBoxStyle.DropDownList;
86 imageBox.DropDownStyle = ComboBoxStyle.DropDownList;
87 boundsBox.DropDownStyle = ComboBoxStyle.DropDownList;
88 paceBox.DropDownStyle = ComboBoxStyle.DropDownList;
89 viewBox.DropDownStyle = ComboBoxStyle.DropDownList;
90
91 domainBox.SelectedItem = translateToLanguage(Settings.Domain);
92 imageBox.SelectedItem = translateToLanguage(Settings.Image);
93
94 boundsBox.SelectedItem = Settings.UpperBound ? StringResources.Maximal : StringResources.Minimal;
95 speedUnit = getMostUsedSpeedUnit(activities);
96 paceBox.SelectedItem = speedUnit;
97 if (Settings.ShowTable)
98 viewBox.SelectedItem = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelList;
99 else
100 viewBox.SelectedItem = StringResources.Graph;
101
102 domain = Settings.Domain;
103 image = Settings.Image;
104 upperBound = Settings.UpperBound;
105
106 domainBox.SelectedIndexChanged += new EventHandler(domainBox_SelectedIndexChanged);
107 imageBox.SelectedIndexChanged += new EventHandler(imageBox_SelectedIndexChanged);
108 boundsBox.SelectedIndexChanged += new EventHandler(boundsBox_SelectedIndexChanged);
109 paceBox.SelectedIndexChanged += new EventHandler(paceBox_SelectedIndexChanged);
110 viewBox.SelectedIndexChanged += new EventHandler(viewBox_SelectedIndexChanged);
111
112 dataGrid.CellToolTipTextNeeded += new DataGridViewCellToolTipTextNeededEventHandler(dataGrid_CellToolTipTextNeeded);
113 contextMenu.Click += new EventHandler(contextMenu_Click);
114
115 if (showDialog)
116 {
117 //Theme and Culture must be set manually
118 this.ThemeChanged(
119 #if ST_2_1
120 Plugin.GetApplication().VisualTheme
121 #else
122 Plugin.GetApplication().SystemPreferences.VisualTheme
123 #endif
124 );
125 this.UICultureChanged(
126 #if ST_2_1
127 new System.Globalization.CultureInfo("en")
128 #else
129 Plugin.GetApplication().SystemPreferences.UICulture
130 #endif
131 );
132 popupForm = new Form();
133 popupForm.Controls.Add(this);
134 popupForm.Size = Settings.WindowSize;
135 popupForm.Icon = Icon.FromHandle(Properties.Resources.Image_32_HighScore.GetHicon());
136 this.Size = new Size(Parent.Size.Width - 17, Parent.Size.Height - 38);
137 this.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
138 | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Bottom)));
139 Parent.SizeChanged += new EventHandler(Parent_SizeChanged);
140 popupForm.StartPosition = FormStartPosition.CenterScreen;
141 popupForm.Show();
142 }
143 else
144 {
145 SizeChanged += new EventHandler(SizeChanged_handler);
146 }
147 Activities = activities;
148 }
149
150 void InitControls()
151 {
152 paceBox.Items.Add(CommonResources.Text.LabelPace);
153 paceBox.Items.Add(CommonResources.Text.LabelSpeed);
154 viewBox.Items.Add(StringResources.Graph);
155 viewBox.Items.Add(ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelList);
156 boundsBox.Items.Add(StringResources.Minimal);
157 boundsBox.Items.Add(StringResources.Maximal);
158 domainBox.Items.Add(CommonResources.Text.LabelDistance);
159 domainBox.Items.Add(CommonResources.Text.LabelElevation);
160 domainBox.Items.Add(CommonResources.Text.LabelTime);
161 imageBox.Items.Add(CommonResources.Text.LabelDistance);
162 imageBox.Items.Add(CommonResources.Text.LabelElevation);
163 imageBox.Items.Add(CommonResources.Text.LabelTime);
164 imageBox.Items.Add(StringResources.HRZone);
165 imageBox.Items.Add(Resources.HRAndSpeedZones);
166 toolStripMenuCopy.Image = ZoneFiveSoftware.Common.Visuals.CommonResources.Images.DocumentCopy16;
167
168 //This will disable gradient header, but make them more like ST controls
169 //(required for setting ColumnHeadersDefaultCellStyle.BackColor)
170 this.dataGrid.EnableHeadersVisualStyles = false;
171 this.dataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
172 this.dataGrid.RowsDefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
173 this.dataGrid.AdvancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Outset;
174 }
175
176 private string translateToLanguage(GoalParameter goalParameter)
177 {
178 if (goalParameter.Equals(GoalParameter.PulseZone))
179 return StringResources.HRZone;
180 if (goalParameter.Equals(GoalParameter.SpeedZone))
181 return StringResources.SpeedZone;
182 if (goalParameter.Equals(GoalParameter.PulseZoneSpeedZone))
183 return Resources.HRAndSpeedZones;
184 if (goalParameter.Equals(GoalParameter.Distance))
185 return CommonResources.Text.LabelDistance;
186 if (goalParameter.Equals(GoalParameter.Elevation))
187 return CommonResources.Text.LabelElevation;
188 if (goalParameter.Equals(GoalParameter.Time))
189 return CommonResources.Text.LabelTime;
190 return null;
191 }
192
193 private void correctUI(IList<Control> comp)
194 {
195 Control prev = null;
196 foreach (Control c in comp)
197 {
198 if (prev != null)
199 {
200 c.Location = new Point(prev.Location.X + prev.Size.Width,
201 prev.Location.Y);
202 }
203 prev = c;
204 }
205 }
206
207 public void ThemeChanged(ITheme visualTheme)
208 {
209 //RefreshPage();
210 //m_visualTheme = visualTheme;
211 this.chart.ThemeChanged(visualTheme);
212
213 this.splitContainer1.Panel1.BackColor = visualTheme.Control;
214 this.splitContainer1.Panel2.BackColor = visualTheme.Control;
215 this.dataGrid.BackgroundColor = visualTheme.Control;
216 this.dataGrid.GridColor = visualTheme.Border;
217 this.dataGrid.DefaultCellStyle.BackColor = visualTheme.Window;
218 this.dataGrid.ColumnHeadersDefaultCellStyle.BackColor = visualTheme.SubHeader;
219 }
220
221 public void UICultureChanged(System.Globalization.CultureInfo culture)
222 {
223 Remarks.Text = "";
224 label1.Text = StringResources.Find;
225 label2.Text = StringResources.PerSpecified;
226 label3.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelShow;
227 correctUI(new Control[] { boundsBox, domainBox, label2, imageBox });
228 label1.Location = new Point(boundsBox.Location.X - 5 - label1.Width, label1.Location.Y);
229 correctUI(new Control[] { paceBox, viewBox, Remarks });
230 label3.Location = new Point(paceBox.Location.X - 5 - label3.Width, label3.Location.Y);
231 toolStripMenuCopy.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionCopy;
232 label2.Location = new Point(label2.Location.X, label1.Location.Y);
233 }
234
235 private bool _showPage = false;
236 public bool HidePage()
237 {
238 _showPage = false;
239 return true;
240 }
241 public void ShowPage(string bookmark)
242 {
243 bool changed = (_showPage != true);
244 _showPage = true;
245 // if (changed) { makeData(); }
246 }
247 private void setSize()
248 {
249 if (dataGrid.Columns.Count > 0 && dataGrid.Rows.Count > 0)
250 {
251 foreach (DataGridViewColumn column in dataGrid.Columns)
252 {
253 if (column.Name.Equals(ActivityIdColumn))
254 {
255 column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
256 column.Width = 0;
257 column.Visible = false;
258 }
259 else
260 {
261 column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
262 }
263 }
264 }
265 }
266
267 /***********************************************************/
268
269 void contextMenu_Click(object sender, EventArgs e)
270 {
271 StringBuilder s = new StringBuilder();
272 foreach (DataGridViewColumn column in dataGrid.Columns)
273 {
274 s.Append(column.HeaderText + "\t");
275 }
276 s.Append(StringResources.Goal);
277 s.Append("\n");
278 int rowIndex = 0;
279 foreach (DataGridViewRow row in dataGrid.Rows)
280 {
281 foreach (DataGridViewCell cell in row.Cells)
282 {
283 s.Append(cell.Value + "\t");
284 }
285 Goal goal = getGoalFromTable(rowIndex);
286 if (goal != null)
287 s.Append(getGoalFromTable(rowIndex).ToString(speedUnit));
288 s.Append("\n");
289 rowIndex++;
290 }
291 Clipboard.SetText(s.ToString());
292 }
293
294 void SystemPreferences_PropertyChanged(object sender, PropertyChangedEventArgs e)
295 {
296 if (e.PropertyName.Equals("DistanceUnits") || e.PropertyName.Equals("ElevationUnits"))
297 {
298 resetCachedTables();
299 showResults();
300 }
301 }
302
303 private String getLabel(GoalParameter gp)
304 {
305 switch (gp)
306 {
307 case GoalParameter.Distance:
308 return UnitUtil.Distance.LabelAxis;
309 case GoalParameter.Time:
310 return UnitUtil.Time.LabelAxis;
311 case GoalParameter.Elevation:
312 return UnitUtil.Elevation.LabelAxis;
313 case GoalParameter.PulseZone:
314 return UnitUtil.HeartRate.LabelAxis;
315 case GoalParameter.SpeedZone:
316 if (speedUnit.Equals(CommonResources.Text.LabelPace)) return UnitUtil.Pace.LabelAxis;
317 return UnitUtil.Speed.LabelAxis;
318 case GoalParameter.PulseZoneSpeedZone:
319 return UnitUtil.HeartRate.LabelAxis;
320 }
321 throw new Exception();
322 }
323
324 void viewBox_SelectedIndexChanged(object sender, EventArgs e)
325 {
326 setSettings();
327 showResults();
328 }
329
330 private double getValue(Result result, GoalParameter gp)
331 {
332 switch (gp)
333 {
334 case GoalParameter.Distance:
335 return UnitUtil.Distance.ConvertFrom(result.Meters);
336 case GoalParameter.Time:
337 return result.Seconds;
338 case GoalParameter.Elevation:
339 return UnitUtil.Elevation.ConvertFrom(result.Elevations);
340 case GoalParameter.PulseZone:
341 return result.AveragePulse;
342 case GoalParameter.SpeedZone:
343 double speed = result.Meters / result.Seconds;
344 return UnitUtil.PaceOrSpeed.ConvertFrom(speedUnit.Equals(CommonResources.Text.LabelPace), speed);
345 case GoalParameter.PulseZoneSpeedZone:
346 return result.AveragePulse;
347 }
348 throw new Exception();
349 }
350
351 private string getMostUsedSpeedUnit(IList<IActivity> activities)
352 {
353 int speed = 0, pace = 0;
354 foreach (IActivity activity in activities)
355 {
356 if (activity.Category.SpeedUnits.ToString().ToLower().Equals(CommonResources.Text.LabelPace))
357 pace++;
358 else speed++;
359 }
360 if (speed >= pace) return CommonResources.Text.LabelSpeed;
361 return CommonResources.Text.LabelPace;
362 }
363
364 private void resetCachedTables()
365 {
366 foreach (GoalParameter domain in Enum.GetValues(typeof(GoalParameter)))
367 {
368 if (cachedTables[domain] != null)
369 {
370 foreach (GoalParameter image in Enum.GetValues(typeof(GoalParameter)))
371 {
372 if (cachedTables[domain][image] != null)
373 {
374 cachedTables[domain][image][true] = null;
375 cachedTables[domain][image][false] = null;
376 }
377 }
378 }
379 }
380 }
381
382 private void resetCachedResults()
383 {
384 cachedTables = new Dictionary<GoalParameter, IDictionary<GoalParameter, IDictionary<bool, DataTable>>>();
385 tableFormat = new Dictionary<DataTable, String>();
386 cachedResults = new Dictionary<GoalParameter, IDictionary<GoalParameter, IDictionary<bool, IList<Result>>>>();
387 IList<Goal> goals = new List<Goal>();
388 foreach (GoalParameter domain in Enum.GetValues(typeof(GoalParameter)))
389 {
390 IDictionary<GoalParameter, IDictionary<bool, DataTable>> imageTableCache = new Dictionary<GoalParameter, IDictionary<bool, DataTable>>();
391 IDictionary<GoalParameter, IDictionary<bool, IList<Result>>> imageResultCache = new Dictionary<GoalParameter, IDictionary<bool, IList<Result>>>();
392
393 foreach (GoalParameter image in Enum.GetValues(typeof(GoalParameter)))
394 {
395 IDictionary<bool, DataTable> upperBoundTable = new Dictionary<bool, DataTable>();
396 upperBoundTable.Add(true, null);
397 upperBoundTable.Add(false, null);
398 imageTableCache.Add(image, upperBoundTable);
399 IDictionary<bool, IList<Result>> upperBoundResult = new Dictionary<bool, IList<Result>>();
400 if (image != domain &&
401 (domain == GoalParameter.Distance ||
402 domain == GoalParameter.Time ||
403 domain == GoalParameter.Elevation))
404 {
405 HighScore.generateGoals(domain, image, true, goals);
406 HighScore.generateGoals(domain, image, false, goals);
407 }
408 upperBoundResult.Add(true, null);
409 upperBoundResult.Add(false, null);
410 imageResultCache.Add(image, upperBoundResult);
411 }
412 cachedTables.Add(domain, imageTableCache);
413 cachedResults.Add(domain, imageResultCache);
414 }
415 progressBar.Minimum = 0;
416 progressBar.Maximum = activities.Count;
417 progressBar.Value = 0;
418 progressBar.Visible = true;
419 IList<Result> results = HighScore.calculate(activities, goals, progressBar);
420 progressBar.Visible = false;
421 foreach (GoalParameter domain in Enum.GetValues(typeof(GoalParameter)))
422 foreach (GoalParameter image in Enum.GetValues(typeof(GoalParameter)))
423 {
424 if (domain != image &&
425 (domain == GoalParameter.Distance ||
426 domain == GoalParameter.Time ||
427 domain == GoalParameter.Elevation))
428 {
429 cachedResults[domain][image][true] = filter(results, goals, domain, image, true);
430 cachedTables[domain][image][true] = HighScore.generateTable(cachedResults[domain][image][true],
431 speedUnit, includeLocationAndDate, domain, image, true);
432 tableFormat[cachedTables[domain][image][true]] = speedUnit;
433 cachedResults[domain][image][false] = filter(results, goals, domain, image, false);
434 cachedTables[domain][image][false] = HighScore.generateTable(cachedResults[domain][image][false],
435 speedUnit, includeLocationAndDate, domain, image, false);
436 tableFormat[cachedTables[domain][image][false]] = speedUnit;
437 }
438 }
439 }
440
441 private IList<Result> filter(IList<Result> results, IList<Goal> goals,
442 GoalParameter domain, GoalParameter image, bool p)
443 {
444 IList<Result> list = new List<Result>();
445 for (int i = 0; i < results.Count; i++)
446 {
447 if (goals[i].Domain.Equals(domain) && goals[i].Image.Equals(image) &&
448 goals[i].UpperBound == p)
449 list.Add(results[i]);
450 }
451 return list;
452 }
453
454 void paceBox_SelectedIndexChanged(object sender, EventArgs e)
455 {
456 speedUnit = (String)paceBox.SelectedItem;
457 showResults();
458 }
459
460 void imageBox_SelectedIndexChanged(object sender, EventArgs e)
461 {
462 setSettings();
463 showResults();
464 }
465
466 void domainBox_SelectedIndexChanged(object sender, EventArgs e)
467 {
468 setSettings();
469 showResults();
470 }
471
472 private void boundsBox_SelectedIndexChanged(object sender, EventArgs e)
473 {
474 setSettings();
475 showResults();
476 }
477
478 private String translateParameter(String str)
479 {
480 if (str.Equals(CommonResources.Text.LabelDistance)) return "distance";
481 if (str.Equals(CommonResources.Text.LabelElevation)) return "elevation";
482 if (str.Equals(CommonResources.Text.LabelTime)) return "time";
483 if (str.Equals(StringResources.HRZone)) return "pulsezone";
484 if (str.Equals(StringResources.SpeedZone)) return "speedzone";
485 if (str.Equals(Resources.HRAndSpeedZones)) return "pulsezonespeedzone";
486 return null;
487 }
488
489 private void setSettings()
490 {
491 Settings.Domain = (GoalParameter)Enum.Parse(typeof(GoalParameter),
492 translateParameter((String)domainBox.SelectedItem), true);
493 Settings.UpperBound = boundsBox.SelectedItem.Equals(StringResources.Maximal);
494 Settings.Image = (GoalParameter)Enum.Parse(typeof(GoalParameter), translateParameter((String)imageBox.SelectedItem), true);
495 domain = Settings.Domain;
496 image = Settings.Image;
497 upperBound = Settings.UpperBound;
498 Settings.ShowTable = viewBox.SelectedItem.Equals(ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelList);
499 }
500
501 private void showResults()
502 {
503 Remarks.Visible = false;
504 dataGrid.Visible = false;
505 chart.Visible = false;
506 if (domain.Equals(image))
507 {
508 Remarks.Text = Resources.NothingToDisplay;
509 Remarks.Visible = true;
510 return;
511 }
512 if (viewBox.SelectedItem.Equals(StringResources.Graph))
513 {
514 showGraph();
515 }
516 else
517 {
518 showTable();
519 }
520 showRemarks();
521 }
522
523 private void showRemarks()
524 {
525 int manualEntered = 0, noStartTime = 0;
526 foreach (IActivity activity in activities)
527 {
528 if (null != activity && activity.HasStartTime)
529 {
530 if (Settings.IgnoreManualData)
531 {
532 if (activity.UseEnteredData)
533 manualEntered++;
534 }
535 }
536 else
537 {
538 noStartTime++;
539 }
540 }
541 if (manualEntered + noStartTime == 0)
542 {
543 Remarks.Text = "";
544 }
545 else
546 {
547 Remarks.Text = String.Format(Resources.IgnoredActivities, (manualEntered + noStartTime)) + ": ";
548 bool first = true;
549 if (noStartTime > 0)
550 {
551 Remarks.Text += noStartTime + " " + Resources.HadNoStartTime;
552 first = false;
553 }
554 if (manualEntered > 0)
555 {
556 if (!first)
557 {
558 Remarks.Text += " " + StringResources.And + " ";
559 }
560 Remarks.Text += manualEntered + " " + Resources.HadManualEnteredData;
561 }
562 Remarks.Visible = true;
563 }
564 }
565
566 private void showTable()
567 {
568 DataTable table = cachedTables[domain][image][upperBound];
569 if (table == null)
570 {
571 IList<Result> results = cachedResults[domain][image][upperBound];
572 if (results == null)
573 {
574 IList<Goal> goals = HighScore.generateGoals();
575 progressBar.Visible = true;
576 results = HighScore.calculate(activities, goals, progressBar);
577 progressBar.Visible = false;
578 }
579 table = HighScore.generateTable(results, speedUnit, includeLocationAndDate,
580 Settings.Domain, Settings.Image, Settings.UpperBound);
581 cachedTables[domain][image][upperBound] = table;
582 tableFormat[table] = speedUnit;
583 cachedResults[domain][image][upperBound] = results;
584 }
585 else if (!tableFormat[table].Equals(speedUnit))
586 {
587 table = HighScore.generateTable(cachedResults[domain][image][upperBound], speedUnit, includeLocationAndDate,
588 Settings.Domain, Settings.Image, Settings.UpperBound);
589 cachedTables[domain][image][upperBound] = table;
590 tableFormat[table] = speedUnit;
591 }
592 if (table.Rows.Count > 0)
593 {
594 dataGrid.DataSource = table;
595 dataGrid.ShowCellToolTips = true;
596 foreach (DataGridViewColumn column in dataGrid.Columns)
597 {
598 column.SortMode = DataGridViewColumnSortMode.NotSortable;
599 }
600 dataGrid.Visible = true;
601 setSize();
602 }
603 else
604 {
605 Remarks.Text = Resources.NoResultsForSettings;
606 Remarks.Visible = true;
607 }
608 }
609
610 private void showGraph()
611 {
612 IList<Result> results = null;
613 if ((image == GoalParameter.Distance ||
614 image == GoalParameter.Time ||
615 image == GoalParameter.Elevation))
616 {
617 // Graph can only be calculated for some X-axis
618 chart.DataSeries.Clear();
619 chart.XAxis.Label = getLabel(image);
620 chart.YAxis.Label = getLabel(domain);
621 results = cachedResults[domain][image][upperBound];
622 if (results == null)
623 {
624 IList<Goal> goals = HighScore.generateGoals();
625 progressBar.Visible = true;
626 results = HighScore.calculate(activities, goals, progressBar);
627 progressBar.Visible = false;
628 }
629 }
630 if (results == null)
631 {
632 Remarks.Text = Resources.NoResultsForSettings;
633 Remarks.Visible = true;
634 }
635 else
636 {
637 ChartDataSeries series = new ChartDataSeries(chart, chart.YAxis);
638 setAxisType(chart.XAxis, image);
639 setAxisType(chart.YAxis, domain);
640 foreach (Result result in results)
641 {
642 if (result != null)
643 {
644 float x = (float)getValue(result, image);
645 float y = (float)getValue(result, domain);
646 if (!x.Equals(float.NaN) && !float.IsInfinity(y) &&
647 series.Points.IndexOfKey(x) == -1)
648 {
649 series.Points.Add(x, new PointF(x, y));
650 }
651 }
652 }
653 chart.DataSeries.Add(series);
654 chart.AutozoomToData(true);
655 setSize();
656 chart.Visible = true;
657 }
658 }
659
660 private void setAxisType(IAxis axis, GoalParameter goal)
661 {
662 switch (goal)
663 {
664 case GoalParameter.Time:
665 axis.Formatter = new Formatter.SecondsToTime(); return;
666 case GoalParameter.Distance:
667 axis.Formatter = new Formatter.General(UnitUtil.Distance.DefaultDecimalPrecision); return;
668 case GoalParameter.Elevation:
669 axis.Formatter = new Formatter.General(UnitUtil.Elevation.DefaultDecimalPrecision); return;
670 case GoalParameter.SpeedZone:
671 //TBD: This is likely not used
672 ArrayList categories = new ArrayList();
673 ArrayList keys = new ArrayList();
674 int index = 0;
675 foreach (double from in Settings.speedZones.Keys)
676 {
677 foreach (double to in Settings.speedZones[from].Keys)
678 {
679 categories.Add(UnitUtil.Speed.ToString(from) + "-" + UnitUtil.Speed.ToString(to));
680 keys.Add(index++);
681 }
682 }
683 axis.Formatter = new Formatter.Category(categories, keys);
684 return;
685 default:
686 axis.Formatter = new Formatter.General(); return;
687 }
688 }
689
690 private void dataGrid_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
691 {
692 Goal goal = getGoalFromTable(e.RowIndex);
693 if (goal != null)
694 e.ToolTipText = StringResources.Goal + ": " + goal.ToString(speedUnit);
695 }
696
697 private Goal getGoalFromTable(int rowIndex)
698 {
699 int index = 0;
700 IList<Result> results = cachedResults[domain][image][upperBound];
701 foreach (Result result in results)
702 {
703 if (index == rowIndex && result != null)
704 {
705 return result.Goal;
706 }
707 else if (result != null)
708 {
709 index++;
710 }
711 }
712 return null;
713 }
714
715 void SizeChanged_handler(object sender, EventArgs e)
716 {
717 setSize();
718 }
719 void Parent_SizeChanged(object sender, EventArgs e)
720 {
721 if (popupForm != null)
722 {
723 Settings.WindowSize = popupForm.Size;
724 }
725 SizeChanged_handler(sender, e);
726 }
727
728 private void selectedRow_DoubleClick(object sender, DataGridViewCellEventArgs e)
729 {
730 Guid view = new Guid("1dc82ca0-88aa-45a5-a6c6-c25f56ad1fc3");
731
732 int rowIndex = e.RowIndex;
733 if (rowIndex >= 0 && dataGrid.Columns[ActivityIdColumn] != null)
734 {
735 object id = dataGrid.Rows[rowIndex].Cells[ActivityIdColumn].Value;
736 if (id != null)
737 {
738 string bookmark = "id=" + id;
739 Plugin.GetApplication().ShowView(view, bookmark);
740 }
741 }
742 }
743
744 public const string ActivityIdColumn = "ActivityId";
745 }
746 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26