forked from hackerzhou/GPATool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreDistributionChartPanel.cs
236 lines (226 loc) · 9.41 KB
/
ScoreDistributionChartPanel.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using GPATool.Util;
namespace GPATool
{
public enum ScoreDistributionChartPanelType
{
SCORE_DISTRIBUTION_COURSE,
SCORE_DISTRIBUTION_SEMESTER,
SCORE_DISTRIBUTION_TEACHER,
NOT_SET
}
public partial class ScoreDistributionChartPanel : UserControl
{
private ScoreDistributionChartPanelType panelType = ScoreDistributionChartPanelType.NOT_SET;
private Color savedDataPointColor;
public ScoreDistributionChartPanel()
{
InitializeComponent();
}
public void SetPanelType(ScoreDistributionChartPanelType type)
{
if (this.panelType != type)
{
this.HidePanel();
this.panelType = type;
comboBox2.Items.Clear();
if (type == ScoreDistributionChartPanelType.SCORE_DISTRIBUTION_COURSE)
{
comboBox2.Items.AddRange(new String[] { "饼状图", "柱状图" });
chart1.Series[0].ChartType = SeriesChartType.Pie;
listView2.Columns[0].Text = "成绩";
listView2.Columns[1].Text = "人数";
listView2.Columns[2].Text = "百分比";
chart1.ChartAreas[0].AxisY.Maximum = double.NaN;
chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 0;
chart1.ChartAreas[0].AxisY.Interval = 0;
chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = true;
}
else if (type == ScoreDistributionChartPanelType.SCORE_DISTRIBUTION_SEMESTER
|| type == ScoreDistributionChartPanelType.SCORE_DISTRIBUTION_TEACHER)
{
if (type == ScoreDistributionChartPanelType.SCORE_DISTRIBUTION_SEMESTER)
{
comboBox2.Items.AddRange(new String[] { "折线图", "柱状图" });
chart1.Series[0].ChartType = SeriesChartType.Line;
listView2.Columns[0].Text = "学期";
}
else
{
comboBox2.Items.AddRange(new String[] { "柱状图", "条状图" });
chart1.Series[0].ChartType = SeriesChartType.Column;
listView2.Columns[0].Text = "老师";
}
listView2.Columns[1].Text = "平均成绩";
listView2.Columns[2].Text = "Top 2 比例成绩";
chart1.ChartAreas[0].AxisY.Maximum = 4.0;
chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 0.5;
chart1.ChartAreas[0].AxisY.Interval = 0.5;
chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
}
comboBox2.SelectedIndex = 0;
}
}
public void RefreshData(String[][] listViewItemStr, DataPoint[] chartPoint)
{
chart1.Series[0].Points.Clear();
listView2.Items.Clear();
foreach (String[] listItem in listViewItemStr)
{
listView2.Items.Add(new ListViewItem(listItem));
}
listView2.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
foreach (DataPoint dp in chartPoint)
{
chart1.Series[0].Points.Add(dp);
}
comboBox2_SelectedIndexChanged(null, null);
this.ShowPanel();
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool AnimateWindow(IntPtr hwnd, uint dwTime, uint dwFlags);
public const Int32 AW_HOR_POSITIVE = 0x00000001;
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
public const Int32 AW_VER_POSITIVE = 0x00000004;
public const Int32 AW_VER_NEGATIVE = 0x00000008;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;
private delegate void SetPanelOperation();
public void ShowPanel()
{
if (this.InvokeRequired)
{
SetPanelOperation cb = new SetPanelOperation(ShowPanel);
this.Invoke(cb);
}
else
{
AnimateWindow(Handle, 300, AW_VER_POSITIVE | AW_SLIDE);
this.Show();
this.chart1.Visible = true;
}
}
public void HidePanel()
{
if (this.InvokeRequired)
{
SetPanelOperation cb = new SetPanelOperation(HidePanel);
this.Invoke(cb);
}
else
{
AnimateWindow(Handle, 300, AW_VER_NEGATIVE | AW_HIDE | AW_SLIDE);
this.Hide();
this.chart1.Visible = false;
}
}
private void ScoreDistributionChartPanel_Load(object sender, EventArgs e)
{
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
ListViewStripMenuHelper.CopyAllItemsToClipBoard(listView2);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView2.SelectedIndices.Count > 0)
{
chart1.Series[0].Points[listView2.SelectedIndices[0]].BorderWidth = 0;
listView2.SelectedIndices.Clear();
}
if ("饼状图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].ChartType = SeriesChartType.Pie;
chart1.Series[0].IsVisibleInLegend = true;
}
else
{
chart1.Series[0].IsVisibleInLegend = false;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Triangle;
chart1.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Triangle;
if ("柱状图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].ChartType = SeriesChartType.Column;
foreach (DataPoint dp in chart1.Series[0].Points)
{
dp.MarkerStyle = MarkerStyle.None;
}
}
else if ("折线图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].ChartType = SeriesChartType.Line;
foreach (DataPoint dp in chart1.Series[0].Points)
{
dp.MarkerStyle = MarkerStyle.Circle;
dp.MarkerSize = 10;
}
}
else if ("条状图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].ChartType = SeriesChartType.Bar;
foreach (DataPoint dp in chart1.Series[0].Points)
{
dp.MarkerStyle = MarkerStyle.None;
}
}
}
}
private void listView2_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (e.IsSelected)
{
int index = e.ItemIndex;
if (index >= 0 && index < chart1.Series[0].Points.Count)
{
Color highlightColor = Color.Orange;
if ("柱状图".Equals(comboBox2.SelectedItem))
{
savedDataPointColor = chart1.Series[0].Points[index].Color;
chart1.Series[0].Points[index].Color = highlightColor;
}
else if ("饼状图".Equals(comboBox2.SelectedItem))
{
savedDataPointColor = chart1.Series[0].Points[index].BorderColor;
chart1.Series[0].Points[index].BorderColor = Color.OrangeRed;
chart1.Series[0].Points[index].BorderWidth = 3;
chart1.Series[0].Points[index].BorderDashStyle = ChartDashStyle.Solid;
}
else
{
savedDataPointColor = chart1.Series[0].Points[index].MarkerColor;
chart1.Series[0].Points[index].MarkerColor = highlightColor;
}
}
}
else
{
if ("柱状图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].Points[e.ItemIndex].Color = savedDataPointColor;
}
else if ("饼状图".Equals(comboBox2.SelectedItem))
{
chart1.Series[0].Points[e.ItemIndex].BorderColor = savedDataPointColor;
chart1.Series[0].Points[e.ItemIndex].BorderWidth = 0;
}
else
{
chart1.Series[0].Points[e.ItemIndex].MarkerColor = savedDataPointColor;
}
}
}
}
}