1 /* 2 * "GEDKeeper", the personal genealogical database editor. 3 * Copyright (C) 2009-2017 by Sergey V. Zhdanovskih. 4 * 5 * This file is part of "GEDKeeper". 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 using System.Collections.Generic; 22 using System.Drawing; 23 using System.Windows.Forms; 24 using BSLib; 25 using GKCore.MVP.Controls; 26 using GKCore.Stats; 27 using ZedGraph; 28 29 namespace GKUI.Components 30 { 31 /// <summary> 32 /// 33 /// </summary> 34 public sealed class ZGraphControl : UserControl, IGraphControl 35 { 36 private readonly ZedGraphControl fGraph; 37 ZGraphControl()38 public ZGraphControl() 39 { 40 fGraph = new ZedGraphControl(); 41 fGraph.IsShowPointValues = true; 42 fGraph.Dock = DockStyle.Fill; 43 Controls.Add(fGraph); 44 } 45 Activate()46 public void Activate() 47 { 48 Select(); 49 } 50 Clear()51 public void Clear() 52 { 53 GraphPane gPane = fGraph.GraphPane; 54 gPane.Title.Text = ""; 55 gPane.XAxis.Title.Text = ""; 56 gPane.YAxis.Title.Text = ""; 57 gPane.CurveList.Clear(); 58 59 fGraph.AxisChange(); 60 fGraph.Invalidate(); 61 } 62 PrepareArray(string title, string xAxis, string yAxis, ChartStyle style, bool excludeUnknowns, List<StatsItem> vals)63 public void PrepareArray(string title, string xAxis, string yAxis, ChartStyle style, bool excludeUnknowns, List<StatsItem> vals) 64 { 65 GraphPane gPane = fGraph.GraphPane; 66 try { 67 gPane.CurveList.Clear(); 68 69 gPane.Title.Text = title; 70 gPane.XAxis.Title.Text = xAxis; 71 gPane.YAxis.Title.Text = yAxis; 72 73 if (style != ChartStyle.ClusterBar) { 74 PointPairList ppList = new PointPairList(); 75 76 int num = vals.Count; 77 for (int i = 0; i < num; i++) { 78 StatsItem item = vals[i]; 79 80 string s = item.Caption; 81 double lab = (s == "?") ? 0.0f : ConvertHelper.ParseFloat(s, 0.0f, true); 82 83 if (lab != 0.0d || !excludeUnknowns) { 84 ppList.Add(lab, item.Value); 85 } 86 } 87 ppList.Sort(); 88 89 switch (style) { 90 case ChartStyle.Bar: 91 gPane.AddBar("-", ppList, Color.Green); 92 break; 93 94 case ChartStyle.Point: 95 gPane.AddCurve("-", ppList, Color.Green, SymbolType.Diamond).Symbol.Size = 3; 96 break; 97 } 98 } else { 99 gPane.CurveList.Clear(); 100 101 int itemscount = vals.Count; 102 double[] yValuesF = new double[itemscount]; 103 double[] yValuesM = new double[itemscount]; 104 double[] xValues = new double[itemscount]; 105 106 for (int i = 0; i < itemscount; i++) { 107 StatsItem sti = vals[i]; 108 xValues[i] = ConvertHelper.ParseInt(sti.Caption, 0); 109 yValuesF[i] = sti.ValF; 110 yValuesM[i] = sti.ValM; 111 } 112 113 gPane.AddBar("F", xValues, yValuesF, Color.Red); 114 gPane.AddBar("M", xValues, yValuesM, Color.Blue); 115 116 gPane.BarSettings.MinBarGap = 0.0f; 117 gPane.BarSettings.MinClusterGap = 2.5f; 118 119 // expand the range of the Y axis slightly to accommodate the labels 120 //gPane.YAxis.Scale.Max += gPane.YAxis.Scale.MajorStep; 121 122 // Create TextObj's to provide labels for each bar 123 BarItem.CreateBarLabels(gPane, false, "f0"); 124 } 125 } finally { 126 fGraph.AxisChange(); 127 fGraph.Invalidate(); 128 } 129 } 130 } 131 } 132